LDMX Software
Track.h
1#ifndef TRACKING_EVENT_TRACK_H_
2#define TRACKING_EVENT_TRACK_H_
3
4//----------------------//
5// C++ Standard Lib //
6//----------------------//
7#include <iostream>
8#include <optional>
9#include <vector>
10
11//----------//
12// ROOT //
13//----------//
14#include "TObject.h"
15
16// --- ACTS --- //
17// #include "Acts/Definitions/TrackParametrization.hpp"
18// #include "Acts/EventData/TrackParameters.hpp"
19
20namespace ldmx {
21
29
33
34enum TrackStateType {
35 RefPoint = 0,
36 AtTarget = 1,
37 AtFirstMeasurement = 2,
38 AtLastMeasurement = 3,
39 AtECAL = 4,
40 AtBeamOrigin = 5,
41 Invalid = 6,
42 AtHCAL = 7
43};
44
53class Track {
54 public:
55 // Track states won't be visualized in the root tree from the TBrowser, but it
56 // will be accessible when reading back the rootfile using for example the
57 // monitoring code.
58 // All positions, momenta, and covariances are in the LDMX global frame:
59 // x: horizontal (bend plane), y: vertical, z: downstream beam direction.
60 // ACTS uses a rotated frame (x downstream, y horizontal, z vertical).
61 // The conversion ACTS->LDMX is: x_ldmx=y_acts, y_ldmx=z_acts, z_ldmx=x_acts.
62 // This rotation must be applied before filling these fields (see
63 // makeTrackState in TrackingUtils.h).
64 struct TrackState {
65 std::vector<double> pos_{-666., -666.,
66 -666.}; // (x, y, z) in mm, LDMX global
67 std::vector<double> mom_{-666., -666.,
68 -666.}; // (px, py, pz) in MeV, LDMX global
69 // 21-element upper-triangular 6x6 covariance over (x, y, z, px, py, pz)
70 // in LDMX global coordinates, units: mm^2 (pos-pos), mm*MeV (pos-mom),
71 // MeV^2 (mom-mom): xx xy xz xpx xpy xpz
72 // yy yz ypx ypy ypz
73 // zz zpx zpy zpz
74 // pxpx pxpy pxpz
75 // pypy pypz
76 // pzpz
77 std::vector<double> pos_mom_cov_;
78 TrackStateType ts_type_;
79 };
80
81 Track() {};
82
88 virtual ~Track() {};
89
95 friend std::ostream& operator<<(std::ostream& o, const Track& d);
96
97 // To match the Framework Bus clear. It's doing nothing
98 void clear() {};
99
100 void setNhits(int nhits) { n_hits_ = nhits; }
101 int getNhits() const { return n_hits_; }
102
103 std::optional<TrackState> getTrackState(TrackStateType tstype) const {
104 for (auto ts : track_states_)
105 if (ts.ts_type_ == tstype) return std::optional<TrackState>(ts);
106
107 return std::nullopt;
108 }
109
110 // void setNholes(int nholes) {n_holes_ = nholes;}
111 // int getNholes() const {return n_holes_;}
112
113 void setNoutliers(int nout) { n_outliers_ = nout; }
114 int getNoutliers() const { return n_outliers_; }
115
116 void setNdf(int ndf) { ndf_ = ndf; }
117 int getNdf() const { return ndf_; };
118
119 void setNsharedHits(int nsh) { n_shared_hits_ = nsh; }
120 int getNsharedHits() const { return n_shared_hits_; }
121
122 void setChi2(double chi2) { chi2_ = chi2; }
123 double getChi2() const { return chi2_; }
124
125 void setTrackID(int trackid) { track_id_ = trackid; };
126 int getTrackID() const { return track_id_; };
127
128 void setTruthProb(double truthProb) { truth_prob_ = truthProb; };
129 double getTruthProb() const { return truth_prob_; };
130
131 void setPdgID(int pdgID) { pdg_id_ = pdgID; };
132 int getPdgID() const { return pdg_id_; };
133
134 // Add measurement indices to tracks
135 // For reco tracks they corresponds to the indices in the measurement
136 // container For truth tracks they corresponds to the indices of the
137 // SimHitCointainer
138
139 void addDedxMeasurement(float path_length) {
140 dedx_measurements_.push_back(path_length);
141 }
142 std::vector<float> getDedxMeasurements() const { return dedx_measurements_; }
143
144 void addMeasurementIndex(unsigned int measIdx) {
145 meas_idxs_.push_back(measIdx);
146 }
147 std::vector<unsigned int> getMeasurementsIdxs() const { return meas_idxs_; }
148
149 void addOutlierIndex(unsigned int measIdx) {
150 outlier_idxs_.push_back(measIdx);
151 }
152 std::vector<unsigned int> getOutlierIdxs() const { return outlier_idxs_; }
153
154 void addHoleIndex(unsigned int measIdx) { hole_idxs_.push_back(measIdx); }
155 std::vector<unsigned int> getHoleIdxs() const { return hole_idxs_; }
156
157 void addSharedIndex(unsigned int measIdx) { shared_idxs_.push_back(measIdx); }
158 std::vector<unsigned int> getSharedIdxs() const { return shared_idxs_; }
159
160 // Per-hit smoothed state at each measurement surface (same order as
161 // meas_idxs_). Used to form unbiased residuals via the algebraic
162 // leave-one-out formula of NIM A 262, 444 (1987):
163 // r_ubs = V/(V - C) * (m - x_smooth)
164 // pull = (m - x_smooth) / sqrt(V - C)
165 // where V = cov_uu, C = smoothed_cov_loc0.
166 void addSmoothedLoc0(float loc0, float cov_loc0) {
167 smoothed_loc0_.push_back(loc0);
168 smoothed_cov_loc0_.push_back(cov_loc0);
169 }
170 const std::vector<float>& getSmoothedLoc0() const { return smoothed_loc0_; }
171 const std::vector<float>& getSmoothedCovLoc0() const {
172 return smoothed_cov_loc0_;
173 }
174
175 void setCharge(int q) { charge_ = q; }
176 double getCharge() const { return charge_; }
177
178 void setTime(double time) { time_ = time; }
179 double getTime() const { return time_; }
180
181 // Perigee parameters at the target surface: d0, z0, phi, theta, q/p, t
182 void setPerigeeParameters(const std::vector<double>& par) {
183 perigee_pars_ = par;
184 }
185 std::vector<double> getPerigeeParameters() const { return perigee_pars_; }
186
187 void setPerigeeCov(const std::vector<double>& cov) { perigee_cov_ = cov; }
188 std::vector<double> getPerigeeCov() const { return perigee_cov_; }
189
190 void setPerigeeLocation(const std::vector<double>& perigee) {
191 perigee_ = perigee;
192 }
193 void setPerigeeLocation(const double& x, const double& y, const double& z) {
194 perigee_.resize(3);
195 perigee_[0] = x;
196 perigee_[1] = y;
197 perigee_[2] = z;
198 }
199 std::vector<double> getPerigeeLocation() const { return perigee_; }
200 double getPerigeeX() const { return perigee_[0]; }
201 double getPerigeeY() const { return perigee_[1]; }
202 double getPerigeeZ() const { return perigee_[2]; }
203
204 double getD0() const { return perigee_pars_[0]; }
205 double getZ0() const { return perigee_pars_[1]; }
206 double getPhi() const { return perigee_pars_[2]; }
207 double getTheta() const { return perigee_pars_[3]; }
208 double getQoP() const { return perigee_pars_[4]; }
209 double getT() const { return perigee_pars_[5]; }
210
211 void addTrackState(const ldmx::Track::TrackState& ts) {
212 track_states_.push_back(ts);
213 };
214
215 std::vector<TrackState> getTrackStates() const { return track_states_; }
216
219 std::vector<double> getMomentumAtTarget() const {
220 for (const auto& ts : track_states_)
221 if (ts.ts_type_ == AtTarget) return ts.mom_;
222 return {};
223 }
224
227 std::vector<double> getPositionAtTarget() const {
228 for (const auto& ts : track_states_)
229 if (ts.ts_type_ == AtTarget) return ts.pos_;
230 return {};
231 }
232
236 std::vector<double> getMomentum(TrackStateType tstype) const {
237 for (const auto& ts : track_states_)
238 if (ts.ts_type_ == tstype) return ts.mom_;
239 return {};
240 }
241
245 std::vector<double> getPosition(TrackStateType tstype) const {
246 for (const auto& ts : track_states_)
247 if (ts.ts_type_ == tstype) return ts.pos_;
248 return {};
249 }
250
255 std::vector<double> getCovariance(TrackStateType tstype) const {
256 for (const auto& ts : track_states_)
257 if (ts.ts_type_ == tstype) return ts.pos_mom_cov_;
258 return {};
259 }
260
261 protected:
262 int n_hits_{0};
263 int n_outliers_{0};
264 int ndf_{0};
265 int n_shared_hits_{0};
266 int n_holes_{0};
267
268 double chi2_{0};
269
270 // Perigee parameters at the target surface, expressed in LDMX global frame.
271 // Parameter order: d0 / z0 / phi / theta / qop / t
272 // d0d0 d0z0 d0phi d0th d0qop d0t
273 // z0z0 z0phi z0th z0qop z0t
274 // phph phith phqop pht
275 // thth thqop tht
276 // qopqop qopt
277 // tt
278 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
279 std::vector<double> perigee_cov_;
280 std::vector<double> perigee_{0., 0.,
281 0.}; // perigee location in mm, LDMX global
282
283 // dE/dx measurements (path length in MeV/mm)
284 std::vector<float> dedx_measurements_{};
285
286 // The vector of measurement IDs
287 std::vector<unsigned int> meas_idxs_{};
288
289 // The vector of outlier IDs
290 std::vector<unsigned int> outlier_idxs_{};
291
292 // The vector of hole IDs
293 std::vector<unsigned int> hole_idxs_{};
294
295 // The vector of shared hit IDs
296 std::vector<unsigned int> shared_idxs_{};
297
298 // Per-hit Kalman smoothed loc0 (mm) and its variance (mm²) at each
299 // measurement surface, in the same order as meas_idxs_.
300 std::vector<float> smoothed_loc0_{};
301 std::vector<float> smoothed_cov_loc0_{};
302
303 // ID of the matched particle in the SimParticles map
304 int track_id_{-1};
305
306 // Truth probability
307 double truth_prob_{0.};
308
309 // pdgID
310 int pdg_id_{0};
311
312 // Track charge
313 int charge_{0};
314
315 // Track time
316 double time_{-666.0};
317
318 // Track States
319 std::vector<TrackState> track_states_;
320
323
324}; // Track
325
326typedef std::vector<ldmx::Track> Tracks;
327// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
328
329} // namespace ldmx
330
331#endif // TRACKING_EVENT_TRACK_H_
Implementation of a track object.
Definition Track.h:53
std::vector< double > getMomentumAtTarget() const
Returns the momentum (px, py, pz) in MeV in the LDMX global frame from the AtTarget TrackState.
Definition Track.h:219
std::vector< double > getMomentum(TrackStateType tstype) const
Returns the momentum (px, py, pz) in MeV in the LDMX global frame for the requested TrackState type.
Definition Track.h:236
friend std::ostream & operator<<(std::ostream &o, const Track &d)
Print the string representation of this object.
Definition Track.cxx:8
ClassDef(Track, 7)
Class declaration needed by the ROOT dictionary.
virtual ~Track()
Destructor.
Definition Track.h:88
std::vector< double > getCovariance(TrackStateType tstype) const
Returns the 21-element upper-triangular covariance vector over (x, y, z, px, py, pz) in LDMX global c...
Definition Track.h:255
std::vector< double > getPositionAtTarget() const
Returns the position (x, y, z) in mm in the LDMX global frame from the AtTarget TrackState.
Definition Track.h:227
std::vector< double > getPosition(TrackStateType tstype) const
Returns the position (x, y, z) in mm in the LDMX global frame for the requested TrackState type.
Definition Track.h:245