ATLAS Offline Software
CaloLayerCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id: CaloLayerCalculator.cxx,v 1.1 2006-03-20 17:42:26 ssnyder Exp $
15 #include "CaloUtils/CaloCellList.h"
17 
24 {
25  reset();
26 }
27 
28 
48  const CaloCellContainer* cell_container,
49  double eta,
50  double phi,
51  double deta,
52  double dphi,
53  CaloSampling::CaloSample sampling,
54  xAOD::CaloCluster* tofill /*= 0*/)
55 {
56 
57  //Check if cell_container and cluster matches
58  if (tofill) {
59  if (tofill->getCellLinks()->getCellContainer()!=cell_container) {
60  std::cout << "ERROR attempt to fill a cluster from different cell containers\n";
61  return StatusCode::FAILURE;
62  }
63  }
64 
65  CaloCellList cell_list(&mgr,cell_container);
66  cell_list.select(eta,phi,deta,dphi,sampling);
67 
68  fill (cell_list.begin(),
69  cell_list.end(),
70  eta, phi, deta, dphi, sampling, tofill);
71 
72  return StatusCode::SUCCESS;
73 }
74 
77 {
78  m_etam = -999;
79  m_phim = -999;
80  m_etamax = -999;
81  m_phimax = -999;
82  m_etarmax= -999;
83  m_phirmax= -999;
84 
85  m_etas = 0;
86  m_phis = 0;
87  m_em = 0;
88  m_emax = 0;
89 
90  // Added to cluster in the calorimeter frame
91  m_etamr = -999;
92  m_phimr = -999;
93 
94 }
95 
96 
99 {
100  m_etam = -999;
101  m_phim = -999;
102  m_etamax = -999;
103  m_phimax = -999;
104  // Don't reset these --- that could prevent us from being able
105  // to calculate the e2* variables in egammaMiddleShape if there
106  // are negative energy cells just outside the cluster.
107  //m_etarmax= -999;
108  //m_phirmax= -999;
109 
110  m_etas = 0;
111  m_phis = 0;
112  //m_em = 0;
113  m_emax = 0;
114 
115  // Added to cluster in the calorimeter frame
116  m_etamr = -999;
117  m_phimr = -999;
118 }
119 
122 {
123  m_etam = eta;
124  m_phim = phi;
125  m_etamax = eta;
126  m_phimax = phi;
127  m_etarmax= eta;
128  m_phirmax= phi;
129 
130  m_etas = 0;
131  m_phis = 0;
132  //m_em = 0;
133  m_emax = 0;
134 
135  // Added to cluster in the calorimeter frame
136  m_etamr = eta;
137  m_phimr = phi;
138 }
139 
140 
155  double eta,
156  double phi,
157  double deta,
158  double dphi,
159  CaloSampling::CaloSample sampling,
160  xAOD::CaloCluster* tofill,
161  const CaloCellContainer*
162  cell_container)
163  : m_calc (calc),
164  m_eta (eta),
165  m_phi (CaloPhiRange::fix (phi)),
166  m_deta (deta),
167  m_dphi (dphi),
168  m_sampling (sampling),
169  m_tofill (tofill),
170  m_cell_container (cell_container),
171  m_s00 (0),
172  m_s10 (0),
173  m_s20 (0),
174  m_s01 (0),
175  m_s02 (0),
176  // Added to cluster in the calorimeter frame
177  m_s10r (0),
178  m_s01r (0)
179 {
180  m_calc.m_emax = -999999;
181 }
182 
183 
189 void
191 {
192  // Test to see if this cell should be selected.
193  if (cell->caloDDE()->getSampling() == m_sampling) {
194  double etac = cell->eta();
195  double phic = cell->phi();
196  double etar = cell->caloDDE()->eta_raw();
197  double phir = cell->caloDDE()->phi_raw();
198  // Ideally, phi is computed as a deltaphi + phi to be safe with range
199  // the offset is taken to be the seed from the previous sampling
200  // I take the same offset for the raw and real computations
201  double dphic = CaloPhiRange::diff (phic, m_phi);
202  double dphir = CaloPhiRange::diff (phir, m_phi);
203 
204  // The conditions are applied in the calorimeter frame, the biggest difference w.r.t. before...
205  if (etar >= m_eta-m_deta/2. && etar <= m_eta+m_deta/2.) {
206  if (dphir >= -m_dphi/2. && dphir <= m_dphi/2.) {
207 
208  // Is this the maximum-energy cell so far?
209  double ene = cell->energy() * weight;
210 
211  if (ene > m_calc.m_emax) {
212  m_calc.m_etamax = etac;
213  m_calc.m_phimax = phic;
214  m_calc.m_emax = ene;
215  // In the calorimeter frame
216  m_calc.m_etarmax = etar;
217  m_calc.m_phirmax = phir;
218  }
219 
220  // Update accumulation.
221  m_s00 += ene;
222  m_s10 += etac*ene;
223  m_s20 += ene*etac*etac;
224  m_s01 += dphic*ene;
225  m_s02 += ene*dphic*dphic;
226  // In the calorimeter frame
227  m_s10r += etar*ene;
228  m_s01r += dphir*ene;
229 
230  // Add the cell to the cluster, if requested.
231  if (m_tofill)
232  m_tofill->addCell(m_cell_container->findIndex(cell->caloDDE()->calo_hash()), weight);
233  }
234  }
235  }
236 }
237 
238 
245 {
246  m_calc.m_em = m_s00;
247 
248  if (m_s00 > 0.) {
249  // When we computed m_s01 and m_s02 above, we had subtracted phi from each
250  // angle to avoid wrapping problems. We need to add it back in
251  // when computing the mean, but not when we compute the width.
252  // To be pedantic (but i got this wrong the first time, so maybe
253  // someone else will also be confused):
254  // We want <phic^2>-<phic>^2.
255  // s2 = s02/s00 = <(phic-phi)^2>
256  // s1 = s01/s00 = <(phic-phi)>
257  // Expanding the square in s2 gives
258  // <phic^2>-<phic>^2 = s2 - <phic>^2 + phi*(2<phic>-phi)
259  // Expanding the square in s1^2 and substituting for <phic>^2 above gives
260  // <phic^2>-<phic>^2 = s2 - s1^2
261  double s1 = m_s01/m_s00;
262  m_calc.m_phim = CaloPhiRange::fix (s1 + m_phi);
263  m_calc.m_phis = m_s02/m_s00 - s1*s1;
264 
265 
266  m_calc.m_etam = m_s10/m_s00;
267  m_calc.m_etas = m_s20/m_s00 - m_calc.m_etam*m_calc.m_etam;
268 
269  // In the calorimeter frame
270  m_calc.m_etamr = m_s10r/m_s00;
271  m_calc.m_phimr = CaloPhiRange::fix(m_s01r/m_s00 + m_phi);
272 
273  // Reset position variables if the calculated eta,phi is outside
274  // of the window defined by deta,dphi. This usually happens
275  // if the negative energy within the window nearly cancels
276  // the positive energy.
277  if (std::abs (m_calc.m_etamr - m_eta) > m_deta ||
278  std::abs (m_calc.m_etam) > 10 ||
279  std::abs (CaloPhiRange::fix (m_calc.m_phimr - m_phi)) > m_dphi)
280  {
281  m_calc.resetOnNegativeEnergy(m_eta,m_phi);
282  }
283  }
284  else {
285  //reset();//replaced by:
286  m_calc.resetOnNegativeEnergy(m_eta,m_phi);
287 
288  //energy of a sampling CAN be negative (especially PS and back)
289  //when there is the (gaussian) noise
290  //TEMPORARY SOLUTION ( energy negative is not reset to 0 anymore,
291  //but m_etam, m_phim, m_etas, m_phis are still null !! )
292  // => << TO BE REDONE >>
293  }
294 
295  if (m_calc.m_etas > 0.) m_calc.m_etas = sqrt(m_calc.m_etas);
296  if (m_calc.m_phis > 0.) m_calc.m_phis = sqrt (m_calc.m_phis);
297 }
CaloLayerCalculator::Helper::m_calc
CaloLayerCalculator & m_calc
These members hold the values passed to the constructor.
Definition: CaloLayerCalculator.h:327
CaloLayerCalculator::m_phim
double m_phim
Definition: CaloLayerCalculator.h:259
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
CaloLayerCalculator::reset
void reset()
Internals.
Definition: CaloLayerCalculator.cxx:76
CaloPhiRange
This class defines the phi convention for Calorimeters.
Definition: CaloPhiRange.h:28
CaloCellList::begin
list_iterator begin() const
Definition: CaloCellList.h:87
CaloCellList
Definition: CaloCellList.h:40
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
CaloLayerCalculator::resetOnNegativeEnergy
void resetOnNegativeEnergy()
Reset output variables, but not m_em, allowing samplings to be negative.
Definition: CaloLayerCalculator.cxx:98
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
CaloCellList::select
void select(double eta, double phi, double deta, double dphi)
Definition: CaloCellList.cxx:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
CaloLayerCalculator::Helper::~Helper
~Helper()
Calculate the layer variables from the accumulated cells The variables in the parent CaloLayerCalcula...
Definition: CaloLayerCalculator.cxx:244
CaloCellList.h
CaloLayerCalculator::Helper::cell
void cell(const CaloCell *cell, double weight)
Accumulate results for another cell.
Definition: CaloLayerCalculator.cxx:190
CaloLayerCalculator::m_etas
double m_etas
Definition: CaloLayerCalculator.h:260
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
BchCleanup.mgr
mgr
Definition: BchCleanup.py:294
CaloCellList::end
list_iterator end() const
Definition: CaloCellList.h:93
CaloLayerCalculator::Helper::Helper
Helper(CaloLayerCalculator &calc, double eta, double phi, double deta, double dphi, CaloSampling::CaloSample sampling, xAOD::CaloCluster *tofill, const CaloCellContainer *cell_container)
Initialize for doing layer variable calculation.
Definition: CaloLayerCalculator.cxx:154
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
CaloSampling::CaloSample
CaloSample
Definition: Calorimeter/CaloGeoHelpers/CaloGeoHelpers/CaloSampling.h:22
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CaloLayerCalculator::m_etamax
double m_etamax
Definition: CaloLayerCalculator.h:263
CaloLayerCalculator::m_phis
double m_phis
Definition: CaloLayerCalculator.h:261
CaloLayerCalculator::m_etamr
double m_etamr
Definition: CaloLayerCalculator.h:268
CaloLayerCalculator::m_phimax
double m_phimax
Definition: CaloLayerCalculator.h:264
CaloLayerCalculator::m_em
double m_em
Definition: CaloLayerCalculator.h:262
CaloLayerCalculator::CaloLayerCalculator
CaloLayerCalculator()
Initialization.
Definition: CaloLayerCalculator.cxx:23
CaloLayerCalculator::m_etarmax
double m_etarmax
Definition: CaloLayerCalculator.h:270
CaloPhiRange::fix
static double fix(double phi)
Definition: CaloPhiRange.cxx:14
xAOD::CaloCluster_v1::getCellLinks
const CaloClusterCellLink * getCellLinks() const
Get a pointer to the CaloClusterCellLink object (const version)
Definition: CaloCluster_v1.cxx:905
CaloCellContainer.h
CaloCellContainer
Container class for CaloCell.
Definition: CaloCellContainer.h:55
CaloLayerCalculator::m_phirmax
double m_phirmax
Definition: CaloLayerCalculator.h:271
CaloLayerCalculator::m_etam
double m_etam
Layer variables.
Definition: CaloLayerCalculator.h:258
CaloLayerCalculator::m_emax
double m_emax
Definition: CaloLayerCalculator.h:265
CaloDetDescrManager
This class provides the client interface for accessing the detector description information common to...
Definition: CaloDetDescrManager.h:473
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloLayerCalculator
Definition: CaloLayerCalculator.h:82
CaloLayerCalculator::m_phimr
double m_phimr
Definition: CaloLayerCalculator.h:269
beamspotnt.calc
calc
Definition: bin/beamspotnt.py:1252
CaloLayerCalculator::fill
void fill(Iterator beg, Iterator end, double eta, double phi, double deta, double dphi, CaloSampling::CaloSample sampling, xAOD::CaloCluster *tofill=0)
Calculate layer variables from cells in a list.
Definition: CaloLayerCalculator.h:376
CaloPhiRange::diff
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
Definition: CaloPhiRange.cxx:22
CaloLayerCalculator.h
Calculate total energy, position, etc. for a given layer of a cluster.