11from heavyFlavourScaling
import (
12 check_run_type_override,
13 derive_cross_sections,
17ROOT.gROOT.LoadMacro(
"$VMCWORKDIR/gconfig/basiclibs.C")
20ap = argparse.ArgumentParser(description=
"Decay charm/beauty signals from makeCascade output with Pythia8")
24 default=
"/eos/experiment/ship/data/Charm/Cascade-parp16-MSTP82-1-MSEL4-76Mpot_1",
25 help=
"input file with charm/beauty hadrons (.root suffix optional)",
27ap.add_argument(
"-p",
"--pot", type=float, default=5.0e13, help=
"number of protons on target per spill to normalise on")
29cross_section = ap.add_mutually_exclusive_group()
30cross_section.add_argument(
31 "-c",
"--chicc", type=float, default=
None, help=
"ccbar over mbias cross section (overrides target-derived value)"
33cross_section.add_argument(
34 "--chibb", type=float, default=
None, help=
"bbbar over mbias cross section (overrides target-derived value)"
37 "--target-composition",
40 help=
"Target composition. Default is Tungsten (W); Molybdenum (Mo) is the other preset.",
47 "Target mass number; overrides --target-composition preset. "
48 "Used to scale chicc/chibb as (A/A_Mo)^(heavyflavour_Ascale-mbias_Ascale) "
49 "(default exponent: 0.29)."
54fname = args.input.replace(
".root",
"")
57cs = derive_cross_sections(args.target_composition, args.A, args.chicc, args.chibb)
58chicc, chibb = cs.chicc, cs.chibb
60print(format_summary(cs,
None if args.A
is not None else args.target_composition))
63tmp = os.path.abspath(FIN).split(
"/")
64FOUT =
"Decay-" + tmp[len(tmp) - 1]
65fin = ROOT.TFile.Open(FIN)
66sTree = fin.FindObjectAny(
"pythia6")
67nEvents = sTree.GetEntries()
73 hc[
"2"] = fin.Get(
"2")
75 fhin = ROOT.TFile.Open(FIN.replace(
"ntuple",
"hists"))
76 hc[
"2"] = fhin.Get(
"2")
79nrcpot = hc[
"2"].GetBinContent(1) / 2.0
80print(
"Input file: ", FIN,
" with ", nEvents,
" entries, corresponding to nr-pot=", nrcpot)
82print(
"Output ntuples written to: ", FOUT)
84P8gen = ROOT.TPythia8()
86P8.readString(
"ProcessLevel:all = off")
91 n = P8.particleData.nextId(n)
92 p = P8.particleData.particleDataEntryPtr(n)
94 command = str(n) +
":mayDecay = false"
95 P8.readString(command)
96 print(
"Pythia8 configuration: Made %s stable for Pythia, should decay in Geant4" % p.name())
101ftup = ROOT.TFile.Open(FOUT,
"RECREATE")
102Ntup = ROOT.TNtuple(
"Decay",
"pythia8 heavy flavour decays",
"id:px:py:pz:E:M:weight:mid:mpx:mpy:mpz:mE:pot:ptGM:pzGM")
107PDG = ROOT.TDatabasePDG.Instance()
108for idnu
in range(12, 18, 2):
110 for idadd
in range(-1, 3, 2):
116 _p = ut.get_particle(idw)
118 ut.bookHist(h, str(idhnu), name +
" momentum (GeV)", 400, 0.0, 400.0)
119 ut.bookHist(h, str(idhnu + 100), name +
" log10-p vs log10-pt", 100, -0.3, 1.7, 100, -2.0, 0.5)
120 ut.bookHist(h, str(idhnu + 200), name +
" log10-p vs log10-pt", 25, -0.3, 1.7, 100, -2.0, 0.5)
128for n
in range(nEvents):
129 rc = sTree.GetEvent(n)
132 is_beauty = sTree.M > 5
133 check_run_type_override(is_beauty, args.chicc, args.chibb)
136 print(
"automatic detection of beauty, configured for beauty")
137 print(
"bb cross section / mbias ", chicc)
139 print(
"cc cross section / mbias ", chicc)
141 print(
"weights: ", nrpotspill,
" p.o.t. per spill")
143 wspill = nrpotspill * chicc / nrcpot
145 pt = ROOT.TMath.Sqrt(sTree.mpx**2 + sTree.mpy**2)
147 if pt < 1.0e-5
and int(sTree.mid) == 2212:
150 idabs = int(abs(sTree.id))
154 P8.event.append(int(sTree.id), 1, 0, 0, sTree.px, sTree.py, sTree.pz, sTree.E, sTree.M, 0.0, 9.0)
157 for n
in range(len(P8.event)):
159 if P8.event[n].isFinal():
161 idabs = int(abs(P8.event[n].id()))
162 if idabs > 11
and idabs < 17:
164 ptGM = ROOT.TMath.Sqrt(sTree.mpx * sTree.mpx + sTree.mpy * sTree.mpy)
183 if idabs == 16
or idabs == 14
or idabs == 12:
187 pt2 = par.px() ** 2 + par.py() ** 2
188 ptot = ROOT.TMath.Sqrt(pt2 + par.pz() ** 2)
189 l10ptot = min(max(ROOT.TMath.Log10(ptot), -0.3), 1.69999)
190 l10pt = min(max(ROOT.TMath.Log10(ROOT.TMath.Sqrt(pt2)), -2.0), 0.4999)
191 h[str(idhnu)].Fill(ptot, wspill)
192 h[str(idhnu + 100)].Fill(l10ptot, l10pt, wspill)
193 h[str(idhnu + 200)].Fill(l10ptot, l10pt, wspill)
195print(
"Now at Ntup.Write() for pot=", pot, nrcpot)
196if (1.0 - pot / nrcpot) < 1.0e-2:
197 print(
"write ntuple, weight/event=", nrpotspill,
"x", chicc,
"/", nrcpot,
"=", wspill)
202 print(
"Neutrino statistics/spill of 5.e15 pot:")
203 for idnu
in range(12, 18, 2):
205 for idadd
in range(-1, 3, 2):
211 print(idhnu, h[str(idhnu)].GetTitle(), (
"%8.3E " % (h[str(idhnu)].Integral())))
213 fDsP6 = 1.0 * nDsprim / ntotprim
216 print(
"fDs of primary proton interactions in P6=", fDsP6,
" should be ", fDs)
219 print(
"*********** WARNING ***********")
220 print(
"number of POT does not agree between ntuple and hists, i.e.:", pot,
"<>", nrcpot)
221 print(
"mu/neutrino ntuple has NOT been written")