ATLAS Offline Software
Loading...
Searching...
No Matches
xAODTruthParticleSlimmerTau.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
11
12#include "GaudiKernel/MsgStream.h"
13#include "GaudiKernel/DataSvc.h"
14#include "GaudiKernel/PhysicalConstants.h"
15
19
21
24
25using namespace std;
26
27xAODTruthParticleSlimmerTau::xAODTruthParticleSlimmerTau(const string &name, ISvcLocator *svcLoc)
28 : AthAlgorithm(name, svcLoc)
29{
30}
31
33{
34 ATH_CHECK(m_classifier.retrieve());
36 ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName.key());
38 ATH_MSG_INFO("xAOD output TruthTauParticleContainer name = " << m_xaodTruthTauParticleContainerName.key());
39 return StatusCode::SUCCESS;
40}
41
43{
44 CLHEP::HepLorentzVector nu(0, 0, 0, 0);
45 if (MC::isSMNeutrino(part) && MC::isPhysical(part))
46 {
47 nu.setPx(part->px());
48 nu.setPy(part->py());
49 nu.setPz(part->pz());
50 nu.setE(part->e());
51 }
52 if (!part->hasDecayVtx())
53 return nu;
54
55 for (size_t n = 0; n < part->nChildren(); ++n)
56 nu += sumDaughterNeutrinos(part->child(n));
57
58 return nu;
59}
60
62{
63
64 CLHEP::HepLorentzVector nutau;
65
66 // If the containers already exists then assume that nothing needs to be done
68 {
69 ATH_MSG_WARNING("xAOD Tau Truth Particles are already available in the event");
70 return StatusCode::SUCCESS;
71 }
72
73 // Create new output container
75 ATH_CHECK(xTruthTauParticleContainer.record(std::make_unique<xAOD::TruthParticleContainer>(), std::make_unique<xAOD::TruthParticleAuxContainer>()));
76 ATH_MSG_INFO("Recorded TruthTauParticleContainer with key: " << m_xaodTruthTauParticleContainerName.key());
77
78 // Retrieve full TruthParticle container
80 if ( !xTruthParticleContainer.isValid() )
81 {
82 ATH_MSG_ERROR("No TruthParticle collection with name " << m_xaodTruthParticleContainerName.key() << " found in StoreGate!");
83 return StatusCode::FAILURE;
84 }
85
86 // Set up decorators
87
88 const static SG::AuxElement::Decorator<unsigned int> originDecorator("classifierParticleOrigin");
89 const static SG::AuxElement::Decorator<unsigned int> typeDecorator("classifierParticleType");
90 const static SG::AuxElement::Decorator<unsigned int> outcomeDecorator("classifierParticleOutCome");
91 const static SG::AuxElement::Decorator<unsigned int> classificationDecorator("Classification");
92 const static SG::AuxElement::Decorator<int> parenthadronPIDDecorator("parentHadronID");
93
94 // sum of neutrinos 4-vector in tau decay products
95 const static SG::AuxElement::Decorator<CLHEP::HepLorentzVector> nuDecorator("nuVector");
96 const static SG::AuxElement::Decorator<int> tauTypeDecorator("tauType");
97
98 // Loop over full TruthParticle container
99
100 std::vector<int> uniqueID_list;
101 int zero_uniqueID=0;
102 int dup_uniqueID = 0;
103
104 unsigned int nParticles = xTruthParticleContainer->size();
105
106 for (unsigned int iPart = 0; iPart < nParticles; ++iPart)
107 {
108 ElementLink<xAOD::TruthParticleContainer> eltp(*xTruthParticleContainer, iPart);
109 const xAOD::TruthParticle *theParticle = (*xTruthParticleContainer)[iPart];
110
111 int my_uniqueID = HepMC::uniqueID(theParticle);
112 if ( my_uniqueID == HepMC::UNDEFINED_ID ) {
113 zero_uniqueID++;
114 continue;
115 }
116 bool found = false;
117 if (uniqueID_list.size() > 0){
118 found = (std::find(uniqueID_list.begin(), uniqueID_list.end(), my_uniqueID) != uniqueID_list.end());
119 if(found) {
120 dup_uniqueID++;
121 continue;}
122 }
123 uniqueID_list.push_back(my_uniqueID);
124
125 float this_abseta = theParticle->abseta();
126 float this_pt = theParticle->pt();
127
128
129 //Save Taus above 0.001 GeV, & with any eta (may be changed on JOs level eg. to dectector acceptance of eta 4.5)
130 // see GeneratorFilters/share/common/xAODTauFilter_Common.py
131 // we want to avoid status 3 taus
132 if (MC::isPhysical(theParticle) && MC::isTau(theParticle) && this_pt >= m_tau_pt_selection && this_abseta < m_abseta_selection)
133 {
134 xAOD::TruthParticle *xTruthParticle = new xAOD::TruthParticle();
135
136 xTruthTauParticleContainer->push_back(xTruthParticle);
137 // Fill with numerical content
138 *xTruthParticle=*theParticle;
139 const xAOD::TruthParticle *tau = theParticle;
140 nutau = sumDaughterNeutrinos(tau);
141
142 nuDecorator(*xTruthParticle) = nutau;
143
144 int tauType = 0;
145 for (size_t n = 0; n < tau->nChildren(); ++n)
146 {
147 if (tau->child(n)->absPdgId() == MC::NU_E)
148 tauType = 1; //Tau decays into an electron
149 else if (tau->child(n)->absPdgId() == MC::NU_MU)
150 tauType = 2; //Tau decays into a muon
151 else if (MC::isTau(tau->child(n)))
152 tauType = 11; //Tau radiates a particle and decays into another tau
153 }
154 tauTypeDecorator(*xTruthParticle) = tauType;
155
156unsigned int particleOutCome;
157unsigned int result;
158unsigned int particleType;
159unsigned int particleOrigin;
160int hadron_pdg;
161Common::classify(m_classifier,theParticle,particleOutCome,result,hadron_pdg,particleType,particleOrigin );
162 typeDecorator(*xTruthParticle) = particleType;
163 originDecorator(*xTruthParticle) = particleOrigin;
164 outcomeDecorator(*xTruthParticle) = particleOutCome;
165
166 classificationDecorator(*xTruthParticle) = result;
167 parenthadronPIDDecorator(*xTruthParticle) = hadron_pdg;
168 }
169
170 } //end of loop over particles
171 if(zero_uniqueID!=0 || dup_uniqueID != 0) ATH_MSG_INFO("Found " << zero_uniqueID << " uniqueID=0 particles and " << dup_uniqueID << " duplicated");
172 return StatusCode::SUCCESS;
173}
#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:
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.
xAODTruthParticleSlimmerTau(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
virtual StatusCode execute()
Function executing the algorithm.
virtual StatusCode initialize()
Function initialising the algorithm.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerName
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthTauParticleContainerName
The key for the output xAOD truth containers.
PublicToolHandle< IMCTruthClassifier > m_classifier
CLHEP::HepLorentzVector sumDaughterNeutrinos(const xAOD::TruthParticle *tau)
DoubleProperty m_tau_pt_selection
Selection values for keeping taus and leptons.
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
double abseta() const
The absolute pseudorapidity ( ) of the particle.
int absPdgId() const
Absolute PDG ID code (often useful)
virtual double pt() const override final
The transverse momentum ( ) of the particle.
size_t nChildren() const
Number of children of this particle.
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
int uniqueID(const T &p)
constexpr int UNDEFINED_ID
bool isSMNeutrino(const T &p)
static const int NU_MU
static const int NU_E
bool isTau(const T &p)
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
STL namespace.
TruthParticle_v1 TruthParticle
Typedef to implementation.