All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
signal_to_background.py
Go to the documentation of this file.
1 import ROOT
2 import util
3 import argparse
4 
5 
6 def main(args):
7  f = ROOT.TFile(args.input)
8 
9  sigs = [f.Get(h.lstrip("-")) for h in args.histo_sig]
10  util.validate_hists(args.histo_sig, sigs)
11  sigs = [util.resize_histo(args, h) for h in sigs]
12 
13  bkgs = [f.Get(h.lstrip("-")) for h in args.histo_bkg]
14  util.validate_hists(args.histo_bkg, bkgs)
15  bkgs = [util.resize_histo(args, h) for h in bkgs]
16 
17 
18  n_sig = 0.
19  for h in sigs:
20  n_sig += h.Integral()
21 
22  n_bkg = 0.
23  for h in bkgs:
24  n_bkg += h.Integral()
25 
26  print args.format % (n_sig / n_bkg)
27 
28 if __name__ == "__main__":
29  parser = argparse.ArgumentParser()
30  parser = util.with_io_args(parser)
31  parser = util.with_histosize_args(parser)
32  parser.add_argument("-hs", "--histo_sig", required=True, type=util.comma_separated)
33  parser.add_argument("-hb", "--histo_bkg", required=True, type=util.comma_separated)
34  parser.add_argument("-f", "--format", default="%f")
35  main(parser.parse_args())
36 
def validate_hists
Definition: util.py:352
def with_histosize_args
Definition: util.py:100
def with_io_args
Definition: util.py:84
def resize_histo
Definition: util.py:118