10 #include "Acts/Definitions/Units.hpp"
11 #include "Acts/Propagator/ActorList.hpp"
12 #include "Acts/Propagator/Propagator.hpp"
13 #include "Acts/Propagator/MaterialInteractor.hpp"
14 #include "Acts/Propagator/EigenStepper.hpp"
15 #include "Acts/Utilities/VectorHelpers.hpp"
16 #include "Acts/Visualization/ObjVisualization3D.hpp"
17 #include "Acts/Visualization/GeometryView3D.hpp"
23 using namespace Acts::UnitLiterals;
28 using result_type = std::vector<Acts::Experimental::DetectorNavigator::State>;
30 template <
typename propagator_state_t,
typename stepper_t,
typename navigator_t>
31 void act(propagator_state_t& state,
const stepper_t& ,
33 const Acts::Logger& )
const {
35 result.push_back(state.navigation);
38 template <
typename propagator_state_t,
typename stepper_t,
typename navigator_t>
41 const Acts::Logger& )
const {
53 for(
const auto& state :
states){
54 os <<
"v " << state.position.x() <<
" " << state.position.y() <<
" " << state.position.z() <<
'\n';
56 std::size_t vBreak = vCounter +
states.size() - 1;
57 for(; vCounter < vBreak; ++vCounter){
58 os <<
"l " << vCounter <<
" " << vCounter + 1 <<
'\n';
64 MuonDetectorNavTest::MuonDetectorNavTest(
const std::string&
name, ISvcLocator* pSvcLocator):
83 ATH_CHECK(
book(TH1D(
"distanceBetweenHits",
"distanceBetweenHits", 250, 0., 500.),
"MuonNavigationTestR4",
"MuonNavigationTestR4"));
86 return StatusCode::SUCCESS;
92 hist(
"distanceBetweenHits")->GetXaxis()->SetTitle(
"Distance between hits [mm]");
93 return StatusCode::SUCCESS;
98 const EventContext& ctx{Gaudi::Hive::currentContext()};
102 if (!gctx.isValid() or !truthParticles.isValid() or !magFieldHandle.isValid()) {
103 ATH_MSG_FATAL(
"Failed to retrieve either the geometry context, truth particles or magnetic field");
104 return StatusCode::FAILURE;
107 Acts::GeometryContext geoContext = gctx->context();
108 Acts::MagneticFieldContext mfContext = Acts::MagneticFieldContext(*magFieldHandle);
110 std::vector<std::pair<Identifier, Amg::Vector3D>> propagatedHits;
111 std::vector<std::pair<Identifier, Amg::Vector3D>> propagatedHitsGlobal;
112 std::vector<std::pair<Identifier, Amg::Vector3D>> truthHits;
114 for(
auto& simHitCollection : simHitCollections){
116 if(simHit->pdgId() != 13)
continue;
118 const Amg::Vector3D localPos = xAOD::toEigen(simHit->localPosition());
121 truthHits.emplace_back(
ID, localPos);
125 using Stepper = Acts::EigenStepper<>;
126 using Navigator = Acts::Experimental::DetectorNavigator;
127 using Propagator = Acts::Propagator<Stepper,Navigator>;
128 using ActorList = Acts::ActorList<StateRecorder, Acts::MaterialInteractor, Acts::EndOfWorldReached>;
129 using PropagatorOptions = Propagator::Options<ActorList>;
131 auto bField = std::make_shared<ATLASMagneticFieldWrapper>();
132 auto stepper =
Stepper(std::move(bField));
134 PropagatorOptions
options(geoContext, mfContext);
137 options.stepping.maxStepSize = 0.5_m;
140 auto& materialInteractor =
options.actorList.get<Acts::MaterialInteractor>();
141 materialInteractor.energyLoss =
true;
142 materialInteractor.multipleScattering =
true;
143 materialInteractor.recordInteractions =
true;
146 for(
const auto& truthParticle : *truthParticles){
148 if(truthParticle->status() == 1 and truthParticle->pdgId() == 13){
149 const auto&
particle = truthParticle->p4();
150 const auto& prodVertex = (!truthParticle->hasProdVtx()) ?
nullptr : truthParticle->prodVtx();
151 double x = prodVertex ? prodVertex->x() : 0.;
152 double y = prodVertex ? prodVertex->y() : 0.;
153 double z = prodVertex ? prodVertex->z() : 0.;
155 Acts::CurvilinearTrackParameters
start(
156 Acts::VectorHelpers::makeVector4(Acts::Vector3(
x,
y,
z), 0.),
158 truthParticle->charge() /
particle.P(),
162 Acts::Experimental::DetectorNavigator::Config navCfg;
164 navCfg.resolvePassive =
true;
166 Acts::Experimental::DetectorNavigator navigator(navCfg, Acts::getDefaultLogger(
"DetectorNavigator",
Acts::Logging::Level::INFO));
167 Acts::Propagator<Stepper, Acts::Experimental::DetectorNavigator> propagator(
168 std::move(stepper), std::move(navigator),
173 const Acts::MaterialInteractor::result_type material =
result.get<Acts::MaterialInteractor::result_type>();
174 ATH_MSG_DEBUG(
"Material interactions: " << material.materialInteractions.size());
177 std::vector<Acts::MaterialInteraction> interactions = material.materialInteractions;
178 for(
const Acts::MaterialInteraction& interaction : interactions){
179 ATH_MSG_DEBUG(
"Path Correction: " << interaction.pathCorrection);
183 Acts::ObjVisualization3D
helper{};
184 for (
const auto&
s : state) {
185 if(
s.currentSurface) Acts::GeometryView3D::drawSurface(
helper, *
s.currentSurface, geoContext);
191 for(
const auto& state: state){
192 if(state.currentSurface){
202 propagatedHits.emplace_back(
ID, localPos);
203 propagatedHitsGlobal.emplace_back(
ID, state.position);
209 for(
const auto& truthHit : truthHits){
210 bool hitFound =
false;
211 for(
const auto& propagatedHit : propagatedHits){
212 if(truthHit.first == propagatedHit.first){
221 for(
const auto& propagatedHit : propagatedHits){
222 bool hitFound =
false;
223 for(
const auto& truthHit : truthHits){
224 if(truthHit.first == propagatedHit.first){
235 for(
const auto& propagatedHit: propagatedHitsGlobal){
238 for(
const auto& truthHit: truthHits){
242 closestID = truthHit.first;
249 hist(
"distanceBetweenHits")->Fill(minDistance);
253 return StatusCode::SUCCESS;