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
27 #include "ActsInterop/Logger.h"
28 
29 // OTHER
30 #include "CLHEP/Random/RandomEngine.h"
31 
32 // STL
33 #include <fstream>
34 #include <string>
35 
36 using namespace Acts::UnitLiterals;
37 
38 namespace Acts{
43  std::pair<std::pair<Acts::Vector3, Acts::Vector3>, RecordedMaterial>;
44 }
45 
46 
48 
49  ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
50 
51  ATH_CHECK(m_rndmGenSvc.retrieve());
52  ATH_CHECK(m_extrapolationTool.retrieve());
53  ATH_CHECK(m_propStepWriterSvc.retrieve());
54  ATH_CHECK(m_trackingGeometryTool.retrieve());
55  if (m_writeMaterialTracks) {
56  ATH_CHECK( m_materialTrackWriterSvc.retrieve() );
57  }
58 
59  return StatusCode::SUCCESS;
60 }
61 
62 StatusCode ActsExtrapolationAlg::execute(const EventContext &ctx) const {
63 
64  ATH_MSG_VERBOSE(name() << "::" << __FUNCTION__);
65 
66  ATHRNG::RNGWrapper *rngWrapper = m_rndmGenSvc->getEngine(this);
67  rngWrapper->setSeed(name(), ctx);
68  CLHEP::HepRandomEngine *rngEngine = rngWrapper->getEngine(ctx);
69 
70  ATH_MSG_VERBOSE("Extrapolating " << m_nParticlePerEvent << " particles");
71 
72  for (size_t i = 0; i < m_nParticlePerEvent; i++) {
73  double d0 = 0;
74  double z0 = 0;
75  double phi = rngEngine->flat() * 2 * M_PI - M_PI;
76  std::vector<double> etaRange = m_etaRange;
77  double etaMin = etaRange.at(0);
78  double etaMax = etaRange.at(1);
79  double eta = rngEngine->flat() * std::abs(etaMax - etaMin) + etaMin;
80 
81  std::vector<double> ptRange = m_ptRange;
82  double ptMin = ptRange.at(0) * 1_GeV;
83  double ptMax = ptRange.at(1) * 1_GeV;
84 
85  double pt = rngEngine->flat() * std::abs(ptMax - ptMin) + ptMin;
86 
87  Acts::Vector3 momentum(pt * std::cos(phi), pt * std::sin(phi),
88  pt * std::sinh(eta));
89 
90  double theta = Acts::VectorHelpers::theta(momentum);
91 
92  double charge = rngEngine->flat() > 0.5 ? -1 : 1;
93 
94  double qop = charge / momentum.norm();
95 
96  std::shared_ptr<Acts::PerigeeSurface> surface =
97  Acts::Surface::makeShared<Acts::PerigeeSurface>(
98  Acts::Vector3(0, 0, 0));
99 
100  double t = 0;
101  ATH_MSG_VERBOSE("Pseudo-particle: eta: " << eta << " phi: " << phi);
102 
103  Acts::BoundVector pars;
104  // cppcheck-suppress constStatement; will be able to initialize this directly with eigen 3.4
105  pars << d0, z0, phi, theta, qop, t;
106  std::optional<Acts::BoundSquareMatrix> cov = std::nullopt;
107 
108  ActsPropagationOutput output;
109 
110  if (charge != 0.) {
111  // Perigee, no alignment -> default geo context
112  ActsGeometryContext gctx = m_trackingGeometryTool->getNominalGeometryContext();
113  Acts::GenericBoundTrackParameters startParameters(std::move(surface), std::move(pars), std::move(cov), Acts::ParticleHypothesis::pion());
114  output = m_extrapolationTool->propagationSteps(ctx, startParameters);
115  if(output.first.size() == 0) {
116  ATH_MSG_WARNING("Got ZERO steps from the extrapolation tool");
117  }
118  if (m_writePropStep) {
119  m_propStepWriterSvc->write(output.first);
120  }
121 
122  if(m_writeMaterialTracks){
124  track.first.first = Acts::Vector3(0,0,0);
125  track.first.second = momentum;
126  track.second = std::move(output.second);
127  m_materialTrackWriterSvc->write(track);
128  }
129  }
130 
131  ATH_MSG_VERBOSE(name() << " execute done");
132  }
133 
134  return StatusCode::SUCCESS;
135 }
136 
137 
139  const std::vector<Acts::detail::Step>& steps) const {
140 
141  std::lock_guard<std::mutex> lock(m_writeMutex);
142 
143  static std::ofstream out ATLAS_THREAD_SAFE ("steps.obj");
144  std::stringstream lstr;
145  lstr << "l";
146  for (const auto &step : steps) {
147  const auto &pos = step.position;
148  out << "v " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
149  lstr << " " << m_objVtxCount;
150  m_objVtxCount++;
151  }
152 
153  lstr << std::endl;
154 
155  out << lstr.str() << std::endl;
156 }
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:47
ActsGeometryContext.h
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:43
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
beamspotman.steps
int steps
Definition: beamspotman.py:503
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
Acts
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/xAODMuonPrepData/UtilFunctions.h:17
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
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
ActsGeometryContext
Include the GeoPrimitives which need to be put first.
Definition: ActsGeometryContext.h:27
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:986
ActsExtrapolationAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: ActsExtrapolationAlg.cxx:62
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:138
ActsPropagationOutput
std::pair< std::vector< Acts::detail::Step >, ActsRecordedMaterial > ActsPropagationOutput
Finally the output of the propagation test.
Definition: IActsExtrapolationTool.h:25
IActsExtrapolationTool.h
IAthRNGSvc.h