All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
eff_ratio.py
Go to the documentation of this file.
1 import ROOT
2 import util
3 import argparse
4 
5 def main(args):
6  base_histos = [util.get_tobject(args, r) for r in args.base_histos]
7  util.validate_hists(args.base_histos, base_histos)
8  base_histos = [util.resize_histo(args, util.get_tobject(args, r)) for r in args.base_histos]
9 
10  cut_histos = [util.get_tobject(args, r) for r in args.cut_histos]
11  util.validate_hists(args.cut_histos, cut_histos)
12  cut_histos = [util.resize_histo(args, util.get_tobject(args, r)) for r in args.cut_histos]
13 
14  canvas = ROOT.TCanvas("canvas", "Canvas", 250,100,700,500)
15 
16  all_histos = []
17  for i, (base_histo,cut_histo) in enumerate(zip(base_histos,cut_histos)):
18  ratio = cut_histo.Clone()
19  ratio.Divide(base_histo)
20  ratio.SetLineColor(util.fillcolors(i))
21  ratio.SetLineWidth(2)
22  if i == 0:
23  util.style(args, canvas, ratio)
24  ratio.Draw("PE")
25  else:
26  ratio.Draw("PE SAME")
27  all_histos.append(ratio)
28 
29  if args.names:
30  name = args.names[i]
31  ratio.SetTitle(name)
32 
33  legend = ROOT.gPad.BuildLegend(*(args.legend_position + [""]))
34  if args.title is not None:
35  all_histos[0].SetTitle(args.title)
36  canvas.Update()
37 
38  util.wait(args)
39  util.write(args, canvas)
40 
41 if __name__ == "__main__":
42  parser = argparse.ArgumentParser()
43  parser = util.with_io_args(parser)
44  parser = util.with_histosize_args(parser)
45  parser = util.with_histostyle_args(parser)
46  parser.add_argument("-b", "--base_histos", type=util.comma_separated, required=True)
47  parser.add_argument("-c", "--cut_histos", type=util.comma_separated, required=True)
48  parser.add_argument("-t" ,"--title", default=None)
49  parser.add_argument("-n", "--names", default=None, type=util.comma_separated)
50  parser.add_argument("-lp", "--legend_position", default=[0.75,0.75,0.95,0.95], type=util.legend_position)
51  main(parser.parse_args())
52 
def main
Definition: eff_ratio.py:5
def validate_hists
Definition: util.py:352
def get_tobject
Definition: util.py:47
def style
Definition: util.py:237
def write
Definition: util.py:23
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
def with_histostyle_args
Definition: util.py:220
def with_histosize_args
Definition: util.py:100
def wait
Definition: util.py:19
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
def fillcolors
Definition: util.py:272
def with_io_args
Definition: util.py:84
def resize_histo
Definition: util.py:118