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 struct TrackState {
59 double ref_x_, ref_y_, ref_z_;
60 std::vector<double> params_;
61 std::vector<double> cov_;
62 TrackStateType ts_type_;
63 };
64
65 Track(){};
66
72 virtual ~Track(){};
73
79 friend std::ostream& operator<<(std::ostream& o, const Track& d);
80
81 // To match the Framework Bus clear. It's doing nothing
82 void clear() {};
83
84 void setNhits(int nhits) { n_hits_ = nhits; }
85 int getNhits() const { return n_hits_; }
86
87 std::optional<TrackState> getTrackState(TrackStateType tstype) const {
88 for (auto ts : track_states_)
89 if (ts.ts_type_ == tstype) return std::optional<TrackState>(ts);
90
91 return std::nullopt;
92 }
93
94 // void setNholes(int nholes) {n_holes_ = nholes;}
95 // int getNholes() const {return n_holes_;}
96
97 void setNoutliers(int nout) { n_outliers_ = nout; }
98 int getNoutliers() const { return n_outliers_; }
99
100 void setNdf(int ndf) { ndf_ = ndf; }
101 int getNdf() const { return ndf_; };
102
103 void setNsharedHits(int nsh) { n_shared_hits_ = nsh; }
104 int getNsharedHits() const { return n_shared_hits_; }
105
106 void setChi2(double chi2) { chi2_ = chi2; }
107 double getChi2() const { return chi2_; }
108
109 void setTrackID(int trackid) { track_id_ = trackid; };
110 int getTrackID() const { return track_id_; };
111
112 void setTruthProb(double truthProb) { truth_prob_ = truthProb; };
113 double getTruthProb() const { return truth_prob_; };
114
115 void setPdgID(int pdgID) { pdg_id_ = pdgID; };
116 int getPdgID() const { return pdg_id_; };
117
118 // in units of e
119 int q() const { return perigee_pars_[4] > 0 ? 1 : -1; }
120
121 // Add measurement indices to tracks
122 // For reco tracks they corresponds to the indices in the measurement
123 // container For truth tracks they corresponds to the indices of the
124 // SimHitCointainer
125
126 void addMeasurementIndex(unsigned int measIdx) {
127 meas_idxs_.push_back(measIdx);
128 }
129 std::vector<unsigned int> getMeasurementsIdxs() const { return meas_idxs_; }
130
131 void addOutlierIndex(unsigned int measIdx) {
132 outlier_idxs_.push_back(measIdx);
133 }
134 std::vector<unsigned int> getOutlierIdxs() const { return outlier_idxs_; }
135
136 void addHoleIndex(unsigned int measIdx) { hole_idxs_.push_back(measIdx); }
137 std::vector<unsigned int> getHoleIdxs() const { return hole_idxs_; }
138
139 void addSharedIndex(unsigned int measIdx) { shared_idxs_.push_back(measIdx); }
140 std::vector<unsigned int> getSharedIdxs() const { return shared_idxs_; }
141
142 void addDedxMeasurement(float path_length) {
143 dedx_measurements_.push_back(path_length);
144 }
145 std::vector<float> getDedxMeasurements() const { return dedx_measurements_; }
146
148 // void setPerigeeParameters(const Acts::BoundVector& par) {perigee_pars_ =
149 // par; } Acts::BoundVector getPerigeeParameters() {return perigee_pars_;}
150
151 // void setPerigeeCov(const Acts::BoundMatrix& cov) {perigee_cov_ = cov;}
152 // Acts::BoundMatrix getPerigeeCov() {return perigee_cov_;}
153
154 // void setPerigeeState(const Acts::BoundVector& par, const Acts::BoundMatrix&
155 // cov) {
156 // perigee_pars_ = par;
157 // perigee_cov_ = cov;
158 // }
159
160 // Vector representation
161 void setPerigeeParameters(const std::vector<double>& par) {
162 perigee_pars_ = par;
163 }
164 std::vector<double> getPerigeeParameters() const { return perigee_pars_; }
165
166 void setPerigeeCov(const std::vector<double>& cov) { perigee_cov_ = cov; }
167 std::vector<double> getPerigeeCov() const { return perigee_cov_; }
168
169 void setPerigeeLocation(const std::vector<double>& perigee) {
170 perigee_ = perigee;
171 }
172
173 void setPerigeeLocation(const double& x_, const double& y_,
174 const double& z_) {
175 perigee_[0] = x_;
176 perigee_[1] = y_;
177 perigee_[2] = z_;
178 }
179
180 void setMomentum(const double& px, const double& py, const double& pz) {
181 momentum_[0] = px;
182 momentum_[1] = py;
183 momentum_[2] = pz;
184 }
185
186 void setPosition(const double& x_, const double& y_, const double& z_) {
187 position_[0] = x_;
188 position_[1] = y_;
189 position_[2] = z_;
190 }
191
192 std::vector<double> getPerigeeLocation() const { return perigee_; };
193 double getPerigeeX() const { return perigee_[0]; };
194 double getPerigeeY() const { return perigee_[1]; };
195 double getPerigeeZ() const { return perigee_[2]; };
196
197 std::vector<double> getMomentum() const { return momentum_; };
198 std::vector<double> getPosition() const { return position_; };
199
200 // getters -- TODO use an enum instead
201
202 double getD0() const { return perigee_pars_[0]; };
203 double getZ0() const { return perigee_pars_[1]; };
204 double getPhi() const { return perigee_pars_[2]; };
205 double getTheta() const { return perigee_pars_[3]; };
206 double getQoP() const { return perigee_pars_[4]; };
207 double getT() const { return perigee_pars_[5]; };
208
209 void addTrackState(const ldmx::Track::TrackState& ts) {
210 track_states_.push_back(ts);
211 };
212
213 std::vector<TrackState> getTrackStates() const { return track_states_; }
214
215 protected:
216 int n_hits_{0};
217 int n_outliers_{0};
218 int ndf_{0};
219 int n_shared_hits_{0};
220 int n_holes_{0};
221
222 // particle hypothesis if truth track
223 // int pdgID_{0};
224
225 double chi2_{0};
226
227 // The parameters and covariance matrix wrt the perigee surface
228 // Acts::BoundVector perigee_pars_;
229 // Acts::BoundSymMatrix perigee_cov_;
230
231 // 6 elements
232 // d0 / z0 / phi / theta / qop / t
233 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
234
235 // 21 elements
236 // d0d0 d0z0 d0phi d0th d0qop d0t
237 // z0z0 z0phi z0th z0qop z0t
238 // phph phith phqop pht
239 // thth thqop tht
240 // qopqop qopt
241 // t
242 std::vector<double> perigee_cov_;
243
244 // The perigee location
245 std::vector<double> perigee_{0., 0., 0.};
246
247 // The 3-momentum at the perigee
248 std::vector<double> momentum_{0., 0., 0.};
249
250 // The 3-position at the perigee
251 std::vector<double> position_{0., 0., 0.};
252
253 // The vector of measurement IDs
254 std::vector<unsigned int> meas_idxs_{};
255
256 // The vector of outlier IDs
257 std::vector<unsigned int> outlier_idxs_{};
258
259 // The vector of hole IDs
260 std::vector<unsigned int> hole_idxs_{};
261
262 // The vector of shared hit IDs
263 std::vector<unsigned int> shared_idxs_{};
264
265 // The vector of dE/dx measurements (in MeV/mm)
266 std::vector<float> dedx_measurements_{};
267
268 // ID of the matched particle in the SimParticles map
269 int track_id_{-1};
270
271 // Truth probability
272 double truth_prob_{0.};
273
274 // pdgID
275 int pdg_id_{0};
276
277 // Track States
278 std::vector<TrackState> track_states_;
279
282
283}; // Track
284
285typedef std::vector<ldmx::Track> Tracks;
286// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
287
288} // namespace ldmx
289
290#endif // TRACKING_EVENT_TRACK_H_
Implementation of a track object.
Definition Track.h:53
void setPerigeeParameters(const std::vector< double > &par)
d_0 z_0 phi_0 theta q/p t
Definition Track.h:161
friend std::ostream & operator<<(std::ostream &o, const Track &d)
Print the string representation of this object.
Definition Track.cxx:8
virtual ~Track()
Destructor.
Definition Track.h:72
ClassDef(Track, 5)
Class declaration needed by the ROOT dictionary.