LDMX Software
tracking::reco::TrackExtrapolatorTool< propagator_t > Class Template Reference

Public Types

using PropagatorOptions
 Method to extrapolate to a target surface given a set of BoundTrackParameters.
 

Public Member Functions

 TrackExtrapolatorTool (propagator_t propagator, const Acts::GeometryContext &gctx, const Acts::MagneticFieldContext &mctx)
 
void setDebug (bool debug)
 Turn on/off internal debug flag.
 
void setMaxStepSize (double step)
 
void setPathLimit (double limit)
 
std::optional< Acts::BoundTrackParameters > extrapolate (const Acts::BoundTrackParameters pars, const std::shared_ptr< Acts::Surface > &target_surface)
 
template<class track_t >
std::optional< Acts::BoundTrackParameters > extrapolate (track_t track, const std::shared_ptr< Acts::Surface > &target_surface)
 Method to extrapolate to a target surface given a track The method computes which track state is closest to the surface to choose which one to use to extrapolate.
 
template<class track_t >
std::optional< Acts::BoundTrackParameters > extrapolateToEcal (track_t track, const std::shared_ptr< Acts::Surface > &target_surface)
 Create an ldmx::TrackState to the extrapolated position.
 
template<class track_t >
bool trackStateAtSurface (track_t track, const std::shared_ptr< Acts::Surface > &target_surface, ldmx::Track::TrackState &ts, ldmx::TrackStateType type)
 Create an ldmx::TrackState to the extrapolated position.
 

Private Attributes

propagator_t propagator_
 
Acts::GeometryContext gctx_
 
Acts::MagneticFieldContext mctx_
 
bool debug_ {false}
 
double max_step_size_ {-1}
 
double path_limit_ {-1}
 

Detailed Description

template<class propagator_t>
class tracking::reco::TrackExtrapolatorTool< propagator_t >

Definition at line 28 of file TrackExtrapolatorTool.h.

Member Typedef Documentation

◆ PropagatorOptions

template<class propagator_t >
using tracking::reco::TrackExtrapolatorTool< propagator_t >::PropagatorOptions
Initial value:
typename propagator_t::template Options<ActionList, AbortList>

Method to extrapolate to a target surface given a set of BoundTrackParameters.

Parameters
parsBound Track Parameters
target_target_surfaceThe target surface
Returns
optional with BoundTrackParameters

Definition at line 56 of file TrackExtrapolatorTool.h.

Constructor & Destructor Documentation

◆ TrackExtrapolatorTool()

template<class propagator_t >
tracking::reco::TrackExtrapolatorTool< propagator_t >::TrackExtrapolatorTool ( propagator_t propagator,
const Acts::GeometryContext & gctx,
const Acts::MagneticFieldContext & mctx )
inline

Definition at line 31 of file TrackExtrapolatorTool.h.

34 : propagator_(std::move(propagator)) {
35 gctx_ = gctx;
36 mctx_ = mctx;
37 }

Member Function Documentation

◆ extrapolate() [1/2]

template<class propagator_t >
std::optional< Acts::BoundTrackParameters > tracking::reco::TrackExtrapolatorTool< propagator_t >::extrapolate ( const Acts::BoundTrackParameters pars,
const std::shared_ptr< Acts::Surface > & target_surface )
inline

Definition at line 59 of file TrackExtrapolatorTool.h.

