15 bool debugTransform =
false;
16 auto transformPos = [debugTransform](
const Acts::Vector3& pos) {
17 Acts::Vector3 rot_pos;
20 rot_pos(2) = pos(0) + DIPOLE_OFFSET;
26 std::cout <<
"PF::DEFAULT3 TRANSFORM" << std::endl;
27 std::cout <<
"PF::Check:: transforming Pos" << std::endl;
28 std::cout << pos << std::endl;
29 std::cout <<
"TO" << std::endl;
30 std::cout << rot_pos << std::endl;
36 Acts::RotationMatrix3 rotation = Acts::RotationMatrix3::Identity();
39 auto transformBField = [rotation, scale, debugTransform](
40 const Acts::Vector3& field,
41 const Acts::Vector3& ) {
43 Acts::Vector3 rot_field;
44 rot_field(0) = field(2);
45 rot_field(1) = field(0);
46 rot_field(2) = field(1);
49 rot_field = scale * rot_field;
52 rot_field = rotation * rot_field;
57 std::cout <<
"PF::DEFAULT3 TRANSFORM" << std::endl;
58 std::cout <<
"PF::Check:: transforming" << std::endl;
59 std::cout << field << std::endl;
60 std::cout <<
"TO" << std::endl;
61 std::cout << rot_field << std::endl;
68 const auto map = std::make_shared<InterpolatedMagneticField3>(
69 loadDefaultBField(field_map_,
72 transformPos, transformBField));
74 auto acts_loggingLevel = Acts::Logging::ERROR;
76 if (debug_) acts_loggingLevel = Acts::Logging::VERBOSE;
90 Acts::MultiEigenStepperLoop multi_stepper(map);
96 Acts::Navigator::Config navCfg{geometry().getTG()};
97 navCfg.resolveMaterial =
true;
98 navCfg.resolvePassive =
false;
99 navCfg.resolveSensitive =
true;
100 const Acts::Navigator navigator(navCfg);
102 auto gsf_propagator =
103 GsfPropagator(std::move(multi_stepper), std::move(navigator),
104 Acts::getDefaultLogger(
"GSF_PROP", acts_loggingLevel));
106 BetheHeitlerApprox betheHeitler = Acts::makeDefaultBetheHeitlerApprox();
108 const auto gsfLogger = Acts::getDefaultLogger(
"GSF", acts_loggingLevel);
110 gsf_ = std::make_unique<std::decay_t<
decltype(*gsf_)>>(
111 std::move(gsf_propagator), std::move(betheHeitler),
112 Acts::getDefaultLogger(
"GSF", acts_loggingLevel));
114 const auto stepper = Acts::EigenStepper<>{map};
115 propagator_ = std::make_unique<Propagator>(
116 stepper, navigator, Acts::getDefaultLogger(
"PROP", acts_loggingLevel));
118 trk_extrap_ = std::make_shared<std::decay_t<
decltype(*trk_extrap_)>>(
119 *propagator_, geometry_context(), magnetic_field_context());
157 if (!event.
exists(trackCollection_))
return;
158 auto tracks{
event.getCollection<
ldmx::Track>(trackCollection_)};
161 if (!event.
exists(measCollection_))
return;
167 Acts::GainMatrixUpdater updater;
168 Acts::GsfExtensions<Acts::VectorMultiTrajectory> gsf_extensions;
169 gsf_extensions.updater.connect<
170 &Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(
172 gsf_extensions.calibrator
174 Acts::VectorMultiTrajectory>>(&calibrator);
177 struct SurfaceAccessor {
178 const Acts::TrackingGeometry* trackingGeometry;
180 const Acts::Surface* operator()(
const Acts::SourceLink& sourceLink)
const {
181 const auto& indexSourceLink =
183 return trackingGeometry->findSurface(indexSourceLink.geometryId());
187 SurfaceAccessor m_slSurfaceAccessor{tg.getTG().get()};
189 gsf_extensions.surfaceAccessor.connect<&SurfaceAccessor::operator()>(
190 &m_slSurfaceAccessor);
191 gsf_extensions.mixtureReducer.connect<&Acts::reduceMixtureLargestWeights>();
196 Acts::PropagatorOptions<Acts::StepperPlainOptions,
197 Acts::NavigatorPlainOptions, ActionList, AbortList>
198 propagator_options(geometry_context(), magnetic_field_context());
200 propagator_options.pathLimit = std::numeric_limits<double>::max();
203 propagator_options.loopProtection =
208 propagator_options.actionList.get<Acts::MaterialInteractor>();
209 mInteractor.multipleScattering =
true;
210 mInteractor.energyLoss =
true;
211 mInteractor.recordInteractions =
false;
215 propagator_options.actionList.get<Acts::detail::SteppingLogger>();
216 sLogger.sterile =
true;
218 propagator_options.stepping.maxStepSize =
219 propagator_step_size_ * Acts::UnitConstants::mm;
220 propagator_options.maxSteps = propagator_maxSteps_;
227 std::shared_ptr<const Acts::PerigeeSurface> origin_surface =
228 Acts::Surface::makeShared<Acts::PerigeeSurface>(
229 Acts::Vector3(0., 0., 0.));
231 std::shared_ptr<const Acts::PerigeeSurface> tagger_layer_surface =
232 Acts::Surface::makeShared<Acts::PerigeeSurface>(
233 Acts::Vector3(-700., 0., 0.));
235 std::shared_ptr<const Acts::PerigeeSurface> reference_surface =
237 if (taggerTracking_) {
238 reference_surface = tagger_layer_surface;
249 Acts::GsfOptions<Acts::VectorMultiTrajectory> gsfOptions{
250 geometry_context(), magnetic_field_context(), calibration_context()};
252 gsfOptions.extensions = gsf_extensions;
253 gsfOptions.propagatorPlainOptions = propagator_options;
254 gsfOptions.referenceSurface = &(*reference_surface);
255 gsfOptions.maxComponents = maxComponents_;
256 gsfOptions.weightCutoff = weightCutoff_;
257 gsfOptions.abortOnError = abortOnError_;
258 gsfOptions.disableAllMaterialHandling = disableAllMaterialHandling_;
261 std::vector<ldmx::Track> out_tracks;
264 Acts::VectorTrackContainer vtc;
265 Acts::VectorMultiTrajectory mtj;
266 Acts::TrackContainer tc{vtc, mtj};
269 unsigned int itrk = 0;
271 for (
auto& track : tracks) {
273 std::vector<ldmx::Measurement> measOnTrack;
276 std::vector<Acts::SourceLink> fit_trackSourceLinks;
278 for (
auto imeas : track.getMeasurementsIdxs()) {
279 auto meas = measurements.at(imeas);
280 measOnTrack.push_back(meas);
284 const Acts::Surface* hit_surface = tg.getSurface(meas.getLayerID());
288 fit_trackSourceLinks.push_back(Acts::SourceLink(idx_sl));
292 std::reverse(measOnTrack.begin(), measOnTrack.end());
293 std::reverse(fit_trackSourceLinks.begin(), fit_trackSourceLinks.end());
295 for (
auto m : measOnTrack) {
296 ldmx_log(debug) <<
"Measurement:\n" << m <<
"\n";
299 ldmx_log(debug) <<
"GSF Refitting";
303 std::shared_ptr<Acts::PerigeeSurface> perigee =
304 Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Vector3(
305 track.getPerigeeX(), track.getPerigeeY(), track.getPerigeeZ()));
307 Acts::BoundTrackParameters trk_btp =
308 tracking::sim::utils::boundTrackParameters(track, perigee);
310 std::shared_ptr<Acts::Surface> beamOrigin_surface =
311 tracking::sim::utils::unboundSurface(-700);
313 const std::shared_ptr<Acts::Surface> target_surface =
314 tracking::sim::utils::unboundSurface(0.);
316 const std::shared_ptr<Acts::Surface> ecal_surface =
317 tracking::sim::utils::unboundSurface(240.5);
319 Acts::BoundTrackParameters trk_btp_bO =
320 tracking::sim::utils::boundTrackParameters(track, perigee);
322 if (taggerTracking_) {
323 if (!track.getTrackState(ldmx::TrackStateType::AtBeamOrigin)
325 ldmx_log(warn) <<
"Failed retreiving AtBeamOrigin TrackState for "
330 auto ts = track.getTrackState(ldmx::TrackStateType::AtBeamOrigin).value();
331 trk_btp_bO = tracking::sim::utils::btp(
332 ts, beamOrigin_surface,
335 if (!track.getTrackState(ldmx::TrackStateType::AtTarget).has_value()) {
337 <<
"Failed retreiving AtTarget TrackState for track. Skipping..";
340 auto ts = track.getTrackState(ldmx::TrackStateType::AtTarget).value();
341 trk_btp_bO = tracking::sim::utils::btp(ts, target_surface, 11);
343 const Acts::BoundVector& trkpars = trk_btp.parameters();
344 ldmx_log(debug) <<
"CKF Track parameters" << std::endl
345 << trkpars[0] <<
" " << trkpars[1] <<
" " << trkpars[2]
346 <<
" " << trkpars[3] <<
" " << trkpars[4] <<
" "
347 << trkpars[5] << std::endl
348 <<
"Perigee Surface" << std::endl
349 << track.getPerigeeX() <<
" " << track.getPerigeeY() <<
" "
350 << track.getPerigeeZ();
352 Acts::Vector3 trk_pos = trk_btp.position(geometry_context());
354 ldmx_log(debug) << trk_pos(0) <<
" " << trk_pos(1) <<
" " << trk_pos(2)
357 const Acts::BoundVector& trkpars_bO = trk_btp_bO.parameters();
358 ldmx_log(debug) <<
"CKF BeamOrigin track parameters" << std::endl
359 << trkpars_bO[0] <<
" " << trkpars_bO[1] <<
" "
360 << trkpars_bO[2] <<
" " << trkpars_bO[3] <<
" "
361 << trkpars_bO[4] <<
" " << trkpars_bO[5] <<
" ";
363 Acts::Vector3 trk_pos_bO = trk_btp_bO.position(geometry_context());
364 ldmx_log(debug) << trk_pos_bO(0) <<
" " << trk_pos_bO(1) <<
" "
365 << trk_pos_bO(2) << std::endl;
367 auto gsf_refit_result =
368 gsf_->fit(fit_trackSourceLinks.begin(), fit_trackSourceLinks.end(),
369 trk_btp_bO, gsfOptions, tc);
371 if (!gsf_refit_result.ok()) {
372 ldmx_log(warn) <<
"GSF re-fit failed" << std::endl;
376 if (tc.size() < 1)
continue;
378 auto gsftrk = tc.getTrack(itrk);
379 calculateTrackQuantities(gsftrk);
381 const Acts::BoundVector& perigee_pars = gsftrk.parameters();
382 const Acts::BoundMatrix& trk_cov = gsftrk.covariance();
383 const Acts::Surface& perigee_surface = gsftrk.referenceSurface();
386 <<
"Found track:" << std::endl
387 <<
"Track states " << gsftrk.nTrackStates() << std::endl
388 << perigee_pars[Acts::eBoundLoc0] <<
" "
389 << perigee_pars[Acts::eBoundLoc1] <<
" "
390 << perigee_pars[Acts::eBoundPhi] <<
" "
391 << perigee_pars[Acts::eBoundTheta] <<
" "
392 << perigee_pars[Acts::eBoundQOverP] << std::endl
393 <<
"Reference Surface" << std::endl
394 <<
" " << perigee_surface.transform(geometry_context()).translation()(0)
395 <<
" " << perigee_surface.transform(geometry_context()).translation()(1)
396 <<
" " << perigee_surface.transform(geometry_context()).translation()(2)
401 bool success =
false;
402 if (taggerTracking_) {
403 ldmx_log(debug) <<
"Target extrapolation";
406 success = trk_extrap_->TrackStateAtSurface(
407 gsftrk, target_surface, tsAtTarget, ldmx::TrackStateType::AtTarget);
409 if (success) trk.addTrackState(tsAtTarget);
411 ldmx_log(debug) <<
"Ecal Extrapolation";
413 success = trk_extrap_->TrackStateAtSurface(gsftrk, ecal_surface, tsAtEcal,
414 ldmx::TrackStateType::AtECAL);
416 if (success) trk.addTrackState(tsAtEcal);
419 trk.setPerigeeLocation(
420 perigee_surface.transform(geometry_context()).translation()(0),
421 perigee_surface.transform(geometry_context()).translation()(1),
422 perigee_surface.transform(geometry_context()).translation()(2));
424 trk.setChi2(gsftrk.chi2());
425 trk.setNhits(gsftrk.nMeasurements());
426 trk.setNdf(gsftrk.nMeasurements() - 5);
428 tracking::sim::utils::convertActsToLdmxPars(perigee_pars));
429 std::vector<double> v_trk_cov;
430 tracking::sim::utils::flatCov(trk_cov, v_trk_cov);
431 trk.setPerigeeCov(v_trk_cov);
432 Acts::Vector3 trk_momentum = gsftrk.momentum();
433 trk.setMomentum(trk_momentum(0), trk_momentum(1), trk_momentum(2));
436 trk.setTrackID(track.getTrackID());
437 trk.setPdgID(track.getPdgID());
438 trk.setTruthProb(track.getTruthProb());
442 out_tracks.push_back(trk);
446 event.add(out_trk_collection_, out_tracks);