CMS 3D CMS Logo

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