32 const Acts::GeometryContext& gctx,
33 const Acts::MagneticFieldContext& mctx)
34 : propagator_(std::move(propagator)) {
45 void setMaxStepSize(
double step) { max_step_size_ = step; }
46 void setPathLimit(
double limit) { path_limit_ = limit; }
57 typename propagator_t::template Options<ActionList, AbortList>;
59 std::optional<Acts::BoundTrackParameters> extrapolate(
60 const Acts::BoundTrackParameters pars,
61 const std::shared_ptr<Acts::Surface>& target_surface) {
62 auto intersection = target_surface->intersect(gctx_, pars.position(gctx_),
66 if (max_step_size_ > 0) p_options.stepping.maxStepSize = max_step_size_;
67 if (path_limit_ > 0) p_options.pathLimit = path_limit_;
69 p_options.direction = intersection.intersections()[0].pathLength() >= 0
70 ? Acts::Direction::Forward
71 : Acts::Direction::Backward;
73 auto result = propagator_.propagate(pars, *target_surface, p_options);
79 std::cout <<
"INITIAL COV MATRIX\n";
80 std::cout << (*(pars.covariance())) << std::endl;
82 std::cout <<
"FINAL COV MATRIX\n";
83 auto opt_pars = *result->endParameters;
84 std::cout << *(opt_pars.covariance()) << std::endl;
89 return *result->endParameters;
104 template <
class track_t>
106 track_t track,
const std::shared_ptr<Acts::Surface>& target_surface) {
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;
118 <<
"[TrackExtrapolatorTool] Getting outermost track state...\n";
119 auto outermost = *(track.trackStatesReversed().begin());
122 <<
"[TrackExtrapolatorTool] Getting innermost track state...\n";
123 auto begin = track.trackStatesReversed().begin();
124 std::advance(begin, track.nTrackStates() - 1);
125 auto innermost = *begin;
127 std::cout <<
"[TrackExtrapolatorTool] Got innermost and outermost "
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));
139 double last_dis = std::abs(
140 outermost.referenceSurface().transform(gctx_).translation()(0) -
141 target_surface->transform(gctx_).translation()(0));
143 std::cout <<
"[TrackExtrapolatorTool] first_dis = " << first_dis
144 <<
", last_dis = " << last_dis << std::endl;
148 const auto& ts = first_dis < last_dis ? innermost : outermost;
149 if (debug_) std::cout <<
"[TrackExtrapolatorTool] Selected track state\n";
154 std::cout <<
"[TrackExtrapolatorTool] Getting reference surface...\n";
155 const auto& surface = ts.referenceSurface();
157 std::cout <<
"[TrackExtrapolatorTool] Checking hasSmoothed...\n";
158 bool has_smoothed = ts.hasSmoothed();
160 std::cout <<
"[TrackExtrapolatorTool] has_smoothed = " << has_smoothed
164 Acts::BoundVector params;
165 Acts::BoundMatrix cov;
169 std::cout <<
"[TrackExtrapolatorTool] Using smoothed parameters...\n";
170 params = ts.smoothed();
171 cov = ts.smoothedCovariance();
174 std::cout <<
"[TrackExtrapolatorTool] Using filtered parameters...\n";
175 params = ts.filtered();
176 cov = ts.filteredCovariance();
179 std::cout <<
"[TrackExtrapolatorTool] Got all track state components\n";
182 std::cout <<
"Surface::" << surface.transform(gctx_).translation()
184 std::cout <<
"HasSmoothed::" << has_smoothed << std::endl;
185 std::cout <<
"Parameters::" << params.transpose() << std::endl;
190 <<
"[TrackExtrapolatorTool] Creating BoundTrackParameters...\n";
191 auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
192 Acts::BoundTrackParameters sp(surface.getSharedPtr(), params, cov,
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";
211 template <
class track_t>
213 track_t track,
const std::shared_ptr<Acts::Surface>& target_surface) {
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();
227 auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
229 Acts::BoundTrackParameters state_parameters(surface.getSharedPtr(),
230 smoothed, cov, part_hypo);
235 propagator_.propagate(state_parameters, *target_surface, p_options);
238 return *result->endParameters;
253 template <
class track_t>
255 const std::shared_ptr<Acts::Surface>& target_surface,
257 ldmx::TrackStateType type) {
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";
269 auto opt_pars = extrapolate(track, target_surface);
272 std::cout <<
"[TrackExtrapolatorTool] extrapolate returned, "
273 "opt_pars.has_value() = "
274 << opt_pars.has_value() << std::endl;
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)
285 ts = tracking::sim::utils::makeTrackState(gctx_, *opt_pars, type);
287 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface SUCCESS\n";
291 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface FAILED - "
292 "opt_pars is empty\n";
298 propagator_t propagator_;
299 Acts::GeometryContext gctx_;
300 Acts::MagneticFieldContext mctx_;
302 double max_step_size_{-1};
303 double path_limit_{-1};