ATLAS Offline Software
Loading...
Searching...
No Matches
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
6#include "AthLinks/ElementLink.h"
7
9
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/DataSvc.h"
12#include "GaudiKernel/PhysicalConstants.h"
13
17
19
22
24
25xAODTruthParticleSlimmerMET::xAODTruthParticleSlimmerMET(const std::string &name, ISvcLocator *svcLoc)
26 : AthAlgorithm(name, svcLoc)
27{
28}
29
31{
33 ATH_MSG_INFO("xAOD output TruthParticleContainerMET name = " << m_xaodTruthParticleContainerNameMET.key());
35 ATH_MSG_INFO("xAOD input xAODTruthEventContainerName name = " << m_xaodTruthEventContainerName.key());
36 ATH_CHECK(m_classif.retrieve());
37 return StatusCode::SUCCESS;
38}
39
41{
42 // If the containers already exists then assume that nothing needs to be done
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
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
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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
ATLAS-specific HepMC functions.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
virtual bool isValid() override final
Can the handle be successfully dereferenced?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerNameMET
The key for the output xAOD truth containers.
virtual StatusCode initialize()
Function initialising the algorithm.
virtual StatusCode execute()
Function executing the algorithm.
PublicToolHandle< IMCTruthClassifier > m_classif
SG::ReadHandleKey< xAOD::TruthEventContainer > m_xaodTruthEventContainerName
xAODTruthParticleSlimmerMET(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
bool isGenStable() const
Check if this is generator stable particle.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
bool prompt(const xAOD::TruthParticle *part, ToolHandle< IMCTruthClassifier > &m_classif)
Definition Common.cxx:7
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
bool isInteracting(const T &p)
Identify if the particle with given PDG ID would not interact with the detector, i....
TruthParticle_v1 TruthParticle
Typedef to implementation.