All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
projections.py
Go to the documentation of this file.
1 import ROOT
2 import util
3 import argparse
4 from array import array
5 import math
6 
7 # ROOT.gStyle.SetPalette(21)
8 
9 def main(args):
10  util.optstat(args)
11  f = ROOT.TFile(args.input)
12  hist = f.Get(args.hist)
13  util.validate_hists([args.hist], [hist])
14  hist = util.resize_histo(args, hist, "")
15  hstack = ROOT.THStack()
16  canvas = ROOT.TCanvas("canvas", "Canvas", 250,100,700,500)
17 
18  class ArgDict(dict):
19  __getattr__ = dict.get
20 
21  hists = []
22  for i,(low,high) in enumerate(zip(args.lows, args.highs)):
23  this_args = ArgDict({"y_min": low, "y_max": high, "projectionX": True})
24  h = util.resize_histo(this_args, hist.Clone(), str(i))
25  h.SetLineColor(util.fillcolors(i))
26  h.SetLineWidth(3)
27  if args.names:
28  name = args.names[i]
29  h.SetTitle(name)
30  hists.append(h)
31  hstack.Add(h)
32 
33  hstack.Draw("NOSTACK HIST")
34  legend = ROOT.gPad.BuildLegend(*(args.legend_position + [""]))
35  if args.title is not None:
36  hstack.SetTitle(args.title)
37  util.style(args, canvas, hstack)
38 
39  box = util.draw_text(args)
40 
41  canvas.Update()
42 
43  util.wait(args)
44  util.write(args, canvas)
45 
46 if __name__ == "__main__":
47  parser = argparse.ArgumentParser()
48  parser = util.with_io_args(parser)
49  parser = util.with_histostyle_args(parser)
50  parser = util.with_text_args(parser)
51  parser = util.with_histosize_args(parser)
52  parser.add_argument("-t" ,"--title", default=None)
53  parser.add_argument("-hn", "--hist", required=True)
54  parser.add_argument("-ls", "--lows", nargs="+", type=float)
55  parser.add_argument("-hs", "--highs", nargs="+", type=float)
56  parser.add_argument("-n", "--names", type=util.comma_separated)
57  parser.add_argument("-lp", "--legend_position", default=[0.75,0.75,0.95,0.95], type=util.legend_position)
58  main(parser.parse_args())
59 
def validate_hists
Definition: util.py:352
def with_text_args
Definition: util.py:54
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
def optstat
Definition: util.py:233
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 draw_text
Definition: util.py:62
def with_io_args
Definition: util.py:84
def resize_histo
Definition: util.py:118