5 eclChargedPidDatabaseImporter.py :
6 script to perform fits of PDFs for ECL charged PID for different charged particle hypotheses,
7 and create a (local) DB payload.
10 __author__ =
"Marco Milesi"
11 __email__ =
"marco.milesi@unimelb.edu.au"
12 __maintainer__ =
"Marco Milesi"
13 __date__ =
"June 2018"
22 g_hypotheses = [11, -11, 13, -13, 211, -211, 321, -321, 2212, -2212]
24 parser = argparse.ArgumentParser(description=description)
26 parser.add_argument(
"inputpath",
29 help=
"Path to the directory where input histograms are stored.")
30 parser.add_argument(
"--noDB",
34 help=
"Do not create DB payload. Just for debugging.")
35 parser.add_argument(
"-or",
"--outputROOT",
39 help=
"Create an output ROOT file with the PDFs at the path given. Useful for debugging.")
40 parser.add_argument(
"-op",
"--outputplots",
44 help=
"Create plots for the fits in pdf format at the path given.")
46 args = parser.parse_args()
51 ROOT.gROOT.SetBatch(
True)
52 ROOT.gErrorIgnoreLevel = ROOT.kWarning
54 ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.WARNING)
55 ROOT.RooMsgService.instance().setSilentMode(
True)
57 from electrons_pdf
import fit_electron_eop
58 from muons_pdf
import fit_muon_eop
59 from pions_pdf
import fit_pion_eop
60 from kaons_pdf
import fit_kaon_eop
61 from protons_pdf
import fit_proton_eop
63 if __name__ ==
"__main__":
66 payload = ROOT.Belle2.ECLChargedPidPDFs()
71 pmin_vals = [300.0, 400.0, 500.0, 750.0, 1000.0, 1500.0, 2000.0, 3000.0, 4000.0, 4500.0, 5000.0]
72 thetamin_vals = [0.0, 17.0, 31.4, 32.2, 44.0, 117.0, 128.7, 130.7, 150.0]
76 payload.setEnergyUnit(ROOT.Belle2.Unit.MeV)
77 payload.setAngularUnit(ROOT.Belle2.Unit.deg)
79 arr_p = array.array(
"d", pmin_vals + [5500.0])
80 arr_theta = array.array(
"d", thetamin_vals + [180.0])
82 histgrid = ROOT.TH2F(
"binsgrid",
"bins grid;#theta_{lab};p_{lab} [MeV/c]", len(thetamin_vals), arr_theta, len(pmin_vals), arr_p)
84 xyg = ROOT.TF2(
"xyg",
"xygaus", thetamin_vals[0], 180.0, pmin_vals[0], 5500.0)
85 xyg.SetParameters(10000, 75.0, 65.0, 2500.0, 2000.0)
86 histgrid.FillRandom(
"xyg", 1000000)
87 histgrid.SetDirectory(0)
90 if not os.path.exists(args.outputROOT):
91 os.makedirs(args.outputROOT)
93 for hypo
in g_hypotheses:
96 payload.setBinsHist(hypo, histgrid)
99 append =
"" if hypo > 0
else "anti"
100 outROOT = ROOT.TFile(
"{0}/pdf_{1}{2}.root".format(args.outputROOT, append, abs(hypo)),
"RECREATE")
104 for ip, pmin
in enumerate(pmin_vals, 1):
109 pmax = pmin_vals[ip]
if ip <= pmin_vals.index(pmin_vals[-1])
else arr_p[-1]
111 for jth, thetamin
in enumerate(thetamin_vals, 1):
116 thetamax = thetamin_vals[jth]
if jth <= thetamin_vals.index(thetamin_vals[-1])
else arr_theta[-1]
118 params = {
"inputpath": args.inputpath,
122 "thetamin": thetamin,
123 "thetamax": thetamax,
126 "charge": hypo / abs(hypo),
127 "outputplots": args.outputplots
131 "Hypothesis: {0},\t{1:.2f} < p < {2:.2f},\t{3:.2f} < theta < {4:.2f}".format(
132 hypo, pmin, pmax, thetamin, thetamax))
135 pdf = fit_electron_eop(**params)
136 elif abs(hypo) == 13:
137 pdf = fit_muon_eop(**params)
138 elif abs(hypo) == 211:
139 pdf = fit_pion_eop(**params)
140 elif abs(hypo) == 321:
141 pdf = fit_kaon_eop(**params)
142 elif abs(hypo) == 2212:
143 pdf = fit_proton_eop(**params)
146 payload.setPDFsInternalMap(hypo, ip, jth, pdf)
152 payload.setPDFsMap(hypo)
155 ROOT.Belle2.Database.Instance().storeData(
"ECLChargedPidPDFs",
157 ROOT.Belle2.IntervalOfValidity.always())