61 {
62 auto intersection = target_surface->intersect(gctx_, pars.position(gctx_),
63 pars.direction());
64
65 PropagatorOptions p_options(gctx_, mctx_);
66 if (max_step_size_ > 0) p_options.stepping.maxStepSize = max_step_size_;
67 if (path_limit_ > 0) p_options.pathLimit = path_limit_;
68
69 p_options.direction = intersection.intersections()[0].pathLength() >= 0
70 ? Acts::Direction::Forward
71 : Acts::Direction::Backward;
72
73 auto result = propagator_.propagate(pars, *target_surface, p_options);
74
75 // CHECK THE EXTRAPOLATION COVARIANCE MATRIX
76
77 if (debug_) {
78 if (result.ok()) {
79 std::cout << "INITIAL COV MATRIX\n";
80 std::cout << (*(pars.covariance())) << std::endl;
81
82 std::cout << "FINAL COV MATRIX\n";
83 auto opt_pars = *result->endParameters;
84 std::cout << *(opt_pars.covariance()) << std::endl;
85 }
86 }
87
88 if (result.ok())
89 return *result->endParameters;
90 else
91 return std::nullopt;
92 } // end of extrapolate()
typename propagator_t::template Options< ActionList, AbortList > PropagatorOptions
Method to extrapolate to a target surface given a set of BoundTrackParameters.

◆ extrapolate() [2/2]

template<class propagator_t >
template<class track_t >
std::optional< Acts::BoundTrackParameters > tracking::reco::TrackExtrapolatorTool< propagator_t >::extrapolate ( track_t track,
const std::shared_ptr< Acts::Surface > & target_surface )
inline

Method to extrapolate to a target surface given a track The method computes which track state is closest to the surface to choose which one to use to extrapolate.

This method doesn't use a measurement, but whatever first/last track state is defined.

Parameters
trackAn Acts::Track
target_surfaceThe target surface
Returns
optional containing the bound track parameters.

Definition at line 105 of file TrackExtrapolatorTool.h.

106 {
107 if (debug_) {
108 std::cout << "[TrackExtrapolatorTool] extrapolate START\n";
109 std::cout << "[TrackExtrapolatorTool] track.nTrackStates() = "
110 << track.nTrackStates() << std::endl;
111 std::cout << "[TrackExtrapolatorTool] target_surface = "
112 << target_surface.get() << std::endl;
113 }
114
115 // get first and last track state on surface
116 if (debug_)
117 std::cout
118 << "[TrackExtrapolatorTool] Getting outermost track state...\n";
119 auto outermost = *(track.trackStatesReversed().begin());
120 if (debug_)
121 std::cout
122 << "[TrackExtrapolatorTool] Getting innermost track state...\n";
123 auto begin = track.trackStatesReversed().begin();
124 std::advance(begin, track.nTrackStates() - 1);
125 auto innermost = *begin;
126 if (debug_)
127 std::cout << "[TrackExtrapolatorTool] Got innermost and outermost "
128 "track states\n";
129
130 // I'm checking which track state is closer to the origin of the target
131 // surface to decide from where to start the extrapolation to the surface. I
132 // use the coordinate along the beam axis.
133 if (debug_)
134 std::cout << "[TrackExtrapolatorTool] Calculating distances...\n";
135 double first_dis = std::abs(
136 innermost.referenceSurface().transform(gctx_).translation()(0) -
137 target_surface->transform(gctx_).translation()(0));
138
139 double last_dis = std::abs(
140 outermost.referenceSurface().transform(gctx_).translation()(0) -
141 target_surface->transform(gctx_).translation()(0));
142 if (debug_)
143 std::cout << "[TrackExtrapolatorTool] first_dis = " << first_dis
144 << ", last_dis = " << last_dis << std::endl;
145
146 // This is the track state to use for the extrapolation
147
148 const auto& ts = first_dis < last_dis ? innermost : outermost;
149 if (debug_) std::cout << "[TrackExtrapolatorTool] Selected track state\n";
150
151 // Get the BoundTrackStateParameters
152
153 if (debug_)
154 std::cout << "[TrackExtrapolatorTool] Getting reference surface...\n";
155 const auto& surface = ts.referenceSurface();
156 if (debug_)
157 std::cout << "[TrackExtrapolatorTool] Checking hasSmoothed...\n";
158 bool has_smoothed = ts.hasSmoothed();
159 if (debug_)
160 std::cout << "[TrackExtrapolatorTool] has_smoothed = " << has_smoothed
161 << std::endl;
162
163 // Use smoothed parameters if available, otherwise use filtered
164 Acts::BoundVector params;
165 Acts::BoundMatrix cov;
166
167 if (has_smoothed) {
168 if (debug_)
169 std::cout << "[TrackExtrapolatorTool] Using smoothed parameters...\n";
170 params = ts.smoothed();
171 cov = ts.smoothedCovariance();
172 } else {
173 if (debug_)
174 std::cout << "[TrackExtrapolatorTool] Using filtered parameters...\n";
175 params = ts.filtered();
176 cov = ts.filteredCovariance();
177 }
178 if (debug_)
179 std::cout << "[TrackExtrapolatorTool] Got all track state components\n";
180
181 if (debug_) {
182 std::cout << "Surface::" << surface.transform(gctx_).translation()
183 << std::endl;
184 std::cout << "HasSmoothed::" << has_smoothed << std::endl;
185 std::cout << "Parameters::" << params.transpose() << std::endl;
186 }
187 // mg Aug 2024 ... v36 takes the particle...assume electron
188 if (debug_)
189 std::cout
190 << "[TrackExtrapolatorTool] Creating BoundTrackParameters...\n";
191 auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
192 Acts::BoundTrackParameters sp(surface.getSharedPtr(), params, cov,
193 part_hypo);
194 if (debug_)
195 std::cout << "[TrackExtrapolatorTool] BoundTrackParameters created, "
196 "calling extrapolate(BTP)...\n";
197 auto result = extrapolate(sp, target_surface);
198 if (debug_) std::cout << "[TrackExtrapolatorTool] extrapolate DONE\n";
199 return result;
200 }

