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_[0] = x;
195 perigee_[1] = y;
196 perigee_[2] = z;
197 }
198 std::vector<double> getPerigeeLocation() const { return perigee_; }
199 double getPerigeeX() const { return perigee_[0]; }
200 double getPerigeeY() const { return perigee_[1]; }
201 double getPerigeeZ() const { return perigee_[2]; }
202
203 double getD0() const { return perigee_pars_[0]; }
204 double getZ0() const { return perigee_pars_[1]; }
205 double getPhi() const { return perigee_pars_[2]; }
206 double getTheta() const { return perigee_pars_[3]; }
207 double getQoP() const { return perigee_pars_[4]; }
208 double getT() const { return perigee_pars_[5]; }
209
210 void addTrackState(const ldmx::Track::TrackState& ts) {
211 track_states_.push_back(ts);
212 };
213
214 std::vector<TrackState> getTrackStates() const { return track_states_; }
215
218 std::vector<double> getMomentumAtTarget() const {
219 for (const auto& ts : track_states_)
220 if (ts.ts_type_ == AtTarget) return ts.mom_;
221 return {};
222 }
223
226 std::vector<double> getPositionAtTarget() const {
227 for (const auto& ts : track_states_)
228 if (ts.ts_type_ == AtTarget) return ts.pos_;
229 return {};
230 }
231
235 std::vector<double> getMomentum(TrackStateType tstype) const {
236 for (const auto& ts : track_states_)
237 if (ts.ts_type_ == tstype) return ts.mom_;
238 return {};
239 }
240
244 std::vector<double> getPosition(TrackStateType tstype) const {
245 for (const auto& ts : track_states_)
246 if (ts.ts_type_ == tstype) return ts.pos_;
247 return {};
248 }
249
254 std::vector<double> getCovariance(TrackStateType tstype) const {
255 for (const auto& ts : track_states_)
256 if (ts.ts_type_ == tstype) return ts.pos_mom_cov_;
257 return {};
258 }
259
260 protected:
261 int n_hits_{0};
262 int n_outliers_{0};
263 int ndf_{0};
264 int n_shared_hits_{0};
265 int n_holes_{0};
266
267 double chi2_{0};
268
269 // Perigee parameters at the target surface, expressed in LDMX global frame.
270 // Parameter order: d0 / z0 / phi / theta / qop / t
271 // d0d0 d0z0 d0phi d0th d0qop d0t
272 // z0z0 z0phi z0th z0qop z0t
273 // phph phith phqop pht
274 // thth thqop tht
275 // qopqop qopt
276 // tt
277 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
278 std::vector<double> perigee_cov_;
279 std::vector<double> perigee_{0., 0.,
280 0.}; // perigee location in mm, LDMX global
281
282 // dE/dx measurements (path length in MeV/mm)
283 std::vector<float> dedx_measurements_{};
284
285 // The vector of measurement IDs
286 std::vector<unsigned int> meas_idxs_{};
287
288 // The vector of outlier IDs
289 std::vector<unsigned int> outlier_idxs_{};
290
291 // The vector of hole IDs
292 std::vector<unsigned int> hole_idxs_{};
293
294 // The vector of shared hit IDs
295 std::vector<unsigned int> shared_idxs_{};
296
297 // Per-hit Kalman smoothed loc0 (mm) and its variance (mm²) at each
298 // measurement surface, in the same order as meas_idxs_.
299 std::vector<float> smoothed_loc0_{};
300 std::vector<float> smoothed_cov_loc0_{};
301
302 // ID of the matched particle in the SimParticles map
303 int track_id_{-1};
304
305 // Truth probability
306 double truth_prob_{0.};
307
308 // pdgID
309 int pdg_id_{0};
310
311 // Track charge
312 int charge_{0};
313
314 // Track time
315 double time_{-666.0};
316
317 // Track States
318 std::vector<TrackState> track_states_;
319
322
323}; // Track
324
325typedef std::vector<ldmx::Track> Tracks;
326// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
327
328} // namespace ldmx
329
330#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:218
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:235
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:254
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:226
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:244