ATLAS Offline Software
PileupTruthParticleSlimmer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
22 using namespace std;
23 
24 
25 PileupTruthParticleSlimmer::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
51  if ( evtStore()->contains< xAOD::TruthParticleContainer >(m_xaodTruthPileupParticleContainerName) &&
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;
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 
103 unsigned int particleOutCome;
104 unsigned int result;
105 unsigned int particleType;
106 unsigned int particleOrigin;
107 int hadron_pdg;
108 Common::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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PileupTruthParticleSlimmer::m_xaodTruthPileupParticleContainerName
std::string m_xaodTruthPileupParticleContainerName
The key for the output xAOD truth containers.
Definition: PileupTruthParticleSlimmer.h:44
get_generator_info.result
result
Definition: get_generator_info.py:21
PileupTruthParticleSlimmer::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: PileupTruthParticleSlimmer.cxx:47
Common::classify
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
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TruthParticleContainer.h
PileupTruthParticleSlimmer::m_forceRerun
bool m_forceRerun
a flag to force rerunning (useful for rerunning on ESDs)
Definition: PileupTruthParticleSlimmer.h:53
particleType
Definition: particleType.h:29
PileupTruthParticleSlimmer::m_photon_pt_selection
double m_photon_pt_selection
Selection values for keeping photons and leptons.
Definition: PileupTruthParticleSlimmer.h:48
TruthParticleAuxContainer.h
xAOD::TruthParticleAuxContainer_v1
Auxiliary store for the truth vertices.
Definition: TruthParticleAuxContainer_v1.h:27
xAOD::TruthParticleAuxContainer
TruthParticleAuxContainer_v1 TruthParticleAuxContainer
Declare the latest version of the truth particle auxiliary container.
Definition: TruthParticleAuxContainer.h:16
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:58
McEventCollection.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::EgammaHelpers::isElectron
bool isElectron(const xAOD::Egamma *eg)
is the object an electron (not Fwd)
Definition: EgammaxAODHelpers.cxx:12
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
PileupTruthParticleSlimmer::m_abseta_selection
double m_abseta_selection
Definition: PileupTruthParticleSlimmer.h:50
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
PileupTruthParticleSlimmer::m_xaodTruthParticleContainerName
std::string m_xaodTruthParticleContainerName
Definition: PileupTruthParticleSlimmer.h:45
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
PileupTruthParticleSlimmer::PileupTruthParticleSlimmer
PileupTruthParticleSlimmer(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: PileupTruthParticleSlimmer.cxx:25
AthAlgorithm
Definition: AthAlgorithm.h:47
Common.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
PileupTruthParticleSlimmer.h
MC::isStable
bool isStable(const T &p)
Definition: HepMCHelpers.h:30
PileupTruthParticleSlimmer::m_lepton_pt_selection
double m_lepton_pt_selection
Definition: PileupTruthParticleSlimmer.h:49
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::EgammaHelpers::isPhoton
bool isPhoton(const xAOD::Egamma *eg)
is the object a photon
Definition: EgammaxAODHelpers.cxx:21
TruthParticle.h
GeV
#define GeV
Definition: CaloTransverseBalanceVecMon.cxx:30
PileupTruthParticleSlimmer::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: PileupTruthParticleSlimmer.cxx:38
HepMCHelpers.h
isMuon
bool isMuon(const T &p)
Definition: AtlasPID.h:145