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