ATLAS Offline Software
Loading...
Searching...
No Matches
ObjTrackVisualizationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
7
10#include "GeoModelHelpers/StringUtils.h"
13
14#include "Acts/Visualization/ObjVisualization3D.hpp"
15#include "Acts/Visualization/GeometryView3D.hpp"
16#include "Acts/Surfaces/PerigeeSurface.hpp"
17#include "Acts/Definitions/Units.hpp"
18
19
20#include <format>
21
22using namespace Acts::UnitLiterals;
23using namespace MuonValR4;
24
27std::string toString(const float number) {
28 using namespace GeoStrUtils;
29 return replaceExpInString(
30 replaceExpInString(std::format("{:.3f}", number), ".", "p"), "-", "m");
31}
32
33namespace ActsTrk {
34
37 ATH_CHECK(m_readKey.initialize());
38 ATH_CHECK(m_ctxProvider.initialize());
39 return StatusCode::SUCCESS;
40 }
41 StatusCode ObjTrackVisualizationAlg::execute(const EventContext& ctx) {
42 const xAOD::TrackParticleContainer* tracks{};
43 ATH_CHECK(SG::get(tracks, m_readKey, ctx));
44 const Acts::GeometryContext tgContext = m_ctxProvider.getGeometryContext(ctx);
45
46 const std::string outDir = std::format("{:}/Event_{:}/", m_outPath.value(),
47 ctx.eventID().event_number());
48 ensureDirectory(outDir);
49 Acts::ObjVisualization3D visualHelper{};
50 std::unordered_set<std::shared_ptr<const Acts::Surface>> passedSurfaces{};
51
52
53 for (const xAOD::TrackParticle* particle : *tracks) {
54 passedSurfaces.clear();
55 auto track = getActsTrack(*particle);
56
57 std::optional<Acts::BoundTrackParameters> startPars{};
58 if (track) {
59 startPars = track->createParametersAtReference();
60 for (const auto& state : track->trackStates()) {
61 Acts::GeometryView3D::drawSurface(visualHelper, state.referenceSurface(),
62 tgContext, Acts::Transform3::Identity(),
63 Acts::s_viewSensitive);
64 passedSurfaces.insert(state.referenceSurface().getSharedPtr());
65 }
66 } else {
67 auto startSurf = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Transform3::Identity());
68 Acts::BoundVector pars{Acts::BoundVector::Zero()};
69 pars[Acts::eBoundLoc0] = particle->d0();
70 pars[Acts::eBoundLoc1] = particle->z0();
71 pars[Acts::eBoundLoc1] = particle->phi();
72 pars[Acts::eBoundTheta] = particle->theta();
73 pars[Acts::eBoundQOverP] = particle->charge() / energyToActs(particle->pt() * std::cosh(particle->eta()));
74 startPars = Acts::BoundTrackParameters{startSurf, pars, std::nullopt,
75 ParticleHypothesis::convert(particle->particleHypothesis())};
76 }
77 auto steps = m_extrapolationTool->propagationSteps(ctx, *startPars, Acts::Direction::Forward(), 50._m);
78 if (!steps.ok()) {
79 continue;
80 }
81
82 drawPropagation(steps->first, visualHelper);
83 for (const auto& step : steps->first) {
84 if (step.surface && passedSurfaces.insert(step.surface).second) {
85 Acts::GeometryView3D::drawSurface(visualHelper, *step.surface,
86 tgContext, Acts::Transform3::Identity(),
87 Acts::s_viewPassive);
88 }
89 }
90 visualHelper.write(std::format("{:}/Track_{:}_pt_{:}_eta_{:}_phi_{:}.obj", outDir,
91 particle->index(), toString(particle->pt() / 1.e3),
92 toString(particle->eta()), toString(particle->phi())));
93 visualHelper.clear();
94 }
95 return StatusCode::SUCCESS;
96 }
97}
#define ATH_CHECK
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
Gaudi::Property< std::string > m_outPath
virtual StatusCode initialize() override final
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_readKey
The track particle container to be dumped.
virtual StatusCode execute(const EventContext &ctx) override final
Execute method.
ToolHandle< IExtrapolationTool > m_extrapolationTool
Track extrapolation tool.
xAOD::ParticleHypothesis convert(Acts::ParticleHypothesis h)
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
constexpr double energyToActs(const double athenaE)
Converts an energy scalar from Athena to Acts units.
std::optional< ActsTrk::TrackContainer::ConstTrackProxy > getActsTrack(const xAOD::TrackParticle &trkPart)
Return the proxy to the Acts track from which the track particle was made frome.
Definition Decoration.cxx:9
std::string toString(const Parameters &pars)
Dumps the parameters into a string with labels in front of each number.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
void ensureDirectory(const std::string &path)
Ensures that the subdirectory in the path is created.
void drawPropagation(const std::vector< Acts::detail::Step > &steps, Acts::ObjVisualization3D &visualHelper, const Acts::ViewConfig &viewConfig=Acts::s_viewLine)
Draws the recorded propagation steps as a polygon line.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186