CbmRoot
CbmEventBuilderQA.cxx
Go to the documentation of this file.
1 
6 // Cbm Headers ----------------------
7 #include "CbmEventBuilderQA.h"
8 #include "CbmMCTrack.h"
9 #include "CbmTrack.h"
10 #include "CbmTrackMatchNew.h"
11 
12 #include "FairRunAna.h"
13 
14 //KF Particle headers
15 #include "CbmKFVertex.h"
16 #include "CbmL1PFFitter.h"
17 #include "KFMCTrack.h"
18 #include "KFParticleMatch.h"
19 #include "KFParticleTopoReconstructor.h"
20 #include "KFTopoPerformance.h"
21 #include "L1Field.h"
22 
23 #include "CbmEvent.h"
24 #include "CbmStsDigi.h"
25 #include "CbmStsHit.h"
26 #include "CbmStsPoint.h"
27 #include "CbmStsTrack.h"
28 
29 #include "CbmStsSensor.h"
30 #include "CbmStsSetup.h"
31 #include "CbmStsStation.h"
32 
33 //ROOT headers
34 #include "TClonesArray.h"
35 #include "TDatabasePDG.h"
36 #include "TDirectory.h"
37 #include "TFile.h"
38 #include "TH1F.h"
39 #include "TH2F.h"
40 #include "TMath.h"
41 #include "TObject.h"
42 
43 //c++ and std headers
44 #include <cmath>
45 #include <iomanip>
46 #include <iostream>
47 
48 #include "CbmGlobalTrack.h"
49 #include "CbmMuchTrack.h"
50 #include "CbmRichRing.h"
51 #include "CbmStsTrack.h"
52 #include "CbmTrack.h"
53 
54 #include "CbmMCDataArray.h"
55 #include "CbmMCDataManager.h"
56 #include "CbmMCEventList.h"
57 #include "CbmMCTrack.h"
58 #include "CbmTrackMatchNew.h"
59 
60 #include "CbmEbEventEfficiencies.h"
61 #include "CbmEbEventMatch.h"
62 #include "CbmEbMCEvent.h"
63 
64 using std::map;
65 using std::vector;
66 
68  TString name, title;
69  int nbins;
70  float xMin, xMax;
71 };
72 
74  Int_t iVerbose,
75  TString outFileName)
76  : FairTask(name, iVerbose)
77  , fPointsInTracks()
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")
90  , fStsDigis(0)
91  , fStsTracks(0)
92  , fMCTracks(0)
93  , fStsHits(0)
94  , fMvdPoints(0)
95  , fStsPoints(0)
96  , fEvents(0)
97  , fStsTrackMatchArray(0)
98  , fStsHitMatch(0)
99  , fEventList(nullptr)
100  , fOutFileName(outFileName)
101  , fOutFile(0)
102  , fHistoDir(0) //, //fNEvents(0),
103  // fPDGtoIndexMap()
104 {
105  TFile* curFile = gFile;
106  TDirectory* curDirectory = gDirectory;
107 
108  if (!(fOutFileName == ""))
109  fOutFile = new TFile(fOutFileName.Data(), "RECREATE");
110  else
111  fOutFile = gFile;
112 
113  fOutFile->cd();
114  fHistoDir = fOutFile->mkdir("4DQA");
115  fHistoDir->cd();
116 
117  gDirectory->mkdir("TimeHisto");
118  gDirectory->cd("TimeHisto");
119  {
120  TH1FParameters timeHisto[fNTimeHistos] = {
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",
129  12100,
130  -100.f,
131  12000.f},
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",
138  120100,
139  -100.f,
140  12000.f},
141  {"NTracksInEventsVsTime2",
142  "NTracksInEventsVsTime2",
143  120100,
144  -100.f,
145  12000.f},
146  {"NTracksInEventsVsTime3",
147  "NTracksInEventsVsTime3",
148  120100,
149  -100.f,
150  12000.f},
151  {"NTracksInEventsVsTime4",
152  "NTracksInEventsVsTime4",
153  120100,
154  -100.f,
155  12000.f},
156  {"NTracksInEventsVsTime5",
157  "NTracksInEventsVsTime5",
158  120100,
159  -100.f,
160  12000.f},
161 
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},
167 
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}};
174  for (int iH = 0; iH < fNTimeHistos; iH++)
175  fTimeHisto[iH] = new TH1F(timeHisto[iH].name.Data(),
176  timeHisto[iH].title.Data(),
177  timeHisto[iH].nbins,
178  timeHisto[iH].xMin,
179  timeHisto[iH].xMax);
180 
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");
185 
186  fTimeHisto[11]->SetLineColor(5);
187  fTimeHisto[11]->SetFillColor(5);
188  fTimeHisto[12]->SetLineColor(2);
189  fTimeHisto[12]->SetFillColor(2);
190  fTimeHisto[13]->SetLineColor(3);
191  fTimeHisto[13]->SetFillColor(3);
192  fTimeHisto[14]->SetLineColor(7);
193  fTimeHisto[14]->SetFillColor(7);
194  fTimeHisto[15]->SetLineColor(6);
195  fTimeHisto[15]->SetFillColor(6);
196 
197  fTimeHisto[16]->SetLineColor(5);
198  fTimeHisto[16]->SetFillColor(5);
199  fTimeHisto[17]->SetLineColor(2);
200  fTimeHisto[17]->SetFillColor(2);
201  fTimeHisto[18]->SetLineColor(3);
202  fTimeHisto[18]->SetFillColor(3);
203  fTimeHisto[19]->SetLineColor(7);
204  fTimeHisto[19]->SetFillColor(7);
205  fTimeHisto[20]->SetLineColor(6);
206  fTimeHisto[20]->SetFillColor(6);
207  }
208  gDirectory->cd(".."); //4DQA
209 
210 
211  gFile = curFile;
212  gDirectory = curDirectory;
213 }
214 
216 
217 
218 struct CbmBuildEventMCTrack {
220  : fMCFileId(-1)
221  , fMCEventId(-1)
222  , fMCTrackId(-1)
223  , fRecoTrackId()
224  , fRecoEventId() {}
225 
226  int fMCFileId;
227  int fMCEventId;
228  int fMCTrackId;
229 
230  vector<int> fRecoTrackId;
231  vector<int> fRecoEventId;
232 };
233 
235  //Get ROOT Manager
236  FairRootManager* ioman = FairRootManager::Instance();
237 
238  if (ioman == 0) {
239  Warning("CbmEventBuilderQA::Init", "RootManager not instantiated!");
240  return kERROR;
241  }
242 
243  CbmMCDataManager* mcManager =
244  (CbmMCDataManager*) ioman->GetObject("MCDataManager");
245  if (mcManager == nullptr) LOG(fatal) << GetName() << ": No CbmMCDataManager!";
246 
247  fMCTracks = (CbmMCDataArray*) mcManager->InitBranch("MCTrack");
248  if (fMCTracks == nullptr) LOG(fatal) << GetName() << ": No MCTrack data!";
249 
250  fEventList = (CbmMCEventList*) ioman->GetObject("MCEventList.");
251  if (fEventList == 0) {
252  Error("CbmEventBuilderQA::Init", "MC Event List not found!");
253  return kERROR;
254  }
255 
256  // open MCTrack array
257  fStsTracks = (TClonesArray*) ioman->GetObject("StsTrack");
258  assert(fStsTracks);
259 
260  fStsTrackMatchArray = (TClonesArray*) ioman->GetObject("StsTrackMatch");
261  if (fStsTrackMatchArray == 0) {
262  Error("CbmEventBuilderQA::Init", "track match array not found!");
263  return kERROR;
264  }
265 
266  fStsHits = (TClonesArray*) ioman->GetObject("StsHit");
267  assert(fStsHits);
268 
269  fStsPoints = mcManager->InitBranch("StsPoint");
270  assert(fStsPoints);
271 
272  fMvdPoints = mcManager->InitBranch("StsPoint");
273  assert(fStsPoints);
274 
275  // --- Get input array (CbmStsDigi)
276  fStsHitMatch = (TClonesArray*) ioman->GetObject("StsHitMatch");
277  assert(fStsHitMatch);
278 
279  // --- Get input array (CbmEvent)
280  fEvents = (TClonesArray*) ioman->GetObject("Event");
281  assert(fEvents);
282 
283  return kSUCCESS;
284 }
285 
286 void CbmEventBuilderQA::Exec(Option_t* /*opt*/) {
287  fPointsInTracks.clear();
288 
289  int nMCEvents = fEventList->GetNofEvents();
290 
291 
292  vector<vector<int>> mcHitMap(nMCEvents);
293  vector<CbmEbMCEvent> fMCEvents(nMCEvents);
294 
295  //Fill Histo for Hits
296 
297  UInt_t nHits = fStsHits->GetEntriesFast();
298 
299 
300  for (UInt_t iHit = 0; iHit < nHits; iHit++) {
301  CbmStsHit* hit = (CbmStsHit*) fStsHits->At(iHit);
302 
303  float hit_time = hit->GetTime();
304 
305  fTimeHisto[3]->Fill(hit_time);
306 
307 
308  CbmMatch* stsHitMatch = (CbmMatch*) fStsHitMatch->At(iHit);
309  if (stsHitMatch->GetNofLinks() == 0) continue;
310  Float_t bestWeight = 0.f;
311  Float_t totalWeight = 0.f;
312  // Int_t mcHitId = -1;
313  int mcEvent = -1;
314  int iMCPoint = -1;
315  CbmLink link;
316 
317  for (int iLink = 0; iLink < stsHitMatch->GetNofLinks(); iLink++) {
318  totalWeight += stsHitMatch->GetLink(iLink).GetWeight();
319  if (stsHitMatch->GetLink(iLink).GetWeight() > bestWeight) {
320  bestWeight = stsHitMatch->GetLink(iLink).GetWeight();
321  iMCPoint = stsHitMatch->GetLink(iLink).GetIndex();
322  link = stsHitMatch->GetLink(iLink);
323  mcEvent = link.GetEntry();
324  }
325  }
326  if (bestWeight / totalWeight < 0.7 || iMCPoint < 0) continue;
327 
328 
329  int iCol = (mcEvent) % 5;
330 
331  if (iCol >= 0) fTimeHisto[16 + iCol]->Fill(hit_time);
332 
333  CbmStsPoint* stsMcPoint = (CbmStsPoint*) fStsPoints->Get(
334  link.GetFile(), link.GetEntry(), link.GetIndex());
335  double mcTime =
336  stsMcPoint->GetTime()
337  + fEventList->GetEventTime(link.GetEntry() + 1, link.GetFile());
338 
339  fTimeHisto[7]->Fill(mcTime);
340 
341  double residual = hit_time - mcTime;
342  double pull = residual / 5.;
343 
344  fTimeHisto[4]->Fill(residual);
345  fTimeHisto[5]->Fill(pull);
346  }
347 
349  UInt_t nTracks = fStsTracks->GetEntriesFast();
350 
351  vector<bool> IsTrackReconstructed(nTracks, 0);
352  vector<bool> IsTrackReconstructable(nTracks, 0);
353 
354  const int iMCFile = 0;
355  if (fStsPoints) {
356  fPointsInTracks.resize(nMCEvents);
357  for (int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
358  const int nMCTracksInEvent = fMCTracks->Size(iMCFile, iMCEvent);
359  fPointsInTracks[iMCEvent].resize(nMCTracksInEvent);
360 
361  unsigned int nStsPoints = fStsPoints->Size(iMCFile, iMCEvent);
362 
363  for (unsigned int iStsPoint = 0; iStsPoint < nStsPoints; iStsPoint++) {
364  CbmStsPoint* point =
365  (CbmStsPoint*) fStsPoints->Get(iMCFile, iMCEvent, iStsPoint);
366  const int iMCTrack = point->GetTrackID();
367  fPointsInTracks[iMCEvent][iMCTrack].push_back(iStsPoint);
368  }
369  }
370  }
371 
372  for (unsigned int iTrack = 0; iTrack < nTracks; iTrack++) {
373 
374  CbmStsTrack* track = (CbmStsTrack*) fStsTracks->At(iTrack);
375 
376  fTimeHisto[0]->Fill(track->GetTime());
377 
378 
379  UInt_t NHits = track->GetNofStsHits();
380 
381  for (UInt_t iHit = 0; iHit < NHits; iHit++) {
382 
383  CbmMatch* stsHitMatch = (CbmMatch*) fStsHitMatch->At(iHit);
384  if (stsHitMatch->GetNofLinks() == 0) continue;
385  Float_t bestWeight = 0.f;
386  Float_t totalWeight = 0.f;
387  // Int_t mcHitId = -1;
388  // int mcEvent = -1;
389  int iMCPoint = -1;
390  CbmLink link;
391  for (int iLink = 0; iLink < stsHitMatch->GetNofLinks(); iLink++) {
392  totalWeight += stsHitMatch->GetLink(iLink).GetWeight();
393  if (stsHitMatch->GetLink(iLink).GetWeight() > bestWeight) {
394  bestWeight = stsHitMatch->GetLink(iLink).GetWeight();
395  iMCPoint = stsHitMatch->GetLink(iLink).GetIndex();
396  link = stsHitMatch->GetLink(iLink);
397  }
398  }
399  if (bestWeight / totalWeight < 0.7 || iMCPoint < 0) continue;
400 
401 
402  // CbmStsPoint* stsMcPoint = (CbmStsPoint*) fStsPoints->Get(link.GetFile(),link.GetEntry(),link.GetIndex());
403  // double mcTime = stsMcPoint->GetTime() + fEventList->GetEventTime(link.GetEntry()+1, link.GetFile());
404 
405  //fTimeHisto[8]->Fill(mcTime);
406  }
407 
408  CbmTrackMatchNew* stsTrackMatch =
409  (CbmTrackMatchNew*) fStsTrackMatchArray->At(iTrack);
410  if (stsTrackMatch->GetNofLinks() == 0) continue;
411  Float_t bestWeight = 0.f;
412  Float_t totalWeight = 0.f;
413  Int_t mcTrackId = -1;
414  int mcEvent = -1;
415  CbmLink link;
416  for (int iLink = 0; iLink < stsTrackMatch->GetNofLinks(); iLink++) {
417  totalWeight += stsTrackMatch->GetLink(iLink).GetWeight();
418  if (stsTrackMatch->GetLink(iLink).GetWeight() > bestWeight) {
419  bestWeight = stsTrackMatch->GetLink(iLink).GetWeight();
420  int iMCTrack = stsTrackMatch->GetLink(iLink).GetIndex();
421  link = stsTrackMatch->GetLink(iLink);
422 
423 
424  mcEvent = link.GetEntry();
425  mcTrackId = iMCTrack;
426  }
427  }
428  if (bestWeight / totalWeight < 0.7 || mcTrackId < 0) continue;
429 
430  IsTrackReconstructed[iTrack] = 1;
431 
432  CbmMCTrack* mcTrack = (CbmMCTrack*) fMCTracks->Get(0, mcEvent, mcTrackId);
433 
434  double mcTime = mcTrack->GetStartT()
435  + fEventList->GetEventTime(mcEvent + 1, link.GetFile());
436  double residual = track->GetTime() - mcTime;
437  double pull = residual / track->GetTimeError();
438  fTimeHisto[1]->Fill(residual);
439  fTimeHisto[2]->Fill(pull);
440  }
441 
442 
443  vector<vector<int>> mcTrackMap(nMCEvents);
444  vector<CbmBuildEventMCTrack> mcTracks;
445 
446  float tEvent = 0.f;
447  // int eventId = 0;
448 
449 
450  for (int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
451  unsigned int nMCTracks = fMCTracks->Size(0, iMCEvent);
452 
453  mcTrackMap[iMCEvent].resize(nMCTracks);
454 
455  fTimeHisto[10]->Fill(
456  fEventList->GetEventTime(iMCEvent + 1, 0)
457  - tEvent); // +fEventList->GetEventTime(iMCEvent+1, 0) );
458  tEvent = fEventList->GetEventTime(iMCEvent + 1, 0);
459 
460  int nReconstructableMCTracks = 0;
461  for (unsigned int iMC = 0; iMC < nMCTracks; iMC++) {
462  CbmMCTrack* mcTrack = (CbmMCTrack*) fMCTracks->Get(0, iMCEvent, iMC);
463 
464  if (CalculateIsReconstructable(0, iMCEvent, iMC))
465  nReconstructableMCTracks++;
466 
467  fTimeHisto[8]->Fill(mcTrack->GetStartT()
468  + fEventList->GetEventTime(iMCEvent + 1, 0));
469 
470  CbmBuildEventMCTrack newMCTrack;
471  newMCTrack.fMCFileId = 0;
472  newMCTrack.fMCEventId = iMCEvent;
473  newMCTrack.fMCTrackId = iMC;
474 
475  mcTrackMap[iMCEvent][iMC] = mcTracks.size();
476  vector<int>& trackIds = fMCEvents[iMCEvent].GetMCTrackIds();
477  trackIds.push_back(mcTracks.size());
478 
479  mcTracks.push_back(newMCTrack);
480 
481  // if(mcTrack->GetMotherId()<eventId)
482  // {
483  // fTimeHisto[10]->Fill( mcTrack->GetStartT() - tEvent);// +fEventList->GetEventTime(iMCEvent+1, 0) );
484  // tEvent = mcTrack->GetStartT();
485  // eventId = mcTrack->GetMotherId();
486  // }
487  }
488  if (nReconstructableMCTracks > 2) fMCEvents[iMCEvent].SetReconstructable(1);
489  }
490 
491  for (int iTrack = 0; iTrack < fStsTrackMatchArray->GetEntriesFast();
492  iTrack++) {
493  CbmTrackMatchNew* stsTrackMatch =
494  (CbmTrackMatchNew*) fStsTrackMatchArray->At(iTrack);
495  if (stsTrackMatch->GetNofLinks() == 0) continue;
496  Float_t bestWeight = 0.f;
497  Float_t totalWeight = 0.f;
498  Int_t mcTrackId = -1;
499  int mcEvent = -1;
500  CbmLink link;
501  for (int iLink = 0; iLink < stsTrackMatch->GetNofLinks(); iLink++) {
502  totalWeight += stsTrackMatch->GetLink(iLink).GetWeight();
503  if (stsTrackMatch->GetLink(iLink).GetWeight() > bestWeight) {
504  bestWeight = stsTrackMatch->GetLink(iLink).GetWeight();
505  int iMCTrack = stsTrackMatch->GetLink(iLink).GetIndex();
506  link = stsTrackMatch->GetLink(iLink);
507  mcEvent = link.GetEntry();
508  mcTrackId = iMCTrack;
509  }
510  }
511  if (bestWeight / totalWeight < 0.7 || mcTrackId < 0) continue;
512 
513  fMCEvents[mcEvent].GetRecoTrackIds().push_back(iTrack);
514  }
515 
516  vector<CbmEbEventMatch> eventMatches;
517 
518  for (int iEvent = 0; iEvent < fEvents->GetEntriesFast(); iEvent++) {
519  CbmEvent* event = (CbmEvent*) fEvents->At(iEvent);
520 
521 
522  vector<int> tracksId;
523  Int_t nEventTracks = event->GetNofData(ECbmDataType::kStsTrack);
524 
525  fTimeHisto[23]->Fill(nEventTracks);
526 
527  CbmEbEventMatch EventMatch;
528  EventMatch.SetNEventTracks(nEventTracks);
529  vector<int> tracks;
530 
531  float tLastTrack = 0;
532  float tFirstTrack = 100000000000000;
533 
534  for (int iTr = 0; iTr < nEventTracks; iTr++) {
535  const int stsTrackIndex = event->GetStsTrackIndex(iTr);
536 
537  tracks.push_back(stsTrackIndex);
538 
539  CbmTrackMatchNew* stsTrackMatch =
540  (CbmTrackMatchNew*) fStsTrackMatchArray->At(stsTrackIndex);
541  if (stsTrackMatch->GetNofLinks() == 0) continue;
542  Float_t bestWeight = 0.f;
543  Float_t totalWeight = 0.f;
544  Int_t mcTrackId = -1;
545  int mcEvent = -1;
546  CbmLink link;
547  for (int iLink = 0; iLink < stsTrackMatch->GetNofLinks(); iLink++) {
548  totalWeight += stsTrackMatch->GetLink(iLink).GetWeight();
549  if (stsTrackMatch->GetLink(iLink).GetWeight() > bestWeight) {
550  bestWeight = stsTrackMatch->GetLink(iLink).GetWeight();
551  int iMCTrack = stsTrackMatch->GetLink(iLink).GetIndex();
552  link = stsTrackMatch->GetLink(iLink);
553 
554 
555  mcEvent = link.GetEntry();
556  mcTrackId = iMCTrack;
557  }
558  }
559  if (bestWeight / totalWeight < 0.7 || mcTrackId < 0) continue;
560 
561  CbmMCTrack* mcTrack = (CbmMCTrack*) fMCTracks->Get(0, mcEvent, mcTrackId);
562 
563  CbmStsTrack* track = (CbmStsTrack*) fStsTracks->At(stsTrackIndex);
564 
565  if ((track->GetTime()) > tLastTrack) tLastTrack = (track->GetTime());
566  if ((track->GetTime()) < tFirstTrack) tFirstTrack = (track->GetTime());
567 
568  double mcTime = mcTrack->GetStartT()
569  + fEventList->GetEventTime(mcEvent + 1, link.GetFile());
570 
571  fTimeHisto[24]->Fill(fabs(track->GetTime() - mcTime)
572  / track->GetTimeError());
573 
574  if (fMCEvents[mcEvent].IsReconstructable()) EventMatch.AddTrack(mcEvent);
575 
576  for (int iTr1 = iTr + 1; iTr1 < nEventTracks; iTr1++) {
577  if (iTr1 == iTr) continue;
578  const int stsTrackIndex1 = event->GetStsTrackIndex(iTr1);
579  CbmStsTrack* track1 = (CbmStsTrack*) fStsTracks->At(stsTrackIndex1);
580 
581  fTimeHisto[25]->Fill(
582  fabs(track->GetTime() - track1->GetTime())
583  / sqrt(track->GetTimeError() + track1->GetTimeError()));
584  }
585 
586  for (int iEvent1 = 0; iEvent1 < fEvents->GetEntriesFast(); iEvent1++) {
587 
588  if (iEvent == iEvent1) continue;
589  CbmEvent* event1 = (CbmEvent*) fEvents->At(iEvent1);
590 
591  Int_t nTracks1 = event1->GetNofData(ECbmDataType::kStsTrack);
592  for (int iTr1 = 0; iTr1 < nTracks1; iTr1++) {
593  const int stsTrackIndex1 = event1->GetStsTrackIndex(iTr1);
594  CbmStsTrack* track1 = (CbmStsTrack*) fStsTracks->At(stsTrackIndex1);
595 
596  if (fabs(track->GetTime() - track1->GetTime()) > 8.5) continue;
597 
598  fTimeHisto[26]->Fill(
599  fabs(track->GetTime() - track1->GetTime())
600  / sqrt(track->GetTimeError() + track1->GetTimeError()));
601  }
602  }
603  }
604 
605  EventMatch.SetTracks(tracks);
606  fTimeHisto[22]->Fill(tLastTrack - tFirstTrack);
607  eventMatches.push_back(EventMatch);
608 
609  for (std::map<int, int>::iterator it = EventMatch.GetMCEvents().begin();
610  it != EventMatch.GetMCEvents().end();
611  ++it) {
612 
613  fMCEvents[it->first].AddRecoEvent(iEvent);
614  }
615  }
616 
617 
618  vector<SortEvents> Ev;
619 
620  for (int iMCEvent = 0; iMCEvent < nMCEvents; iMCEvent++) {
621  int nMcPoints = fStsPoints->Size(0, iMCEvent);
622  for (int i = 0; i < nMcPoints; i++) {
623  CbmStsPoint* stsMcPoint = (CbmStsPoint*) fStsPoints->Get(0, iMCEvent, i);
624  double mcTime =
625  stsMcPoint->GetTime() + fEventList->GetEventTime(iMCEvent + 1, 0);
626  fTimeHisto[9]->Fill(mcTime);
627  }
628  }
629 
630 
631  int nEvents = fEvents->GetEntriesFast();
632 
633  for (int k = 0; k < nEvents; k++) {
634  SortEvents Event1;
635 
636  CbmEvent* event = (CbmEvent*) fEvents->At(k);
637 
638  Event1.Event = event;
639  const int stsTrackIndex = event->GetStsTrackIndex(0);
640  CbmStsTrack* track = (CbmStsTrack*) fStsTracks->At(stsTrackIndex);
641  Event1.track = *track;
642  Ev.push_back(Event1);
643  }
644 
645 
646  std::sort(Ev.begin(), Ev.end(), CompareTrackTime);
647 
648  for (int k = 0; k < nEvents; k++) {
649  CbmEvent* event = Ev[k].Event; //(CbmEvent*) fEvents->At(k);
650 
651  int iCol = k % 5;
652  for (int i = 0; i < event->GetNofData(ECbmDataType::kStsTrack); i++) {
653  const int stsTrackIndex = event->GetStsTrackIndex(i);
654  CbmStsTrack* track = (CbmStsTrack*) fStsTracks->At(stsTrackIndex);
655 
656  fTimeHisto[6]->Fill(track->GetTime());
657 
658 
659  fTimeHisto[11 + iCol]->Fill(track->GetTime());
660 
661  UInt_t NHits = track->GetNofStsHits();
662 
663  for (UInt_t iHit = 0; iHit < NHits; iHit++) {
664  CbmStsHit* hit = (CbmStsHit*) fStsHits->At(track->GetStsHitIndex(iHit));
665  fTimeHisto[7]->Fill(hit->GetTime());
666  }
667  }
668  }
669 
670 
671  CbmEbEventEfficiencies fEventEfficiency;
672 
673  CbmEbEventEfficiencies eventEfficiency; // efficiencies for current event
674  for (unsigned int iEvent = 0; iEvent < eventMatches.size(); iEvent++)
675  eventEfficiency.AddGhost(eventMatches[iEvent].IsGhost());
676 
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(); // for length calculations
682  bool reco = 0;
683  if (recoEvents.size() == 1) reco = 1;
684  // number of cloned events
685  int nclones = 0;
686  if (fMCEvents[iMCEvent].NClones() > 0) nclones = 1;
687  eventEfficiency.Inc(reco, nclones, "reconstructable");
688  }
689  // if( fMCEvents[iMCEvent].IsReconstructed() )
690  if (fMCEvents[iMCEvent].GetRecoTrackIds().size() > 2) {
691  const vector<int>& recoEvents =
692  fMCEvents[iMCEvent].GetRecoEvents(); // for length calculations
693  bool reco = 0;
694  if (recoEvents.size() == 1) reco = 1;
695  // number of cloned events
696  int nclones = 0;
697  if (fMCEvents[iMCEvent].NClones() > 0) nclones = 1;
698  eventEfficiency.Inc(reco, nclones, "reconstructed");
699  }
700  } // for mcTracks
701  eventEfficiency.IncNEvents();
702  fEventEfficiency += eventEfficiency;
703  eventEfficiency.CalcEff();
704  fEventEfficiency.CalcEff();
705 
706  std::cout << "Event reconstruction efficiency" << std::endl;
707  fEventEfficiency.PrintEff();
708  cout << endl;
709 
710 
711  // int iDMcTrack;
712  for (unsigned int iM = 0; iM < eventMatches.size(); iM++) {
713  // cout<<eventMatches[iM].NMCEvents()<<" Nevents"<<endl;
714 
715  fTimeHisto[21]->Fill(eventMatches[iM].NMCEvents());
716  }
717 }
718 
720  const int iMCEvent,
721  const int iMCTrack) {
722 
723  CbmMCTrack* mcTrack =
724  (CbmMCTrack*) fMCTracks->Get(iMCFile, iMCEvent, iMCTrack);
725 
726  bool f = 1;
727 
728  // reject very slow tracks from analysis
729  f &= (mcTrack->GetP() > 0.1);
730  // detected at least in 4 stations
731  // f &= (nMCContStations >= 4);
732 
733  int maxNStaMC = 0; // max number of mcPoints on station
734  int maxNSensorMC = 0; // max number of mcPoints with same z
735  int nMCStations = 0;
736 
737  maxNStaMC = 0;
738  maxNSensorMC = 0;
739  nMCStations = 0;
740  int lastSta = -1;
741  float lastz = -1;
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();
746  iH++) {
747 
748  int iStsPoint = fPointsInTracks[iMCEvent][iMCTrack][iH];
749  CbmStsPoint* point =
750  (CbmStsPoint*) fStsPoints->Get(iMCFile, iMCEvent, iStsPoint);
751 
752  int currentStation = -1;
753  for (int iStation = 0; iStation < CbmStsSetup::Instance()->GetNofStations();
754  iStation++) {
755  CbmStsStation* station = CbmStsSetup::Instance()->GetStation(iStation);
756  const float zStation = station->GetZ();
757 
758  if (fabs(point->GetZ() - zStation) < 2.5) {
759  currentStation = iStation;
760  break;
761  }
762  }
763  if (currentStation < 0) continue;
764 
765  if (currentStation == lastSta)
766  cur_maxNStaMC++;
767  else { // new station
768  if (cur_maxNStaMC > maxNStaMC) maxNStaMC = cur_maxNStaMC;
769  cur_maxNStaMC = 1;
770  lastSta = currentStation;
771  nMCStations++;
772  }
773 
774  if (point->GetZ() == lastz) // TODO: works incorrect because of different z
775  cur_maxNSensorMC++;
776  else { // new z
777  if (cur_maxNSensorMC > maxNSensorMC) maxNSensorMC = cur_maxNSensorMC;
778  cur_maxNSensorMC = 1;
779  lastz = point->GetZ();
780  }
781 
782  int ista = currentStation;
783  if (ista - istaold == 1)
784  ncont++;
785  else if (ista - istaold > 1) {
786  if (nMCContStations < ncont) nMCContStations = ncont;
787  ncont = 1;
788  }
789  if (ista <= istaold) continue; // backward direction
790  istaold = ista;
791  };
792 
793  if (nMCContStations < ncont) nMCContStations = ncont;
794 
795  if (cur_maxNStaMC > maxNStaMC) maxNStaMC = cur_maxNStaMC;
796  if (cur_maxNSensorMC > maxNSensorMC) maxNSensorMC = cur_maxNSensorMC;
797  // cout << pdg << " " << p << " " << Points.size() << " > " << maxNStaMC << " " << maxNSensorMC << endl;
798 
799 
800  // maximul 4 layers for a station.
801  // f &= (maxNStaHits <= 4);
802  f &= (maxNStaMC <= 4);
803 
804  bool isReconstructableTrack = f & (nMCContStations >= 4); // L1-MC
805 
806  return (isReconstructableTrack);
807 };
808 
810  TDirectory* curr = gDirectory;
811  TFile* currentFile = gFile;
812  // Open output file and write histograms
813 
814  fOutFile->cd();
816  if (!(fOutFileName == "")) {
817  fOutFile->Close();
818  fOutFile->Delete();
819  }
820  gFile = currentFile;
821  gDirectory = curr;
822 }
823 
825 
826  if (!obj->IsFolder())
827  obj->Write();
828  else {
829  TDirectory* cur = gDirectory;
830  TFile* currentFile = gFile;
831 
832  TDirectory* sub = cur->GetDirectory(obj->GetName());
833  sub->cd();
834  TList* listSub = (static_cast<TDirectory*>(obj))->GetList();
835  TIter it(listSub);
836  while (TObject* obj1 = it())
837  WriteHistosCurFile(obj1);
838  cur->cd();
839  gFile = currentFile;
840  gDirectory = cur;
841  }
842 }
843 
844 
TH1FParameters::nbins
int nbins
Definition: CbmEventBuilderQA.cxx:69
CbmStsStation::GetZ
Double_t GetZ() const
Definition: CbmStsStation.h:127
CbmMCDataManager::GetObject
CbmMCDataObject * GetObject(const char *name)
Definition: CbmMCDataManager.cxx:137
CbmMatch
Definition: CbmMatch.h:22
CbmMCDataManager.h
KFParticleMatch.h
CbmEventBuilderQA::fStsTracks
TClonesArray * fStsTracks
Input array (class CbmStsDigi)
Definition: CbmEventBuilderQA.h:104
CbmEventBuilderQA::SortEvents::track
CbmStsTrack track
Definition: CbmEventBuilderQA.h:69
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
TH1FParameters::xMax
float xMax
Definition: CbmEventBuilderQA.cxx:70
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
CbmMatch::GetNofLinks
Int_t GetNofLinks() const
Definition: CbmMatch.h:38
CbmBuildEventMCTrack::fMCFileId
int fMCFileId
Definition: CbmBuildEventsFromTracksIdeal.cxx:176
CbmStsSetup.h
L1Field.h
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
CbmMCDataArray::Size
Int_t Size(Int_t fileNumber, Int_t eventNumber)
Definition: CbmMCDataArray.cxx:133
CbmEbEventEfficiencies::IncNEvents
void IncNEvents()
Definition: CbmEbEventEfficiencies.h:71
ClassImp
ClassImp(CbmEventBuilderQA)
CbmEventBuilderQA::fEventList
CbmMCEventList * fEventList
Definition: CbmEventBuilderQA.h:113
CbmEventBuilderQA::fHistoDir
TDirectory * fHistoDir
Definition: CbmEventBuilderQA.h:118
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmMCDataManager::InitBranch
CbmMCDataArray * InitBranch(const char *name)
Definition: CbmMCDataManager.cxx:106
CbmStsSetup::Instance
static CbmStsSetup * Instance()
Definition: CbmStsSetup.cxx:293
CbmStsStation.h
CbmMCDataArray.h
CbmGlobalTrack.h
CbmEventBuilderQA::fStsPoints
CbmMCDataArray * fStsPoints
Input array (class CbmStsDigi)
Definition: CbmEventBuilderQA.h:108
CbmEventBuilderQA::CalculateIsReconstructable
bool CalculateIsReconstructable(const int iMCFile, const int iMCEvent, const int iMCTrack)
Definition: CbmEventBuilderQA.cxx:719
CbmMCDataArray
Access to a MC data branch for time-based analysis.
Definition: CbmMCDataArray.h:35
CbmBuildEventMCTrack::fMCEventId
int fMCEventId
Definition: CbmBuildEventsFromTracksIdeal.cxx:177
CbmEbEventEfficiencies::Inc
void Inc(bool isReco, int _nclones, string name)
Definition: CbmEbEventEfficiencies.h:64
CbmEventBuilderQA::fMvdPoints
CbmMCDataArray * fMvdPoints
Input array (class CbmStsDigi)
Definition: CbmEventBuilderQA.h:107
CbmRichRing.h
CbmStsPoint
Definition: CbmStsPoint.h:27
CbmEventBuilderQA.h
CbmEventBuilderQA::fTimeHisto
TH1F * fTimeHisto[fNTimeHistos]
Definition: CbmEventBuilderQA.h:100
CbmEventBuilderQA::fStsTrackMatchArray
TClonesArray * fStsTrackMatchArray
Definition: CbmEventBuilderQA.h:110
CbmStsSetup::GetNofStations
Int_t GetNofStations() const
Definition: CbmStsSetup.h:90
CbmBuildEventMCTrack::fRecoEventId
vector< int > fRecoEventId
Definition: CbmBuildEventsFromTracksIdeal.cxx:181
CbmEventBuilderQA::CbmEventBuilderQA
CbmEventBuilderQA(const char *name="CbmEventBuilderQA", Int_t iVerbose=0, TString outFileName="CbmEventBuilderQA.root")
Definition: CbmEventBuilderQA.cxx:73
CbmEventBuilderQA::fStsHits
TClonesArray * fStsHits
Input array (class CbmStsDigi)
Definition: CbmEventBuilderQA.h:106
CbmBuildEventMCTrack::fMCTrackId
int fMCTrackId
Definition: CbmBuildEventsFromTracksIdeal.cxx:178
CbmEventBuilderQA
Definition: CbmEventBuilderQA.h:29
CbmBuildEventMCTrack
Definition: CbmBuildEventsFromTracksIdeal.cxx:168
CbmEventBuilderQA::SortEvents
Definition: CbmEventBuilderQA.h:67
CbmEvent.h
CbmStsHit
data class for a reconstructed 3-d hit in the STS
Definition: CbmStsHit.h:31
CbmEbEventMatch::SetTracks
void SetTracks(vector< int > tracks)
Definition: CbmEbEventMatch.h:26
ECbmDataType::kStsTrack
@ kStsTrack
CbmMCEventList::GetNofEvents
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
Definition: CbmMCEventList.h:90
CbmStsDigi.h
CbmStsTrack.h
Data class for STS tracks.
CbmEventBuilderQA::fOutFileName
TString fOutFileName
Definition: CbmEventBuilderQA.h:116
TH1FParameters
Definition: CbmEventBuilderQA.cxx:67
CbmMuchTrack.h
CbmEventBuilderQA::fMCTracks
CbmMCDataArray * fMCTracks
Input array (class CbmStsDigi)
Definition: CbmEventBuilderQA.h:105
tracks
TClonesArray * tracks
Definition: Analyze_matching.h:17
mcTracks
static vector< vector< QAMCTrack > > mcTracks
Definition: CbmTofHitFinderTBQA.cxx:112
CbmTrack.h
CbmEvent::GetStsTrackIndex
Int_t GetStsTrackIndex(Int_t iTrack)
Definition: CbmEvent.h:117
CbmMCDataArray::Get
TObject * Get(const CbmLink *lnk)
Definition: CbmMCDataArray.h:47
CbmHit::GetTime
Double_t GetTime() const
Definition: CbmHit.h:75
CbmTrackMatchNew.h
CbmMCEventList::GetEventTime
Double_t GetEventTime(UInt_t event, UInt_t file)
Event start time.
Definition: CbmMCEventList.cxx:86
CbmL1PFFitter.h
CbmEbEventEfficiencies::CalcEff
void CalcEff()
Definition: CbmEbEventEfficiencies.h:52
nMCTracks
Int_t nMCTracks
Definition: CbmHadronAnalysis.cxx:63
CbmEbEventMatch::SetNEventTracks
void SetNEventTracks(int ntracks)
Definition: CbmEbEventMatch.h:25
CbmEventBuilderQA::Finish
virtual void Finish()
Definition: CbmEventBuilderQA.cxx:809
CbmMCEventList
Container class for MC events with number, file and start time.
Definition: CbmMCEventList.h:38
CbmEventBuilderQA::~CbmEventBuilderQA
~CbmEventBuilderQA()
Definition: CbmEventBuilderQA.cxx:215
CbmEbEventEfficiencies::AddGhost
void AddGhost(int i)
Definition: CbmEbEventEfficiencies.h:73
CbmEbEventEfficiencies.h
CbmEventBuilderQA::fNTimeHistos
static const int fNTimeHistos
Definition: CbmEventBuilderQA.h:99
CbmEbEventEfficiencies::PrintEff
void PrintEff()
Definition: CbmEbEventEfficiencies.h:75
CbmMCDataManager
Task class creating and managing CbmMCDataArray objects.
Definition: CbmMCDataManager.h:27
CbmEvent::GetNofData
Int_t GetNofData() const
Definition: CbmEvent.h:90
CbmEbMCEvent.h
CbmStsSetup::GetStation
CbmStsStation * GetStation(Int_t stationId) const
Definition: CbmStsSetup.h:97
CbmMCEventList.h
CbmEventBuilderQA::Exec
virtual void Exec(Option_t *opt)
Definition: CbmEventBuilderQA.cxx:286
CbmEbEventMatch::AddTrack
void AddTrack(int mcEventId)
Definition: CbmEbEventMatch.h:24
CbmEventBuilderQA::SortEvents::Event
CbmEvent * Event
Definition: CbmEventBuilderQA.h:68
CbmEbEventEfficiencies
Definition: CbmEbEventEfficiencies.h:13
CbmEventBuilderQA::CompareTrackTime
static bool CompareTrackTime(const SortEvents &a, const SortEvents &b)
Definition: CbmEventBuilderQA.h:74
CbmEventBuilderQA::fPointsInTracks
std::vector< std::vector< std::vector< int > > > fPointsInTracks
Definition: CbmEventBuilderQA.h:64
CbmEventBuilderQA::Init
virtual InitStatus Init()
Definition: CbmEventBuilderQA.cxx:234
CbmStsPoint.h
CbmMCTrack.h
CbmBuildEventMCTrack::fRecoTrackId
vector< int > fRecoTrackId
Definition: CbmBuildEventsFromTracksIdeal.cxx:180
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmEbEventMatch::GetMCEvents
map< int, int > & GetMCEvents()
Definition: CbmEbEventMatch.h:32
fabs
friend F32vec4 fabs(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:60
CbmBuildEventMCTrack::CbmBuildEventMCTrack
CbmBuildEventMCTrack()
Definition: CbmEventBuilderQA.cxx:219
CbmEbEventMatch
Definition: CbmEbEventMatch.h:16
CbmEventBuilderQA::WriteHistosCurFile
void WriteHistosCurFile(TObject *obj)
Definition: CbmEventBuilderQA.cxx:824
TH1FParameters::xMin
float xMin
Definition: CbmEventBuilderQA.cxx:70
CbmEvent
Class characterising one event by a collection of links (indices) to data objects,...
Definition: CbmEvent.h:30
CbmTrack::GetTime
Double_t GetTime() const
Definition: CbmTrack.h:64
CbmTrackMatchNew
Definition: CbmTrackMatchNew.h:19
CbmEventBuilderQA::fEvents
TClonesArray * fEvents
Output array (class CbmEvent)
Definition: CbmEventBuilderQA.h:109
CbmStsTrack::GetStsHitIndex
Int_t GetStsHitIndex(Int_t iHit) const
Definition: CbmStsTrack.h:98
CbmEventBuilderQA::fOutFile
TFile * fOutFile
Definition: CbmEventBuilderQA.h:117
CbmStsTrack
Definition: CbmStsTrack.h:37
CbmEbEventMatch.h
CbmTrack::GetTimeError
Double_t GetTimeError() const
Definition: CbmTrack.h:65
CbmEventBuilderQA::fStsHitMatch
TClonesArray * fStsHitMatch
Definition: CbmEventBuilderQA.h:111
CbmKFVertex.h
TH1FParameters::name
TString name
Definition: CbmEventBuilderQA.cxx:68
CbmMCTrack::GetP
Double_t GetP() const
Definition: CbmMCTrack.h:100
TH1FParameters::title
TString title
Definition: CbmEventBuilderQA.cxx:68
CbmStsStation
Class representing a station of the StsSystem.
Definition: CbmStsStation.h:29
CbmStsHit.h
Data class for a reconstructed hit in the STS.
CbmStsSensor.h
CbmMCTrack::GetStartT
Double_t GetStartT() const
Definition: CbmMCTrack.h:78
CbmStsTrack::GetNofStsHits
Int_t GetNofStsHits() const
Definition: CbmStsTrack.h:90