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