ATLAS Offline Software
Loading...
Searching...
No Matches
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
21namespace 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 }
44 ATH_CHECK(m_beamSpotKey.initialize());
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
95 HepGeom::Transform3D transform(
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
static Double_t a
Header file for AthHistogramAlgorithm.
CLHEP::HepLorentzVector * generate(const EventContext &ctx) const override final
computes the vertex displacement
Gaudi::Property< bool > m_timeSmearing
Do time smearing.
StatusCode initialize() override final
Athena algtool's Hooks.
VertexBeamCondPositioner(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
StatusCode finalize() override final
Athena algtool's Hooks.
Gaudi::Property< std::string > m_randomEngineName
Name of the random number stream.
Gaudi::Property< float > m_timeWidth
Width of time for smearing.
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey