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};
43
52class Track {
53 public:
54 // Track states won't be visualized in the root tree from the TBrowser, but it
55 // will be accessible when reading back the rootfile using for example the
56 // monitoring code.
57 struct TrackState {
58 double refX, refY, refZ;
59 std::vector<double> params;
60 std::vector<double> cov;
61 TrackStateType ts_type;
62 };
63
64 Track(){};
65
71 virtual ~Track(){};
72
78 void Print() const;
79
80 // To match the Framework Bus clear. It's doing nothing
81 void Clear(){};
82
83 void setNhits(int nhits) { n_hits_ = nhits; }
84 int getNhits() const { return n_hits_; }
85
86 std::optional<TrackState> getTrackState(TrackStateType tstype) const {
87 for (auto ts : trackStates_)
88 if (ts.ts_type == tstype) return std::optional<TrackState>(ts);
89
90 return std::nullopt;
91 }
92
93 // void setNholes(int nholes) {n_holes_ = nholes;}
94 // int getNholes() const {return n_holes_;}
95
96 void setNoutliers(int nout) { n_outliers_ = nout; }
97 int getNoutliers() const { return n_outliers_; }
98
99 void setNdf(int ndf) { ndf_ = ndf; }
100 int getNdf() const { return ndf_; };
101
102 void setNsharedHits(int nsh) { n_shared_hits_ = nsh; }
103 int getNsharedHits() const { return n_shared_hits_; }
104
105 void setChi2(double chi2) { chi2_ = chi2; }
106 double getChi2() const { return chi2_; }
107
108 void setTrackID(int trackid) { trackID_ = trackid; };
109 int getTrackID() const { return trackID_; };
110
111 void setTruthProb(double truthProb) { truthProb_ = truthProb; };
112 double getTruthProb() const { return truthProb_; };
113
114 void setPdgID(int pdgID) { pdgID_ = pdgID; };
115 int getPdgID() const { return pdgID_; };
116
117 // in units of e
118 int q() const { return perigee_pars_[4] > 0 ? 1 : -1; }
119
120 // Add measurement indices to tracks
121 // For reco tracks they corresponds to the indices in the measurement
122 // container For truth tracks they corresponds to the indices of the
123 // SimHitCointainer
124
125 void addMeasurementIndex(unsigned int measIdx) {
126 meas_idxs_.push_back(measIdx);
127 }
128 std::vector<unsigned int> getMeasurementsIdxs() const { return meas_idxs_; }
129
131 // void setPerigeeParameters(const Acts::BoundVector& par) {perigee_pars_ =
132 // par; } Acts::BoundVector getPerigeeParameters() {return perigee_pars_;}
133
134 // void setPerigeeCov(const Acts::BoundMatrix& cov) {perigee_cov_ = cov;}
135 // Acts::BoundMatrix getPerigeeCov() {return perigee_cov_;}
136
137 // void setPerigeeState(const Acts::BoundVector& par, const Acts::BoundMatrix&
138 // cov) {
139 // perigee_pars_ = par;
140 // perigee_cov_ = cov;
141 // }
142
143 // Vector representation
144 void setPerigeeParameters(const std::vector<double>& par) {
145 perigee_pars_ = par;
146 }
147 std::vector<double> getPerigeeParameters() const { return perigee_pars_; }
148
149 void setPerigeeCov(const std::vector<double>& cov) { perigee_cov_ = cov; }
150 std::vector<double> getPerigeeCov() const { return perigee_cov_; }
151
152 void setPerigeeLocation(const std::vector<double>& perigee) {
153 perigee_ = perigee;
154 }
155
156 void setPerigeeLocation(const double& x, const double& y, const double& z) {
157 perigee_[0] = x;
158 perigee_[1] = y;
159 perigee_[2] = z;
160 }
161
162 void setMomentum(const double& px, const double& py, const double& pz) {
163 momentum_[0] = px;
164 momentum_[1] = py;
165 momentum_[2] = pz;
166 }
167
168 void setPosition(const double& x, const double& y, const double& z) {
169 position_[0] = x;
170 position_[1] = y;
171 position_[2] = z;
172 }
173
174 std::vector<double> getPerigeeLocation() const { return perigee_; };
175 double getPerigeeX() const { return perigee_[0]; };
176 double getPerigeeY() const { return perigee_[1]; };
177 double getPerigeeZ() const { return perigee_[2]; };
178
179 std::vector<double> getMomentum() const { return momentum_; };
180 std::vector<double> getPosition() const { return position_; };
181
182 // getters -- TODO use an enum instead
183
184 double getD0() const { return perigee_pars_[0]; };
185 double getZ0() const { return perigee_pars_[1]; };
186 double getPhi() const { return perigee_pars_[2]; };
187 double getTheta() const { return perigee_pars_[3]; };
188 double getQoP() const { return perigee_pars_[4]; };
189 double getT() const { return perigee_pars_[5]; };
190
191 void addTrackState(const ldmx::Track::TrackState& ts) {
192 trackStates_.push_back(ts);
193 };
194
195 std::vector<TrackState> getTrackStates() const { return trackStates_; }
196
197 protected:
198 int n_hits_{0};
199 int n_outliers_{0};
200 int ndf_{0};
201 int n_shared_hits_{0};
202 int n_holes_{0};
203
204 // particle hypothesis if truth track
205 // int pdgID_{0};
206
207 double chi2_{0};
208
209 // The parameters and covariance matrix wrt the perigee surface
210 // Acts::BoundVector perigee_pars_;
211 // Acts::BoundSymMatrix perigee_cov_;
212
213 // 6 elements
214 // d0 / z0 / phi / theta / qop / t
215 std::vector<double> perigee_pars_{0., 0., 0., 0., 0., 0.};
216
217 // 21 elements
218 // d0d0 d0z0 d0phi d0th d0qop d0t
219 // z0z0 z0phi z0th z0qop z0t
220 // phph phith phqop pht
221 // thth thqop tht
222 // qopqop qopt
223 // t
224 std::vector<double> perigee_cov_;
225
226 // The perigee location
227 std::vector<double> perigee_{0., 0., 0.};
228
229 // The 3-momentum at the perigee
230 std::vector<double> momentum_{0., 0., 0.};
231
232 // The 3-position at the perigee
233 std::vector<double> position_{0., 0., 0.};
234
235 // The vector of measurement IDs
236 std::vector<unsigned int> meas_idxs_{};
237
238 // ID of the matched particle in the SimParticles map
239 int trackID_{-1};
240
241 // Truth probability
242 double truthProb_{0.};
243
244 // pdgID
245 int pdgID_{0};
246
247 // Track States
248 std::vector<TrackState> trackStates_;
249
252
253}; // Track
254
255typedef std::vector<ldmx::Track> Tracks;
256// typedef std::vector<std::reference_wrapper<const ldmx::Track>> Tracks;
257
258} // namespace ldmx
259
260#endif // TRACKING_EVENT_TRACK_H_
Implementation of a track object.
Definition Track.h:52
ClassDef(Track, 2)
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:144
virtual ~Track()
Destructor.
Definition Track.h:71
void Print() const
Print the string representation of this object.