23 if(x<=histo->GetBinCenter(1)) {
24 return histo->GetBinContent(1);
25 }
else if(
x>=
histo->GetBinCenter(
histo->GetNbinsX())) {
26 return histo->GetBinContent(
histo->GetNbinsX());
28 if(x<=histo->GetBinCenter(xbin)) {
29 y0 =
histo->GetBinContent(xbin-1);
30 x0 =
histo->GetBinCenter(xbin-1);
31 y1 =
histo->GetBinContent(xbin);
34 y0 =
histo->GetBinContent(xbin);
35 x0 =
histo->GetBinCenter(xbin);
36 y1 =
histo->GetBinContent(xbin+1);
37 x1 =
histo->GetBinCenter(xbin+1);
39 return y0 + (
x-x0)*((
y1-y0)/(
x1-x0));
52 if (xAxis == 0 || xAxis >
histo->GetDimension())
54 histo->Error(
"Interpolate2D",
"Invalid x-axis specified");
57 if (yAxis == 0 || yAxis >
histo->GetDimension())
59 histo->Error(
"Interpolate2D",
"Invalid y-axis specified");
64 histo->Error(
"Interpolate2D",
"Requested x-axis == y-axis, invalid for 2D interpolation");
70 const TAxis* fXaxis = xAxis == 1 ?
histo->GetXaxis() : xAxis == 2 ?
histo->GetYaxis() : xAxis == 3 ?
histo->GetZaxis() :
nullptr;
71 const TAxis* fYaxis = yAxis == 1 ?
histo->GetXaxis() : yAxis == 2 ?
histo->GetYaxis() : yAxis == 3 ?
histo->GetZaxis() :
nullptr;
73 if (!fXaxis || !fYaxis)
75 histo->Error(
"Interpolate2D",
"Failed to parse axes from inputs");
82 int bin_x = fXaxis->FindBin(
x);
83 int bin_y = fYaxis->FindBin(
y);
84 if(bin_x<1 || bin_x>fXaxis->GetNbins() || bin_y<1 || bin_y>fYaxis->GetNbins()) {
85 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));
90 dx = fXaxis->GetBinUpEdge(bin_x)-
x;
91 dy = fYaxis->GetBinUpEdge(bin_y)-
y;
92 if (dx<=fXaxis->GetBinWidth(bin_x)/2 && dy<=fYaxis->GetBinWidth(bin_y)/2)
94 if (
dx>fXaxis->GetBinWidth(bin_x)/2 && dy<=fYaxis->GetBinWidth(bin_y)/2)
96 if (
dx>fXaxis->GetBinWidth(bin_x)/2 &&
dy>fYaxis->GetBinWidth(bin_y)/2)
98 if (dx<=fXaxis->GetBinWidth(bin_x)/2 &&
dy>fYaxis->GetBinWidth(bin_y)/2)
102 x1 = fXaxis->GetBinCenter(bin_x);
103 y1 = fYaxis->GetBinCenter(bin_y);
104 x2 = fXaxis->GetBinCenter(bin_x+1);
105 y2 = fYaxis->GetBinCenter(bin_y+1);
108 x1 = fXaxis->GetBinCenter(bin_x-1);
109 y1 = fYaxis->GetBinCenter(bin_y);
110 x2 = fXaxis->GetBinCenter(bin_x);
111 y2 = fYaxis->GetBinCenter(bin_y+1);
114 x1 = fXaxis->GetBinCenter(bin_x-1);
115 y1 = fYaxis->GetBinCenter(bin_y-1);
116 x2 = fXaxis->GetBinCenter(bin_x);
117 y2 = fYaxis->GetBinCenter(bin_y);
120 x1 = fXaxis->GetBinCenter(bin_x);
121 y1 = fYaxis->GetBinCenter(bin_y-1);
122 x2 = fXaxis->GetBinCenter(bin_x+1);
123 y2 = fYaxis->GetBinCenter(bin_y);
126 int bin_x1 = fXaxis->FindBin(
x1);
127 if(bin_x1<1) bin_x1=1;
128 int bin_x2 = fXaxis->FindBin(
x2);
129 if(bin_x2>fXaxis->GetNbins()) bin_x2=fXaxis->GetNbins();
130 int bin_y1 = fYaxis->FindBin(
y1);
131 if(bin_y1<1) bin_y1=1;
132 int bin_y2 = fYaxis->FindBin(
y2);
133 if(bin_y2>fYaxis->GetNbins()) bin_y2=fYaxis->GetNbins();
142 if (xAxis == 1 && yAxis == 2)
144 q11 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y1,otherDimBin));
145 q12 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y2,otherDimBin));
146 q21 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y1,otherDimBin));
147 q22 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y2,otherDimBin));
150 else if (xAxis == 1 && yAxis == 3)
152 q11 =
histo->GetBinContent(
histo->GetBin(bin_x1,otherDimBin,bin_y1));
153 q12 =
histo->GetBinContent(
histo->GetBin(bin_x1,otherDimBin,bin_y2));
154 q21 =
histo->GetBinContent(
histo->GetBin(bin_x2,otherDimBin,bin_y1));
155 q22 =
histo->GetBinContent(
histo->GetBin(bin_x2,otherDimBin,bin_y2));
158 else if (xAxis == 2 && yAxis == 3)
160 q11 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x1,bin_y1));
161 q12 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x1,bin_y2));
162 q21 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x2,bin_y1));
163 q22 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_x2,bin_y2));
166 else if (xAxis == 2 && yAxis == 1)
168 q11 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x1,otherDimBin));
169 q12 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x2,otherDimBin));
170 q21 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x1,otherDimBin));
171 q22 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x2,otherDimBin));
174 else if (xAxis == 3 && yAxis == 1)
176 q11 =
histo->GetBinContent(
histo->GetBin(bin_y1,otherDimBin,bin_x1));
177 q12 =
histo->GetBinContent(
histo->GetBin(bin_y1,otherDimBin,bin_x2));
178 q21 =
histo->GetBinContent(
histo->GetBin(bin_y2,otherDimBin,bin_x1));
179 q22 =
histo->GetBinContent(
histo->GetBin(bin_y2,otherDimBin,bin_x2));
182 else if (xAxis == 3 && yAxis == 2)
184 q11 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y1,bin_x1));
185 q12 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y1,bin_x2));
186 q21 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y2,bin_x1));
187 q22 =
histo->GetBinContent(
histo->GetBin(otherDimBin,bin_y2,bin_x2));
191 histo->Error(
"Interpolate2D",
"Unsupported axis combination: (x,y)=(%d,%d) with one bin fixed",xAxis,yAxis);
198 if (xAxis == 1 && yAxis == 2)
200 q11 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y1));
201 q12 =
histo->GetBinContent(
histo->GetBin(bin_x1,bin_y2));
202 q21 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y1));
203 q22 =
histo->GetBinContent(
histo->GetBin(bin_x2,bin_y2));
206 else if (xAxis == 2 && yAxis == 1)
208 q11 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x1));
209 q12 =
histo->GetBinContent(
histo->GetBin(bin_y1,bin_x2));
210 q21 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x1));
211 q22 =
histo->GetBinContent(
histo->GetBin(bin_y2,bin_x2));
215 histo->Error(
"Interpolate2D",
"Unsupported axis combination: (x,y)=(%d,%d)",xAxis,yAxis);
229 const TAxis* fXaxis =
histo->GetXaxis();
230 const TAxis* fYaxis =
histo->GetYaxis();
231 const TAxis* fZaxis =
histo->GetZaxis();
234 int ubx = fXaxis->FindBin(
x);
235 int uby = fYaxis->FindBin(
y);
236 int ubz = fZaxis->FindBin(
z);
239 if ( ubx < 1 || ubx >
histo->GetNbinsX() || uby < 1 || uby >
histo->GetNbinsY() || ubz < 1 || ubz >
histo->GetNbinsZ() )
241 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));
256 if (x < fXaxis->GetBinCenter(ubx)) { ubx -= 1; obx -= 1; }
257 if (ubx < 1) ubx = 1;
258 if (obx >
histo->GetNbinsX()) obx =
histo->GetNbinsX();
260 if (y < fYaxis->GetBinCenter(uby)) { uby -= 1; oby -= 1; }
261 if (uby < 1) uby = 1;
262 if (oby >
histo->GetNbinsY()) oby =
histo->GetNbinsY();
264 if (z < fZaxis->GetBinCenter(ubz)) { ubz -= 1; obz -= 1; }
265 if (ubz < 1) ubz = 1;
266 if (obz >
histo->GetNbinsZ()) obz =
histo->GetNbinsZ();
272 if (ubx == obx || uby == oby || ubz == obz)
287 double xw = fXaxis->GetBinCenter(obx) - fXaxis->GetBinCenter(ubx);
288 double yw = fYaxis->GetBinCenter(oby) - fYaxis->GetBinCenter(uby);
289 double zw = fZaxis->GetBinCenter(obz) - fZaxis->GetBinCenter(ubz);
292 double xd = (
x - fXaxis->GetBinCenter(ubx)) / xw;
293 double yd = (
y - fYaxis->GetBinCenter(uby)) / yw;
294 double zd = (
z - fZaxis->GetBinCenter(ubz)) / zw;
297 double v[] = {
histo->GetBinContent( ubx, uby, ubz ),
histo->GetBinContent( ubx, uby, obz ),
298 histo->GetBinContent( ubx, oby, ubz ),
histo->GetBinContent( ubx, oby, obz ),
299 histo->GetBinContent( obx, uby, ubz ),
histo->GetBinContent( obx, uby, obz ),
300 histo->GetBinContent( obx, oby, ubz ),
histo->GetBinContent( obx, oby, obz ) };
303 double i1 =
v[0] * (1 - zd) +
v[1] * zd;
304 double i2 =
v[2] * (1 - zd) +
v[3] * zd;
305 double j1 =
v[4] * (1 - zd) +
v[5] * zd;
306 double j2 =
v[6] * (1 - zd) +
v[7] * zd;
309 double w1 = i1 * (1 - yd) + i2 * yd;
310 double w2 =
j1 * (1 - yd) +
j2 * yd;