10from array
import array
15ROOT.gROOT.LoadMacro(
"$VMCWORKDIR/gconfig/basiclibs.C")
17timer = ROOT.TStopwatch()
20ap = argparse.ArgumentParser(description=
"Run SHiP makeCascade: generate ccbar or bbar")
25 default=
int(time.time() * 100000000 % 900000000),
26 help=
"Random number seed, integer. If not given, current time will be used",
32 help=
"Name of ntuple output file, default: Cascade{nevgen/1000}k-parp16-MSTP82-1-MSEL{mselcb}-ntuple.root",
34ap.add_argument(
"-n",
"--nevgen", type=int, default=100000, help=
"Number of events to produce, default 100000")
35ap.add_argument(
"-E",
"--pbeamh", type=float, default=400.0, help=
"Energy of beam in GeV, default 400 GeV")
37 "-m",
"--mselcb", type=int, default=4, help=
"4 (5): charm (beauty) production, default charm", choices=[4, 5]
42 action=argparse.BooleanOptionalAction,
44 help=
"If this argument is used, store all particles produced together with charm.",
47 "--target_composition",
49 help=
"Target composition (to determine the ratio of protons in the material). Default is Tungsten (W). Only other choice is Molybdenum (Mo)",
55 help=
"Choices of Pythia tune are PoorE791 (default, settings with default Pythia6 pdf, based on getting <pt> at 500 GeV pi-) or LHCb (settings by LHCb for Pythia 6.427)",
56 choices=[
"PoorE791",
"LHCb"],
59ap.add_argument(
"--nev", type=int, default=5000, help=
"Events / momentum")
60ap.add_argument(
"--nrpoints", type=int, default=20, help=
"Number of momentum points taken to calculate sig/sigtot")
64 args.Fntuple = f
"Cascade{int(args.nevgen / 1000)}k-parp16-MSTP82-1-MSEL{args.mselcb}-ntuple.root"
66print(f
"Generate {args.nevgen} p.o.t. with msel = {args.mselcb} proton beam {args.pbeamh}GeV")
67print(f
"Output ntuples written to: {args.Fntuple}")
70idbeam = [2212, 211, 2112, 321, 130, 310]
72print(f
"Chi generation with {args.nev} events/point, nr points={args.nrpoints}")
73print(f
"Cascade beam particle: {idbeam}")
76if args.target_composition ==
"W":
81print(f
"Target particles: {target}, fraction of protons in {args.target_composition}={fracp}")
87 idsig = [411, 421, 431, 4122, 4132, 4232, 4332, 4412, 4414, 4422, 4424, 4432, 4434, 4444]
121 print(f
"Error: msel is unknown: {args.mselcb}, STOP program")
122 sys.exit(
"ERROR on input, exit")
124PDG = ROOT.TDatabasePDG.Instance()
125myPythia = ROOT.TPythia6()
126tp = ROOT.tPythia6Generator()
129PDG.GetParticle(2212).SetName(
"p+")
130PDG.GetParticle(-2212).SetName(
"pbar-")
131PDG.GetParticle(2112).SetName(
"n0")
132PDG.GetParticle(-2112).SetName(
"nbar0")
133PDG.GetParticle(130).SetName(
"KL0")
134PDG.GetParticle(310).SetName(
"KS0")
136myPythia.SetPARP(2, 2.0)
143 print(
"********** PoorE791_tune **********")
146 print(f
"PARP(91)={P6.GetPARP(91)}")
148 print(
"MSTP PDF info, i.e. (51) and (52)=", P6.GetMSTP(51), P6.GetMSTP(52))
151 P6.SetPARP(89, 1000.0)
153 "And corresponding multiple parton stuff, i.e. MSTP(82),PARP(81,89,90)=",
159 print(
"********** PoorE791_tune **********")
167 print(
"********** LHCb_tune **********")
175 P6.SetMSTP(51, 10042)
179 P6.SetPARP(89, 14000)
180 P6.SetPARP(90, 0.238)
184 P6.SetPARP(149, 0.02)
185 P6.SetPARP(150, 0.085)
188 P6.SetPARJ(13, 0.769)
190 P6.SetPARJ(15, 0.018)
191 P6.SetPARJ(16, 0.0815)
192 P6.SetPARJ(17, 0.0815)
195 print(
"********** LHCb_tune **********")
201 nb = hist.GetNbinsX()
202 i1 = hist.FindBin(pbeaml, 0.0, 0.0)
203 y1 = hist.GetBinContent(i1)
204 p1 = hist.GetBinCenter(i1)
205 for i
in range(i1 + 1, nb + 1):
206 if hist.GetBinContent(i) > 0.0:
207 y2 = hist.GetBinContent(i)
208 p2 = hist.GetBinCenter(i)
209 tg = (y2 - y1) / (p2 - p1)
210 for ib
in range(i1 + 1, i):
211 px = hist.GetBinCenter(ib)
212 yx = (px - p1) * tg + y1
219if args.pythia_tune ==
"PoorE791":
221 myPythia.OpenFortranFile(11, os.devnull)
222 myPythia.SetMSTU(11, 11)
225 myPythia.OpenFortranFile(6, os.devnull)
228print(f
"Setting random number seed = {args.seed}")
229myPythia.SetMRPY(1, args.seed)
239idhist = len(idbeam) * 4 * [0]
240print(
"Get chi vs momentum for all beam+target particles")
241for idp
in range(0, len(idbeam)):
243 idw = idbeam[idp] * idpm
244 if PDG.GetParticle(idw)
is not None:
245 name = PDG.GetParticle(idw).GetName()
247 for idnp
in range(2):
248 idb = id * 10 + idnp * 4
249 ut.bookHist(h, str(idb + 1), f
"sigma vs p, {name} -> {target[idnp]}", nb, 0.5, args.pbeamh + 0.5)
250 ut.bookHist(h, str(idb + 2), f
"sigma-tot vs p, {name} -> {target[idnp]}", nb, 0.5, args.pbeamh + 0.5)
251 ut.bookHist(h, str(idb + 3), f
"chi vs p, {name}-> {target[idnp]}", nb, 0.5, args.pbeamh + 0.5)
252 ut.bookHist(h, str(idb + 4), f
"Prob(normalised), {name} -> {target[idnp]}", nb, 0.5, args.pbeamh + 0.5)
255 for idpn
in range(2):
257 print(f
"{name}, {target[idpn]}, for chi, seconds: {time.time() - t0}")
258 for ipbeam
in range(args.nrpoints):
259 pbw = ipbeam * (args.pbeamh - pbeaml) / (args.nrpoints - 1) + pbeaml
261 ibin = h[str(id * 10 + 1 + idadd)].FindBin(pbw, 0.0, 0.0)
262 pbw = h[str(id * 10 + 1 + idadd)].GetBinCenter(ibin)
264 myPythia.SetMSEL(args.mselcb)
265 myPythia.Initialize(
"FIXT", name, target[idpn], pbw)
266 for iev
in range(args.nev):
267 myPythia.GenerateEvent()
269 h[str(id * 10 + 1 + idadd)].Fill(pbw, tp.getPyint5_XSEC(2, 0))
271 myPythia.Initialize(
"FIXT", name, target[idpn], pbw)
272 for iev
in range(args.nev // 10):
274 myPythia.GenerateEvent()
276 h[str(id * 10 + 2 + idadd)].Fill(pbw, tp.getPyint5_XSEC(2, 0))
278 h[str(id * 10 + 3 + idadd)].Divide(h[str(id * 10 + 1 + idadd)], h[str(id * 10 + 2 + idadd)], 1.0, 1.0)
280 fillp1(h[str(id * 10 + 3 + idadd)])
284for i
in range(1, id + 1):
285 for idpn
in range(2):
286 idw = i * 10 + idpn * 4 + 3
287 ibh = h[str(idw)].FindBin(args.pbeamh)
289 f
"beam id: {i}, {idw}, {idhist[i]}, momentum: {args.pbeamh},chi: {h[str(idw)].GetBinContent(ibh)}, chimx: {chimx}"
291 if h[str(idw)].GetBinContent(ibh) > chimx:
292 chimx = h[str(idw)].GetBinContent(ibh)
294for i
in range(1, id + 1):
295 for idpn
in range(2):
296 idw = i * 10 + idpn * 4 + 3
297 h[str(idw + 1)].Add(h[str(idw)], h[str(idw)], chimx, 0.0)
302ut.bookHist(h, str(1),
"E of signals", 100, 0.0, 400.0)
303ut.bookHist(h, str(2),
"nr signal per cascade depth", 50, 0.5, 50.5)
304ut.bookHist(h, str(3),
"D0 pt**2", 40, 0.0, 4.0)
305ut.bookHist(h, str(4),
"D0 pt**2", 100, 0.0, 18.0)
306ut.bookHist(h, str(5),
"D0 pt", 100, 0.0, 10.0)
307ut.bookHist(h, str(6),
"D0 XF", 100, -1.0, 1.0)
309ftup = ROOT.TFile.Open(args.Fntuple,
"RECREATE")
312 "pythia6 heavy flavour",
313 "id:px:py:pz:E:M:mid:mpx:mpy:mpz:mE:mM:k:a0:a1:a2:a3:a4:a5:a6:a7:a8:a9:a10:a11:a12:a13:a14:a15:\
314s0:s1:s2:s3:s4:s5:s6:s7:s8:s9:s10:s11:s12:s13:s14:s15",
319 kc = myPythia.Pycomp(kf)
320 myPythia.SetMDCY(kc, 1, 0)
323 kc = myPythia.Pycomp(kf)
324 myPythia.SetMDCY(kc, 1, 0)
327for iev
in range(args.nevgen):
329 print(
"Generate event ", iev)
333 stack[nstack] = [2212, 0.0, 0.0, args.pbeamh, 1, 100 * [0], 100 * [0]]
334 stack[nstack][5][0] = 2212
337 ptot = ROOT.TMath.Sqrt(stack[nstack][1] ** 2 + stack[nstack][2] ** 2 + stack[nstack][3] ** 2)
339 for i
in range(1, id + 1):
340 if stack[nstack][0] == idhist[i]:
342 if random.random() > fracp:
344 idw = i * 10 + idpn * 4 + 4
345 ib = h[str(idw)].FindBin(ptot, 0.0, 0.0)
346 prbsig = h[str(idw)].GetBinContent(ib)
347 if prbsig > random.random():
349 for k
in range(1, 4):
350 myPythia.SetP(1, k, stack[nstack][k])
351 myPythia.SetP(2, k, 0.0)
353 myPythia.SetMSEL(args.mselcb)
354 myPythia.Initialize(
"3MOM", PDG.GetParticle(stack[nstack][0]).GetName(), target[idpn], 0.0)
355 myPythia.GenerateEvent()
358 for itrk
in range(1, myPythia.GetN() + 1):
359 idabs = ROOT.TMath.Abs(myPythia.GetK(itrk, 2))
362 vl.append(
float(myPythia.GetK(itrk, 2)))
363 for i
in range(1, 6):
364 vl.append(
float(myPythia.GetP(itrk, i)))
365 vl.append(
float(myPythia.GetK(1, 2)))
366 for i
in range(1, 6):
367 vl.append(
float(myPythia.GetP(1, i)))
368 vl.append(
float(stack[nstack][4]))
370 vl.append(
float(stack[nstack][5][i]))
371 nsub = stack[nstack][4] - 1
374 for i
in range(nsub):
375 vl.append(
float(stack[nstack][6][i]))
376 vl.append(
float(myPythia.GetMSTI(1)))
377 for i
in range(nsub + 1, 16):
380 charmFound.append(itrk)
381 h[
"1"].Fill(myPythia.GetP(itrk, 4))
382 h[
"2"].Fill(stack[nstack][4])
383 if idabs == 421
and stack[nstack][4] == 1:
385 pt2 = myPythia.GetP(itrk, 1) ** 2 + myPythia.GetP(itrk, 2) ** 2
388 h[
"5"].Fill(ROOT.TMath.Sqrt(pt2))
390 beta = args.pbeamh / (myPythia.GetP(1, 4) + myPythia.GetP(2, 5))
391 gamma = (1 - beta**2) ** (-0.5)
392 pbcm = -gamma * beta * myPythia.GetP(1, 4) + gamma * myPythia.GetP(1, 3)
393 pDcm = -gamma * beta * myPythia.GetP(itrk, 4) + gamma * myPythia.GetP(itrk, 3)
396 if len(charmFound) > 0
and args.storePrimaries:
397 for itP
in range(1, myPythia.GetN() + 1):
398 if itP
in charmFound:
400 if myPythia.GetK(itP, 1) == 1:
404 float(myPythia.GetK(itP, 2)),
405 float(myPythia.GetP(itP, 1)),
406 float(myPythia.GetP(itP, 2)),
407 float(myPythia.GetP(itP, 3)),
408 float(myPythia.GetP(itP, 4)),
409 float(myPythia.GetP(itP, 5)),
411 float(myPythia.GetV(itP, 1) - myPythia.GetV(charmFound[0], 1)),
412 float(myPythia.GetV(itP, 2) - myPythia.GetV(charmFound[0], 2)),
413 float(myPythia.GetV(itP, 3) - myPythia.GetV(charmFound[0], 3)),
420 for k
in range(1, 4):
421 myPythia.SetP(1, k, stack[nstack][k])
422 myPythia.SetP(2, k, 0.0)
426 if random.random() > fracp:
428 myPythia.Initialize(
"3MOM", PDG.GetParticle(stack[nstack][0]).GetName(), target[idpn], 0.0)
429 myPythia.GenerateEvent()
432 icas = stack[nstack][4] + 1
435 anclist = copy.copy(stack[nstack][5])
436 sublist = copy.copy(stack[nstack][6])
439 sublist[0] = myPythia.GetMSTI(1)
441 for itrk
in range(1, myPythia.GetN() + 1):
442 if myPythia.GetK(itrk, 1) == 1:
443 ptot = ROOT.TMath.Sqrt(
444 myPythia.GetP(itrk, 1) ** 2 + myPythia.GetP(itrk, 2) ** 2 + myPythia.GetP(itrk, 3) ** 2
448 for isig
in range(len(idbeam)):
449 if ROOT.TMath.Abs(myPythia.GetK(itrk, 2)) == idbeam[isig]
and nstack < 999:
453 tmp = copy.copy(anclist)
454 tmp[icas - 1] = myPythia.GetK(itrk, 2)
455 stmp = copy.copy(sublist)
457 stmp[icas - 1] = myPythia.GetMSTI(1)
459 myPythia.GetK(itrk, 2),
460 myPythia.GetP(itrk, 1),
461 myPythia.GetP(itrk, 2),
462 myPythia.GetP(itrk, 3),
468print(
"Now at Ntup.Write()")
475rtime = timer.RealTime()
476ctime = timer.CpuTime()
478print(
"Macro finished successfully.")
479print(f
"Output file is {ftup.GetName()}")
480print(f
"Real time {rtime} s, CPU time {ctime} s")