ATLAS Offline Software
Classes | Functions
CaloClusterCorr Namespace Reference

Classes

class  CaloSwCalibHitsShowerDepth
 Helper to calculate the shower depth as used in the calib hits SW cluster correction. More...
 
class  DDHelper
 
struct  et_compare_larem_only
 Helper to compare two cells by Et. More...
 
class  SamplingHelper
 Sampling calculator helper class. More...
 
class  SamplingHelper_CaloCellList
 Version of helper class for cells taken from StoreGate. More...
 
class  SamplingHelper_Cluster
 Version of helper class for cells taken from the cluster itself. More...
 
class  Segmentation
 

Functions

float interpolate (const CaloRec::Array< 2 > &a, float x, unsigned int degree, unsigned int ycol=1, const CaloRec::Array< 1 > &regions=CaloRec::Array< 1 >(), int n_points=-1, bool fixZero=false)
 Polynomial interpolation in a table. More...
 
void etaphi_range (const CaloDetDescrManager &dd_man, double eta, double phi, CaloCell_ID::CaloSample sampling, double &deta, double &dphi)
 Return eta/phi ranges encompassing +- 1 cell. More...
 

Function Documentation

◆ etaphi_range()

void CaloClusterCorr::etaphi_range ( const CaloDetDescrManager dd_man,
double  eta,
double  phi,
CaloCell_ID::CaloSample  sampling,
double &  deta,
double &  dphi 
)

Return eta/phi ranges encompassing +- 1 cell.

Parameters
etaCentral eta value.
phiCentral phi value.
samplingThe sampling to use.
[out]detaRange in eta.
[out]dphiRange in phi.

This can be a little tricky due to misalignments and the fact that cells have different sizes in different regions. Also, CaloLayerCalculator takes only a symmetric eta range. We try to find the neighboring cells by starting from the center cell and looking a little bit more than half its width in either direction, and finding the centers of those cells. Then we use the larger of these for the symmetric range.

Definition at line 64 of file CaloFillRectangularCluster.cxx.

70 {
71  deta = 0;
72  dphi = 0;
73 
74  // Get the DD element for the central cell.
75  const CaloDetDescrElement* elt = dd_man.get_element_raw (sampling, eta, phi);
76  if (!elt) return;
77 
78  // Should be smaller than the eta half-width of any cell.
79  const double eps = 0.001;
80 
81  // Now look in the negative eta direction.
82  const CaloDetDescrElement* elt_l = dd_man.get_element_raw
83  (sampling,
84  eta - elt->deta() - eps,
85  phi);
86  double deta_l = 0; // Eta difference on the low (left) side.
87  if (elt_l)
88  deta_l = std::abs (eta - elt_l->eta_raw()) + eps;
89 
90  // Now look in the positive eta direction.
91  const CaloDetDescrElement* elt_r = dd_man.get_element_raw
92  (sampling,
93  eta + elt->deta() + eps,
94  phi);
95  double deta_r = 0; // Eta difference on the high (right) side.
96  if (elt_r)
97  deta_r = std::abs (eta - elt_r->eta_raw()) + eps;
98 
99  // Total deta is twice the maximum.
100  deta = 2 * std::max (deta_r, deta_l);
101 
102  // Now for the phi variation.
103  // The phi size can change as a function of eta, but not of phi.
104  // Thus we have to look again at the adjacent eta cells, and
105  // take the largest variation.
106 
107  // Now look in the negative eta direction.
108  elt_l = dd_man.get_element_raw
109  (sampling,
110  eta - elt->deta() - eps,
111  CaloPhiRange::fix (phi - elt->dphi() - eps));
112  double dphi_l = 0; // Phi difference on the low-eta () side.
113  if (elt_l)
114  dphi_l = std::abs (CaloPhiRange::fix (phi - elt_l->phi_raw())) + eps;
115 
116  // Now look in the positive eta direction.
117  elt_r = dd_man.get_element_raw
118  (sampling,
119  eta + elt->deta() + eps,
120  CaloPhiRange::fix (phi - elt->dphi() - eps));
121  double dphi_r = 0; // Phi difference on the positive (down) side.
122  if (elt_r)
123  dphi_r = std::abs (CaloPhiRange::fix (phi - elt_r->phi_raw())) + eps;
124 
125  // Total dphi is twice the maximum.
126  dphi = 2 * std::max (dphi_l, dphi_r);
127 }

◆ interpolate()

float CaloClusterCorr::interpolate ( const CaloRec::Array< 2 > &  a,
float  x,
unsigned int  degree,
unsigned int  ycol = 1,
const CaloRec::Array< 1 > &  regions = CaloRec::Array<1>(),
int  n_points = -1,
bool  fixZero = false 
)

