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 TAxis *xaxis = h.GetXaxis(), *yaxis = h.GetYaxis();
81 for (Int_t i = 1; i <
nBinsX; ++i) {
82 if (std::abs(xaxis->GetBinWidth(i) /
binSizeX - 1.) > 1e-9) {
83 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
84 gSystem->Exit(EXIT_FAILURE);
87 for (Int_t i = 1; i <
nBinsY; ++i) {
88 if (std::abs(yaxis->GetBinWidth(i) /
binSizeY - 1.) > 1e-9) {
89 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
90 gSystem->Exit(EXIT_FAILURE);
97 for (Int_t j = -1; j < nBinsY - 1; ++j) {
98 for (Int_t i = -1; i < nBinsX - 1; ++i) {
99 const Double_t rhs[
NCoeff] = {
128 coeff(1 + i, 1 + j, 15) = rhs[0];
129 coeff(1 + i, 1 + j, 14) = rhs[4];
130 coeff(1 + i, 1 + j, 13) =
131 3. * (-rhs[0] + rhs[1]) - 2. * rhs[4] - rhs[5];
132 coeff(1 + i, 1 + j, 12) =
133 2. * (rhs[0] - rhs[1]) + rhs[4] + rhs[5];
135 coeff(1 + i, 1 + j, 11) = rhs[8];
136 coeff(1 + i, 1 + j, 10) = rhs[12];
137 coeff(1 + i, 1 + j, 9) =
138 3. * (-rhs[8] + rhs[9]) - 2. * rhs[12] - rhs[13];
139 coeff(1 + i, 1 + j, 8) =
140 2. * (rhs[8] - rhs[9]) + rhs[12] + rhs[13];
142 coeff(1 + i, 1 + j, 7) =
143 3. * (-rhs[0] + rhs[2]) - 2. * rhs[8] - rhs[10];
144 coeff(1 + i, 1 + j, 6) =
145 3. * (-rhs[4] + rhs[6]) - 2. * rhs[12] - rhs[14];
146 coeff(1 + i, 1 + j, 5) =
147 9. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
148 6. * (rhs[4] - rhs[6] + rhs[8] - rhs[9]) + 4. * rhs[12] +
149 3. * (rhs[5] - rhs[7] + rhs[10] - rhs[11]) +
150 2. * (rhs[13] + rhs[14]) + rhs[15];
151 coeff(1 + i, 1 + j, 4) =
152 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
153 4. * (-rhs[8] + rhs[9]) +
154 3. * (-rhs[4] - rhs[5] + rhs[6] + rhs[7]) +
155 2. * (-rhs[10] + rhs[11] - rhs[12] - rhs[13]) -
158 coeff(1 + i, 1 + j, 3) =
159 2. * (rhs[0] - rhs[2]) + rhs[8] + rhs[10];
160 coeff(1 + i, 1 + j, 2) =
161 2. * (rhs[4] - rhs[6]) + rhs[12] + rhs[14];
162 coeff(1 + i, 1 + j, 1) =
163 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
164 4. * (-rhs[4] + rhs[6]) +
165 3. * (-rhs[8] + rhs[9] - rhs[10] + rhs[11]) +
166 2. * (- rhs[5] + rhs[7] - rhs[12] - rhs[14]) -
168 coeff(1 + i, 1 + j, 0) =
169 4. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
170 2. * (rhs[4] + rhs[5] - rhs[6] - rhs[7] +
171 rhs[8] - rhs[9] + rhs[10] - rhs[11]) +
172 rhs[12] + rhs[13] + rhs[14] + rhs[15];
177 for (Int_t k = 0; k <
NCoeff; ++k)
178 sum +=
coeff(1 + i, 1 + j, k) /
179 Double_t((4 - (k % 4)) * (4 - (k / 4)));
180 coeff(1 + i, 1 + j, NCoeff) = sum;
188 if (x <= xmin || x >=
xmax || y <= ymin || y >=
ymax || x != x || y != y)
199 const Double_t hx = (x - xlo) /
binSizeX;
200 const Double_t hy = (y - ylo) /
binSizeY;
202 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
203 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
205 Double_t retVal = 0.;
206 for (Int_t k = 0; k <
NCoeff; ++k)
207 retVal +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
219 if(y1==y2)
return evalX(x1, x2, y1);
220 if(x1==x2)
return evalY(x1, y1, y2);
221 return evalXY(x1, x2, y1, y2);
227 if (x1 != x1 || x2 != x2 || y != y)
return 0.;
234 const Double_t hy = (y - ylo) /
binSizeY;
236 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
239 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
241 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
242 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
243 if (xhi < x1)
continue;
244 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
245 Double_t(binx) / Double_t(nBinsX) *
xmax;
248 const Double_t a = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
251 const Double_t hxton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
252 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
254 for (Int_t k = 0; k <
NCoeff; ++k)
255 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
265 if (x != x || y1 != y1 || y2 != y2)
return 0.;
267 const Int_t binx = Int_t(Double_t(nBinsX) * (x -
xmin) / (
xmax -
xmin));
269 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
270 Double_t(binx) / Double_t(nBinsX) *
xmax;
272 const Double_t hx = (x - xlo) /
binSizeX;
274 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
277 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
279 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
280 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
281 if (yhi < y1)
continue;
282 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
283 Double_t(biny) / Double_t(nBinsY) *
ymax;
286 const Double_t a = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
289 const Double_t hyton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
290 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
292 for (Int_t k = 0; k <
NCoeff; ++k)
293 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
301 Double_t x1, Double_t x2, Double_t y1, Double_t y2)
const
304 if (x1 != x1 || x2 != x2 || y1 != y1 || y2 != y2)
return 0.;
307 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
309 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
310 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
311 if (yhi < y1)
continue;
312 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
313 Double_t(biny) / Double_t(nBinsY) *
ymax;
316 const Double_t ay = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
318 const Bool_t yFullyContained = std::abs(by - ay - 1.0) < 1e-15;
320 const Double_t hyton[4] = {
321 0.25 * (by * by * by * by - ay * ay * ay * ay),
322 (by * by * by - ay * ay * ay) / 3., 0.5 * (by * by - ay * ay),
324 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
326 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
327 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
328 if (xhi < x1)
continue;
329 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
330 Double_t(binx) / Double_t(nBinsX) *
xmax;
333 const Double_t ax = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
335 const Bool_t xFullyContained = std::abs(bx - ax - 1.0) < 1e-15;
336 if (xFullyContained && yFullyContained) {
342 const Double_t hxton[4] = {
343 0.25 * (bx * bx * bx * bx - ax * ax * ax * ax),
344 (bx * bx * bx - ax * ax * ax) / 3., 0.5 * (bx * bx - ax * ax),
349 for (Int_t k = 0; k <
NCoeff; ++k)
350 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.