48 const TH2& h, Int_t xbin, Int_t ybin)
const
51 while(xbin < 0 || xbin >=
nBinsX - 1) {
52 if(xbin < 0) xbin = -xbin-1;
55 while(ybin < 0 || ybin >=
nBinsY - 1) {
56 if(ybin < 0) ybin = -ybin-1;
60 return h.GetBinContent(1 + xbin, 1 + ybin);
64 const TH2& h, Int_t xbin, Int_t ybin)
const
66 return 0.5 * (
histcont(h, xbin + 1, ybin) -
71 const TH2& h, Int_t xbin, Int_t ybin)
const
73 return 0.5 * (
histcont(h, xbin, ybin + 1) -
78 const TH2& h, Int_t xbin, Int_t ybin)
const
80 return 0.5 * (
histcont(h, xbin - 1, ybin - 1) -
87 nBinsX(1 + h.GetNbinsX()), nBinsY(1 + h.GetNbinsY()),
88 binSizeX(h.GetXaxis()->GetBinWidth(1)),
89 binSizeY(h.GetYaxis()->GetBinWidth(1)),
90 xmin(h.GetXaxis()->GetBinCenter(1) - binSizeX),
91 xmax(h.GetXaxis()->GetBinCenter(nBinsX - 1) + binSizeX),
92 ymin(h.GetYaxis()->GetBinCenter(1) - binSizeY),
93 ymax(h.GetYaxis()->GetBinCenter(nBinsY - 1) + binSizeY),
94 coeffs(CoeffRecLen * nBinsX * nBinsY)
96 const TAxis* xaxis = h.GetXaxis();
97 const TAxis* yaxis = h.GetYaxis();
99 for (Int_t i = 1; i <
nBinsX; ++i) {
100 if (std::abs(xaxis->GetBinWidth(i) /
binSizeX - 1.) > 1e-9) {
101 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
102 gSystem->Exit(EXIT_FAILURE);
105 for (Int_t i = 1; i <
nBinsY; ++i) {
106 if (std::abs(yaxis->GetBinWidth(i) /
binSizeY - 1.) > 1e-9) {
107 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
108 gSystem->Exit(EXIT_FAILURE);
115 for (Int_t j = -1; j < nBinsY - 1; ++j) {
116 for (Int_t i = -1; i < nBinsX - 1; ++i) {
117 const Double_t rhs[
NCoeff] = {
146 coeff(1 + i, 1 + j, 15) = rhs[0];
147 coeff(1 + i, 1 + j, 14) = rhs[4];
148 coeff(1 + i, 1 + j, 13) =
149 3. * (-rhs[0] + rhs[1]) - 2. * rhs[4] - rhs[5];
150 coeff(1 + i, 1 + j, 12) =
151 2. * (rhs[0] - rhs[1]) + rhs[4] + rhs[5];
153 coeff(1 + i, 1 + j, 11) = rhs[8];
154 coeff(1 + i, 1 + j, 10) = rhs[12];
155 coeff(1 + i, 1 + j, 9) =
156 3. * (-rhs[8] + rhs[9]) - 2. * rhs[12] - rhs[13];
157 coeff(1 + i, 1 + j, 8) =
158 2. * (rhs[8] - rhs[9]) + rhs[12] + rhs[13];
160 coeff(1 + i, 1 + j, 7) =
161 3. * (-rhs[0] + rhs[2]) - 2. * rhs[8] - rhs[10];
162 coeff(1 + i, 1 + j, 6) =
163 3. * (-rhs[4] + rhs[6]) - 2. * rhs[12] - rhs[14];
164 coeff(1 + i, 1 + j, 5) =
165 9. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
166 6. * (rhs[4] - rhs[6] + rhs[8] - rhs[9]) + 4. * rhs[12] +
167 3. * (rhs[5] - rhs[7] + rhs[10] - rhs[11]) +
168 2. * (rhs[13] + rhs[14]) + rhs[15];
169 coeff(1 + i, 1 + j, 4) =
170 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
171 4. * (-rhs[8] + rhs[9]) +
172 3. * (-rhs[4] - rhs[5] + rhs[6] + rhs[7]) +
173 2. * (-rhs[10] + rhs[11] - rhs[12] - rhs[13]) -
176 coeff(1 + i, 1 + j, 3) =
177 2. * (rhs[0] - rhs[2]) + rhs[8] + rhs[10];
178 coeff(1 + i, 1 + j, 2) =
179 2. * (rhs[4] - rhs[6]) + rhs[12] + rhs[14];
180 coeff(1 + i, 1 + j, 1) =
181 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
182 4. * (-rhs[4] + rhs[6]) +
183 3. * (-rhs[8] + rhs[9] - rhs[10] + rhs[11]) +
184 2. * (- rhs[5] + rhs[7] - rhs[12] - rhs[14]) -
186 coeff(1 + i, 1 + j, 0) =
187 4. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
188 2. * (rhs[4] + rhs[5] - rhs[6] - rhs[7] +
189 rhs[8] - rhs[9] + rhs[10] - rhs[11]) +
190 rhs[12] + rhs[13] + rhs[14] + rhs[15];
195 for (Int_t k = 0; k <
NCoeff; ++k)
196 sum +=
coeff(1 + i, 1 + j, k) /
197 Double_t((4 - (k % 4)) * (4 - (k / 4)));
198 coeff(1 + i, 1 + j, NCoeff) = sum;
206 if (x <= xmin || x >=
xmax || y <= ymin || y >=
ymax || x != x || y != y)
217 const Double_t hx = (x - xlo) /
binSizeX;
218 const Double_t hy = (y - ylo) /
binSizeY;
220 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
221 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
223 Double_t retVal = 0.;
224 for (Int_t k = 0; k <
NCoeff; ++k)
225 retVal +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
237 if(y1==y2)
return evalX(x1, x2, y1);
238 if(x1==x2)
return evalY(x1, y1, y2);
239 return evalXY(x1, x2, y1, y2);
245 if (x1 != x1 || x2 != x2 || y != y)
return 0.;
252 const Double_t hy = (y - ylo) /
binSizeY;
254 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
257 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
259 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
260 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
261 if (xhi < x1)
continue;
262 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
263 Double_t(binx) / Double_t(nBinsX) *
xmax;
266 const Double_t a = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
269 const Double_t hxton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
270 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
272 for (Int_t k = 0; k <
NCoeff; ++k)
273 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
283 if (x != x || y1 != y1 || y2 != y2)
return 0.;
285 const Int_t binx = Int_t(Double_t(nBinsX) * (x -
xmin) / (
xmax -
xmin));
287 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
288 Double_t(binx) / Double_t(nBinsX) *
xmax;
290 const Double_t hx = (x - xlo) /
binSizeX;
292 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
295 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
297 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
298 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
299 if (yhi < y1)
continue;
300 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
301 Double_t(biny) / Double_t(nBinsY) *
ymax;
304 const Double_t a = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
307 const Double_t hyton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
308 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
310 for (Int_t k = 0; k <
NCoeff; ++k)
311 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
319 Double_t x1, Double_t x2, Double_t y1, Double_t y2)
const
322 if (x1 != x1 || x2 != x2 || y1 != y1 || y2 != y2)
return 0.;
325 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
327 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
328 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
329 if (yhi < y1)
continue;
330 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
331 Double_t(biny) / Double_t(nBinsY) *
ymax;
334 const Double_t ay = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
336 const Bool_t yFullyContained = std::abs(by - ay - 1.0) < 1e-15;
338 const Double_t hyton[4] = {
339 0.25 * (by * by * by * by - ay * ay * ay * ay),
340 (by * by * by - ay * ay * ay) / 3., 0.5 * (by * by - ay * ay),
342 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
344 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
345 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
346 if (xhi < x1)
continue;
347 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
348 Double_t(binx) / Double_t(nBinsX) *
xmax;
351 const Double_t ax = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
353 const Bool_t xFullyContained = std::abs(bx - ax - 1.0) < 1e-15;
354 if (xFullyContained && yFullyContained) {
360 const Double_t hxton[4] = {
361 0.25 * (bx * bx * bx * bx - ax * ax * ax * ax),
362 (bx * bx * bx - ax * ax * ax) / 3., 0.5 * (bx * bx - ax * ax),
367 for (Int_t k = 0; k <
NCoeff; ++k)
368 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.
Class for defining a 2D cubic spline based on an input 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.
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.