ATLAS Offline Software
Loading...
Searching...
No Matches
PileupTruthParticleSlimmer.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
9
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/DataSvc.h"
12#include "GaudiKernel/PhysicalConstants.h"
13
17
21
22using namespace std;
23
24
25PileupTruthParticleSlimmer::PileupTruthParticleSlimmer( const string& name, ISvcLocator* svcLoc )
26: AthAlgorithm( name, svcLoc ), m_classifier("MCTruthClassifier/MCTruthClassifier")
27{
29 declareProperty("xAODTruthParticleContainerName", m_xaodTruthParticleContainerName="TruthParticles" );
30 declareProperty("xAODTruthPileupParticleContainerName", m_xaodTruthPileupParticleContainerName="TruthPileupParticles" );
31 declareProperty( "ForceRerun", m_forceRerun = false);
32 declareProperty("photon_pt_selection", m_photon_pt_selection=8.*Gaudi::Units::GeV ); //User provides units in MeV!
33 declareProperty("lepton_pt_selection", m_lepton_pt_selection=1.*Gaudi::Units::GeV ); //User provides units in MeV!
34 declareProperty("abseta_selection", m_abseta_selection=4.5 );
35}
36
37
39 ATH_MSG_DEBUG("Initializing");
40 ATH_MSG_DEBUG("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName );
41 ATH_MSG_DEBUG("xAOD output TruthPileupParticleContainer name = " << m_xaodTruthPileupParticleContainerName );
42 ATH_CHECK(m_classifier.retrieve());
43 return StatusCode::SUCCESS;
44}
45
46
48
49
50 // If the containers already exist then assume that nothing needs to be done
52 !m_forceRerun) {
53 ATH_MSG_WARNING("xAOD Pileup Truth Particles are already available in the event");
54 return StatusCode::SUCCESS;
55 }
56
57
58 // Create new output container
59 xAOD::TruthParticleContainer* xTruthPileupParticleContainer = new xAOD::TruthParticleContainer();
60 CHECK( evtStore()->record( xTruthPileupParticleContainer, m_xaodTruthPileupParticleContainerName ) );
61 xAOD::TruthParticleAuxContainer* xTruthPileupParticleAuxContainer = new xAOD::TruthParticleAuxContainer();
62 CHECK( evtStore()->record( xTruthPileupParticleAuxContainer, m_xaodTruthPileupParticleContainerName + "Aux." ) );
63 xTruthPileupParticleContainer->setStore( xTruthPileupParticleAuxContainer );
64 ATH_MSG_DEBUG( "Recorded TruthPileupParticleContainer with key: " << m_xaodTruthPileupParticleContainerName );
65
66 // Retrieve full TruthParticle container
67 const xAOD::TruthParticleContainer* xTruthParticleContainer = nullptr;
68 if (evtStore()->retrieve(xTruthParticleContainer, m_xaodTruthParticleContainerName).isFailure()) {
69 ATH_MSG_ERROR("No TruthParticle collection with name " << m_xaodTruthParticleContainerName << " found in StoreGate!");
70 return StatusCode::FAILURE;
71 }
72
73 // Set up decorators
74 const static SG::AuxElement::Decorator<unsigned int> originDecorator("classifierParticleOrigin");
75 const static SG::AuxElement::Decorator<unsigned int> typeDecorator("classifierParticleType");
76 const static SG::AuxElement::Decorator<unsigned int> outcomeDecorator("classifierParticleOutCome");
77 const static SG::AuxElement::Decorator<unsigned int> classificationDecorator("Classification");
78 const static SG::AuxElement::Decorator<int> parenthadronPIDDecorator("parentHadronID");
79
80 // Loop over full TruthParticle container
81 //unsigned int nParticles = xTruthParticleContainer->size();
82 //for (unsigned int iPart=0; iPart<nParticles; ++iPart) {
83 for (const xAOD::TruthParticle *theParticle : *xTruthParticleContainer) {
84
85 //We only want to save stable particles (lifetime > 10mm)
86 if (!MC::isStable(theParticle)){
87 continue; //Skip this particle
88 }
89
90 float this_abseta = theParticle->abseta();
91 float this_pt = theParticle->pt();
92
93 //Save photons above 8 GeV or electrons/muons above 1 GeV, & within detector acceptance (4.5)
94 if( ( (MC::isPhoton(theParticle) && this_pt >= m_photon_pt_selection) || ((MC::isElectron(theParticle) || MC::isMuon(theParticle)) && this_pt >= m_lepton_pt_selection) )
95 && (this_abseta < m_abseta_selection) ){
96
97 xAOD::TruthParticle* xTruthParticle = new xAOD::TruthParticle();
98 xTruthPileupParticleContainer->push_back( xTruthParticle );
99
100 // Fill with numerical content
101 *xTruthParticle=*theParticle;
102
103unsigned int particleOutCome;
104unsigned int result;
105unsigned int particleType;
106unsigned int particleOrigin;
107int hadron_pdg;
108Common::classify(m_classifier,theParticle,particleOutCome,result,hadron_pdg,particleType,particleOrigin );
109 typeDecorator(*xTruthParticle) = particleType;
110 originDecorator(*xTruthParticle) = particleOrigin;
111 outcomeDecorator(*xTruthParticle) = particleOutCome;
112
113 classificationDecorator(*xTruthParticle) = result;
114 parenthadronPIDDecorator(*xTruthParticle) = hadron_pdg;
115 }
116
117 } //end of loop over particles
118
119 return StatusCode::SUCCESS;
120}
121
122
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
ATLAS-specific HepMC functions.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
value_type push_back(value_type pElem)
Add an element to the end of the collection.
double m_photon_pt_selection
Selection values for keeping photons and leptons.
virtual StatusCode initialize()
Function initialising the algorithm.
ToolHandle< IMCTruthClassifier > m_classifier
std::string m_xaodTruthPileupParticleContainerName
The key for the output xAOD truth containers.
PileupTruthParticleSlimmer(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
bool m_forceRerun
a flag to force rerunning (useful for rerunning on ESDs)
virtual StatusCode execute()
Function executing the algorithm.
SG::Decorator< T, ALLOC > Decorator
Definition AuxElement.h:575
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
void classify(ToolHandle< IMCTruthClassifier > &m_classif, const xAOD::TruthParticle *theParticle, unsigned int &particleOutCome, unsigned int &result, int &hadron_pdg, unsigned int &particleType, unsigned int &particleOrigin)
Definition Common.cxx:96
bool isPhoton(const T &p)
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isMuon(const T &p)
STL namespace.
TruthParticleAuxContainer_v2 TruthParticleAuxContainer
Declare the latest version of the truth particle auxiliary container.
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.