ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Generators
GeneratorFilters
src
xAODTruthParticleSlimmerGen.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/xAODTruthParticleSlimmerGen.h
"
21
22
#include "
MCTruthClassifier/IMCTruthClassifier.h
"
23
24
xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen
(
const
std::string &name, ISvcLocator *svcLoc)
25
:
AthAlgorithm
(name, svcLoc)
26
{
27
}
28
29
StatusCode
xAODTruthParticleSlimmerGen::initialize
()
30
{
31
ATH_CHECK
(
m_xaodTruthParticleContainerNameGen
.initialize());
32
ATH_MSG_INFO
(
"xAOD output TruthParticleContainerGen name = "
<<
m_xaodTruthParticleContainerNameGen
.key());
33
ATH_CHECK
(
m_xaodTruthEventContainerName
.initialize());
34
ATH_CHECK
(
m_classif
.retrieve());
35
36
return
StatusCode::SUCCESS;
37
}
38
39
StatusCode
xAODTruthParticleSlimmerGen::execute
(
const
EventContext& ctx)
40
{
41
// Create new output container
42
SG::WriteHandle<xAOD::TruthParticleContainer>
xTruthParticleContainerGen(
m_xaodTruthParticleContainerNameGen
, ctx);
43
ATH_CHECK
(xTruthParticleContainerGen.
record
(std::make_unique<xAOD::TruthParticleContainer>(),
44
std::make_unique<xAOD::TruthParticleAuxContainer>()));
45
ATH_MSG_DEBUG
(
"Recorded TruthParticleContainerGen with key: "
<<
m_xaodTruthParticleContainerNameGen
.key());
46
47
// Retrieve full TruthEventContainer container
48
SG::ReadHandle<xAOD::TruthEventContainer>
xTruthEventContainer{
m_xaodTruthEventContainerName
, ctx};
49
if
( !xTruthEventContainer.
isValid
() )
50
{
51
ATH_MSG_ERROR
(
"No TruthEvent collection with name "
<<
m_xaodTruthEventContainerName
<<
" found in StoreGate!"
);
52
return
StatusCode::FAILURE;
53
}
54
55
// Loop over full TruthParticle container
56
xAOD::TruthEventContainer::const_iterator
itr;
57
for
(itr = xTruthEventContainer->begin(); itr!=xTruthEventContainer->end(); ++itr) {
58
59
unsigned
int
nPart = (*itr)->nTruthParticles();
60
std::vector<int> uniqueID_list;
61
int
zero_uniqueID=0;
62
int
dup_uniqueID=0;
63
64
for
(
unsigned
int
iPart = 0; iPart < nPart; ++iPart) {
65
const
xAOD::TruthParticle
* theParticle = (*itr)->truthParticle(iPart);
66
67
const
int
my_uniqueID =
HepMC::uniqueID
(theParticle);
68
if
(my_uniqueID ==
HepMC::UNDEFINED_ID
) {
69
zero_uniqueID++;
70
continue
;
71
}
72
bool
found =
false
;
73
if
(uniqueID_list.size() > 0){
74
found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
75
if
(found) {
76
dup_uniqueID++;
77
continue
;}
78
}
79
uniqueID_list.push_back(my_uniqueID);
80
81
82
83
xAOD::TruthParticle
*xTruthParticle =
new
xAOD::TruthParticle
();
84
xTruthParticleContainerGen->push_back( xTruthParticle );
85
// Fill with numerical content
86
*xTruthParticle=*theParticle;
87
88
}
89
if
(zero_uniqueID != 0 || dup_uniqueID != 0)
ATH_MSG_DEBUG
(
"Found "
<< zero_uniqueID <<
" uniqueID=0 particles and "
<< dup_uniqueID <<
" duplicated"
);
90
}
91
92
return
StatusCode::SUCCESS;
93
}
94
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_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
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
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.
xAODTruthParticleSlimmerGen::m_xaodTruthEventContainerName
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerName
Definition
xAODTruthParticleSlimmerGen.h:33
xAODTruthParticleSlimmerGen::m_xaodTruthParticleContainerNameGen
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameGen
The key for the output xAOD truth containers.
Definition
xAODTruthParticleSlimmerGen.h:32
xAODTruthParticleSlimmerGen::execute
virtual StatusCode execute(const EventContext &ctx)
Function executing the algorithm.
Definition
xAODTruthParticleSlimmerGen.cxx:39
xAODTruthParticleSlimmerGen::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition
xAODTruthParticleSlimmerGen.cxx:29
xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen
xAODTruthParticleSlimmerGen(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition
xAODTruthParticleSlimmerGen.cxx:24
xAODTruthParticleSlimmerGen::m_classif
PublicToolHandle< IMCTruthClassifier > m_classif
Definition
xAODTruthParticleSlimmerGen.h:35
HepMC::uniqueID
int uniqueID(const T &p)
Definition
MagicNumbers.h:89
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAODTruthParticleLink.h
xAODTruthParticleSlimmerGen.h
Generated on
for ATLAS Offline Software by
1.17.0