8 #include "CbmMuchFindHitsStraws.h"
14 #include "CbmMuchStrawHit.h"
17 #include "FairEventHeader.h"
18 #include "FairRootManager.h"
19 #include "FairRunAna.h"
21 #include <TClonesArray.h>
39 : FairTask(
"MuchFindVectorsQA")
53 FairRootManager* ioman = FairRootManager::Instance();
55 Fatal(
"CbmMuchFindTracksQA::Init",
"RootManager not instantiated!");
61 fVectors =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchVector"));
62 fMCTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"MCTrack"));
63 fPoints =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPoint"));
64 fHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchStrawHit"));
65 fHitsGem =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPixelHit"));
66 fDigis =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchStrawDigi"));
67 fDigisGem =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchDigi"));
69 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchStrawDigiMatch"));
71 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchDigiMatch"));
72 fClusters =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchCluster"));
77 for (Int_t
i = 0;
i < nSt; ++
i) {
86 for (Int_t lay = 0; lay < nLays; ++lay) {
89 for (Int_t iside = 0; iside < 2; ++iside) {
91 Int_t plane = lay * 2 + iside;
99 TDirectory* dir =
new TDirectory(
"muchQA",
"",
"");
147 for (Int_t ist = 0; ist <
fNstat; ++ist) {
149 fhNvec[ist] =
new TH1D(Form(
"hNvec%i", stat),
150 Form(
"Number of vectors in station %i", stat),
155 new TH1D(Form(
"hNdoubl%i", stat),
156 Form(
"Number of tubes in lay. 1 in station %i", stat),
160 fhNhits[ist] =
new TH1D(Form(
"hNhits%i", stat),
161 Form(
"Number of hits/vector in station %i", stat),
166 new TH1D(Form(
"hNhitsOk%i", stat),
167 Form(
"Number of hits/good vector in station %i", stat),
171 fhChi2[ist] =
new TH1D(Form(
"hChi2all%i", stat),
172 Form(
"Chi2 of all vectors in station %i", stat),
176 fhNgood[ist] =
new TH1D(Form(
"hNgood%i", stat),
177 Form(
"Number of good vectors in station %i", stat),
182 new TH1D(Form(
"hNghost%i", stat),
183 Form(
"Number of ghost vectors in station %i", stat),
187 fhChi2ok[ist] =
new TH1D(Form(
"hChi2ok%i", stat),
188 Form(
"Chi2 of good vectors in station %i", stat),
192 fhChi2bad[ist] =
new TH1D(Form(
"hChi2bad%i", stat),
193 Form(
"Chi2 of ghost vectors in station %i", stat),
197 fhDx[ist] =
new TH1D(
198 Form(
"hDx%i", stat), Form(
"Xrec-Xmc in station %i", stat), 100, -2, 2);
199 fhDy[ist] =
new TH1D(
200 Form(
"hDy%i", stat), Form(
"Yrec-Ymc in station %i", stat), 100, -15, 15);
201 fhDtx[ist] =
new TH1D(Form(
"hDtx%i", stat),
202 Form(
"TXrec-TXmc in station %i", stat),
206 fhDty[ist] =
new TH1D(
207 Form(
"hDty%i", stat), Form(
"TYrec-TYmc in station %i", stat), 100, -1, 1);
208 fhIds[ist] =
new TH1D(Form(
"hIds%i", stat),
209 Form(
"Good track ID in station %i", stat),
214 new TH2D(Form(
"hIdVsEv%i", stat),
215 Form(
"Good track ID vs ev. No. in station %i", stat),
223 fhDtxAll[ist] =
new TH1D(Form(
"hDtxAll%i", stat),
224 Form(
"TXvec-TXhit in station %i", stat),
228 fhDtyAll[ist] =
new TH1D(Form(
"hDtyAll%i", stat),
229 Form(
"TYvec-TYhit in station %i", stat),
233 fhDtxOk[ist] =
new TH1D(Form(
"hDtxOk%i", stat),
234 Form(
"TXvec-TXhit in station %i (ok)", stat),
238 fhDtyOk[ist] =
new TH1D(Form(
"hDtyOk%i", stat),
239 Form(
"TYvec-TYhit in station %i (ok)", stat),
243 fhDtube[ist][0] =
new TH1D(Form(
"hDtube21_%i", stat),
244 Form(
"Dtube 21 vs tube in station %i", stat),
248 fhDtube[ist][1] =
new TH1D(Form(
"hDtube32_%i", stat),
249 Form(
"Dtube 32 vs tube in station %i", stat),
253 fhDtube[ist][2] =
new TH1D(Form(
"hDtube43_%i", stat),
254 Form(
"Dtube 43 vs tube in station %i", stat),
258 fhShort[ist] =
new TH1D(Form(
"hShort%i", stat),
259 Form(
"Number of shared hits in station %i", stat),
263 fhOverlap[ist] =
new TH2D(Form(
"hOverlap%i", stat),
264 Form(
"Overlap multipl. in station %i", stat),
271 fhChi2mat[ist] =
new TH1D(Form(
"hChi2mat%i", stat),
272 Form(
"Chi2 of matching in station %i", stat),
277 new TH1D(Form(
"hMatchMult%i", stat),
278 Form(
"Multiplicity of matching in station %i", stat),
282 fhOccup[ist] =
new TH1D(Form(
"hOccup%i", stat),
283 Form(
"Occupancy in station %i", stat),
287 fhDtube2[ist][0] =
new TH2D(Form(
"hDtube31_%i", stat),
288 Form(
"Dtube 31 vs tube in station %i", stat),
295 fhDtube2[ist][1] =
new TH2D(Form(
"hDtube42_%i", stat),
296 Form(
"Dtube 42 vs tube in station %i", stat),
303 fhMCFit[ist][0] =
new TH1D(Form(
"hMCFitX_%i", stat),
304 Form(
"Chi2 of fit in X in station %i", stat),
308 fhMCFit[ist][1] =
new TH1D(Form(
"hMCFitY_%i", stat),
309 Form(
"Chi2 of fit in Y in station %i", stat),
313 fhDx12[ist] =
new TH2D(Form(
"hDx12_%i", stat),
314 Form(
"Dx2 vs Dx1 in station %i", stat),
321 fhDx23[ist] =
new TH2D(Form(
"hDx23_%i", stat),
322 Form(
"Dx3 vs Dx2 in station %i", stat),
329 fhDy12[ist] =
new TH2D(Form(
"hDy12_%i", stat),
330 Form(
"Dy2 vs Dy1 in station %i", stat),
337 fhDy23[ist] =
new TH2D(Form(
"hDy23_%i", stat),
338 Form(
"Dy3 vs Dy2 in station %i", stat),
346 fhSim =
new TH1D(
"hSim",
"Number of reconstructable muons", 10, 0, 10);
347 fhRec =
new TH1D(
"hRec",
"Number of reconstructed muons", 10, 0, 10);
348 fhZXY[0] =
new TH1D(
"hZX",
"Z - X", 180, 0, 45);
349 fhZXY[1] =
new TH1D(
"hZY",
"Z - Y", 180, 0, 45);
350 fhEvents =
new TH1D(
"hEvents",
"Number of processed events", 5, 0, 5);
358 Int_t* mult =
new Int_t[
fNstat];
359 Int_t* multOk =
new Int_t[
fNstat];
360 Int_t* multBad =
new Int_t[
fNstat];
362 mult[
i] = multOk[
i] = multBad[
i] = 0;
365 Int_t nvec =
fVectors->GetEntriesFast();
366 cout <<
" nvec " << nvec << endl;
367 for (Int_t iv = 0; iv < nvec; ++iv) {
369 Int_t ista = vec->GetUniqueID();
374 fhDtxAll[ista]->Fill(params->GetTx() - params->GetX() / params->GetZ());
375 fhDtyAll[ista]->Fill(params->GetTy() - params->GetY() / params->GetZ());
386 cout << mult[0] <<
" " << mult[1] << endl;
402 Int_t nhits =
fHits->GetEntriesFast(), nDouble[10] = {0};
403 for (Int_t
i = 0;
i < nhits; ++
i) {
404 CbmMuchStrawHit* hit = (CbmMuchStrawHit*)
fHits->UncheckedAt(
i);
406 fhOccup[ista]->Fill(hit->GetTube());
409 if (lay == 0 && side == 0) ++nDouble[ista];
412 for (Int_t ista = 0; ista <
fNstat; ++ista)
425 Int_t ista = vec->GetUniqueID();
428 Int_t nhits = vec->
GetNofHits(), nthr = nhits / 2,
id = 0;
430 map<Int_t, Int_t> ids;
432 for (Int_t ih = 0; ih < nhits; ++ih) {
433 CbmMuchStrawHit* hit =
436 if (hit->GetFlag() % 2) {
440 if (ids.find(
id) == ids.end())
441 ids.insert(pair<Int_t, Int_t>(
id, 1));
448 for (Int_t ip = 0; ip < np; ++ip) {
452 id = point->GetTrackID();
454 if (ids.find(
id) == ids.end())
455 ids.insert(pair<Int_t, Int_t>(
id, 1));
462 Int_t maxim = -1, idmax = -9;
463 for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) {
464 if (it->second > maxim) {
471 if (maxim <= nthr || idmax < 0)
return kFALSE;
473 if (idmax > 1)
return kFALSE;
476 fhIds[ista]->Fill(idmax);
477 Int_t evID = FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber() + 1;
481 Double_t zp = 0.0, parsTr[4] = {0.0};
483 for (Int_t ih = 0; ih < nhits; ++ih) {
484 CbmMuchStrawHit* hit =
489 for (Int_t ip = 0; ip < np; ++ip) {
492 id = point->GetTrackID();
493 if (
id != idmax)
continue;
497 parsTr[2] = point->GetPx() / point->GetPz();
498 parsTr[3] = point->GetPy() / point->GetPz();
506 parsTr[0] += parsTr[2] * (params->GetZ() - zp);
507 parsTr[1] += parsTr[3] * (params->GetZ() - zp);
508 fhDx[ista]->Fill(params->GetX() - parsTr[0]);
509 fhDy[ista]->Fill(params->GetY() - parsTr[1]);
510 fhDtx[ista]->Fill(params->GetTx() - parsTr[2]);
511 fhDty[ista]->Fill(params->GetTy() - parsTr[3]);
512 fhDtxOk[ista]->Fill(params->GetTx() - params->GetX() / params->GetZ());
513 fhDtyOk[ista]->Fill(params->GetTy() - params->GetY() / params->GetZ());
514 cout <<
" Good: " << idmax <<
" " << zp <<
" " << params->GetZ() <<
" "
515 << parsTr[0] <<
" " << params->GetX() <<
" " << parsTr[1] <<
" "
516 << params->GetY() <<
" " << parsTr[2] <<
" " << params->GetTx() <<
" "
517 << parsTr[3] <<
" " << params->GetTy() <<
" " << vec->
GetChiSq() << endl;
520 map<Int_t, Int_t> tubes[2];
527 for (Int_t ih = 0; ih < nhits; ++ih) {
528 CbmMuchStrawHit* hit =
533 for (Int_t ip = 0; ip < np; ++ip) {
536 id = point->GetTrackID();
537 if (
id > 1)
continue;
538 if (id0 < 0) id0 = id;
541 if (id0 < 0 ||
id != id0)
continue;
544 tubes[id].insert(pair<Int_t, Int_t>(lay + stat * combi, hit->GetTube()));
546 Double_t slope[2] = {0.08, 0.06};
547 for (Int_t j = 0; j < 2; ++j) {
549 Int_t nd = tubes[j].size();
550 if (nd < 2)
continue;
551 Int_t tubeNos[6] = {1000, 1000, 1000, 1000, 1000, 1000};
552 map<Int_t, Int_t>::iterator it = tubes[j].begin();
553 tubeNos[it->first] = it->second;
555 for (; it != tubes[j].end(); ++it)
556 tubeNos[it->first] = it->second;
557 for (Int_t lay = 1; lay < 4; ++lay) {
558 if (tubeNos[lay] < 1000 & tubeNos[lay - 1] < 1000)
559 fhDtube[ista][lay - 1]->Fill(tubeNos[lay] - tubeNos[lay - 1]);
562 if (lay == 2 && tubeNos[lay] < 1000 & tubeNos[lay - 2] < 1000)
563 fhDtube2[ista][lay - 2]->Fill(tubeNos[lay - 2],
564 tubeNos[lay] - tubeNos[lay - 2]);
565 if (lay == 3 && tubeNos[lay] < 1000 & tubeNos[lay - 2] < 1000) {
567 Double_t dzz = (
fZpos[ista][lay * 2] -
fZpos[ista][lay * 2 - 4])
568 /
fZpos[ista][lay * 2 - 4];
569 fhDtube2[ista][lay - 2]->Fill(tubeNos[lay - 2],
570 tubeNos[lay] - tubeNos[lay - 2]
571 - dzz * tubeNos[lay - 2]);
575 if (lay == 3 && tubeNos[lay] < 1000 & tubeNos[lay - 3] < 1000)
576 fhDtube2[ista][lay - 3]->Fill(tubeNos[lay - 3],
577 tubeNos[lay] - tubeNos[lay - 3]);
578 if (lay == 1 && tubeNos[lay] < 1000 & tubeNos[lay + 3] < 1000) {
580 Double_t dzz = (
fZpos[ista + 1][lay * 2] -
fZpos[ista][lay * 2])
581 /
fZpos[ista][lay * 2];
583 tubeNos[lay], tubeNos[lay + 3] - tubeNos[lay] - dzz * tubeNos[lay]);
598 Int_t ista = vec->GetUniqueID();
599 Int_t nhits = vec->
GetNofHits(), nthr = nhits / 2,
id = 0;
601 map<Int_t, Int_t> ids;
603 for (Int_t ih = 0; ih < nhits; ++ih) {
609 for (Int_t j = 0; j < nDigis; ++j) {
613 for (Int_t ip = 0; ip < np; ++ip) {
617 id = point->GetTrackID();
625 Int_t maxim = -1, idmax = -9;
626 for (map<Int_t, Int_t>::iterator it = ids.begin(); it != ids.end(); ++it) {
627 if (it->second > maxim) {
635 if (maxim <= nthr || idmax < 0)
return kFALSE;
637 if (idmax > 1)
return kFALSE;
640 fhIds[ista]->Fill(idmax);
641 Int_t evID = FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber() + 1;
645 Double_t zp = 0.0, parsTr[4] = {0.0};
648 for (Int_t ih = 0; ih < nhits; ++ih) {
654 for (Int_t j = 0; j < nDigis; ++j) {
658 for (Int_t ip = 0; ip < np; ++ip) {
661 id = point->GetTrackID();
662 if (
id != idmax)
continue;
666 parsTr[2] = point->GetPx() / point->GetPz();
667 parsTr[3] = point->GetPy() / point->GetPz();
677 parsTr[0] += parsTr[2] * (params->GetZ() - zp);
678 parsTr[1] += parsTr[3] * (params->GetZ() - zp);
679 fhDx[ista]->Fill(params->GetX() - parsTr[0]);
680 fhDy[ista]->Fill(params->GetY() - parsTr[1]);
681 fhDtx[ista]->Fill(params->GetTx() - parsTr[2]);
682 fhDty[ista]->Fill(params->GetTy() - parsTr[3]);
683 fhDtxOk[ista]->Fill(params->GetTx() - params->GetX() / params->GetZ());
684 fhDtyOk[ista]->Fill(params->GetTy() - params->GetY() / params->GetZ());
685 cout <<
" Good: " << idmax <<
" " << zp <<
" " << params->GetZ() <<
" "
686 << parsTr[0] <<
" " << params->GetX() <<
" " << parsTr[1] <<
" "
687 << params->GetY() <<
" " << parsTr[2] <<
" " << params->GetTx() <<
" "
688 << parsTr[3] <<
" " << params->GetTy() <<
" " << vec->
GetChiSq() << endl;
698 Int_t nvec =
fVectors->GetEntriesFast();
700 for (Int_t iv = 0; iv < nvec; ++iv) {
703 if (nhits != nhits0)
continue;
704 Int_t ista = vec->GetUniqueID();
706 multiset<Int_t> overlap1;
708 for (Int_t iv1 = iv + 1; iv1 < nvec; ++iv1) {
710 if (vec1->GetUniqueID() != ista)
continue;
715 for (Int_t ih = 0; ih < nhits; ++ih) {
720 Int_t plane = lay * 2 + side;
722 for (; ih1 < nhits1; ++ih1) {
728 Int_t plane1 = lay1 * 2 + side1;
729 if (plane1 < plane)
continue;
730 if (plane1 > plane)
break;
737 if (overlap.size() == nhits0) {
742 fhShort[ista]->Fill(overlap.size());
743 if (overlap.size())
fhOverlap[ista]->
Fill(overlap.size(), overlap1.size());
755 set<Int_t> doublets[20][nMu], singlets[20][nMu];
756 Int_t nPoints =
fPoints->GetEntriesFast();
757 Double_t xp[7][20][nMu], yp[7][20][nMu];
758 Bool_t lstraws = kFALSE;
760 for (Int_t ip = 0; ip < nPoints; ++ip) {
762 Int_t
id = p->GetTrackID();
763 if (
id > 1)
continue;
764 if (p->GetZ() <
fZpos[0][0] - 2.0)
continue;
769 doublets[ista][id].insert(lay);
770 singlets[ista][id].insert(lay * 2 + side);
771 xp[ista][lay * 2 + side][id] = (p->
GetXIn() + p->
GetXOut()) / 2;
772 yp[ista][lay * 2 + side][id] = (p->
GetYIn() + p->
GetYOut()) / 2;
781 Int_t muons[7][nMu] = {{0}, {0}}, nMuVec = 0;
782 for (Int_t ista = 0; ista <
fNstat; ++ista) {
783 if (doublets[ista][0].size() ==
fNdoubl[ista]) {
788 if (doublets[ista][1].size() ==
fNdoubl[ista]) {
795 if (nMuVec == 0)
return;
823 Int_t nvec =
fVectors->GetEntriesFast();
827 Double_t errxS[6] = {0.33, 0.50, 0.2, 0.2, 1, 1};
828 Double_t erryS[6] = {0.33, 0.50, 1.9, 1.9, 1, 1},
832 Double_t errxG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1};
833 Double_t erryG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1};
834 Int_t nMatch[7][nMu] = {{0}, {0}}, combi = 0;
835 Double_t *errx = errxG, *erry = erryG;
843 for (Int_t iv = 0; iv < nvec; ++iv) {
846 Int_t ista = vec->GetUniqueID();
847 if (muons[ista][0] == 0 && muons[ista][1] == 0)
continue;
854 Double_t chi2[nMu] = {0.0};
855 for (Int_t mu = 0; mu < nMu; ++mu) {
856 if (!muons[ista][mu]) {
861 Double_t dx0 = 0, dy0 = 0;
863 for (Int_t ih = 0; ih < nhits; ++ih) {
870 Int_t plane = lay * 2 + side;
871 plane += stat * combi;
872 if (singlets[ista][mu].find(plane) == singlets[ista][mu].end())
874 Double_t
x = params->GetX()
875 + params->GetTx() * (
fZpos[ista][plane] - params->GetZ());
876 Double_t
y = params->GetY()
877 + params->GetTy() * (
fZpos[ista][plane] - params->GetZ());
878 Double_t dx =
x - xp[ista][plane][mu];
879 Double_t dy =
y - yp[ista][plane][mu];
880 chi2[mu] += dx * dx / errx[ista] / errx[ista];
881 chi2[mu] += dy * dy / erry[ista] / erry[ista];
885 fhDx12[ista]->Fill(dx0, dx);
886 fhDy12[ista]->Fill(dy0, dy);
887 }
else if (lay == 2) {
888 fhDx23[ista]->Fill(dx0, dx);
889 fhDy23[ista]->Fill(dy0, dy);
897 if (nm > 4) chi2[mu] /= (nm - 4);
903 fhChi2mat[ista]->Fill(TMath::Min(chi2[0], chi2[1]));
904 if (chi2[0] < chi2cut) ++nMatch[ista][0];
905 if (chi2[1] < chi2cut) ++nMatch[ista][1];
906 cout << chi2[0] <<
" " << chi2[1] << endl;
908 for (Int_t ista = 0; ista <
fNstat; ++ista) {
909 if (combi && ista ==
fNstat - 1)
continue;
910 for (Int_t
id = 0;
id < nMu; ++id) {
911 if (muons[ista][
id]) {
912 if (combi && ista ==
fNstat - 2 && muons[ista + 1][
id] == 0)
915 if (nMatch[ista][
id] == 0)
916 cout <<
" !!! No match found !!! " << ista <<
" " <<
id << endl;
925 for (Int_t ista = 0; ista <
fNstat; ++ista) {
930 TDirectory* dir = (TDirectory*) gROOT->FindObjectAny(
"muchQA");
931 gDirectory->mkdir(
"muchQA");
932 gDirectory->cd(
"muchQA");
933 dir->GetList()->Write();