12 #include "FairRunAna.h"
17 #include "KFMCTrack.h"
19 #include "KFParticleTopoReconstructor.h"
20 #include "KFTopoPerformance.h"
34 #include "TClonesArray.h"
35 #include "TDatabasePDG.h"
36 #include "TDirectory.h"
76 : FairTask(name, iVerbose)
78 , fStsTrackBranchName(
"StsTrack")
79 , fGlobalTrackBranchName(
"GlobalTrack")
80 , fRichBranchName(
"RichRing")
81 , fTrdBranchName(
"TrdTrack")
82 , fTofBranchName(
"TofHit")
83 , fMuchTrackBranchName(
"MuchTrack")
84 , fMCTracksBranchName(
"MCTrack")
85 , fStsTrackMatchBranchName(
"StsTrackMatch")
86 , fRichRingMatchBranchName(
"RichRingMatch")
87 , fTrdTrackMatchBranchName(
"TrdTrackMatch")
88 , fTofHitMatchBranchName(
"TofHitMatch")
89 , fMuchTrackMatchBranchName(
"MuchTrackMatch")
97 , fStsTrackMatchArray(0)
100 , fOutFileName(outFileName)
105 TFile* curFile = gFile;
106 TDirectory* curDirectory = gDirectory;
117 gDirectory->mkdir(
"TimeHisto");
118 gDirectory->cd(
"TimeHisto");
121 {
"NTracksVsTime",
"NTracksVsTime", 12100, -100.f, 12000.f},
122 {
"TracksTimeResidual",
"TracksTimeResidual", 300, -30.f, 30.f},
123 {
"TracksTimePull",
"TracksTimePull", 100, -10.f, 10.f},
124 {
"NHitsVsTime",
"NHitsVsTime", 12100, -100.f, 12000.f},
125 {
"HitsTimeResidual",
"HitsTimeResidual", 300, -30.f, 30.f},
126 {
"HitsTimePull",
"HitsTimePull", 100, -10.f, 10.f},
127 {
"NTracksInEventsVsTime",
128 "NTracksInEventsVsTime",
132 {
"NHitsInEventsVsTime",
"NHitsInEventsVsTime", 12100, -100.f, 12000.f},
133 {
"NTracksVsMCTime",
"NTracksVsMCTime", 12100, -100.f, 12000.f},
134 {
"NHitsVsMCTime",
"NHitsVsMCTime", 12100, -100.f, 12000.f},
135 {
"dtDistribution",
"dtDistribution", 100, 0.f, 50.f},
136 {
"NTracksInEventsVsTime1",
137 "NTracksInEventsVsTime1",
141 {
"NTracksInEventsVsTime2",
142 "NTracksInEventsVsTime2",
146 {
"NTracksInEventsVsTime3",
147 "NTracksInEventsVsTime3",
151 {
"NTracksInEventsVsTime4",
152 "NTracksInEventsVsTime4",
156 {
"NTracksInEventsVsTime5",
157 "NTracksInEventsVsTime5",
162 {
"NHitsInEventsVsTime1",
"NHitsInEventsVsTime1", 12100, -100.f, 12000.f},
163 {
"NHitsInEventsVsTime2",
"NHitsInEventsVsTime2", 12100, -100.f, 12000.f},
164 {
"NHitsInEventsVsTime3",
"NHitsInEventsVsTime3", 12100, -100.f, 12000.f},
165 {
"NHitsInEventsVsTime4",
"NHitsInEventsVsTime4", 12100, -100.f, 12000.f},
166 {
"NHitsInEventsVsTime5",
"NHitsInEventsVsTime5", 12100, -100.f, 12000.f},
168 {
"Number of merged events",
"Number of merged events", 6, -0.5f, 5.5f},
169 {
"Event length",
"Event length", 100, 0.f, 50.f},
170 {
"NTracksPerEvent",
"NTracksPerEvent", 250, 0.f, 250.f},
171 {
"TrackRecoTimePull",
"TrackRecoTimePull", 100, -10.f, 10.f},
172 {
"TrackTimeEvent",
"TrackTimeEvent", 100, -10.f, 10.f},
173 {
"TrackTimeNoEvent",
"TrackTimeNoEvent", 100, -10.f, 10.f}};
175 fTimeHisto[iH] =
new TH1F(timeHisto[iH].name.Data(),
176 timeHisto[iH].
title.Data(),
181 fTimeHisto[0]->GetXaxis()->SetTitle(
"Time, ns");
182 fTimeHisto[0]->GetYaxis()->SetTitle(
"Number of tracks");
183 fTimeHisto[16]->GetYaxis()->SetTitle(
"Number of Events");
184 fTimeHisto[16]->GetXaxis()->SetTitle(
"Number of MCEvents in Event");
208 gDirectory->cd(
"..");
212 gDirectory = curDirectory;
236 FairRootManager* ioman = FairRootManager::Instance();
239 Warning(
"CbmEventBuilderQA::Init",
"RootManager not instantiated!");
245 if (mcManager ==
nullptr) LOG(fatal) << GetName() <<
": No CbmMCDataManager!";
248 if (
fMCTracks ==
nullptr) LOG(fatal) << GetName() <<
": No MCTrack data!";
252 Error(
"CbmEventBuilderQA::Init",
"MC Event List not found!");
257 fStsTracks = (TClonesArray*) ioman->GetObject(
"StsTrack");
262 Error(
"CbmEventBuilderQA::Init",
"track match array not found!");
266 fStsHits = (TClonesArray*) ioman->GetObject(
"StsHit");
276 fStsHitMatch = (TClonesArray*) ioman->GetObject(
"StsHitMatch");
280 fEvents = (TClonesArray*) ioman->GetObject(
"Event");
292 vector<vector<int>> mcHitMap(nMCEvents);
293 vector<CbmEbMCEvent> fMCEvents(nMCEvents);
297 UInt_t nHits =
fStsHits->GetEntriesFast();
300 for (UInt_t iHit = 0; iHit < nHits; iHit++) {
303 float hit_time = hit->
GetTime();
310 Float_t bestWeight = 0.f;
311 Float_t totalWeight = 0.f;
317 for (
int iLink = 0; iLink < stsHitMatch->
GetNofLinks(); iLink++) {
322 link = stsHitMatch->
GetLink(iLink);
326 if (bestWeight / totalWeight < 0.7 || iMCPoint < 0)
continue;
329 int iCol = (mcEvent) % 5;
331 if (iCol >= 0)
fTimeHisto[16 + iCol]->Fill(hit_time);
336 stsMcPoint->GetTime()
341 double residual = hit_time - mcTime;
342 double pull = residual / 5.;
349 UInt_t nTracks =
fStsTracks->GetEntriesFast();
351 vector<bool> IsTrackReconstructed(nTracks, 0);
352 vector<bool> IsTrackReconstructable(nTracks, 0);
354 const int iMCFile = 0;
357 for (
int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
358 const int nMCTracksInEvent =
fMCTracks->
Size(iMCFile, iMCEvent);
363 for (
unsigned int iStsPoint = 0; iStsPoint < nStsPoints; iStsPoint++) {
366 const int iMCTrack = point->GetTrackID();
372 for (
unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
381 for (UInt_t iHit = 0; iHit < NHits; iHit++) {
385 Float_t bestWeight = 0.f;
386 Float_t totalWeight = 0.f;
391 for (
int iLink = 0; iLink < stsHitMatch->
GetNofLinks(); iLink++) {
396 link = stsHitMatch->
GetLink(iLink);
399 if (bestWeight / totalWeight < 0.7 || iMCPoint < 0)
continue;
411 Float_t bestWeight = 0.f;
412 Float_t totalWeight = 0.f;
413 Int_t mcTrackId = -1;
416 for (
int iLink = 0; iLink < stsTrackMatch->
GetNofLinks(); iLink++) {
421 link = stsTrackMatch->
GetLink(iLink);
425 mcTrackId = iMCTrack;
428 if (bestWeight / totalWeight < 0.7 || mcTrackId < 0)
continue;
430 IsTrackReconstructed[iTrack] = 1;
436 double residual = track->
GetTime() - mcTime;
443 vector<vector<int>> mcTrackMap(nMCEvents);
444 vector<CbmBuildEventMCTrack>
mcTracks;
450 for (
int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
460 int nReconstructableMCTracks = 0;
461 for (
unsigned int iMC = 0; iMC <
nMCTracks; iMC++) {
465 nReconstructableMCTracks++;
475 mcTrackMap[iMCEvent][iMC] =
mcTracks.size();
476 vector<int>& trackIds = fMCEvents[iMCEvent].GetMCTrackIds();
477 trackIds.push_back(
mcTracks.size());
488 if (nReconstructableMCTracks > 2) fMCEvents[iMCEvent].SetReconstructable(1);
496 Float_t bestWeight = 0.f;
497 Float_t totalWeight = 0.f;
498 Int_t mcTrackId = -1;
501 for (
int iLink = 0; iLink < stsTrackMatch->
GetNofLinks(); iLink++) {
506 link = stsTrackMatch->
GetLink(iLink);
508 mcTrackId = iMCTrack;
511 if (bestWeight / totalWeight < 0.7 || mcTrackId < 0)
continue;
513 fMCEvents[mcEvent].GetRecoTrackIds().push_back(iTrack);
516 vector<CbmEbEventMatch> eventMatches;
518 for (
int iEvent = 0; iEvent <
fEvents->GetEntriesFast(); iEvent++) {
522 vector<int> tracksId;
531 float tLastTrack = 0;
532 float tFirstTrack = 100000000000000;
534 for (
int iTr = 0; iTr < nEventTracks; iTr++) {
535 const int stsTrackIndex =
event->GetStsTrackIndex(iTr);
537 tracks.push_back(stsTrackIndex);
542 Float_t bestWeight = 0.f;
543 Float_t totalWeight = 0.f;
544 Int_t mcTrackId = -1;
547 for (
int iLink = 0; iLink < stsTrackMatch->
GetNofLinks(); iLink++) {
552 link = stsTrackMatch->
GetLink(iLink);
556 mcTrackId = iMCTrack;
559 if (bestWeight / totalWeight < 0.7 || mcTrackId < 0)
continue;
565 if ((track->
GetTime()) > tLastTrack) tLastTrack = (track->
GetTime());
566 if ((track->
GetTime()) < tFirstTrack) tFirstTrack = (track->
GetTime());
574 if (fMCEvents[mcEvent].IsReconstructable()) EventMatch.
AddTrack(mcEvent);
576 for (
int iTr1 = iTr + 1; iTr1 < nEventTracks; iTr1++) {
577 if (iTr1 == iTr)
continue;
578 const int stsTrackIndex1 =
event->GetStsTrackIndex(iTr1);
586 for (
int iEvent1 = 0; iEvent1 <
fEvents->GetEntriesFast(); iEvent1++) {
588 if (iEvent == iEvent1)
continue;
592 for (
int iTr1 = 0; iTr1 < nTracks1; iTr1++) {
606 fTimeHisto[22]->Fill(tLastTrack - tFirstTrack);
607 eventMatches.push_back(EventMatch);
609 for (std::map<int, int>::iterator it = EventMatch.
GetMCEvents().begin();
613 fMCEvents[it->first].AddRecoEvent(iEvent);
618 vector<SortEvents> Ev;
620 for (
int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
622 for (
int i = 0;
i < nMcPoints;
i++) {
631 int nEvents =
fEvents->GetEntriesFast();
633 for (
int k = 0; k < nEvents; k++) {
638 Event1.
Event = event;
641 Event1.
track = *track;
642 Ev.push_back(Event1);
648 for (
int k = 0; k < nEvents; k++) {
663 for (UInt_t iHit = 0; iHit < NHits; iHit++) {
674 for (
unsigned int iEvent = 0; iEvent < eventMatches.size(); iEvent++)
675 eventEfficiency.
AddGhost(eventMatches[iEvent].IsGhost());
677 for (
unsigned int iMCEvent = 0; iMCEvent < fMCEvents.size(); iMCEvent++) {
678 if (fMCEvents[iMCEvent].IsReconstructable()
679 && fMCEvents[iMCEvent].NMCTracks() > 1) {
680 const vector<int>& recoEvents =
681 fMCEvents[iMCEvent].GetRecoEvents();
683 if (recoEvents.size() == 1) reco = 1;
686 if (fMCEvents[iMCEvent].NClones() > 0) nclones = 1;
687 eventEfficiency.
Inc(reco, nclones,
"reconstructable");
690 if (fMCEvents[iMCEvent].GetRecoTrackIds().size() > 2) {
691 const vector<int>& recoEvents =
692 fMCEvents[iMCEvent].GetRecoEvents();
694 if (recoEvents.size() == 1) reco = 1;
697 if (fMCEvents[iMCEvent].NClones() > 0) nclones = 1;
698 eventEfficiency.
Inc(reco, nclones,
"reconstructed");
702 fEventEfficiency += eventEfficiency;
706 std::cout <<
"Event reconstruction efficiency" << std::endl;
712 for (
unsigned int iM = 0; iM < eventMatches.size(); iM++) {
715 fTimeHisto[21]->Fill(eventMatches[iM].NMCEvents());
721 const int iMCTrack) {
729 f &= (mcTrack->
GetP() > 0.1);
734 int maxNSensorMC = 0;
742 int nMCContStations = 0;
743 int istaold = -1, ncont = 0;
744 int cur_maxNStaMC = 0, cur_maxNSensorMC = 0;
745 for (
unsigned int iH = 0; iH <
fPointsInTracks[iMCEvent][iMCTrack].size();
752 int currentStation = -1;
756 const float zStation = station->
GetZ();
758 if (
fabs(point->GetZ() - zStation) < 2.5) {
759 currentStation = iStation;
763 if (currentStation < 0)
continue;
765 if (currentStation == lastSta)
768 if (cur_maxNStaMC > maxNStaMC) maxNStaMC = cur_maxNStaMC;
770 lastSta = currentStation;
774 if (point->GetZ() == lastz)
777 if (cur_maxNSensorMC > maxNSensorMC) maxNSensorMC = cur_maxNSensorMC;
778 cur_maxNSensorMC = 1;
779 lastz = point->GetZ();
782 int ista = currentStation;
783 if (ista - istaold == 1)
785 else if (ista - istaold > 1) {
786 if (nMCContStations < ncont) nMCContStations = ncont;
789 if (ista <= istaold)
continue;
793 if (nMCContStations < ncont) nMCContStations = ncont;
795 if (cur_maxNStaMC > maxNStaMC) maxNStaMC = cur_maxNStaMC;
796 if (cur_maxNSensorMC > maxNSensorMC) maxNSensorMC = cur_maxNSensorMC;
802 f &= (maxNStaMC <= 4);
804 bool isReconstructableTrack =
f & (nMCContStations >= 4);
806 return (isReconstructableTrack);
810 TDirectory* curr = gDirectory;
811 TFile* currentFile = gFile;
826 if (!obj->IsFolder())
829 TDirectory* cur = gDirectory;
830 TFile* currentFile = gFile;
832 TDirectory* sub = cur->GetDirectory(obj->GetName());
834 TList* listSub = (
static_cast<TDirectory*
>(obj))->GetList();
836 while (TObject* obj1 = it())