BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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#include "FairMCPoint.h"
11#include "FairRootManager.h"
12#include "TClonesArray.h"
13
14#include <iomanip>
15#include <iostream>
16#include <map>
17
18using std::cout;
19using std::endl;
20using std::fixed;
21using std::left;
22using std::map;
23using std::right;
24using std::setprecision;
25using std::setw;
26
27// ----- Default constructor -------------------------------------------
29 : FairTask("STSMatchTracks")
30 , fTracks(NULL)
31 , fPoints(NULL)
32 , fPointsSi(nullptr)
33 , // AZ-280322
34 fHits(NULL)
35 , fMatches(NULL)
36 , fTimer()
37 , fMatchMap()
38 , fNEvents(0)
40 , fTime(0.)
41 , fNTrackMatches(0.)
42 , fNAllHits(0.)
43 , fNTrueHits(0.)
44{}
45
46// ----- Standard constructor -------------------------------------------
48 : FairTask("STSMatchTracks", iVerbose)
49 , fTracks(NULL)
50 , fPoints(NULL)
51 , fPointsSi(nullptr)
52 , // AZ-280322
53 fHits(NULL)
54 , fMatches(NULL)
55 , fTimer()
56 , fMatchMap()
57 , fNEvents(0)
59 , fTime(0.)
60 , fNTrackMatches(0.)
61 , fNAllHits(0.)
62 , fNTrueHits(0.)
63{}
64
65// ----- Constructor with task name ------------------------------------
67 : FairTask(name, iVerbose)
68 , fTracks(NULL)
69 , fPoints(NULL)
70 , fPointsSi(nullptr)
71 , // AZ-280322
72 fHits(NULL)
73 , fMatches(NULL)
74 , fTimer()
75 , fMatchMap()
76 , fNEvents(0)
78 , fTime(0.)
79 , fNTrackMatches(0.)
80 , fNAllHits(0.)
81 , fNTrueHits(0.)
82{}
83
84// ----- Destructor ----------------------------------------------------
86// -------------------------------------------------------------------------
87
88// ----- Virtual public method Exec ------------------------------------
90{
91
92 // Timer
93 fTimer.Start();
94 Bool_t warn = kFALSE;
95
96 // Clear output array
97 // fMatches->Clear();
98 fMatches->Delete();
99
100 // Create some pointers and variables
101 CbmStsTrack* track = NULL;
102 CbmStsHit* hit = NULL;
103 FairMCPoint* point = NULL;
104 Int_t nHits = 0;
105 Int_t nMCTracks = 0;
106 Int_t iPoint = 0;
107 Int_t iMCTrack = 0;
108 Int_t nAll = 0;
109 Int_t nTrue = 0;
110 Int_t nWrong = 0;
111 Int_t nFake = 0;
112 Int_t nHitSum = 0;
113 Int_t nTrueSum = 0;
114 Int_t nWrongSum = 0;
115 Int_t nFakeSum = 0;
116 Int_t nMCTrackSum = 0;
117 map<Int_t, Int_t>::iterator it;
118 TClonesArray* points = nullptr; // AZ-289322
119
120 // Loop over StsTracks
121 Int_t nTracks = fTracks->GetEntriesFast();
122 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
123 track = (CbmStsTrack*)fTracks->At(iTrack);
124 if (!track) {
125 cout << "-W- CbmStsMatchTracks::Exec: Empty StsTrack at " << 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)
133 cout << endl << "Track " << iTrack << ", Hits " << 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 << " (track " << iTrack << ")" << endl;
158 warn = kTRUE;
159 continue;
160 }
161 iMCTrack = point->GetTrackID();
162 if (fVerbose > 2)
163 cout << "Track " << iTrack << ", MAPS hit " << track->GetStsHitIndex(iHit) << ", StsPoint " << iPoint
164 << ", MCTrack " << iMCTrack << endl;
165 fMatchMap[iMCTrack]++;
166 }
167
168 // Search for best matching MCTrack
169 iMCTrack = -1;
170 for (it = fMatchMap.begin(); it != fMatchMap.end(); it++) {
171 if (fVerbose > 2)
172 cout << it->second << " common points wth MCtrack " << it->first << endl;
173 nMCTracks++;
174 nAll += it->second;
175 if (it->second > nTrue) {
176 iMCTrack = it->first;
177 nTrue = it->second;
178 }
179 }
180 nWrong = nAll - nTrue;
181 if (fVerbose > 1)
182 cout << "-I- CbmStsMatchTracks: StsTrack " << iTrack << ", MCTrack " << iMCTrack << ", true " << nTrue
183 << ", wrong " << nWrong << ", fake " << nFake << ", #MCTracks " << nMCTracks << endl;
184
185 // Create StsTrackMatch
186 new ((*fMatches)[iTrack]) CbmTrackMatch(iMCTrack, nTrue, nWrong, nFake, nMCTracks);
187
188 // Some statistics
189 nHitSum += nHits;
190 nTrueSum += nTrue;
191 nWrongSum += nWrong;
192 nFakeSum += nFake;
193 nMCTrackSum += nMCTracks;
194
195 } // Track loop
196
197 // Event statistics
198 fTimer.Stop();
199 Double_t qTrue = 0.;
200 if (nHitSum)
201 qTrue = Double_t(nTrueSum) / Double_t(nHitSum) * 100.;
202 if (fVerbose > 1) {
203 Double_t qWrong = Double_t(nWrongSum) / Double_t(nHitSum) * 100.;
204 Double_t qFake = Double_t(nFakeSum) / Double_t(nHitSum) * 100.;
205 Double_t qMC = Double_t(nMCTrackSum) / Double_t(nTracks);
206 cout << endl;
207 cout << "-------------------------------------------------------" << endl;
208 cout << "-I- Sts Track Matching -I-" << endl;
209 cout << "Reconstructed StsTracks : " << nTracks << endl;
210 ;
211 cout << "True hit assignments : " << qTrue << " %" << endl;
212 cout << "Wrong hit assignments : " << qWrong << " %" << endl;
213 cout << "Fake hit assignments : " << qFake << " %" << endl;
214 cout << "MCTracks per StsTrack : " << qMC << endl;
215 cout << "--------------------------------------------------------" << endl;
216 }
217 if (fVerbose == 1) {
218 if (warn)
219 cout << "- ";
220 else
221 cout << "+ ";
222 cout << setw(15) << left << fName << ": " << setprecision(4) << setw(8) << fixed << right << fTimer.RealTime()
223 << " s, matches " << nTracks << ", hit quota " << qTrue << " %" << endl;
224 }
225
226 // Run statistics
227 if (warn)
229 else {
230 fNEvents++;
231 fTime += fTimer.RealTime();
232 fNTrackMatches += Double_t(nTracks);
233 fNAllHits += Double_t(nHitSum);
234 fNTrueHits += Double_t(nTrueSum);
235 }
236}
237// -------------------------------------------------------------------------
238
239// ----- Virtual private method Init -----------------------------------
241{
242
243 // Get FairRootManager
244 FairRootManager* ioman = FairRootManager::Instance();
245 if (!ioman) {
246 cout << "-E- CbmStsMatchTracks::Init: "
247 << "RootManager not instantised!" << endl;
248 return kFATAL;
249 }
250
251 // Get StsHit Array
252 fHits = (TClonesArray*)ioman->GetObject("StsHit");
253 if (!fHits) {
254 cout << "-W- CbmStsMatchTracks::Init: No StsHit array!" << endl;
255 }
256
257 // Get StsTrack Array
258 fTracks = (TClonesArray*)ioman->GetObject("StsTrack");
259 if (!fTracks) {
260 cout << "-E- CbmStsMatchTracks::Init: No StsTrack array!" << endl;
261 return kERROR;
262 }
263
264 // Get StsPoint array
265 fPoints = (TClonesArray*)ioman->GetObject("StsPoint");
266 if (!fPoints) {
267 // cout << "-E- CbmStsMatchTracks::Init: No StsPoint array!" << endl;
268 return kERROR;
269 }
270 fPointsSi = (TClonesArray*)ioman->GetObject("SiliconPoint"); // AZ-280322
271
272 // Create and register StsTrackMatch array
273 fMatches = new TClonesArray("CbmTrackMatch", 100);
274 ioman->Register("StsTrackMatch", "STS", fMatches, kTRUE);
275
276 return kSUCCESS;
277}
278// -------------------------------------------------------------------------
279
280// ----- Virtual private method Finish ---------------------------------
282{
283
284 cout << endl;
285 cout << "============================================================" << endl;
286 cout << "===== " << GetName() << ": Run summary " << endl;
287 cout << "===== " << endl;
288 cout << "===== Good events : " << setw(6) << fNEvents << endl;
289 cout << "===== Failed events : " << setw(6) << fNEventsFailed << endl;
290 cout << "===== Average time : " << setprecision(4) << setw(8) << right << fTime / Double_t(fNEvents) << " s"
291 << endl;
292 cout << "===== " << endl;
293 cout << "===== Tracks per event : " << fixed << setprecision(0) << fNTrackMatches / Double_t(fNEvents) << endl;
294 cout << setprecision(2);
295 cout << "===== True hits : " << fixed << setw(6) << right << fNTrueHits / fNAllHits * 100. << " %" << endl;
296 cout << "============================================================" << endl;
297}
298// -------------------------------------------------------------------------
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
virtual Int_t GetStationNr() const
Definition CbmStsHit.h:67
CbmStsMatchTracks()
Default constructor.
Double_t fNAllHits
Total number of matched tracks.
virtual void Finish()
Finishing.
Double_t fNTrueHits
Total number of hits.
Int_t fNEventsFailed
Number of events with success.
TClonesArray * fHits
TClonesArray * fMatches
TClonesArray * fPointsSi
Double_t fTime
Number of events with failure.
Double_t fNTrackMatches
Total real time used for good events.
virtual void Exec(Option_t *opt)
Execution.
virtual InitStatus Init()
Intialisation at beginning of each event.
std::map< Int_t, Int_t > fMatchMap
Map from MCTrackId to number of common hits.
virtual ~CbmStsMatchTracks()
Destructor.
TClonesArray * fTracks
TClonesArray * fPoints
Int_t GetNStsHits() const
Accessors.
Definition CbmStsTrack.h:60
Int_t GetStsHitIndex(Int_t iHit) const
Definition CbmStsTrack.h:62
CbmStsTrackMatch.h.
TObject * At(Int_t idx) const override