20 print(
"old binning: " +
", ".
join((
"%.3f" % old.GetBinLowEdge(ibin))
21 for ibin
in range(1, old.GetNbinsX()
23 print(
"new binning: " +
", ".
join((
"%.3f" % new.GetBinLowEdge(ibin))
24 for ibin
in range(1, new.GetNbinsX()
31 OVERFLOW = new.GetNbinsX() + 1
33 for iold
in range(1, old.GetNbinsX()):
34 low = old.GetBinLowEdge(iold)
35 r = low + old.GetBinWidth(iold)
37 il_new = new.FindFixBin(low)
38 ir_new = new.FindFixBin(r)
41 if il_new == UNDERFLOW
and ir_new == UNDERFLOW:
42 print(
"1. adding %.3f - %.3f from old" % (low, r))
43 new_binning.append((low, r))
44 new_values.append(old.GetBinContent(iold))
45 new_errors.append(old.GetBinError(iold))
47 elif il_new == UNDERFLOW
and ir_new > UNDERFLOW:
48 if abs(new.GetBinLowEdge(1) - low) < 1E-100:
50 new_binning.append((low, new.GetBinLowEdge(1)))
51 new_values.append(old.GetBinContent(iold))
52 new_errors.append(old.GetBinError(iold))
53 if ir_new == OVERFLOW:
59 for inew
in range(1, new.GetNbinsX() + 1):
60 low = new.GetBinLowEdge(inew)
61 r = low + new.GetBinWidth(inew)
62 print(
"2. adding %.3f - %.3f from new" % (low, r))
63 new_binning.append((low, r))
64 new_values.append(new.GetBinContent(inew))
65 new_errors.append(new.GetBinError(inew))
67 for iold
in range(last_old, old.GetNbinsX() + 1):
68 low = old.GetBinLowEdge(iold)
69 r = low + old.GetBinWidth(iold)
71 il_new = new.FindFixBin(low)
72 ir_new = new.FindFixBin(r)
74 if il_new == OVERFLOW
and ir_new == OVERFLOW:
75 print(
"4. adding %.3f - %.3f from old" % (low, r))
76 new_binning.append((low, r))
77 new_values.append(old.GetBinContent(iold))
78 new_errors.append(old.GetBinError(iold))
79 elif il_new < OVERFLOW
and ir_new == OVERFLOW:
80 if abs(new.GetBinLowEdge(new.GetNbinsX() + 1) - r) < 1E-100:
82 new_binning.append((new.GetBinLowEdge(new.GetNbinsX() + 1), r))
83 new_values.append(old.GetBinContent(iold))
84 new_errors.append(old.GetBinError(iold))
87 new_edges =
array(
'f', [x[0]
for x
in new_binning] + [new_binning[-1][1]])
88 histo_type =
type(new)
89 result = histo_type(new.GetName(), new.GetTitle(),
90 len(new_edges) - 1, new_edges)
91 for i, (v, e)
in enumerate(zip(new_values, new_errors), 1):
92 result.SetBinContent(i, v)
94 result.SetBinError(i, e)
96 print(
"merged binning: " +
", ".
join((
"%.3f" % result.GetBinLowEdge(ibin))
97 for ibin
in range(1, result.GetNbinsX()