153def QuadratureSumHisto(histoName,histos):
154
155 if len(histos) == 1:
156 return histos[0]
157
158
159 tolerance = 1.e-4
160 for aHisto in histos[1:]:
161 if aHisto.GetNbinsX() != histos[0].GetNbinsX():
162 print "Input histograms have different number of x bins - can't do quadrature sum safely"
163 return None
164 elif aHisto.GetNbinsY() != histos[0].GetNbinsY():
165 print "Input histograms have different number of y bins - can't do quadrature sum safely"
166 return None
167 for xBin in range(1,histos[0].GetNbinsX()+2):
168 edge = None
169 for aHisto in histos:
170 if edge is None:
171 edge = aHisto.GetXaxis().GetBinLowEdge(xBin)
172 elif fabs(edge-aHisto.GetXaxis().GetBinLowEdge(xBin)) > tolerance:
173 print "Input histograms have different x binning - can't do quadrature sum safely"
174 return None
175 for yBin in range(1,histos[0].GetNbinsY()+2):
176 edge = None
177 for aHisto in histos:
178 if edge is None:
179 edge = aHisto.GetYaxis().GetBinLowEdge(yBin)
180 elif fabs(edge-aHisto.GetYaxis().GetBinLowEdge(yBin)) > tolerance:
181 print "Input histograms have different y binning - can't do quadrature sum safely"
182 return None
183
184
185
186 quadSumHisto = histos[0].Clone()
187 for xBin in range(1,quadSumHisto.GetNbinsX()+1):
188 for yBin in range(1,quadSumHisto.GetNbinsY()+1):
189 quadSum = 0
190 for aHisto in histos:
191 quadSum +=
pow(aHisto.GetBinContent(xBin,yBin),2)
192 quadSumHisto.SetBinContent(xBin,yBin,sqrt(quadSum))
193
194 return quadSumHisto
195
196
197
198
constexpr int pow(int base, int exp) noexcept