ATLAS Offline Software
Loading...
Searching...
No Matches
Simulation::ZeroLifetimePositioner Class Reference

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

#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.
StatusCode initialize () override final
 Athena algtool's Hooks.
StatusCode finalize () override final
 Athena algtool's Hooks.
virtual StatusCode applyWorkaround (HepMC::GenEvent &ge) const override final
 Applies the workaround for zero-lifetime particles to the GenEvent.
virtual StatusCode removeWorkaround (HepMC::GenEvent &ge) const override final
 Removes the workaround for zero-lifetime particles from the GenEvent.

Private Member Functions

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

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}
#define ATH_MSG_DEBUG(x)
StatusCode manipulate(HepMC::GenEvent &ge, bool applyPatch, bool removePatch) const
modifies (displaces) the given GenEvent

◆ 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}
#define ATH_MSG_VERBOSE(x)

◆ 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}
Gaudi::Property< std::vector< int > > m_pdgCodesToCheck

◆ 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
66 const auto pdgCodesBegin = m_pdgCodesToCheck.begin();
67 const auto pdgCodesEnd = m_pdgCodesToCheck.end();
68 for (auto& curVtx: ge.vertices()) {
69 if (curVtx->particles_in().size()!=1 || curVtx->particles_out().size()!=1) { continue; }
70 const int pdgIn=curVtx->particles_in().front()->pdg_id();
71 const int pdgOut=curVtx->particles_out().front()->pdg_id();
72 if (pdgIn!=-pdgOut ||
73 std::find(pdgCodesBegin, pdgCodesEnd, std::abs(pdgIn))== pdgCodesEnd) {
74 continue;
75 }
76 HepMC::GenVertexPtr nextVtx = curVtx->particles_out().front()->end_vertex();
77 if(!nextVtx) { continue; }
78 ATH_MSG_DEBUG("Found a vertex to correct with incoming PDG code = " << pdgIn);
79 ATH_MSG_VERBOSE("Next Vertex:");
80 if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
81 HepMC::Print::line(nextVtx);
82 }
83 // NB Doing this check to explicitly avoid the fallback mechanism in
84 // HepMC3::GenVertex::position() to return the position of
85 // another GenVertex in the event if the position isn't set (or is set to zero)!
86 const HepMC::FourVector &nextVec = (nextVtx->has_set_position()) ? nextVtx->position() : HepMC::FourVector::ZERO_VECTOR();
87 const CLHEP::HepLorentzVector nextPos( nextVec.x(), nextVec.y(), nextVec.z(), nextVec.t() );
88 ATH_MSG_VERBOSE("Current Vertex:");
89 if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
90 HepMC::Print::line(curVtx);
91 }
92 if (applyPatch) {
93 HepMC::GenVertexPtr prevVtx = curVtx->particles_in().front()->production_vertex();
94 ATH_MSG_VERBOSE("Previous Vertex:");
95 if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
96 HepMC::Print::line(prevVtx);
97 }
98 // NB Doing this check to explicitly avoid the fallback mechanism in
99 // HepMC3::GenVertex::position() to return the position of
100 // another GenVertex in the event if the position isn't set (or is set to zero)!
101 const HepMC::FourVector &prevVec = (prevVtx->has_set_position()) ? prevVtx->position() : HepMC::FourVector::ZERO_VECTOR();
102 const CLHEP::HepLorentzVector prevPos( prevVec.x(), prevVec.y(), prevVec.z(), prevVec.t() );
103 CLHEP::HepLorentzVector newPos = 0.5*(prevPos+nextPos);
104 curVtx->set_position(HepMC::FourVector(newPos.x(),newPos.y(),newPos.z(),newPos.t()));
105 ATH_MSG_DEBUG("Revised current Vertex");
106 if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
107 HepMC::Print::line(curVtx);
108 }
109 }
110 if (removePatch) {
111 CLHEP::HepLorentzVector newPos = nextPos;
112 curVtx->set_position(HepMC::FourVector(newPos.x(),newPos.y(),newPos.z(),newPos.t()));
113 ATH_MSG_DEBUG("Revised current Vertex");
114 if (ATH_UNLIKELY(this->msgLvl (MSG::VERBOSE))) {
115 HepMC::Print::line(curVtx);
116 }
117 }
118 }
119
120 return StatusCode::SUCCESS;
121}
#define ATH_UNLIKELY(x)
HepMC3::FourVector FourVector
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23

◆ 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.

39{this, "ApplyPatch", false};

◆ 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.

41{ this, "PDGCodesToCheck", {421,511,531} }; // Apply fix to neutral mesons with oscillations: B0, B0s, D0

◆ m_removePatch

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

Definition at line 40 of file ZeroLifetimePositioner.h.

40{this, "RemovePatch", false};

The documentation for this class was generated from the following files: