2 from array
import array
3 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=
"beam_pdf.root")
8 parser.add_argument(
"-n", type=int, help=
'Max number of entries', default=-1)
9 parser.add_argument(
"-p", type=str, help=
'Which momentum', default=
"1")
10 args = parser.parse_args()
16 inputFile = RT.TFile(args.i,
"OPEN")
17 tree = inputFile.Get(
"beamreco/tree")
18 outputFile = RT.TFile(args.o,
"RECREATE")
20 nBins =
array(
"i", [100, 32, 32, 32, 32])
39 nBins =
array(
"i", [50, 32, 32, 32, 32])
43 mins =
array(
"d", [min_p, 0., 0., 0., 0.])
44 maxes =
array(
"d", [max_p, 192., 192., 192., 192.])
46 Pions = RT.THnSparseD(
"Pions",
"", 5, nBins, mins, maxes)
47 Protons = RT.THnSparseD(
"Protons",
"", 5, nBins, mins, maxes)
48 Electrons = RT.THnSparseD(
"Electrons",
"", 5, nBins, mins, maxes)
49 Kaons = RT.THnSparseD(
"Kaons",
"", 5, nBins, mins, maxes)
51 if args.p
in [
"0.5",
"1",
"2",
"3"]:
52 pdfs = [Pions, Protons, Electrons]
53 elif args.p
in [
"6",
"7"]:
54 pdfs = [Pions, Protons, Kaons]
59 max_entries = tree.GetEntries()
64 if counter >= max_entries:
break 65 f_v_up = [i
for i
in e.fibers_v_upstream]
66 f_h_up = [i
for i
in e.fibers_h_upstream]
67 f_v_down = [i
for i
in e.fibers_v_downstream]
68 f_h_down = [i
for i
in e.fibers_h_downstream]
71 pdgs = [i
for i
in e.possible_pdg]
74 if not (perfectP
and len(f_v_up) == 1
and len(f_h_up) == 1
and 75 len(f_v_down) == 1
and len(f_h_down) == 1
and len(pdgs) > 0):
78 if Momentum < min_p
or Momentum > max_p:
continue 80 data =
array(
"d", [Momentum, f_v_up[0], f_h_up[0], f_v_down[0], f_h_down[0]])
82 if args.p
in [
"1",
"2",
"0.5"]:
98 elif args.p
in [
"6",
"7"]:
111 if pdf.Projection(0).Integral() > 0:
112 pdf.Scale(1./pdf.Projection(0).Integral())
auto array(Array const &a)
Returns a manipulator which will print the specified array.