ATLAS Offline Software
JetCaloQualityUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "xAODJet/Jet.h"
8 
11 
12 #include "CaloGeoHelpers/CaloSampling.h"
13 
14 
15 using xAOD::Jet;
16 using xAOD::CaloCluster;
17 
18 
19 
20 namespace {
21 
30 
31 //const double GeV = 1000.0;
32 }
33 
34 namespace jet {
35 
36 
37  int JetCaloQualityUtils::compute_nLeading(std::vector<double> &cell_energies, const float& e, const float& frac)
38  {
39  std::sort(cell_energies.rbegin(),cell_energies.rend());
40  int counter =0;
41  float sum = 0;
42  for(unsigned int i=0;i<cell_energies.size();i++)
43  {
44  sum += cell_energies[i];
45  counter++;
46  if(sum>frac*e) break;
47  }
48  return counter;
49  }
50 
51 
52 
54  *xAOD::JetAttributeAccessor::accessor< std::vector<float> >(xAOD::JetAttribute::EnergyPerSampling);
55 
56  double JetCaloQualityUtils::emFraction(const std::vector<float>& e_sampling){
57  double e_EM = 0;
58  for(int i=0; i<9; i++) e_EM += e_sampling[ ::em_calosample[i] ];
59 
60  double e_HAD = 0;
61  for(int i=0; i<15; i++) e_HAD += e_sampling[ ::had_calosample[i] ];
62  if( (e_EM==0) || ((e_EM+e_HAD)==0) ) return 0.;
63  return (e_EM / (e_EM+e_HAD));
64  }
65 
66 
68  {
69 
70  const std::vector<float> & einsampling = eperSamplAcc(*jet);
71 
72  double e_hec =einsampling[CaloSampling::HEC0]
73  +einsampling[CaloSampling::HEC1]
74  +einsampling[CaloSampling::HEC2]
75  +einsampling[CaloSampling::HEC3];
76 
77  double e_jet = jet->jetP4(xAOD::JetEMScaleMomentum).E();
78 
79  if(e_jet!=0) return e_hec/e_jet;
80  else return -999;
81  }
82 
84  {
85  const std::vector<float>& einsampling = eperSamplAcc(*jet);
86 
87  double e_pres = einsampling[CaloSampling::PreSamplerB] + einsampling[CaloSampling::PreSamplerE];
88 
89  double e_jet = jet->jetP4(xAOD::JetEMScaleMomentum).E();
90 
91  if(e_jet!=0) return e_pres/e_jet;
92  else return -999;
93  }
94 
96  {
97  const std::vector<float> & einsampling = eperSamplAcc(*jet);
98 
99  double e_tileGap3 =einsampling[CaloSampling::TileGap3];
100  double e_jet = jet->jetP4(xAOD::JetEMScaleMomentum).E();
101 
102  if(e_jet!=0) return e_tileGap3/e_jet;
103  else return -999;
104  }
105 
106 
107  double JetCaloQualityUtils::fracSamplingMax(const Jet* jet, int& SamplingMax)
108  {
109  const std::vector<float> & einsampling = eperSamplAcc(*jet);
110 
111  double fracSamplingMax=-999999999.;
112  double sumE_samplings=0.;
113  for ( unsigned int i(0); i < einsampling.size(); ++i )
114  {
115  double e = einsampling[i];
116  sumE_samplings+=e;
117  if (e>fracSamplingMax)
118  {
120  SamplingMax=i;
121  }
122  }
123 
124  if(sumE_samplings!=0)
125  fracSamplingMax/=sumE_samplings;
126  else fracSamplingMax=0;
127 
128  return fracSamplingMax;
129  }
130 
131 
132 
133 
134 
135 
136 
138  {
140  return negE(jet);
141  }
142 
143 
144  bool JetCaloQualityUtils::isUgly(const Jet* jet,const bool /*recalculateQuantities*/){
145  double fcor = jet->getAttribute<float>(xAOD::JetAttribute::BchCorrCell);
146  double tileGap3f = JetCaloQualityUtils::tileGap3F(jet);
147 
148  if (fcor>0.5) return true;
149  if (tileGap3f >0.5) return true;
150 
151  return false;
152  }
153 
154 
155 
156 
157  // ****************************************************************
158  // JetCalcnLeadingCells *************************************************
159  // ****************************************************************
160 
161  bool JetCalcnLeadingCells::setupJet(const Jet* j){
162  m_sumE_cells=0;
163  m_cell_energies.clear();
164  m_cell_energies.reserve(j->numConstituents());
165  return true;
166  }
167 
168 
170 
171  double e = iter->e();
172  if(iter->type() == xAOD::Type::ParticleFlow){
173  e = iter->rawConstituent()->e();
174  }
175  m_cell_energies.push_back(e);
176  m_sumE_cells+=e;
177  return true;
178  }
179 
180  double JetCalcnLeadingCells::jetCalculation() const {
181  std::vector<double> nc_cell_energies(m_cell_energies);
183  }
184 
185 
186  // ****************************************************************
187  // JetCalcOutOfTimeEnergyFraction *************************************************
188  // ****************************************************************
190  m_sumE=0;
191  m_sumE_OOT=0;
192  return true;
193  }
194 
195 
197  if( m_sumE== 0.) return -1;
198  return m_sumE_OOT/m_sumE ;
199  }
200 
202 
203  //double sum_all(0), sum_time(0);
204 
205  double aClusterE = iter->e();
206  if(iter->type() == xAOD::Type::ParticleFlow){
207  aClusterE = iter->rawConstituent()->e();
208  }
209  double aClusterTime = m_constitExtractor->time(iter);//;static_cast<const xAOD::CaloCluster*>(iter->rawConstituent())->time();
210 
211 
212  if(onlyPosEnergy && aClusterE<0) return true;
213 
214  m_sumE += aClusterE;
215  if(fabs(aClusterTime) > timecut) m_sumE_OOT += aClusterE;
216 
217  return true;
218  }
219 
220  // ****************************************************************
221  // JetCalcTimeCells *************************************************
222  // ****************************************************************
223  bool JetCalcTimeCells::setupJet(const Jet* ){
224  m_time = 0; m_norm = 0;
225  return true;
226  }
227 
228 
229 
231 
232  double thisNorm = iter->e()* iter->e();
233  if(iter->type() == xAOD::Type::ParticleFlow){
234  thisNorm = iter->rawConstituent()->e()*iter->rawConstituent()->e();
235  }
236  m_time += m_constitExtractor->time(iter) * thisNorm; //theClus->time() * thisNorm ;
237  m_norm += thisNorm;
238 
239  return true;
240  }
241 
242  double JetCalcTimeCells::jetCalculation() const {
243  if (m_norm==0) return 0;
244  return m_time/m_norm ;
245  }
246 
247 
248  // ****************************************************************
249  // JetCalcAverageLArQualityF *************************************************
250  // ****************************************************************
252  m_qf = 0; m_norm = 0; return true;
253  }
254 
255 
257  if(m_norm==0) return 0;
258  return m_qf/m_norm;
259  }
260 
262 
263  double e2 = iter->e();
264  if(iter->type() == xAOD::Type::ParticleFlow){
265  e2 = iter->rawConstituent()->e();
266  }
267  e2 = e2*e2;
268 
269  m_norm+= e2;
270  double qual(0);
271  if(m_useTile)
273  else
275  m_qf += qual*e2;
276  return true;
277  }
278 
279  // ****************************************************************
280  // JetCalcQuality *************************************************
281  // ****************************************************************
282  bool JetCalcQuality::setupJet(const Jet* ){
283  m_totE=0; m_badE=0; return true;
284  }
285 
286 
287  double JetCalcQuality::jetCalculation() const {
288  if (m_totE==0) return 0;
289  return m_badE/m_totE ;
290  }
291 
292 
294 
296 
297  if(iter->type() == xAOD::Type::ParticleFlow){
298  m_totE += iter->rawConstituent()->e(); // using iter since it is set at the expected scale by the JetCaloCalculations instance
299  m_badE += f * iter->rawConstituent()->e();
300  }
301  else{
302  m_totE += iter->e();
303  m_badE += f * iter->e();
304  }
305 
306  return true;
307  }
308 
309 
310  // ****************************************************************
311  // JetCalcQualityHEC *************************************************
312  // ****************************************************************
313 
314 
315 
317  double clustHEC = m_constitExtractor->energyHEC(iter);
318  m_totE += clustHEC ;
319 
321 
322  m_badE += f *clustHEC;
323  return true;
324  }
325 
326  // ****************************************************************
327  // JetCalcNegativeEnergy *************************************************
328  // ****************************************************************
329  bool JetCalcNegativeEnergy::setupJet(const Jet* ){
330  m_totE =0;
331  return true;
332  }
333 
334 
335  double JetCalcNegativeEnergy::jetCalculation() const {
336 
337  return m_totE;
338 
339  }
340 
342 
343  double e = iter->e() ; // using iter since it is set at the expected scale by the JetCaloCalculations instance
344  if(iter->type() == xAOD::Type::ParticleFlow){
345  e = iter->rawConstituent()->e();
346  }
347 
349  m_totE += (e - epos );
350 
351  return true;
352  }
353 
354  // ****************************************************************
355  // JetCalcCentroid *************************************************
356  // ****************************************************************
357  bool JetCalcCentroid::setupJet(const Jet* /*j*/){
358  m_totE =0;
360  return true;
361  }
362 
363 
364  double JetCalcCentroid::jetCalculation() const {
365 
366  if (m_totE == 0) return 0;
367 
368  double c_x = m_centroid_x/ m_totE;
369  double c_z = m_centroid_z/ m_totE;
370  double c_y = m_centroid_y/ m_totE;
371 
372  return sqrt(c_x*c_x + c_y*c_y+ c_z*c_z);
373  }
374 
376 
377  double e = iter->e() ; // using iter since it is set at the expected scale by the JetCaloCalculations instance
378  if(iter->type() == xAOD::Type::ParticleFlow){
379  e = iter->rawConstituent()->e();
380  }
381 
382  m_totE +=e;
383  double x,y,z;
384 
388 
389  m_centroid_x += x* e;
390  m_centroid_y += y* e;
391  m_centroid_z += z* e;
392 
393  return true;
394  }
395 
396  // ****************************************************************
397  // JetCalcBadCellsFrac *************************************************
398  // ****************************************************************
399  bool JetCalcBadCellsFrac::setupJet(const Jet* j){
400  m_totE = j->jetP4(xAOD::JetEMScaleMomentum).E() ;
401  m_badE = 0;
402  return true;
403  }
404 
405 
408  return true;
409  }
410 
411  double JetCalcBadCellsFrac::jetCalculation() const {
412  if (m_totE == 0) return 0;
413  return m_badE / m_totE ;
414  }
415 
416 
417 }
jet::JetCalcOutOfTimeEnergyFraction::m_sumE_OOT
double m_sumE_OOT
Definition: JetCaloQualityUtils.h:97
xAOD::JetAttribute::BchCorrCell
@ BchCorrCell
Definition: JetAttributes.h:94
jet::JetCaloCalculator::processConstituent
virtual bool processConstituent(xAOD::JetConstituentVector::iterator &)
Perform 1 calculation step using 1 constituent.
Definition: JetCaloCalculations.h:93
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
Jet.h
jet::JetCalcTimeCells::m_time
double m_time
Definition: JetCaloQualityUtils.h:108
CaloCell_ID_FCS::TileExt2
@ TileExt2
Definition: FastCaloSim_CaloCell_ID.h:39
constants.EMB1
int EMB1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:53
xAOD::CaloCluster_v1::CENTER_X
@ CENTER_X
Cluster Centroid ( )
Definition: CaloCluster_v1.h:131
Jet
Basic data class defines behavior for all Jet objects The Jet class is the principal data class for...
Definition: Reconstruction/Jet/JetEvent/JetEvent/Jet.h:47
jet::JetCaloQualityUtils::tileGap3F
static double tileGap3F(const Jet *jet)
Definition: JetCaloQualityUtils.cxx:95
CaloCell_ID_FCS::TileExt0
@ TileExt0
Definition: FastCaloSim_CaloCell_ID.h:37
CaloCell_ID_FCS::TileBar1
@ TileBar1
Definition: FastCaloSim_CaloCell_ID.h:32
jet::JetCaloQualityUtils::isUgly
static bool isUgly(const Jet *jet, const bool recalculateQuantities=false)
Definition: JetCaloQualityUtils.cxx:144
jet::JetCalcQualityHEC::processConstituent
bool processConstituent(xAOD::JetConstituentVector::iterator &iter)
Perform 1 calculation step using 1 constituent.
Definition: JetCaloQualityUtils.cxx:316
xAOD::CaloCluster_v1::AVG_LAR_Q
@ AVG_LAR_Q
Sum(E_cell_LAr^2 Q_cell_LAr)/Sum(E_cell_LAr^2)
Definition: CaloCluster_v1.h:163
CaloConstitHelpers::CaloConstitExtractor::energyHEC
virtual double energyHEC(xAOD::JetConstituentVector::iterator &) const
Definition: JetCaloCalculations.h:36
jet::JetCaloQualityUtils::jetNegativeEnergy
static double jetNegativeEnergy(const Jet *jet)
Definition: JetCaloQualityUtils.cxx:137
CaloCell_ID_FCS::FCAL1
@ FCAL1
Definition: FastCaloSim_CaloCell_ID.h:41
jet::JetCalcNegativeEnergy
Definition: JetCaloQualityUtils.h:154
CaloConstitHelpers::CaloConstitExtractor::moment
virtual double moment(xAOD::JetConstituentVector::iterator &, xAOD::CaloCluster::MomentType) const
Definition: JetCaloCalculations.h:34
xAOD::JetAttribute::EnergyPerSampling
@ EnergyPerSampling
Definition: JetAttributes.h:115
CaloCell_ID_FCS::HEC2
@ HEC2
Definition: FastCaloSim_CaloCell_ID.h:29
jet::JetCalcAverageLArQualityF::m_qf
double m_qf
Definition: JetCaloQualityUtils.h:118
jet::JetCaloCalculator::setupJet
virtual bool setupJet(const xAOD::Jet *)=0
x
#define x
CaloCell_ID_FCS::TileGap3
@ TileGap3
Definition: FastCaloSim_CaloCell_ID.h:36
JetAccessorMap.h
xAOD::CaloCluster
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
Definition: Event/xAOD/xAODCaloEvent/xAODCaloEvent/CaloCluster.h:19
jet::JetCalcTimeCells::m_norm
double m_norm
Definition: JetCaloQualityUtils.h:108
xAOD::CaloCluster_v1::CENTER_Z
@ CENTER_Z
Cluster Centroid ( )
Definition: CaloCluster_v1.h:133
CaloConstitHelpers::CaloConstitExtractor::time
virtual double time(xAOD::JetConstituentVector::iterator &) const
Definition: JetCaloCalculations.h:35
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
jet::JetCalcOutOfTimeEnergyFraction::m_sumE
double m_sumE
Definition: JetCaloQualityUtils.h:97
CaloCell_ID_FCS::HEC1
@ HEC1
Definition: FastCaloSim_CaloCell_ID.h:28
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
constants.EMB2
int EMB2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:54
lumiFormat.i
int i
Definition: lumiFormat.py:92
CaloCluster.h
z
#define z
CaloCell_ID_FCS::TileBar0
@ TileBar0
Definition: FastCaloSim_CaloCell_ID.h:31
jet::JetCalcCentroid::m_totE
double m_totE
Definition: JetCaloQualityUtils.h:164
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:256
CaloCell_ID_FCS::TileGap2
@ TileGap2
Definition: FastCaloSim_CaloCell_ID.h:35
jet::JetCalcnLeadingCells::m_threshold
double m_threshold
Definition: JetCaloQualityUtils.h:88
jet::JetCalcOutOfTimeEnergyFraction::onlyPosEnergy
bool onlyPosEnergy
Definition: JetCaloQualityUtils.h:100
jet::JetCalcQuality::m_totE
double m_totE
Definition: JetCaloQualityUtils.h:127
constants.EME1
int EME1
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:55
xAODType::ParticleFlow
@ ParticleFlow
The object is a particle-flow object.
Definition: ObjectType.h:41
jet::JetCalcQuality::m_badE
double m_badE
Definition: JetCaloQualityUtils.h:127
xAOD::JetConstituent::rawConstituent
const IParticle * rawConstituent() const
Access the real underlying IParticle.
Definition: JetConstituentVector.h:102
jet::JetCaloCalculator::m_constitExtractor
const CaloConstitHelpers::CaloConstitExtractor * m_constitExtractor
Definition: JetCaloCalculations.h:115
jet::JetCalcCentroid::m_centroid_z
double m_centroid_z
Definition: JetCaloQualityUtils.h:164
CaloCell_ID_FCS::TileGap1
@ TileGap1
Definition: FastCaloSim_CaloCell_ID.h:34
xAOD::CaloCluster_v1::ENG_BAD_CELLS
@ ENG_BAD_CELLS
Total em-scale energy of bad cells in this cluster.
Definition: CaloCluster_v1.h:148
xAOD::JetEMScaleMomentum
@ JetEMScaleMomentum
Definition: JetTypes.h:28
CaloCell_ID_FCS::TileExt1
@ TileExt1
Definition: FastCaloSim_CaloCell_ID.h:38
xAOD::JetConstituent::type
Type::ObjectType type() const
The full 4-momentum of the particle.
Definition: JetConstituentVector.h:91
CaloCell_ID_FCS::EME3
@ EME3
Definition: FastCaloSim_CaloCell_ID.h:26
jet::JetCalcCentroid::m_centroid_y
double m_centroid_y
Definition: JetCaloQualityUtils.h:164
jet::JetCaloQualityUtils::fracSamplingMax
static double fracSamplingMax(const Jet *jet, int &SamplingMax)
Definition: JetCaloQualityUtils.cxx:107
xAOD::CaloCluster_v1::AVG_TILE_Q
@ AVG_TILE_Q
Sum(E_cell_Tile^2 Q_cell_Tile)/Sum(E_cell_Tile^2)
Definition: CaloCluster_v1.h:165
CaloCell_ID_FCS::HEC0
@ HEC0
Definition: FastCaloSim_CaloCell_ID.h:27
jet::JetCaloQualityUtils::hecF
static double hecF(const Jet *jet)
Definition: JetCaloQualityUtils.cxx:67
jet::JetCalcBadCellsFrac::m_totE
double m_totE
Definition: JetCaloQualityUtils.h:173
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
y
#define y
egammaEnergyPositionAllSamples::e2
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
jet::JetCalcAverageLArQualityF::m_norm
double m_norm
Definition: JetCaloQualityUtils.h:118
jet::JetCalcnLeadingCells::m_cell_energies
std::vector< double > m_cell_energies
Definition: JetCaloQualityUtils.h:86
xAOD::JetAttributeAccessor::AccessorWrapper
Definition: JetAccessors.h:49
CaloCell_ID_FCS::PreSamplerE
@ PreSamplerE
Definition: FastCaloSim_CaloCell_ID.h:23
jobOptions.epos
epos
Definition: jobOptions.crmc.py:50
CaloCell_ID_FCS::PreSamplerB
@ PreSamplerB
Definition: FastCaloSim_CaloCell_ID.h:19
jet::JetCalcAverageLArQualityF::m_useTile
bool m_useTile
Definition: JetCaloQualityUtils.h:119
jet::JetCaloCalculator::jetCalculation
virtual double jetCalculation() const
return the result of the calculation
Definition: JetCaloCalculations.h:97
jet::JetCaloQualityUtils::compute_nLeading
static int compute_nLeading(std::vector< double > &cell_energies, const float &e, const float &frac)
Definition: JetCaloQualityUtils.cxx:37
jet::JetCalcOutOfTimeEnergyFraction::timecut
double timecut
Definition: JetCaloQualityUtils.h:99
jet::JetCalcnLeadingCells::m_sumE_cells
double m_sumE_cells
Definition: JetCaloQualityUtils.h:87
jet::JetCalcBadCellsFrac::m_badE
double m_badE
Definition: JetCaloQualityUtils.h:174
xAOD::JetConstituent::e
double e() const
The total energy of the particle.
Definition: JetConstituentVector.h:76
jet::JetCaloQualityUtils::emFraction
static double emFraction(const std::vector< float > &ePerSampling)
Definition: JetCaloQualityUtils.cxx:56
beamspotman.qual
qual
Definition: beamspotman.py:481
CaloCell_ID_FCS::FCAL2
@ FCAL2
Definition: FastCaloSim_CaloCell_ID.h:42
xAOD::JetConstituentVector::iterator
Definition: JetConstituentVector.h:121
JetCaloQualityUtils.h
CaloCell_ID_FCS::HEC3
@ HEC3
Definition: FastCaloSim_CaloCell_ID.h:30
test_pyathena.counter
counter
Definition: test_pyathena.py:15
jet::JetCalcNegativeEnergy::m_totE
double m_totE
Definition: JetCaloQualityUtils.h:156
CaloCell_ID_FCS::FCAL0
@ FCAL0
Definition: FastCaloSim_CaloCell_ID.h:40
CaloCell_ID_FCS::EMB3
@ EMB3
Definition: FastCaloSim_CaloCell_ID.h:22
jet::JetCalcCentroid::m_centroid_x
double m_centroid_x
Definition: JetCaloQualityUtils.h:164
CaloCell_ID_FCS::TileBar2
@ TileBar2
Definition: FastCaloSim_CaloCell_ID.h:33
jet::JetCaloQualityUtils::presamplerFraction
static double presamplerFraction(const Jet *jet)
Definition: JetCaloQualityUtils.cxx:83
xAOD::Jet
Jet_v1 Jet
Definition of the current "jet version".
Definition: Event/xAOD/xAODJet/xAODJet/Jet.h:17
xAOD::CaloCluster_v1::CENTER_Y
@ CENTER_Y
Cluster Centroid ( )
Definition: CaloCluster_v1.h:132
constants.EME2
int EME2
Definition: Calorimeter/CaloClusterCorrection/python/constants.py:56
xAOD::IParticle::e
virtual double e() const =0
The total energy of the particle.
xAOD::CaloCluster_v1::ENG_POS
@ ENG_POS
Total positive Energy of this cluster.
Definition: CaloCluster_v1.h:156
xAOD::CaloCluster_v1::BADLARQ_FRAC
@ BADLARQ_FRAC
Energy fraction of LAr cells with quality larger than a given cut.
Definition: CaloCluster_v1.h:155