ATLAS Offline Software
Loading...
Searching...
No Matches
PileUpTruthDecoration.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
6//
10
11PileUpTruthDecoration::PileUpTruthDecoration(const std::string &name, ISvcLocator *pSvcLocator)
12 : AthReentrantAlgorithm(name, pSvcLocator)
13{
14}
15
16
18{
19 // Check and initialize keys
21 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_inputTruthCollectionKey);
22 ATH_CHECK(m_particleKey.initialize());
23 ATH_MSG_VERBOSE("Initialized ReadHandleKey: " << m_particleKey);
24 ATH_CHECK(m_decKey.initialize());
25 ATH_MSG_VERBOSE("Initialized DecorHandleKey: " << m_decKey);
26 return StatusCode::SUCCESS;
27}
28
29
30StatusCode PileUpTruthDecoration::execute(const EventContext &ctx) const
31{
32 ATH_MSG_VERBOSE("PileUpTruthDecoration::execute()");
34 if (!inputCollection.isValid()) {
35 ATH_MSG_ERROR("Could not get input truth collection " << inputCollection.name() << " from store " << inputCollection.store());
36 return StatusCode::FAILURE;
37 }
38 ATH_MSG_DEBUG("Found input truth collection " << inputCollection.name() << " in store " << inputCollection.store());
39 const float refPVtxZ = getPVtxZ(inputCollection);
40
43 if( !particles.isValid() ) {
44 ATH_MSG_WARNING ("Couldn't retrieve container with key: " << m_particleKey.key() );
45 return StatusCode::FAILURE;
46 }
47 for( const xAOD::IParticle* truthParticle : *particles ) {
48 decHandle( *truthParticle ) = refPVtxZ;
49 }
50 return StatusCode::SUCCESS;
51}
52
54{
55 const HepMC::GenEvent* genEvt = *(inputCollection->begin());
56//AV: this should be vertex with id=-3, but it is not a standard.
57// This function should be rediscussed and standartized.
58#ifdef HEPMC3
59 const HepMC::ConstGenVertexPtr hScatVx = genEvt->vertices().size()<3 ? nullptr : genEvt->vertices().at(3-1);
60#else
62#endif
63 if (hScatVx) {
64 HepMC::FourVector pmvxpos=hScatVx->position();
65 return static_cast<float>(pmvxpos.z());
66 }
67 return 0.0f;
68}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for adding a decoration to an object.
An algorithm that can be simultaneously executed in multiple threads.
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &ctx) const override
SG::ReadHandleKey< xAOD::IParticleContainer > m_particleKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decKey
virtual float getPVtxZ(SG::ReadHandle< McEventCollection > &inputCollection) const
SG::ReadHandleKey< McEventCollection > m_inputTruthCollectionKey
PileUpTruthDecoration(const std::string &name, ISvcLocator *pSvcLocator)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::string store() const
Return the name of the store holding the object we are proxying.
const std::string & name() const
Return the StoreGate ID for the referenced object.
Handle class for adding a decoration to an object.
Class providing the definition of the 4-vector interface.
GenVertex * barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:629
const HepMC::GenVertex * ConstGenVertexPtr
Definition GenVertex.h:60