ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
GeneratorFilters
src
xAODTruthParticleSlimmerMET.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
AthenaKernel/errorcheck.h
"
6
#include "AthLinks/ElementLink.h"
7
8
#include "
GeneratorObjects/xAODTruthParticleLink.h
"
9
10
#include "GaudiKernel/MsgStream.h"
11
#include "GaudiKernel/DataSvc.h"
12
#include "GaudiKernel/PhysicalConstants.h"
13
14
#include "
xAODTruth/TruthParticle.h
"
15
#include "
xAODTruth/TruthParticleContainer.h
"
16
#include "
xAODTruth/TruthParticleAuxContainer.h
"
17
18
#include "
TruthUtils/HepMCHelpers.h
"
19
20
#include "
GeneratorFilters/xAODTruthParticleSlimmerMET.h
"
21
#include "
GeneratorFilters/Common.h
"
22
23
#include "
MCTruthClassifier/IMCTruthClassifier.h
"
24
25
xAODTruthParticleSlimmerMET::xAODTruthParticleSlimmerMET
(
const
std::string &name, ISvcLocator *svcLoc)
26
:
AthAlgorithm
(name, svcLoc)
27
{
28
}
29
30
StatusCode
xAODTruthParticleSlimmerMET::initialize
()
31
{
32
ATH_CHECK
(
m_xaodTruthParticleContainerNameMET
.initialize());
33
ATH_MSG_INFO
(
"xAOD output TruthParticleContainerMET name = "
<<
m_xaodTruthParticleContainerNameMET
.key());
34
ATH_CHECK
(
m_xaodTruthEventContainerName
.initialize());
35
ATH_MSG_INFO
(
"xAOD input xAODTruthEventContainerName name = "
<<
m_xaodTruthEventContainerName
.key());
36
ATH_CHECK
(
m_classif
.retrieve());
37
return
StatusCode::SUCCESS;
38
}
39
40
StatusCode
xAODTruthParticleSlimmerMET::execute
(
const
EventContext& ctx)
41
{
42
// If the containers already exists then assume that nothing needs to be done
43
if
(
evtStore
()->
contains<xAOD::TruthParticleContainer>
(
m_xaodTruthParticleContainerNameMET
.key()))
44
{
45
ATH_MSG_WARNING
(
"xAOD MET Truth Particles are already available in the event"
);
46
return
StatusCode::SUCCESS;
47
}
48
49
// Create new output container
50
SG::WriteHandle<xAOD::TruthParticleContainer>
xTruthParticleContainerMET(
m_xaodTruthParticleContainerNameMET
, ctx);
51
ATH_CHECK
(xTruthParticleContainerMET.
record
(std::make_unique<xAOD::TruthParticleContainer>(), std::make_unique<xAOD::TruthParticleAuxContainer>()));
52
ATH_MSG_INFO
(
"Recorded TruthParticleContainerMET with key: "
<<
m_xaodTruthParticleContainerNameMET
.key());
53
54
// Retrieve full TruthEventContainer container
55
SG::ReadHandle<xAOD::TruthEventContainer>
xTruthEventContainer{
m_xaodTruthEventContainerName
, ctx};
56
if
( !xTruthEventContainer.
isValid
() )
57
{
58
ATH_MSG_ERROR
(
"No TruthEvent collection with name "
<<
m_xaodTruthEventContainerName
.key() <<
" found in StoreGate!"
);
59
return
StatusCode::FAILURE;
60
}
61
62
// Set up decorators if needed
63
const
static
SG::AuxElement::Decorator<bool> isPrompt(
"isPrompt"
);
64
65
// Loop over full TruthParticle container
66
xAOD::TruthEventContainer::const_iterator
itr;
67
for
(itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
68
69
unsigned
int
nPart = (*itr)->nTruthParticles();
70
std::vector<int> uniqueID_list;
71
int
zero_uniqueID=0;
72
int
dup_uniqueID=0;
73
74
for
(
unsigned
int
iPart = 0; iPart < nPart; ++iPart) {
75
const
xAOD::TruthParticle
* theParticle = (*itr)->truthParticle(iPart);
76
77
int
my_uniqueID =
HepMC::uniqueID
(theParticle);
78
if
( my_uniqueID ==
HepMC::UNDEFINED_ID
) {
79
zero_uniqueID++;
80
continue
;
81
}
82
bool
found =
false
;
83
if
(uniqueID_list.size() > 0){
84
found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
85
if
(found) {
86
dup_uniqueID++;
87
continue
;}
88
}
89
uniqueID_list.push_back(my_uniqueID);
90
91
92
93
// stable and non-interacting, implemented from DerivationFramework
94
//https://gitlab.cern.ch/atlas/athena/-/blob/master/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/python/MCTruthCommon.py#L183
95
// which in turn use the implementation from Reconstruction
96
//https://gitlab.cern.ch/atlas/athena/blob/21.0/Reconstruction/MET/METReconstruction/Root/METTruthTool.cxx#L143
97
if
(!theParticle->
isGenStable
())
continue
;
98
if
(
MC::isInteracting
(theParticle))
continue
;
99
100
101
xAOD::TruthParticle
*xTruthParticle =
new
xAOD::TruthParticle
();
102
xTruthParticleContainerMET->push_back( xTruthParticle );
103
104
// Fill with numerical content
105
*xTruthParticle=*theParticle;
106
107
//Decorate
108
isPrompt(*xTruthParticle) =
Common::prompt
(theParticle,
m_classif
);
109
}
110
if
(zero_uniqueID != 0 || dup_uniqueID !=0 )
ATH_MSG_INFO
(
"Found "
<< zero_uniqueID <<
" uniqueID=0 particles and "
<<dup_uniqueID <<
"duplicated"
);
111
}
112
113
return
StatusCode::SUCCESS;
114
}
115
116
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_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
Common.h
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TruthParticleContainer.h
TruthParticle.h
HepMCHelpers.h
ATLAS-specific HepMC functions.
IMCTruthClassifier.h
TruthParticleAuxContainer.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
DataVector< TruthEvent_v1 >::const_iterator
DataModel_detail::const_iterator< DataVector > const_iterator
Definition
DataVector.h:838
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
xAODTruthParticleSlimmerMET::m_xaodTruthParticleContainerNameMET
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameMET
The key for the output xAOD truth containers.
Definition
xAODTruthParticleSlimmerMET.h:37
xAODTruthParticleSlimmerMET::execute
virtual StatusCode execute(const EventContext &ctx)
Function executing the algorithm.
Definition
xAODTruthParticleSlimmerMET.cxx:40
xAODTruthParticleSlimmerMET::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition
xAODTruthParticleSlimmerMET.cxx:30
xAODTruthParticleSlimmerMET::m_classif
PublicToolHandle< IMCTruthClassifier > m_classif
Definition
xAODTruthParticleSlimmerMET.h:39
xAODTruthParticleSlimmerMET::m_xaodTruthEventContainerName
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerName
Definition
xAODTruthParticleSlimmerMET.h:34
xAODTruthParticleSlimmerMET::xAODTruthParticleSlimmerMET
xAODTruthParticleSlimmerMET(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition
xAODTruthParticleSlimmerMET.cxx:25
xAOD::TruthParticle_v1::isGenStable
bool isGenStable() const
Check if this is generator stable particle.
Definition
TruthParticle_v1.cxx:311
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
Common::prompt
bool prompt(const xAOD::TruthParticle *part, ToolHandle< IMCTruthClassifier > &m_classif)
Definition
Common.cxx:7
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
MC::isInteracting
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
Definition
HepMCHelpers.h:34
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAODTruthParticleLink.h
xAODTruthParticleSlimmerMET.h
Generated on
for ATLAS Offline Software by
1.17.0