◆ extrapolateToEcal()

template<class propagator_t >
template<class track_t >
std::optional< Acts::BoundTrackParameters > tracking::reco::TrackExtrapolatorTool< propagator_t >::extrapolateToEcal ( track_t track,
const std::shared_ptr< Acts::Surface > & target_surface )
inline

Create an ldmx::TrackState to the extrapolated position.

Parameters
trackActs::Track
target_surfaceextrapolation surface
tsldmx::Track::TrackState
typeTrackStateType
Returns
optional boolean to check if there was a problem in the extrapolation

Definition at line 212 of file TrackExtrapolatorTool.h.

213 {
214 // get last track state on the track.
215 // Now.. I'm taking whatever it is. I'm not checking here if it is a
216 // measurement.
217
218 auto& tsc = track.container().trackStateContainer();
219 auto begin = track.trackStates().begin();
220 auto ts_last = *begin;
221 const auto& surface = (ts_last).referenceSurface();
222 const auto& smoothed = (ts_last).smoothed();
223 const auto& cov = (ts_last).smoothedCovariance();
224
225 // Get the BoundTrackStateParameters
226 // assume electron for now
227 auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
228
229 Acts::BoundTrackParameters state_parameters(surface.getSharedPtr(),
230 smoothed, cov, part_hypo);
231
232 // One can also use directly the extrapolate method
233 PropagatorOptions p_options(gctx_, mctx_);
234 auto result =
235 propagator_.propagate(state_parameters, *target_surface, p_options);
236
237 if (result.ok())
238 return *result->endParameters;
239 else
240 return std::nullopt;
241 }

◆ setDebug()

template<class propagator_t >
void tracking::reco::TrackExtrapolatorTool< propagator_t >::setDebug ( bool debug)
inline

Turn on/off internal debug flag.

Parameters
debug

Definition at line 44 of file TrackExtrapolatorTool.h.

44{ debug_ = debug; }

◆ setMaxStepSize()

template<class propagator_t >
void tracking::reco::TrackExtrapolatorTool< propagator_t >::setMaxStepSize ( double step)
inline

Definition at line 45 of file TrackExtrapolatorTool.h.

45{ max_step_size_ = step; }

◆ setPathLimit()

