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
143 // void setPerigeeParameters(const Acts::BoundVector& par) {perigee_pars_ =
144 // par; } Acts::BoundVector getPerigeeParameters() {return perigee_pars_;}
145
146 // void setPerigeeCov(const Acts::BoundMatrix& cov) {perigee_cov_ = cov;}
147 // Acts::BoundMatrix getPerigeeCov() {return perigee_cov_;}
148
149 // void setPerigeeState(const Acts::BoundVector& par, const Acts::BoundMatrix&
150 // cov) {
151 // perigee_pars_ = par;
152 // perigee_cov_ = cov;
153 // }
154
155 // Vector representation
156 void setPerigeeParameters(const std::vector<double>& par) {
157 perigee_pars_ = par;
158 }
159 std::vector<double> getPerigeeParameters() const { return perigee_pars_; }
160
161 void setPerigeeCov(const std::vector<double>& cov) { perigee_cov_ = cov; }
162 std::vector<double> getPerigeeCov() const { return perigee_cov_; }
163
164 void setPerigeeLocation(const std::vector<double>& perigee) {
165 perigee_ = perigee;
166 }
167
168 void setPerigeeLocation(const double& x_, const double& y_,
169 const double& z_) {
170 perigee_[0] = x_;
171 perigee_[1] = y_;
172 perigee_[2] = z_;
173 }
174
175 void setMomentum(const double& px, const double& py, const double& pz) {
176 momentum_[0] = px;
177 momentum_[1] = py;
178 momentum_[2] = pz;
179 }
180
181 void setPosition(const double& x_, const double& y_, const double& z_) {
182 position_[0] = x_;
183 position_[1] = y_;
184 position_[2] = z_;
185 }
186
187 std::vector<double> getPerigeeLocation() const { return perigee_; };
188 double getPerigeeX() const { return perigee_[0]; };
189 double getPerigeeY() const { return perigee_[1]; };
190 double getPerigeeZ() const { return perigee_[2]; };
191
192 std::vector<double> getMomentum() const { return momentum_; };
193 std::vector<double> getPosition() const { return position_; };
194
195 // getters -- TODO use an enum instead
196
197 double getD0() const { return perigee_pars_[0]; };
198 double getZ0() const { return perigee_pars_[1]; };
199 double getPhi() const { return perigee_pars_[2]; };
200 double getTheta() const { return perigee_pars_[3]; };
201 double getQoP() const { return perigee_pars_[4]; };
202 double getT() const { return perigee_pars_[5]; };
203
204 void addTrackState(const ldmx::Track::TrackState& ts) {
205 track_states_.push_back(ts);
206 };
207
208 std::vector<TrackState> getTrackStates() const { return track_states_; }
209
210 protected:
211 int n_hits_{0};
212 int n_outliers_{0};
213 int ndf_{0};
214 int n_shared_hits_{0};
215 int n_holes_{0};
216
217 // particle hypothesis if truth track
218 // int pdgID_{0};
219
220 double chi2_{0};
221
222 // The parameters and covariance matrix wrt the perigee surface
223 // Acts::BoundVector perigee_pars_;
224 // Acts::BoundSymMatrix perigee_cov_;
225
226 // 6 elements
227 // d0 / z0 / phi / theta / qop / t
228 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
229
230 // 21 elements
231 // d0d0 d0z0 d0phi d0th d0qop d0t
232 // z0z0 z0phi z0th z0qop z0t
233 // phph phith phqop pht
234 // thth thqop tht
235 // qopqop qopt
236 // t
237 std::vector<double> perigee_cov_;
238
239 // The perigee location
240 std::vector<double> perigee_{0., 0., 0.};
241
242 // The 3-momentum at the perigee
243 std::vector<double> momentum_{0., 0., 0.};
244
245 // The 3-position at the perigee
246 std::vector<double> position_{0., 0., 0.};
247
248 // The vector of measurement IDs
249 std::vector<unsigned int> meas_idxs_{};
250
251 // The vector of outlier IDs
252 std::vector<unsigned int> outlier_idxs_{};
253
254 // The vector of hole IDs
255 std::vector<unsigned int> hole_idxs_{};
256
257 // The vector of shared hit IDs
258 std::vector<unsigned int> shared_idxs_{};
259
260 // ID of the matched particle in the SimParticles map
261 int track_id_{-1};
262
263 // Truth probability
264 double truth_prob_{0.};
265
266 // pdgID
267 int pdg_id_{0};
268
269 // Track States
270 std::vector<TrackState> track_states_;
271
274
275}; // Track
276
277typedef std::vector<ldmx::Track> Tracks;
278// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
279
280} // namespace ldmx
281
282#endif // TRACKING_EVENT_TRACK_H_
Implementation of a track object.
Definition Track.h:53
ClassDef(Track, 4)
Class declaration needed by the ROOT dictionary.
void setPerigeeParameters(const std::vector< double > &par)
d_0 z_0 phi_0 theta q/p t
Definition Track.h:156
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