8 #include "CbmMuchFindHitsStraws.h"
12 #include "CbmMuchStrawHit.h"
15 #include "FairEventHeader.h"
16 #include "FairRootManager.h"
17 #include "FairRunAna.h"
19 #include <TClonesArray.h>
34 : FairTask(
"MuchMergeVectorsQA")
48 FairRootManager* ioman = FairRootManager::Instance();
49 if (ioman == NULL) Fatal(
"Init",
"RootManager not instantiated!");
55 fTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchVectorTrack"));
56 fVectors =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchVector"));
57 fMCTracks =
static_cast<TClonesArray*
>(ioman->GetObject(
"MCTrack"));
58 fPoints =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPoint"));
59 fHits =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchStrawHit"));
60 fHitsGem =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchPixelHit"));
61 fDigis =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchStrawDigi"));
62 fDigisGem =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchDigi"));
64 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchStrawDigiMatch"));
66 static_cast<TClonesArray*
>(ioman->GetObject(
"MuchDigiMatch"));
67 fClusters =
static_cast<TClonesArray*
>(ioman->GetObject(
"MuchCluster"));
72 for (Int_t
i = 0;
i < nSt; ++
i) {
81 for (Int_t lay = 0; lay < nLays; ++lay) {
84 for (Int_t iside = 0; iside < 2; ++iside) {
86 Int_t plane = lay * 2 + iside;
95 TDirectory* dir0 = (TDirectory*) gROOT->FindObjectAny(
"muchQA");
96 TDirectory* dir =
new TDirectory(
"muchQA1",
"",
"", dir0);
115 for (Int_t ist = 0; ist <
fNstat; ++ist) {
117 Int_t stat = 1 + ist;
118 fhChi2mat[ist] =
new TH1D(Form(
"hChi2mat%i", stat),
119 Form(
"Chi2 of matching in station %i", stat),
125 new TH1D(
"hChi2mat",
"Chi2 of matching in 2 stations", 100, 0, 100);
127 new TH1D(
"hChi2Abs",
"Chi2 of 2 vector matching", 100, 0, 50);
128 fhSim =
new TH1D(
"hSim",
"Number of reconstructable muons", 10, 0, 10);
129 fhRec =
new TH1D(
"hRec",
"Number of reconstructed muons", 10, 0, 10);
130 fhMatchMult =
new TH1D(
"hMatchMult",
"Multiplicity of matching", 10, 0, 10);
131 fhMatchOver =
new TH1D(
"hMatchOver",
"Matching overlaps", 10, 0, 10);
132 fhOverlap =
new TH1D(
"hOverlap",
"Matching overlap flag", 10, 0, 10);
133 fhSimRec =
new TH2D(
"hSimRec",
"Reco muons vs simulated", 4, 0, 4, 4, 0, 4);
284 set<Int_t> doublets[20][nMu], singlets[20][nMu];
285 Int_t nPoints =
fPoints->GetEntriesFast();
286 Double_t xp[7][20][nMu], yp[7][20][nMu];
287 Bool_t lstraws = kFALSE;
289 for (Int_t ip = 0; ip < nPoints; ++ip) {
291 Int_t
id = p->GetTrackID();
292 if (
id > 1)
continue;
299 doublets[ista][id].insert(lay);
300 singlets[ista][id].insert(lay * 2 + side);
301 xp[ista][lay * 2 + side][id] = (p->
GetXIn() + p->
GetXOut()) / 2;
302 yp[ista][lay * 2 + side][id] = (p->
GetYIn() + p->
GetYOut()) / 2;
311 Int_t muons[7][nMu] = {{0}, {0}}, nMuVec = 0, nMuRec = 0;
312 for (Int_t ista = 0; ista <
fNstat; ++ista) {
313 if (doublets[ista][0].size() ==
fNdoubl[ista]) {
317 if (doublets[ista][1].size() ==
fNdoubl[ista]) {
323 if (nMuVec == 0)
return;
325 for (Int_t mu = 0; mu < nMu; ++mu) {
327 for (Int_t ista = 0; ista <
fNstat; ++ista)
328 simOk += muons[ista][mu];
333 Int_t ntracks =
fTracks->GetEntriesFast();
335 Double_t errxS[6] = {0.33, 0.50, 0.2, 0.2, 1, 1};
336 Double_t erryS[6] = {0.33, 0.50, 1.9, 1.9, 1, 1},
340 Double_t errxG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1};
341 Double_t erryG[6] = {0.33, 0.54, 1.0, 1.7, 1, 1};
342 Double_t chi2tot = 0.0, chi2min = 0.0, chi2[10][nMu] = {{0.0}, {0.0}};
343 Int_t iMatch[nMu] = {0};
344 Double_t *errx = errxG, *erry = erryG;
350 for (Int_t mu = 0; mu < nMu; ++mu) {
354 fhSim->Fill(muons[2][mu] + muons[3][mu]);
355 if (muons[2][mu] == 0 || muons[3][mu] == 0)
continue;
356 for (Int_t j = 0; j < 10; ++j)
357 chi2[j][mu] = 999999.0;
358 chi2tot = chi2min = 999999.0;
361 for (Int_t itr = 0; itr < ntracks; ++itr) {
364 if (nvecs < 5)
continue;
365 Double_t c2[10] = {0.0}, c2tot = 0.0;
367 for (Int_t ivec = 0; ivec < nvecs; ++ivec) {
373 Int_t ista = vec->GetUniqueID();
377 if (pluto &&
id != mu)
384 for (Int_t ih = 0; ih < nhits; ++ih) {
389 Int_t plane = lay * 2 + side;
390 if (singlets[ista][mu].find(plane) == singlets[ista][mu].end())
394 + params->GetTx() * (
fZpos[ista][plane] - params->GetZ());
397 + params->GetTy() * (
fZpos[ista][plane] - params->GetZ());
398 Double_t dx =
x - xp[ista][plane][mu];
399 Double_t dy =
y - yp[ista][plane][mu];
400 c2[ista] += dx * dx / errx[ista] / errx[ista];
401 c2[ista] += dy * dy / erry[ista] / erry[ista];
406 if (nm > 4) c2[ista] /= (nm - 4);
411 if (c2tot < chi2tot * 1.2 && track->GetChiSq() < chi2min
412 || c2tot < chi2tot && track->
GetChiSq() < chi2min * 1.2) {
413 for (Int_t j = 0; j < 10; ++j)
420 if (c2[0] < chi2cut && c2[1] < chi2cut && c2[2] < chi2cut
421 && c2[3] < chi2cut && track->
GetChiSq() < chi2cut * 4)
425 cout <<
" Nover " << ntracks <<
" " << nmatch << endl;
426 if (iMatch[mu] < 0)
continue;
428 nMuRec += TMath::Min(1, nmatch);
430 for (Int_t ista = 0; ista <
fNstat; ++ista)
439 for (Int_t ista = 0; ista <
fNstat; ++ista)
440 if (chi2[ista][mu] < chi2cut) ++nmatch;
443 if (iMatch[0] == iMatch[1] && iMatch[0] >= 0)
452 TDirectory* dir0 = (TDirectory*) gROOT->FindObjectAny(
"muchQA");
453 TDirectory* dir = (TDirectory*) dir0->FindObjectAny(
"muchQA1");
454 gDirectory->mkdir(
"muchQA1");
455 gDirectory->cd(
"muchQA1");
456 dir->GetList()->Write();