ATLAS Offline Software
TauSubstructureVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
21 
22 const float TauSubstructureVariables::DEFAULT = -1111.;
23 
25  : TauRecToolBase(name) {
26  declareProperty("VertexCorrection", m_doVertexCorrection = true);
27 }
28 
29 
30 
32 
33  CaloClusterVariables CaloClusterVariablesTool;
34 
35  bool isFilled = CaloClusterVariablesTool.update(tau);
36 
37  if (!isFilled) {
38  ATH_MSG_DEBUG("problem in calculating calo cluster variables -> will be set to -1111");
39 
46  }
47  else {
48  tau.setDetail(xAOD::TauJetParameters::numTopoClusters, static_cast<int>(CaloClusterVariablesTool.numConstituents()));
49  tau.setDetail(xAOD::TauJetParameters::numEffTopoClusters, static_cast<float>(CaloClusterVariablesTool.effectiveNumConstituents()));
50  tau.setDetail(xAOD::TauJetParameters::topoInvMass, static_cast<float>(CaloClusterVariablesTool.totalMass()));
51  tau.setDetail(xAOD::TauJetParameters::effTopoInvMass, static_cast<float>(CaloClusterVariablesTool.effectiveMass()));
52  tau.setDetail(xAOD::TauJetParameters::topoMeanDeltaR, static_cast<float>(CaloClusterVariablesTool.averageRadius()));
53  tau.setDetail(xAOD::TauJetParameters::effTopoMeanDeltaR, static_cast<float>(CaloClusterVariablesTool.averageEffectiveRadius()));
54  }
55 
56  //*****************************************************
57  // calculate some new cluster based ID variables
58  //*****************************************************
59  // New cluster-based variables
60  float totalEnergy(0.);
61  float calo_iso(0.);
62  float dr(0.);
63 
64  TLorentzVector leadClusVec;
65  TLorentzVector subLeadClusVec;
66  TLorentzVector approxSubstructure4Vec;
67  double clusELead = DEFAULT;
68  double clusESubLead = DEFAULT;
69 
70  TLorentzVector tauAxis = tauRecTools::getTauAxis(tau, m_doVertexCorrection);
71 
72  // TODO: check which scale is needed here
73  // p4 from cluster is at LC scale, p4 from vertexedCluster is at LC/EM scale for LC/EM seed jets
74  std::vector<xAOD::CaloVertexedTopoCluster> vertexedClusterList = tau.vertexedClusters();
75  for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : vertexedClusterList){
76  TLorentzVector clusterP4 = vertexedCluster.p4();
77 
78  totalEnergy += clusterP4.E();
79 
80  dr = tauAxis.DeltaR(clusterP4);
81 
82  if (0.2 <= dr && dr < 0.4) {
83  calo_iso += clusterP4.Et();
84  }
85  else if (dr < 0.2) {
86  const xAOD::CaloCluster& cluster = vertexedCluster.clust();
87  double clusEnergyBE = ( cluster.energyBE(0) + cluster.energyBE(1) + cluster.energyBE(2) );
88 
89  if (clusEnergyBE > clusELead) {
90  //change current leading cluster to subleading
91  clusESubLead = clusELead;
92  subLeadClusVec = leadClusVec;
93 
94  //set energy and 4-vector of leading cluster
95  clusELead = clusEnergyBE;
96  leadClusVec.SetPtEtaPhiM(clusELead/std::cosh(clusterP4.Eta()), clusterP4.Eta(), clusterP4.Phi(), 0.);
97  }
98  else if (clusEnergyBE > clusESubLead) {
99  //set energy and 4-vector of subleading cluster only
100  clusESubLead = clusEnergyBE;
101  subLeadClusVec.SetPtEtaPhiM(clusESubLead/std::cosh(clusterP4.Eta()), clusterP4.Eta(), clusterP4.Phi(), 0.);
102  }
103  }
104  }
105 
106  if (clusELead > 0.) {
107  approxSubstructure4Vec += leadClusVec;
108  }
109  if (clusESubLead > 0.) {
110  approxSubstructure4Vec += subLeadClusVec;
111  }
112 
113  // now sort cluster by energy
114  auto compare = [](const xAOD::CaloVertexedTopoCluster& left, const xAOD::CaloVertexedTopoCluster& right) {
115  return left.e() > right.e();
116  };
117  std::sort(vertexedClusterList.begin(), vertexedClusterList.end(), compare);
118 
119  // determine energy sum of leading 2 and leading 3 clusters
120  float sum2LeadClusterE = 0.;
121  if(!vertexedClusterList.empty()) {
122  sum2LeadClusterE = vertexedClusterList.at(0).e();
123  if(vertexedClusterList.size()>1) sum2LeadClusterE += vertexedClusterList.at(1).e();
124  }
125  float sum3LeadClusterE = sum2LeadClusterE;
126  if(vertexedClusterList.size()>2) sum3LeadClusterE += vertexedClusterList.at(2).e();
127 
128  if (totalEnergy != 0.) {
129  tau.setDetail(xAOD::TauJetParameters::lead2ClusterEOverAllClusterE, (sum2LeadClusterE / totalEnergy) );
130  tau.setDetail(xAOD::TauJetParameters::lead3ClusterEOverAllClusterE, (sum3LeadClusterE / totalEnergy) );
131  }
132 
134 
135  // calculate calorimeter energies in different layers
136  float PSSEnergy(0.);
137  float EMEnergy(0.);
138  float HADEnergy(0.);
139 
140  for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : vertexedClusterList) {
141  // It is at EM/LC scale for EM/LC seed jets
142  float clEnergy = vertexedCluster.e();
143 
144  const xAOD::CaloCluster& cluster = vertexedCluster.clust();
145 
146  // Calculate the fractions of energy in different calorimeter layers
148  float EMLayer1 = cluster.eSample(CaloSampling::EMB1) + cluster.eSample(CaloSampling::EME1);
149  float EMLayer2 = cluster.eSample(CaloSampling::EMB2) + cluster.eSample(CaloSampling::EME2);
150 
151  float Energy = cluster.rawE();
152  float PSSF = (Energy != 0.) ? (PreSampler + EMLayer1) / Energy : 0.;
153  float EM2F = (Energy != 0.) ? EMLayer2 / Energy : 0.;
154  float EMF = PSSF + EM2F;
155 
156  PSSEnergy += PSSF * clEnergy;
157  EMEnergy += EMF * clEnergy;
158  HADEnergy += (Energy != 0.) ? (1 - EMF) * clEnergy : 0.;
159  }
160 
161  // calculate trk momentum
162  float trkSysMomentum(0.);
163  for (size_t i=0; i < tau.nTracks(); ++i) {
164  trkSysMomentum += tau.track(i)->pt() * std::cosh(tau.track(i)->eta());
165 
166  //adding the core tracks to the approximate substructure 4 vector
167  approxSubstructure4Vec += tau.track(i)->p4();
168  }
169 
170  // set new approximate energy flow variables for tau ID
172  tau.setDetail(xAOD::TauJetParameters::ptRatioEflowApprox, static_cast<float>(approxSubstructure4Vec.Pt()/ tau.ptIntermediateAxis()) );
173  }
174  else {
175  tau.setDetail(xAOD::TauJetParameters::ptRatioEflowApprox, static_cast<float>(approxSubstructure4Vec.Pt()/ tau.ptDetectorAxis()) );
176  }
177  tau.setDetail(xAOD::TauJetParameters::mEflowApprox, static_cast<float>(approxSubstructure4Vec.M()) );
178 
179  float fPSSFraction = (totalEnergy != 0.) ? PSSEnergy / totalEnergy : DEFAULT;
180  float fChPIEMEOverCaloEME = (EMEnergy != 0.) ? (trkSysMomentum - HADEnergy) / EMEnergy : DEFAULT;
181  float fEMPOverTrkSysP = DEFAULT;
182  if (tau.nTracks() > 0) fEMPOverTrkSysP = (trkSysMomentum != 0.) ? EMEnergy / trkSysMomentum : DEFAULT;
183 
185  tau.setDetail(xAOD::TauJetParameters::ChPiEMEOverCaloEME, fChPIEMEOverCaloEME);
187 
188  // calculate dRMax
189  size_t numTrack = tau.nTracks();
190  if (numTrack > 0) {
191  float dRmax = 0.;
192  float dR = 0.;
193 
194  for (size_t i=0; i < numTrack; ++i) {
195  dR = tau.track(i)->p4().DeltaR(tauAxis);
196  if (dR > dRmax) dRmax = dR;
197  }
199  }
200 
201  return StatusCode::SUCCESS;
202 }
CaloClusterVariables::effectiveNumConstituents
double effectiveNumConstituents() const
Definition: CaloClusterVariables.h:34
xAOD::CaloCluster_v1::rawE
flt_t rawE() const
Jet.h
Amg::compare
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
Definition: EventPrimitivesHelpers.h:109
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
xAOD::TauJetParameters::topoInvMass
@ topoInvMass
get invariant mass from topoclusters of jet associated to tau candidate
Definition: TauDefs.h:177
xAOD::TauTrack_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauTrack_v1.cxx:31
CaloClusterVariables
Provide calculations of cluster based variables using the clusters associated to the jet seed of the ...
Definition: CaloClusterVariables.h:16
xAOD::TauJetParameters::lead2ClusterEOverAllClusterE
@ lead2ClusterEOverAllClusterE
Get sum of 2 leading cluster energy over all cluster energy.
Definition: TauDefs.h:218
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:526
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
xAOD::TauJetParameters::mEflowApprox
@ mEflowApprox
Definition: TauDefs.h:292
xAOD::TauJetParameters::lead3ClusterEOverAllClusterE
@ lead3ClusterEOverAllClusterE
Get sum of 3 leading cluster energy over all cluster energy.
Definition: TauDefs.h:220
TauSubstructureVariables::TauSubstructureVariables
TauSubstructureVariables(const std::string &name="TauSubstructureVariables")
Definition: TauSubstructureVariables.cxx:24
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
CaloClusterVariables::numConstituents
unsigned int numConstituents() const
Definition: CaloClusterVariables.h:29
CaloClusterVariables::averageRadius
double averageRadius() const
Definition: CaloClusterVariables.h:38
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:59
xAOD::TauJetParameters::topoMeanDeltaR
@ topoMeanDeltaR
get mean distance to leading topocluster for topoclusters of jet associated to tau candidate
Definition: TauDefs.h:181
xAOD::TauJetParameters::effTopoMeanDeltaR
@ effTopoMeanDeltaR
get mean distance to leading topocluster for effective topoclusters of jet associated to tau candidat...
Definition: TauDefs.h:183
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:85
TauSubstructureVariables.h
xAOD::TauJetParameters::caloIso
@ caloIso
Get sum of transvers energy of clusters around jet seed within 0.2 < dR < 0.4
Definition: TauDefs.h:222
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::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:450
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:31
CaloClusterVariables::averageEffectiveRadius
double averageEffectiveRadius() const
Definition: CaloClusterVariables.h:37
TauSubstructureVariables::m_doVertexCorrection
bool m_doVertexCorrection
Definition: TauSubstructureVariables.h:36
xAOD::TauJetParameters::numTopoClusters
@ numTopoClusters
get number of topocluster constituents of jet associated to tau candidate
Definition: TauDefs.h:173
CaloClusterVariables::effectiveMass
double effectiveMass() const
Definition: CaloClusterVariables.h:32
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:221
CaloClusterVariables::totalMass
double totalMass() const
Definition: CaloClusterVariables.h:31
xAOD::TauJet_v3::vertexedClusters
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
Definition: TauJet_v3.cxx:626
HI::SubCalo::Lists::PreSampler
constexpr std::initializer_list< int > PreSampler
Definition: HIEventDefs.h:77
xAOD::TauJetParameters::numEffTopoClusters
@ numEffTopoClusters
get number of effective topocluster constituents of jet associated to tau candidate !...
Definition: TauDefs.h:175
xAOD::CaloCluster_v1::eSample
float eSample(const CaloSample sampling) const
Definition: CaloCluster_v1.cxx:521
CaloClusterVariables.h
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:630
xAOD::TauJetParameters::effTopoInvMass
@ effTopoInvMass
get invariant mass from effective topoclusters of jet associated to tau candidate
Definition: TauDefs.h:179
xAOD::TauJet_v3::setDetail
void setDetail(TauJetParameters::Detail detail, int value)
Definition: TauJet_v3.cxx:337
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:32
xAOD::TauJetParameters::PSSFraction
@ PSSFraction
Definition: TauDefs.h:277
CaloClusterVariables::update
bool update(const xAOD::TauJet &pTau)
update the internal variables for the given tau
Definition: CaloClusterVariables.cxx:34
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
xAOD::TauJetParameters::EMPOverTrkSysP
@ EMPOverTrkSysP
Definition: TauDefs.h:279
xAOD::CaloVertexedClusterBase::e
virtual double e() const final
The total energy of the particle.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedClusterBase.h:83