33 const Acts::GeometryContext& gctx,
34 const Acts::MagneticFieldContext& mctx)
35 : propagator_(std::move(propagator)), gctx_(gctx), mctx_(mctx) {}
43 void setMaxStepSize(
double step) { max_step_size_ = step; }
44 void setPathLimit(
double limit) { path_limit_ = limit; }
56 std::optional<Acts::BoundTrackParameters> extrapolate(
57 const Acts::BoundTrackParameters pars,
58 const std::shared_ptr<Acts::Surface>& target_surface) {
59 auto intersection = target_surface->intersect(gctx_, pars.position(gctx_),
63 if (max_step_size_ > 0) p_options.stepping.maxStepSize = max_step_size_;
64 if (path_limit_ > 0) p_options.pathLimit = path_limit_;
66 p_options.direction = intersection[0].pathLength() >= 0
67 ? Acts::Direction::Forward()
68 : Acts::Direction::Backward();
70 auto result = propagator_.propagate(pars, *target_surface, p_options);
76 std::cout <<
"INITIAL COV MATRIX\n";
77 std::cout << (*(pars.covariance())) << std::endl;
79 std::cout <<
"FINAL COV MATRIX\n";
80 auto opt_pars = *result->endParameters;
81 std::cout << *(opt_pars.covariance()) << std::endl;
86 return *result->endParameters;
101 template <
class track_t>
103 track_t track,
const std::shared_ptr<Acts::Surface>& target_surface) {
105 std::cout <<
"[TrackExtrapolatorTool] extrapolate START\n";
106 std::cout <<
"[TrackExtrapolatorTool] track.nTrackStates() = "
107 << track.nTrackStates() << std::endl;
108 std::cout <<
"[TrackExtrapolatorTool] target_surface = "
109 << target_surface.get() << std::endl;
112 if (track.nTrackStates() == 0) {
119 auto state_result = Acts::findTrackStateForExtrapolation(
120 gctx_, track, *target_surface,
121 Acts::TrackExtrapolationStrategy::firstOrLast);
123 if (!state_result.ok()) {
127 const auto& ts = state_result->first;
128 const auto& surface = ts.referenceSurface();
130 Acts::BoundVector params;
131 Acts::BoundMatrix cov;
133 if (ts.hasSmoothed()) {
135 std::cout <<
"[TrackExtrapolatorTool] Using smoothed parameters\n";
136 params = ts.smoothed();
137 cov = ts.smoothedCovariance();
138 }
else if (ts.hasFiltered()) {
140 std::cout <<
"[TrackExtrapolatorTool] Using filtered parameters\n";
141 params = ts.filtered();
142 cov = ts.filteredCovariance();
148 std::cout <<
"Surface::"
149 << surface.localToGlobalTransform(gctx_).translation()
151 std::cout <<
"HasSmoothed::" << ts.hasSmoothed() << std::endl;
152 std::cout <<
"Parameters::" << params.transpose() << std::endl;
155 auto part_hypo{Acts::ParticleHypothesis::electron()};
156 Acts::BoundTrackParameters sp(surface.getSharedPtr(), params, cov,
159 std::cout <<
"[TrackExtrapolatorTool] calling extrapolate(BTP)...\n";
160 auto result = extrapolate(sp, target_surface);
161 if (debug_) std::cout <<
"[TrackExtrapolatorTool] extrapolate DONE\n";
174 template <
class track_t>
176 track_t track,
const std::shared_ptr<Acts::Surface>& target_surface) {
181 auto& tsc = track.container().trackStateContainer();
182 auto begin = track.trackStates().begin();
183 auto ts_last = *begin;
184 const auto& surface = (ts_last).referenceSurface();
185 const auto& smoothed = (ts_last).smoothed();
186 const auto& cov = (ts_last).smoothedCovariance();
190 auto part_hypo{Acts::ParticleHypothesis::electron()};
192 Acts::BoundTrackParameters state_parameters(surface.getSharedPtr(),
193 smoothed, cov, part_hypo);
198 propagator_.propagate(state_parameters, *target_surface, p_options);
201 return *result->endParameters;
216 template <
class track_t>
218 const std::shared_ptr<Acts::Surface>& target_surface,
220 ldmx::TrackStateType type) {
222 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface START\n";
223 std::cout <<
"[TrackExtrapolatorTool] target_surface = "
224 << target_surface.get() << std::endl;
225 std::cout <<
"[TrackExtrapolatorTool] track.nTrackStates() = "
226 << track.nTrackStates() << std::endl;
227 std::cout <<
"[TrackExtrapolatorTool] TrackStateType = "
228 <<
static_cast<int>(type) << std::endl;
229 std::cout <<
"[TrackExtrapolatorTool] About to call extrapolate...\n";
232 auto opt_pars = extrapolate(track, target_surface);
235 std::cout <<
"[TrackExtrapolatorTool] extrapolate returned, "
236 "opt_pars.has_value() = "
237 << opt_pars.has_value() << std::endl;
242 Acts::Vector3 surf_loc =
243 target_surface->localToGlobalTransform(gctx_).translation();
244 std::cout <<
"[TrackExtrapolatorTool] Surface location: ("
245 << surf_loc(0) <<
", " << surf_loc(1) <<
", " << surf_loc(2)
249 ts = tracking::sim::utils::makeTrackState(gctx_, *opt_pars, type);
251 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface SUCCESS\n";
255 std::cout <<
"[TrackExtrapolatorTool] trackStateAtSurface FAILED - "
256 "opt_pars is empty\n";
262 propagator_t propagator_;
263 Acts::GeometryContext gctx_;
264 Acts::MagneticFieldContext mctx_;
266 double max_step_size_{-1};
267 double path_limit_{-1};