ATLAS Offline Software
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 
25 using namespace std;
26 
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);
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
67  if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthTauParticleContainerName.key()))
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 
156 unsigned int particleOutCome;
157 unsigned int result;
158 unsigned int particleType;
159 unsigned int particleOrigin;
160 int hadron_pdg;
161 Common::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 }
xAODTruthParticleSlimmerTau::m_tau_pt_selection
DoubleProperty m_tau_pt_selection
Selection values for keeping taus and leptons.
Definition: xAODTruthParticleSlimmerTau.h:49
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
xAOD::TruthParticle_v1::absPdgId
int absPdgId() const
Absolute PDG ID code (often useful)
get_generator_info.result
result
Definition: get_generator_info.py:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
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
SG::ReadHandle< xAOD::TruthParticleContainer >
TruthParticleContainer.h
xAODTruthParticleSlimmerTau::m_xaodTruthTauParticleContainerName
SG::WriteHandleKey< xAOD::TruthParticleContainer > m_xaodTruthTauParticleContainerName
The key for the output xAOD truth containers.
Definition: xAODTruthParticleSlimmerTau.h:46
xAODTruthParticleSlimmerTau::m_xaodTruthParticleContainerName
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_xaodTruthParticleContainerName
Definition: xAODTruthParticleSlimmerTau.h:43
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
particleType
Definition: particleType.h:29
xAODTruthParticleSlimmerTau::xAODTruthParticleSlimmerTau
xAODTruthParticleSlimmerTau(const std::string &name, ISvcLocator *svcLoc)
Regular algorithm constructor.
Definition: xAODTruthParticleSlimmerTau.cxx:27
TruthParticleAuxContainer.h
MC::isPhysical
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
Definition: HepMCHelpers.h:51
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
IMCTruthClassifier.h
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:59
McEventCollection.h
beamspotman.n
n
Definition: beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAODTruthParticleSlimmerTau::initialize
virtual StatusCode initialize()
Function initialising the algorithm.
Definition: xAODTruthParticleSlimmerTau.cxx:32
xAODTruthParticleSlimmerTau.h
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
HepMC::uniqueID
int uniqueID(const T &p)
Definition: MagicNumbers.h:116
xAODTruthParticleSlimmerTau::execute
virtual StatusCode execute()
Function executing the algorithm.
Definition: xAODTruthParticleSlimmerTau.cxx:61
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
isTau
bool isTau(const T &p)
Definition: AtlasPID.h:205
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:56
xAODTruthParticleSlimmerTau::m_abseta_selection
DoubleProperty m_abseta_selection
Definition: xAODTruthParticleSlimmerTau.h:50
xAOD::TruthParticle_v1::nChildren
size_t nChildren() const
Number of children of this particle.
Definition: TruthParticle_v1.cxx:135
Common.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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::TruthParticle_v1::child
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:144
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
xAODTruthParticleSlimmerTau::m_classifier
PublicToolHandle< IMCTruthClassifier > m_classifier
Definition: xAODTruthParticleSlimmerTau.h:55
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.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
isSMNeutrino
bool isSMNeutrino(const T &p)
Definition: AtlasPID.h:212
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:161
xAODTruthParticleSlimmerTau::sumDaughterNeutrinos
CLHEP::HepLorentzVector sumDaughterNeutrinos(const xAOD::TruthParticle *tau)
Definition: xAODTruthParticleSlimmerTau.cxx:42
TruthParticle.h
HepMCHelpers.h
xAOD::TruthParticle_v1::abseta
double abseta() const
The absolute pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:213