ATLAS Offline Software
VertexBeamCondPositioner.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // class header include
7 
8 // For the speed of light
9 #include "GaudiKernel/PhysicalConstants.h"
10 
11 // CLHEP includes
12 #include "CLHEP/Vector/LorentzVector.h"
13 #include "CLHEP/Geometry/Point3D.h"
14 #include "CLHEP/Geometry/Transform3D.h"
15 
16 // RandomNumber generator
18 #include "CLHEP/Random/RandGaussZiggurat.h"
19 #include <cmath>
20 
21 namespace Simulation
22 {
23 
26  const std::string& n,
27  const IInterface* p )
28  : base_class(t,n,p)
29  {
30  }
31 
34  {
35  ATH_MSG_VERBOSE("Initializing ...");
36 
37  // retrieve the random number service
38  ATH_CHECK(m_rndGenSvc.retrieve());
39  m_randomEngine = m_rndGenSvc->getEngine(this, m_randomEngineName);
40  if (!m_randomEngine) {
41  ATH_MSG_ERROR("Could not get random number engine from RandomNumberService. Abort.");
42  return StatusCode::FAILURE;
43  }
45  // everything set up properly
46  return StatusCode::SUCCESS;
47  }
48 
51  {
52  ATH_MSG_VERBOSE("Finalizing ...");
53  return StatusCode::SUCCESS;
54  }
55 
57  CLHEP::HepLorentzVector *VertexBeamCondPositioner::generate(const EventContext& ctx) const
58  {
59  // Prepare the random engine
60  m_randomEngine->setSeed( name(), ctx );
61  CLHEP::HepRandomEngine* randomEngine(m_randomEngine->getEngine(ctx));
63  // See jira issue ATLASSIM-497 for an explanation of why calling
64  // shoot outside the CLHEP::HepLorentzVector constructor is
65  // necessary/preferable.
66  float vertexX = CLHEP::RandGaussZiggurat::shoot(randomEngine)*beamSpotHandle->beamSigma(0);
67  float vertexY = CLHEP::RandGaussZiggurat::shoot(randomEngine)*beamSpotHandle->beamSigma(1);
68  float vertexZ = CLHEP::RandGaussZiggurat::shoot(randomEngine)*beamSpotHandle->beamSigma(2);
69  // calculate the vertexSmearing
70  CLHEP::HepLorentzVector *vertexSmearing =
71  new CLHEP::HepLorentzVector( vertexX, vertexY, vertexZ, 0. );
72 
73  // (1) code from: Simulation/G4Atlas/G4AtlasUtilities/VertexPositioner.cxx
74  const double tx = tan( beamSpotHandle->beamTilt(1) );
75  const double ty = tan( beamSpotHandle->beamTilt(0) );
76 
77  const double sqrt_abc = sqrt(1. + tx*tx + ty*ty);
78  const double sqrt_fgh = sqrt(1. + ty*ty);
79 
80  const double a = ty/sqrt_abc;
81  const double b = tx/sqrt_abc;
82  const double c = 1./sqrt_abc;
83 
84  HepGeom::Point3D<double> from1(0,0,1);
85  HepGeom::Point3D<double> to1(a,b,c);
86 
87  const double f = 1./sqrt_fgh;
88  const double g = 0.;
89  const double h = -(ty)/sqrt_fgh;
90 
91  HepGeom::Point3D<double> from2(1,0,0);
92  HepGeom::Point3D<double> to2(f,g,h);
93 
94  // first rotation, then translation
96  HepGeom::Rotate3D(from1, from2, to1, to2).getRotation(),
97  CLHEP::Hep3Vector( beamSpotHandle->beamPos().x(),
98  beamSpotHandle->beamPos().y(),
99  beamSpotHandle->beamPos().z() )
100  );
101 
102  // FIXME: don't use endl in MsgStream printouts
103  ATH_MSG_VERBOSE("BeamSpotSvc reported beam position as " << beamSpotHandle->beamPos() << std::endl
104  << "\tWidth is (" << beamSpotHandle->beamSigma(0)
105  << ", " << beamSpotHandle->beamSigma(1) << ", "
106  << beamSpotHandle->beamSigma(2) << ")" << std::endl
107  << "\tTime smearing is " << (m_timeSmearing ? "on" : "off") << " with width " << m_timeWidth << std::endl
108  << "\tTilts are " << beamSpotHandle->beamTilt(0) << " and " << beamSpotHandle->beamTilt(1) << std::endl
109  << "\tVertex Position before transform: " << *vertexSmearing);
110 
111  // update with the tilt
112  *vertexSmearing = transform * HepGeom::Point3D<double>(*vertexSmearing);
113 
114  float vertexT = m_timeSmearing ? CLHEP::RandGaussZiggurat::shoot(randomEngine)*m_timeWidth*Gaudi::Units::c_light : 0.;
115  vertexSmearing->setT(vertexT);
116 
117  // and return it
118  return vertexSmearing;
119  }
120 
121 } // namespace Simulation
Simulation::VertexBeamCondPositioner::finalize
StatusCode finalize() override final
Athena algtool's Hooks.
Definition: VertexBeamCondPositioner.cxx:50
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Simulation::VertexBeamCondPositioner::m_randomEngineName
Gaudi::Property< std::string > m_randomEngineName
Name of the random number stream.
Definition: VertexBeamCondPositioner.h:56
Simulation::VertexBeamCondPositioner::m_timeSmearing
Gaudi::Property< bool > m_timeSmearing
Do time smearing.
Definition: VertexBeamCondPositioner.h:57
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Simulation::VertexBeamCondPositioner::generate
CLHEP::HepLorentzVector * generate(const EventContext &ctx) const override final
computes the vertex displacement
Definition: VertexBeamCondPositioner.cxx:57
Simulation::VertexBeamCondPositioner::m_rndGenSvc
ServiceHandle< IAthRNGSvc > m_rndGenSvc
Definition: VertexBeamCondPositioner.h:53
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
Simulation::VertexBeamCondPositioner::m_beamSpotKey
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
Definition: VertexBeamCondPositioner.h:52
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
VertexBeamCondPositioner.h
Simulation::VertexBeamCondPositioner::m_timeWidth
Gaudi::Property< float > m_timeWidth
Width of time for smearing.
Definition: VertexBeamCondPositioner.h:58
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
hist_file_dump.f
f
Definition: hist_file_dump.py:135
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
Simulation::VertexBeamCondPositioner::initialize
StatusCode initialize() override final
Athena algtool's Hooks.
Definition: VertexBeamCondPositioner.cxx:33
Simulation::VertexBeamCondPositioner::VertexBeamCondPositioner
VertexBeamCondPositioner(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: VertexBeamCondPositioner.cxx:25
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
RNGWrapper.h
a
TList * a
Definition: liststreamerinfos.cxx:10
h
Simulation
Definition: BeamEffectsAlg.cxx:21
python.compressB64.c
def c
Definition: compressB64.py:93
TileDCSDataPlotter.tx
tx
Definition: TileDCSDataPlotter.py:878