All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions | Variables
savehist Namespace Reference

Functions

def main
 
def project_variance
 
def project_mean
 
def mean_and_err
 

Variables

tuple parser = argparse.ArgumentParser()
 

Function Documentation

def savehist.main (   args)

Definition at line 7 of file savehist.py.

7 
8 def main(args):
9  util.optstat(args)
10  hist = util.get_tobject(args, args.hist)
11  util.validate_hists([args.hist], [hist])
12  hist = util.resize_histo(args, hist)
13 
14  if args.make_percentages:
15  if isinstance(hist, ROOT.TH2D):
16  for i in range(1, hist.GetNbinsX()+1):
17  this_norm = hist.Integral(i, i, 1, hist.GetNbinsY())
18  for j in range(1, hist.GetNbinsY()+1):
19  if this_norm < 1e-3:
20  hist.SetBinContent(i, j, 0)
21  else:
22  hist.SetBinContent(i, j, hist.GetBinContent(i, j) / this_norm)
23  else:
24  for k in range(1, hist.GetNbinsZ()+1):
25  for i in range(1, hist.GetNbinsX()+1):
26  this_norm = hist.Integral(i, i, 1, hist.GetNbinsY(), k, k)
27  for j in range(1, hist.GetNbinsY()+1):
28  if this_norm < 1e-3:
29  hist.SetBinContent(i, j, k, 0)
30  else:
31  hist.SetBinContent(i, j, k, hist.GetBinContent(i, j, k) / this_norm)
32 
33  hist2 = None
34  if args.meanY:
35  hist2 = mean_and_err(hist)
36 
37  canvas = ROOT.TCanvas("canvas", "Canvas", 250,100,700,500)
38  drawstr = ""
39  if args.drawstr is not None:
40  drawstr = args.drawstr
41  elif isinstance(hist, ROOT.TH2D):
42  drawstr = "COLZ"
43  if args.draw_text:
44  drawstr += " TEXT"
45  hist.SetMarkerSize(3)
46  ROOT.gStyle.SetPaintTextFormat("1.3f")
47  elif isinstance(hist, ROOT.TH1D):
48  drawstr = "HIST"
49  elif isinstance(hist, ROOT.TGraph):
50  drawstr = "AL"
51  hist.Draw(drawstr)
52  if hist2:
53  hist2.SetLineColor(ROOT.kRed)
54  hist2.SetLineWidth(3)
55  hist2.SetMarkerSize(1)
56  hist2.SetMarkerStyle(21)
57  hist2.SetMarkerColor(ROOT.kRed)
58  hist2.Draw("P")
59  if args.title is not None:
60  hist.SetTitle(args.title)
61  util.style(args, canvas, hist)
62 
63  if args.logy:
64  canvas.SetLogy()
65  if args.logz:
66  canvas.SetLogz()
67  box = util.draw_text(args)
68 
69  canvas.Update()
70 
71  util.wait(args)
72  util.write(args, canvas)
def validate_hists
Definition: util.py:352
def get_tobject
Definition: util.py:47
def main
Definition: savehist.py:7
def style
Definition: util.py:237
def write
Definition: util.py:23
def wait
Definition: util.py:19
def optstat
Definition: util.py:233
def draw_text
Definition: util.py:62
def resize_histo
Definition: util.py:118
def mean_and_err
Definition: savehist.py:109
def savehist.mean_and_err (   hist)

Definition at line 109 of file savehist.py.

110 def mean_and_err(hist):
111  hist = hist.Clone()
112  hist.RebinX(4)
113  g_mean = project_mean(hist)
114  g_err = project_variance(hist)
115  x_err = array('d', [0 for i in range(len(g_mean.GetX()))])
116  return ROOT.TGraphErrors(len(g_mean.GetX()), g_mean.GetX(), g_mean.GetY(), x_err, g_err.GetY())
def project_variance
Definition: savehist.py:73
def project_mean
Definition: savehist.py:93
def mean_and_err
Definition: savehist.py:109
def savehist.project_mean (   hist)

Definition at line 93 of file savehist.py.

93 
94 def project_mean(hist):
95  # calculate the variance in each y-axis -- this is the y-value
96  mean = []
97  xs = []
98  for i in range(1, hist.GetNbinsX()+1):
99  this_sum = 0
100  n_entries = 0
101  for j in range(1, hist.GetNbinsY()+1):
102  this_sum += hist.GetYaxis().GetBinCenter(j) * hist.GetBinContent(i, j)
103  n_entries += hist.GetBinContent(i, j)
104  if n_entries < 1e-3: continue
105  this_mean = this_sum / n_entries if n_entries > 1e-3 else this_sum
106  mean.append(this_mean)
107  xs.append(hist.GetXaxis().GetBinCenter(i))
108  return ROOT.TGraph(len(xs), array('d', xs), array('d', mean))
def project_mean
Definition: savehist.py:93
def savehist.project_variance (   hist)

Definition at line 73 of file savehist.py.

73 
74 def project_variance(hist):
75  # calculate the variance in each y-axis -- this is the y-value
76  var = []
77  xs = []
78  for i in range(1, hist.GetNbinsX()+1):
79  this_sum = 0
80  n_entries = 0
81  for j in range(1, hist.GetNbinsY()+1):
82  this_sum += hist.GetYaxis().GetBinCenter(j) * hist.GetBinContent(i, j)
83  n_entries += hist.GetBinContent(i, j)
84  if n_entries < 1e-3: continue
85  this_mean = this_sum / n_entries if n_entries > 1e-3 else this_sum
86  this_var_sum = 0
87  for j in range(1, hist.GetNbinsY()+1):
88  this_var_sum += hist.GetBinContent(i, j) * (hist.GetYaxis().GetBinCenter(j) - this_mean)**2
89  xs.append(hist.GetXaxis().GetBinCenter(i))
90  this_var = this_var_sum / n_entries if n_entries > 1e-3 else this_var_sum
91  var.append(math.sqrt(this_var))
92  return ROOT.TGraph(len(xs), array('d', xs), array('d', var))
def project_variance
Definition: savehist.py:73

Variable Documentation

tuple savehist.parser = argparse.ArgumentParser()

Definition at line 118 of file savehist.py.