CMS 3D CMS Logo

interpolateHistoND.h
Go to the documentation of this file.
1 #ifndef NPSTAT_INTERPOLATEHISTOND_HH_
2 #define NPSTAT_INTERPOLATEHISTOND_HH_
3 
25 
26 namespace npstat {
34  template <typename Float, class Axis>
35  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
36  const double* coords,
37  unsigned coordsDim,
38  unsigned interpolationDegree);
40 
44  template <typename Float, class Axis>
45  Float interpolateHistoND(const HistoND<Float, Axis>& histo, double x0, unsigned interpolationDegree);
46 
47  template <typename Float, class Axis>
48  Float interpolateHistoND(const HistoND<Float, Axis>& histo, double x0, double x1, unsigned interpolationDegree);
49 
50  template <typename Float, class Axis>
52  const HistoND<Float, Axis>& histo, double x0, double x1, double x2, unsigned interpolationDegree);
53 
54  template <typename Float, class Axis>
56  const HistoND<Float, Axis>& histo, double x0, double x1, double x2, double x3, unsigned interpolationDegree);
57 
58  template <typename Float, class Axis>
59  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
60  double x0,
61  double x1,
62  double x2,
63  double x3,
64  double x4,
65  unsigned interpolationDegree);
66 
67  template <typename Float, class Axis>
68  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
69  double x0,
70  double x1,
71  double x2,
72  double x3,
73  double x4,
74  double x5,
75  unsigned interpolationDegree);
76 
77  template <typename Float, class Axis>
78  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
79  double x0,
80  double x1,
81  double x2,
82  double x3,
83  double x4,
84  double x5,
85  double x6,
86  unsigned interpolationDegree);
87 
88  template <typename Float, class Axis>
89  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
90  double x0,
91  double x1,
92  double x2,
93  double x3,
94  double x4,
95  double x5,
96  double x6,
97  double x7,
98  unsigned interpolationDegree);
99 
100  template <typename Float, class Axis>
101  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
102  double x0,
103  double x1,
104  double x2,
105  double x3,
106  double x4,
107  double x5,
108  double x6,
109  double x7,
110  double x8,
111  unsigned interpolationDegree);
112 
113  template <typename Float, class Axis>
114  Float interpolateHistoND(const HistoND<Float, Axis>& histo,
115  double x0,
116  double x1,
117  double x2,
118  double x3,
119  double x4,
120  double x5,
121  double x6,
122  double x7,
123  double x8,
124  double x9,
125  unsigned interpolationDegree);
127 } // namespace npstat
128 
129 #include <cassert>
131 
132 namespace npstat {
133  namespace Private {
134  template <typename Float, class Axis>
135  void iHND_checkArgs(const HistoND<Float, Axis>& histo, const unsigned xDim, const unsigned interpolationDegree) {
136  if (xDim != histo.dim())
138  "In npstat::interpolateHistoND: incompatible "
139  "dimensionality of input coordinates");
140  if (xDim == 0U)
142  "In npstat::interpolateHistoND: can not interpolate "
143  "zero-dimensional histograms");
144  if (!(interpolationDegree == 0U || interpolationDegree == 1U || interpolationDegree == 3U))
146  "In npstat::interpolateHistoND: "
147  "unsupported interpolation degree");
148  if (interpolationDegree == 3U && !histo.isUniformlyBinned())
150  "In npstat::interpolateHistoND: unsupported "
151  "interpolation degree for non-uniform binning");
152  }
153  } // namespace Private
154 
155  template <typename Float, class Axis>
157  const double* x,
158  const unsigned xDim,
159  const unsigned interpolationDegree) {
160  Private::iHND_checkArgs(histo, xDim, interpolationDegree);
161  assert(x);
162  const Axis* ax = &histo.axes()[0];
163  double coords[CHAR_BIT * sizeof(unsigned long)];
164  for (unsigned i = 0; i < xDim; ++i)
165  coords[i] = ax[i].fltBinNumber(x[i], false);
166  const ArrayND<Float>& bins(histo.binContents());
167  switch (interpolationDegree) {
168  case 1U:
169  return bins.interpolate1(coords, xDim);
170  case 3U:
171  return bins.interpolate3(coords, xDim);
172  default:
173  return bins.closest(coords, xDim);
174  }
175  }
176 
177  template <typename Float, class Axis>
178  Float interpolateHistoND(const HistoND<Float, Axis>& histo, const double x0, const unsigned interpolationDegree) {
179  const unsigned expDim = 1U;
180  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
181  const double coords = histo.axis(0).fltBinNumber(x0, false);
182  const ArrayND<Float>& bins(histo.binContents());
183  switch (interpolationDegree) {
184  case 1U:
185  return bins.interpolate1(&coords, expDim);
186  case 3U:
187  return bins.interpolate3(&coords, expDim);
188  default:
189  return bins.closest(&coords, expDim);
190  }
191  }
192 
193  template <typename Float, class Axis>
195  const double x0,
196  const double x1,
197  const unsigned interpolationDegree) {
198  const unsigned expDim = 2U;
199  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
200  const Axis* ax = &histo.axes()[0];
201  double coords[expDim];
202  coords[0] = ax[0].fltBinNumber(x0, false);
203  coords[1] = ax[1].fltBinNumber(x1, false);
204  const ArrayND<Float>& bins(histo.binContents());
205  switch (interpolationDegree) {
206  case 1U:
207  return bins.interpolate1(coords, expDim);
208  case 3U:
209  return bins.interpolate3(coords, expDim);
210  default:
211  return bins.closest(coords, expDim);
212  }
213  }
214 
215  template <typename Float, class Axis>
217  const double x0,
218  const double x1,
219  const double x2,
220  const unsigned interpolationDegree) {
221  const unsigned expDim = 3U;
222  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
223  const Axis* ax = &histo.axes()[0];
224  double coords[expDim];
225  coords[0] = ax[0].fltBinNumber(x0, false);
226  coords[1] = ax[1].fltBinNumber(x1, false);
227  coords[2] = ax[2].fltBinNumber(x2, false);
228  const ArrayND<Float>& bins(histo.binContents());
229  switch (interpolationDegree) {
230  case 1U:
231  return bins.interpolate1(coords, expDim);
232  case 3U:
233  return bins.interpolate3(coords, expDim);
234  default:
235  return bins.closest(coords, expDim);
236  }
237  }
238 
239  template <typename Float, class Axis>
241  const double x0,
242  const double x1,
243  const double x2,
244  const double x3,
245  const unsigned interpolationDegree) {
246  const unsigned expDim = 4U;
247  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
248  const Axis* ax = &histo.axes()[0];
249  double coords[expDim];
250  coords[0] = ax[0].fltBinNumber(x0, false);
251  coords[1] = ax[1].fltBinNumber(x1, false);
252  coords[2] = ax[2].fltBinNumber(x2, false);
253  coords[3] = ax[3].fltBinNumber(x3, false);
254  const ArrayND<Float>& bins(histo.binContents());
255  switch (interpolationDegree) {
256  case 1U:
257  return bins.interpolate1(coords, expDim);
258  case 3U:
259  return bins.interpolate3(coords, expDim);
260  default:
261  return bins.closest(coords, expDim);
262  }
263  }
264 
265  template <typename Float, class Axis>
267  const double x0,
268  const double x1,
269  const double x2,
270  const double x3,
271  const double x4,
272  const unsigned interpolationDegree) {
273  const unsigned expDim = 5U;
274  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
275  const Axis* ax = &histo.axes()[0];
276  double coords[expDim];
277  coords[0] = ax[0].fltBinNumber(x0, false);
278  coords[1] = ax[1].fltBinNumber(x1, false);
279  coords[2] = ax[2].fltBinNumber(x2, false);
280  coords[3] = ax[3].fltBinNumber(x3, false);
281  coords[4] = ax[4].fltBinNumber(x4, false);
282  const ArrayND<Float>& bins(histo.binContents());
283  switch (interpolationDegree) {
284  case 1U:
285  return bins.interpolate1(coords, expDim);
286  case 3U:
287  return bins.interpolate3(coords, expDim);
288  default:
289  return bins.closest(coords, expDim);
290  }
291  }
292 
293  template <typename Float, class Axis>
295  const double x0,
296  const double x1,
297  const double x2,
298  const double x3,
299  const double x4,
300  const double x5,
301  const unsigned interpolationDegree) {
302  const unsigned expDim = 6U;
303  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
304  const Axis* ax = &histo.axes()[0];
305  double coords[expDim];
306  coords[0] = ax[0].fltBinNumber(x0, false);
307  coords[1] = ax[1].fltBinNumber(x1, false);
308  coords[2] = ax[2].fltBinNumber(x2, false);
309  coords[3] = ax[3].fltBinNumber(x3, false);
310  coords[4] = ax[4].fltBinNumber(x4, false);
311  coords[5] = ax[5].fltBinNumber(x5, false);
312  const ArrayND<Float>& bins(histo.binContents());
313  switch (interpolationDegree) {
314  case 1U:
315  return bins.interpolate1(coords, expDim);
316  case 3U:
317  return bins.interpolate3(coords, expDim);
318  default:
319  return bins.closest(coords, expDim);
320  }
321  }
322 
323  template <typename Float, class Axis>
325  const double x0,
326  const double x1,
327  const double x2,
328  const double x3,
329  const double x4,
330  const double x5,
331  const double x6,
332  const unsigned interpolationDegree) {
333  const unsigned expDim = 7U;
334  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
335  const Axis* ax = &histo.axes()[0];
336  double coords[expDim];
337  coords[0] = ax[0].fltBinNumber(x0, false);
338  coords[1] = ax[1].fltBinNumber(x1, false);
339  coords[2] = ax[2].fltBinNumber(x2, false);
340  coords[3] = ax[3].fltBinNumber(x3, false);
341  coords[4] = ax[4].fltBinNumber(x4, false);
342  coords[5] = ax[5].fltBinNumber(x5, false);
343  coords[6] = ax[6].fltBinNumber(x6, false);
344  const ArrayND<Float>& bins(histo.binContents());
345  switch (interpolationDegree) {
346  case 1U:
347  return bins.interpolate1(coords, expDim);
348  case 3U:
349  return bins.interpolate3(coords, expDim);
350  default:
351  return bins.closest(coords, expDim);
352  }
353  }
354 
355  template <typename Float, class Axis>
357  const double x0,
358  const double x1,
359  const double x2,
360  const double x3,
361  const double x4,
362  const double x5,
363  const double x6,
364  const double x7,
365  const unsigned interpolationDegree) {
366  const unsigned expDim = 8U;
367  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
368  const Axis* ax = &histo.axes()[0];
369  double coords[expDim];
370  coords[0] = ax[0].fltBinNumber(x0, false);
371  coords[1] = ax[1].fltBinNumber(x1, false);
372  coords[2] = ax[2].fltBinNumber(x2, false);
373  coords[3] = ax[3].fltBinNumber(x3, false);
374  coords[4] = ax[4].fltBinNumber(x4, false);
375  coords[5] = ax[5].fltBinNumber(x5, false);
376  coords[6] = ax[6].fltBinNumber(x6, false);
377  coords[7] = ax[7].fltBinNumber(x7, false);
378  const ArrayND<Float>& bins(histo.binContents());
379  switch (interpolationDegree) {
380  case 1U:
381  return bins.interpolate1(coords, expDim);
382  case 3U:
383  return bins.interpolate3(coords, expDim);
384  default:
385  return bins.closest(coords, expDim);
386  }
387  }
388 
389  template <typename Float, class Axis>
391  const double x0,
392  const double x1,
393  const double x2,
394  const double x3,
395  const double x4,
396  const double x5,
397  const double x6,
398  const double x7,
399  const double x8,
400  const unsigned interpolationDegree) {
401  const unsigned expDim = 9U;
402  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
403  const Axis* ax = &histo.axes()[0];
404  double coords[expDim];
405  coords[0] = ax[0].fltBinNumber(x0, false);
406  coords[1] = ax[1].fltBinNumber(x1, false);
407  coords[2] = ax[2].fltBinNumber(x2, false);
408  coords[3] = ax[3].fltBinNumber(x3, false);
409  coords[4] = ax[4].fltBinNumber(x4, false);
410  coords[5] = ax[5].fltBinNumber(x5, false);
411  coords[6] = ax[6].fltBinNumber(x6, false);
412  coords[7] = ax[7].fltBinNumber(x7, false);
413  coords[8] = ax[8].fltBinNumber(x8, false);
414  const ArrayND<Float>& bins(histo.binContents());
415  switch (interpolationDegree) {
416  case 1U:
417  return bins.interpolate1(coords, expDim);
418  case 3U:
419  return bins.interpolate3(coords, expDim);
420  default:
421  return bins.closest(coords, expDim);
422  }
423  }
424 
425  template <typename Float, class Axis>
427  const double x0,
428  const double x1,
429  const double x2,
430  const double x3,
431  const double x4,
432  const double x5,
433  const double x6,
434  const double x7,
435  const double x8,
436  const double x9,
437  const unsigned interpolationDegree) {
438  const unsigned expDim = 10U;
439  Private::iHND_checkArgs(histo, expDim, interpolationDegree);
440  const Axis* ax = &histo.axes()[0];
441  double coords[expDim];
442  coords[0] = ax[0].fltBinNumber(x0, false);
443  coords[1] = ax[1].fltBinNumber(x1, false);
444  coords[2] = ax[2].fltBinNumber(x2, false);
445  coords[3] = ax[3].fltBinNumber(x3, false);
446  coords[4] = ax[4].fltBinNumber(x4, false);
447  coords[5] = ax[5].fltBinNumber(x5, false);
448  coords[6] = ax[6].fltBinNumber(x6, false);
449  coords[7] = ax[7].fltBinNumber(x7, false);
450  coords[8] = ax[8].fltBinNumber(x8, false);
451  coords[9] = ax[9].fltBinNumber(x9, false);
452  const ArrayND<Float>& bins(histo.binContents());
453  switch (interpolationDegree) {
454  case 1U:
455  return bins.interpolate1(coords, expDim);
456  case 3U:
457  return bins.interpolate3(coords, expDim);
458  default:
459  return bins.closest(coords, expDim);
460  }
461  }
462 } // namespace npstat
463 
464 #endif // NPSTAT_INTERPOLATEHISTOND_HH_
mps_fire.i
i
Definition: mps_fire.py:428
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
cms::cuda::assert
assert(be >=bs)
npstat::Private::iHND_checkArgs
void iHND_checkArgs(const HistoND< Float, Axis > &histo, const unsigned xDim, const unsigned interpolationDegree)
Definition: interpolateHistoND.h:135
npstat
Definition: AbsArrayProjector.h:14
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
npstat::interpolateHistoND
Float interpolateHistoND(const HistoND< Float, Axis > &histo, const double *coords, unsigned coordsDim, unsigned interpolationDegree)
Definition: interpolateHistoND.h:156
hgcal_conditions::positions::HeterogeneousHGCalPositionsType::Float
npstat::ArrayND
Definition: ArrayND.h:48
npstat::HistoND
Definition: HistoAxis.h:23
trigObjTnPSource_cfi.bins
bins
Definition: trigObjTnPSource_cfi.py:20
NpstatException.h
Exceptions for the npstat namespace.
HistoND.h
Arbitrary-dimensional histogram template.