ATLAS Offline Software
Simulation
Tools
McEventCollectionFilter
src
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
5
#include "
PileUpTruthDecoration.h
"
6
//
7
#include "
AtlasHepMC/GenEvent.h
"
8
#include "
AtlasHepMC/GenVertex.h
"
9
#include "
StoreGate/WriteDecorHandle.h
"
10
11
PileUpTruthDecoration::PileUpTruthDecoration
(
const
std::string &
name
, ISvcLocator *pSvcLocator)
12
:
AthReentrantAlgorithm
(
name
, pSvcLocator)
13
{
14
}
15
16
17
StatusCode
PileUpTruthDecoration::initialize
()
18
{
19
// Check and initialize keys
20
ATH_CHECK
(
m_inputTruthCollectionKey
.
initialize
() );
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()"
);
33
SG::ReadHandle<McEventCollection>
inputCollection
(
m_inputTruthCollectionKey
, ctx);
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
41
SG::WriteDecorHandle<xAOD::IParticleContainer, float>
decHandle(
m_decKey
, ctx);
42
SG::ReadHandle<xAOD::IParticleContainer>
particles
(
m_particleKey
, ctx);
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
53
float
PileUpTruthDecoration::getPVtxZ
(
SG::ReadHandle<McEventCollection>
&
inputCollection
)
const
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
61
HepMC::ConstGenVertexPtr
hScatVx =
HepMC::barcode_to_vertex
(genEvt,-3);
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 >
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:40
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
PhysDESDM_SmpCaloId.inputCollection
inputCollection
Definition:
PhysDESDM_SmpCaloId.py:95
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:99
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
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:195
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:505
HepMC::ConstGenVertexPtr
const HepMC::GenVertex * ConstGenVertexPtr
Definition:
GenVertex.h:60
PileUpTruthDecoration::PileUpTruthDecoration
PileUpTruthDecoration(const std::string &name, ISvcLocator *pSvcLocator)
Definition:
PileUpTruthDecoration.cxx:11
Generated on Fri Jul 5 2024 21:24:26 for ATLAS Offline Software by
1.8.18