31 const TH2& h, Int_t xbin, Int_t ybin)
const
34 while(xbin < 0 || xbin >=
nBinsX - 1) {
35 if(xbin < 0) xbin = -xbin-1;
38 while(ybin < 0 || ybin >=
nBinsY - 1) {
39 if(ybin < 0) ybin = -ybin-1;
43 return h.GetBinContent(1 + xbin, 1 + ybin);
47 const TH2& h, Int_t xbin, Int_t ybin)
const
49 return 0.5 * (
histcont(h, xbin + 1, ybin) -
54 const TH2& h, Int_t xbin, Int_t ybin)
const
56 return 0.5 * (
histcont(h, xbin, ybin + 1) -
61 const TH2& h, Int_t xbin, Int_t ybin)
const
63 return 0.5 * (
histcont(h, xbin - 1, ybin - 1) -
70 nBinsX(1 + h.GetNbinsX()), nBinsY(1 + h.GetNbinsY()),
71 binSizeX(h.GetXaxis()->GetBinWidth(1)),
72 binSizeY(h.GetYaxis()->GetBinWidth(1)),
73 xmin(h.GetXaxis()->GetBinCenter(1) - binSizeX),
74 xmax(h.GetXaxis()->GetBinCenter(nBinsX - 1) + binSizeX),
75 ymin(h.GetYaxis()->GetBinCenter(1) - binSizeY),
76 ymax(h.GetYaxis()->GetBinCenter(nBinsY - 1) + binSizeY),
77 coeffs(CoeffRecLen * nBinsX * nBinsY)
79 const TAxis* xaxis = h.GetXaxis();
80 const TAxis* yaxis = h.GetYaxis();
82 for (Int_t i = 1; i <
nBinsX; ++i) {
83 if (std::abs(xaxis->GetBinWidth(i) /
binSizeX - 1.) > 1e-9) {
84 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
85 gSystem->Exit(EXIT_FAILURE);
88 for (Int_t i = 1; i <
nBinsY; ++i) {
89 if (std::abs(yaxis->GetBinWidth(i) /
binSizeY - 1.) > 1e-9) {
90 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
91 gSystem->Exit(EXIT_FAILURE);
98 for (Int_t j = -1; j < nBinsY - 1; ++j) {
99 for (Int_t i = -1; i < nBinsX - 1; ++i) {
100 const Double_t rhs[
NCoeff] = {
129 coeff(1 + i, 1 + j, 15) = rhs[0];
130 coeff(1 + i, 1 + j, 14) = rhs[4];
131 coeff(1 + i, 1 + j, 13) =
132 3. * (-rhs[0] + rhs[1]) - 2. * rhs[4] - rhs[5];
133 coeff(1 + i, 1 + j, 12) =
134 2. * (rhs[0] - rhs[1]) + rhs[4] + rhs[5];
136 coeff(1 + i, 1 + j, 11) = rhs[8];
137 coeff(1 + i, 1 + j, 10) = rhs[12];
138 coeff(1 + i, 1 + j, 9) =
139 3. * (-rhs[8] + rhs[9]) - 2. * rhs[12] - rhs[13];
140 coeff(1 + i, 1 + j, 8) =
141 2. * (rhs[8] - rhs[9]) + rhs[12] + rhs[13];
143 coeff(1 + i, 1 + j, 7) =
144 3. * (-rhs[0] + rhs[2]) - 2. * rhs[8] - rhs[10];
145 coeff(1 + i, 1 + j, 6) =
146 3. * (-rhs[4] + rhs[6]) - 2. * rhs[12] - rhs[14];
147 coeff(1 + i, 1 + j, 5) =
148 9. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
149 6. * (rhs[4] - rhs[6] + rhs[8] - rhs[9]) + 4. * rhs[12] +
150 3. * (rhs[5] - rhs[7] + rhs[10] - rhs[11]) +
151 2. * (rhs[13] + rhs[14]) + rhs[15];
152 coeff(1 + i, 1 + j, 4) =
153 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
154 4. * (-rhs[8] + rhs[9]) +
155 3. * (-rhs[4] - rhs[5] + rhs[6] + rhs[7]) +
156 2. * (-rhs[10] + rhs[11] - rhs[12] - rhs[13]) -
159 coeff(1 + i, 1 + j, 3) =
160 2. * (rhs[0] - rhs[2]) + rhs[8] + rhs[10];
161 coeff(1 + i, 1 + j, 2) =
162 2. * (rhs[4] - rhs[6]) + rhs[12] + rhs[14];
163 coeff(1 + i, 1 + j, 1) =
164 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
165 4. * (-rhs[4] + rhs[6]) +
166 3. * (-rhs[8] + rhs[9] - rhs[10] + rhs[11]) +
167 2. * (- rhs[5] + rhs[7] - rhs[12] - rhs[14]) -
169 coeff(1 + i, 1 + j, 0) =
170 4. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
171 2. * (rhs[4] + rhs[5] - rhs[6] - rhs[7] +
172 rhs[8] - rhs[9] + rhs[10] - rhs[11]) +
173 rhs[12] + rhs[13] + rhs[14] + rhs[15];
178 for (Int_t k = 0; k <
NCoeff; ++k)
179 sum +=
coeff(1 + i, 1 + j, k) /
180 Double_t((4 - (k % 4)) * (4 - (k / 4)));
181 coeff(1 + i, 1 + j, NCoeff) = sum;
189 if (x <= xmin || x >=
xmax || y <= ymin || y >=
ymax || x != x || y != y)
200 const Double_t hx = (x - xlo) /
binSizeX;
201 const Double_t hy = (y - ylo) /
binSizeY;
203 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
204 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
206 Double_t retVal = 0.;
207 for (Int_t k = 0; k <
NCoeff; ++k)
208 retVal +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
220 if(y1==y2)
return evalX(x1, x2, y1);
221 if(x1==x2)
return evalY(x1, y1, y2);
222 return evalXY(x1, x2, y1, y2);
228 if (x1 != x1 || x2 != x2 || y != y)
return 0.;
235 const Double_t hy = (y - ylo) /
binSizeY;
237 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
240 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
242 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
243 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
244 if (xhi < x1)
continue;
245 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
246 Double_t(binx) / Double_t(nBinsX) *
xmax;
249 const Double_t a = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
252 const Double_t hxton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
253 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
255 for (Int_t k = 0; k <
NCoeff; ++k)
256 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
266 if (x != x || y1 != y1 || y2 != y2)
return 0.;
268 const Int_t binx = Int_t(Double_t(nBinsX) * (x -
xmin) / (
xmax -
xmin));
270 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
271 Double_t(binx) / Double_t(nBinsX) *
xmax;
273 const Double_t hx = (x - xlo) /
binSizeX;
275 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
278 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
280 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
281 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
282 if (yhi < y1)
continue;
283 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
284 Double_t(biny) / Double_t(nBinsY) *
ymax;
287 const Double_t a = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
290 const Double_t hyton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
291 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
293 for (Int_t k = 0; k <
NCoeff; ++k)
294 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
302 Double_t x1, Double_t x2, Double_t y1, Double_t y2)
const
305 if (x1 != x1 || x2 != x2 || y1 != y1 || y2 != y2)
return 0.;
308 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
310 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
311 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
312 if (yhi < y1)
continue;
313 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
314 Double_t(biny) / Double_t(nBinsY) *
ymax;
317 const Double_t ay = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
319 const Bool_t yFullyContained = std::abs(by - ay - 1.0) < 1e-15;
321 const Double_t hyton[4] = {
322 0.25 * (by * by * by * by - ay * ay * ay * ay),
323 (by * by * by - ay * ay * ay) / 3., 0.5 * (by * by - ay * ay),
325 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
327 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
328 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
329 if (xhi < x1)
continue;
330 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
331 Double_t(binx) / Double_t(nBinsX) *
xmax;
334 const Double_t ax = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
336 const Bool_t xFullyContained = std::abs(bx - ax - 1.0) < 1e-15;
337 if (xFullyContained && yFullyContained) {
343 const Double_t hxton[4] = {
344 0.25 * (bx * bx * bx * bx - ax * ax * ax * ax),
345 (bx * bx * bx - ax * ax * ax) / 3., 0.5 * (bx * bx - ax * ax),
350 for (Int_t k = 0; k <
NCoeff; ++k)
351 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
Double_t dhistdx(const TH2 &h, Int_t xbin, Int_t ybin) const
Get d/dx finite difference in a given bin from a histogram.
Double_t histcont(const TH2 &h, Int_t xbin, Int_t ybin) const
Get contents of a given bin from a histogram.
Double_t xmax
Maximum x value.
virtual Double_t analyticalIntegral() const
Evaluate analytical integral across the whole function.
Double_t d2histdxdy(const TH2 &h, Int_t xbin, Int_t ybin) const
Get d^2/dydx finite difference in a given bin from a histogram.
Int_t nBinsX
Number of bins in x axis.
Double_t evalX(Double_t x1, Double_t x2, Double_t y) const
Evaluate integral over x at a given y from (x1, y) to (x2, y)
Int_t nBinsY
Number of bins in y axis.
virtual Double_t evaluate(Double_t x, Double_t y) const
Evaluate the function at given point.
Double_t xmin
Minimum x value.
Lau2DCubicSpline(const TH2 &h)
Constructor from histogram.
Double_t binSizeX
Bin size in x.
virtual ~Lau2DCubicSpline()
Destructor.
Double_t evalXY(Double_t x1, Double_t x2, Double_t y1, Double_t y2) const
Evaluate integral over x and y from (x1, y1) to (x2, y2)
Double_t ymax
Maximum y value.
Double_t dhistdy(const TH2 &h, Int_t xbin, Int_t ybin) const
Get d/dy finite difference in a given bin from a histogram.
Double_t ymin
Minimum y value.
Double_t binSizeY
Bin size in y.
File containing declaration of Lau2DCubicSpline class.
Double_t evalY(Double_t x, Double_t y1, Double_t y2) const
Evaluate integral over y at a given x from (x, y1) to (x, y2)
const Double_t & coeff(Int_t binx, Int_t biny, Int_t theCoeff) const
Const access to coefficients.