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

#include <ZeroLifetimePositioner.h>

Inheritance diagram for Simulation::ZeroLifetimePositioner:
Collaboration diagram for Simulation::ZeroLifetimePositioner:

Public Member Functions

 ZeroLifetimePositioner (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters. More...
 
StatusCode initialize () override final
 Athena algtool's Hooks. More...
 
StatusCode finalize () override final
 Athena algtool's Hooks. More...
 
virtual StatusCode applyWorkaround (HepMC::GenEvent &ge) const override final
 Applies the workaround for zero-lifetime particles to the GenEvent. More...
 
virtual StatusCode removeWorkaround (HepMC::GenEvent &ge) const override final
 Removes the workaround for zero-lifetime particles from the GenEvent. More...
 

Private Member Functions

StatusCode manipulate (HepMC::GenEvent &ge, bool applyPatch, bool removePatch) const
 modifies (displaces) the given GenEvent More...
 

Private Attributes

Gaudi::Property< bool > m_applyPatch {this, "ApplyPatch", false}
 
Gaudi::Property< bool > m_removePatch {this, "RemovePatch", false}
 
Gaudi::Property< std::vector< int > > m_pdgCodesToCheck { this, "PDGCodesToCheck", {421,511,531} }
 

Detailed Description

This tool works around the issue of zero-lifetime particles in Geant4.

Definition at line 21 of file ZeroLifetimePositioner.h.

Constructor & Destructor Documentation

◆ ZeroLifetimePositioner()

Simulation::ZeroLifetimePositioner::ZeroLifetimePositioner ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor with parameters.

Constructor.

Definition at line 19 of file ZeroLifetimePositioner.cxx.

21  : base_class(name, pSvcLocator)
22 {
23 }

Member Function Documentation

◆ applyWorkaround()

StatusCode Simulation::ZeroLifetimePositioner::applyWorkaround ( HepMC::GenEvent &  ge) const
finaloverridevirtual

Applies the workaround for zero-lifetime particles to the GenEvent.

Definition at line 47 of file ZeroLifetimePositioner.cxx.

48 {
49  ATH_MSG_DEBUG("applyWorkaround");
50  return this->manipulate(ge, m_applyPatch, false);
51 }

◆ finalize()

StatusCode Simulation::ZeroLifetimePositioner::finalize ( )
finaloverride

Athena algtool's Hooks.

Definition at line 40 of file ZeroLifetimePositioner.cxx.

41 {
42  ATH_MSG_VERBOSE("Finalizing ...");
43  return StatusCode::SUCCESS;
44 }

◆ initialize()

StatusCode Simulation::ZeroLifetimePositioner::initialize ( )
finaloverride

Athena algtool's Hooks.

Definition at line 27 of file ZeroLifetimePositioner.cxx.

28 {
29  ATH_MSG_VERBOSE("Initializing ...");
30  for(auto& pdgcode : m_pdgCodesToCheck) {
31  pdgcode = std::abs(pdgcode);
32  ATH_MSG_DEBUG("Will look for verices where " << pdgcode <<
33  " oscillates into -" << pdgcode << " (and vice versa).");
34  }
35  return StatusCode::SUCCESS;
36 }

◆ manipulate()

StatusCode Simulation::ZeroLifetimePositioner::manipulate ( HepMC::GenEvent &  ge,
bool  applyPatch,
bool  removePatch 
) const
private

modifies (displaces) the given GenEvent

Definition at line 62 of file ZeroLifetimePositioner.cxx.

63 {
64  // loop over the vertices in the event
65 #ifdef HEPMC3
66 
67  const auto pdgCodesBegin = m_pdgCodesToCheck.begin();
68  const auto pdgCodesEnd = m_pdgCodesToCheck.end();
69  for (auto& curVtx: ge.vertices()) {
70  if (curVtx->particles_in().size()!=1 || curVtx->particles_out().size()!=1) { continue; }
71  const int pdgIn=curVtx->particles_in().front()->pdg_id();
72  const int pdgOut=curVtx->particles_out().front()->pdg_id();
73  if (pdgIn!=-pdgOut ||
74  std::find(pdgCodesBegin, pdgCodesEnd, std::abs(pdgIn))== pdgCodesEnd) {
75  continue;
76  }
77  HepMC::GenVertexPtr nextVtx = curVtx->particles_out().front()->end_vertex();
78  if(!nextVtx) { continue; }
79  ATH_MSG_DEBUG("Found a vertex to correct with incoming PDG code = " << pdgIn);
80  ATH_MSG_VERBOSE("Next Vertex:");
81  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
82  HepMC::Print::line(nextVtx);
83  }
84  // NB Doing this check to explicitly avoid the fallback mechanism in
85  // HepMC3::GenVertex::position() to return the position of
86  // another GenVertex in the event if the position isn't set (or is set to zero)!
87  const HepMC::FourVector &nextVec = (nextVtx->has_set_position()) ? nextVtx->position() : HepMC::FourVector::ZERO_VECTOR();
88  const CLHEP::HepLorentzVector nextPos( nextVec.x(), nextVec.y(), nextVec.z(), nextVec.t() );
89  ATH_MSG_VERBOSE("Current Vertex:");
90  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
91  HepMC::Print::line(curVtx);
92  }
93  if (applyPatch) {
94  HepMC::GenVertexPtr prevVtx = curVtx->particles_in().front()->production_vertex();
95  ATH_MSG_VERBOSE("Previous Vertex:");
96  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
97  HepMC::Print::line(prevVtx);
98  }
99  // NB Doing this check to explicitly avoid the fallback mechanism in
100  // HepMC3::GenVertex::position() to return the position of
101  // another GenVertex in the event if the position isn't set (or is set to zero)!
102  const HepMC::FourVector &prevVec = (prevVtx->has_set_position()) ? prevVtx->position() : HepMC::FourVector::ZERO_VECTOR();
103  const CLHEP::HepLorentzVector prevPos( prevVec.x(), prevVec.y(), prevVec.z(), prevVec.t() );
104  CLHEP::HepLorentzVector newPos = 0.5*(prevPos+nextPos);
105  curVtx->set_position(HepMC::FourVector(newPos.x(),newPos.y(),newPos.z(),newPos.t()));
106  ATH_MSG_DEBUG("Revised current Vertex");
107  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
108  HepMC::Print::line(curVtx);
109  }
110  }
111  if (removePatch) {
112  CLHEP::HepLorentzVector newPos = nextPos;
113  curVtx->set_position(HepMC::FourVector(newPos.x(),newPos.y(),newPos.z(),newPos.t()));
114  ATH_MSG_DEBUG("Revised current Vertex");
115  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
116  HepMC::Print::line(curVtx);
117  }
118  }
119  }
120 #else
121  HepMC::GenEvent::vertex_iterator vtxIt = ge.vertices_begin();
122  const HepMC::GenEvent::vertex_iterator vtxItEnd = ge.vertices_end();
123  const auto pdgCodesBegin = m_pdgCodesToCheck.begin();
124  const auto pdgCodesEnd = m_pdgCodesToCheck.end();
125  for (; vtxIt != vtxItEnd; ++vtxIt) {
126  // quick access:
127  auto curVtx = (*vtxIt);
128  if (curVtx->particles_in_size()!=1 || curVtx->particles_out_size()!=1) { continue; }
129  const int pdgIn=(*(curVtx->particles_in_const_begin()))->pdg_id();
130  const int pdgOut=(*(curVtx->particles_out_const_begin()))->pdg_id();
131  if (pdgIn!=-pdgOut ||
132  std::find(pdgCodesBegin, pdgCodesEnd, std::abs(pdgIn))== pdgCodesEnd) {
133  continue;
134  }
135  auto nextVtx = (*(curVtx->particles_out_const_begin()))->end_vertex();
136  if(!nextVtx) { continue; }
137  ATH_MSG_DEBUG("Found a vertex to correct with incoming PDG code = " << pdgIn);
138  ATH_MSG_VERBOSE("Next Vertex:");
139  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
140  nextVtx->print();
141  }
142  const HepMC::FourVector &nextVec = nextVtx->position();
143  const CLHEP::HepLorentzVector nextPos( nextVec.x(), nextVec.y(), nextVec.z(), nextVec.t() );
144  ATH_MSG_VERBOSE("Current Vertex:");
145  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
146  curVtx->print();
147  }
148  if (applyPatch) {
149  auto prevVtx = (*(curVtx->particles_in_const_begin()))->production_vertex();
150  ATH_MSG_VERBOSE("Previous Vertex:");
151  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
152  prevVtx->print();
153  }
154  const HepMC::FourVector &prevVec = prevVtx->position();
155  const CLHEP::HepLorentzVector prevPos( prevVec.x(), prevVec.y(), prevVec.z(), prevVec.t() );
156  CLHEP::HepLorentzVector newPos = 0.5*(prevPos+nextPos);
157  curVtx->set_position(newPos);
158  ATH_MSG_DEBUG("Revised current Vertex");
159  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
160  curVtx->print();
161  }
162  }
163  if (removePatch) {
164  const CLHEP::HepLorentzVector& newPos = nextPos;
165  curVtx->set_position(newPos);
166  ATH_MSG_DEBUG("Revised current Vertex");
167  if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
168  curVtx->print();
169  }
170  }
171  }
172 #endif
173 
174  return StatusCode::SUCCESS;
175 }

