CbmRoot
Loading...
Searching...
No Matches
CaMcTrack.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
9
10#include "CaMcTrack.h"
11
12#include "CaMcHitInfo.h"
13#include "CaMcPoint.h"
14
15#include <iomanip>
16#include <sstream>
17
20
21// ---------------------------------------------------------------------------------------------------------------------
22//
24{
25 McTrack other(std::move(*this));
30}
31
32// ---------------------------------------------------------------------------------------------------------------------
33//
35{
36 McPoint point;
37 point.SetCharge(this->GetCharge());
38 point.SetEventId(this->GetEventId());
39 point.SetFileId(this->GetFileId());
40 point.SetExternalId(-1); // not in the array
41 point.SetId(-1); // not in the array
42 point.SetMass(this->GetMass());
43 point.SetMotherId(this->GetMotherId());
44 point.SetPdgCode(this->GetPdgCode());
45 point.SetPx(this->GetPx());
46 point.SetPy(this->GetPy());
47 point.SetPz(this->GetPz());
48 point.SetPxIn(this->GetPx());
49 point.SetPyIn(this->GetPy());
50 point.SetPzIn(this->GetPz());
51 point.SetPxOut(this->GetPx());
52 point.SetPyOut(this->GetPy());
53 point.SetPzOut(this->GetPz());
54 point.SetX(this->GetStartX());
55 point.SetY(this->GetStartY());
56 point.SetZ(this->GetStartZ());
57 point.SetXIn(this->GetStartX());
58 point.SetYIn(this->GetStartY());
59 point.SetZIn(this->GetStartZ());
60 point.SetXOut(this->GetStartX());
61 point.SetYOut(this->GetStartY());
62 point.SetZOut(this->GetStartZ());
63 point.SetTime(this->GetStartT());
64 return point;
65}
66
67// ---------------------------------------------------------------------------------------------------------------------
68//
70{
71 // NOTE: vHits must be sorted over stations!
75
76 int iStPrev = -1; // Station index of previous hit
77 int currNofConsStationsWithHit = 0; // Current number of consecutive stations with a point in MC track
78 int currMaxNofHitsOnStation = 0; // Current max number of hits on station
79
80 // Loop over hit indexes assigned to this track
81 for (int iH : fvHitIndexes) {
82 int iSt = vHits[iH].iStation; // current index of active station
83 // Check if the track is going to the backward direction and is not reconstructable
84 if (iSt < iStPrev) {
87 //fTotNofStationsWithHit = 0; // TODO: Check, if this is correct
88 return;
89 }
90
91 // Check if this hit is on the same station as the previous one and update max number of hits within a station a
92 // station
93 if (iSt == iStPrev) {
94 currMaxNofHitsOnStation++;
95 } // the same station
96 else { // the next station (reset hits counter and update number of stations)
97 if (currMaxNofHitsOnStation > fMaxNofHitsOnStation) {
98 fMaxNofHitsOnStation = currMaxNofHitsOnStation;
99 }
100 currMaxNofHitsOnStation = 1;
102 }
103
104 // Check if this hit is on the next station comparing with the previous hit and update the number of consecutive
105 // stations
106 if (iSt - iStPrev == 1) {
107 currNofConsStationsWithHit++;
108 }
109 else if (iSt - iStPrev > 1) {
110 if (currNofConsStationsWithHit > fNofConsStationsWithHit) {
111 fNofConsStationsWithHit = currNofConsStationsWithHit;
112 }
113 currNofConsStationsWithHit = 1;
114 }
115
116 iStPrev = iSt;
117 } // Loop over hit indexes assigned to this track: end
118 if (currMaxNofHitsOnStation > fMaxNofHitsOnStation) {
119 fMaxNofHitsOnStation = currMaxNofHitsOnStation;
120 }
121 if (currNofConsStationsWithHit > fNofConsStationsWithHit) {
122 fNofConsStationsWithHit = currNofConsStationsWithHit;
123 }
124}
125
126// ---------------------------------------------------------------------------------------------------------------------
127//
129{
133
134 int currMaxNofPointsOnStation = 0; // current max number of points within station
135 int currMaxNofPointsOnSensor = 0; // current max number of points within sensor
136 int iStPrev = -1; // index of station for previous point
137 float zPrev = 0; // Z position of previous point
138
139 // Loop over point indexes assigned to this track
140 for (int iP : fvPointIndexes) {
141 const auto& point = vPoints[iP]; // current MC point object
142 int iSt = point.GetActiveStationId(); // current index of active station
143
144 // Check if this point is on the same station as the previous one and update max number of points within a station
145 if (iSt == iStPrev) {
146 currMaxNofPointsOnStation++;
147 } // the same station
148 else { // the next station (reset points counter and update number of stations)
149 if (currMaxNofPointsOnStation > fMaxNofPointsOnStation) {
150 fMaxNofPointsOnStation = currMaxNofPointsOnStation;
151 }
152 currMaxNofPointsOnStation = 1;
154 }
155
156 // Check if this point is on the same sensor as the previous one and update max number of points within a sensor
157 // NOTE: points sometimes have different z positions within a sensor, so the max number of points within a sensor
158 // might be calculated incorrectly. (TODO: remove this variable?)
159 if (point.GetZ() == zPrev) {
160 currMaxNofPointsOnSensor++;
161 }
162 else {
163 if (currMaxNofPointsOnSensor > fMaxNofPointsOnSensor) {
164 fMaxNofPointsOnSensor = currMaxNofPointsOnSensor;
165 }
166 currMaxNofPointsOnSensor = 1;
167 }
168
169 iStPrev = iSt;
170 zPrev = point.GetZ();
171 } // Loop over point indexes assigned to this track
172
173 if (currMaxNofPointsOnStation > fMaxNofPointsOnStation) {
174 fMaxNofPointsOnStation = currMaxNofPointsOnStation;
175 }
176 if (currMaxNofPointsOnSensor > fMaxNofPointsOnSensor) {
177 fMaxNofPointsOnSensor = currMaxNofPointsOnSensor;
178 }
179
181 int currNofConsStationsWithPoint = 0; // current number of consecutive stations with points
182 iStPrev = -1;
183 // Loop over point indexes assigned to this track
184 for (int iP : fvPointIndexes) {
185 int iSt = vPoints[iP].GetActiveStationId();
186 // Check if this point is on the next station comparing with the previous point and update the number of consecutive
187 // stations
188 if (iSt - iStPrev == 1) {
189 currNofConsStationsWithPoint++;
190 }
191 else if (iSt - iStPrev > 1) {
192 if (currNofConsStationsWithPoint > fNofConsStationsWithPoint) {
193 fNofConsStationsWithPoint = currNofConsStationsWithPoint;
194 }
195 currNofConsStationsWithPoint = 1;
196 }
197
198 if (iSt <= iStPrev) {
199 continue;
200 } // Tracks propagating in backward direction
201 iStPrev = iSt;
202 }
203 if (currNofConsStationsWithPoint > fNofConsStationsWithPoint) {
204 fNofConsStationsWithPoint = currNofConsStationsWithPoint;
205 }
206}
207
208// ---------------------------------------------------------------------------------------------------------------------
209//
210void McTrack::SortPointIndexes(const std::function<bool(const int& lhs, const int& rhs)>& cmpFn)
211{
212 std::sort(fvPointIndexes.begin(), fvPointIndexes.end(), cmpFn);
213}
214
215// ---------------------------------------------------------------------------------------------------------------------
216//
217std::string McTrack::ToString(int verbose, bool header) const
218{
219 using std::setfill;
220 using std::setw;
221 std::stringstream msg;
222 if (header) {
223 if (verbose > 0) {
224 msg << setw(8) << setfill(' ') << "ID" << ' ';
225 msg << setw(8) << setfill(' ') << "Mother" << ' ';
226 msg << setw(8) << setfill(' ') << "PDG" << ' ';
227 if (verbose > 1) {
228 msg << setw(8) << setfill(' ') << "N h." << ' ';
229 msg << setw(8) << setfill(' ') << "N p." << ' ';
230 msg << setw(8) << setfill(' ') << "N r.tr." << ' ';
231 if (verbose > 2) {
232 msg << setw(8) << setfill(' ') << "N t.tr." << ' ';
233 }
234 msg << setw(12) << setfill(' ') << "zVTX [cm]" << ' ';
235 msg << setw(12) << setfill(' ') << "t [ns]" << ' ';
236 msg << setw(12) << setfill(' ') << "p [GeV/c]" << ' ';
237 }
238 msg << setw(8) << setfill(' ') << "rec-able" << ' ';
239 msg << setw(8) << setfill(' ') << "rec-ed" << ' ';
240 }
241 }
242 else {
243 if (verbose > 0) {
244 msg << setw(8) << setfill(' ') << fId << ' ';
245 msg << setw(8) << setfill(' ') << fMotherId << ' ';
246 msg << setw(8) << setfill(' ') << fPdgCode << ' ';
247 if (verbose > 1) {
248 msg << setw(8) << setfill(' ') << GetNofHits() << ' ';
249 msg << setw(8) << setfill(' ') << GetNofPoints() << ' ';
250 msg << setw(8) << setfill(' ') << GetNofRecoTracks() << ' ';
251 if (verbose > 2) {
252 msg << setw(8) << setfill(' ') << GetNofTouchTracks() << ' ';
253 }
254 msg << setw(12) << setfill(' ') << GetStartZ() << ' ';
255 msg << setw(12) << setfill(' ') << GetStartT() << ' ';
256 msg << setw(12) << setfill(' ') << GetP() << ' ';
257 }
258 msg << setw(8) << setfill(' ') << IsReconstructable() << ' ';
259 msg << setw(8) << setfill(' ') << IsReconstructed() << ' ';
260 if (verbose > 1) {
261 msg << "\n\t- point indexes: ";
262 for (int index : fvPointIndexes) {
263 msg << index << ' ';
264 }
265 msg << "\n\t- hit indexes: ";
266 for (int index : fvHitIndexes) {
267 msg << index << ' ';
268 }
269 msg << "\n\t- reconstructed track indexes: ";
270 for (int index : fvRecoTrackIndexes) {
271 msg << index << ' ';
272 }
273 if (verbose > 2) {
274 msg << "\n\t- touch track indexes: ";
275 for (int index : fvTouchTrackIndexes) {
276 msg << index << ' ';
277 }
278 }
279 }
280 }
281 }
282 return msg.str();
283}
Internal class describing a MC point for CA tracking QA and performance (header)
Class represents a MC track for CA tracking QA and performance (implementation)
void Clear()
Clears contents.
Definition CaMcTrack.cxx:23
Class describes a unified MC-point, used in CA tracking QA analysis.
Definition CaMcPoint.h:33
void SetCharge(double charge)
Sets particle charge [e].
Definition CaMcPoint.h:262
void SetPdgCode(int pdg)
Sets PDG code.
Definition CaMcPoint.h:292
void SetPy(double py)
Sets track momentum y component at reference z of station [GeV/c].
Definition CaMcPoint.h:304
void SetYIn(double y)
Sets y coordinate at entrance to station [cm].
Definition CaMcPoint.h:340
void SetZ(double z)
Sets z coordinate at reference z of station [cm].
Definition CaMcPoint.h:346
void SetPx(double px)
Sets track momentum x component at reference z of station [GeV/c].
Definition CaMcPoint.h:295
void SetYOut(double y)
Sets x coordinate at exit of station [cm].
Definition CaMcPoint.h:343
void SetMass(double mass)
Sets particle mass [GeV/c2].
Definition CaMcPoint.h:286
void SetXOut(double x)
Sets x coordinate at exit of station [cm].
Definition CaMcPoint.h:334
void SetPxIn(double px)
Sets track momentum x component at entrance to station [GeV/c].
Definition CaMcPoint.h:298
void SetPyIn(double py)
Sets track momentum y component at entrance to station [GeV/c].
Definition CaMcPoint.h:307
void SetFileId(int fileId)
Sets index of MC file containing this point.
Definition CaMcPoint.h:280
void SetTime(double time)
Sets time [ns].
Definition CaMcPoint.h:322
void SetZIn(double z)
Sets z coordinate at entrance to station [cm].
Definition CaMcPoint.h:349
void SetPzIn(double pz)
Sets track momentum z component at entrance to station [GeV/c].
Definition CaMcPoint.h:316
void SetPyOut(double py)
Sets track momentum y component at exit of station [GeV/c].
Definition CaMcPoint.h:310
void SetEventId(int eventId)
Sets index of MC event containing this point.
Definition CaMcPoint.h:274
void SetPzOut(double pz)
Sets track momentum z component at exit of station [GeV/c].
Definition CaMcPoint.h:319
void SetX(double x)
Sets x coordinate at reference z of station [cm].
Definition CaMcPoint.h:328
void SetY(double y)
Sets y coordinate at reference z of station [cm].
Definition CaMcPoint.h:337
void SetPxOut(double px)
Sets track momentum x component at exit of station [GeV/c].
Definition CaMcPoint.h:301
void SetXIn(double x)
Sets x coordinate at entrance to station [cm].
Definition CaMcPoint.h:331
void SetExternalId(int id)
Sets index of this point in external data structures.
Definition CaMcPoint.h:277
void SetMotherId(int motherId)
Sets index of mother track in the internal CA data structures.
Definition CaMcPoint.h:289
void SetId(int id)
Sets index of this point in the CA internal structure.
Definition CaMcPoint.h:283
void SetPz(double pz)
Sets track momentum z component at reference z of station [GeV/c].
Definition CaMcPoint.h:313
void SetZOut(double z)
Sets z coordinate at exit of station [cm].
Definition CaMcPoint.h:352
int fMaxNofPointsOnSensor
Max number of MC points with same Z (means on same sensor)
Definition CaMcTrack.h:369
void ClearRecoTrackIndexes()
Clears container of reconstructed track indexes.
Definition CaMcTrack.h:71
int fPdgCode
PDG encoding.
Definition CaMcTrack.h:348
double GetPx() const
Gets x component of momentum [GeV/c].
Definition CaMcTrack.h:166
int fId
Index of MC track in internal container for TS/event.
Definition CaMcTrack.h:352
bool IsReconstructed() const
Definition CaMcTrack.h:252
McPoint GetVertexPoint() const
Creates an MC point from the track vertex.
Definition CaMcTrack.cxx:34
bool IsReconstructable() const
Definition CaMcTrack.h:250
ca::Vector< int > fvTouchTrackIndexes
Definition CaMcTrack.h:375
void ClearHitIndexes()
Clears container of hit indexes.
Definition CaMcTrack.h:68
double GetStartX() const
Gets x component of the track vertex [cm].
Definition CaMcTrack.h:187
double GetStartZ() const
Gets z component of the track vertex [cm].
Definition CaMcTrack.h:193
ca::Vector< int > fvRecoTrackIndexes
Indexes of associated reco tracks.
Definition CaMcTrack.h:374
int GetNofHits() const
Gets number of hits.
Definition CaMcTrack.h:136
std::string ToString(int verbose=1, bool header=false) const
Provides string representation of a track.
int GetNofTouchTracks() const
Gets number of reconstructed tracks, which contain hits from this MC track.
Definition CaMcTrack.h:145
int fMotherId
Index of mother MC track in the external tracks container.
Definition CaMcTrack.h:353
int GetNofRecoTracks() const
Gets number of assigned reconstructed tracks.
Definition CaMcTrack.h:142
void InitHitsInfo(const ca::Vector< cbm::algo::ca::McHitInfo > &vHits)
Initializes information about MC track hits arrangement within stations Defines: #1) Number of statio...
Definition CaMcTrack.cxx:69
ca::Vector< int > fvHitIndexes
Indexes of hits in int.container.
Definition CaMcTrack.h:373
void SortPointIndexes(const std::function< bool(const int &lhs, const int &rhs)> &cmpFn)
int fNofConsStationsWithPoint
Number of consecutive stations with points.
Definition CaMcTrack.h:365
int fMaxNofPointsOnStation
Max number of MC points on a station.
Definition CaMcTrack.h:368
void ClearPointIndexes()
Clears container of point indexes.
Definition CaMcTrack.h:65
int GetMotherId() const
Gets index of mother track in CA internal data structures.
Definition CaMcTrack.h:124
double GetMass() const
Gets particle mass [GeV/c2].
Definition CaMcTrack.h:115
int GetNofPoints() const
Gets number of points.
Definition CaMcTrack.h:139
double GetCharge() const
Gets charge [e].
Definition CaMcTrack.h:85
int fTotNofStationsWithPoint
Total number of stations with MC points.
Definition CaMcTrack.h:367
int fNofConsStationsWithHit
Number of consecutive stations with hits.
Definition CaMcTrack.h:364
int GetFileId() const
Gets index of MC file containing this track in external data structures.
Definition CaMcTrack.h:103
int GetEventId() const
Gets index of MC event containing this track in external data structures.
Definition CaMcTrack.h:97
double GetP() const
Gets absolute momentum [GeV/c].
Definition CaMcTrack.h:148
void ClearTouchTrackIndexes()
Definition CaMcTrack.h:75
int fTotNofStationsWithHit
Total number of stations with hits.
Definition CaMcTrack.h:366
double GetStartT() const
Gets time of the track vertex [ns].
Definition CaMcTrack.h:184
void InitPointsInfo(const ca::Vector< McPoint > &vPoints)
Initializes information about MC track points arrangement within stations Defines: #1) Number of stat...
ca::Vector< int > fvPointIndexes
Indexes of MC points in ext.container.
Definition CaMcTrack.h:372
int fMaxNofHitsOnStation
Max number of hits on a station.
Definition CaMcTrack.h:370
double GetPz() const
Gets x component of momentum [GeV/c].
Definition CaMcTrack.h:172
double GetPy() const
Gets x component of momentum [GeV/c].
Definition CaMcTrack.h:169
McTrack()=default
Default constructor.
int GetPdgCode() const
Gets PDG encoding.
Definition CaMcTrack.h:151
double GetStartY() const
Gets y component of the track vertex [cm].
Definition CaMcTrack.h:190