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 void setCharge(int q) { charge_ = q; }
161 double getCharge() const { return charge_; }
162
163 void setTime(double time) { time_ = time; }
164 double getTime() const { return time_; }
165
166 // Perigee parameters at the target surface: d0, z0, phi, theta, q/p, t
167 void setPerigeeParameters(const std::vector<double>& par) {
168 perigee_pars_ = par;
169 }
170 std::vector<double> getPerigeeParameters() const { return perigee_pars_; }
171
172 void setPerigeeCov(const std::vector<double>& cov) { perigee_cov_ = cov; }
173 std::vector<double> getPerigeeCov() const { return perigee_cov_; }
174
175 void setPerigeeLocation(const std::vector<double>& perigee) {
176 perigee_ = perigee;
177 }
178 void setPerigeeLocation(const double& x, const double& y, const double& z) {
179 perigee_[0] = x;
180 perigee_[1] = y;
181 perigee_[2] = z;
182 }
183 std::vector<double> getPerigeeLocation() const { return perigee_; }
184 double getPerigeeX() const { return perigee_[0]; }
185 double getPerigeeY() const { return perigee_[1]; }
186 double getPerigeeZ() const { return perigee_[2]; }
187
188 double getD0() const { return perigee_pars_[0]; }
189 double getZ0() const { return perigee_pars_[1]; }
190 double getPhi() const { return perigee_pars_[2]; }
191 double getTheta() const { return perigee_pars_[3]; }
192 double getQoP() const { return perigee_pars_[4]; }
193 double getT() const { return perigee_pars_[5]; }
194
195 void addTrackState(const ldmx::Track::TrackState& ts) {
196 track_states_.push_back(ts);
197 };
198
199 std::vector<TrackState> getTrackStates() const { return track_states_; }
200
203 std::vector<double> getMomentumAtTarget() const {
204 for (const auto& ts : track_states_)
205 if (ts.ts_type_ == AtTarget) return ts.mom_;
206 return {};
207 }
208
211 std::vector<double> getPositionAtTarget() const {
212 for (const auto& ts : track_states_)
213 if (ts.ts_type_ == AtTarget) return ts.pos_;
214 return {};
215 }
216
220 std::vector<double> getMomentum(TrackStateType tstype) const {
221 for (const auto& ts : track_states_)
222 if (ts.ts_type_ == tstype) return ts.mom_;
223 return {};
224 }
225
229 std::vector<double> getPosition(TrackStateType tstype) const {
230 for (const auto& ts : track_states_)
231 if (ts.ts_type_ == tstype) return ts.pos_;
232 return {};
233 }
234
239 std::vector<double> getCovariance(TrackStateType tstype) const {
240 for (const auto& ts : track_states_)
241 if (ts.ts_type_ == tstype) return ts.pos_mom_cov_;
242 return {};
243 }
244
245 protected:
246 int n_hits_{0};
247 int n_outliers_{0};
248 int ndf_{0};
249 int n_shared_hits_{0};
250 int n_holes_{0};
251
252 double chi2_{0};
253
254 // Perigee parameters at the target surface, expressed in LDMX global frame.
255 // Parameter order: d0 / z0 / phi / theta / qop / t
256 // d0d0 d0z0 d0phi d0th d0qop d0t
257 // z0z0 z0phi z0th z0qop z0t
258 // phph phith phqop pht
259 // thth thqop tht
260 // qopqop qopt
261 // tt
262 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
263 std::vector<double> perigee_cov_;
264 std::vector<double> perigee_{0., 0.,
265 0.}; // perigee location in mm, LDMX global
266
267 // dE/dx measurements (path length in MeV/mm)
268 std::vector<float> dedx_measurements_{};
269
270 // The vector of measurement IDs
271 std::vector<unsigned int> meas_idxs_{};
272
273 // The vector of outlier IDs
274 std::vector<unsigned int> outlier_idxs_{};
275
276 // The vector of hole IDs
277 std::vector<unsigned int> hole_idxs_{};
278
279 // The vector of shared hit IDs
280 std::vector<unsigned int> shared_idxs_{};
281
282 // ID of the matched particle in the SimParticles map
283 int track_id_{-1};
284
285 // Truth probability
286 double truth_prob_{0.};
287
288 // pdgID
289 int pdg_id_{0};
290
291 // Track charge
292 int charge_{0};
293
294 // Track time
295 double time_{-666.0};
296
297 // Track States
298 std::vector<TrackState> track_states_;
299
302
303}; // Track
304
305typedef std::vector<ldmx::Track> Tracks;
306// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
307
308} // namespace ldmx
309
310#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:203
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:220
friend std::ostream & operator<<(std::ostream &o, const Track &d)
Print the string representation of this object.
Definition Track.cxx:8
ClassDef(Track, 6)
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:239
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:211
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:229