ATLAS Offline Software
GenEventRotator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // class header include
6 #include "GenEventRotator.h"
7 
8 // Athena includes
9 #include "CLHEP/Random/RandGaussZiggurat.h"
10 
11 // CLHEP includes
12 #include "CLHEP/Vector/LorentzVector.h"
13 #include "CLHEP/Units/PhysicalConstants.h"
14 
15 // HepMC includes
16 #include "AtlasHepMC/GenEvent.h"
17 #include "AtlasHepMC/GenParticle.h"
18 
19 namespace Simulation
20 {
22  GenEventRotator::GenEventRotator( const std::string& t,
23  const std::string& n,
24  const IInterface* p )
25  : base_class(t,n,p)
26  {
27  }
28 
31  {
32  ATH_MSG_VERBOSE("Initializing ...");
33  return StatusCode::SUCCESS;
34  }
35 
38  {
39  ATH_MSG_VERBOSE("Finalizing ...");
40  return StatusCode::SUCCESS;
41  }
42 
44  {
45  return StatusCode::SUCCESS;
46  }
47 
48  StatusCode GenEventRotator::initializeGenEvent(CLHEP::HepLorentzRotation& transform, const EventContext&) const
49  {
50  // Reset the transformation
51  transform = CLHEP::HepLorentzRotation(); //TODO drop this
52 
53  // Setting up three rotation matrices, via 3x3 rep. rather than even more messy EulerAngles
54  const double sinX = sin(m_xangle*CLHEP::deg);
55  const double cosX = cos(m_xangle*CLHEP::deg);
56  const CLHEP::HepRotation rotx(CLHEP::HepRep3x3(1.0,0.0,0.0, 0.0,cosX,-sinX, 0.0,sinX,cosX));
57  const double sinY = sin(m_yangle*CLHEP::deg);
58  const double cosY = cos(m_yangle*CLHEP::deg);
59  const CLHEP::HepRotation roty(CLHEP::HepRep3x3(cosY,0.0,sinY, 0.0,1.0,0.0, -sinY,0.0,cosY));
60  const double sinZ = sin(m_zangle*CLHEP::deg);
61  const double cosZ = cos(m_zangle*CLHEP::deg);
62  const CLHEP::HepRotation rotz(CLHEP::HepRep3x3(cosZ,-sinZ,0.0, sinZ,cosZ,0.0, 0.0,0.0,1.0));
63  // Combine the three rotations - order of trf execution is unimportant as they are orthogonal.
64  const CLHEP::HepRotation rot = rotx*roty*rotz;
65  transform.set(rot);
66  return StatusCode::SUCCESS;
67  }
68 
70  StatusCode GenEventRotator::manipulate(HepMC::GenEvent& ge, const EventContext& ctx) const
71  {
72  // Obtain the transformation
73  CLHEP::HepLorentzRotation transform = CLHEP::HepLorentzRotation();
75 
76  for(auto particleIter: ge) {
77  rotateParticle(particleIter, transform);
78  }
79  return StatusCode::SUCCESS;
80  }
81 
83  const CLHEP::HepLorentzRotation& transform) const
84  {
85  // Apply the same transformation for EVERY HepMC::GenParticle
86  const HepMC::FourVector mom = p->momentum();
87  CLHEP::HepLorentzVector hv(mom.px(), mom.py(), mom.pz(), mom.e()); //TODO check units
88  ATH_MSG_VERBOSE("initial momentum " << hv );
89  hv.transform(transform);
90  ATH_MSG_VERBOSE("transformed momentum " << hv);
91  p->set_momentum(HepMC::FourVector(hv.px(),hv.py(),hv.pz(),hv.e())); //TODO check units
92  }
93 
94 }
Simulation::GenEventRotator::manipulate
StatusCode manipulate(HepMC::GenEvent &ge, const EventContext &ctx) const override final
modifies the given GenEvent
Definition: GenEventRotator.cxx:70
GenEvent.h
Simulation::GenEventRotator::GenEventRotator
GenEventRotator(const std::string &t, const std::string &n, const IInterface *p)
Constructor with parameters.
Definition: GenEventRotator.cxx:22
HepMC::GenParticlePtr
GenParticle * GenParticlePtr
Definition: GenParticle.h:37
deg
#define deg
Definition: SbPolyhedron.cxx:17
Simulation::GenEventRotator::m_yangle
Gaudi::Property< double > m_yangle
Definition: GenEventRotator.h:50
Simulation::GenEventRotator::m_zangle
Gaudi::Property< double > m_zangle
Definition: GenEventRotator.h:51
Simulation::GenEventRotator::initializeGenEvent
StatusCode initializeGenEvent(CLHEP::HepLorentzRotation &transform, const EventContext &ctx) const
calculate the transformations that we want to apply to the particles in the current GenEvent
Definition: GenEventRotator.cxx:48
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
GenParticle.h
Simulation::GenEventRotator::initialize
StatusCode initialize() override final
Athena algtool's Hooks.
Definition: GenEventRotator.cxx:30
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ParticleGun_EoverP_Config.mom
mom
Definition: ParticleGun_EoverP_Config.py:63
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Simulation::GenEventRotator::finalize
StatusCode finalize() override final
Athena algtool's Hooks.
Definition: GenEventRotator.cxx:37
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Simulation::GenEventRotator::m_xangle
Gaudi::Property< double > m_xangle
Definition: GenEventRotator.h:49
Simulation::GenEventRotator::initializeAthenaEvent
StatusCode initializeAthenaEvent()
Definition: GenEventRotator.cxx:43
GenEventRotator.h
Simulation
Definition: BeamEffectsAlg.cxx:21
Simulation::GenEventRotator::rotateParticle
void rotateParticle(HepMC::GenParticlePtr &p, const CLHEP::HepLorentzRotation &transform) const
apply rotations to individual GenParticles
Definition: GenEventRotator.cxx:82
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36