template<class propagator_t >
void tracking::reco::TrackExtrapolatorTool< propagator_t >::setPathLimit ( double limit)
inline

Definition at line 46 of file TrackExtrapolatorTool.h.

46{ path_limit_ = limit; }

◆ trackStateAtSurface()

template<class propagator_t >
template<class track_t >
bool tracking::reco::TrackExtrapolatorTool< propagator_t >::trackStateAtSurface ( track_t track,
const std::shared_ptr< Acts::Surface > & target_surface,
ldmx::Track::TrackState & ts,
ldmx::TrackStateType type )
inline

Create an ldmx::TrackState to the extrapolated position.

Parameters
trackActs::Track
target_surfaceextrapolation surface
tsldmx::Track::TrackState
typeTrackStateType
Returns
boolean to check if there was a problem in the extrapolation

Definition at line 254 of file TrackExtrapolatorTool.h.

257 {
258 if (debug_) {
259 std::cout << "[TrackExtrapolatorTool] trackStateAtSurface START\n";
260 std::cout << "[TrackExtrapolatorTool] target_surface = "
261 << target_surface.get() << std::endl;
262 std::cout << "[TrackExtrapolatorTool] track.nTrackStates() = "
263 << track.nTrackStates() << std::endl;
264 std::cout << "[TrackExtrapolatorTool] TrackStateType = "
265 << static_cast<int>(type) << std::endl;
266 std::cout << "[TrackExtrapolatorTool] About to call extrapolate...\n";
267 }
268
269 auto opt_pars = extrapolate(track, target_surface);
270
271 if (debug_) {
272 std::cout << "[TrackExtrapolatorTool] extrapolate returned, "
273 "opt_pars.has_value() = "
274 << opt_pars.has_value() << std::endl;
275 }
276
277 if (opt_pars) {
278 if (debug_) {
279 Acts::Vector3 surf_loc = target_surface->transform(gctx_).translation();
280 std::cout << "[TrackExtrapolatorTool] Surface location: ("
281 << surf_loc(0) << ", " << surf_loc(1) << ", " << surf_loc(2)
282 << ")\n";
283 }
284
285 ts = tracking::sim::utils::makeTrackState(gctx_, *opt_pars, type);
286 if (debug_)
287 std::cout << "[TrackExtrapolatorTool] trackStateAtSurface SUCCESS\n";
288 return true;
289 } else {
290 if (debug_)
291 std::cout << "[TrackExtrapolatorTool] trackStateAtSurface FAILED - "
292 "opt_pars is empty\n";
293 return false;
294 }
295 }

Member Data Documentation

◆ debug_

template<class propagator_t >
bool tracking::reco::TrackExtrapolatorTool< propagator_t >::debug_ {false}
private

Definition at line 301 of file TrackExtrapolatorTool.h.

301{false};

◆ gctx_

template<class propagator_t >
Acts::GeometryContext tracking::reco::TrackExtrapolatorTool< propagator_t >::gctx_
private

Definition at line 299 of file TrackExtrapolatorTool.h.

◆ max_step_size_

template<class propagator_t >
double tracking::reco::TrackExtrapolatorTool< propagator_t >::max_step_size_ {-1}
private

Definition at line 302 of file TrackExtrapolatorTool.h.

302{-1};

◆ mctx_

template<class propagator_t >
Acts::MagneticFieldContext tracking::reco::TrackExtrapolatorTool< propagator_t >::mctx_
private

Definition at line 300 of file TrackExtrapolatorTool.h.

◆ path_limit_

template<class propagator_t >
double tracking::reco::TrackExtrapolatorTool< propagator_t >::path_limit_ {-1}
private

Definition at line 303 of file TrackExtrapolatorTool.h.

303{-1};

◆ propagator_

template<class propagator_t >
propagator_t tracking::reco::TrackExtrapolatorTool< propagator_t >::propagator_
private

Definition at line 298 of file TrackExtrapolatorTool.h.


The documentation for this class was generated from the following file: