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);