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