Polynomial interpolation in a table.

Parameters
aInterpolation table. The x values are in the first column (column 0), and by default, the y values are in the second column (column 1). The x values must be in ascending order, with no duplicates.
xThe value to interpolate.
degreeThe degree of the interpolating polynomial.
ycolThe column number of the y values. (0-based.)
regionsSometimes, you want to divide the range being interpolated into several distinct regions, where the interpolated function may be discontinuous at the boundaries between regions. To do this, supply this argument, which should contain a list (in ascending order) of the x-coordinates of the region boundaries. When the interpolation runs against a boundary, the algorithm will add a copy of the last point before the boundary, positioned at the boundary. This helps to control runaway extrapolation leading up to the boundary.
n_pointsThe number of interpolation points in the table to use. If -1, then the entire table is used.
fixZeroIf true, remove zeros among y-values by averaging adjacent points.
Returns
The interpolated value.

The method used is Newtonian interpolation. Based on the cernlib routine divdif.

Parameters
aInterpolation table. The x values are in the first column (column 0), and by default, the y values are in the second column (column 1).
xThe value to interpolate.
degreeThe degree of the interpolating polynomial.
ycolThe column number of the y values. (0-based.)
regionsSometimes, you want to divide the range being interpolated into several distinct regions, where the interpolated function may be discontinuous at the boundaries between regions. To do this, supply this argument, which should contain a list (in ascending order) of the x-coordinates of the region boundaries. When the interpolation runs against a boundary, the algorithm will add a copy of the last point before the boundary, positioned at the boundary. This helps to control runaway extrapolation leading up to the boundary.
n_pointsThe number of interpolation points in the table to use. If -1, then the entire table is used.
fixZeroIf true, remove zeros among y-values by averaging adjacent points.
Returns
The interpolated value.

The method used is Newtonian interpolation. Based on the cernlib routine divdif.

Definition at line 75 of file interpolate.cxx.

