20endOfHadronAbsorber = (ship_geo[
"muShield"].Entrance[0] + 2 * ship_geo[
"muShield"].half_length[0]) / 100.0
52 ut.bookCanvas(h, key=
"P", title=
"momentum", nx=1800, ny=1200, cx=3, cy=2)
53 ut.bookCanvas(h, key=
">P", title=
"N >P", nx=1800, ny=1200, cx=3, cy=2)
54 ut.bookCanvas(h, key=
"PT", title=
"Pt", nx=1800, ny=1200, cx=3, cy=2)
55 ut.bookCanvas(h, key=
">PT", title=
"N >Pt", nx=1800, ny=1200, cx=3, cy=2)
62 "nutaubar":
"id==-16",
67 "nuesum":
"abs(id)==12",
68 "numusum":
"abs(id)==14",
69 "nutausum":
"abs(id)==16",
73 "charm":
"&(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
74 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )",
77 for x
in [
"",
"charm"]:
82 ut.bookHist(h, hn, p +
" ;p [GeV] ;N", 400, 0.0, 400.0)
83 ut.bookHist(h, hnt, p +
" ;pt [GeV] ;N", 40, 0.0, 4.0)
84 sTree.Draw(
"sqrt(px**2+py**2+pz**2)>>" + hn,
"w*(" + cuts[q] + OpenCharm[x] +
")",
"goff")
85 sTree.Draw(
"sqrt(px**2+py**2)>>" + hnt,
"w*(" + cuts[q] + OpenCharm[x] +
")",
"goff")
91 for q
in [
"mu",
"mu-",
"mu+",
"nu",
"nue",
"nuesum",
"nuebar",
"numusum",
"numu",
"numubar",
"nutau",
"nutaubar"]:
92 for x
in [
"",
"charm"]:
96 h[hi] = h[
"T" + p].Clone(hi)
99 for i
in range(h[hi].GetNbinsX() + 1, 0, -1):
100 nsum += h[
"T" + p].GetBinContent(i)
101 h[hi].SetBinContent(i, nsum)
102 for z
in [
"p",
"pt"]:
104 for x
in [
"mu",
"nu"]:
110 if h[
"T" + p].GetEntries() >= 1:
111 if not p.find(
"mu") < 0:
112 h[
"T" + p +
"+"].Draw(
"same")
113 h[
"T" + p +
"-"].Draw(
"same")
114 cv = h[
">" + t].cd(k)
116 h[
"T" + p +
"_>E"].Draw()
124 h[
"tlnu" + z + str(k)] = ROOT.TLegend(0.49, 0.13, 0.88, 0.36)
125 for p
in [
"numu",
"numubar",
"nue",
"nuebar",
"nutau",
"nutaubar"]:
127 h[
"tlnu" + z + str(k)].AddEntry(h[hn], z +
" " + p,
"PL")
128 h[hn].SetLineColor(i)
129 h[hn +
"8"] = h[hn].Clone()
130 h[hn +
"8"].SetName(hn +
"8")
136 h[hn +
"8"].Draw(
"same")
137 h[
"tlnu" + z + str(k)].Draw()
147 "stats": {1.0: [1.1e8], 10.0: [1.22e9], 100: [1.27e10]},
151 productions[
"Yandex"] = {
"stats": {5.0: [2.1e9, 1e9], 0.5: [1e8]},
"file":
"Mbias/pythia8_Geant4_total_Yandex.root"}
178 for p
in productions:
179 f = ROOT.TFile.Open(eospath + productions[p][
"file"])
180 t = f.FindObjectAny(
"pythia8-Geant4")
184 for leaf
in t.GetListOfLeaves():
186 tuples += leaf.GetName()
188 tuples +=
":" + leaf.GetName()
189 fxx = fnew.replace(
".root", opt +
".root")
191 fxx = fnew.replace(
".root",
"old-charm.root")
192 h[
"N"] = ROOT.TFile(fxx,
"RECREATE")
193 print(
"new file created", fxx)
194 h[
"ntuple"] = ROOT.TNtuple(
"pythia8-Geant4",
"min bias flux after 3m hadron absorber " + opt, tuples)
198 t.Draw(
">>temp", cuts[opt] +
"&" + OpCharm)
200 t.Draw(
">>temp", cuts[opt] +
"&" + noOpCharm)
201 temp = ROOT.gROOT.FindObjectAny(
"temp")
204 leaves = t.GetListOfLeaves()
205 nL = leaves.GetEntries()
206 for iev
in range(nev):
207 t.GetEntry(temp.GetEntry(iev))
212 if nL > 11
and (k == 7
or k == 8
or k == 9):
214 vlist.append(leaves.At(x).GetValue())
216 print(
"this should never happen, big error", len(vlist), k, p, iev, nev)
217 raise RuntimeError(f
"unexpected vlist length: {len(vlist)}")
221 Psq = vlist[1] ** 2 + vlist[2] ** 2 + vlist[3] ** 2
222 if abs(vlist[0]) == 13:
223 Ekin = ROOT.TMath.Sqrt(Mmu2 + Psq) - Mmu
225 Ekin = ROOT.TMath.Sqrt(Psq)
239 vlist[9] = norm / (pot[
"CERN-Cracow"][100.0] + pot[
"Yandex"][5.0] + pot[
"Yandex2"][10.0])
241 vlist[9] = norm / (pot[
"CERN-Cracow"][10.0] + pot[
"Yandex"][5.0] + pot[
"Yandex2"][10.0])
243 vlist[9] = norm / (pot[
"CERN-Cracow"][1.0] + pot[
"Yandex"][5.0])
245 vlist[9] = norm / (pot[
"CERN-Cracow"][1.0] + pot[
"Yandex"][0.5])
247 vlist[9] = norm / (pot[
"Yandex"][0.5])
249 print(
"this should not happen, except some rounding errors", p, Ekin, vlist[9])
250 vlist[6] = endOfHadronAbsorber
282 f = ROOT.TFile.Open(eospath + productions[p][
"file"])
283 t = f.FindObjectAny(
"pythia8-Geant4")
288 for leaf
in t.GetListOfLeaves():
290 tuples += leaf.GetName()
292 tuples +=
":" + leaf.GetName()
293 h[
"N"] = ROOT.TFile(fnew,
"RECREATE")
294 print(
"new file created", fnew)
295 h[
"ntuple"] = ROOT.TNtuple(
"pythia8-Geant4", t.GetTitle() +
" no charm", tuples)
298 t.Draw(
">>temp", noOpCharm)
299 temp = ROOT.gROOT.FindObjectAny(
"temp")
302 leaves = t.GetListOfLeaves()
304 for iev
in range(nev):
305 t.GetEntry(temp.GetEntry(iev))
307 for x
in range(leaves.GetEntries()):
308 vlist.append(leaves.At(x).GetValue())
309 h[
"ntuple"].Fill(vlist)
320 fcascade = ROOT.TFile.Open(eospath +
"/Charm/Decay-Cascade-parp16-MSTP82-1-MSEL4-76Mpot_1.root")
322 newFile = ROOT.TFile(
"pythia8_Charm.root",
"RECREATE")
324 "pythia8-Geant4",
"mu/nu flux from charm",
"id:px:py:pz:x:y:z:opx:opy:opz:ox:oy:oz:pythiaid:parentid:w:ecut"
326 for n
in range(t.GetEntries()):
328 ztarget = rnr.Exp(0.16) + startOfTarget
356 os.system(
"hadd -f pythia8_Geant4-withCharm.root pythia8_Geant4-noOpenCharm.root pythia8_Charm.root")
357 print(
" progress: minbias and charm merged")
361 event = ROOT.std.vector(
"float")
362 f = ROOT.TFile(
"pythia8_Geant4-withCharm.root")
363 t = f.FindObjectAny(
"pythia8-Geant4")
364 leaves = t.GetListOfLeaves()
365 L = leaves.GetEntries()
368 for n
in range(t.GetEntries()):
371 print(
"status read", m)
375 a.push_back(leaves.At(idx).GetValue())
379 for n
in range(len(allEvents)):
381 random.shuffle(evList)
382 leaves = t.GetListOfLeaves()
386 tuples += leaf.GetName()
388 tuples +=
":" + leaf.GetName()
389 newFile = ROOT.TFile(
"pythia8_Geant4-withCharm-ram.root",
"RECREATE")
390 randomTuple = ROOT.TNtuple(t.GetName(), t.GetTitle(), tuples)
395 print(
"status write", m)
400 randomTuple.Fill(vlist)
406 print(
" progress: order of events randomized")
409 cuts = {
"_onlyNeutrinos":
"abs(id)==12||abs(id)==14||abs(id)==16",
"_onlyMuons":
"abs(id)==13"}
410 fName =
"pythia8_Geant4-withCharm-ram.root"
411 f = ROOT.TFile(fName)
412 t = f.FindObjectAny(
"pythia8-Geant4")
415 for idnu
in [16, -16, 14, -14, 12, -12]:
416 _p = ut.get_particle(idnu)
420 idhnu = 2000 + abs(idnu)
421 ut.bookHist(h, str(idhnu), name +
" momentum (GeV)", 400, 0.0, 400.0)
422 ut.bookHist(h, str(idhnu + 100), name +
" log10(ptot) vs log10(pt+0.01)", 100, -0.3, 1.7, 100, -2.0, 1.0)
423 ut.bookHist(h, str(idhnu + 200), name +
" log10(ptot) vs log10(pt+0.01)", 25, -0.3, 1.7, 100, -2.0, 1.0)
424 leaves = t.GetListOfLeaves()
427 tuples += leaf.GetName()
429 tuples +=
":" + leaf.GetName()
431 fxx = fName.replace(
"-ram.root", opt +
".root")
432 N = ROOT.TFile(fxx,
"RECREATE")
433 ntuple = ROOT.TNtuple(
"pythia8-Geant4", opt.replace(
"_only",
"") +
" flux mbias and charm" + opt, tuples)
436 t.Draw(
">>temp", cuts[opt])
437 temp = ROOT.gROOT.FindObjectAny(
"temp")
439 for iev
in range(temp.GetN()):
440 t.GetEntry(temp.GetEntry(iev))
442 for n
in range(leaves.GetSize()):
443 vlist.append(leaves.At(n).GetValue())
445 if "Neutrinos" in opt:
446 pt2 = t.px**2 + t.py**2
447 ptot = ROOT.TMath.Sqrt(pt2 + t.pz**2)
448 l10ptot = min(max(ROOT.TMath.Log10(ptot), -0.3), 1.69999)
449 l10pt = min(ROOT.TMath.Log10(ROOT.TMath.Sqrt(pt2) + 0.01), 0.9999)
453 idhnu = 2000 + abs(idnu)
454 h[str(idhnu)].Fill(ptot, t.w)
455 h[str(idhnu + 100)].Fill(l10ptot, l10pt, t.w)
456 h[str(idhnu + 200)].Fill(l10ptot, l10pt, t.w)
460 if "Neutrinos" in opt:
462 cln = h[akey].Class().GetName()
463 if not cln.find(
"TH") < 0:
466 print(
" progress: split " + opt)
476 test(eospath +
"pythia8_Geant4_onlyMuons.root")
477 for x
in [
"",
"_>E"]:
478 for z
in [
"p",
"pt"]:
479 for ahist
in [
"mu-",
"mu+",
"mu",
"mu-charm",
"mu+charm",
"mucharm"]:
480 h[
"TP" + z + ahist + x] = h[
"T" + z + ahist + x].Clone(
"CT" + ahist + x)
481 test(eospath +
"pythia8_Geant4_Yandex_onlyNeutrinos.root")
482 for x
in [
"",
"_>E"]:
483 for z
in [
"p",
"pt"]:
498 h[
"TP" + z + ahist + x] = h[
"T" + z + ahist + x].Clone(
"CT" + ahist + x)
499 test(eospath +
"Mbias/pythia8_Geant4-withCharm-ram.root")
500 for x
in [
"",
"_>E"]:
501 for z
in [
"p",
"pt"]:
507 h[
"T" + p + x].SetTitle(
"musum")
508 h[
"T" + p + x].Draw()
509 h[
"T" + p +
"charm" + x].Draw(
"same")
510 h[
"TP" + p + x].Draw(
"same")
511 h[
"TP" + p + x].SetLineColor(6)
512 h[
"TP" + p +
"charm" + x].Draw(
"same")
513 h[
"TP" + p +
"charm" + x].SetLineColor(3)
514 h[
"T" + p +
"charm" + x].SetLineColor(2)
515 h[
"T" + p + x].SetLineColor(4)
516 h[
"L" + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
517 h[
"L" + p + x].AddEntry(h[
"T" + p + x],
"muon new with charm, cascade, k-fac",
"PL")
518 h[
"L" + p + x].AddEntry(h[
"T" + p +
"charm" + x],
"muon from charm new with charm, cascade, k-fac",
"PL")
519 h[
"L" + p + x].AddEntry(h[
"TP" + p + x],
"muon old CERN-Cracow prod",
"PL")
520 h[
"L" + p + x].AddEntry(h[
"TP" + p +
"charm" + x],
"muon from charm old CERN-Cracow prod",
"PL")
521 h[
"L" + p + x].Draw()
524 h[
"T" + p + x].Draw()
525 h[
"T" + p +
"charm" + x].Draw(
"same")
526 h[
"TP" + p + x].Draw(
"same")
527 h[
"TP" + p + x].SetLineColor(6)
528 h[
"TP" + p +
"charm" + x].Draw(
"same")
529 h[
"TP" + p +
"charm" + x].SetLineColor(3)
530 h[
"T" + p +
"charm" + x].SetLineColor(2)
531 h[
"T" + p + x].SetLineColor(4)
532 h[
"L" + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
533 h[
"L" + p + x].AddEntry(h[
"T" + p + x],
"nu_mu new with charm, cascade, k-fac",
"PL")
534 h[
"L" + p + x].AddEntry(h[
"T" + p +
"charm" + x],
"nu_mu from charm new with charm, cascade, k-fac",
"PL")
535 h[
"L" + p + x].AddEntry(h[
"TP" + p + x],
"nu_mu old CERN-Cracow prod",
"PL")
536 h[
"L" + p + x].AddEntry(h[
"TP" + p +
"charm" + x],
"nu_mu from charm old CERN-Cracow prod",
"PL")
537 h[
"L" + p + x].Draw()
541 h[
"T" + p + x].Draw()
542 h[
"T" + p +
"charm" + x].Draw(
"same")
543 h[
"TP" + p + x].Draw(
"same")
544 h[
"TP" + p + x].SetLineColor(6)
545 h[
"TP" + p +
"charm" + x].Draw(
"same")
546 h[
"TP" + p +
"charm" + x].SetLineColor(3)
547 h[
"T" + p +
"charm" + x].SetLineColor(2)
548 h[
"T" + p + x].SetLineColor(4)
549 h[
"L" + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
550 h[
"L" + p + x].AddEntry(h[
"T" + p + x],
"nu_e new with charm, cascade, k-fac",
"PL")
551 h[
"L" + p + x].AddEntry(h[
"T" + p +
"charm" + x],
"nu_e from charm new with charm, cascade, k-fac",
"PL")
552 h[
"L" + p + x].AddEntry(h[
"TP" + p + x],
"nu_e old CERN-Cracow prod",
"PL")
553 h[
"L" + p + x].AddEntry(h[
"TP" + p +
"charm" + x],
"nu_e from charm old CERN-Cracow prod",
"PL")
554 h[
"L" + p + x].Draw()
558 h[
"Lmuc" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
560 h[
"T" + p + x].SetTitle(
"mu-/mu+")
561 h[
"T" + p + x].Draw()
562 h[
"TP" + p + x].Draw(
"same")
563 h[
"TP" + p + x].SetLineColor(6)
564 h[
"T" + p + x].SetLineColor(4)
565 h[
"Lmuc" + z + x].AddEntry(h[
"T" + p + x],
"mu- new with charm, cascade, k-fac",
"PL")
566 h[
"Lmuc" + z + x].AddEntry(h[
"TP" + p + x],
"mu- old Yandex prod",
"PL")
568 h[
"T" + p + x].Draw(
"same")
569 h[
"TP" + p + x].Draw(
"same")
570 h[
"TP" + p + x].SetLineColor(3)
571 h[
"T" + p + x].SetLineColor(2)
572 h[
"Lmuc" + z + x].AddEntry(h[
"T" + p + x],
"mu+ new with charm, cascade, k-fac",
"PL")
573 h[
"Lmuc" + z + x].AddEntry(h[
"TP" + p + x],
"mu+ old Yandex prod",
"PL")
574 h[
"Lmuc" + z + x].Draw()
578 h[
"Lnumu" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
580 h[
"T" + p + x].SetTitle(
"numu/numubar")
581 h[
"T" + p + x].Draw()
582 h[
"TP" + p + x].Draw(
"same")
583 h[
"TP" + p + x].SetLineColor(6)
584 h[
"T" + p + x].SetLineColor(4)
585 h[
"Lnumu" + z + x].AddEntry(h[
"T" + p + x],
"nu_mu new with charm, cascade, k-fac",
"PL")
586 h[
"Lnumu" + z + x].AddEntry(h[
"TP" + p + x],
"nu_mu old Yandex prod",
"PL")
588 h[
"T" + p + x].Draw(
"same")
589 h[
"TP" + p + x].Draw(
"same")
590 h[
"TP" + p + x].SetLineColor(3)
591 h[
"T" + p + x].SetLineColor(2)
592 h[
"Lnumu" + z + x].AddEntry(h[
"T" + p + x],
"anti nu_mu new with charm, cascade, k-fac",
"PL")
593 h[
"Lnumu" + z + x].AddEntry(h[
"TP" + p + x],
"anti nu_mu old Yandex prod",
"PL")
594 h[
"Lnumu" + z + x].Draw()
598 h[
"Lnue" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
599 h[
"T" + p + x].SetTitle(
"nue/nuebar")
600 h[
"T" + p + x].Draw()
601 h[
"TP" + p + x].Draw(
"same")
602 h[
"TP" + p + x].SetLineColor(6)
603 h[
"T" + p + x].SetLineColor(4)
604 h[
"Lnue" + z + x].AddEntry(h[
"T" + p + x],
"nu_e new with charm, cascade, k-fac",
"PL")
605 h[
"Lnue" + z + x].AddEntry(h[
"TP" + p + x],
"nu_e old Yandex prod",
"PL")
607 h[
"T" + p + x].Draw(
"same")
608 h[
"TP" + p + x].Draw(
"same")
609 h[
"TP" + p + x].SetLineColor(3)
610 h[
"T" + p + x].SetLineColor(2)
611 h[
"Lnue" + z + x].AddEntry(h[
"T" + p + x],
"anti nu_e new with charm, cascade, k-fac",
"PL")
612 h[
"Lnue" + z + x].AddEntry(h[
"TP" + p + x],
"anti nu_e old Yandex prod",
"PL")
613 h[
"Lnue" + z + x].Draw()
615 h[t].Print(
"comparison" + z + x.replace(
"_>",
"") +
".png")
616 h[t].Print(
"comparison" + z + x.replace(
"_>",
"") +
".pdf")
619 for z
in [
"p",
"pt"]:
620 h[z +
"muRatio" + x] = h[
"T" + z +
"mu" + x].Clone(z +
"muRatio" + x)
621 h[z +
"muRatio" + x].Divide(h[
"TP" + z +
"mu" + x])
622 h[z +
"numuRatio" + x] = h[
"T" + z +
"numusum" + x].Clone(z +
"numuRatio" + x)
623 h[z +
"numuRatio" + x].Divide(h[
"TP" + z +
"numusum" + x])
624 h[z +
"nueRatio" + x] = h[
"T" + z +
"nuesum" + x].Clone(z +
"nueRatio" + x)
625 h[z +
"nueRatio" + x].Divide(h[
"TP" + z +
"nuesum" + x])
626 ut.bookCanvas(h, key=
"ratios", title=
"ratios", nx=1800, ny=600, cx=2, cy=1)
628 for z
in [
"p",
"pt"]:
629 h[
"Lratio" + z + x] = ROOT.TLegend(0.21, 0.74, 0.71, 0.85)
632 h[z +
"muRatio" + x].SetLineColor(2)
633 h[z +
"muRatio" + x].SetMaximum(max(h[z +
"muRatio" + x].GetMaximum(), h[z +
"numuRatio" + x].GetMaximum()))
634 h[z +
"muRatio" + x].SetMinimum(0)
635 h[z +
"muRatio" + x].SetStats(0)
636 h[z +
"muRatio" + x].Draw()
637 h[z +
"numuRatio" + x].SetLineColor(3)
638 h[z +
"numuRatio" + x].SetStats(0)
639 h[z +
"numuRatio" + x].Draw(
"same")
642 h[
"Lratio" + z + x].AddEntry(h[z +
"muRatio" + x],
"muon flux new / old ",
"PL")
643 h[
"Lratio" + z + x].AddEntry(h[z +
"numuRatio" + x],
"nu_mu flux new / old ",
"PL")
645 h[
"Lratio" + z + x].Draw()
646 h[
"ratios"].Print(
"comparisonRatios.png")
647 h[
"ratios"].Print(
"comparisonRatios.pdf")
create_config(str DecayVolumeMedium="helium", float Yheight=6.0, int strawDesign=10, str shieldName="TRY_2026", int nuTargetPassive=1, bool SND=True, SND_design=None, TARGET_YAML=None)