ATLAS Offline Software
Loading...
Searching...
No Matches
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"
18
21
22const 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
64 float PreSampler = cluster.eSample(CaloSampling::PreSamplerB) + cluster.eSample(CaloSampling::PreSamplerE);
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
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}
std::vector< double > Energy
TauRecToolBase(const std::string &name)
TauSubstructureVariables(const std::string &name="TauSubstructureVariables")
Gaudi::Property< bool > m_doVertexCorrection
virtual StatusCode execute(xAOD::TauJet &tau) const override
Execute - called for each tau candidate.
flt_t rawE() const
float eSample(const CaloSample sampling) const
float energyBE(const unsigned layer) const
Get the energy in one layer of the EM Calo.
Evaluate cluster kinematics with a different vertex / signal state.
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
double ptDetectorAxis() const
double ptIntermediateAxis() const
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...
void setDetail(TauJetParameters::Detail detail, int value)
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
virtual FourMom_t p4() const
The full 4-momentum of the particle.
virtual double eta() const
The pseudorapidity ( ) of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
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 ...
@ numTopoClusters
get number of topocluster constituents of jet associated to tau candidate
Definition TauDefs.h:173
@ dRmax
Get maximal dR of tracks associated to calo-seeded tau.
Definition TauDefs.h:226
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TauJet_v3 TauJet
Definition of the current "tau version".
Tell the compiler to optimize assuming that FP may trap.
#define CXXUTILS_TRAPPING_FP
Definition trapping_fp.h:24