ATLAS Offline Software
Tool_InputConverter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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"
13 
14 
16  asg::AsgTool(name),
17  m_Tool_InformationStore("PanTau::Tool_InformationStore/Tool_InformationStore")
18 {
19  declareProperty("Tool_InformationStore", m_Tool_InformationStore, "Link to tool with all information");
20  declareProperty("Tool_InformationStoreName", m_Tool_InformationStoreName="", "Optional Name for InformationStore insance in ABR");
21 }
22 
24 
26 
27  ATH_MSG_INFO(" initialize()");
28  m_init=true;
29 
30  ATH_CHECK( HelperFunctions::bindToolHandle( m_Tool_InformationStore, m_Tool_InformationStoreName) ); //ABR only
31 
32  ATH_CHECK( m_Tool_InformationStore.retrieve() );
33 
34  ATH_CHECK( m_Tool_InformationStore->getInfo_Int("TauConstituents_UsePionMass", m_Config_UsePionMass) );
35  ATH_CHECK( m_Tool_InformationStore->getInfo_Int("TauConstituents_UseShrinkingCone", m_Config_TauConstituents_UseShrinkingCone) );
36  ATH_CHECK( m_Tool_InformationStore->getInfo_Double("TauConstituents_Types_DeltaRCore", m_Config_TauConstituents_Types_DeltaRCore) );
37  ATH_CHECK( m_Tool_InformationStore->getInfo_Double("TauConstituents_PreselectionMinEnergy", m_Config_TauConstituents_PreselectionMinEnergy) );
38  ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_BinEdges_Eta", m_Config_CellBased_BinEdges_Eta) );
39  ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_EtaBinned_Pi0MVACut_1prong", m_Config_CellBased_EtaBinned_Pi0MVACut_1prong) );
40  ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_EtaBinned_Pi0MVACut_3prong", m_Config_CellBased_EtaBinned_Pi0MVACut_3prong) );
41 
42  return StatusCode::SUCCESS;
43 }
44 
45 
47  return energy >= m_Config_TauConstituents_PreselectionMinEnergy;
48 }
49 
50 
51 // PFO converter
53  PanTau::TauConstituent* &tauConstituent,
54  const xAOD::TauJet* tauJet) const {
55 
56  // check for invalid eta, phi, e "NAN" values -- likely no longer needed, raise severity to be sure
57  if (pfo->eta() != pfo->eta() || pfo->phi() != pfo->phi() || pfo->e() != pfo->e()) {
58  ATH_MSG_ERROR("Will not convert PFO with eta value of " << pfo->eta() << " -> return to Tool_TauConstituentGetter");
59  return StatusCode::FAILURE;
60  }
61 
62  // Check whether neutral input pfo has pion mass (it may have if xAOD is being reprocessed)
63  // If it does,
64  // - old (R21) approach: make it massless again and use that
65  // - new (R22) approach: complain and abort, reconstruction from AOD implies rebuilding PFOs upstream, so the mass should not have been set at that point
66  if (!pfo->isCharged() && pfo->m() != 0) {
67  ATH_MSG_ERROR("Input neutral PFO should have null mass. If reconstruction runs from AOD, PFOs must be rebuilt!");
68  return StatusCode::FAILURE;
69  }
70 
71  // preselection to veto very low energy PFOs
72  if (!passesPreselectionEnergy(pfo->e())) {
73  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);
74  return StatusCode::SUCCESS;
75  }
76 
77  // get the mass correct & build 4-vector
78  double constituentMass = pfo->m();
79  if (m_Config_UsePionMass) {
80 
81  // clusters: don't touch the measured energy. set mass to pion mass, so momentum will be altered
82  if (!pfo->isCharged()) {
83  constituentMass = 134.98;
84  }
85  }
86 
87  TLorentzVector momentum;
88  PanTau::SetP4EEtaPhiM( momentum, pfo->e(), pfo->eta(), pfo->phi(), constituentMass);
89 
90  // get type (based on charge and DR to tau)
91  std::vector<int> typeFlags = std::vector<int>((unsigned int)PanTau::TauConstituent::t_nTypes, 0);
92  if (typeFlags.size() < (unsigned int)PanTau::TauConstituent::t_nTypes) std::abort(); // suppress cppcheck warning
93  typeFlags.at((int)PanTau::TauConstituent::t_NoType) = 1;
94 
95  double mvaValue = PanTau::TauConstituent::DefaultBDTValue();
96 
97  TLorentzVector tlv_intAxis = tauJet->p4(xAOD::TauJetParameters::IntermediateAxis);
98  double deltaR_toTauJet = tlv_intAxis.DeltaR( pfo->p4() );
99 
100  if (deltaR_toTauJet > m_Config_TauConstituents_Types_DeltaRCore) {
101  if (pfo->isCharged()) {
102  typeFlags.at((int)PanTau::TauConstituent::t_Charged) = 1;
103  }
104  else {
105  typeFlags.at((int)PanTau::TauConstituent::t_OutNeut) = 1;
106  mvaValue = pfo->bdtPi0Score();
107  }
108  }//end if pfo is not in core
109 
110  if (deltaR_toTauJet <= m_Config_TauConstituents_Types_DeltaRCore) {
111 
112  if (pfo->isCharged()) {
113  typeFlags.at((int)PanTau::TauConstituent::t_Charged) = 1;
114  }
115  else {
116  typeFlags.at((int)PanTau::TauConstituent::t_Neutral) = 1;
117  typeFlags.at((int)PanTau::TauConstituent::t_NeutLowA) = 1;
118  typeFlags.at((int)PanTau::TauConstituent::t_NeutLowB) = 1;
119 
120  //neutral PFO arranging --- check for pi0 tag
121  mvaValue = pfo->bdtPi0Score();
122 
123  int nPi0sPerCluster = 0;
124  if ( !pfo->attribute(xAOD::PFODetails::nPi0Proto, nPi0sPerCluster) ) {
125  ATH_MSG_WARNING("WARNING: Could not retrieve nPi0Proto. Will set it to 1.");
126  nPi0sPerCluster = 1;
127  }
128  if (nPi0sPerCluster > 0) typeFlags.at((int)PanTau::TauConstituent::t_Pi0Neut) = 1;
129 
130  }
131  }//end if pfo is in core
132 
133  // create the tau constituent
134  tauConstituent = new PanTau::TauConstituent(momentum, static_cast<int>(pfo->charge()), typeFlags, mvaValue, pfo);
135  tauConstituent->makePrivateStore();
136 
137  // Check if the pfo object has shots:
138  std::vector<const xAOD::IParticle*> list_TauShots = std::vector<const xAOD::IParticle*>(0);
139  if (!(pfo->associatedParticles(xAOD::PFODetails::TauShot, list_TauShots))) {
140  ATH_MSG_DEBUG("WARNING: Could not get shots from current pfo");
141  }
142 
143  for (unsigned int iShot=0; iShot<list_TauShots.size(); iShot++) {
144 
145  if (list_TauShots.at(iShot) == nullptr) {
146  ATH_MSG_WARNING("Shot number " << iShot << " points to 0! Skip it");
147  continue;
148  }
149 
150  const xAOD::PFO* curShot = dynamic_cast<const xAOD::PFO*>(list_TauShots.at(iShot));
151  TLorentzVector shotMomentum;
152  PanTau::SetP4EEtaPhiM( shotMomentum, curShot->e(), curShot->eta(), curShot->phi(), curShot->m());
153  std::vector<int> shotTypeFlags = std::vector<int>((unsigned int)PanTau::TauConstituent::t_nTypes, 0);
154  PanTau::TauConstituent* shotConstituent = new PanTau::TauConstituent(shotMomentum, 0, typeFlags, PanTau::TauConstituent::DefaultBDTValue(), curShot);
155  shotConstituent->makePrivateStore();
156 
157  int nPhotons = 0;
158  if (!curShot->attribute(xAOD::PFODetails::tauShots_nPhotons, nPhotons)) {
159  nPhotons = -1;
160  ATH_MSG_DEBUG("WARNING: Could not get nPhotons for this shot! Set to -1");
161  }
162  shotConstituent->setNPhotonsInShot(nPhotons);
163  tauConstituent->addShot(shotConstituent);
164  }//end loop over shots
165 
166  return StatusCode::SUCCESS;
167 }
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:46
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
PanTau::Tool_InputConverter::m_Tool_InformationStore
ToolHandle< PanTau::ITool_InformationStore > m_Tool_InformationStore
Definition: Tool_InputConverter.h:51
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:254
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
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
PanTau::TauConstituent::t_OutNeut
@ t_OutNeut
Definition: TauConstituent.h:48
PFO.h
PanTau::Tool_InputConverter::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: Tool_InputConverter.cxx:25
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
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:52
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
PanTau::Tool_InputConverter::m_Tool_InformationStoreName
std::string m_Tool_InformationStoreName
Definition: Tool_InputConverter.h:52
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:239
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
PanTau::HelperFunctions::bindToolHandle
static StatusCode bindToolHandle(ToolHandle< T > &, std::string)
Definition: Reconstruction/PanTau/PanTauAlgs/PanTauAlgs/HelperFunctions.h:60
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
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:97
PanTau::TauConstituent::t_NoType
@ t_NoType
Definition: TauConstituent.h:43
TauJet.h
PanTau::TauConstituent::t_NeutLowB
@ t_NeutLowB
Definition: TauConstituent.h:50
PFODefs.h
PanTau::TauConstituent::t_NeutLowA
@ t_NeutLowA
Definition: TauConstituent.h:49
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:15