ATLAS Offline Software
ExtrapolatorTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // ExtrapolatorTest.cxx, (c) ATLAS Detector software
8 
9 // Tracking
18 #include "GaudiKernel/SystemOfUnits.h"
19 // std
20 #include <cmath>
21 
22 //================ Constructor =================================================
23 
24 Trk::ExtrapolatorTest::ExtrapolatorTest(const std::string& name, ISvcLocator* pSvcLocator)
25  :
26  AthAlgorithm(name,pSvcLocator),
27  m_extrapolator("Trk::Extrapolator/AtlasExtrapolator"),
28  m_propagator("Trk::RungeKuttaPropagator/RungeKuttaPropagator"),
29  m_magFieldProperties(nullptr),
30  m_gaussDist(nullptr),
31  m_flatDist(nullptr),
32  m_sigmaD0(17.*Gaudi::Units::micrometer),
33  m_sigmaZ0(50.*Gaudi::Units::millimeter),
34  m_minPhi(-M_PI),
35  m_maxPhi(M_PI),
36  m_minEta(-3.),
37  m_maxEta(3.),
38  m_minP(0.5*Gaudi::Units::GeV),
39  m_maxP(50000.*Gaudi::Units::GeV),
40  m_direction(1),
41  m_particleType(2),
42  m_referenceSurfaces(0),
43  m_eventsPerExecute(-1),
44  m_useExtrapolator(false)
45 {
46  // used algorithms and alg tools
47  declareProperty("Extrapolator", m_extrapolator);
48  declareProperty("Propagator", m_propagator);
49 
50  // algorithm steering
51  declareProperty("StartPerigeeSigmaD0" , m_sigmaD0);
52  declareProperty("StartPerigeeSigmaZ0" , m_sigmaZ0);
53  declareProperty("StartPerigeeMinPhi" , m_minPhi);
54  declareProperty("StartPerigeeMaxPhi" , m_maxPhi);
55  declareProperty("StartPerigeeMinEta" , m_minEta);
56  declareProperty("StartPerigeeMaxEta" , m_maxEta);
57  declareProperty("StartPerigeeMinP" , m_minP);
58  declareProperty("StartPerigeeMaxP" , m_maxP);
59  declareProperty("StartDirection" , m_direction);
60  declareProperty("ParticleType" , m_particleType);
61 
62  // template for property decalration
63  declareProperty("ReferenceSurfaceRadius", m_referenceSurfaceRadius);
64  declareProperty("ReferenceSurfaceHalfZ", m_referenceSurfaceHalflength);
65  declareProperty("EventsPerExecute", m_eventsPerExecute );
66  declareProperty("UseExtrapolator", m_useExtrapolator );
67 }
68 
69 //================ Destructor =================================================
70 
72 {
73  delete m_gaussDist;
74  delete m_flatDist;
75  // cleanup of the surfaces
76  std::vector< std::vector< const Trk::Surface* > >::const_iterator surfaceTripleIter = m_referenceSurfaceTriples.begin();
77  std::vector< std::vector< const Trk::Surface* > >::const_iterator surfaceTripleIterEnd = m_referenceSurfaceTriples.end();
78  for ( ; surfaceTripleIter != surfaceTripleIterEnd; ++surfaceTripleIter)
79  {
80  std::vector<const Trk::Surface*>::const_iterator surfIter = (*surfaceTripleIter).begin();
81  std::vector<const Trk::Surface*>::const_iterator surfIterEnd = (*surfaceTripleIter).end();
82  for ( ; surfIter != surfIterEnd; delete (*surfIter), ++surfIter);
83 
84 
85  }
86 
87 }
88 
89 
90 //================ Initialisation =================================================
91 
93 {
94  // Code entered here will be executed once at program start.
95 
96  msg(MSG::INFO) << " initialize()" << endmsg;
97 
98  // Get Extrapolator from ToolService
99  if (m_extrapolator.retrieve().isFailure()) {
100  msg(MSG::FATAL) << "Could not retrieve Tool " << m_extrapolator << ". Exiting."<<endmsg;
101  return StatusCode::FAILURE;
102  }
103  // Get Propagator from ToolService
104  if (m_propagator.retrieve().isFailure()) {
105  msg(MSG::FATAL) << "Could not retrieve Tool " << m_propagator << ". Exiting."<<endmsg;
106  return StatusCode::FAILURE;
107  }
108 
109  m_magFieldProperties = new Trk::MagneticFieldProperties();
110 
111  if (m_referenceSurfaceRadius.size() == m_referenceSurfaceHalflength.size()) {
112  // assign the size
113  m_referenceSurfaces = m_referenceSurfaceRadius.size();
114  // loop over it and create the
115  std::vector<double>::iterator radiusIter = m_referenceSurfaceRadius.begin();
116  std::vector<double>::iterator radiusIterEnd = m_referenceSurfaceRadius.end();
117  std::vector<double>::iterator halfZIter = m_referenceSurfaceHalflength.begin();
118 
119  for ( ; radiusIter != radiusIterEnd; ++radiusIter, ++halfZIter){
120  // create the Surface triplet
121  std::vector< const Trk::Surface*> surfaceTriplet;
122  surfaceTriplet.push_back(new Trk::DiscSurface(Amg::Transform3D(Amg::Translation3D(0.,0.,*halfZIter)),0.,*radiusIter));
123  surfaceTriplet.push_back(new Trk::CylinderSurface(Amg::Transform3D(),*radiusIter, *halfZIter));
124  surfaceTriplet.push_back(new Trk::DiscSurface(Amg::Transform3D(Amg::Translation3D(0.,0.,-(*halfZIter))),0.,*radiusIter));
125 
126  ATH_MSG_INFO("Creating surfaces: R " << *radiusIter << " Z " << *halfZIter);
127  m_referenceSurfaceTriples.push_back(surfaceTriplet);
128 
129  m_referenceSurfaceNegativeBoundary.push_back(atan2(*radiusIter,-(*halfZIter)));
130  m_referenceSurfacePositiveBoundary.push_back(atan2(*radiusIter,(*halfZIter)));
131 
132  }
133  }
134 
135  m_gaussDist = new Rndm::Numbers(randSvc(), Rndm::Gauss(0.,1.));
136  m_flatDist = new Rndm::Numbers(randSvc(), Rndm::Flat(0.,1.));
137 
138  msg(MSG::INFO) << "initialize() successful in " << endmsg;
139 
140  if( m_eventsPerExecute > 0 ){
141  m_perigees.reserve(m_eventsPerExecute);
142  for( int i=0;i<m_eventsPerExecute;++i ) m_perigees.push_back(generatePerigee());
143  }
144 
145  return StatusCode::SUCCESS;
146 }
147 
148 //================ Finalisation =================================================
149 
151 {
152  // Code entered here will be executed once at the end of the program run.
153  return StatusCode::SUCCESS;
154 }
155 
157  // generate with random number generator
158  double d0 = m_gaussDist->shoot() * m_sigmaD0;
159  double z0 = m_gaussDist->shoot() * m_sigmaZ0;
160  double phi = m_minPhi + (m_maxPhi-m_minPhi)* m_flatDist->shoot();
161  double eta = m_minEta + m_flatDist->shoot()*(m_maxEta-m_minEta);
162  double theta = 2.*atan(exp(-eta));
163  double p = m_minP + m_flatDist->shoot()*(m_maxP-m_minP);
164  double charge = (m_flatDist->shoot() > 0.5 ) ? -1. : 1.;
165  double qOverP = charge/(p);
166  const Trk::PerigeeSurface perSurface;
167  return {d0, z0, phi, theta, qOverP,perSurface};
168 }
169 
170 //================ Execution ====================================================
171 
173 {
174 
175  if( m_eventsPerExecute <= 0 ) runTest(generatePerigee());
176  else for( int i=0;i<m_eventsPerExecute;++i ) runTest(m_perigees[i]);
177  return StatusCode::SUCCESS;
178 }
179 
180 
181 void Trk::ExtrapolatorTest::runTest( const Trk::Perigee& initialPerigee ) {
182  Trk::PropDirection propagationDirection = m_direction > 0 ? Trk::alongMomentum : oppositeMomentum;
183 
184  ATH_MSG_VERBOSE("Starting from : " << initialPerigee );
185  ATH_MSG_VERBOSE(" ---> with direction: " << propagationDirection );
186 
187 
188 
189  std::vector< std::vector< const Trk::Surface* > >::const_iterator surfaceTripleIter = m_referenceSurfaceTriples.begin();
190  std::vector< std::vector< const Trk::Surface* > >::const_iterator surfaceTripleIterEnd = m_referenceSurfaceTriples.end();
191 
192  std::vector<double>::iterator negRefIter = m_referenceSurfaceNegativeBoundary.begin();
193  std::vector<double>::iterator posRefIter = m_referenceSurfacePositiveBoundary.begin();
194 
195  double theta = initialPerigee.parameters()[Trk::theta];
196 
197  const EventContext& ctx = Gaudi::Hive::currentContext();
198  for (int refSurface = 0 ; surfaceTripleIter != surfaceTripleIterEnd; ++surfaceTripleIter, ++negRefIter, ++posRefIter ){
199  // decide which reference surface to take
200  refSurface = theta < (*posRefIter) ? 2 : 1;
201  refSurface = theta > (*negRefIter) ? 0 : 1;
202 
203  const Trk::Surface* destinationSurface = (*surfaceTripleIter)[refSurface];
204 
205  const auto* destParameters =
206  m_useExtrapolator
207  ? m_extrapolator->extrapolate(
208  ctx,
209  initialPerigee,
210  *destinationSurface,
211  propagationDirection,
212  false,
213  (Trk::ParticleHypothesis)m_particleType).release()
214  :
215 
216  m_propagator
217  ->propagate(ctx,
218  initialPerigee,
219  *destinationSurface,
220  propagationDirection,
221  false,
222  *m_magFieldProperties,
223  (Trk::ParticleHypothesis)m_particleType)
224  .release();
225 
226  if (destParameters) {
227  // global position parameter
228  //const Amg::Vector3D& gp = destParameters->position();
229 
230  // intersection output
231  ATH_MSG_VERBOSE(" [ intersection ] with surface at (x,y,z) = " << destParameters->position().x() << ", " << destParameters->position().y() << ", " << destParameters->position().z() );
232 
233  } else if (!destParameters)
234  ATH_MSG_DEBUG(" Extrapolation not successful! " );
235  delete destParameters;
236 
237  }
238 }
239 
240 //============================================================================================
241 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Trk::ExtrapolatorTest::m_maxEta
double m_maxEta
Maximal eta value.
Definition: ExtrapolatorTest.h:80
Trk::ExtrapolatorTest::m_minPhi
double m_minPhi
Minimal phi value.
Definition: ExtrapolatorTest.h:77
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
Trk::ExtrapolatorTest::m_maxPhi
double m_maxPhi
Maximal phi value.
Definition: ExtrapolatorTest.h:78
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
Trk::MagneticFieldProperties
Definition: MagneticFieldProperties.h:31
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Trk::ExtrapolatorTest::m_minEta
double m_minEta
Minimal eta value.
Definition: ExtrapolatorTest.h:79
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
Trk::oppositeMomentum
@ oppositeMomentum
Definition: PropDirection.h:21
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
Trk::ExtrapolatorTest::finalize
StatusCode finalize()
standard Athena-Algorithm method
Definition: ExtrapolatorTest.cxx:150
Trk::ExtrapolatorTest::runTest
void runTest(const Trk::Perigee &perigee)
Definition: ExtrapolatorTest.cxx:181
Trk::ExtrapolatorTest::m_referenceSurfaceRadius
std::vector< double > m_referenceSurfaceRadius
Definition: ExtrapolatorTest.h:91
M_PI
#define M_PI
Definition: ActiveFraction.h:11
Trk::z0
@ z0
Definition: ParamDefs.h:64
IExtrapolator.h
IPropagator.h
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
Trk::DiscSurface
Definition: DiscSurface.h:54
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
drawFromPickle.exp
exp
Definition: drawFromPickle.py:36
Trk::ExtrapolatorTest::execute
StatusCode execute()
standard Athena-Algorithm method
Definition: ExtrapolatorTest.cxx:172
Trk::ExtrapolatorTest::m_particleType
int m_particleType
the particle typre for the extrap.
Definition: ExtrapolatorTest.h:86
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
Trk::ExtrapolatorTest::generatePerigee
Trk::Perigee generatePerigee()
Definition: ExtrapolatorTest.cxx:156
Trk::ExtrapolatorTest::m_sigmaD0
double m_sigmaD0
Sigma of distribution for D0.
Definition: ExtrapolatorTest.h:75
Trk::ExtrapolatorTest::m_maxP
double m_maxP
Maximal p value.
Definition: ExtrapolatorTest.h:82
MagneticFieldProperties.h
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
Trk::ExtrapolatorTest::~ExtrapolatorTest
~ExtrapolatorTest()
Default Destructor.
Definition: ExtrapolatorTest.cxx:71
Trk::ExtrapolatorTest::m_sigmaZ0
double m_sigmaZ0
Sigma of distribution for Z0.
Definition: ExtrapolatorTest.h:76
Trk::PropDirection
PropDirection
Definition: PropDirection.h:19
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
python.SystemOfUnits.millimeter
int millimeter
Definition: SystemOfUnits.py:53
Trk::ExtrapolatorTest::initialize
StatusCode initialize()
standard Athena-Algorithm method
Definition: ExtrapolatorTest.cxx:92
lumiFormat.i
int i
Definition: lumiFormat.py:85
Trk::ExtrapolatorTest::m_direction
int m_direction
extrapolation direction
Definition: ExtrapolatorTest.h:84
Trk::theta
@ theta
Definition: ParamDefs.h:66
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
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
Trk::CylinderSurface
Definition: CylinderSurface.h:55
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
CylinderSurface.h
Trk::ExtrapolatorTest::m_referenceSurfaceHalflength
std::vector< double > m_referenceSurfaceHalflength
Definition: ExtrapolatorTest.h:92
python.SystemOfUnits.micrometer
int micrometer
Definition: SystemOfUnits.py:71
ParticleHypothesis.h
Trk::ExtrapolatorTest::m_useExtrapolator
bool m_useExtrapolator
Definition: ExtrapolatorTest.h:100
AthAlgorithm
Definition: AthAlgorithm.h:47
Athena::Units
Definition: Units.h:45
EventPrimitives.h
Trk::ExtrapolatorTest::ExtrapolatorTest
ExtrapolatorTest(const std::string &name, ISvcLocator *pSvcLocator)
Standard Athena-Algorithm Constructor.
Definition: ExtrapolatorTest.cxx:24
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Trk::d0
@ d0
Definition: ParamDefs.h:63
charge
double charge(const T &p)
Definition: AtlasPID.h:756
Trk::ExtrapolatorTest::m_minP
double m_minP
Minimal p value.
Definition: ExtrapolatorTest.h:81
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
ExtrapolatorTest.h
Trk::ExtrapolatorTest::m_propagator
ToolHandle< IPropagator > m_propagator
Definition: ExtrapolatorTest.h:68
DiscSurface.h
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
Trk::phi
@ phi
Definition: ParamDefs.h:75
Trk::ExtrapolatorTest::m_extrapolator
ToolHandle< IExtrapolator > m_extrapolator
The Extrapolator to be retrieved.
Definition: ExtrapolatorTest.h:67
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::ExtrapolatorTest::m_eventsPerExecute
int m_eventsPerExecute
Definition: ExtrapolatorTest.h:98