ATLAS Offline Software
CaloClusterVariables.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 
9 
10 #include <cmath>
11 
12 const double CaloClusterVariables::DEFAULT = -1111.;
13 
14 //****************************************
15 // constructor
16 //****************************************
17 
19  m_numConstit((int) DEFAULT),
20  m_effNumConstit_int((int) DEFAULT),
21  m_effNumConstit(DEFAULT),
22  m_aveRadius(DEFAULT),
23  m_aveEffRadius(DEFAULT),
24  m_totMass(DEFAULT),
25  m_effMass(DEFAULT),
26  m_totEnergy(DEFAULT),
27  m_effEnergy(DEFAULT) {
28  }
29 
30 //*******************************************
31 // update/fill the cluster based variables
32 //*******************************************
33 
35 
36  const auto& vertexedClusterList = pTau.vertexedClusters();
37 
38  std::vector<TLorentzVector> clusterP4Vector;
39  clusterP4Vector.reserve(vertexedClusterList.size());
40 
41  for (const xAOD::CaloVertexedTopoCluster& vertexedCluster : vertexedClusterList) {
42  clusterP4Vector.push_back(vertexedCluster.p4());
43  }
44 
45  this->m_numConstit = (int) clusterP4Vector.size();
46 
47  // Order constituents by energy
48  sort(clusterP4Vector.begin(), clusterP4Vector.end(), CaloClusterCompare());
49 
50  //****************************************
51  // Looping over all constituents
52  //****************************************
53 
54  double sum_px = 0.;
55  double sum_py = 0.;
56  double sum_pz = 0.;
57  double sum_e = 0.;
58  double sum_of_E2 = 0.;
59  double sum_radii = 0.;
60  TLorentzVector centroid = calculateTauCentroid(this->m_numConstit, clusterP4Vector);
61 
62  for (const TLorentzVector& clusterP4 : clusterP4Vector) {
63 
64  sum_of_E2 += clusterP4.E()*clusterP4.E();
65  sum_radii += clusterP4.DeltaR(centroid);
66  sum_e += clusterP4.E();
67  sum_px += clusterP4.Px();
68  sum_py += clusterP4.Py();
69  sum_pz += clusterP4.Pz();
70 
71  }
72 
73  // Sum up the energy for constituents
74  this->m_totEnergy = sum_e;
75 
76  // Calculate the mass of the constituents
77  if (this->m_numConstit < 2) this->m_totMass = DEFAULT;
78  else {
79  double mass2 = sum_e * sum_e - (sum_px * sum_px + sum_py * sum_py + sum_pz * sum_pz);
80  this->m_totMass = mass2 > 0 ? std::sqrt(mass2) : -std::sqrt(-mass2);
81  }
82 
83  // Calculate the average radius of the constituents wrt the tau centroid
84  this->m_aveRadius = this->m_numConstit > 0 ? sum_radii / this->m_numConstit : DEFAULT;
85 
86  // Effective number of constituents
87  this->m_effNumConstit = sum_of_E2 > 0 ? (sum_e * sum_e) / (sum_of_E2) : DEFAULT;
88 
89  this->m_effNumConstit_int = int(ceil(this->m_effNumConstit));
90 
91  // A problem!
92  if (this->m_effNumConstit_int > this->m_numConstit) return false;
93 
94  // Avoid segfault, happens when we try to iterate below if sum_of_E2 was 0 or negative
95  if (this->m_effNumConstit_int < 0) return false;
96 
97  //****************************************
98  // Now: Looping over effective constituents
99  //****************************************
100 
101  sum_px = 0.;
102  sum_py = 0.;
103  sum_pz = 0.;
104  sum_e = 0.;
105  sum_of_E2 = 0.;
106  sum_radii = 0.;
107  centroid = calculateTauCentroid(this->m_effNumConstit_int, clusterP4Vector);
108 
109  int icount = this->m_effNumConstit_int;
110  for (const TLorentzVector& clusterP4 : clusterP4Vector) {
111  if (icount <= 0) break;
112  --icount;
113 
114  sum_radii += clusterP4.DeltaR(centroid);
115  sum_e += clusterP4.E();
116  sum_px += clusterP4.Px();
117  sum_py += clusterP4.Py();
118  sum_pz += clusterP4.Pz();
119 
120  }
121 
122  // Sum up the energy for effective constituents
123  this->m_effEnergy = sum_e;
124 
125  // Calculate the mass of the constituents
126  if (this->m_effNumConstit_int < 2) this->m_effMass = DEFAULT;
127  else {
128  double mass2 = sum_e * sum_e - (sum_px * sum_px + sum_py * sum_py + sum_pz * sum_pz);
129  this->m_effMass = mass2 > 0 ? std::sqrt(mass2) : -std::sqrt(-mass2);
130  }
131 
132  // Calculate the average radius of the constituents wrt the tau centroid
133  this->m_aveEffRadius = this->m_effNumConstit_int > 0 ? sum_radii / this->m_effNumConstit_int : DEFAULT;
134 
135  return true;
136 }
137 
138 
139 //***********************************************************
140 // Calculate the geometrical center of the tau constituents
141 //***********************************************************
142 TLorentzVector CaloClusterVariables::calculateTauCentroid(int nConst, const std::vector<TLorentzVector>& clusterP4Vector) const {
143 
144  double px = 0.;
145  double py = 0.;
146  double pz = 0.;
147  double modulus = 0.;
148 
149  for (const TLorentzVector& clusterP4: clusterP4Vector) {
150  if (nConst <= 0) break;
151  --nConst;
152 
153  modulus = std::sqrt((clusterP4.Px() * clusterP4.Px()) + (clusterP4.Py() * clusterP4.Py()) + (clusterP4.Pz() * clusterP4.Pz()));
154 
155  px += clusterP4.Px() / modulus;
156  py += clusterP4.Py() / modulus;
157  pz += clusterP4.Pz() / modulus;
158 
159  }
160 
161  TLorentzVector centroid(px, py, pz, 1);
162  return centroid;
163 }
DEFAULT
@ DEFAULT
Definition: sTGCenumeration.h:15
CaloClusterVariables::m_effEnergy
double m_effEnergy
Definition: CaloClusterVariables.h:53
test_pyathena.px
px
Definition: test_pyathena.py:18
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CaloClusterVariables::CaloClusterVariables
CaloClusterVariables()
Definition: CaloClusterVariables.cxx:18
CaloClusterVariables::m_aveRadius
double m_aveRadius
Definition: CaloClusterVariables.h:48
CaloClusterVariables::m_totEnergy
double m_totEnergy
Definition: CaloClusterVariables.h:52
CaloClusterVariables::DEFAULT
static const double DEFAULT
Definition: CaloClusterVariables.h:19
CaloClusterVariables::calculateTauCentroid
TLorentzVector calculateTauCentroid(int nConst, const std::vector< TLorentzVector > &clusterP4Vector) const
Definition: CaloClusterVariables.cxx:142
CaloClusterVariables::m_totMass
double m_totMass
Definition: CaloClusterVariables.h:50
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
Amg::py
@ py
Definition: GeoPrimitives.h:39
CaloVertexedTopoCluster.h
Evaluate cluster kinematics with a different vertex / signal state.
xAOD::TauJet_v3::vertexedClusters
std::vector< xAOD::CaloVertexedTopoCluster > vertexedClusters() const
Definition: TauJet_v3.cxx:626
CaloClusterVariables::m_numConstit
int m_numConstit
Definition: CaloClusterVariables.h:45
CaloClusterVariables.h
CaloClusterVariables::m_effNumConstit
double m_effNumConstit
Definition: CaloClusterVariables.h:47
HelperFunctions.h
CaloClusterVariables::m_effNumConstit_int
int m_effNumConstit_int
Definition: CaloClusterVariables.h:46
CaloClusterCompare
Descending order by energy.
Definition: CaloClusterVariables.h:62
xAOD::CaloVertexedTopoCluster
Evaluate cluster kinematics with a different vertex / signal state.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloVertexedTopoCluster.h:38
CaloClusterVariables::update
bool update(const xAOD::TauJet &pTau)
update the internal variables for the given tau
Definition: CaloClusterVariables.cxx:34
NSWL1::centroid
Vertex centroid(const Polygon &p)
Definition: GeoUtils.cxx:59
CaloClusterVariables::m_effMass
double m_effMass
Definition: CaloClusterVariables.h:51
CaloClusterVariables::m_aveEffRadius
double m_aveEffRadius
Definition: CaloClusterVariables.h:49