18 const double fXmin =
axis->GetXmin();
19 const double fXmax =
axis->GetXmax();
20 const Int_t fNbins =
axis->GetNbins();
21 const TArrayD* fXbins =
axis->GetXbins();
25 }
else if ( !(
x < fXmax)) {
29 bin = 1 +
int (fNbins*(
x-fXmin)/(fXmax-fXmin) );
32 bin = 1 + TMath::BinarySearch(fXbins->fN,fXbins->fArray,
x);
47 if(x<=histo->GetBinCenter(1)) {
48 return histo->GetBinContent(1);
49 }
else if(
x>=
histo->GetBinCenter(
histo->GetNbinsX())) {
50 return histo->GetBinContent(
histo->GetNbinsX());
52 if(x<=histo->GetBinCenter(xbin)) {
53 y0 =
histo->GetBinContent(xbin-1);
54 x0 =
histo->GetBinCenter(xbin-1);
55 y1 =
histo->GetBinContent(xbin);
58 y0 =
histo->GetBinContent(xbin);
59 x0 =
histo->GetBinCenter(xbin);
60 y1 =
histo->GetBinContent(xbin+1);
61 x1 =
histo->GetBinCenter(xbin+1);
63 return y0 + (
x-x0)*((
y1-y0)/(
x1-x0));
73 double Interpolate2D(
const TH1*
histo,
const double x,
const double y,
const int xAxis,
const int yAxis,
const int otherDimBin)
78 const TAxis* fXaxis = xAxis == 1 ?
histo->GetXaxis() : xAxis == 2 ?
histo->GetYaxis() : xAxis == 3 ?
histo->GetZaxis() :
nullptr;
79 const TAxis* fYaxis = yAxis == 1 ?
histo->GetXaxis() : yAxis == 2 ?
histo->GetYaxis() : yAxis == 3 ?
histo->GetZaxis() :
nullptr;
81 if (!fXaxis || !fYaxis)
83 histo->Error(
"Interpolate2D",
"Failed to parse axes from inputs");
92 if(bin_x<1 || bin_x>fXaxis->GetNbins() || bin_y<1 || bin_y>fYaxis->GetNbins()) {
93 histo->Error(
"Interpolate",
"Cannot interpolate outside histogram domain. (x: %f vs [%f,%f], y: %f vs [%f,%f])",
x,fXaxis->GetBinLowEdge(1),fXaxis->GetBinLowEdge(fXaxis->GetNbins()+1),
y,fYaxis->GetBinLowEdge(1),fYaxis->GetBinLowEdge(fYaxis->GetNbins()+1));
98 dx = fXaxis->GetBinUpEdge(bin_x)-
x;
99 dy = fYaxis->GetBinUpEdge(bin_y)-
y;
100 if (dx<=fXaxis->GetBinWidth(bin_x)/2 && dy<=fYaxis->GetBinWidth(bin_y)/2)
102 if (
dx>fXaxis->GetBinWidth(bin_x)/2 && dy<=fYaxis->GetBinWidth(bin_y)/2)
104 if (
dx>fXaxis->GetBinWidth(bin_x)/2 &&
dy>fYaxis->GetBinWidth(bin_y)/2)
106 if (dx<=fXaxis->GetBinWidth(bin_x)/2 &&
dy>fYaxis->GetBinWidth(bin_y)/2)
110 x1 = fXaxis->GetBinCenter(bin_x);
111 y1 = fYaxis->GetBinCenter(bin_y);
112 x2 = fXaxis->GetBinCenter(bin_x+1);
113 y2 = fYaxis->GetBinCenter(bin_y+1);
116 x1 = fXaxis->GetBinCenter(bin_x-1);
117 y1 = fYaxis->GetBinCenter(bin_y);
118 x2 = fXaxis->GetBinCenter(bin_x);
119 y2 = fYaxis->GetBinCenter(bin_y+1);
122 x1 = fXaxis->GetBinCenter(bin_x-1);
123 y1 = fYaxis->GetBinCenter(bin_y-1);
124 x2 = fXaxis->GetBinCenter(bin_x);
125 y2 = fYaxis->GetBinCenter(bin_y);
128 x1 = fXaxis->GetBinCenter(bin_x);
129 y1 = fYaxis->GetBinCenter(bin_y-1);
130 x2 = fXaxis->GetBinCenter(bin_x+1);
131 y2 = fYaxis->GetBinCenter(bin_y);
135 if(bin_x1<1) bin_x1=1;
137 if(bin_x2>fXaxis->GetNbins()) bin_x2=fXaxis->GetNbins();
139 if(bin_y1<1) bin_y1=1;
141 if(bin_y2>fYaxis->GetNbins()) bin_y2=fYaxis->GetNbins();
150 if (xAxis == 1 && yAxis == 2)
152 q11 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y1,otherDimBin));
153 q12 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y2,otherDimBin));
154 q21 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y1,otherDimBin));
155 q22 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y2,otherDimBin));
158 else if (xAxis == 1 && yAxis == 3)
160 q11 =
histo->GetBinContent(
histo->GetBin(bin_x1,otherDimBin,bin_y1));
161 q12 =
histo->GetBinContent(
histo->GetBin(bin_x1,otherDimBin,bin_y2));
162 q21 =
histo->GetBinContent(
histo->GetBin(bin_x2,otherDimBin,bin_y1));
163 q22 =
histo->GetBinContent(
histo->GetBin(bin_x2,otherDimBin,bin_y2));
166 else if (xAxis == 2 && yAxis == 3)
168 q11 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x1,bin_y1));
169 q12 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x1,bin_y2));
170 q21 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x2,bin_y1));
171 q22 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x2,bin_y2));
174 else if (xAxis == 2 && yAxis == 1)
176 q11 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x1,otherDimBin));
177 q12 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x2,otherDimBin));
178 q21 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x1,otherDimBin));
179 q22 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x2,otherDimBin));
182 else if (xAxis == 3 && yAxis == 1)
184 q11 =
histo->GetBinContent(
histo->GetBin(bin_y1,otherDimBin,bin_x1));
185 q12 =
histo->GetBinContent(
histo->GetBin(bin_y1,otherDimBin,bin_x2));
186 q21 =
histo->GetBinContent(
histo->GetBin(bin_y2,otherDimBin,bin_x1));
187 q22 =
histo->GetBinContent(
histo->GetBin(bin_y2,otherDimBin,bin_x2));
190 else if (xAxis == 3 && yAxis == 2)
192 q11 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y1,bin_x1));
193 q12 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y1,bin_x2));
194 q21 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y2,bin_x1));
195 q22 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y2,bin_x2));
199 histo->Error(
"Interpolate2D",
"Unsupported axis combination: (x,y)=(%d,%d) with one bin fixed",xAxis,yAxis);
206 if (xAxis == 1 && yAxis == 2)
208 q11 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y1));
209 q12 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y2));
210 q21 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y1));
211 q22 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y2));
214 else if (xAxis == 2 && yAxis == 1)
216 q11 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x1));
217 q12 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x2));
218 q21 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x1));
219 q22 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x2));
223 histo->Error(
"Interpolate2D",
"Unsupported axis combination: (x,y)=(%d,%d)",xAxis,yAxis);
238 const TAxis* fXaxis =
histo->GetXaxis();
239 const TAxis* fYaxis =
histo->GetYaxis();
240 const TAxis* fZaxis =
histo->GetZaxis();
248 if ( ubx < 1 || ubx >
histo->GetNbinsX() || uby < 1 || uby >
histo->GetNbinsY() || ubz < 1 || ubz >
histo->GetNbinsZ() )
250 histo->Error(
"Interpolate",
"Cannot interpolate outside histogram domain. (x: %f vs [%f,%f], y: %f vs [%f,%f], z: %f vs [%f,%f])",
x,fXaxis->GetBinLowEdge(1),fXaxis->GetBinLowEdge(
histo->GetNbinsX()+1),
y,fYaxis->GetBinLowEdge(1),fYaxis->GetBinLowEdge(
histo->GetNbinsY()+1),
z,fZaxis->GetBinLowEdge(1),fZaxis->GetBinLowEdge(
histo->GetNbinsZ()+1));
263 Double_t xw = fXaxis->GetBinCenter(obx) - fXaxis->GetBinCenter(ubx);
264 Double_t yw = fYaxis->GetBinCenter(oby) - fYaxis->GetBinCenter(uby);
265 Double_t zw = fZaxis->GetBinCenter(obz) - fZaxis->GetBinCenter(ubz);
267 if (x < fXaxis->GetBinCenter(ubx)) { ubx -= 1; obx -= 1; }
268 if (ubx < 1) ubx = 1;
269 if (obx >
histo->GetNbinsX()) obx =
histo->GetNbinsX();
271 if (y < fYaxis->GetBinCenter(uby)) { uby -= 1; oby -= 1; }
272 if (uby < 1) uby = 1;
273 if (oby >
histo->GetNbinsY()) oby =
histo->GetNbinsY();
275 if (z < fZaxis->GetBinCenter(ubz)) { ubz -= 1; obz -= 1; }
276 if (ubz < 1) ubz = 1;
277 if (obz >
histo->GetNbinsZ()) obz =
histo->GetNbinsZ();
297 Double_t
xd = (
x - fXaxis->GetBinCenter(ubx)) / xw;
298 Double_t yd = (
y - fYaxis->GetBinCenter(uby)) / yw;
299 Double_t zd = (
z - fZaxis->GetBinCenter(ubz)) / zw;
302 Double_t
v[] = {
histo->GetBinContent( ubx, uby, ubz ),
histo->GetBinContent( ubx, uby, obz ),
303 histo->GetBinContent( ubx, oby, ubz ),
histo->GetBinContent( ubx, oby, obz ),
304 histo->GetBinContent( obx, uby, ubz ),
histo->GetBinContent( obx, uby, obz ),
305 histo->GetBinContent( obx, oby, ubz ),
histo->GetBinContent( obx, oby, obz ) };
308 Double_t i1 =
v[0] * (1 - zd) +
v[1] * zd;
309 Double_t i2 =
v[2] * (1 - zd) +
v[3] * zd;
310 Double_t
j1 =
v[4] * (1 - zd) +
v[5] * zd;
311 Double_t
j2 =
v[6] * (1 - zd) +
v[7] * zd;
314 Double_t w1 = i1 * (1 - yd) + i2 * yd;
315 Double_t w2 =
j1 * (1 - yd) +
j2 * yd;