ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Simulation::GenEventVertexPositioner Class Reference

#include <GenEventVertexPositioner.h>

Inheritance diagram for Simulation::GenEventVertexPositioner:
Collaboration diagram for Simulation::GenEventVertexPositioner:

Public Member Functions

 GenEventVertexPositioner (const std::string &t, const std::string &n, const IInterface *p)
 Constructor with parameters. More...
 
StatusCode initialize () override final
 Athena algtool's Hooks. More...
 
StatusCode finalize () override final
 Athena algtool's Hooks. More...
 
StatusCode manipulate (HepMC::GenEvent &ge, const EventContext &ctx) const override final
 modifies (displaces) the given GenEvent More...
 

Private Attributes

ToolHandleArray< ILorentzVectorGeneratorm_vertexShifters {this, "VertexShifters", {}}
 Vertex Shifters applied in the given order. More...
 

Detailed Description

This tool takes a HepMC::GenEvent and applies geometrical modifications, such as random vertex smearing, beam tilt, etc.

based on: https://svnweb.cern.ch/trac/atlasoff/browser/Simulation/G4Atlas/G4AtlasUtilities/trunk/src/VertexPositioner.cxx

Author
Andreas.Salzburger -at- cern.ch , Elmar.Ritsch -at- cern.ch

Definition at line 29 of file GenEventVertexPositioner.h.

Constructor & Destructor Documentation

◆ GenEventVertexPositioner()

Simulation::GenEventVertexPositioner::GenEventVertexPositioner ( const std::string &  t,
const std::string &  n,
const IInterface *  p 
)

Constructor with parameters.

Constructor.

Definition at line 21 of file GenEventVertexPositioner.cxx.

24  : base_class(t,n,p)
25  {
26  }

Member Function Documentation

◆ finalize()

StatusCode Simulation::GenEventVertexPositioner::finalize ( )
finaloverride

Athena algtool's Hooks.

Definition at line 42 of file GenEventVertexPositioner.cxx.

43  {
44  ATH_MSG_VERBOSE("Finalizing ...");
45  return StatusCode::SUCCESS;
46  }

◆ initialize()

StatusCode Simulation::GenEventVertexPositioner::initialize ( )
finaloverride

Athena algtool's Hooks.

Definition at line 29 of file GenEventVertexPositioner.cxx.

30  {
31  ATH_MSG_VERBOSE("Initializing ...");
32 
33  // retrieve Vertex Shifters
34  if ( !m_vertexShifters.empty() ) {
35  ATH_CHECK(m_vertexShifters.retrieve());
36  }
37 
38  return StatusCode::SUCCESS;
39  }

◆ manipulate()

StatusCode Simulation::GenEventVertexPositioner::manipulate ( HepMC::GenEvent &  ge,
const EventContext &  ctx 
) const
finaloverride

modifies (displaces) the given GenEvent

Definition at line 49 of file GenEventVertexPositioner.cxx.

50  {
51  // Grab signal_process_vertex pointer
52  auto signalProcVtx=HepMC::signal_process_vertex(&ge);
53  if(!signalProcVtx) {
54  ATH_MSG_ERROR("Expected GenEvent::signal_process_vertex() to already have been set at this point!");
55  return StatusCode::FAILURE;
56  }
57 
58  // loop over all given ILorentzVectorGenerator AlgTools
59  for (const auto& vertexShifter : m_vertexShifters) {
60 
61  // call VertexShifter and let it compute the current shift
62  CLHEP::HepLorentzVector *curShift = vertexShifter->generate(ctx);
63  if (!curShift) {
64  ATH_MSG_ERROR("Vertex Shifter AthenaTool returned zero-pointer! Ignore.");
65  continue;
66  }
67 
68  ATH_MSG_VERBOSE("Retrieved Vertex shift of: " << *curShift << " from " << vertexShifter->name());
69 
70  // As signal process vertex is a pointer, there is some risk
71  // that the pointer points to a vertex somewhere else in the
72  // event, rather than a unique / new vertex, in which case we
73  // will modify its position in the loop below and will not need
74  // to treat it separately.
75  bool modifySigVtx(true);
76 
77  // loop over the vertices in the event, they are in respect with another
78  // (code from Simulation/Fatras/FatrasAlgs/McEventPreProcessing.cxx)
79 #ifdef HEPMC3
80  for(auto& curVtx: ge.vertices()) {
81  // NB Doing this check to explicitly avoid the fallback mechanism in
82  // HepMC3::GenVertex::position() to return the position of
83  // another GenVertex in the event if the position isn't set (or is set to zero)!
84  const HepMC::FourVector &curPos = (curVtx->has_set_position()) ? curVtx->position() : HepMC::FourVector::ZERO_VECTOR();
85 #else
86  auto vtxIt = ge.vertices_begin();
87  auto vtxItEnd = ge.vertices_end();
88  for( ; vtxIt != vtxItEnd; ++vtxIt) {
89  // quick access:
90  auto curVtx = (*vtxIt);
91  const HepMC::FourVector &curPos = curVtx->position();
92 #endif
93 
94  // get a copy of the current vertex position
95  CLHEP::HepLorentzVector newPos( curPos.x(), curPos.y(), curPos.z(), curPos.t() );
96  // and update it with the given smearing
97  newPos += (*curShift);
98 
99  ATH_MSG_VERBOSE( "Original vtx position = " << curPos.x() << ", " << curPos.y() << ", " << curPos.z() );
100  ATH_MSG_VERBOSE( "Updated vtx position = " << newPos );
101 
102  // store the updated position in the vertex
103  curVtx->set_position( HepMC::FourVector(newPos.x(),newPos.y(),newPos.z(),newPos.t()));
104  if(modifySigVtx && signalProcVtx==curVtx) {
105  modifySigVtx=false;
106  }
107  }
108 
109  // Do the same for the signal process vertex if still required.
110  if (modifySigVtx) {
111  const HepMC::FourVector &curPos = HepMC::signal_process_vertex(&ge)->position();
112  CLHEP::HepLorentzVector newPos( curPos.x(), curPos.y(), curPos.z(), curPos.t() );
113  newPos += (*curShift);
114  (HepMC::signal_process_vertex(&ge))->set_position( HepMC::FourVector(newPos.x(),newPos.y(),newPos.z(),newPos.t()) );
115  }
116 
117  // memory cleanup
118  delete curShift;
119  }
120 
121  return StatusCode::SUCCESS;
122  }

Member Data Documentation

◆ m_vertexShifters

ToolHandleArray<ILorentzVectorGenerator> Simulation::GenEventVertexPositioner::m_vertexShifters {this, "VertexShifters", {}}
private

Vertex Shifters applied in the given order.

Definition at line 44 of file GenEventVertexPositioner.h.


The documentation for this class was generated from the following files:
Simulation::GenEventVertexPositioner::m_vertexShifters
ToolHandleArray< ILorentzVectorGenerator > m_vertexShifters
Vertex Shifters applied in the given order.
Definition: GenEventVertexPositioner.h:44
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HepMC::signal_process_vertex
GenVertex * signal_process_vertex(const GenEvent *e)
Definition: GenEvent.h:625