ATLAS Offline Software
Loading...
Searching...
No Matches
ExtrapolationTestAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// ATHENA
8
9
10// ACTS
11#include "Acts/Propagator/MaterialInteractor.hpp"
12#include "Acts/Propagator/detail/SteppingLogger.hpp"
13#include "Acts/Surfaces/PerigeeSurface.hpp"
14#include "Acts/Utilities/Helpers.hpp"
15#include "Acts/Definitions/Units.hpp"
16#include "Acts/Utilities/Logger.hpp"
17
18// PACKAGE
21#include "ActsInterop/Logger.h"
22
23// OTHER
24#include "CLHEP/Random/RandomEngine.h"
25
26// STL
27#include <fstream>
28#include <string>
29
30using namespace Acts::UnitLiterals;
31
32namespace ActsTrk{
34
35 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
36
37 ATH_CHECK(m_rndmGenSvc.retrieve());
41 ATH_CHECK(m_tree.init(this));
42 return StatusCode::SUCCESS;
43}
44
46 ATH_CHECK(m_tree.write());
47 return StatusCode::SUCCESS;
48}
49StatusCode ExtrapolationTestAlg::execute(const EventContext &ctx) {
50
51 ATH_MSG_VERBOSE(name() << "::" << __FUNCTION__);
52
53 ATHRNG::RNGWrapper *rngWrapper = m_rndmGenSvc->getEngine(this);
54 rngWrapper->setSeed(name(), ctx);
55 CLHEP::HepRandomEngine *rngEngine = rngWrapper->getEngine(ctx);
56
57 ATH_MSG_VERBOSE("Extrapolating " << m_nParticlePerEvent << " particles");
58
59 // Write to the collection to the EventStore
61
62 // Record the collection once per event if not already there
63 if (!materialTracks.isPresent()) {
64 ATH_CHECK(materialTracks.record(std::make_unique<ActsTrk::RecordedMaterialTrackCollection>()));
65 }
66
67 // Add the track to the recorded collection
68 auto* coll = materialTracks.ptr();
69
70 for (size_t i = 0; i < m_nParticlePerEvent; ++i) {
71 double d0 = 0;
72 double z0 = 0;
73 double phi = rngEngine->flat() * 2 * std::numbers::pi - std::numbers::pi;
74 std::vector<double> etaRange = m_etaRange;
75 double etaMin = etaRange.at(0);
76 double etaMax = etaRange.at(1);
77 double eta = rngEngine->flat() * std::abs(etaMax - etaMin) + etaMin;
78
79 std::vector<double> ptRange = m_ptRange;
80 double ptMin = ptRange.at(0) * 1_GeV;
81 double ptMax = ptRange.at(1) * 1_GeV;
82
83 double pt = rngEngine->flat() * std::abs(ptMax - ptMin) + ptMin;
84
85 Acts::Vector3 momentum(pt * std::cos(phi), pt * std::sin(phi),
86 pt * std::sinh(eta));
87
88 double theta = momentum.theta();
89
90 double charge = rngEngine->flat() > 0.5 ? -1 : 1;
91
92 double qop = charge / momentum.norm();
93
94 auto surface = Acts::Surface::makeShared<Acts::PerigeeSurface>(Amg::Vector3D::Zero());
95
96 double t = 0;
97 ATH_MSG_VERBOSE("Pseudo-particle: eta: " << eta << " phi: " << phi);
98
99 Acts::BoundVector pars;
100 // cppcheck-suppress constStatement; will be able to initialize this directly with eigen 3.4
101 pars << d0, z0, phi, theta, qop, t;
102 std::optional<Acts::BoundMatrix> cov = std::nullopt;
103
104 if (charge != 0.) {
105 // Perigee, no alignment -> default geo context
106 Acts::BoundTrackParameters startParameters(std::move(surface), std::move(pars), std::move(cov), Acts::ParticleHypothesis::pion());
107 auto result = m_extrapolationTool->propagationSteps(ctx, startParameters);
108 if (!result.ok()) {
109 ATH_MSG_WARNING("Extrapolation tool failed to extrapolate the track: "
110 << result.error().message());
111 continue;
112 }
113 auto &output = result.value();
114 if(output.first.size() == 0) {
115 ATH_MSG_WARNING("Got ZERO steps from the extrapolation tool");
116 }
117 if (m_writePropStep) {
118 ATH_CHECK(writePropagationSteps(ctx, output.first));
119 }
120
122 Acts::RecordedMaterialTrack track;
123 track.first.first = Acts::Vector3::Zero();
124 track.first.second = momentum;
125 track.second = std::move(output.second);
126 coll->push_back(track);
127 }
128 }
129
130 ATH_MSG_VERBOSE(name() << " execute done");
131 }
132
133 return StatusCode::SUCCESS;
134}
135
136StatusCode ExtrapolationTestAlg::writePropagationSteps(const EventContext& ctx, const StepVector& steps) {
137 m_eventNum = ctx.eventID().event_number();
138 for(const auto& step : steps) {
139 Acts::GeometryIdentifier::Value volumeID = 0;
140 Acts::GeometryIdentifier::Value boundaryID = 0;
141 Acts::GeometryIdentifier::Value layerID = 0;
142 Acts::GeometryIdentifier::Value approachID = 0;
143 Acts::GeometryIdentifier::Value sensitiveID = 0;
144 // get the identification from the surface first
145 if (step.surface) {
146 auto geoID = step.surface->geometryId();
147 sensitiveID = geoID.sensitive();
148 approachID = geoID.approach();
149 layerID = geoID.layer();
150 boundaryID = geoID.boundary();
151 volumeID = geoID.volume();
152 }
153 // a current volume overwrites the surface tagged one
154 if (step.geoID != Acts::GeometryIdentifier()) {
155 volumeID = step.geoID.volume();
156 }
157 // now fill
158 m_s_sensitiveID.push_back(sensitiveID);
159 m_s_approachID.push_back(approachID);
160 m_s_layerID.push_back(layerID);
161 m_s_boundaryID.push_back(boundaryID);
162 m_s_volumeID.push_back(volumeID);
163
164 m_s_pX.push_back(step.position.x());
165 m_s_pY.push_back(step.position.y());
166 m_s_pZ.push_back(step.position.z());
167 m_s_pR.push_back(Acts::VectorHelpers::perp(step.position));
168 }
169
170
171
172 return m_tree.fill(ctx) ? StatusCode::SUCCESS : StatusCode::FAILURE;
173}
174
175}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:154
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:108
MuonVal::VectorBranch< float > & m_s_pZ
Global z position of the step.
Gaudi::Property< std::vector< double > > m_etaRange
Gaudi::Property< bool > m_writePropStep
MuonVal::VectorBranch< int > & m_s_approachID
approach identification
Gaudi::Property< size_t > m_nParticlePerEvent
MuonVal::VectorBranch< int > & m_s_boundaryID
boundary identification
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
MuonVal::VectorBranch< int > & m_s_sensitiveID
sensitive identification
Gaudi::Property< std::vector< double > > m_ptRange
MuonVal::VectorBranch< float > & m_s_pX
Global x position of the step.
virtual StatusCode finalize() override
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
MuonVal::VectorBranch< int > & m_s_layerID
layer identification
Gaudi::Property< bool > m_writeMaterialTracks
MuonVal::VectorBranch< float > & m_s_pY
Global y position of the step.
std::vector< Acts::detail::Step > StepVector
MuonVal::ScalarBranch< int > & m_eventNum
SG::WriteHandleKey< ActsTrk::RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to write.
StatusCode writePropagationSteps(const EventContext &ctx, const StepVector &steps)
MuonVal::VectorBranch< float > & m_s_pR
Global radial position of the step sqrt(x^{2} + y^{2}).
virtual StatusCode initialize() override
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
MuonVal::VectorBranch< int > & m_s_volumeID
volume identification
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...