ATLAS Offline Software
Loading...
Searching...
No Matches
ActsExtrapolationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// ATHENA
10#include "GaudiKernel/EventContext.h"
11#include "GaudiKernel/ISvcLocator.h"
12
13// ACTS
14#include "Acts/Propagator/MaterialInteractor.hpp"
15#include "Acts/Propagator/detail/SteppingLogger.hpp"
16#include "Acts/Surfaces/PerigeeSurface.hpp"
17#include "Acts/Utilities/Helpers.hpp"
18#include "Acts/Definitions/Units.hpp"
19#include "Acts/Utilities/Logger.hpp"
20
21// PACKAGE
26#include "ActsInterop/Logger.h"
27
28// OTHER
29#include "CLHEP/Random/RandomEngine.h"
30
31// STL
32#include <fstream>
33#include <string>
34
35using namespace Acts::UnitLiterals;
36
37namespace Acts{
42 std::pair<std::pair<Acts::Vector3, Acts::Vector3>, RecordedMaterial>;
43}
44
45
47
48 ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
49
50 ATH_CHECK(m_rndmGenSvc.retrieve());
56 }
57
58 return StatusCode::SUCCESS;
59}
60
61StatusCode ActsExtrapolationAlg::execute(const EventContext &ctx) const {
62
63 ATH_MSG_VERBOSE(name() << "::" << __FUNCTION__);
64
65 ATHRNG::RNGWrapper *rngWrapper = m_rndmGenSvc->getEngine(this);
66 rngWrapper->setSeed(name(), ctx);
67 CLHEP::HepRandomEngine *rngEngine = rngWrapper->getEngine(ctx);
68
69 ATH_MSG_VERBOSE("Extrapolating " << m_nParticlePerEvent << " particles");
70
71 for (size_t i = 0; i < m_nParticlePerEvent; i++) {
72 double d0 = 0;
73 double z0 = 0;
74 double phi = rngEngine->flat() * 2 * M_PI - M_PI;
75 std::vector<double> etaRange = m_etaRange;
76 double etaMin = etaRange.at(0);
77 double etaMax = etaRange.at(1);
78 double eta = rngEngine->flat() * std::abs(etaMax - etaMin) + etaMin;
79
80 std::vector<double> ptRange = m_ptRange;
81 double ptMin = ptRange.at(0) * 1_GeV;
82 double ptMax = ptRange.at(1) * 1_GeV;
83
84 double pt = rngEngine->flat() * std::abs(ptMax - ptMin) + ptMin;
85
86 Acts::Vector3 momentum(pt * std::cos(phi), pt * std::sin(phi),
87 pt * std::sinh(eta));
88
89 double theta = Acts::VectorHelpers::theta(momentum);
90
91 double charge = rngEngine->flat() > 0.5 ? -1 : 1;
92
93 double qop = charge / momentum.norm();
94
95 std::shared_ptr<Acts::PerigeeSurface> surface =
96 Acts::Surface::makeShared<Acts::PerigeeSurface>(
97 Acts::Vector3(0, 0, 0));
98
99 double t = 0;
100 ATH_MSG_VERBOSE("Pseudo-particle: eta: " << eta << " phi: " << phi);
101
102 Acts::BoundVector pars;
103 // cppcheck-suppress constStatement; will be able to initialize this directly with eigen 3.4
104 pars << d0, z0, phi, theta, qop, t;
105 std::optional<Acts::BoundSquareMatrix> cov = std::nullopt;
106
107 using PropagationOutput = ActsTrk::IExtrapolationTool::PropagationOutput;
108 PropagationOutput output;
109
110 if (charge != 0.) {
111 // Perigee, no alignment -> default geo context
112 Acts::GenericBoundTrackParameters startParameters(std::move(surface), std::move(pars), std::move(cov), Acts::ParticleHypothesis::pion());
113 output = m_extrapolationTool->propagationSteps(ctx, startParameters);
114 if(output.first.size() == 0) {
115 ATH_MSG_WARNING("Got ZERO steps from the extrapolation tool");
116 }
117 if (m_writePropStep) {
118 m_propStepWriterSvc->write(output.first);
119 }
120
123 track.first.first = Acts::Vector3::Zero();
124 track.first.second = momentum;
125 track.second = std::move(output.second);
126 m_materialTrackWriterSvc->write(track);
127 }
128 }
129
130 ATH_MSG_VERBOSE(name() << " execute done");
131 }
132
133 return StatusCode::SUCCESS;
134}
135
136
138 const std::vector<Acts::detail::Step>& steps) const {
139
140 std::lock_guard<std::mutex> lock(m_writeMutex);
141
142 static std::ofstream out ATLAS_THREAD_SAFE ("steps.obj");
143 std::stringstream lstr;
144 lstr << "l";
145 for (const auto &step : steps) {
146 const auto &pos = step.position;
147 out << "v " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
148 lstr << " " << m_objVtxCount;
149 m_objVtxCount++;
150 }
151
152 lstr << std::endl;
153
154 out << lstr.str() << std::endl;
155}
#define M_PI
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:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
ToolHandle< ActsTrk::IExtrapolationTool > m_extrapolationTool
Gaudi::Property< size_t > m_nParticlePerEvent
size_t m_objVtxCount ATLAS_THREAD_SAFE
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
Gaudi::Property< bool > m_writePropStep
Gaudi::Property< std::vector< double > > m_etaRange
PublicToolHandle< ActsTrk::ITrackingGeometryTool > m_trackingGeometryTool
Gaudi::Property< bool > m_writeMaterialTracks
Gaudi::Property< std::vector< double > > m_ptRange
ServiceHandle< IActsPropStepRootWriterSvc > m_propStepWriterSvc
StatusCode execute(const EventContext &ctx) const override
ServiceHandle< IActsMaterialTrackWriterSvc > m_materialTrackWriterSvc
StatusCode initialize() override
void writeStepsObj(const std::vector< Acts::detail::Step > &steps) const
std::pair< std::vector< Acts::detail::Step >, RecordedMaterial > PropagationOutput
Abrivation of the recorded steps and the allocated material.
std::pair< std::pair< Acts::Vector3, Acts::Vector3 >, RecordedMaterial > RecordedMaterialTrack
Recorded material track.