ATLAS Offline Software
Functions | Variables
merge_scale_histograms Namespace Reference

Functions

def merge_histograms (old, new, merge_error=True)
 

Variables

string doc
 
 IgnoreCommandLineOptions
 
 level
 
 parser
 
 help
 
 action
 
 default
 
 args = parser.parse_args()
 
 file_old = ROOT.TFile.Open(args.histo_old.split(":")[0])
 
 file_new = ROOT.TFile.Open(args.histo_new.split(":")[0])
 
 histo_old = file_old.Get(args.histo_old.split(":")[1])
 
 histo_new = file_new.Get(args.histo_new.split(":")[1])
 
def histo_merged = merge_histograms(histo_old, histo_new)
 
 canvas = ROOT.TCanvas()
 
 legend = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)
 
 fout
 
 name = args.name or histo_old.GetName()
 

Function Documentation

◆ merge_histograms()

def merge_scale_histograms.merge_histograms (   old,
  new,
  merge_error = True 
)

Definition at line 19 of file merge_scale_histograms.py.

19 def merge_histograms(old, new, merge_error=True):
20  print("old binning: " + ", ".join(("%.3f" % old.GetBinLowEdge(ibin))
21  for ibin in range(1, old.GetNbinsX()
22  + 2)))
23  print("new binning: " + ", ".join(("%.3f" % new.GetBinLowEdge(ibin))
24  for ibin in range(1, new.GetNbinsX()
25  + 2)))
26 
27  new_binning = []
28  new_values = []
29  new_errors = []
30  UNDERFLOW = 0
31  OVERFLOW = new.GetNbinsX() + 1
32 
33  for iold in range(1, old.GetNbinsX()):
34  low = old.GetBinLowEdge(iold)
35  r = low + old.GetBinWidth(iold)
36 
37  il_new = new.FindFixBin(low)
38  ir_new = new.FindFixBin(r)
39  remainer = None
40 
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))
46 
47  elif il_new == UNDERFLOW and ir_new > UNDERFLOW:
48  if abs(new.GetBinLowEdge(1) - low) < 1E-100:
49  continue
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:
54  remainer = iold # noqa: F841
55  print("breaking")
56  break
57  last_old = iold
58 
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))
66 
67  for iold in range(last_old, old.GetNbinsX() + 1):
68  low = old.GetBinLowEdge(iold)
69  r = low + old.GetBinWidth(iold)
70 
71  il_new = new.FindFixBin(low)
72  ir_new = new.FindFixBin(r)
73 
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:
81  continue
82  new_binning.append((new.GetBinLowEdge(new.GetNbinsX() + 1), r))
83  new_values.append(old.GetBinContent(iold))
84  new_errors.append(old.GetBinError(iold))
85 
86  print(new_binning)
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)
93  if merge_error:
94  result.SetBinError(i, e)
95 
96  print("merged binning: " + ", ".join(("%.3f" % result.GetBinLowEdge(ibin))
97  for ibin in range(1, result.GetNbinsX()
98  + 1)))
99 
100  return result
101 
102 

Variable Documentation

◆ action

merge_scale_histograms.action

Definition at line 119 of file merge_scale_histograms.py.

◆ args

merge_scale_histograms.args = parser.parse_args()

Definition at line 122 of file merge_scale_histograms.py.

◆ canvas

merge_scale_histograms.canvas = ROOT.TCanvas()

Definition at line 139 of file merge_scale_histograms.py.

◆ default

merge_scale_histograms.default

Definition at line 120 of file merge_scale_histograms.py.

◆ doc

string merge_scale_histograms.doc
Initial value:
1 = """
2 This is an utility to merge histograms. The common case is when you have
3 old scale factors for the whole calorimeter and new scale factor only for
4 a subpart.
5 """

Definition at line 9 of file merge_scale_histograms.py.

◆ file_new

merge_scale_histograms.file_new = ROOT.TFile.Open(args.histo_new.split(":")[0])

Definition at line 125 of file merge_scale_histograms.py.

◆ file_old

merge_scale_histograms.file_old = ROOT.TFile.Open(args.histo_old.split(":")[0])

Definition at line 124 of file merge_scale_histograms.py.

◆ fout

merge_scale_histograms.fout
Initial value:
1 = ROOT.TFile.Open(args.output_filename,
2  "recreate" if args.recreate else "update")

Definition at line 156 of file merge_scale_histograms.py.

◆ help

merge_scale_histograms.help

Definition at line 116 of file merge_scale_histograms.py.

◆ histo_merged

def merge_scale_histograms.histo_merged = merge_histograms(histo_old, histo_new)

Definition at line 137 of file merge_scale_histograms.py.

◆ histo_new

merge_scale_histograms.histo_new = file_new.Get(args.histo_new.split(":")[1])

Definition at line 128 of file merge_scale_histograms.py.

◆ histo_old

merge_scale_histograms.histo_old = file_old.Get(args.histo_old.split(":")[1])

Definition at line 127 of file merge_scale_histograms.py.

◆ IgnoreCommandLineOptions

merge_scale_histograms.IgnoreCommandLineOptions

Definition at line 15 of file merge_scale_histograms.py.

◆ legend

merge_scale_histograms.legend = ROOT.TLegend(0.6, 0.7, 0.9, 0.9)

Definition at line 150 of file merge_scale_histograms.py.

◆ level

merge_scale_histograms.level

Definition at line 16 of file merge_scale_histograms.py.

◆ name

merge_scale_histograms.name = args.name or histo_old.GetName()

Definition at line 160 of file merge_scale_histograms.py.

◆ parser

merge_scale_histograms.parser
Initial value:
1 = argparse.ArgumentParser(description=doc,
2  formatter_class=argparse.RawTextHelpFormatter)

Definition at line 112 of file merge_scale_histograms.py.

merge_scale_histograms.merge_histograms
def merge_histograms(old, new, merge_error=True)
Definition: merge_scale_histograms.py:19
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
array
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28