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