45 const TH2& h, Int_t xbin, Int_t ybin)
const
48 while(xbin < 0 || xbin >=
nBinsX - 1) {
49 if(xbin < 0) xbin = -xbin-1;
52 while(ybin < 0 || ybin >=
nBinsY - 1) {
53 if(ybin < 0) ybin = -ybin-1;
57 return h.GetBinContent(1 + xbin, 1 + ybin);
61 const TH2& h, Int_t xbin, Int_t ybin)
const
63 return 0.5 * (
histcont(h, xbin + 1, ybin) -
68 const TH2& h, Int_t xbin, Int_t ybin)
const
70 return 0.5 * (
histcont(h, xbin, ybin + 1) -
75 const TH2& h, Int_t xbin, Int_t ybin)
const
77 return 0.5 * (
histcont(h, xbin - 1, ybin - 1) -
84 nBinsX(1 + h.GetNbinsX()), nBinsY(1 + h.GetNbinsY()),
85 binSizeX(h.GetXaxis()->GetBinWidth(1)),
86 binSizeY(h.GetYaxis()->GetBinWidth(1)),
87 xmin(h.GetXaxis()->GetBinCenter(1) - binSizeX),
88 xmax(h.GetXaxis()->GetBinCenter(nBinsX - 1) + binSizeX),
89 ymin(h.GetYaxis()->GetBinCenter(1) - binSizeY),
90 ymax(h.GetYaxis()->GetBinCenter(nBinsY - 1) + binSizeY),
91 coeffs(CoeffRecLen * nBinsX * nBinsY)
93 const TAxis* xaxis = h.GetXaxis();
94 const TAxis* yaxis = h.GetYaxis();
96 for (Int_t i = 1; i <
nBinsX; ++i) {
97 if (std::abs(xaxis->GetBinWidth(i) /
binSizeX - 1.) > 1e-9) {
98 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
99 gSystem->Exit(EXIT_FAILURE);
102 for (Int_t i = 1; i <
nBinsY; ++i) {
103 if (std::abs(yaxis->GetBinWidth(i) /
binSizeY - 1.) > 1e-9) {
104 std::cerr <<
"ERROR in Lau2DCubicSpline constructor : the histogram has variable bin sizes." << std::endl;
105 gSystem->Exit(EXIT_FAILURE);
112 for (Int_t j = -1; j < nBinsY - 1; ++j) {
113 for (Int_t i = -1; i < nBinsX - 1; ++i) {
114 const Double_t rhs[
NCoeff] = {
143 coeff(1 + i, 1 + j, 15) = rhs[0];
144 coeff(1 + i, 1 + j, 14) = rhs[4];
145 coeff(1 + i, 1 + j, 13) =
146 3. * (-rhs[0] + rhs[1]) - 2. * rhs[4] - rhs[5];
147 coeff(1 + i, 1 + j, 12) =
148 2. * (rhs[0] - rhs[1]) + rhs[4] + rhs[5];
150 coeff(1 + i, 1 + j, 11) = rhs[8];
151 coeff(1 + i, 1 + j, 10) = rhs[12];
152 coeff(1 + i, 1 + j, 9) =
153 3. * (-rhs[8] + rhs[9]) - 2. * rhs[12] - rhs[13];
154 coeff(1 + i, 1 + j, 8) =
155 2. * (rhs[8] - rhs[9]) + rhs[12] + rhs[13];
157 coeff(1 + i, 1 + j, 7) =
158 3. * (-rhs[0] + rhs[2]) - 2. * rhs[8] - rhs[10];
159 coeff(1 + i, 1 + j, 6) =
160 3. * (-rhs[4] + rhs[6]) - 2. * rhs[12] - rhs[14];
161 coeff(1 + i, 1 + j, 5) =
162 9. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
163 6. * (rhs[4] - rhs[6] + rhs[8] - rhs[9]) + 4. * rhs[12] +
164 3. * (rhs[5] - rhs[7] + rhs[10] - rhs[11]) +
165 2. * (rhs[13] + rhs[14]) + rhs[15];
166 coeff(1 + i, 1 + j, 4) =
167 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
168 4. * (-rhs[8] + rhs[9]) +
169 3. * (-rhs[4] - rhs[5] + rhs[6] + rhs[7]) +
170 2. * (-rhs[10] + rhs[11] - rhs[12] - rhs[13]) -
173 coeff(1 + i, 1 + j, 3) =
174 2. * (rhs[0] - rhs[2]) + rhs[8] + rhs[10];
175 coeff(1 + i, 1 + j, 2) =
176 2. * (rhs[4] - rhs[6]) + rhs[12] + rhs[14];
177 coeff(1 + i, 1 + j, 1) =
178 6. * (-rhs[0] + rhs[1] + rhs[2] - rhs[3]) +
179 4. * (-rhs[4] + rhs[6]) +
180 3. * (-rhs[8] + rhs[9] - rhs[10] + rhs[11]) +
181 2. * (- rhs[5] + rhs[7] - rhs[12] - rhs[14]) -
183 coeff(1 + i, 1 + j, 0) =
184 4. * (rhs[0] - rhs[1] - rhs[2] + rhs[3]) +
185 2. * (rhs[4] + rhs[5] - rhs[6] - rhs[7] +
186 rhs[8] - rhs[9] + rhs[10] - rhs[11]) +
187 rhs[12] + rhs[13] + rhs[14] + rhs[15];
192 for (Int_t k = 0; k <
NCoeff; ++k)
193 sum +=
coeff(1 + i, 1 + j, k) /
194 Double_t((4 - (k % 4)) * (4 - (k / 4)));
195 coeff(1 + i, 1 + j, NCoeff) = sum;
203 if (x <= xmin || x >=
xmax || y <= ymin || y >=
ymax || x != x || y != y)
214 const Double_t hx = (x - xlo) /
binSizeX;
215 const Double_t hy = (y - ylo) /
binSizeY;
217 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
218 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
220 Double_t retVal = 0.;
221 for (Int_t k = 0; k <
NCoeff; ++k)
222 retVal +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
234 if(y1==y2)
return evalX(x1, x2, y1);
235 if(x1==x2)
return evalY(x1, y1, y2);
236 return evalXY(x1, x2, y1, y2);
242 if (x1 != x1 || x2 != x2 || y != y)
return 0.;
249 const Double_t hy = (y - ylo) /
binSizeY;
251 const Double_t hyton[4] = { hy * hy * hy, hy * hy, hy, 1. };
254 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
256 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
257 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
258 if (xhi < x1)
continue;
259 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
260 Double_t(binx) / Double_t(nBinsX) *
xmax;
263 const Double_t a = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
266 const Double_t hxton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
267 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
269 for (Int_t k = 0; k <
NCoeff; ++k)
270 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
280 if (x != x || y1 != y1 || y2 != y2)
return 0.;
282 const Int_t binx = Int_t(Double_t(nBinsX) * (x -
xmin) / (
xmax -
xmin));
284 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
285 Double_t(binx) / Double_t(nBinsX) *
xmax;
287 const Double_t hx = (x - xlo) /
binSizeX;
289 const Double_t hxton[4] = { hx * hx * hx, hx * hx, hx, 1. };
292 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
294 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
295 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
296 if (yhi < y1)
continue;
297 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
298 Double_t(biny) / Double_t(nBinsY) *
ymax;
301 const Double_t a = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
304 const Double_t hyton[4] = { 0.25 * (b * b * b * b - a * a * a * a),
305 (b * b * b - a * a * a) / 3., 0.5 * (b * b - a * a), b - a };
307 for (Int_t k = 0; k <
NCoeff; ++k)
308 lsum +=
coeff(binx, biny, k) * hxton[k % 4] * hyton[k / 4];
316 Double_t x1, Double_t x2, Double_t y1, Double_t y2)
const
319 if (x1 != x1 || x2 != x2 || y1 != y1 || y2 != y2)
return 0.;
322 for (Int_t biny = 0; biny <
nBinsY; ++biny) {
324 const Double_t yhi = Double_t(nBinsY - biny - 1) / Double_t(nBinsY) *
ymin +
325 Double_t(biny + 1) / Double_t(nBinsY) *
ymax;
326 if (yhi < y1)
continue;
327 const Double_t ylo = Double_t(nBinsY - biny) / Double_t(nBinsY) *
ymin +
328 Double_t(biny) / Double_t(nBinsY) *
ymax;
331 const Double_t ay = ((ylo > y1) ? 0. : (y1 - ylo)) /
binSizeY;
333 const Bool_t yFullyContained = std::abs(by - ay - 1.0) < 1e-15;
335 const Double_t hyton[4] = {
336 0.25 * (by * by * by * by - ay * ay * ay * ay),
337 (by * by * by - ay * ay * ay) / 3., 0.5 * (by * by - ay * ay),
339 for (Int_t binx = 0; binx <
nBinsX; ++binx) {
341 const Double_t xhi = Double_t(nBinsX - binx - 1) / Double_t(nBinsX) *
xmin +
342 Double_t(binx + 1) / Double_t(nBinsX) *
xmax;
343 if (xhi < x1)
continue;
344 const Double_t xlo = Double_t(nBinsX - binx) / Double_t(nBinsX) *
xmin +
345 Double_t(binx) / Double_t(nBinsX) *
xmax;
348 const Double_t ax = ((xlo > x1) ? 0. : (x1 - xlo)) /
binSizeX;
350 const Bool_t xFullyContained = std::abs(bx - ax - 1.0) < 1e-15;
351 if (xFullyContained && yFullyContained) {
357 const Double_t hxton[4] = {
358 0.25 * (bx * bx * bx * bx - ax * ax * ax * ax),
359 (bx * bx * bx - ax * ax * ax) / 3., 0.5 * (bx * bx - ax * ax),
364 for (Int_t k = 0; k <
NCoeff; ++k)
365 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.