◆ removeWorkaround()

StatusCode Simulation::ZeroLifetimePositioner::removeWorkaround ( HepMC::GenEvent &  ge) const
finaloverridevirtual

Removes the workaround for zero-lifetime particles from the GenEvent.

Definition at line 54 of file ZeroLifetimePositioner.cxx.

55 {
56  ATH_MSG_DEBUG("removeWorkaround");
57  return this->manipulate(ge, false, m_removePatch);
58 }

Member Data Documentation

◆ m_applyPatch

Gaudi::Property<bool> Simulation::ZeroLifetimePositioner::m_applyPatch {this, "ApplyPatch", false}
private

Definition at line 39 of file ZeroLifetimePositioner.h.

◆ m_pdgCodesToCheck

Gaudi::Property<std::vector<int> > Simulation::ZeroLifetimePositioner::m_pdgCodesToCheck { this, "PDGCodesToCheck", {421,511,531} }
private

Definition at line 41 of file ZeroLifetimePositioner.h.

◆ m_removePatch

Gaudi::Property<bool> Simulation::ZeroLifetimePositioner::m_removePatch {this, "RemovePatch", false}
private

Definition at line 40 of file ZeroLifetimePositioner.h.


The documentation for this class was generated from the following files:
HepMC::GenVertexPtr
HepMC::GenVertex * GenVertexPtr
Definition: GenVertex.h:59
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
HepMC::Print::line
void line(std::ostream &os, const GenEvent &e)
Definition: GenEvent.h:676
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Simulation::ZeroLifetimePositioner::m_applyPatch
Gaudi::Property< bool > m_applyPatch
Definition: ZeroLifetimePositioner.h:39
Simulation::ZeroLifetimePositioner::m_removePatch
Gaudi::Property< bool > m_removePatch
Definition: ZeroLifetimePositioner.h:40
Simulation::ZeroLifetimePositioner::manipulate
StatusCode manipulate(HepMC::GenEvent &ge, bool applyPatch, bool removePatch) const
modifies (displaces) the given GenEvent
Definition: ZeroLifetimePositioner.cxx:62
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
Simulation::ZeroLifetimePositioner::m_pdgCodesToCheck
Gaudi::Property< std::vector< int > > m_pdgCodesToCheck
Definition: ZeroLifetimePositioner.h:41