4 from array
import array
13 if args.make_percentages:
14 if isinstance(hist, ROOT.TH2D):
15 for i
in range(1, hist.GetNbinsX()+1):
16 this_norm = hist.Integral(i, i, 1, hist.GetNbinsY())
17 for j
in range(1, hist.GetNbinsY()+1):
19 hist.SetBinContent(i, j, 0)
21 hist.SetBinContent(i, j, hist.GetBinContent(i, j) / this_norm)
23 for k
in range(1, hist.GetNbinsZ()+1):
24 for i
in range(1, hist.GetNbinsX()+1):
25 this_norm = hist.Integral(i, i, 1, hist.GetNbinsY(), k, k)
26 for j
in range(1, hist.GetNbinsY()+1):
28 hist.SetBinContent(i, j, k, 0)
30 hist.SetBinContent(i, j, k, hist.GetBinContent(i, j, k) / this_norm)
36 canvas = ROOT.TCanvas(
"canvas",
"Canvas", 250,100,700,500)
38 if args.drawstr
is not None:
39 drawstr = args.drawstr
40 elif isinstance(hist, ROOT.TH2D):
45 ROOT.gStyle.SetPaintTextFormat(
"1.3f")
46 elif isinstance(hist, ROOT.TH1D):
48 elif isinstance(hist, ROOT.TGraph):
52 hist2.SetLineColor(ROOT.kRed)
54 hist2.SetMarkerSize(1)
55 hist2.SetMarkerStyle(21)
56 hist2.SetMarkerColor(ROOT.kRed)
58 if args.title
is not None:
59 hist.SetTitle(args.title)
77 for i
in range(1, hist.GetNbinsX()+1):
80 for j
in range(1, hist.GetNbinsY()+1):
81 this_sum += hist.GetYaxis().GetBinCenter(j) * hist.GetBinContent(i, j)
82 n_entries += hist.GetBinContent(i, j)
83 if n_entries < 1e-3:
continue
84 this_mean = this_sum / n_entries
if n_entries > 1e-3
else this_sum
86 for j
in range(1, hist.GetNbinsY()+1):
87 this_var_sum += hist.GetBinContent(i, j) * (hist.GetYaxis().GetBinCenter(j) - this_mean)**2
88 xs.append(hist.GetXaxis().GetBinCenter(i))
89 this_var = this_var_sum / n_entries
if n_entries > 1e-3
else this_var_sum
90 var.append(math.sqrt(this_var))
91 return ROOT.TGraph(len(xs), array(
'd', xs), array(
'd', var))
97 for i
in range(1, hist.GetNbinsX()+1):
100 for j
in range(1, hist.GetNbinsY()+1):
101 this_sum += hist.GetYaxis().GetBinCenter(j) * hist.GetBinContent(i, j)
102 n_entries += hist.GetBinContent(i, j)
103 if n_entries < 1e-3:
continue
104 this_mean = this_sum / n_entries
if n_entries > 1e-3
else this_sum
105 mean.append(this_mean)
106 xs.append(hist.GetXaxis().GetBinCenter(i))
107 return ROOT.TGraph(len(xs), array(
'd', xs), array(
'd', mean))
114 x_err = array(
'd', [0
for i
in range(len(g_mean.GetX()))])
115 return ROOT.TGraphErrors(len(g_mean.GetX()), g_mean.GetX(), g_mean.GetY(), x_err, g_err.GetY())
117 if __name__ ==
"__main__":
118 parser = argparse.ArgumentParser()
123 parser.add_argument(
"-t" ,
"--title", default=
None)
124 parser.add_argument(
"-hn",
"--hist", required=
True)
125 parser.add_argument(
"-ly",
"--logy", action=
"store_true")
126 parser.add_argument(
"-lz",
"--logz", action=
"store_true")
127 parser.add_argument(
"-meanY",
"--meanY", action=
"store_true")
128 parser.add_argument(
"-mp",
"--make_percentages", action=
"store_true")
129 parser.add_argument(
"-dt",
"--draw_text", action=
"store_true")
130 parser.add_argument(
"-ds",
"--drawstr", default=
None)
131 main(parser.parse_args())