CbmRoot
CbmStsTrackFinderIdeal.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- CbmStsTrackFinderIdeal source file -----
3 // ----- Created 01/02/05 by V. Friese -----
4 // -------------------------------------------------------------------------
5 
7 
8 #include "CbmStsHit.h"
9 #include "CbmStsTrack.h"
10 
11 // CBM includes
12 #include "CbmMCTrack.h"
13 #include "FairMCPoint.h"
14 #include "FairRootManager.h"
15 
16 // ROOT includes
17 #include "TClonesArray.h"
18 
19 // C++ includes
20 #include <iomanip>
21 #include <iostream>
22 #include <map>
23 
24 using std::cout;
25 using std::endl;
26 using std::left;
27 using std::map;
28 using std::setw;
29 
30 
31 // ----- Default constructor -------------------------------------------
33  : CbmStsTrackFinder(), fMCTrackArray(NULL), fMCPointArray(NULL) {
34  fVerbose = 1;
35  fName = "STSTrackFinderIdeal";
36 }
37 // -------------------------------------------------------------------------
38 
39 
40 // ----- Standard constructor ------------------------------------------
42  : CbmStsTrackFinder(), fMCTrackArray(NULL), fMCPointArray(NULL) {
43  fVerbose = verbose;
44  fName = "STSTrackFinderIdeal";
45 }
46 // -------------------------------------------------------------------------
47 
48 
49 // ----- Destructor ----------------------------------------------------
51 // -------------------------------------------------------------------------
52 
53 
54 // ----- Public method Init --------------------------------------------
56 
57  // Get and check FairRootManager
58  FairRootManager* ioman = FairRootManager::Instance();
59  if (!ioman) {
60  cout << "-E- " << fName << "::Init: "
61  << "RootManager not instantised!" << endl;
62  return;
63  }
64 
65  // Get MCTrack array
66  fMCTrackArray = (TClonesArray*) ioman->GetObject("MCTrack");
67  if (!fMCTrackArray) {
68  cout << "-E- " << fName << "::Init: No MCTrack array!" << endl;
69  return;
70  }
71 
72  // Get MCPoint array
73  fMCPointArray = (TClonesArray*) ioman->GetObject("StsPoint");
74  if (!fMCPointArray) {
75  cout << "-E- " << fName << "::Init: No MCPoint array!" << endl;
76  return;
77  }
78 }
79 // -------------------------------------------------------------------------
80 
81 
82 // ----- Public method DoFind ------------------------------------------
84 
85  Bool_t success = kTRUE;
86 
87  // Check pointers
88  if (!fMCTrackArray) {
89  cout << "-E- " << fName << "::DoFind: "
90  << "MCTrack array missing! " << endl;
91  return -1;
92  }
93  if (!fMCPointArray) {
94  cout << "-E- " << fName << "::DoFind: "
95  << "MCPoint array missing! " << endl;
96  return -1;
97  }
98 
99  if (!fStsHits) {
100  cout << "-E- " << fName << "::DoFind: "
101  << "Hit array missing! " << endl;
102  return -1;
103  }
104 
105  if (!fTracks) {
106  cout << "-E- " << fName << "::DoFind: "
107  << "Track array missing! " << endl;
108  return -1;
109  }
110 
111  // Initialise control counters
112  Int_t nNoMCTrack = 0;
113  Int_t nNoTrack = 0;
114  Int_t nNoStsPoint = 0;
115  Int_t nNoStsHit = 0;
116 
117  // Create pointers to StsHit and StsPoint
118  CbmStsHit* pHit = NULL;
119  FairMCPoint* pMCpt = NULL;
120  CbmMCTrack* pMCtr = NULL;
121  CbmStsTrack* pTrck = NULL;
122 
123  // Number of Sts hits
124  Int_t nHits = fStsHits->GetEntriesFast();
125  ;
126 
127  // Declare some variables outside the loops
128  Int_t ptIndex = 0; // MCPoint index
129  Int_t mcTrackIndex = 0; // MCTrack index
130  Int_t trackIndex = 0; // StsTrack index
131 
132 
133  // Create STL map from MCtrack index to number of valid StsHits
134  map<Int_t, Int_t> hitMap;
135 
136  // Loop over Sts hits
137  for (Int_t iHit = 0; iHit < nHits; iHit++) {
138  pHit = (CbmStsHit*) fStsHits->At(iHit);
139  if (!pHit) continue;
140  ptIndex = pHit->GetRefId();
141  if (ptIndex < 0) continue; // fake or background hit
142  pMCpt = (FairMCPoint*) (fMCPointArray->At(ptIndex));
143  if (!pMCpt) continue;
144  mcTrackIndex = pMCpt->GetTrackID();
145  hitMap[mcTrackIndex]++;
146  }
147 
148  // Create STL map from MCTrack index to StsTrack index
149  map<Int_t, Int_t> trackMap;
150 
151  // Create StsTracks for reconstructable MCTracks
152  Int_t nMCacc = 0; // accepted MCTracks
153  Int_t nTracks = 0; // reconstructable MCTracks
154  Int_t nMCTracks = fMCTrackArray->GetEntriesFast();
155  for (Int_t iMCTrack = 0; iMCTrack < nMCTracks; iMCTrack++) {
156  pMCtr = (CbmMCTrack*) fMCTrackArray->At(iMCTrack);
157  if (!pMCtr) continue;
158  if (pMCtr->GetNPoints(ECbmModuleId::kSts) < 3) continue;
159  nMCacc++;
160  if (hitMap[iMCTrack] < 3) continue;
161  new ((*fTracks)[nTracks]) CbmStsTrack();
162  if (fVerbose > 1)
163  cout << "-I- " << fName << ": StsTrack " << nTracks
164  << " created from MCTrack " << iMCTrack << " ("
165  << pMCtr->GetNPoints(ECbmModuleId::kSts) << " StsPoints)" << endl;
166  trackMap[iMCTrack] = nTracks++;
167  }
168 
169  if (fVerbose > 2) cout << "-I- " << GetName() << ": " << endl;
170 
171  // Loop over Sts hits. Get corresponding MCPoint and MCTrack index
172  for (Int_t iHit = 0; iHit < nHits; iHit++) {
173  pHit = (CbmStsHit*) fStsHits->At(iHit);
174  if (!pHit) {
175  cout << "-E- " << fName << "::DoFind: Empty slot "
176  << "in StsHitArray at position " << iHit << endl;
177  nNoStsHit++;
178  success = kFALSE;
179  continue;
180  }
181  ptIndex = pHit->GetRefId();
182  if (ptIndex < 0) continue; // fake or background hit
183  pMCpt = (FairMCPoint*) (fMCPointArray->At(ptIndex));
184  if (!pMCpt) {
185  cout << "-E- " << fName << "::DoFind: No reference "
186  << "MCPoint " << ptIndex << " for hit " << iHit << endl;
187  nNoStsPoint++;
188  success = kFALSE;
189  continue;
190  }
191  mcTrackIndex = pMCpt->GetTrackID();
192  if (mcTrackIndex < 0 || mcTrackIndex > nMCTracks) {
193  cout << "-E- " << fName << "::DoFind: "
194  << "MCTrack index out of range. " << mcTrackIndex << " " << nMCTracks
195  << endl;
196  nNoMCTrack++;
197  success = kFALSE;
198  continue;
199  }
200  if (trackMap.find(mcTrackIndex) == trackMap.end()) continue;
201  trackIndex = trackMap[mcTrackIndex];
202  pTrck = (CbmStsTrack*) fTracks->At(trackIndex);
203  if (!pTrck) {
204  cout << "-E- " << fName << "::DoFind: "
205  << "No StsTrack pointer. " << iHit << " " << ptIndex << " "
206  << mcTrackIndex << " " << trackIndex << endl;
207  nNoTrack++;
208  success = kFALSE;
209  continue;
210  }
211  pTrck->AddHit(iHit, kSTSHIT);
212  if (fVerbose > 2)
213  cout << "Sts Hit " << iHit << " from StsPoint " << ptIndex << " (MCTrack "
214  << mcTrackIndex << ") added to StsTrack " << trackIndex << endl;
215  }
216 
217 
218  if (fVerbose) {
219  cout << endl;
220  cout << "-------------------------------------------------------" << endl;
221  cout << "-I- " << fName << endl;
222  cout << "Sts hits: " << nHits << endl;
223  cout << "MCTracks: total " << nMCTracks << ", accepted " << nMCacc
224  << ", reconstructable: " << nTracks << endl;
225  if (nNoStsHit) cout << "StsHits not found : " << nNoStsHit << endl;
226  if (nNoStsPoint) cout << "StsPoints not found : " << nNoStsPoint << endl;
227  if (nNoMCTrack) cout << "MCTracks not found : " << nNoMCTrack << endl;
228  if (nNoTrack) cout << "StsTracks not found : " << nNoTrack << endl;
229  cout << "-------------------------------------------------------" << endl;
230  } else if (success)
231  cout << "+ ";
232  else
233  cout << "- ";
234  cout << setw(15) << left << fName << ": " << nMCTracks << ", acc. " << nMCacc
235  << ", rec. " << nTracks << endl;
236 
237  return nTracks;
238 }
239 // -------------------------------------------------------------------------
240 
241 
CbmStsTrackFinderIdeal::DoFind
virtual Int_t DoFind()
Definition: CbmStsTrackFinderIdeal.cxx:83
CbmStsTrackFinderIdeal
MC-based track finding in the STS.
Definition: CbmStsTrackFinderIdeal.h:38
CbmStsTrackFinder::fStsHits
TClonesArray * fStsHits
Definition: CbmStsTrackFinder.h:82
CbmHit::GetRefId
Int_t GetRefId() const
Definition: CbmHit.h:72
CbmStsTrackFinderIdeal::fMCPointArray
TClonesArray * fMCPointArray
Definition: CbmStsTrackFinderIdeal.h:75
CbmStsHit
data class for a reconstructed 3-d hit in the STS
Definition: CbmStsHit.h:31
CbmStsTrack.h
Data class for STS tracks.
CbmMCTrack::GetNPoints
Int_t GetNPoints(ECbmModuleId detId) const
Definition: CbmMCTrack.cxx:186
CbmStsTrackFinder
Definition: CbmStsTrackFinder.h:30
CbmStsTrackFinderIdeal.h
nMCTracks
Int_t nMCTracks
Definition: CbmHadronAnalysis.cxx:63
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmStsTrackFinderIdeal::CbmStsTrackFinderIdeal
CbmStsTrackFinderIdeal()
Definition: CbmStsTrackFinderIdeal.cxx:32
CbmStsTrackFinderIdeal::~CbmStsTrackFinderIdeal
virtual ~CbmStsTrackFinderIdeal()
Definition: CbmStsTrackFinderIdeal.cxx:50
CbmMCTrack.h
CbmStsTrackFinder::fVerbose
Int_t fVerbose
Definition: CbmStsTrackFinder.h:85
CbmStsTrackFinder::fTracks
TClonesArray * fTracks
Definition: CbmStsTrackFinder.h:83
CbmStsTrackFinderIdeal::fMCTrackArray
TClonesArray * fMCTrackArray
Definition: CbmStsTrackFinderIdeal.h:74
CbmMCTrack
Definition: CbmMCTrack.h:34
kSTSHIT
@ kSTSHIT
Definition: CbmHit.h:20
CbmStsTrackFinderIdeal::Init
virtual void Init()
Definition: CbmStsTrackFinderIdeal.cxx:55
CbmStsTrack
Definition: CbmStsTrack.h:37
ECbmModuleId::kSts
@ kSts
Silicon Tracking System.
CbmTrack::AddHit
void AddHit(Int_t index, HitType type)
Definition: CbmTrack.cxx:75
CbmStsHit.h
Data class for a reconstructed hit in the STS.