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 
47  ISvcLocator *pSvcLocator)
48  : AthReentrantAlgorithm(name, pSvcLocator),
49  m_propStepWriterSvc("ActsPropStepRootWriterSvc", name),
50  m_rndmGenSvc("AthRNGSvc", name) ,
51  m_materialTrackWriterSvc("ActsMaterialTrackWriterSvc", name)
52 {}
53 
55 
56  ATH_MSG_DEBUG(name() << "::" << __FUNCTION__);
57 
58  ATH_CHECK(m_rndmGenSvc.retrieve());
59  ATH_CHECK(m_extrapolationTool.retrieve());
60  ATH_CHECK(m_propStepWriterSvc.retrieve());
61 
63  ATH_CHECK( m_materialTrackWriterSvc.retrieve() );
64  }
65 
66  return StatusCode::SUCCESS;
67 }
68 
69 StatusCode ActsExtrapolationAlg::execute(const EventContext &ctx) const {
70 
71  ATH_MSG_VERBOSE(name() << "::" << __FUNCTION__);
72 
73  ATHRNG::RNGWrapper *rngWrapper = m_rndmGenSvc->getEngine(this);
74  rngWrapper->setSeed(name(), ctx);
75  CLHEP::HepRandomEngine *rngEngine = rngWrapper->getEngine(ctx);
76 
77  ATH_MSG_VERBOSE("Extrapolating " << m_nParticlePerEvent << " particles");
78 
79  for (size_t i = 0; i < m_nParticlePerEvent; i++) {
80  double d0 = 0;
81  double z0 = 0;
82  double phi = rngEngine->flat() * 2 * M_PI - M_PI;
83  std::vector<double> etaRange = m_etaRange;
84  double etaMin = etaRange.at(0);
85  double etaMax = etaRange.at(1);
86  double eta = rngEngine->flat() * std::abs(etaMax - etaMin) + etaMin;
87 
88  std::vector<double> ptRange = m_ptRange;
89  double ptMin = ptRange.at(0) * 1_GeV;
90  double ptMax = ptRange.at(1) * 1_GeV;
91 
92  double pt = rngEngine->flat() * std::abs(ptMax - ptMin) + ptMin;
93 
94  Acts::Vector3 momentum(pt * std::cos(phi), pt * std::sin(phi),
95  pt * std::sinh(eta));
96 
98 
99  double charge = rngEngine->flat() > 0.5 ? -1 : 1;
100 
101  double qop = charge / momentum.norm();
102 
103  std::shared_ptr<Acts::PerigeeSurface> surface =
104  Acts::Surface::makeShared<Acts::PerigeeSurface>(
105  Acts::Vector3(0, 0, 0));
106 
107  double t = 0;
108  ATH_MSG_VERBOSE("Pseudo-particle: eta: " << eta << " phi: " << phi);
109 
110  Acts::BoundVector pars;
111  // cppcheck-suppress constStatement; will be able to initialize this directly with eigen 3.4
112  pars << d0, z0, phi, theta, qop, t;
113  std::optional<Acts::BoundSquareMatrix> cov = std::nullopt;
114 
116 
117  if (charge != 0.) {
118  // Perigee, no alignment -> default geo context
119  ActsGeometryContext gctx = m_extrapolationTool->trackingGeometryTool()
120  ->getNominalGeometryContext();
121  Acts::GenericBoundTrackParameters startParameters(std::move(surface), std::move(pars), std::move(cov), Acts::ParticleHypothesis::pion());
122  output = m_extrapolationTool->propagationSteps(ctx, startParameters);
123  if(output.first.size() == 0) {
124  ATH_MSG_WARNING("Got ZERO steps from the extrapolation tool");
125  }
126  if (m_writePropStep) {
127  m_propStepWriterSvc->write(output.first);
128  }
129 
132  track.first.first = Acts::Vector3(0,0,0);
133  track.first.second = momentum;
134  track.second = std::move(output.second);
136  }
137  }
138 
139  ATH_MSG_VERBOSE(name() << " execute done");
140  }
141 
142  return StatusCode::SUCCESS;
143 }
144 
145 
147  const std::vector<Acts::detail::Step>& steps) const {
148 
149  std::lock_guard<std::mutex> lock(m_writeMutex);
150 
151  static std::ofstream out ATLAS_THREAD_SAFE ("steps.obj");
152  std::stringstream lstr;
153  lstr << "l";
154  for (const auto &step : steps) {
155  const auto &pos = step.position;
156  out << "v " << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
157  lstr << " " << m_objVtxCount;
158  m_objVtxCount++;
159  }
160 
161  lstr << std::endl;
162 
163  out << lstr.str() << std::endl;
164 }
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:54
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
ActsGeometryContext.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
LArCellBinning.etaRange
etaRange
Filling Eta range.
Definition: LArCellBinning.py:128
theta
Scalar theta() const
theta method
Definition: AmgMatrixBasePlugin.h:71
ActsExtrapolationAlg::ActsExtrapolationAlg
ActsExtrapolationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ActsExtrapolationAlg.cxx:46
plotBeamSpotVxVal.cov
cov
Definition: plotBeamSpotVxVal.py:201
test_pyathena.pt
pt
Definition: test_pyathena.py:11
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
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:196
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
ActsExtrapolationAlg::m_writePropStep
Gaudi::Property< bool > m_writePropStep
Definition: ActsExtrapolationAlg.h:61
ActsExtrapolationAlg::m_nParticlePerEvent
Gaudi::Property< size_t > m_nParticlePerEvent
Definition: ActsExtrapolationAlg.h:57
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ActsExtrapolationAlg::ATLAS_THREAD_SAFE
size_t m_objVtxCount ATLAS_THREAD_SAFE
Definition: ActsExtrapolationAlg.h:66
beamspotman.steps
int steps
Definition: beamspotman.py:505
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
Acts
Definition: MultiTrajectory.h:45
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
ActsExtrapolationAlg::m_ptRange
Gaudi::Property< std::vector< double > > m_ptRange
Definition: ActsExtrapolationAlg.h:56
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:28
ActsExtrapolationAlg::m_propStepWriterSvc
ServiceHandle< IActsPropStepRootWriterSvc > m_propStepWriterSvc
Definition: ActsExtrapolationAlg.h:48
merge.output
output
Definition: merge.py:17
IActsPropStepRootWriterSvc.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
charge
double charge(const T &p)
Definition: AtlasPID.h:494
ActsExtrapolationAlg::m_etaRange
Gaudi::Property< std::vector< double > > m_etaRange
Definition: ActsExtrapolationAlg.h:55
ActsExtrapolationAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: ActsExtrapolationAlg.cxx:69
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:18
ActsExtrapolationAlg::m_rndmGenSvc
ServiceHandle< IAthRNGSvc > m_rndmGenSvc
Definition: ActsExtrapolationAlg.h:49
ActsExtrapolationAlg::m_writeMaterialTracks
Gaudi::Property< bool > m_writeMaterialTracks
Definition: ActsExtrapolationAlg.h:60
LArCellBinning.etaMin
etaMin
Definition: LArCellBinning.py:84
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
PhysDESDM_SmpCaloId.ptMin
ptMin
Definition: PhysDESDM_SmpCaloId.py:90
LArCellBinning.step
step
Definition: LArCellBinning.py:158
ActsExtrapolationAlg::m_extrapolationTool
ToolHandle< IActsExtrapolationTool > m_extrapolationTool
Definition: ActsExtrapolationAlg.h:51
ActsExtrapolationAlg::m_materialTrackWriterSvc
ServiceHandle< IActsMaterialTrackWriterSvc > m_materialTrackWriterSvc
Definition: ActsExtrapolationAlg.h:62
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ActsExtrapolationAlg::m_writeMutex
std::mutex m_writeMutex
Definition: ActsExtrapolationAlg.h:65
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:146
IActsTrackingGeometryTool.h
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