BmnRoot
Loading...
Searching...
No Matches
CbmStsMatchTracks.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- CbmStsMatchTracks source file -----
3// ----- Created 24/11/05 by V. Friese -----
4// -------------------------------------------------------------------------
5#include "CbmStsMatchTracks.h"
6
7#include "CbmStsHit.h"
8#include "CbmStsTrack.h"
9#include "CbmTrackMatch.h"
10
11#include "FairMCPoint.h"
12#include "FairRootManager.h"
13
14#include "TClonesArray.h"
15
16#include <iostream>
17#include <iomanip>
18#include <map>
19
20using std::cout;
21using std::endl;
22using std::left;
23using std::right;
24using std::setw;
25using std::fixed;
26using std::setprecision;
27using std::map;
28
29// ----- Default constructor -------------------------------------------
31: FairTask("STSMatchTracks"),
32 fTracks(NULL),
33 fPoints(NULL),
34 fPointsSi(nullptr), //AZ-280322
35 fHits(NULL),
36 fMatches(NULL),
37 fTimer(),
38 fMatchMap(),
39 fNEvents(0),
40 fNEventsFailed(0),
41 fTime(0.),
42 fNTrackMatches(0.),
43 fNAllHits(0.),
44 fNTrueHits(0.)
45{}
46
47// ----- Standard constructor -------------------------------------------
49: FairTask("STSMatchTracks", iVerbose),
50 fTracks(NULL),
51 fPoints(NULL),
52 fPointsSi(nullptr), //AZ-280322
53 fHits(NULL),
54 fMatches(NULL),
55 fTimer(),
56 fMatchMap(),
57 fNEvents(0),
58 fNEventsFailed(0),
59 fTime(0.),
60 fNTrackMatches(0.),
61 fNAllHits(0.),
62 fNTrueHits(0.)
63{}
64
65// ----- Constructor with task name ------------------------------------
66CbmStsMatchTracks::CbmStsMatchTracks(const char* name, Int_t iVerbose)
67: FairTask(name, iVerbose),
68 fTracks(NULL),
69 fPoints(NULL),
70 fPointsSi(nullptr), //AZ-280322
71 fHits(NULL),
72 fMatches(NULL),
73 fTimer(),
74 fMatchMap(),
75 fNEvents(0),
76 fNEventsFailed(0),
77 fTime(0.),
78 fNTrackMatches(0.),
79 fNAllHits(0.),
80 fNTrueHits(0.)
81{}
82
83// ----- Destructor ----------------------------------------------------
85// -------------------------------------------------------------------------
86
87
88// ----- Virtual public method Exec ------------------------------------
89void CbmStsMatchTracks::Exec(Option_t* opt) {
90
91 // Timer
92 fTimer.Start();
93 Bool_t warn = kFALSE;
94
95 // Clear output array
96 // fMatches->Clear();
97 fMatches->Delete();
98
99 // Create some pointers and variables
100 CbmStsTrack* track = NULL;
101 CbmStsHit* hit = NULL;
102 FairMCPoint* point = NULL;
103 Int_t nHits = 0;
104 Int_t nMCTracks = 0;
105 Int_t iPoint = 0;
106 Int_t iMCTrack = 0;
107 Int_t nAll = 0;
108 Int_t nTrue = 0;
109 Int_t nWrong = 0;
110 Int_t nFake = 0;
111 Int_t nHitSum = 0;
112 Int_t nTrueSum = 0;
113 Int_t nWrongSum = 0;
114 Int_t nFakeSum = 0;
115 Int_t nMCTrackSum = 0;
116 map<Int_t, Int_t>::iterator it;
117 TClonesArray *points = nullptr; //AZ-289322
118
119 // Loop over StsTracks
120 Int_t nTracks = fTracks->GetEntriesFast();
121 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
122 track = (CbmStsTrack*) fTracks->At(iTrack);
123 if ( ! track) {
124 cout << "-W- CbmStsMatchTracks::Exec: Empty StsTrack at "
125 << iTrack << endl;
126 warn = kTRUE;
127 continue;
128 }
129 nHits = track->GetNStsHits();
130 nAll = nTrue = nWrong = nFake = nMCTracks = 0;
131 fMatchMap.clear();
132 if (fVerbose > 2) cout << endl << "Track " << iTrack << ", Hits "
133 << nHits << endl;
134
135 // Loop over StsHits of track
136 for (Int_t iHit=0; iHit<nHits; iHit++) {
137 hit = (CbmStsHit*) fHits->At(track->GetStsHitIndex(iHit));
138 if ( ! hit ) {
139 cout << "-E- CbmStsMatchTracks::Exec: "
140 << "No StsHit " << iHit << " for track " << iTrack << endl;
141 warn = kTRUE;
142 continue;
143 }
144 iPoint = hit->GetRefIndex();
145 if ( iPoint < 0 ) { // Fake or background hit
146 nFake++;
147 continue;
148 }
149
150 points = fPoints; //AZ-280322
151 if (fPointsSi && hit->GetStationNr() < 5 && hit->GetDx() < 0.01)
152 points = fPointsSi; //AZ-280322
153 //AZ-289322 point = (FairMCPoint*) fPoints->At(iPoint);
154 point = (FairMCPoint*) points->At(iPoint);
155 if ( ! point ) {
156 cout << "-E- CbmStsMatchTracks::Exec: "
157 << "Empty MCPoint " << iPoint << " from MapsHit " << iHit
158 << " (track " << iTrack << ")" << endl;
159 warn = kTRUE;
160 continue;
161 }
162 iMCTrack = point->GetTrackID();
163 if ( fVerbose > 2 ) cout << "Track " << iTrack << ", MAPS hit "
164 << track->GetStsHitIndex(iHit)
165 << ", StsPoint " << iPoint << ", MCTrack "
166 << iMCTrack << endl;
167 fMatchMap[iMCTrack]++;
168 }
169
170
171 // Search for best matching MCTrack
172 iMCTrack = -1;
173 for (it=fMatchMap.begin(); it!=fMatchMap.end(); it++) {
174 if (fVerbose > 2) cout << it->second
175 << " common points wth MCtrack "
176 << it->first << endl;
177 nMCTracks++;
178 nAll += it->second;
179 if ( it->second > nTrue ) {
180 iMCTrack = it->first;
181 nTrue = it->second;
182 }
183 }
184 nWrong = nAll - nTrue;
185 if (fVerbose>1) cout << "-I- CbmStsMatchTracks: StsTrack " << iTrack
186 << ", MCTrack " << iMCTrack << ", true "
187 << nTrue << ", wrong " << nWrong << ", fake "
188 << nFake << ", #MCTracks " << nMCTracks << endl;
189
190 // Create StsTrackMatch
191 new ((*fMatches)[iTrack]) CbmTrackMatch(iMCTrack, nTrue,
192 nWrong, nFake,
193 nMCTracks);
194
195 // Some statistics
196 nHitSum += nHits;
197 nTrueSum += nTrue;
198 nWrongSum += nWrong;
199 nFakeSum += nFake;
200 nMCTrackSum += nMCTracks;
201
202 } // Track loop
203
204 // Event statistics
205 fTimer.Stop();
206 Double_t qTrue = 0.;
207 if ( nHitSum) qTrue = Double_t(nTrueSum) / Double_t(nHitSum) * 100.;
208 if (fVerbose > 1) {
209 Double_t qWrong = Double_t(nWrongSum) / Double_t(nHitSum) * 100.;
210 Double_t qFake = Double_t(nFakeSum) / Double_t(nHitSum) * 100.;
211 Double_t qMC = Double_t(nMCTrackSum) / Double_t(nTracks);
212 cout << endl;
213 cout << "-------------------------------------------------------"
214 << endl;
215 cout << "-I- Sts Track Matching -I-"
216 << endl;
217 cout << "Reconstructed StsTracks : " << nTracks << endl;;
218 cout << "True hit assignments : " << qTrue << " %" << endl;
219 cout << "Wrong hit assignments : " << qWrong << " %" << endl;
220 cout << "Fake hit assignments : " << qFake << " %" << endl;
221 cout << "MCTracks per StsTrack : " << qMC << endl;
222 cout << "--------------------------------------------------------"
223 << endl;
224 }
225 if (fVerbose == 1) {
226 if ( warn) cout << "- ";
227 else cout << "+ ";
228 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8)
229 << fixed << right << fTimer.RealTime() << " s, matches "
230 << nTracks << ", hit quota " << qTrue << " %" << endl;
231 }
232
233 // Run statistics
234 if ( warn ) fNEventsFailed++;
235 else {
236 fNEvents++;
237 fTime += fTimer.RealTime();
238 fNTrackMatches += Double_t(nTracks);
239 fNAllHits += Double_t(nHitSum);
240 fNTrueHits += Double_t(nTrueSum);
241 }
242
243}
244// -------------------------------------------------------------------------
245
246
247
248// ----- Virtual private method Init -----------------------------------
250
251 // Get FairRootManager
252 FairRootManager* ioman = FairRootManager::Instance();
253 if (! ioman) {
254 cout << "-E- CbmStsMatchTracks::Init: "
255 << "RootManager not instantised!" << endl;
256 return kFATAL;
257 }
258
259 // Get StsHit Array
260 fHits = (TClonesArray*) ioman->GetObject("StsHit");
261 if ( ! fHits) {
262 cout << "-W- CbmStsMatchTracks::Init: No StsHit array!"
263 << endl;
264 }
265
266 // Get StsTrack Array
267 fTracks = (TClonesArray*) ioman->GetObject("StsTrack");
268 if ( ! fTracks ) {
269 cout << "-E- CbmStsMatchTracks::Init: No StsTrack array!" << endl;
270 return kERROR;
271 }
272
273 // Get StsPoint array
274 fPoints = (TClonesArray*) ioman->GetObject("StsPoint");
275 if ( ! fPoints ) {
276 //cout << "-E- CbmStsMatchTracks::Init: No StsPoint array!" << endl;
277 return kERROR;
278 }
279 fPointsSi = (TClonesArray*) ioman->GetObject("SiliconPoint"); //AZ-280322
280
281 // Create and register StsTrackMatch array
282 fMatches = new TClonesArray("CbmTrackMatch",100);
283 ioman->Register("StsTrackMatch", "STS", fMatches, kTRUE);
284
285 return kSUCCESS;
286
287}
288// -------------------------------------------------------------------------
289
290
291
292
293// ----- Virtual private method Finish ---------------------------------
295
296 cout << endl;
297 cout << "============================================================"
298 << endl;
299 cout << "===== " << GetName() << ": Run summary " << endl;
300 cout << "===== " << endl;
301 cout << "===== Good events : " << setw(6) << fNEvents << endl;
302 cout << "===== Failed events : " << setw(6) << fNEventsFailed << endl;
303 cout << "===== Average time : " << setprecision(4) << setw(8) << right
304 << fTime / Double_t(fNEvents) << " s" << endl;
305 cout << "===== " << endl;
306 cout << "===== Tracks per event : " << fixed << setprecision(0)
307 << fNTrackMatches / Double_t(fNEvents) << endl;
308 cout << setprecision(2);
309 cout << "===== True hits : " << fixed << setw(6) << right
310 << fNTrueHits / fNAllHits * 100. << " %" << endl;
311 cout << "============================================================"
312 << endl;
313
314}
315// -------------------------------------------------------------------------
virtual Int_t GetStationNr() const
Definition CbmStsHit.h:66
virtual void Exec(Option_t *opt)
virtual InitStatus Init()
Int_t GetNStsHits() const
Definition CbmStsTrack.h:60
Int_t GetStsHitIndex(Int_t iHit) const
Definition CbmStsTrack.h:62