82 {
83  const int xcol = 0;
84 
85  // Check arguments.
86  if (n_points < 0)
87  n_points = static_cast<int> (a.size());
88  if (n_points < 2 || degree < 1) {
89  std::abort();
90  }
91  degree = std::min (degree, static_cast<unsigned int> (n_points) - 1);
92 
93  // Find subscripts of the input value in the input arrays.
94  unsigned int ix = std::lower_bound (a.begin(), a.begin()+n_points, x,
95  xcompare()) -
96  a.begin();
97  unsigned int ir = std::lower_bound (regions.begin(), regions.end(), x) -
98  regions.begin();
99 
100  // Number of points to try for.
101  // Either degree+1 or degree+2, whichever is even,
102  // to give the same number of points on each side.
103  // If we run up against an edge or a boundary, we'll
104  // fall back to using just degree+1 points (or fewer if we can't
105  // even get that many).
106  // If we end up using degree+2 points, we'll do two interpolations
107  // of degree degree and average them.
108  unsigned int npts = degree + 2 - (degree%2);
109 
110  // If we run up against the edge of a region boundary,
111  // we'll want to add a pseudopoint right at the boundary
112  // (copying the point closest to the boundary) instead of the
113  // point farthest away from it.
114  bool extralo = false;
115  bool extrahi = false;
116 
117  // Starting point index, not considering edges or boundaries.
118  int ilo = ix - npts/2;
119 
120  // Make sure this point is within the array range and has not
121  // crossed a region boundary.
122  if (ilo < 0) {
123  ilo = 0;
124  npts = degree+1;
125  }
126  while (ilo < n_points &&
127  ir > 0 && a[ilo][xcol] < regions[ir-1])
128  {
129  ++ilo;
130  npts = degree+1;
131  extralo = true;
132  }
133 
134  // Same deal for the right hand edge.
135  // ihi is one past the last point to use.
136  bool himoved = false;
137  int ihi = ilo + npts;
138  if (ihi > n_points) {
139  ihi = n_points;
140  npts = degree+1;
141  himoved = true;
142  }
143  while (ihi > 0 && ir < regions.size() && a[ihi-1][xcol] >= regions[ir]) {
144  --ihi;
145  npts = degree+1;
146  himoved = true;
147  extrahi = true;
148  }
149 
150  // The adjustment due to ihi may have moved the low point of the range
151  // back over a boundary. If so, we lose points from the fit.
152  bool lomoved = false;
153  ilo = ihi - npts;
154  if (ilo < 0) {
155  ilo = 0;
156  lomoved = true;
157  }
158  while (ilo < n_points &&
159  ir > 0 && a[ilo][xcol] < regions[ir-1])
160  {
161  ++ilo;
162  extralo = true;
163  lomoved = true;
164  }
165 
166  // Copy the points we're going to use to arrays t and d.
167  // t gets the x coordinates, d gets the y coordinates.
168  // Note that the order doesn't matter.
169  // Reserve two extra points in case we end up adding some.
170  npts = ihi - ilo;
171  std::vector<float> t;
172  t.reserve (npts+2);
173  std::vector<float> d;
174  d.reserve (npts+2);
175 
176  // Add the pseudopoints, if needed, removing a point from the other end.
177  // Be careful not to duplicate a point if there's already one
178  // right at the boundary.
179  if (extralo && is_different (a[ilo][xcol], regions[ir-1])) {
180  if (!himoved)
181  --ihi;
182  else
183  ++npts;
184  t.push_back (regions[ir-1]);
185  d.push_back (a[ilo][ycol]);
186  }
187  if (extrahi && is_different (a[ihi-1][xcol], regions[ir])) {
188  if (!lomoved)
189  ++ilo;
190  else
191  ++npts;
192  t.push_back (regions[ir]);
193  d.push_back (a[ihi-1][ycol]);
194  }
195 
196  // Add the rest if the points.
197  for (; ilo < ihi; ++ilo) {
198  t.push_back (a[ilo][xcol]);
199  d.push_back (a[ilo][ycol]);
200  }
201 
202  // Now figure out the interpolation degree we're really going to use.
203  assert (t.size() == npts);
204  assert (d.size() == npts);
205  degree = std::min (degree, npts-1);
206 
207  // Option to remove zeros in the interpolation table, by averaging
208  // adjacent points. Used to handle a couple bad points in the rfac-v5
209  // table.
210  if (fixZero) {
211  for (size_t i = 1; i < npts-1; i++) {
212  if (d[i] == 0) {
213  d[i] = (d[i-1] + d[i+1])/2;
214  }
215  }
216  }
217 
218  // True if we're averaging together two interpolations
219  // (to get a symmetric range).
220  bool extra = npts != degree+1;
221 
222  // If we're averaging two interpolations, we need to be sure the
223  // two extreme points are at the end of the table.
224  // (If extra is true, extrahi and extralo must be false.)
225  if (extra) {
226  std::swap (t[0], t[npts-2]);
227  std::swap (d[0], d[npts-2]);
228  }
229 
230  // Here we start the actual interpolation.
231  // Replace d by the leading diagonal of a divided-difference table,
232  // supplemented by an extra line if extra is true.
233  for (unsigned int l=0; l<degree; l++) {
234  if (extra)
235  d[degree+1] = (d[degree+1]-d[degree-1])/(t[degree+1]-t[degree-1-l]);
236  for (unsigned int i = degree; i > l; --i)
237  d[i] = (d[i]-d[i-1])/(t[i]-t[i-1-l]);
238  }
239 
240  // Evaluate the Newton interpolation formula at x, averaging
241  // two values of the last difference if extra is true.
242  float sum = d[degree];
243  if (extra)
244  sum = 0.5*(sum+d[degree+1]);
245  for (int j = degree-1; j >= 0; --j)
246  sum = d[j] + (x - t[j]) * sum;
247 
248  return sum;
249 }
CaloDetDescrElement::deta
float deta() const
cell deta
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:356
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
hist_file_dump.d
d
Definition: hist_file_dump.py:142
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CxxUtils::Array::size
unsigned int size(unsigned int dim=0) const
Return the size of the array along one dimension.
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:157
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
x
#define x
CaloDetDescrElement::eta_raw
float eta_raw() const
cell eta_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:350
CxxUtils::Array::end
const_iterator end() const
Return an iterator pointing past the end of the container.
CalibDbCompareRT.n_points
n_points
Definition: CalibDbCompareRT.py:75
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
lumiFormat.i
int i
Definition: lumiFormat.py:85
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
CaloPhiRange::fix
static double fix(double phi)
Definition: CaloPhiRange.cxx:14
python.handimod.extra
int extra
Definition: handimod.py:521
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
CaloDetDescrElement::dphi
float dphi() const
cell dphi
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:358
a
TList * a
Definition: liststreamerinfos.cxx:10
CxxUtils::Array::begin
const_iterator begin() const
Return an iterator pointing at the beginning of the container.
CaloDetDescrManager_Base::get_element_raw
const CaloDetDescrElement * get_element_raw(CaloCell_ID::CaloSample sample, double eta, double phi) const
Get element from raw quantities (to build real fixed size clusters)
Definition: CaloDetDescrManager.cxx:349
python.SystemOfUnits.degree
tuple degree
Definition: SystemOfUnits.py:121
CaloDetDescrElement::phi_raw
float phi_raw() const
cell phi_raw
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:352