ATLAS Offline Software
TauCellVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef XAOD_ANALYSIS
6 
7 #include "TauCellVariables.h"
9 
10 #include "xAODTau/TauJet.h"
11 #include "xAODJet/Jet.h"
13 
14 #include <cmath>
15 #include <vector>
16 
17 
20 }
21 
22 
23 
25 
26  int numStripCell = 0;
27 
28  double sumCellET = 0.;
29  double sumCellET01 = 0;
30  double sumCellET12 = 0.;
31  double sumStripET = 0.;
32  double sumEMCellET = 0.;
33  double sumHadCellET = 0.;
34  double stripEta = 0.;
35  double stripEta2 = 0.;
36  double EMRadius = 0.;
37  double HadRadius = 0.;
38 
39  std::vector<double> cellRingEnergys(7,0.);
40 
41  int numCells = 0;
42  std::bitset<200000> cellSeen;
43 
44  TLorentzVector tauAxis = tauRecTools::getTauAxis(pTau, m_doVertexCorrection);
45 
46  // loop over cells in all the clusters and calculate the variables
47  for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : pTau.vertexedClusters()){
48  const xAOD::CaloCluster& cluster = vertexedCluster.clust();
49  const CaloClusterCellLink* cellLinks = cluster.getCellLinks();
50  if (cellLinks == nullptr) {
51  ATH_MSG_DEBUG("NO Cell links found for cluster with pT " << cluster.pt());
52  continue;
53  }
54  for (const CaloCell* cell : *cellLinks) {
55  ++numCells;
56 
57  // cells could be used by more than one cluster, only count the cell one time
58  if (cellSeen.test(cell->caloDDE()->calo_hash())) {
59  continue;
60  }
61  else {
62  cellSeen.set(cell->caloDDE()->calo_hash());
63  }
64 
65  // cell four momentum corrected to point at the required vertex
66  double cellPhi = cell->phi();
67  double cellEta = cell->eta();
68  double cellET = cell->et();
69  double cellEnergy = cell->energy();
70 
71  const xAOD::Vertex* vertex = pTau.vertex();
72  if (m_doVertexCorrection && vertex!=nullptr) {
73  CaloVertexedCell vxCell (*cell, vertex->position());
74  cellPhi = vxCell.phi();
75  cellEta = vxCell.eta();
76  cellET = vxCell.et();
77  cellEnergy = vxCell.energy();
78  }
79 
80  TLorentzVector temp_cc_p4;
81  temp_cc_p4.SetPtEtaPhiE(cellET, cellEta, cellPhi, cellEnergy);
82  double dR = tauAxis.DeltaR(temp_cc_p4);
83 
84  if (dR < m_cellCone) {
85  sumCellET += cellET;
86 
87  if (dR < 0.1) sumCellET01 += cellET;
88  if (dR > 0.1 && dR < 0.2) sumCellET12 += cellET;
89 
90  CaloSampling::CaloSample calo = cell->caloDDE()->getSampling();
91 
92  // EM layer: PreSamplerB, PreSamplerE, EMB1, EME1, EMB2, EME2
93  // Most energy of neutral particles are deposited in the first two EM laywers
94  // The third layer is regarded as HAD layber
95  if (isEMLayer(calo)) {
96  EMRadius += dR*cellET;
97  sumEMCellET += cellET;
98 
99  // Strip layer: EMB1 and EME1
100  if (isStripLayer(calo) && (std::abs(cellEta) < 2.5)) {
101  sumStripET += cellET;
102  stripEta += cellEta * cellET;
103  stripEta2 += pow(cellEta, 2) * cellET;
104  if (cellEnergy > m_stripEthr) numStripCell += 1;
105  }
106  } // end of EM cells
107  else {
108  HadRadius += dR*cellET;
109  sumHadCellET += cellET;
110  } // end of HAD cells
111  } // end of dR < m_cellCone
112 
113  if (dR < 0.05) cellRingEnergys[0] += cellET;
114  if (dR >= 0.05 && dR < 0.075) cellRingEnergys[1] += cellET;
115  if (dR >= 0.075 && dR < 0.1) cellRingEnergys[2] += cellET;
116  if (dR >= 0.1 && dR < 0.125) cellRingEnergys[3] += cellET;
117  if (dR >= 0.125 && dR < 0.15) cellRingEnergys[4] += cellET;
118  if (dR >= 0.15 && dR < 0.2) cellRingEnergys[5] += cellET;
119  if (dR >= 0.2 && dR < 0.4) cellRingEnergys[6] += cellET;
120  } // end of loop over cells
121  } // end of loop over clusters
122 
123  ATH_MSG_DEBUG(numCells << " cells in seed");
124 
125  pTau.setDetail(xAOD::TauJetParameters::numCells , static_cast<int> (numCells));
126  pTau.setDetail(xAOD::TauJetParameters::nStrip , numStripCell );
127  pTau.setDetail(xAOD::TauJetParameters::etEMAtEMScale , static_cast<float>( sumEMCellET ));
128  pTau.setDetail(xAOD::TauJetParameters::etHadAtEMScale , static_cast<float>( sumHadCellET ));
129  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing1 , static_cast<float>( cellRingEnergys[0] ));
130  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing2 , static_cast<float>( cellRingEnergys[1] ));
131  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing3 , static_cast<float>( cellRingEnergys[2] ));
132  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing4 , static_cast<float>( cellRingEnergys[3] ));
133  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing5 , static_cast<float>( cellRingEnergys[4] ));
134  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing6 , static_cast<float>( cellRingEnergys[5] ));
135  pTau.setDetail(xAOD::TauJetParameters::cellBasedEnergyRing7 , static_cast<float>( cellRingEnergys[6] ));
136 
137  // take care of the variables with division
138  // -- fraction of cell energy within [0,0.1] and [0.1,0.2]
139  if (std::abs(sumCellET) > 1e-6) {
140  pTau.setDetail(xAOD::TauJetParameters::centFrac , static_cast<float>( sumCellET01 / sumCellET ));
141  pTau.setDetail(xAOD::TauJetParameters::isolFrac , static_cast<float>( sumCellET12 / sumCellET ));
142  }
143  else {
144  pTau.setDetail(xAOD::TauJetParameters::centFrac , static_cast<float>( 0.0 ));
145  pTau.setDetail(xAOD::TauJetParameters::isolFrac , static_cast<float>( -1.0 ));
146  }
147 
148  // -- width of strip cells
149  double stripWidth2 = 0.0;
150  if (std::abs(sumStripET) > 1e-6) {
151  stripEta = stripEta / sumStripET;
152  stripEta2 = stripEta2 / sumStripET;
153  stripWidth2 = stripEta2 - stripEta * stripEta;
154  }
155  else {
156  stripWidth2 = -1.0;
157  }
158  pTau.setDetail(xAOD::TauJetParameters::stripWidth2 , static_cast<float>( stripWidth2));
159 
160  // -- cell weighted radius of EM cells
161  if (std::abs(sumEMCellET) > 1e-6) {
162  EMRadius = EMRadius / sumEMCellET;
163  }
164  else {
165  EMRadius = -1.0;
166  }
167  pTau.setDetail(xAOD::TauJetParameters::EMRadius , static_cast<float>( EMRadius ));
168 
169  // -- cell weighted radius of HAD cells
170  if (std::abs(sumHadCellET) > 1e-6) {
171  HadRadius = HadRadius / sumHadCellET;
172  }
173  else {
174  HadRadius = -1.0;
175  }
176  pTau.setDetail(xAOD::TauJetParameters::hadRadius , static_cast<float>( HadRadius ));
177 
178  return StatusCode::SUCCESS;
179 }
180 
181 #endif
xAOD::TauJetParameters::cellBasedEnergyRing4
@ cellBasedEnergyRing4
Ring 4: 0.10 < R < 0.125.
Definition: TauDefs.h:252
Jet.h
CaloVertexedCell::eta
virtual double eta() const final
The pseudorapidity of the particle.
Definition: CaloVertexedCell.h:65
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
xAOD::TauJetParameters::cellBasedEnergyRing7
@ cellBasedEnergyRing7
Ring 7: 0.2 < R < 0.4.
Definition: TauDefs.h:258
CaloVertexedCell::energy
double energy() const
The energy of the particle.
Definition: CaloVertexedCell.h:89
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
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
TauRecToolBase
The base class for all tau tools.
Definition: TauRecToolBase.h:21
CaloVertexedCell::phi
virtual double phi() const final
The aximuthal angle of the particle.
Definition: CaloVertexedCell.h:68
xAOD::TauJetParameters::cellBasedEnergyRing1
@ cellBasedEnergyRing1
EM+TES final scale.
Definition: TauDefs.h:246
xAOD::TauJetParameters::cellBasedEnergyRing6
@ cellBasedEnergyRing6
Ring 6: 0.15 < R < 0.2.
Definition: TauDefs.h:256
xAOD::TauJetParameters::hadRadius
@ hadRadius
Get hadron calorimeter radius.
Definition: TauDefs.h:192
xAOD::TauJetParameters::stripWidth2
@ stripWidth2
Get strip width ^2.
Definition: TauDefs.h:202
xAOD::TauJetParameters::centFrac
@ centFrac
Get centrality fraction.
Definition: TauDefs.h:200
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
xAOD::TauJetParameters::etHadAtEMScale
@ etHadAtEMScale
Get Hadronic energy at EM scale.
Definition: TauDefs.h:196
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
TauCellVariables::m_doVertexCorrection
Gaudi::Property< bool > m_doVertexCorrection
Definition: TauCellVariables.h:41
TauCellVariables::m_cellCone
Gaudi::Property< double > m_cellCone
Definition: TauCellVariables.h:40
xAOD::TauJetParameters::cellBasedEnergyRing2
@ cellBasedEnergyRing2
Ring 2: 0.05 < R < 0.075.
Definition: TauDefs.h:248
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
TauCellVariables::m_stripEthr
Gaudi::Property< double > m_stripEthr
Definition: TauCellVariables.h:39
xAOD::TauJetParameters::cellBasedEnergyRing5
@ cellBasedEnergyRing5
Ring 5: 0.125 < R < 0.15.
Definition: TauDefs.h:254
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:905
xAOD::CaloCluster_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle (negative for negative-energy clusters)
Definition: CaloCluster_v1.cxx:247
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::TauJetParameters::nStrip
@ nStrip
Get number of strips.
Definition: TauDefs.h:204
TauCellVariables::isStripLayer
bool isStripLayer(const CaloSampling::CaloSample &calo) const
Check whether the CaloSample is a Strip layer.
Definition: TauCellVariables.h:60
xAOD::TauJet_v3::vertexedClusters
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
Definition: TauJet_v3.cxx:626
xAOD::TauJetParameters::cellBasedEnergyRing3
@ cellBasedEnergyRing3
Ring 3: 0.075 < R < 0.10.
Definition: TauDefs.h:250
Trk::vertex
@ vertex
Definition: MeasurementType.h:21
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
TauCellVariables::execute
virtual StatusCode execute(xAOD::TauJet &pTau) const override
Perform the calculation of cell variables for each tau candidate.
Definition: TauCellVariables.cxx:24
xAOD::TauJetParameters::numCells
@ numCells
Definition: TauDefs.h:171
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloVertexedCell
Evaluate cell kinematics with a different vertex.
Definition: CaloVertexedCell.h:37
xAOD::TauJet_v3::vertex
const Vertex * vertex() const
TauJet.h
HelperFunctions.h
xAOD::TauJet_v3::setDetail
void setDetail(TauJetParameters::Detail detail, int value)
Definition: TauJet_v3.cxx:337
xAOD::TauJetParameters::isolFrac
@ isolFrac
Get isolation fraction.
Definition: TauDefs.h:198
TauCellVariables::isEMLayer
bool isEMLayer(const CaloSampling::CaloSample &calo) const
Check whether the CaloSample is a EM layer.
Definition: TauCellVariables.h:45
TauCellVariables::TauCellVariables
TauCellVariables(const std::string &name)
Constructor.
Definition: TauCellVariables.cxx:18
P4EEtaPhiMBase::et
virtual double et() const
transverse energy defined to be e*sin(theta)
Definition: P4EEtaPhiMBase.cxx:106
xAOD::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
TauCellVariables.h
xAOD::TauJetParameters::EMRadius
@ EMRadius
Get E_T radius.
Definition: TauDefs.h:190
CaloVertexedCell.h
Evaluate cell kinematics with a different vertex.
xAOD::TauJetParameters::etEMAtEMScale
@ etEMAtEMScale
Get EM energy at EM scale.
Definition: TauDefs.h:194