ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
GeneratorFilters
src
xAODTruthParticleSlimmerElectron.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 "
GeneratorFilters/xAODTruthParticleSlimmerElectron.h
"
19
#include "
TruthUtils/HepMCHelpers.h
"
20
21
xAODTruthParticleSlimmerElectron::xAODTruthParticleSlimmerElectron
(
const
std::string &name, ISvcLocator *svcLoc)
22
:
AthAlgorithm
(name, svcLoc)
23
{
24
}
25
26
StatusCode
xAODTruthParticleSlimmerElectron::initialize
()
27
{
28
ATH_CHECK
(
m_xaodTruthParticleContainerNameElectron
.initialize());
29
ATH_MSG_INFO
(
"xAOD output TruthParticleContainerElectron name = "
<<
m_xaodTruthParticleContainerNameElectron
.key());
30
ATH_CHECK
(
m_xaodTruthEventContainerName
.initialize());
31
ATH_MSG_INFO
(
"xAOD input xAODTruthEventContainerName name = "
<<
m_xaodTruthEventContainerName
.key());
32
return
StatusCode::SUCCESS;
33
}
34
35
StatusCode
xAODTruthParticleSlimmerElectron::execute
(
const
EventContext& ctx)
36
{
37
// If the containers already exists then assume that nothing needs to be done
38
if
(
evtStore
()->
contains<xAOD::TruthParticleContainer>
(
m_xaodTruthParticleContainerNameElectron
.key()))
39
{
40
ATH_MSG_WARNING
(
"xAOD Electron Truth Particles are already available in the event"
);
41
return
StatusCode::SUCCESS;
42
}
43
44
// Create new output container
45
SG::WriteHandle<xAOD::TruthParticleContainer>
xTruthParticleContainerElectron(
m_xaodTruthParticleContainerNameElectron
, ctx);
46
ATH_CHECK
(xTruthParticleContainerElectron.
record
(std::make_unique<xAOD::TruthParticleContainer>(), std::make_unique<xAOD::TruthParticleAuxContainer>()));
47
ATH_MSG_INFO
(
"Recorded TruthParticleContainerElectron with key: "
<<
m_xaodTruthParticleContainerNameElectron
.key());
48
49
// Retrieve full TruthEventContainer container
50
SG::ReadHandle<xAOD::TruthEventContainer>
xTruthEventContainer{
m_xaodTruthEventContainerName
, ctx};
51
if
( !xTruthEventContainer.
isValid
() )
52
{
53
ATH_MSG_ERROR
(
"No TruthEvent collection with name "
<<
m_xaodTruthEventContainerName
.key() <<
" found in StoreGate!"
);
54
return
StatusCode::FAILURE;
55
}
56
// Set up decorators if needed
57
xAOD::TruthEventContainer::const_iterator
itr;
58
for
(itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
59
60
unsigned
int
nPart = (*itr)->nTruthParticles();
61
std::vector<int> uniqueID_list;
62
int
zero_uniqueID=0;
63
int
dup_uniqueID=0;
64
for
(
unsigned
int
iPart = 0; iPart < nPart; ++iPart) {
65
const
xAOD::TruthParticle
* theParticle = (*itr)->truthParticle(iPart);
66
int
my_uniqueID =
HepMC::uniqueID
(theParticle);
67
if
(my_uniqueID ==
HepMC::UNDEFINED_ID
) {
68
zero_uniqueID++;
69
continue
;
70
}
71
bool
found =
false
;
72
if
(uniqueID_list.size() > 0){
73
found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
74
if
(found) {
75
dup_uniqueID++;
76
continue
;}
77
}
78
uniqueID_list.push_back(my_uniqueID);
79
80
81
//Save stable Electrons
82
if
(
MC::isStable
(theParticle) &&
MC::isElectron
(theParticle))
83
{
84
xAOD::TruthParticle
*xTruthParticle =
new
xAOD::TruthParticle
();
85
xTruthParticleContainerElectron->push_back( xTruthParticle );
86
87
// Fill with numerical content
88
*xTruthParticle=*theParticle;
89
}
90
}
91
if
(zero_uniqueID!=0 || dup_uniqueID!=0)
ATH_MSG_INFO
(
"Found "
<< zero_uniqueID <<
" uniqueID=0 particles and "
<< dup_uniqueID <<
" duplicated"
);
92
}
93
94
return
StatusCode::SUCCESS;
95
}
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
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TruthParticleContainer.h
TruthParticle.h
HepMCHelpers.h
ATLAS-specific HepMC functions.
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.
xAODTruthParticleSlimmerElectron::m_xaodTruthEventContainerName
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerName
Definition
xAODTruthParticleSlimmerElectron.h:35
xAODTruthParticleSlimmerElectron::m_xaodTruthParticleContainerNameElectron
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameElectron
The key for the output xAOD truth containers.
Definition
xAODTruthParticleSlimmerElectron.h:38
xAODTruthParticleSlimmerElectron::xAODTruthParticleSlimmerElectron
xAODTruthParticleSlimmerElectron(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition
xAODTruthParticleSlimmerElectron.cxx:21
xAODTruthParticleSlimmerElectron::execute
virtual StatusCode execute(const EventContext &ctx)
Function executing the algorithm.
Definition
xAODTruthParticleSlimmerElectron.cxx:35
xAODTruthParticleSlimmerElectron::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition
xAODTruthParticleSlimmerElectron.cxx:26
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
MC::isElectron
bool isElectron(const T &p)
Definition
HepMCHelpers.h:209
MC::isStable
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
Definition
HepMCHelpers.h:46
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAODTruthParticleLink.h
xAODTruthParticleSlimmerElectron.h
Generated on
for ATLAS Offline Software by
1.17.0