29 const Acts::GeometryContext& gctx,
30 const Acts::MagneticFieldContext& mctx)
31 : propagator_(std::move(propagator)), gctx_(gctx), mctx_(mctx) {}
39 void setMaxStepSize(
double step) { max_step_size_ = step; }
40 void setPathLimit(
double limit) { path_limit_ = limit; }
52 std::optional<Acts::BoundTrackParameters> extrapolate(
53 const Acts::BoundTrackParameters pars,
54 const std::shared_ptr<Acts::Surface>& target_surface) {
55 auto intersection = target_surface->intersect(gctx_, pars.position(gctx_),
59 if (max_step_size_ > 0) p_options.stepping.maxStepSize = max_step_size_;
60 if (path_limit_ > 0) p_options.pathLimit = path_limit_;
62 p_options.direction = intersection[0].pathLength() >= 0
63 ? Acts::Direction::Forward()
64 : Acts::Direction::Backward();
66 auto result = propagator_.propagate(pars, *target_surface, p_options);
72 std::cout <<
"INITIAL COV MATRIX\n";
73 std::cout << (*(pars.covariance())) << std::endl;
75 std::cout <<
"FINAL COV MATRIX\n";
76 auto opt_pars = *result->endParameters;
77 std::cout << *(opt_pars.covariance()) << std::endl;
82 return *result->endParameters;
97 template <
class track_t>
99 track_t track,
const std::shared_ptr<Acts::Surface>& target_surface) {
101 std::cout <<
"[TrackExtrapolatorTool] extrapolate START\n";
102 std::cout <<
"[TrackExtrapolatorTool] track.nTrackStates() = "
103 << track.nTrackStates() << std::endl;
104 std::cout <<
"[TrackExtrapolatorTool] target_surface = "
105 << target_surface.get() << std::endl;
108 if (track.nTrackStates() == 0) {
115 auto state_result = Acts::findTrackStateForExtrapolation(
116 gctx_, track, *target_surface,
117 Acts::TrackExtrapolationStrategy::firstOrLast);
119 if (!state_result.ok()) {
123 const auto& ts = state_result->first;
124 const auto& surface = ts.referenceSurface();
126 Acts::BoundVector params;
127 Acts::BoundMatrix cov;
129 if (ts.hasSmoothed()) {
131 std::cout <<
"[TrackExtrapolatorTool] Using smoothed parameters\n";
132 params = ts.smoothed();
133 cov = ts.smoothedCovariance();
134 }
else if (ts.hasFiltered()) {
136 std::cout <<
"[TrackExtrapolatorTool] Using filtered parameters\n";
137 params = ts.filtered();
138 cov = ts.filteredCovariance();
144 std::cout <<
"Surface::"
145 << surface.localToGlobalTransform(gctx_).translation()
147 std::cout <<
"HasSmoothed::" << ts.hasSmoothed() << std::endl;
148 std::cout <<
"Parameters::" << params.transpose() << std::endl;
151 auto part_hypo{Acts::ParticleHypothesis::electron()};
152 Acts::BoundTrackParameters sp(surface.getSharedPtr(), params, cov,
155 std::cout <<
"[TrackExtrapolatorTool] calling extrapolate(BTP)...\n";
156 auto result = extrapolate(sp, target_surface);
157 if (debug_) std::cout <<
"[TrackExtrapolatorTool] extrapolate DONE\n";
170 template <
class track_t>
172 track_t track,
const std::shared_ptr<Acts::Surface>& target_surface) {
177 auto& tsc = track.container().trackStateContainer();
178 auto begin = track.trackStates().begin();
179 auto ts_last = *begin;
180 const auto& surface = (ts_last).referenceSurface();
181 const auto& smoothed = (ts_last).smoothed();
182 const auto& cov = (ts_last).smoothedCovariance();
186 auto part_hypo{Acts::ParticleHypothesis::electron()};
188 Acts::BoundTrackParameters state_parameters(surface.getSharedPtr(),
189 smoothed, cov, part_hypo);
194 propagator_.propagate(state_parameters, *target_surface, p_options);
197 return *result->endParameters;
212 template <
class track_t>
214 const std::shared_ptr<Acts::Surface>& target_surface,
216 ldmx::TrackStateType type) {
218 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface START\n";
219 std::cout <<
"[TrackExtrapolatorTool] target_surface = "
220 << target_surface.get() << std::endl;
221 std::cout <<
"[TrackExtrapolatorTool] track.nTrackStates() = "
222 << track.nTrackStates() << std::endl;
223 std::cout <<
"[TrackExtrapolatorTool] TrackStateType = "
224 <<
static_cast<int>(type) << std::endl;
225 std::cout <<
"[TrackExtrapolatorTool] About to call extrapolate...\n";
228 auto opt_pars = extrapolate(track, target_surface);
231 std::cout <<
"[TrackExtrapolatorTool] extrapolate returned, "
232 "opt_pars.has_value() = "
233 << opt_pars.has_value() << std::endl;
238 Acts::Vector3 surf_loc =
239 target_surface->localToGlobalTransform(gctx_).translation();
240 std::cout <<
"[TrackExtrapolatorTool] Surface location: ("
241 << surf_loc(0) <<
", " << surf_loc(1) <<
", " << surf_loc(2)
245 ts = tracking::sim::utils::makeTrackState(gctx_, *opt_pars, type);
247 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface SUCCESS\n";
251 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface FAILED - "
252 "opt_pars is empty\n";
258 propagator_t propagator_;
259 Acts::GeometryContext gctx_;
260 Acts::MagneticFieldContext mctx_;
262 double max_step_size_{-1};
263 double path_limit_{-1};