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 refX, refY, refZ;
60 std::vector<double> params;
61 std::vector<double> cov;
62 TrackStateType ts_type;
63 };
64
65 Track(){};
66
72 virtual ~Track(){};
73
79 void Print() const;
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 : trackStates_)
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) { trackID_ = trackid; };
110 int getTrackID() const { return trackID_; };
111
112 void setTruthProb(double truthProb) { truthProb_ = truthProb; };
113 double getTruthProb() const { return truthProb_; };
114
115 void setPdgID(int pdgID) { pdgID_ = pdgID; };
116 int getPdgID() const { return pdgID_; };
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, const double& z) {
169 perigee_[0] = x;
170 perigee_[1] = y;
171 perigee_[2] = z;
172 }
173
174 void setMomentum(const double& px, const double& py, const double& pz) {
175 momentum_[0] = px;
176 momentum_[1] = py;
177 momentum_[2] = pz;
178 }
179
180 void setPosition(const double& x, const double& y, const double& z) {
181 position_[0] = x;
182 position_[1] = y;
183 position_[2] = z;
184 }
185
186 std::vector<double> getPerigeeLocation() const { return perigee_; };
187 double getPerigeeX() const { return perigee_[0]; };
188 double getPerigeeY() const { return perigee_[1]; };
189 double getPerigeeZ() const { return perigee_[2]; };
190
191 std::vector<double> getMomentum() const { return momentum_; };
192 std::vector<double> getPosition() const { return position_; };
193
194 // getters -- TODO use an enum instead
195
196 double getD0() const { return perigee_pars_[0]; };
197 double getZ0() const { return perigee_pars_[1]; };
198 double getPhi() const { return perigee_pars_[2]; };
199 double getTheta() const { return perigee_pars_[3]; };
200 double getQoP() const { return perigee_pars_[4]; };
201 double getT() const { return perigee_pars_[5]; };
202
203 void addTrackState(const ldmx::Track::TrackState& ts) {
204 trackStates_.push_back(ts);
205 };
206
207 std::vector<TrackState> getTrackStates() const { return trackStates_; }
208
209 protected:
210 int n_hits_{0};
211 int n_outliers_{0};
212 int ndf_{0};
213 int n_shared_hits_{0};
214 int n_holes_{0};
215
216 // particle hypothesis if truth track
217 // int pdgID_{0};
218
219 double chi2_{0};
220
221 // The parameters and covariance matrix wrt the perigee surface
222 // Acts::BoundVector perigee_pars_;
223 // Acts::BoundSymMatrix perigee_cov_;
224
225 // 6 elements
226 // d0 / z0 / phi / theta / qop / t
227 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
228
229 // 21 elements
230 // d0d0 d0z0 d0phi d0th d0qop d0t
231 // z0z0 z0phi z0th z0qop z0t
232 // phph phith phqop pht
233 // thth thqop tht
234 // qopqop qopt
235 // t
236 std::vector<double> perigee_cov_;
237
238 // The perigee location
239 std::vector<double> perigee_{0., 0., 0.};
240
241 // The 3-momentum at the perigee
242 std::vector<double> momentum_{0., 0., 0.};
243
244 // The 3-position at the perigee
245 std::vector<double> position_{0., 0., 0.};
246
247 // The vector of measurement IDs
248 std::vector<unsigned int> meas_idxs_{};
249
250 // The vector of outlier IDs
251 std::vector<unsigned int> outlier_idxs_{};
252
253 // The vector of hole IDs
254 std::vector<unsigned int> hole_idxs_{};
255
256 // The vector of shared hit IDs
257 std::vector<unsigned int> shared_idxs_{};
258
259 // ID of the matched particle in the SimParticles map
260 int trackID_{-1};
261
262 // Truth probability
263 double truthProb_{0.};
264
265 // pdgID
266 int pdgID_{0};
267
268 // Track States
269 std::vector<TrackState> trackStates_;
270
273
274}; // Track
275
276typedef std::vector<ldmx::Track> Tracks;
277// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
278
279} // namespace ldmx
280
281#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:156
ClassDef(Track, 3)
Class declaration needed by the ROOT dictionary.
virtual ~Track()
Destructor.
Definition Track.h:72
void Print() const
Print the string representation of this object.