ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
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
const
HepMC::ConstGenVertexPtr
hScatVx = genEvt->vertices().size()<3 ? nullptr : genEvt->vertices().at(3-1);
59
if
(hScatVx) {
60
HepMC::FourVector
pmvxpos=hScatVx->position();
61
return
static_cast<
float
>
(pmvxpos.z());
62
}
63
return
0.0f;
64
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
GenEvent.h
GenVertex.h
PileUpTruthDecoration.h
WriteDecorHandle.h
Handle class for adding a decoration to an object.
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
PileUpTruthDecoration::initialize
virtual StatusCode initialize() override
Definition
PileUpTruthDecoration.cxx:17
PileUpTruthDecoration::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
PileUpTruthDecoration.cxx:30
PileUpTruthDecoration::m_particleKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_particleKey
Definition
PileUpTruthDecoration.h:26
PileUpTruthDecoration::m_decKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_decKey
Definition
PileUpTruthDecoration.h:27
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
PileUpTruthDecoration::PileUpTruthDecoration
PileUpTruthDecoration(const std::string &name, ISvcLocator *pSvcLocator)
Definition
PileUpTruthDecoration.cxx:11
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition
StoreGate/src/VarHandleBase.cxx:382
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition
AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition
StoreGate/StoreGate/WriteDecorHandle.h:100
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
HepMC::FourVector
HepMC3::FourVector FourVector
Definition
SimpleVector.h:11
HepMC::ConstGenVertexPtr
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition
GenVertex.h:24
HepMC::GenEvent
HepMC3::GenEvent GenEvent
Definition
GenEvent.h:39
Generated on
for ATLAS Offline Software by
1.17.0