CbmRoot
CbmTrdTrackFinderIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmTrdTrackFinderIdeal source file -----
3 // ----- Created 28/11/05 by V. Friese -----
4 // ----- according to the CbmStsTrackFinderIdeal -----
5 // -------------------------------------------------------------------------
6 // CBM includes
8 
9 #include "CbmTrdHit.h"
10 #include "CbmTrdTrack.h"
11 
12 #include "CbmDigiManager.h"
13 #include "CbmMCTrack.h"
14 #include "CbmMatch.h"
15 #include "FairBaseParSet.h"
16 #include "FairDetector.h"
17 #include "FairMCPoint.h"
18 #include "FairRootManager.h"
19 #include "FairRunAna.h"
20 #include "FairRuntimeDb.h"
21 
22 // ROOT includes
23 #include "TClonesArray.h"
24 #include "TObjArray.h"
25 
26 // C++ includes
27 #include <iostream>
28 #include <map>
29 using std::cout;
30 using std::endl;
31 using std::map;
32 
33 
36  , fMcTracks(NULL)
37  , fTrdPoints(NULL)
38  , fTrdHitMatches(NULL)
39  , fTrdHitProducerType("")
40  , fEventNum(-1) {}
41 
42 
44 
45 
47  FairRootManager* ioman = FairRootManager::Instance();
48  if (NULL == ioman)
49  Fatal("-E- CbmTrdTrackFinderIdeal::Init", "RootManager not instantised!");
50 
51  fMcTracks = (TClonesArray*) ioman->GetObject("MCTrack");
52  if (NULL == fMcTracks)
53  Fatal("-E- CbmTrdTrackFinderIdeal::Init", "No MCTrack array!");
54 
55  fTrdPoints = (TClonesArray*) ioman->GetObject("TrdPoint");
56  if (NULL == fTrdPoints)
57  Fatal("-E- CbmTrdTrackFinderIdeal::Init", "No TrdPoint array!");
58 
59  TClonesArray* digis = (TClonesArray*) ioman->GetObject("TrdDigi");
60  if (NULL == digis) {
61  fTrdHitProducerType = "smearing";
62  } else {
63  fTrdHitProducerType = "digi";
64  fTrdHitMatches = (TClonesArray*) ioman->GetObject("TrdHitMatch");
65  if (NULL == fTrdHitMatches)
66  Fatal("-E- CbmTrdTrackFinderIdeal::Init", "No TrdHitMatch array!");
67  }
68 
69  fEventNum = 1;
70 }
71 
72 Int_t CbmTrdTrackFinderIdeal::DoFind(TClonesArray* trdHits,
73  TClonesArray* trdTracks) {
74  cout << "CbmTrdTrackFinderIdeal, event no. " << fEventNum << " "
75  << fTrdHitProducerType << endl;
76  fEventNum++;
77  if (NULL == trdHits)
78  Fatal("-E- CbmTrdTrackFinderIdeal::DoFind", "No TrdHitArray!");
79  if (NULL == trdTracks)
80  Fatal("-E- CbmTrdTrackFinderIdeal::DoFind", "No TrdTrackArray!");
81 
82  Int_t nofTrdHits = trdHits->GetEntriesFast();
83 
84  // STL map from MCTrack index to CbmTrdTrack
85  map<Int_t, CbmTrdTrack*> mcTrackToTrdTrack;
86  for (Int_t iHit = 0; iHit < nofTrdHits; iHit++) {
87  CbmTrdHit* trdHit = static_cast<CbmTrdHit*>(trdHits->At(iHit));
88  if (NULL == trdHit) continue;
89 
90  int trdPointInd = -1;
91  if (fTrdHitProducerType == "smearing") {
92  trdPointInd = trdHit->GetRefId();
93  } else if (fTrdHitProducerType == "digi") {
94  const CbmMatch* trdHitMatch =
95  static_cast<const CbmMatch*>(fTrdHitMatches->At(iHit));
96  trdPointInd = trdHitMatch->GetMatchedLink().GetIndex();
97  }
98 
99  if (trdPointInd < 0) continue; // fake or background hit
100  FairMCPoint* trdPoint =
101  static_cast<FairMCPoint*>(fTrdPoints->At(trdPointInd));
102  if (NULL == trdPoint) continue;
103 
104  int mcTrackInd = trdPoint->GetTrackID();
105  if (NULL == mcTrackToTrdTrack[mcTrackInd])
106  mcTrackToTrdTrack[mcTrackInd] = new CbmTrdTrack();
107  mcTrackToTrdTrack[mcTrackInd]->AddHit(iHit, kTRDHIT);
108  }
109 
110  int trackCount = 0;
111  for (map<int, CbmTrdTrack*>::iterator it = mcTrackToTrdTrack.begin();
112  it != mcTrackToTrdTrack.end();
113  ++it) {
114  new ((*trdTracks)[trackCount]) CbmTrdTrack(*it->second);
115  trackCount++;
116  }
117 
118  return mcTrackToTrdTrack.size();
119 }
120 
CbmMatch::GetMatchedLink
const CbmLink & GetMatchedLink() const
Definition: CbmMatch.h:37
CbmMatch
Definition: CbmMatch.h:22
CbmTrdTrackFinderIdeal::fTrdPoints
TClonesArray * fTrdPoints
Definition: CbmTrdTrackFinderIdeal.h:59
CbmTrdTrackFinderIdeal::fMcTracks
TClonesArray * fMcTracks
Definition: CbmTrdTrackFinderIdeal.h:58
CbmTrdHit
data class for a reconstructed Energy-4D measurement in the TRD
Definition: CbmTrdHit.h:35
CbmHit::GetRefId
Int_t GetRefId() const
Definition: CbmHit.h:72
CbmTrdTrackFinder
Definition: CbmTrdTrackFinder.h:24
CbmMatch.h
CbmTrdTrackFinderIdeal::fTrdHitMatches
TClonesArray * fTrdHitMatches
Definition: CbmTrdTrackFinderIdeal.h:60
CbmTrdTrackFinderIdeal::CbmTrdTrackFinderIdeal
CbmTrdTrackFinderIdeal()
Definition: CbmTrdTrackFinderIdeal.cxx:34
CbmTrdTrackFinderIdeal::Init
virtual void Init()
Definition: CbmTrdTrackFinderIdeal.cxx:46
CbmTrdTrackFinderIdeal::fTrdHitProducerType
std::string fTrdHitProducerType
Definition: CbmTrdTrackFinderIdeal.h:62
CbmTrdHit.h
Class for hits in TRD detector.
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
kTRDHIT
@ kTRDHIT
Definition: CbmHit.h:25
CbmTrdTrack
Definition: CbmTrdTrack.h:22
CbmMCTrack.h
CbmTrdTrackFinderIdeal::DoFind
virtual Int_t DoFind(TClonesArray *hitArray, TClonesArray *trackArray)
Definition: CbmTrdTrackFinderIdeal.cxx:72
CbmDigiManager.h
CbmTrdTrackFinderIdeal::~CbmTrdTrackFinderIdeal
virtual ~CbmTrdTrackFinderIdeal()
Definition: CbmTrdTrackFinderIdeal.cxx:43
CbmTrdTrackFinderIdeal.h
CbmTrdTrackFinderIdeal::fEventNum
Int_t fEventNum
Definition: CbmTrdTrackFinderIdeal.h:64
CbmTrdTrack.h
CbmTrdTrackFinderIdeal
Definition: CbmTrdTrackFinderIdeal.h:27