ATLAS Offline Software
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 
35 using namespace Acts::UnitLiterals;
36 
37 namespace 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());
51  ATH_CHECK(m_extrapolationTool.retrieve());
52  ATH_CHECK(m_propStepWriterSvc.retrieve());
53  ATH_CHECK(m_trackingGeometryTool.retrieve());
54  if (m_writeMaterialTracks) {
55  ATH_CHECK( m_materialTrackWriterSvc.retrieve() );
56  }
57 
58  return StatusCode::SUCCESS;
59 }
60 
61 StatusCode 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 
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 
121  if(m_writeMaterialTracks){
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 }
make_hlt_rep.pars
pars
Definition: make_hlt_rep.py:90
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
ActsExtrapolationAlg::initialize
StatusCode initialize() override
Definition: ActsExtrapolationAlg.cxx:46
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
LArCellBinning.etaRange
etaRange
Filling Eta range.
Definition: LArCellBinning.py:128
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:75
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:200
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Acts::RecordedMaterialTrack
std::pair< std::pair< Acts::Vector3, Acts::Vector3 >, RecordedMaterial > RecordedMaterialTrack
Recorded material track.
Definition: ActsExtrapolationAlg.cxx:42
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
xAOD::pion
@ pion
Definition: TrackingPrimitives.h:197
python.RatesEmulationExample.lock
lock
Definition: RatesEmulationExample.py:148
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
GeometryContext.h
beamspotman.steps
int steps
Definition: beamspotman.py:501
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
Acts
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/xAODMuonPrepData/UtilFunctions.h:20
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRT::Track::d0
@ d0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:62
ActsTrk::IExtrapolationTool::PropagationOutput
std::pair< std::vector< Acts::detail::Step >, RecordedMaterial > PropagationOutput
Abrivation of the recorded steps and the allocated material.
Definition: IExtrapolationTool.h:31
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ActsExtrapolationAlg.h
TRT::Track::z0
@ z0
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:63
IActsPropStepRootWriterSvc.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
charge
double charge(const T &p)
Definition: AtlasPID.h:991
ActsExtrapolationAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: ActsExtrapolationAlg.cxx:61
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
LArCellBinning.etaMin
etaMin
Definition: LArCellBinning.py:84
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
ITrackingGeometryTool.h
LArCellBinning.step
step
Definition: LArCellBinning.py:158
xAOD::track
@ track
Definition: TrackingPrimitives.h:513
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
Logger.h
IActsMaterialTrackWriterSvc.h
ActsExtrapolationAlg::writeStepsObj
void writeStepsObj(const std::vector< Acts::detail::Step > &steps) const
Definition: ActsExtrapolationAlg.cxx:137
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
IAthRNGSvc.h