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
11#include "GeoModelHelpers/StringUtils.h"
14
15#include "Acts/Visualization/ObjVisualization3D.hpp"
16#include "Acts/Visualization/GeometryView3D.hpp"
17#include "Acts/Surfaces/PerigeeSurface.hpp"
18#include "Acts/Definitions/Units.hpp"
19#include "Acts/Geometry/TrackingGeometry.hpp"
20
21
22#include <format>
23
24using namespace Acts::UnitLiterals;
25using namespace MuonValR4;
26
29std::string toString(const float number) {
30 using namespace GeoStrUtils;
31 return replaceExpInString(
32 replaceExpInString(std::format("{:.3f}", number), ".", "p"), "-", "m");
33}
34
35namespace ActsTrk {
36
39 ATH_CHECK(m_readKey.initialize());
40 ATH_CHECK(m_ctxProvider.initialize());
41 ATH_CHECK(m_trackingGeoSvc.retrieve());
42 return StatusCode::SUCCESS;
43 }
44 StatusCode ObjTrackVisualizationAlg::execute(const EventContext& ctx) {
45 const xAOD::TrackParticleContainer* tracks{};
46 ATH_CHECK(SG::get(tracks, m_readKey, ctx));
47 const Acts::GeometryContext tgContext = m_ctxProvider.getGeometryContext(ctx);
48
49 const std::string outDir = std::format("{:}/Event_{:}/", m_outPath.value(),
50 ctx.eventID().event_number());
51 ensureDirectory(outDir);
52 Acts::ObjVisualization3D visualHelper{};
53 std::unordered_set<std::shared_ptr<const Acts::Surface>> passedSurfaces{};
54
55 const auto trackingGeo = m_trackingGeoSvc->trackingGeometry();
56
57 for (const xAOD::TrackParticle* particle : *tracks) {
58 passedSurfaces.clear();
59 auto track = getActsTrack(*particle);
60
61 std::optional<Acts::BoundTrackParameters> startPars{};
62 if (track) {
63 startPars = track->createParametersAtReference();
64 for (const auto& state : track->trackStates()) {
65 Acts::GeometryView3D::drawSurface(visualHelper, state.referenceSurface(),
66 tgContext, Acts::Transform3::Identity(),
67 Acts::s_viewSensitive);
68 passedSurfaces.insert(state.referenceSurface().getSharedPtr());
69 }
70 } else {
71 auto startSurf = Acts::Surface::makeShared<Acts::PerigeeSurface>(Acts::Transform3::Identity());
72 Acts::BoundVector pars{Acts::BoundVector::Zero()};
73 pars[Acts::eBoundLoc0] = particle->d0();
74 pars[Acts::eBoundLoc1] = particle->z0();
75 pars[Acts::eBoundLoc1] = particle->phi();
76 pars[Acts::eBoundTheta] = particle->theta();
77 pars[Acts::eBoundQOverP] = particle->charge() / energyToActs(particle->pt() * std::cosh(particle->eta()));
78 startPars = Acts::BoundTrackParameters{startSurf, pars, std::nullopt,
79 ParticleHypothesis::convert(particle->particleHypothesis())};
80 }
81 auto steps = m_extrapolationTool->propagationSteps(ctx, *startPars, Acts::Direction::Forward(), 50._m);
82 if (!steps.ok()) {
83 continue;
84 }
85
86 drawPropagation(steps->first, visualHelper);
87 std::stringstream sstr{};
88 unsigned surfCounter{0};
89 for (const auto& step : steps->first) {
90 if (!step.surface) {
91 continue;
92 }
93 sstr<<" --- "<<(++surfCounter)<<" @"<<Amg::toString(step.position)
94 <<", perp: "<<step.position.perp()
95 <<", theta: "<<step.momentum.theta()
96 <<", phi: "<<step.momentum.phi();
97 if (const Acts::TrackingVolume* vol =
98 trackingGeo->findVolume(step.surface->geometryId().withBoundary(0).withSensitive(0)); vol != nullptr) {
99 sstr<<", volume: "<<vol->volumeName();
100 }
101 sstr<<", surface @"<<Amg::toString(step.surface->center(tgContext))
102 <<", id: "<<step.surface->geometryId()
103 <<", bounds: "<<step.surface->bounds()<<std::endl;
104 if (passedSurfaces.insert(step.surface).second) {
105 Acts::GeometryView3D::drawSurface(visualHelper, *step.surface,
106 tgContext, Acts::Transform3::Identity(),
107 Acts::s_viewPassive);
108 }
109 }
110 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Propagated track particle "<<particle->index()
111 <<" with "<<(particle->pt()*1.e-3)<<" [GeV], eta: "<<particle->eta()
112 <<", phi: "<<particle->phi()<<", q: "<<particle->charge()
113 <<"\n"<<sstr.str());
114 visualHelper.write(std::format("{:}/Track_{:}_pt_{:}_eta_{:}_phi_{:}.obj", outDir,
115 particle->index(), toString(particle->pt() / 1.e3),
116 toString(particle->eta()), toString(particle->phi())));
117 visualHelper.clear();
118 }
119 return StatusCode::SUCCESS;
120 }
121}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x,...)
Handle class for reading from StoreGate.
ServiceHandle< ITrackingGeometrySvc > m_trackingGeoSvc
The tracking geometry service.
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 Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
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