ATLAS Offline Software
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 //
7 #include "AtlasHepMC/GenEvent.h"
8 #include "AtlasHepMC/GenVertex.h"
10 
11 PileUpTruthDecoration::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 
30 StatusCode 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 }
GenEvent.h
SG::ReadHandle< McEventCollection >
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
GenVertex.h
PileUpTruthDecoration::initialize
virtual StatusCode initialize() override
Definition: PileUpTruthDecoration.cxx:17
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
PileUpTruthDecoration::getPVtxZ
virtual float getPVtxZ(SG::ReadHandle< McEventCollection > &inputCollection) const
Definition: PileUpTruthDecoration.cxx:53
PileUpTruthDecoration::m_inputTruthCollectionKey
SG::ReadHandleKey< McEventCollection > m_inputTruthCollectionKey
Definition: PileUpTruthDecoration.h:25
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
PileUpTruthDecoration::m_decKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decKey
Definition: PileUpTruthDecoration.h:27
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
PileUpTruthDecoration::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: PileUpTruthDecoration.cxx:30
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:376
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
PileUpTruthDecoration::m_particleKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_particleKey
Definition: PileUpTruthDecoration.h:26
PileUpTruthDecoration.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArG4FSStartPointFilter.particles
list particles
Definition: LArG4FSStartPointFilter.py:84
HepMC::barcode_to_vertex
GenVertex * barcode_to_vertex(const GenEvent *e, int id)
Definition: GenEvent.h:627
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition: GenVertex.h:60
PileUpTruthDecoration::PileUpTruthDecoration
PileUpTruthDecoration(const std::string &name, ISvcLocator *pSvcLocator)
Definition: PileUpTruthDecoration.cxx:11
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.