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#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}
#define ATH_UNLIKELY(x)
void line(std::ostream &os, const GenEvent &e)
Definition GenEvent.h:678
HepMC::GenVertex * GenVertexPtr
Definition GenVertex.h:59

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