Helper function for edge cases in 3D interpolation by interpolating in 2D and keeping the third axis axis (edge) fixed The input parameters "xAxis" and "yAxis" indicate which axes should be used for the 2D interpolation: x-axis: 1, y-axis: 2, z-axis: 3 The input parameter "otherDimBin" is the bin on the third axis which will be kept constant in the interpolation.
74{
75
76
77
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;
80
81 if (!fXaxis || !fYaxis)
82 {
83 histo->Error("Interpolate2D","Failed to parse axes from inputs");
84 return 0;
85 }
86
87 Double_t f=0;
88 Double_t x1=0,x2=0,y1=0,y2=0;
89 Double_t dx,dy;
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));
94 return 0;
95 }
96 Int_t quadrant = 0;
97
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)
101 quadrant = 1;
102 if (dx>fXaxis->GetBinWidth(bin_x)/2 && dy<=fYaxis->GetBinWidth(bin_y)/2)
103 quadrant = 2;
104 if (dx>fXaxis->GetBinWidth(bin_x)/2 && dy>fYaxis->GetBinWidth(bin_y)/2)
105 quadrant = 3;
106 if (dx<=fXaxis->GetBinWidth(bin_x)/2 && dy>fYaxis->GetBinWidth(bin_y)/2)
107 quadrant = 4;
108 switch(quadrant) {
109 case 1:
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);
114 break;
115 case 2:
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);
120 break;
121 case 3:
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);
126 break;
127 case 4:
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);
132 break;
133 }
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();
142
143 Double_t q11;
144 Double_t q12;
145 Double_t q21;
146 Double_t q22;
147 if (otherDimBin > 0)
148 {
149
150 if (xAxis == 1 && yAxis == 2)
151 {
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));
156 }
157
158 else if (xAxis == 1 && yAxis == 3)
159 {
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));
164 }
165
166 else if (xAxis == 2 && yAxis == 3)
167 {
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));
172 }
173
174 else if (xAxis == 2 && yAxis == 1)
175 {
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));
180 }
181
182 else if (xAxis == 3 && yAxis == 1)
183 {
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));
188 }
189
190 else if (xAxis == 3 && yAxis == 2)
191 {
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));
196 }
197 else
198 {
199 histo->Error(
"Interpolate2D",
"Unsupported axis combination: (x,y)=(%d,%d) with one bin fixed",xAxis,yAxis);
200 return 0;
201 }
202 }
203 else
204 {
205
206 if (xAxis == 1 && yAxis == 2)
207 {
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));
212 }
213
214 else if (xAxis == 2 && yAxis == 1)
215 {
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));
220 }
221 else
222 {
223 histo->Error(
"Interpolate2D",
"Unsupported axis combination: (x,y)=(%d,%d)",xAxis,yAxis);
224 return 0;
225 }
226 }
227
228 Double_t
d = 1.0*(
x2-
x1)*(y2-y1);
231}