ATLAS Offline Software
Tool_InputConverter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 #include "xAODTau/TauJet.h"
11 #include "xAODPFlow/PFO.h"
12 #include "xAODPFlow/PFODefs.h"
14 
15 
17  asg::AsgTool(name)
18 {
19 }
20 
22 
24 
25  ATH_MSG_INFO(" initialize()");
26  m_init=true;
27 
28  ATH_CHECK( HelperFunctions::bindToolHandle( m_Tool_InformationStore, m_Tool_InformationStoreName) ); //ABR only
29 
30  ATH_CHECK( m_Tool_InformationStore.retrieve() );
31 
32  ATH_CHECK( m_Tool_InformationStore->getInfo_Int("TauConstituents_UsePionMass", m_Config_UsePionMass) );
33  ATH_CHECK( m_Tool_InformationStore->getInfo_Double("TauConstituents_Types_DeltaRCore", m_Config_TauConstituents_Types_DeltaRCore) );
34  ATH_CHECK( m_Tool_InformationStore->getInfo_Double("TauConstituents_PreselectionMinEnergy", m_Config_TauConstituents_PreselectionMinEnergy) );
35 
36  return StatusCode::SUCCESS;
37 }
38 
39 
41  return energy >= m_Config_TauConstituents_PreselectionMinEnergy;
42 }
43 
44 
45 // PFO converter
47  PanTau::TauConstituent* &tauConstituent,
48  const xAOD::TauJet* tauJet) const {
49 
50  // check for invalid eta, phi, e "NAN" values -- likely no longer needed, raise severity to be sure
51  if (pfo->eta() != pfo->eta() || pfo->phi() != pfo->phi() || pfo->e() != pfo->e()) {
52  ATH_MSG_ERROR("Will not convert PFO with eta value of " << pfo->eta() << " -> return to Tool_TauConstituentGetter");
53  return StatusCode::FAILURE;
54  }
55 
56  // Check whether neutral input pfo has pion mass (it may have if xAOD is being reprocessed)
57  // If it does,
58  // - old (R21) approach: make it massless again and use that
59  // - new (R22) approach: complain and abort, reconstruction from AOD implies rebuilding PFOs upstream, so the mass should not have been set at that point
60  if (!pfo->isCharged() && pfo->m() != 0) {
61  ATH_MSG_ERROR("Input neutral PFO should have null mass. If reconstruction runs from AOD, PFOs must be rebuilt!");
62  return StatusCode::FAILURE;
63  }
64 
65  // preselection to veto very low energy PFOs
66  if (!passesPreselectionEnergy(pfo->e())) {
67  ATH_MSG_DEBUG("EFO of charge " << static_cast<int>(pfo->charge()) << " and energy " << pfo->e() << " does not pass presel Energy cut of " << m_Config_TauConstituents_PreselectionMinEnergy);
68  return StatusCode::SUCCESS;
69  }
70 
71  // get the mass correct & build 4-vector
72  double constituentMass = pfo->m();
73  if (m_Config_UsePionMass) {
74 
75  // clusters: don't touch the measured energy. set mass to pion mass, so momentum will be altered
76  if (!pfo->isCharged()) {
77  constituentMass = ParticleConstants::piZeroMassInMeV;
78  }
79  }
80 
81  TLorentzVector momentum;
82  PanTau::SetP4EEtaPhiM( momentum, pfo->e(), pfo->eta(), pfo->phi(), constituentMass);
83 
84  // get type (based on charge and DR to tau)
85  std::vector<int> typeFlags = std::vector<int>((unsigned int)PanTau::TauConstituent::t_nTypes, 0);
86  if (typeFlags.size() < (unsigned int)PanTau::TauConstituent::t_nTypes) std::abort(); // suppress cppcheck warning
87  typeFlags.at(static_cast<int>(PanTau::TauConstituent::t_NoType)) = 1;
88 
89  double mvaValue = PanTau::TauConstituent::DefaultBDTValue();
90 
91  TLorentzVector tlv_intAxis = tauJet->p4(xAOD::TauJetParameters::IntermediateAxis);
92  double deltaR_toTauJet = tlv_intAxis.DeltaR( pfo->p4() );
93 
94  if (deltaR_toTauJet > m_Config_TauConstituents_Types_DeltaRCore) {
95  if (pfo->isCharged()) {
96  typeFlags.at(static_cast<int>(PanTau::TauConstituent::t_Charged)) = 1;
97  }
98  }//end if pfo is not in core
99 
100  if (deltaR_toTauJet <= m_Config_TauConstituents_Types_DeltaRCore) {
101 
102  if (pfo->isCharged()) {
103  typeFlags.at(static_cast<int>(PanTau::TauConstituent::t_Charged)) = 1;
104  }
105  else {
106  typeFlags.at(static_cast<int>(PanTau::TauConstituent::t_Neutral)) = 1;
107 
108  //neutral PFO arranging --- check for pi0 tag
109  mvaValue = pfo->bdtPi0Score();
110 
111  int nPi0sPerCluster = 0;
112  if ( !pfo->attribute(xAOD::PFODetails::nPi0Proto, nPi0sPerCluster) ) {
113  ATH_MSG_WARNING("WARNING: Could not retrieve nPi0Proto. Will set it to 1.");
114  nPi0sPerCluster = 1;
115  }
116  if (nPi0sPerCluster > 0) typeFlags.at(static_cast<int>(PanTau::TauConstituent::t_Pi0Neut)) = 1;
117 
118  }
119  }//end if pfo is in core
120 
121  // create the tau constituent
122  tauConstituent = new PanTau::TauConstituent(momentum, static_cast<int>(pfo->charge()), typeFlags, mvaValue, pfo);
123  tauConstituent->makePrivateStore();
124 
125  // Check if the pfo object has shots:
126  std::vector<const xAOD::IParticle*> list_TauShots = std::vector<const xAOD::IParticle*>(0);
127  if (!(pfo->associatedParticles(xAOD::PFODetails::TauShot, list_TauShots))) {
128  ATH_MSG_DEBUG("WARNING: Could not get shots from current pfo");
129  }
130 
131  for (unsigned int iShot=0; iShot<list_TauShots.size(); iShot++) {
132 
133  if (list_TauShots.at(iShot) == nullptr) {
134  ATH_MSG_WARNING("Shot number " << iShot << " points to 0! Skip it");
135  continue;
136  }
137 
138  const xAOD::PFO* curShot = dynamic_cast<const xAOD::PFO*>(list_TauShots.at(iShot));
139  TLorentzVector shotMomentum;
140  PanTau::SetP4EEtaPhiM( shotMomentum, curShot->e(), curShot->eta(), curShot->phi(), curShot->m());
141  std::vector<int> shotTypeFlags = std::vector<int>((unsigned int)PanTau::TauConstituent::t_nTypes, 0);
142  PanTau::TauConstituent* shotConstituent = new PanTau::TauConstituent(shotMomentum, 0, typeFlags, PanTau::TauConstituent::DefaultBDTValue(), curShot);
143  shotConstituent->makePrivateStore();
144 
145  int nPhotons = 0;
146  if (!curShot->attribute(xAOD::PFODetails::tauShots_nPhotons, nPhotons)) {
147  nPhotons = -1;
148  ATH_MSG_DEBUG("WARNING: Could not get nPhotons for this shot! Set to -1");
149  }
150  shotConstituent->setNPhotonsInShot(nPhotons);
151  tauConstituent->addShot(shotConstituent);
152  }//end loop over shots
153 
154  return StatusCode::SUCCESS;
155 }
PanTauSeed.h
PanTau::TauConstituent::t_Neutral
@ t_Neutral
Definition: TauConstituent.h:45
PanTau::Tool_InputConverter::passesPreselectionEnergy
virtual bool passesPreselectionEnergy(double energy) const
Definition: Tool_InputConverter.cxx:40
xAOD::TauJetParameters::IntermediateAxis
@ IntermediateAxis
Definition: TauDefs.h:338
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PanTau::TauConstituent::t_Charged
@ t_Charged
Definition: TauConstituent.h:44
xAOD::PFODetails::TauShot
@ TauShot
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:171
xAOD::PFO_v1::attribute
bool attribute(PFODetails::PFOAttributes AttributeType, T &anAttribute) const
get a PFO Variable via enum
xAOD::PFO_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: PFO_v1.cxx:60
HelperFunctions.h
asg
Definition: DataHandleTestTool.h:28
PanTau::TauConstituent::setNPhotonsInShot
void setNPhotonsInShot(int nPhotons)
Definition: TauConstituent.cxx:247
xAOD::PFO_v1::associatedParticles
bool associatedParticles(PFODetails::PFOParticleType ParticleType, std::vector< const IParticle * > &theParticles) const
get a vector of PFO constituent particle types via enum
Definition: PFO_v1.cxx:610
ParticleConstants::PDG2011::piZeroMassInMeV
constexpr double piZeroMassInMeV
the mass of the pi zero (in MeV)
Definition: ParticleConstants.h:38
Tool_InputConverter.h
TauConstituent.h
xAOD::PFODetails::tauShots_nPhotons
@ tauShots_nPhotons
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:162
xAOD::PFO_v1::e
virtual double e() const
The total energy of the particle.
Definition: PFO_v1.cxx:81
PFO.h
PanTau::Tool_InputConverter::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: Tool_InputConverter.cxx:23
PanTau::TauConstituent::DefaultBDTValue
static double DefaultBDTValue()
Definition: TauConstituent.h:54
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
ParticleGun_EoverP_Config.momentum
momentum
Definition: ParticleGun_EoverP_Config.py:63
ParticleConstants.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::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
xAOD::PFO_v1::charge
float charge() const
get charge of PFO
xAOD::PFO_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: PFO_v1.cxx:95
PanTau::Tool_InputConverter::ConvertToTauConstituent
virtual StatusCode ConvertToTauConstituent(const xAOD::PFO *pfo, PanTau::TauConstituent *&tauConstituent, const xAOD::TauJet *tauJet) const
Definition: Tool_InputConverter.cxx:46
PanTau::Tool_InputConverter::~Tool_InputConverter
virtual ~Tool_InputConverter()
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::PFO_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: PFO_v1.cxx:67
xAOD::PFO_v1::bdtPi0Score
float bdtPi0Score() const
get BDT Score used to classify clusters as Pi0 like or not
xAOD::PFO_v1::isCharged
bool isCharged() const
is a charged PFO
Definition: PFO_v1.cxx:251
PanTau::TauConstituent::addShot
void addShot(TauConstituent *shot)
Definition: TauConstituent.cxx:232
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
PanTau::HelperFunctions::bindToolHandle
static StatusCode bindToolHandle(ToolHandle< T > &, std::string)
Definition: Reconstruction/PanTau/PanTauAlgs/PanTauAlgs/HelperFunctions.h:56
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:192
xAOD::PFODetails::nPi0Proto
@ nPi0Proto
Definition: Event/xAOD/xAODPFlow/xAODPFlow/PFODefs.h:31
xAOD::PFO_v1::m
virtual double m() const
The invariant mass of the particle.
Definition: PFO_v1.cxx:74
PanTau::TauConstituent::t_Pi0Neut
@ t_Pi0Neut
Definition: TauConstituent.h:46
Tool_InformationStore.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
xAOD::TauJet_v3::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauJet_v3.cxx:96
PanTau::TauConstituent::t_NoType
@ t_NoType
Definition: TauConstituent.h:43
TauJet.h
PFODefs.h
PanTau::TauConstituent::t_nTypes
@ t_nTypes
Definition: TauConstituent.h:51
PanTau::TauConstituent
Definition: TauConstituent.h:25
PanTau::Tool_InputConverter::Tool_InputConverter
Tool_InputConverter(const std::string &name)
Definition: Tool_InputConverter.cxx:16