ATLAS Offline Software
TauSubstructureVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //********************************************************************//
6 // NAME: TauSubstructureVariables.cxx //
7 // AUTHORS: M. Trottier-McDonald //
8 // CREATED: January 11 2010 //
9 //********************************************************************//
10 
11 #include <algorithm>
12 #include <cmath>
13 #include <sstream>
14 
15 #include "xAODJet/Jet.h"
16 #include "xAODTau/TauJet.h"
17 #include "CxxUtils/trapping_fp.h"
18 
21 
22 const float TauSubstructureVariables::DEFAULT = -1111.;
23 
25  : TauRecToolBase(name) {
26 }
27 
28 
29 
31 
32  //*****************************************************
33  // calculate some new cluster based ID variables
34  //*****************************************************
35  // New cluster-based variables
36  float totalEnergy(0.);
37  float PSSEnergy(0.);
38  float EMEnergy(0.);
39  float HADEnergy(0.);
40 
41  TLorentzVector leadClusVec;
42  TLorentzVector subLeadClusVec;
43  TLorentzVector approxSubstructure4Vec;
44  double clusELead = DEFAULT;
45  double clusESubLead = DEFAULT;
46 
47  TLorentzVector tauAxis = tauRecTools::getTauAxis(tau, m_doVertexCorrection);
48 
49  // TODO: check which scale is needed here
50  // p4 from cluster is at LC scale, p4 from vertexedCluster is at LC/EM scale for LC/EM seed jets
51  std::vector<xAOD::CaloVertexedTopoCluster> vertexedClusterList = tau.vertexedClusters();
52 
53  tau.setDetail(xAOD::TauJetParameters::numTopoClusters, static_cast<int>(vertexedClusterList.size()));
54 
55  for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : vertexedClusterList){
56  // Tell clang to optimize assuming that FP operations may trap.
58  // It is at EM/LC scale for EM/LC seed jets
59  float clEnergy = vertexedCluster.e();
60 
61  const xAOD::CaloCluster& cluster = vertexedCluster.clust();
62 
63  // Calculate the fractions of energy in different calorimeter layers
65  float EMLayer1 = cluster.eSample(CaloSampling::EMB1) + cluster.eSample(CaloSampling::EME1);
66  float EMLayer2 = cluster.eSample(CaloSampling::EMB2) + cluster.eSample(CaloSampling::EME2);
67 
68  float Energy = cluster.rawE();
69  float PSSF = (Energy != 0.) ? (PreSampler + EMLayer1) / Energy : 0.;
70  float EM2F = (Energy != 0.) ? EMLayer2 / Energy : 0.;
71  float EMF = PSSF + EM2F;
72 
73  PSSEnergy += PSSF * clEnergy;
74  EMEnergy += EMF * clEnergy;
75  HADEnergy += (Energy != 0.) ? (1 - EMF) * clEnergy : 0.;
76 
77  TLorentzVector clusterP4 = vertexedCluster.p4();
78 
79  totalEnergy += clusterP4.E();
80 
81  if (tauAxis.DeltaR(clusterP4) < 0.2) {
82  double clusEnergyBE = ( cluster.energyBE(0) + cluster.energyBE(1) + cluster.energyBE(2) );
83 
84  if (clusEnergyBE > clusELead) {
85  //change current leading cluster to subleading
86  clusESubLead = clusELead;
87  subLeadClusVec = leadClusVec;
88 
89  //set energy and 4-vector of leading cluster
90  clusELead = clusEnergyBE;
91  leadClusVec.SetPtEtaPhiM(clusELead/std::cosh(clusterP4.Eta()), clusterP4.Eta(), clusterP4.Phi(), 0.);
92  }
93  else if (clusEnergyBE > clusESubLead) {
94  //set energy and 4-vector of subleading cluster only
95  clusESubLead = clusEnergyBE;
96  subLeadClusVec.SetPtEtaPhiM(clusESubLead/std::cosh(clusterP4.Eta()), clusterP4.Eta(), clusterP4.Phi(), 0.);
97  }
98  }
99  }
100 
101  if (clusELead > 0.) {
102  approxSubstructure4Vec += leadClusVec;
103  }
104  if (clusESubLead > 0.) {
105  approxSubstructure4Vec += subLeadClusVec;
106  }
107 
108  // calculate trk momentum
109  float trkSysMomentum(0.);
110  for (size_t i=0; i < tau.nTracks(); ++i) {
111  trkSysMomentum += tau.track(i)->pt() * std::cosh(tau.track(i)->eta());
112 
113  //adding the core tracks to the approximate substructure 4 vector
114  approxSubstructure4Vec += tau.track(i)->p4();
115  }
116 
117  // set new approximate energy flow variables for tau ID
119  tau.setDetail(xAOD::TauJetParameters::ptRatioEflowApprox, static_cast<float>(approxSubstructure4Vec.Pt()/ tau.ptIntermediateAxis()) );
120  }
121  else {
122  tau.setDetail(xAOD::TauJetParameters::ptRatioEflowApprox, static_cast<float>(approxSubstructure4Vec.Pt()/ tau.ptDetectorAxis()) );
123  }
124  tau.setDetail(xAOD::TauJetParameters::mEflowApprox, static_cast<float>(approxSubstructure4Vec.M()) );
125 
126  float fPSSFraction = (totalEnergy != 0.) ? PSSEnergy / totalEnergy : DEFAULT;
127  float fChPIEMEOverCaloEME = (EMEnergy != 0.) ? (trkSysMomentum - HADEnergy) / EMEnergy : DEFAULT;
128  float fEMPOverTrkSysP = DEFAULT;
129  if (tau.nTracks() > 0) fEMPOverTrkSysP = (trkSysMomentum != 0.) ? EMEnergy / trkSysMomentum : DEFAULT;
130 
132  tau.setDetail(xAOD::TauJetParameters::ChPiEMEOverCaloEME, fChPIEMEOverCaloEME);
134 
135  // calculate dRMax
136  size_t numTrack = tau.nTracks();
137  if (numTrack > 0) {
138  float dRmax = 0.;
139  float dR = 0.;
140 
141  for (size_t i=0; i < numTrack; ++i) {
142  dR = tau.track(i)->p4().DeltaR(tauAxis);
143  if (dR > dRmax) dRmax = dR;
144  }
146  }
147 
148  return StatusCode::SUCCESS;
149 }
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
Jet.h
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
xAOD::TauTrack_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauTrack_v1.cxx:33
Energy
std::vector< double > Energy
Definition: CalibHitToCaloCell.h:23
tauRecTools::getTauAxis
TLorentzVector getTauAxis(const xAOD::TauJet &tau, bool doVertexCorrection=true)
Return the four momentum of the tau axis The tau axis is widely used to select clusters and cells in ...
Definition: Reconstruction/tauRecTools/Root/HelperFunctions.cxx:33
xAOD::TauTrack_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:488
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
xAOD::TauJetParameters::mEflowApprox
@ mEflowApprox
Definition: TauDefs.h:292
TauSubstructureVariables::TauSubstructureVariables
TauSubstructureVariables(const std::string &name="TauSubstructureVariables")
Definition: TauSubstructureVariables.cxx:24
xAOD::TauJet_v3::ptDetectorAxis
double ptDetectorAxis() const
xAOD::TauJetParameters::ptRatioEflowApprox
@ ptRatioEflowApprox
Definition: TauDefs.h:293
xAOD::TauJetParameters::dRmax
@ dRmax
Get maximal dR of tracks associated to calo-seeded tau.
Definition: TauDefs.h:226
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:62
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
TauSubstructureVariables.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
TauSubstructureVariables::m_doVertexCorrection
Gaudi::Property< bool > m_doVertexCorrection
Definition: TauSubstructureVariables.h:37
xAOD::TauJet_v3::track
const TauTrack * track(size_t i, TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged, int *container_index=0) const
Get the pointer to a given tauTrack associated with this tau /*container index needed by trackNonCons...
Definition: TauJet_v3.cxx:422
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
TauSubstructureVariables::execute
virtual StatusCode execute(xAOD::TauJet &tau) const override
Execute - called for each tau candidate.
Definition: TauSubstructureVariables.cxx:30
xAOD::TauJetParameters::numTopoClusters
@ numTopoClusters
get number of topocluster constituents of jet associated to tau candidate
Definition: TauDefs.h:173
trapping_fp.h
Tell the compiler to optimize assuming that FP may trap.
MonDataType::Energy
@ Energy
xAOD::TauTrack_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
xAOD::TauJet_v3::vertexedClusters
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
Definition: TauJet_v3.cxx:586
HI::SubCalo::Lists::PreSampler
constexpr std::initializer_list< int > PreSampler
Definition: HIEventDefs.h:77
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:514
CXXUTILS_TRAPPING_FP
CXXUTILS_TRAPPING_FP
Definition: SegmentLineFitter.cxx:8
xAOD::TauJetParameters::ChPiEMEOverCaloEME
@ ChPiEMEOverCaloEME
Definition: TauDefs.h:278
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
TauJet.h
HelperFunctions.h
xAOD::CaloCluster_v1::energyBE
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
Definition: CaloCluster_v1.cxx:623
xAOD::TauJet_v3::setDetail
void setDetail(TauJetParameters::Detail detail, int value)
Definition: TauJet_v3.cxx:309
xAOD::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
xAOD::TauJet_v3::ptIntermediateAxis
double ptIntermediateAxis() const
TauSubstructureVariables::DEFAULT
static const float DEFAULT
Definition: TauSubstructureVariables.h:33
xAOD::TauJetParameters::PSSFraction
@ PSSFraction
Definition: TauDefs.h:277
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
xAOD::TauJetParameters::EMPOverTrkSysP
@ EMPOverTrkSysP
Definition: TauDefs.h:279