CbmRoot
Loading...
Searching...
No Matches
CaToolsMCTrack.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 "CaToolsMCTrack.h"
11
12#include "CaToolsMCPoint.h"
13#include "CbmL1Hit.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.SetStationId(-1);
43 point.SetMass(this->GetMass());
44 point.SetMotherId(this->GetMotherId());
45 point.SetPdgCode(this->GetPdgCode());
46 point.SetPx(this->GetPx());
47 point.SetPy(this->GetPy());
48 point.SetPz(this->GetPz());
49 point.SetPxIn(this->GetPx());
50 point.SetPyIn(this->GetPy());
51 point.SetPzIn(this->GetPz());
52 point.SetPxOut(this->GetPx());
53 point.SetPyOut(this->GetPy());
54 point.SetPzOut(this->GetPz());
55 point.SetX(this->GetStartX());
56 point.SetY(this->GetStartY());
57 point.SetZ(this->GetStartZ());
58 point.SetXIn(this->GetStartX());
59 point.SetYIn(this->GetStartY());
60 point.SetZIn(this->GetStartZ());
61 point.SetXOut(this->GetStartX());
62 point.SetYOut(this->GetStartY());
63 point.SetZOut(this->GetStartZ());
64 point.SetTime(this->GetStartT());
65 return point;
66}
67
68// ---------------------------------------------------------------------------------------------------------------------
69//
71{
72 // NOTE: vHits must be sorted over stations!
76
77 int iStPrev = -1; // Station index of previous hit
78 int currNofConsStationsWithHit = 0; // Current number of consecutive stations with a point in MC track
79 int currMaxNofHitsOnStation = 0; // Current max number of hits on station
80
81 // Loop over hit indexes assigned to this track
82 for (int iH : fvHitIndexes) {
83 int iSt = vHits[iH].iStation; // current index of active station
84 // Check if the track is going to the backward direction and is not reconstructable
85 if (iSt < iStPrev) {
88 //fTotNofStationsWithHit = 0; // TODO: Check, if this is correct
89 return;
90 }
91
92 // Check if this hit is on the same station as the previous one and update max number of hits within a station a
93 // station
94 if (iSt == iStPrev) {
95 currMaxNofHitsOnStation++;
96 } // the same station
97 else { // the next station (reset hits counter and update number of stations)
98 if (currMaxNofHitsOnStation > fMaxNofHitsOnStation) {
99 fMaxNofHitsOnStation = currMaxNofHitsOnStation;
100 }
101 currMaxNofHitsOnStation = 1;
103 }
104
105 // Check if this hit is on the next station comparing with the previous hit and update the number of consecutive
106 // stations
107 if (iSt - iStPrev == 1) {
108 currNofConsStationsWithHit++;
109 }
110 else if (iSt - iStPrev > 1) {
111 if (currNofConsStationsWithHit > fNofConsStationsWithHit) {
112 fNofConsStationsWithHit = currNofConsStationsWithHit;
113 }
114 currNofConsStationsWithHit = 1;
115 }
116
117 iStPrev = iSt;
118 } // Loop over hit indexes assigned to this track: end
119 if (currMaxNofHitsOnStation > fMaxNofHitsOnStation) {
120 fMaxNofHitsOnStation = currMaxNofHitsOnStation;
121 }
122 if (currNofConsStationsWithHit > fNofConsStationsWithHit) {
123 fNofConsStationsWithHit = currNofConsStationsWithHit;
124 }
125}
126
127// ---------------------------------------------------------------------------------------------------------------------
128//
130{
134
135 int currMaxNofPointsOnStation = 0; // current max number of points within station
136 int currMaxNofPointsOnSensor = 0; // current max number of points within sensor
137 int iStPrev = -1; // index of station for previous point
138 float zPrev = 0; // Z position of previous point
139
140 // Loop over point indexes assigned to this track
141 for (int iP : fvPointIndexes) {
142 const auto& point = vPoints[iP]; // current MC point object
143 int iSt = point.GetStationId(); // current index of active station
144
145 // Check if this point is on the same station as the previous one and update max number of points within a station
146 if (iSt == iStPrev) {
147 currMaxNofPointsOnStation++;
148 } // the same station
149 else { // the next station (reset points counter and update number of stations)
150 if (currMaxNofPointsOnStation > fMaxNofPointsOnStation) {
151 fMaxNofPointsOnStation = currMaxNofPointsOnStation;
152 }
153 currMaxNofPointsOnStation = 1;
155 }
156
157 // Check if this point is on the same sensor as the previous one and update max number of points within a sensor
158 // NOTE: points sometimes have different z positions within a sensor, so the max number of points within a sensor
159 // might be calculated incorrectly. (TODO: remove this variable?)
160 if (point.GetZ() == zPrev) {
161 currMaxNofPointsOnSensor++;
162 }
163 else {
164 if (currMaxNofPointsOnSensor > fMaxNofPointsOnSensor) {
165 fMaxNofPointsOnSensor = currMaxNofPointsOnSensor;
166 }
167 currMaxNofPointsOnSensor = 1;
168 }
169
170 iStPrev = iSt;
171 zPrev = point.GetZ();
172 } // Loop over point indexes assigned to this track
173
174 if (currMaxNofPointsOnStation > fMaxNofPointsOnStation) {
175 fMaxNofPointsOnStation = currMaxNofPointsOnStation;
176 }
177 if (currMaxNofPointsOnSensor > fMaxNofPointsOnSensor) {
178 fMaxNofPointsOnSensor = currMaxNofPointsOnSensor;
179 }
180
182 int currNofConsStationsWithPoint = 0; // current number of consecutive stations with points
183 iStPrev = -1;
184 // Loop over point indexes assigned to this track
185 for (int iP : fvPointIndexes) {
186 int iSt = vPoints[iP].GetStationId();
187 // Check if this point is on the next station comparing with the previous point and update the number of consecutive
188 // stations
189 if (iSt - iStPrev == 1) {
190 currNofConsStationsWithPoint++;
191 }
192 else if (iSt - iStPrev > 1) {
193 if (currNofConsStationsWithPoint > fNofConsStationsWithPoint) {
194 fNofConsStationsWithPoint = currNofConsStationsWithPoint;
195 }
196 currNofConsStationsWithPoint = 1;
197 }
198
199 if (iSt <= iStPrev) {
200 continue;
201 } // Tracks propagating in backward direction
202 iStPrev = iSt;
203 }
204 if (currNofConsStationsWithPoint > fNofConsStationsWithPoint) {
205 fNofConsStationsWithPoint = currNofConsStationsWithPoint;
206 }
207}
208
209// ---------------------------------------------------------------------------------------------------------------------
210//
211void MCTrack::SortPointIndexes(const std::function<bool(const int& lhs, const int& rhs)>& cmpFn)
212{
213 std::sort(fvPointIndexes.begin(), fvPointIndexes.end(), cmpFn);
214}
215
216// ---------------------------------------------------------------------------------------------------------------------
217//
218std::string MCTrack::ToString(int verbose, bool header) const
219{
220 using std::setfill;
221 using std::setw;
222 std::stringstream msg;
223 if (header) {
224 if (verbose > 0) {
225 msg << setw(8) << setfill(' ') << "ID" << ' ';
226 msg << setw(8) << setfill(' ') << "Mother" << ' ';
227 msg << setw(8) << setfill(' ') << "PDG" << ' ';
228 if (verbose > 1) {
229 msg << setw(8) << setfill(' ') << "N h." << ' ';
230 msg << setw(8) << setfill(' ') << "N p." << ' ';
231 msg << setw(8) << setfill(' ') << "N r.tr." << ' ';
232 if (verbose > 2) {
233 msg << setw(8) << setfill(' ') << "N t.tr." << ' ';
234 }
235 msg << setw(12) << setfill(' ') << "zVTX [cm]" << ' ';
236 msg << setw(12) << setfill(' ') << "t [ns]" << ' ';
237 msg << setw(12) << setfill(' ') << "p [GeV/c]" << ' ';
238 }
239 msg << setw(8) << setfill(' ') << "rec-able" << ' ';
240 msg << setw(8) << setfill(' ') << "rec-ed" << ' ';
241 }
242 }
243 else {
244 if (verbose > 0) {
245 msg << setw(8) << setfill(' ') << fId << ' ';
246 msg << setw(8) << setfill(' ') << fMotherId << ' ';
247 msg << setw(8) << setfill(' ') << fPdgCode << ' ';
248 if (verbose > 1) {
249 msg << setw(8) << setfill(' ') << GetNofHits() << ' ';
250 msg << setw(8) << setfill(' ') << GetNofPoints() << ' ';
251 msg << setw(8) << setfill(' ') << GetNofRecoTracks() << ' ';
252 if (verbose > 2) {
253 msg << setw(8) << setfill(' ') << GetNofTouchTracks() << ' ';
254 }
255 msg << setw(12) << setfill(' ') << GetStartZ() << ' ';
256 msg << setw(12) << setfill(' ') << GetStartT() << ' ';
257 msg << setw(12) << setfill(' ') << GetP() << ' ';
258 }
259 msg << setw(8) << setfill(' ') << IsReconstructable() << ' ';
260 msg << setw(8) << setfill(' ') << IsReconstructed() << ' ';
261 if (verbose > 1) {
262 msg << "\n\t- point indexes: ";
263 for (int index : fvPointIndexes) {
264 msg << index << ' ';
265 }
266 msg << "\n\t- hit indexes: ";
267 for (int index : fvHitIndexes) {
268 msg << index << ' ';
269 }
270 msg << "\n\t- reconstructed track indexes: ";
271 for (int index : fvRecoTrackIndexes) {
272 msg << index << ' ';
273 }
274 if (verbose > 2) {
275 msg << "\n\t- touch track indexes: ";
276 for (int index : fvTouchTrackIndexes) {
277 msg << index << ' ';
278 }
279 }
280 }
281 }
282 }
283 return msg.str();
284}
Internal class describing a MC point for CA tracking QA and performance (header)
Class represents a MC track for CA tracking QA and performance (header)
Class describes a unified MC-point, used in CA tracking QA analysis.
void SetPzOut(double pz)
Sets track momentum z component at exit of station [GeV/c].
void SetPz(double pz)
Sets track momentum z component at reference z of station [GeV/c].
void SetPdgCode(int pdg)
Sets PDG code.
void SetPxOut(double px)
Sets track momentum x component at exit of station [GeV/c].
void SetPxIn(double px)
Sets track momentum x component at entrance to station [GeV/c].
void SetZIn(double z)
Sets z coordinate at entrance to station [cm].
void SetMotherId(int motherId)
Sets index of mother track in the internal CA data structures.
void SetX(double x)
Sets x coordinate at reference z of station [cm].
void SetZ(double z)
Sets z coordinate at reference z of station [cm].
void SetXIn(double x)
Sets x coordinate at entrance to station [cm].
void SetY(double y)
Sets y coordinate at reference z of station [cm].
void SetZOut(double z)
Sets z coordinate at exit of station [cm].
void SetPx(double px)
Sets track momentum x component at reference z of station [GeV/c].
void SetYIn(double y)
Sets y coordinate at entrance to station [cm].
void SetId(int id)
Sets index of this point in the CA internal structure.
void SetYOut(double y)
Sets x coordinate at exit of station [cm].
void SetPyIn(double py)
Sets track momentum y component at entrance to station [GeV/c].
void SetPyOut(double py)
Sets track momentum y component at exit of station [GeV/c].
void SetFileId(int fileId)
Sets index of MC file containing this point.
void SetCharge(double charge)
Sets particle charge [e].
void SetXOut(double x)
Sets x coordinate at exit of station [cm].
void SetStationId(int stationId)
Sets global index of active station.
void SetTime(double time)
Sets time [ns].
void SetExternalId(int id)
Sets index of this point in external data structures.
void SetMass(double mass)
Sets particle mass [GeV/c2].
void SetEventId(int eventId)
Sets index of MC event containing this point.
void SetPzIn(double pz)
Sets track momentum z component at entrance to station [GeV/c].
void SetPy(double py)
Sets track momentum y component at reference z of station [GeV/c].
double GetStartX() const
Gets x component of the track vertex [cm].
int GetNofPoints() const
Gets number of points.
void ClearHitIndexes()
Clears container of hit indexes.
double GetPy() const
Gets x component of momentum [GeV/c].
double GetStartZ() const
Gets z component of the track vertex [cm].
int fMotherId
Index of mother MC track in the external tracks container.
int GetNofRecoTracks() const
Gets number of assigned reconstructed tracks.
ca::Vector< int > fvHitIndexes
Indexes of hits in int.container.
double GetMass() const
Gets particle mass [GeV/c2].
void SortPointIndexes(const std::function< bool(const int &lhs, const int &rhs)> &cmpFn)
ca::Vector< int > fvPointIndexes
Indexes of MC points in ext.container.
int GetMotherId() const
Gets index of mother track in CA internal data structures.
int fTotNofStationsWithHit
Total number of stations with hits.
int fMaxNofHitsOnStation
Max number of hits on a station.
int GetNofHits() const
Gets number of hits.
double GetPx() const
Gets x component of momentum [GeV/c].
double GetStartT() const
Gets time of the track vertex [ns].
int GetFileId() const
Gets index of MC file containing this track in external data structures.
int fNofConsStationsWithPoint
Number of consecutive stations with points.
int GetNofTouchTracks() const
Gets number of reconstructed tracks, which contain hits from this MC track.
void InitPointsInfo(const ca::Vector< MCPoint > &vPoints)
Initializes information about MC track points arrangement within stations Defines: #1) Number of stat...
double GetCharge() const
Gets charge [e].
void ClearRecoTrackIndexes()
Clears container of reconstructed track indexes.
int fMaxNofPointsOnStation
Max number of MC points on a station.
int GetEventId() const
Gets index of MC event containing this track in external data structures.
int fTotNofStationsWithPoint
Total number of stations with MC points.
int fPdgCode
PDG encoding.
std::string ToString(int verbose=1, bool header=false) const
Provides string representation of a track.
double GetP() const
Gets absolute momentum [GeV/c].
int GetPdgCode() const
Gets PDG encoding.
MCPoint GetVertexPoint() const
Creates an MC point from the track vertex.
ca::Vector< int > fvTouchTrackIndexes
double GetStartY() const
Gets y component of the track vertex [cm].
ca::Vector< int > fvRecoTrackIndexes
Indexes of associated reco tracks.
double GetPz() const
Gets x component of momentum [GeV/c].
void Clear()
Clears contents.
void InitHitsInfo(const ca::Vector< CbmL1HitDebugInfo > &vHits)
Initializes information about MC track hits arrangement within stations Defines: #1) Number of statio...
int fId
Index of MC track in internal container for TS/event.
int fNofConsStationsWithHit
Number of consecutive stations with hits.
int fMaxNofPointsOnSensor
Max number of MC points with same Z (means on same sensor)
void ClearPointIndexes()
Clears container of point indexes.