CbmRoot
LxTBTrdTask.cxx
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 
7 #include "LxTBTrdTask.h"
8 #include "CbmCluster.h"
9 #include "CbmGlobalTrack.h"
10 #include "CbmMCDataManager.h"
11 #include "CbmMCTrack.h"
12 #include "CbmMatch.h"
13 #include "CbmTrdHit.h"
14 #include "CbmTrdPoint.h"
15 #include "CbmTrdTrack.h"
16 #include "FairLogger.h"
17 #include "LxTBTask.h"
18 #include "TClonesArray.h"
19 #include "TGeoBBox.h"
20 #include "TGeoManager.h"
21 #include "TH1F.h"
22 #include "TMath.h"
23 
24 #include <TFile.h>
25 
26 using std::cout;
27 using std::endl;
28 using std::ifstream;
29 using std::ios_base;
30 using std::list;
31 using std::map;
32 using std::ofstream;
33 using std::pair;
34 using std::set;
35 using std::vector;
36 
38 
40  : fFinder(nullptr)
41  , fTrigDistance(200)
42  , recoTracks()
43  , nof_timebins(5)
44  , last_timebin(nof_timebins - 1)
45  , fTrdHits(nullptr)
46  , fTrdClusters(nullptr)
47  , fTrdDigiMatches(nullptr)
48  , fTrdTracks(nullptr)
49  , fGlobalTracks(nullptr)
50 #ifdef LXTB_QA
51  , fTrdMCPoints(nullptr)
52  , fMCTracks()
53  , fTrdPoints()
54  , fNEvents(1000)
55 #endif //LXTB_QA
56 {
57 }
58 
59 static void
60 FindGeoChild(TGeoNode* node, const char* name, list<TGeoNode*>& results) {
61  Int_t nofChildren = node->GetNdaughters();
62 
63  for (Int_t i = 0; i < nofChildren; ++i) {
64  TGeoNode* child = node->GetDaughter(i);
65  TString childName(child->GetName());
66 
67  if (childName.Contains(name, TString::kIgnoreCase))
68  results.push_back(child);
69  }
70 }
71 
73  Double_t localCoords[3] = {0., 0., 0.};
74  Double_t globalCoords[3];
75  TGeoNavigator* pNavigator = gGeoManager->GetCurrentNavigator();
76  gGeoManager->cd("/cave_1");
77  list<TGeoNode*> detectors;
78  FindGeoChild(gGeoManager->GetCurrentNode(), "trd", detectors);
79 
80  for (list<TGeoNode*>::iterator i = detectors.begin(); i != detectors.end();
81  ++i) {
82  TGeoNode* detector = *i;
83  pNavigator->CdDown(detector);
84  list<TGeoNode*> layers;
85  FindGeoChild(detector, "layer", layers);
86  int layerNumber = 0;
87 
88  for (list<TGeoNode*>::iterator j = layers.begin(); j != layers.end(); ++j) {
89  TGeoNode* layer = *j;
90  pNavigator->CdDown(layer);
91  list<TGeoNode*> modules;
92  FindGeoChild(layer, "module", modules);
93 
94  for (list<TGeoNode*>::iterator k = modules.begin(); k != modules.end();
95  ++k) {
96  TGeoNode* module = *k;
97  pNavigator->CdDown(module);
98  list<TGeoNode*> padCoppers;
99  FindGeoChild(module, "padcopper", padCoppers);
100 
101  for (list<TGeoNode*>::iterator l = padCoppers.begin();
102  l != padCoppers.end();
103  ++l) {
104  TGeoNode* padCopper = *l;
105  pNavigator->CdDown(padCopper);
106  TGeoBBox* pBox =
107  static_cast<TGeoBBox*>(padCopper->GetVolume()->GetShape());
108  pBox->ComputeBBox();
109  gGeoManager->LocalToMaster(localCoords, globalCoords);
110  fFinder->stations[layerNumber].z = globalCoords[2];
111 
112  if (fFinder->stations[layerNumber].minY
113  > globalCoords[1] - pBox->GetDY())
114  fFinder->stations[layerNumber].minY =
115  globalCoords[1] - pBox->GetDY();
116 
117  if (fFinder->stations[layerNumber].maxY
118  < globalCoords[1] + pBox->GetDY())
119  fFinder->stations[layerNumber].maxY =
120  globalCoords[1] + pBox->GetDY();
121 
122  if (fFinder->stations[layerNumber].minX
123  > globalCoords[0] - pBox->GetDX())
124  fFinder->stations[layerNumber].minX =
125  globalCoords[0] - pBox->GetDX();
126 
127  if (fFinder->stations[layerNumber].maxX
128  < globalCoords[0] + pBox->GetDX())
129  fFinder->stations[layerNumber].maxX =
130  globalCoords[0] + pBox->GetDX();
131 
132  pNavigator->CdUp();
133  }
134 
135  pNavigator->CdUp();
136  }
137 
138  ++layerNumber;
139  pNavigator->CdUp();
140  }
141 
142  pNavigator->CdUp();
143  }
144 }
145 
146 static bool GetHistoRMS(const char* name, Double_t& retVal) {
147  char fileName[64];
148  sprintf(fileName, "%s.root", name);
149  bool result = false;
150  TFile* curFile = TFile::CurrentFile();
151  TFile* f = new TFile(fileName);
152 
153  if (!f->IsZombie()) {
154  TH1F* h = static_cast<TH1F*>(f->Get(name));
155  retVal = h->GetRMS();
156  result = true;
157  }
158 
159  delete f;
160  TFile::CurrentFile() = curFile;
161  return result;
162 }
163 
164 static TH1F* signalDistanceHisto = 0;
165 
166 InitStatus LxTBTrdFinder::Init() {
168  new TH1F("signalDistanceHisto", "signalDistanceHisto", 200, 0., 800.);
169  speedOfLight =
170  100 * TMath::C(); // Multiply by 100 to express in centimeters.
171  nof_timebins = 5; // Corresponds to event by event mode.
172  pair<int, int> stSpatLimits[] = {{20, 20}, {20, 20}, {20, 20}, {20, 20}};
173  fFinder = new LxTbBinnedFinder(0,
175  nof_timebins,
176  stSpatLimits,
177  20,
178  20,
180  fFinder->fHasTrd = false;
181  HandleGeometry();
182 
183  for (int i = 0; i < 4; ++i) {
190  }
191 
192  for (int i = 1; i < 4; ++i) {
193  char name[64];
194  sprintf(name, "trdDeltaThetaX_%d", i);
195  Double_t deltaThetaX = 0;
196 
197  if (!GetHistoRMS(name, deltaThetaX)) return kFATAL;
198 
199  fFinder->stations[i].deltaThetaX = deltaThetaX;
200  sprintf(name, "trdDeltaThetaY_%d", i);
201  Double_t deltaThetaY = 0;
202 
203  if (!GetHistoRMS(name, deltaThetaY)) return kFATAL;
204 
205  fFinder->stations[i].deltaThetaY = deltaThetaY;
206  scaltype deltaZ = fFinder->stations[i].z - fFinder->stations[i - 1].z;
207  fFinder->stations[i].dispX = deltaThetaX * deltaZ;
208  fFinder->stations[i].dispY = deltaThetaY * deltaZ;
209  }
210 
211  FairRootManager* ioman = FairRootManager::Instance();
212 
213  if (0 == ioman) LOG(fatal) << "No FairRootManager";
214 
215  Int_t nofEventsInFile = ioman->CheckMaxEventNo();
216 
217  if (nofEventsInFile < fNEvents) fNEvents = nofEventsInFile;
218 
219  fTrdHits = static_cast<TClonesArray*>(ioman->GetObject("TrdHit"));
220 
221  fTrdTracks = new TClonesArray("CbmTrdTrack", 100);
222  LOG(info) << "IsOutputBranchPersistent(TrdTrack) is: "
223  << (IsOutputBranchPersistent("TrdTrack") ? "true" : "false");
224  ioman->Register(
225  "TrdTrack", "Trd", fTrdTracks, IsOutputBranchPersistent("TrdTrack"));
226 
227  fGlobalTracks = new TClonesArray("CbmGlobalTrack", 100);
228  LOG(info) << "IsOutputBranchPersistent(GlobalTrack) is: "
229  << (IsOutputBranchPersistent("GlobalTrack") ? "true" : "false");
230  ioman->Register("GlobalTrack",
231  "Global",
233  IsOutputBranchPersistent("GlobalTrack"));
234 
235 #ifdef LXTB_QA
236  CbmMCDataManager* mcManager =
237  static_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager"));
238  fTrdMCPoints = mcManager->InitBranch("TrdPoint");
239  fTrdClusters = static_cast<TClonesArray*>(ioman->GetObject("TrdCluster"));
241  static_cast<TClonesArray*>(ioman->GetObject("TrdDigiMatch"));
242  CbmMCDataArray* mcTracks = mcManager->InitBranch("MCTrack");
243 
244  for (int i = 0; i < fNEvents; ++i) {
245  Int_t evSize = mcTracks->Size(0, i);
246  fMCTracks.push_back(vector<TrackDataHolder>());
247 
248  if (0 >= evSize) continue;
249 
250  vector<TrackDataHolder>& evTracks = fMCTracks.back();
251 
252  for (int j = 0; j < evSize; ++j) {
253  evTracks.push_back(TrackDataHolder());
254  const CbmMCTrack* mcTrack =
255  static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, j));
256  evTracks.back().pdg = mcTrack->GetPdgCode();
257  evTracks.back().z = mcTrack->GetStartZ();
258 
259  if (mcTrack->GetPdgCode() == 11 || mcTrack->GetPdgCode() == -11) {
260  //Double_t m = mcTrack->GetMass(); (VF) Unused
261  Int_t motherId = mcTrack->GetMotherId();
262 
263  if (static_cast<const CbmMCTrack*>(mcTracks->Get(0, i, motherId))
264  ->GetPdgCode()
265  == 443)
266  evTracks.back().isSignal = true;
267  }
268  } // for (int j = 0; j < evSize; ++j)
269  } // for (int i = 0; i < fNEvents; ++i)
270 
271  for (int i = 0; i < fNEvents; ++i) {
272  Int_t evSize = fTrdMCPoints->Size(0, i);
273  fTrdPoints.push_back(vector<PointDataHolder>());
274 
275  if (0 >= evSize) continue;
276 
277  vector<PointDataHolder>& evPoints = fTrdPoints.back();
278 
279  for (int j = 0; j < evSize; ++j) {
280  const CbmTrdPoint* pTrdPt =
281  static_cast<const CbmTrdPoint*>(fTrdMCPoints->Get(0, i, j));
282  //Int_t trackId = pTrdPt->GetTrackID(); (VF) Unused
283  Int_t layerNumber = CbmTrdAddress::GetLayerId(pTrdPt->GetModuleAddress());
284  PointDataHolder trdPt;
285  trdPt.x = (pTrdPt->GetXIn() + pTrdPt->GetXOut()) / 2;
286  trdPt.y = (pTrdPt->GetYIn() + pTrdPt->GetYOut()) / 2;
287  trdPt.z = (pTrdPt->GetZIn() + pTrdPt->GetZOut()) / 2;
288  trdPt.t = 0; //fEventTimes[i] + pTrdPt->GetTime();
289  trdPt.eventId = i;
290  trdPt.trackId = pTrdPt->GetTrackID();
291  trdPt.pointId = j;
292  trdPt.layerNumber = layerNumber;
293  evPoints.push_back(trdPt);
294  fMCTracks[trdPt.eventId][trdPt.trackId].pointInds[trdPt.layerNumber] =
295  trdPt.pointId;
296  }
297  }
298 
299  int eventId = 0;
300 
301  for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin();
302  i != fMCTracks.end();
303  ++i) {
304  vector<TrackDataHolder>& evTracks = *i;
305  list<TrackDataHolder*> eles;
306  list<TrackDataHolder*> poss;
307 
308  for (vector<TrackDataHolder>::iterator j = evTracks.begin();
309  j != evTracks.end();
310  ++j) {
311  TrackDataHolder& track = *j;
312 
313  if (11 == track.pdg && 15 > track.z) {
314  bool use = true;
315 
316  for (int k = 0; k < CUR_NOF_STATIONS; ++k) {
317  if (track.pointInds[k] < 0) {
318  use = false;
319  break;
320  }
321  }
322 
323  if (use) eles.push_back(&track);
324  } else if (-11 == track.pdg && 15 > track.z) {
325  bool use = true;
326 
327  for (int k = 0; k < CUR_NOF_STATIONS; ++k) {
328  if (track.pointInds[k] < 0) {
329  use = false;
330  break;
331  }
332  }
333 
334  if (use) poss.push_back(&track);
335  }
336 
337  if (!track.isSignal) continue;
338 
339  /*if (11 == track.pdg)
340  negTrack = &track;
341  else
342  posTrack = &track;*/
343 
344  for (int k = 0; k < CUR_NOF_STATIONS; ++k) {
345  if (track.pointInds[k] < 0) {
346  track.isSignal = false;
347  break;
348  }
349  }
350 
351  /*if (track.isSignal)
352  {
353  if (11 == track.pdg)
354  negTrack = &track;
355  else
356  posTrack = &track;
357  }*/
358  }
359 
360  /*if (0 != posTrack && 0 != negTrack && posTrack->pointInds[0] >= 0 && negTrack->pointInds[0] >= 0)
361  {
362  const PointDataHolder& posPt = fTrdPoints[eventId][posTrack->pointInds[0]];
363  const PointDataHolder& negPt = fTrdPoints[eventId][negTrack->pointInds[0]];
364  signalDistanceHisto->Fill(sqrt((posPt.x - negPt.x) * (posPt.x - negPt.x) + (posPt.y - negPt.y) * (posPt.y - negPt.y)));
365  }*/
366 
367  for (list<TrackDataHolder*>::const_iterator k = eles.begin();
368  k != eles.end();
369  ++k) {
370  const TrackDataHolder* negTrack = *k;
371 
372  for (list<TrackDataHolder*>::const_iterator l = poss.begin();
373  l != poss.end();
374  ++l) {
375  const TrackDataHolder* posTrack = *l;
376  const PointDataHolder& posPt =
377  fTrdPoints[eventId][posTrack->pointInds[0]];
378  const PointDataHolder& negPt =
379  fTrdPoints[eventId][negTrack->pointInds[0]];
380  signalDistanceHisto->Fill(
381  sqrt((posPt.x - negPt.x) * (posPt.x - negPt.x)
382  + (posPt.y - negPt.y) * (posPt.y - negPt.y)));
383  }
384  }
385 
386  ++eventId;
387  }
388 #endif //LXTB_QA
389 
390  return kSUCCESS; //, kERROR, kFATAL
391 }
392 
393 static Int_t currentEventN = 0;
394 static unsigned long long tsStartTime = 0;
395 
396 static void SpliceTriggerings(list<pair<timetype, timetype>>& out,
398  for (int i = 0; i < in.nofTimebins; ++i)
399  out.splice(out.end(), in.triggerTimeBins[i]);
400 }
401 
402 #ifdef LXTB_QA
403 static list<pair<timetype, timetype>> triggerTimes_trd0_sign0_dist0;
404 static list<pair<timetype, timetype>> triggerTimes_trd0_sign0_dist1;
405 static list<pair<timetype, timetype>> triggerTimes_trd0_sign1_dist0;
406 static list<pair<timetype, timetype>> triggerTimes_trd0_sign1_dist1;
407 static list<pair<timetype, timetype>> triggerTimes_trd1_sign0_dist0;
408 static list<pair<timetype, timetype>> triggerTimes_trd1_sign0_dist1;
409 static list<pair<timetype, timetype>> triggerTimes_trd1_sign1_dist0;
410 static list<pair<timetype, timetype>> triggerTimes_trd1_sign1_dist1;
411 static scaltype gMaxDx = 0;
412 static scaltype gMaxDy = 0;
413 #endif //LXTB_QA
414 
415 void LxTBTrdFinder::Exec(Option_t*) {
416  fFinder->Clear();
418 
419  for (int i = 0; i < fTrdHits->GetEntriesFast(); ++i) {
420  const CbmTrdHit* hit = static_cast<const CbmTrdHit*>(fTrdHits->At(i));
421  Int_t stationNumber = hit->GetPlaneId();
422  scaltype x = hit->GetX();
423  scaltype y = hit->GetY();
424  timetype t = tsStartTime + 50; //hit->GetTime();
425  scaltype dx = hit->GetDx();
426 
427  if (gMaxDx < dx) gMaxDx = dx;
428 
429  scaltype dy = hit->GetDy();
430 
431  if (gMaxDy < dy) gMaxDy = dy;
432 
433  timetype dt = 4; //hit->GetTimeError();
434  LxTbBinnedPoint point(
435  x, dx, y, dy, t, dt, i, CUR_LAST_STATION == stationNumber);
436 #ifdef LXTB_QA
437  point.isTrd = true;
438  point.stationNumber = stationNumber;
439  Int_t clusterId = hit->GetRefId();
440  const CbmCluster* cluster =
441  static_cast<const CbmCluster*>(fTrdClusters->At(clusterId));
442  Int_t nDigis = cluster->GetNofDigis();
443 
444  for (Int_t j = 0; j < nDigis; ++j) {
445  const CbmMatch* digiMatch =
446  static_cast<const CbmMatch*>(fTrdDigiMatches->At(cluster->GetDigi(j)));
447  Int_t nMCs = digiMatch->GetNofLinks();
448 
449  for (Int_t k = 0; k < nMCs; ++k) {
450  const CbmLink& lnk = digiMatch->GetLink(k);
451  Int_t eventId = currentEventN; // : lnk.GetEntry();
452  Int_t pointId = lnk.GetIndex();
453  const FairMCPoint* pMCPt = static_cast<const FairMCPoint*>(
454  fTrdMCPoints->Get(0, eventId, pointId));
455  Int_t trackId = pMCPt->GetTrackID();
456  LxTbBinnedPoint::PointDesc ptDesc = {eventId, pointId, trackId};
457  point.mcRefs.push_back(ptDesc);
458  }
459  } // for (Int_t j = 0; j < nDigis; ++j)
460 
461  scaltype minY = fFinder->stations[stationNumber].minY;
462  scaltype binSizeY = fFinder->stations[stationNumber].binSizeY;
463  int lastYBin = fFinder->stations[stationNumber].lastYBin;
464  scaltype minX = fFinder->stations[stationNumber].minX;
465  scaltype binSizeX = fFinder->stations[stationNumber].binSizeX;
466  int lastXBin = fFinder->stations[stationNumber].lastXBin;
467 
468  int tInd = (t - fFinder->minT) / CUR_TIMEBIN_LENGTH;
469 
470  if (tInd < 0)
471  tInd = 0;
472  else if (tInd > int(last_timebin))
473  tInd = last_timebin;
474 
475  LxTbTYXBin& tyxBin = fFinder->stations[stationNumber].tyxBins[tInd];
476  int yInd = (y - minY) / binSizeY;
477 
478  if (yInd < 0)
479  yInd = 0;
480  else if (yInd > lastYBin)
481  yInd = lastYBin;
482 
483  LxTbYXBin& yxBin = tyxBin.yxBins[yInd];
484  int xInd = (x - minX) / binSizeX;
485 
486  if (xInd < 0)
487  xInd = 0;
488  else if (xInd > lastXBin)
489  xInd = lastXBin;
490 
491  LxTbXBin& xBin = yxBin.xBins[xInd];
492  xBin.points.push_back(point);
493 
494  if (CUR_LAST_STATION == stationNumber) {
495  xBin.use = true;
496  yxBin.use = true;
497  tyxBin.use = true;
498  }
499 #endif //LXTB_QA
500  }
501 
502  fFinder->Reconstruct();
503 
504  //recoTracks.clear();
505  fTrdTracks->Delete();
506  fGlobalTracks->Clear();
507  int trdTrackNo = 0;
508 
509  for (int i = 0; i < fFinder->nofTrackBins; ++i) {
510  list<LxTbBinnedFinder::Chain*>& recoTracksBin = fFinder->recoTracks[i];
511 
512  for (list<LxTbBinnedFinder::Chain*>::const_iterator j =
513  recoTracksBin.begin();
514  j != recoTracksBin.end();
515  ++j) {
516  LxTbBinnedFinder::Chain* chain = *j;
517  recoTracks.push_back(chain);
518 
519  CbmTrdTrack* track = new ((*fTrdTracks)[trdTrackNo]) CbmTrdTrack();
520 
521  for (int k = 0; k < chain->nofPoints; ++k)
522  track->AddHit(chain->points[k]->refId, kTRDHIT);
523 
524  track->SetChiSq(chain->chi2);
525  track->SetNDF(2 * chain->nofPoints - 5);
526 
527  CbmGlobalTrack* globalTrack =
528  new ((*fGlobalTracks)[trdTrackNo]) CbmGlobalTrack();
529  globalTrack->SetTrdTrackIndex(trdTrackNo);
530  ++trdTrackNo;
531  }
532  }
533 
534  //cout << "In the event #: " << currentEventN << " " << recoTracks.size() << " reconstructed" << endl;
535 
552 
553  ++currentEventN;
555 }
556 
557 struct RecoTrackData {
558  Int_t eventId;
559  Int_t trackId;
560 
561  RecoTrackData(Int_t eId, Int_t tId) : eventId(eId), trackId(tId) {}
562 };
563 
564 struct RTDLess {
565  bool operator()(const RecoTrackData& x, const RecoTrackData& y) const {
566  if (x.eventId < y.eventId) return true;
567 
568  return x.trackId < y.trackId;
569  }
570 };
571 
572 static void SaveHisto(TH1* histo) {
573  TFile* curFile = TFile::CurrentFile();
574  TString histoName = histo->GetName();
575  histoName += ".root";
576  TFile fh(histoName.Data(), "RECREATE");
577  histo->Write();
578  fh.Close();
579  delete histo;
580  TFile::CurrentFile() = curFile;
581 }
582 
584  int nofRecoTracks = recoTracks.size();
585  cout << "LxTbBinnedFinder::Reconstruct() the number of found tracks: "
586  << nofRecoTracks << endl;
587 #ifdef LXTB_QA
588  static int nofSignalTracks = 0;
589  static int nofRecoSignalTracks = 0;
590  int eventN = 0;
591 
592  for (vector<vector<TrackDataHolder>>::iterator i = fMCTracks.begin();
593  i != fMCTracks.end();
594  ++i) {
595  vector<TrackDataHolder>& evTracks = *i;
596 
597  for (vector<TrackDataHolder>::iterator j = evTracks.begin();
598  j != evTracks.end();
599  ++j) {
600  TrackDataHolder& track = *j;
601 
602  if (!track.isSignal) continue;
603 
604  ++nofSignalTracks;
605 
606  int nofMatchPoints = 0;
607 
608  for (list<LxTbBinnedFinder::Chain*>::const_iterator k =
609  recoTracks.begin();
610  k != recoTracks.end();
611  ++k) {
612  const LxTbBinnedFinder::Chain* chain = *k;
613 
614  for (int l = 0; l < CUR_NOF_STATIONS; ++l) {
615  bool pointsMatched = false;
616 
617  for (list<LxTbBinnedPoint::PointDesc>::const_iterator m =
618  chain->points[l]->mcRefs.begin();
619  m != chain->points[l]->mcRefs.end();
620  ++m) {
621  if (m->eventId == eventN && m->pointId == track.pointInds[l]) {
622  pointsMatched = true;
623  break;
624  }
625  }
626 
627  if (pointsMatched) ++nofMatchPoints;
628  }
629  }
630 
631  if (nofMatchPoints >= CUR_NOF_STATIONS - 1) {
632  ++nofRecoSignalTracks;
633  continue;
634  }
635  }
636 
637  ++eventN;
638  }
639 
640  double eff =
641  0 == nofSignalTracks ? 100 : 100.0 * nofRecoSignalTracks / nofSignalTracks;
642  cout << "Reconstruction efficiency is: " << eff << "% [ "
643  << nofRecoSignalTracks << " / " << nofSignalTracks << " ]" << endl;
644 
645  int nofRightRecoTracks = 0;
646  map<Int_t, pair<list<LxTbBinnedPoint*>, list<LxTbBinnedPoint*>>>
647  elecPositrons;
648 
649  for (list<LxTbBinnedFinder::Chain*>::const_iterator i = recoTracks.begin();
650  i != recoTracks.end();
651  ++i) {
652  const LxTbBinnedFinder::Chain* chain = *i;
653  map<RecoTrackData, int, RTDLess> nofTracks;
654 
655  for (int j = 0; j < CUR_NOF_STATIONS; ++j) {
656  int stMask = 1 << j;
657 
658  for (list<LxTbBinnedPoint::PointDesc>::const_iterator k =
659  chain->points[j]->mcRefs.begin();
660  k != chain->points[j]->mcRefs.end();
661  ++k) {
662  RecoTrackData st(k->eventId, k->trackId);
663  map<RecoTrackData, int, RTDLess>::iterator nofTIter =
664  nofTracks.find(st);
665 
666  if (nofTIter != nofTracks.end())
667  nofTIter->second |= stMask;
668  else
669  nofTracks[st] = stMask;
670  }
671  }
672 
673  int nofPoints = 0;
674  const RecoTrackData* bestMCTrack = 0;
675 
676  for (map<RecoTrackData, int, RTDLess>::const_iterator j = nofTracks.begin();
677  j != nofTracks.end();
678  ++j) {
679  int nofp = 0;
680 
681  for (int k = 0; k < CUR_NOF_STATIONS; ++k) {
682  if (j->second & (1 << k)) ++nofp;
683  }
684 
685  if (nofp > nofPoints) {
686  nofPoints = nofp;
687  bestMCTrack = &j->first;
688  }
689  }
690 
691  if (nofPoints >= CUR_NOF_STATIONS - 1) {
692  ++nofRightRecoTracks;
693 
694  //if (35 > fMCTracks[bestMCTrack->eventId][bestMCTrack->trackId].z)
695  {
696  if (11 == fMCTracks[bestMCTrack->eventId][bestMCTrack->trackId].pdg)
697  elecPositrons[bestMCTrack->eventId].first.push_back(chain->points[0]);
698  else if (-11
699  == fMCTracks[bestMCTrack->eventId][bestMCTrack->trackId].pdg)
700  elecPositrons[bestMCTrack->eventId].second.push_back(
701  chain->points[0]);
702  }
703  }
704  }
705 
706  eff =
707  0 == recoTracks.size() ? 100 : 100.0 * nofRightRecoTracks / nofRecoTracks;
708  cout << "Non ghosts are: " << eff << "% [ " << nofRightRecoTracks << " / "
709  << nofRecoTracks << " ]" << endl;
710 
711  int nofTriggPairs = 0;
712 
713  for (map<Int_t,
714  pair<list<LxTbBinnedPoint*>, list<LxTbBinnedPoint*>>>::iterator i =
715  elecPositrons.begin();
716  i != elecPositrons.end();
717  ++i) {
718  list<LxTbBinnedPoint*>& evEls = i->second.first;
719  list<LxTbBinnedPoint*>& evPos = i->second.second;
720  bool trigPair = false;
721 
722  for (list<LxTbBinnedPoint*>::const_iterator j = evEls.begin();
723  j != evEls.end();
724  ++j) {
725  const LxTbBinnedPoint* elp = *j;
726  scaltype negX = elp->x;
727  scaltype negY = elp->y;
728 
729  for (list<LxTbBinnedPoint*>::const_iterator k = evPos.begin();
730  k != evPos.end();
731  ++k) {
732  const LxTbBinnedPoint* pop = *k;
733  scaltype posX = pop->x;
734  scaltype posY = pop->y;
735 
736  if (sqrt((posX - negX) * (posX - negX) + (posY - negY) * (posY - negY))
737  > fTrigDistance)
738  trigPair = true;
739  }
740  }
741 
742  if (trigPair) ++nofTriggPairs;
743  }
744 
745  cout << "NOF triggering events: " << nofTriggPairs << endl;
746 
748 #endif //LXTB_QA
749 }
LxTBTrdFinder::fTrdDigiMatches
TClonesArray * fTrdDigiMatches
Definition: LxTBTrdTask.h:76
LxTbBinnedFinder::TriggerTimeArray
Definition: LxTBBinned.h:451
CbmMCTrack::GetMotherId
Int_t GetMotherId() const
Definition: CbmMCTrack.h:71
LxTbBinnedStation::lastYBin
int lastYBin
Definition: LxTBBinned.h:217
LxTbBinnedPoint::refId
Int_t refId
Definition: LxTBBinned.h:87
CbmMatch
Definition: CbmMatch.h:22
CbmMCDataManager.h
CbmTrdPoint::GetYOut
Double_t GetYOut() const
Definition: CbmTrdPoint.h:67
CUR_LAST_STATION
#define CUR_LAST_STATION
Definition: LxTBTask.h:33
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
CbmTrdPoint::GetZIn
Double_t GetZIn() const
Definition: CbmTrdPoint.h:65
LxTBTrdFinder::TrackDataHolder::pointInds
Int_t pointInds[CUR_NOF_STATIONS]
Definition: LxTBTrdTask.h:29
LxTbBinnedFinder::Chain::points
LxTbBinnedPoint ** points
Definition: LxTBBinned.h:414
CbmPixelHit::GetX
Double_t GetX() const
Definition: CbmPixelHit.h:83
CbmMatch::GetLink
const CbmLink & GetLink(Int_t i) const
Definition: CbmMatch.h:35
CbmMatch::GetNofLinks
Int_t GetNofLinks() const
Definition: CbmMatch.h:38
LxTbBinnedStation::lastXBin
int lastXBin
Definition: LxTBBinned.h:216
LxTbTYXBin
Definition: LxTBBinned.h:180
LxTbBinnedPoint::mcRefs
std::list< PointDesc > mcRefs
Definition: LxTBBinned.h:100
LxTBTrdFinder::fGlobalTracks
TClonesArray * fGlobalTracks
Definition: LxTBTrdTask.h:78
scaltype
#define scaltype
Definition: CbmGlobalTrackingDefs.h:17
LxTbBinnedFinder::SetTSBegin
void SetTSBegin(unsigned long long tsLowBound)
Definition: LxTBBinned.h:654
CbmPixelHit::GetY
Double_t GetY() const
Definition: CbmPixelHit.h:84
LxTbBinnedFinder::triggerTimes_trd0_sign1_dist1
TriggerTimeArray triggerTimes_trd0_sign1_dist1
Definition: LxTBBinned.h:542
LxTbBinnedFinder::minT
timetype minT
Definition: LxTBBinned.h:532
sqrt
friend F32vec4 sqrt(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:41
LxTBTrdFinder
Definition: LxTBTrdTask.h:25
CbmPixelHit::GetDx
Double_t GetDx() const
Definition: CbmPixelHit.h:85
CbmMCDataArray::Size
Int_t Size(Int_t fileNumber, Int_t eventNumber)
Definition: CbmMCDataArray.cxx:133
LxTBTrdFinder::HandleGeometry
void HandleGeometry()
Definition: LxTBTrdTask.cxx:72
CbmGlobalTrack::SetTrdTrackIndex
void SetTrdTrackIndex(Int_t iTrd)
Definition: CbmGlobalTrack.h:55
LxTBTrdFinder::PointDataHolder::x
Double_t x
Definition: LxTBTrdTask.h:41
RecoTrackData::eventId
Int_t eventId
Definition: LxTBMLTask.cxx:1663
LxTbBinnedFinder::nofTrackBins
int nofTrackBins
Definition: LxTBBinned.h:535
LxTBTrdFinder::fNEvents
Int_t fNEvents
Definition: LxTBTrdTask.h:83
LxTbTYXBin::yxBins
LxTbYXBin * yxBins
Definition: LxTBBinned.h:181
CbmMCTrack::GetPdgCode
Int_t GetPdgCode() const
Definition: CbmMCTrack.h:70
LxTBTrdFinder::LxTBTrdFinder
LxTBTrdFinder()
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
LxTBTrdFinder::fFinder
LxTbBinnedFinder * fFinder
Definition: LxTBTrdTask.h:69
RecoTrackData
Definition: LxTBMLTask.cxx:1662
LxTbYXBin::use
bool use
Definition: LxTBBinned.h:164
CbmTrdHit
data class for a reconstructed Energy-4D measurement in the TRD
Definition: CbmTrdHit.h:35
triggerTimes_trd1_sign1_dist1
static list< pair< timetype, timetype > > triggerTimes_trd1_sign1_dist1
Definition: LxTBTrdTask.cxx:410
CbmMCDataManager::InitBranch
CbmMCDataArray * InitBranch(const char *name)
Definition: CbmMCDataManager.cxx:106
LxTbBinnedFinder::Reconstruct
void Reconstruct()
Definition: LxTBBinned.h:844
triggerTimes_trd1_sign0_dist0
static list< pair< timetype, timetype > > triggerTimes_trd1_sign0_dist0
Definition: LxTBTrdTask.cxx:407
CUR_TIMEBIN_LENGTH
#define CUR_TIMEBIN_LENGTH
Definition: LxTBTask.h:36
LxTbBinnedFinder::Chain
Definition: LxTBBinned.h:413
LxTbBinnedStation::nofYBins
int nofYBins
Definition: LxTBBinned.h:214
CbmGlobalTrack.h
CbmTrdPoint::GetXOut
Double_t GetXOut() const
Definition: CbmTrdPoint.h:66
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
LxTBTrdFinder::TrackDataHolder::pdg
Int_t pdg
Definition: LxTBTrdTask.h:31
LxTbBinnedFinder::triggerTimes_trd0_sign0_dist1
TriggerTimeArray triggerTimes_trd0_sign0_dist1
Definition: LxTBBinned.h:540
CbmMCDataArray
Access to a MC data branch for time-based analysis.
Definition: CbmMCDataArray.h:35
LxTbBinnedStation::dispY
scaltype dispY
Definition: LxTBBinned.h:228
LxTbXBin::points
std::list< LxTbBinnedPoint > points
Definition: LxTBBinned.h:145
CbmHit::GetRefId
Int_t GetRefId() const
Definition: CbmHit.h:72
LxTbYXBin::xBins
LxTbXBin * xBins
Definition: LxTBBinned.h:162
GetHistoRMS
static bool GetHistoRMS(const char *name, Double_t &retVal)
Definition: LxTBTrdTask.cxx:146
CbmTrack::SetNDF
void SetNDF(Int_t ndf)
Definition: CbmTrack.h:71
CbmMatch.h
LxTbBinnedPoint::isTrd
bool isTrd
Definition: LxTBBinned.h:91
LxTBTask.h
CbmPixelHit::GetDy
Double_t GetDy() const
Definition: CbmPixelHit.h:86
LxTBTrdFinder::Finish
void Finish()
Definition: LxTBTrdTask.cxx:583
LxTBTrdFinder::Init
InitStatus Init()
Definition: LxTBTrdTask.cxx:166
LxTbBinnedStation::deltaThetaX
scaltype deltaThetaX
Definition: LxTBBinned.h:225
LxTBTrdFinder::PointDataHolder::layerNumber
Int_t layerNumber
Definition: LxTBTrdTask.h:48
CbmCluster::GetNofDigis
Int_t GetNofDigis() const
Number of digis in cluster.
Definition: CbmCluster.h:69
LxTbXBin
Definition: LxTBBinned.h:144
LxTbBinnedFinder::fHasTrd
bool fHasTrd
Definition: LxTBBinned.h:536
LxTbBinnedFinder::triggerTimes_trd1_sign1_dist1
TriggerTimeArray triggerTimes_trd1_sign1_dist1
Definition: LxTBBinned.h:546
CbmMCTrack::GetStartZ
Double_t GetStartZ() const
Definition: CbmMCTrack.h:77
triggerTimes_trd0_sign1_dist0
static list< pair< timetype, timetype > > triggerTimes_trd0_sign1_dist0
Definition: LxTBTrdTask.cxx:405
LxTbBinnedFinder::Chain::chi2
scaltype chi2
Definition: LxTBBinned.h:416
LxTbXBin::use
bool use
Definition: LxTBBinned.h:146
SaveHisto
static void SaveHisto(TH1 *histo)
Definition: LxTBTrdTask.cxx:572
RecoTrackData::RecoTrackData
RecoTrackData(Int_t eId, Int_t tId)
Definition: LxTBTrdTask.cxx:561
LxTBTrdFinder::fMCTracks
std::vector< std::vector< TrackDataHolder > > fMCTracks
Definition: LxTBTrdTask.h:81
LxTBTrdFinder::nof_timebins
unsigned int nof_timebins
Definition: LxTBTrdTask.h:72
LxTbBinnedFinder::TriggerTimeArray::triggerTimeBins
std::list< std::pair< timetype, timetype > > * triggerTimeBins
Definition: LxTBBinned.h:516
h
Data class with information on a STS local track.
LxTbBinnedFinder
Definition: LxTBBinned.h:336
RTDLess
Definition: LxTBMLTask.cxx:1669
gMaxDy
static scaltype gMaxDy
Definition: LxTBTrdTask.cxx:412
LxTbBinnedFinder::Chain::nofPoints
int nofPoints
Definition: LxTBBinned.h:415
mcTracks
static vector< vector< QAMCTrack > > mcTracks
Definition: CbmTofHitFinderTBQA.cxx:112
triggerTimes_trd1_sign0_dist1
static list< pair< timetype, timetype > > triggerTimes_trd1_sign0_dist1
Definition: LxTBTrdTask.cxx:408
LxTbBinnedStation::binSizeX
scaltype binSizeX
Definition: LxTBBinned.h:220
LxTbBinnedFinder::triggerTimes_trd1_sign0_dist1
TriggerTimeArray triggerTimes_trd1_sign0_dist1
Definition: LxTBBinned.h:544
CbmMCDataArray::Get
TObject * Get(const CbmLink *lnk)
Definition: CbmMCDataArray.h:47
LxTbBinnedStation::nofXBins
int nofXBins
Definition: LxTBBinned.h:213
LxTbBinnedStation::minX
scaltype minX
Definition: LxTBBinned.h:218
LxTbBinnedFinder::triggerTimes_trd0_sign1_dist0
TriggerTimeArray triggerTimes_trd0_sign1_dist0
Definition: LxTBBinned.h:541
FindGeoChild
static void FindGeoChild(TGeoNode *node, const char *name, list< TGeoNode * > &results)
Definition: LxTBTrdTask.cxx:60
LxTBTrdFinder::fTrigDistance
Double_t fTrigDistance
Definition: LxTBTrdTask.h:70
LxTbBinnedFinder::triggerTimes_trd0_sign0_dist0
TriggerTimeArray triggerTimes_trd0_sign0_dist0
Definition: LxTBBinned.h:539
LxTBTrdFinder::TrackDataHolder::z
Double_t z
Definition: LxTBTrdTask.h:32
LxTbBinnedFinder::TriggerTimeArray::nofTimebins
int nofTimebins
Definition: LxTBBinned.h:513
CbmTrack::SetChiSq
void SetChiSq(Double_t chiSq)
Definition: CbmTrack.h:70
LxTbBinnedStation::binSizeY
scaltype binSizeY
Definition: LxTBBinned.h:223
LxTbBinnedStation::deltaThetaY
scaltype deltaThetaY
Definition: LxTBBinned.h:226
CbmTrdHit.h
Class for hits in TRD detector.
LxTBTrdFinder::fTrdClusters
TClonesArray * fTrdClusters
Definition: LxTBTrdTask.h:75
CUR_NOF_STATIONS
#define CUR_NOF_STATIONS
Definition: LxTBTask.h:32
LxTbBinnedPoint::y
scaltype y
Definition: LxTBBinned.h:81
LxTBTrdFinder::fTrdTracks
TClonesArray * fTrdTracks
Definition: LxTBTrdTask.h:77
LxTbBinnedPoint::PointDesc
Definition: LxTBBinned.h:94
CbmTrdPoint::GetZOut
Double_t GetZOut() const
Definition: CbmTrdPoint.h:68
LxTBTrdFinder::PointDataHolder::eventId
Int_t eventId
Definition: LxTBTrdTask.h:45
LxTbBinnedStation::z
scaltype z
Definition: LxTBBinned.h:212
LxTBTrdFinder::fTrdPoints
std::vector< std::vector< PointDataHolder > > fTrdPoints
Definition: LxTBTrdTask.h:82
kTRDHIT
@ kTRDHIT
Definition: CbmHit.h:25
CbmTrdPoint
Definition: CbmTrdPoint.h:23
CbmMCDataManager
Task class creating and managing CbmMCDataArray objects.
Definition: CbmMCDataManager.h:27
CbmTrdTrack
Definition: CbmTrdTrack.h:22
LxTbBinnedStation::maxY
scaltype maxY
Definition: LxTBBinned.h:222
LxTbBinnedFinder::triggerTimes_trd1_sign1_dist0
TriggerTimeArray triggerTimes_trd1_sign1_dist0
Definition: LxTBBinned.h:545
LxTBTrdFinder::PointDataHolder::pointId
Int_t pointId
Definition: LxTBTrdTask.h:47
CbmGlobalTrack
Definition: CbmGlobalTrack.h:26
LxTbTYXBin::use
bool use
Definition: LxTBBinned.h:183
SpliceTriggerings
static void SpliceTriggerings(list< pair< timetype, timetype >> &out, LxTbBinnedFinder::TriggerTimeArray &in)
Definition: LxTBTrdTask.cxx:396
LxTBTrdTask.h
CbmMCTrack.h
LxTBTrdFinder::fTrdMCPoints
CbmMCDataArray * fTrdMCPoints
Definition: LxTBTrdTask.h:80
CbmTrdPoint::GetXIn
Double_t GetXIn() const
Definition: CbmTrdPoint.h:63
ClassImp
ClassImp(LxTBTrdFinder) LxTBTrdFinder
Definition: LxTBTrdTask.cxx:37
timetype
#define timetype
Definition: CbmGlobalTrackingDefs.h:18
CbmCluster
Base class for cluster objects.
Definition: CbmCluster.h:26
LxTbBinnedStation::maxX
scaltype maxX
Definition: LxTBBinned.h:219
LxTbYXBin
Definition: LxTBBinned.h:161
LxTBTrdFinder::fTrdHits
TClonesArray * fTrdHits
Definition: LxTBTrdTask.h:74
CbmMCTrack
Definition: CbmMCTrack.h:34
speedOfLight
Double_t speedOfLight
LxTBTrdFinder::Exec
void Exec(Option_t *opt)
Definition: LxTBTrdTask.cxx:415
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdPoint::GetModuleAddress
Int_t GetModuleAddress() const
Definition: CbmTrdPoint.h:76
LxTBTrdFinder::PointDataHolder::z
Double_t z
Definition: LxTBTrdTask.h:43
m
__m128 m
Definition: L1/vectors/P4_F32vec4.h:26
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
signalDistanceHisto
static TH1F * signalDistanceHisto
Definition: LxTBTrdTask.cxx:164
CbmTrdPoint.h
LxTbBinnedStation::dispX
scaltype dispX
Definition: LxTBBinned.h:227
LxTbBinnedStation::minY
scaltype minY
Definition: LxTBBinned.h:221
LxTBTrdFinder::PointDataHolder
Definition: LxTBTrdTask.h:40
triggerTimes_trd0_sign0_dist0
static list< pair< timetype, timetype > > triggerTimes_trd0_sign0_dist0
Definition: LxTBTrdTask.cxx:403
LxTBTrdFinder::PointDataHolder::t
Double_t t
Definition: LxTBTrdTask.h:44
LxTBTrdFinder::PointDataHolder::trackId
Int_t trackId
Definition: LxTBTrdTask.h:46
LXTB_QA
#define LXTB_QA
Definition: LxTBDefinitions.h:18
RTDLess::operator()
bool operator()(const RecoTrackData &x, const RecoTrackData &y) const
Definition: LxTBTrdTask.cxx:565
tsStartTime
static unsigned long long tsStartTime
Definition: LxTBTrdTask.cxx:394
CbmCluster.h
Base class for cluster objects.
LxTbBinnedFinder::recoTracks
std::list< Chain * > * recoTracks
Definition: LxTBBinned.h:534
CbmTrdTrack.h
RecoTrackData::trackId
Int_t trackId
Definition: LxTBMLTask.cxx:1664
currentEventN
static Int_t currentEventN
Definition: LxTBTrdTask.cxx:393
LxTbBinnedFinder::Clear
void Clear()
Definition: LxTBBinned.h:628
triggerTimes_trd0_sign1_dist1
static list< pair< timetype, timetype > > triggerTimes_trd0_sign1_dist1
Definition: LxTBTrdTask.cxx:406
LxTBTrdFinder::last_timebin
unsigned int last_timebin
Definition: LxTBTrdTask.h:73
LxTbBinnedPoint
Definition: LxTBBinned.h:78
LxTBTrdFinder::recoTracks
std::list< LxTbBinnedFinder::Chain * > recoTracks
Definition: LxTBTrdTask.h:71
triggerTimes_trd0_sign0_dist1
static list< pair< timetype, timetype > > triggerTimes_trd0_sign0_dist1
Definition: LxTBTrdTask.cxx:404
CbmTrdPoint::GetYIn
Double_t GetYIn() const
Definition: CbmTrdPoint.h:64
CbmCluster::GetDigi
Int_t GetDigi(Int_t index) const
Get digi at position index.
Definition: CbmCluster.h:76
LxTbBinnedFinder::triggerTimes_trd1_sign0_dist0
TriggerTimeArray triggerTimes_trd1_sign0_dist0
Definition: LxTBBinned.h:543
CbmTrack::AddHit
void AddHit(Int_t index, HitType type)
Definition: CbmTrack.cxx:75
LxTbBinnedStation::tyxBins
LxTbTYXBin * tyxBins
Definition: LxTBBinned.h:229
LxTbBinnedPoint::x
scaltype x
Definition: LxTBBinned.h:79
LxTBTrdFinder::PointDataHolder::y
Double_t y
Definition: LxTBTrdTask.h:42
LxTbBinnedPoint::stationNumber
Int_t stationNumber
Definition: LxTBBinned.h:92
LxTBTrdFinder::TrackDataHolder
Definition: LxTBTrdTask.h:28
LxTbBinnedFinder::stations
LxTbBinnedStation * stations
Definition: LxTBBinned.h:529
triggerTimes_trd1_sign1_dist0
static list< pair< timetype, timetype > > triggerTimes_trd1_sign1_dist0
Definition: LxTBTrdTask.cxx:409
LxTBTrdFinder::TrackDataHolder::isSignal
bool isSignal
Definition: LxTBTrdTask.h:30
gMaxDx
static scaltype gMaxDx
Definition: LxTBTrdTask.cxx:411
CbmTrdHit::GetPlaneId
Int_t GetPlaneId() const
Inherited from CbmBaseHit.
Definition: CbmTrdHit.h:73