2 from argparse
import ArgumentParser
as ap
6 parser.add_argument(
"-i", type=str, help=
'Input file', default =
"")
7 parser.add_argument(
"-o", type=str, help=
'Output file', default =
"angle_weight.root")
8 parser.add_argument(
"-t", type=int, help=
'Shift type', default=0)
9 parser.add_argument(
"-p", type=float, help=
'Position -- only for gaus', default=.5)
10 args = parser.parse_args()
12 f = RT.TFile(args.i,
"OPEN")
13 t = f.Get(
"pduneana/beamana")
15 end_p = [0., .4, .6, .8, 1.]
16 nbins = [ 5, 25, 25, 25, 10]
17 shifts = [ 2, 12, 12, 12, 5]
20 fout = RT.TFile(args.o,
"RECREATE")
25 bins = range(1, n_bins+1)
26 new_bins = [i + shift
for i
in range(1, len(bins)-shift+1)] + [i - len(bins) + shift
for i
in range(len(bins)-shift+1, len(bins)+1)]
29 for i
in range(1, 12):
34 for j
in range(1, h2.GetNbinsX()+1):
35 h2.SetBinContent(j, h.GetBinContent(h2.GetNbinsX() + 1 - j))
40 for j
in range(1, h2.GetNbinsX()+1):
41 h2.SetBinContent(j, 1.)
42 h2.Scale(1. / h2.Integral())
46 new_bins =
shift_bins(h_in.GetNbinsX(), shifts[i])
48 for j
in range(1, h2.GetNbinsX()+1):
49 h2.SetBinContent(j, h.GetBinContent(new_bins[j-1]))
50 h2.Scale(1. / h2.Integral())
54 n_bins = h_in.GetNbinsX()
58 for i
in range(1, n_bins+1):
59 h2.SetBinContent(i, exp(-.5*(((i - mean)/width)**2)))
60 h2.Scale(1. / h2.Integral())
64 for i
in range(1, h_in.GetNbinsX()+1):
65 if h_in.GetBinContent(i) == 0.:
66 print(h_in.GetName(),
"empty:", i)
78 print(
"error, unkown type", t)
80 for i
in range(1, len(end_p)):
81 print(
"hist", i,
"nbins:", nbins[i-1])
82 h = RT.TH1D(
"h" +
str(i),
"", nbins[i-1], -1., 1.)
83 t.Draw(
"(true_beam_daughter_startPz*true_beam_endPz + true_beam_daughter_startPx*true_beam_endPx + true_beam_daughter_startPy*true_beam_endPy)/(true_beam_daughter_startP*true_beam_endP)" +
86 "true_daughter_nPiPlus == 1 && true_daughter_nPiMinus == 0 && " +
87 "new_interaction_topology == 3 && true_beam_PDG == 211 && abs(true_beam_daughter_PDG) == 211 && true_beam_endP >= " +
str(end_p[i-1]) +
" && true_beam_endP < " +
str(end_p[i]))
89 h.Scale(1./h.Integral())
100 h2.Write(
"h" +
str(i) +
"_rev")
101 r.Write(
"r" + str(i)) 104 h = RT.TH1D("h" +
str(len(end_p)),
"", nbins[-1], -1., 1.)
105 t.Draw(
"(true_beam_daughter_startPz*true_beam_endPz + true_beam_daughter_startPx*true_beam_endPx + true_beam_daughter_startPy*true_beam_endPy)/(true_beam_daughter_startP*true_beam_endP)" +
106 ">>h" +
str(len(end_p)),
108 "true_daughter_nPiPlus == 1 && true_daughter_nPiMinus == 0 && " +
109 "new_interaction_topology == 3 && true_beam_PDG == 211 && abs(true_beam_daughter_PDG) == 211 && true_beam_endP >= " +
str(end_p[-1]))
111 h.Scale(1./h.Integral())
121 h2.Write(
"h" +
str(len(end_p)) +
"_rev")
122 r.Write(
"r" + str(len(end_p)))
def get_variation(h_in, t, j=0)
def shift_bins(n_bins, shift)