ATLAS Offline Software
Loading...
Searching...
No Matches
ZeroLifetimePositioner.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5// class header include
7
8// HepMC includes
11
12// CLHEP includes
13#include "CLHEP/Vector/LorentzVector.h"
14
15#include <limits>
16#include <algorithm>
17
20 ISvcLocator* pSvcLocator )
21 : base_class(name, pSvcLocator)
22{
23}
24
25
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}
37
38
41{
42 ATH_MSG_VERBOSE("Finalizing ...");
43 return StatusCode::SUCCESS;
44}
45
46
48{
49 ATH_MSG_DEBUG("applyWorkaround");
50 return this->manipulate(ge, m_applyPatch, false);
51}
52
53
55{
56 ATH_MSG_DEBUG("removeWorkaround");
57 return this->manipulate(ge, false, m_removePatch);
58}
59
60
62StatusCode Simulation::ZeroLifetimePositioner::manipulate(HepMC::GenEvent& ge, bool applyPatch, bool removePatch) const
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_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
#define ATH_UNLIKELY(x)
Gaudi::Property< std::vector< int > > m_pdgCodesToCheck
virtual StatusCode removeWorkaround(HepMC::GenEvent &ge) const override final
Removes the workaround for zero-lifetime particles from the GenEvent.
ZeroLifetimePositioner(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
StatusCode finalize() override final
Athena algtool's Hooks.
StatusCode initialize() 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.
StatusCode manipulate(HepMC::GenEvent &ge, bool applyPatch, bool removePatch) const
modifies (displaces) the given GenEvent
HepMC3::FourVector FourVector
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39