12pdg = ROOT.TDatabasePDG()
13mu = pdg.GetParticle(13)
17eospath = ROOT.gSystem.Getenv(
"EOSSHIP") +
"/eos/experiment/ship/data/"
19endOfHadronAbsorber = (ship_geo[
"hadronAbsorber"].z + ship_geo[
"hadronAbsorber"].length / 2.0) / 100.0
25 for n
in range(t.GetEntries()):
27 if t.parentid
not in particles:
28 particles[t.parentid] = 0
29 particles[t.parentid] += 1
37 f = ROOT.TFile.Open(eospath + productions[p][
"file"])
38 t = f.FindObjectAny(
"pythia8-Geant4")
40 for n
in range(t.GetEntries()):
42 if t.w
not in weights[p]:
43 weights[p][t.w] = [t.ecut, 0]
44 weights[p][t.w][1] += 1
45 if t.ecut > weights[p][t.w][0]:
46 weights[p][t.w][0] = t.ecut
51 ut.bookCanvas(h, key=
"P", title=
"momentum", nx=1800, ny=1200, cx=3, cy=2)
52 ut.bookCanvas(h, key=
">P", title=
"N >P", nx=1800, ny=1200, cx=3, cy=2)
53 ut.bookCanvas(h, key=
"PT", title=
"Pt", nx=1800, ny=1200, cx=3, cy=2)
54 ut.bookCanvas(h, key=
">PT", title=
"N >Pt", nx=1800, ny=1200, cx=3, cy=2)
61 "nutaubar":
"id==-16",
66 "nuesum":
"abs(id)==12",
67 "numusum":
"abs(id)==14",
68 "nutausum":
"abs(id)==16",
72 "charm":
"&(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
73 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )",
76 for x
in [
"",
"charm"]:
81 ut.bookHist(h, hn, p +
" ;p [GeV] ;N", 400, 0.0, 400.0)
82 ut.bookHist(h, hnt, p +
" ;pt [GeV] ;N", 40, 0.0, 4.0)
83 sTree.Draw(
"sqrt(px**2+py**2+pz**2)>>" + hn,
"w*(" + cuts[q] + OpenCharm[x] +
")",
"goff")
84 sTree.Draw(
"sqrt(px**2+py**2)>>" + hnt,
"w*(" + cuts[q] + OpenCharm[x] +
")",
"goff")
90 for q
in [
"mu",
"mu-",
"mu+",
"nu",
"nue",
"nuesum",
"nuebar",
"numusum",
"numu",
"numubar",
"nutau",
"nutaubar"]:
91 for x
in [
"",
"charm"]:
95 h[hi] = h[
"T" + p].Clone(hi)
98 for i
in range(h[hi].GetNbinsX() + 1, 0, -1):
99 nsum += h[
"T" + p].GetBinContent(i)
100 h[hi].SetBinContent(i, nsum)
101 for z
in [
"p",
"pt"]:
103 for x
in [
"mu",
"nu"]:
109 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)
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()
146 productions[
"CERN-Cracow"] = {
147 "stats": {1.0: [1.1e8], 10.0: [1.22e9], 100: [1.27e10]},
148 "file":
"Mbias/pythia8_Geant4_total.root",
151 productions[
"Yandex"] = {
"stats": {5.0: [2.1e9, 1e9], 0.5: [1e8]},
"file":
"Mbias/pythia8_Geant4_total_Yandex.root"}
153 productions[
"Yandex2"] = {
"stats": {10.0: [1e10]},
"file":
"Mbias/pythia8_Geant4_total_Yandex2.root"}
155productions[
"Yandex3"] = {
"stats": {10.0: [1e10]},
"file":
"Mbias/pythia8_Geant4_total_Yandex3.root"}
158fnew =
"pythia8_Geant4-noOpenCharm.root"
160 "!(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
161 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )"
164 "(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
165 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )"
167cuts = {
"":
"abs(id)>0",
"_onlyMuons":
"abs(id)==13",
"_onlyNeutrinos":
"abs(id)==12||abs(id)==14||abs(id)==16"}
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
275 pot[p][we[p][w][0]] = 5.0e13 / w
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 name = pdg.GetParticle(idnu).GetName()
419 idhnu = 2000 + abs(idnu)
420 ut.bookHist(h, str(idhnu), name +
" momentum (GeV)", 400, 0.0, 400.0)
421 ut.bookHist(h, str(idhnu + 100), name +
" log10(ptot) vs log10(pt+0.01)", 100, -0.3, 1.7, 100, -2.0, 1.0)
422 ut.bookHist(h, str(idhnu + 200), name +
" log10(ptot) vs log10(pt+0.01)", 25, -0.3, 1.7, 100, -2.0, 1.0)
423 leaves = t.GetListOfLeaves()
426 tuples += leaf.GetName()
428 tuples +=
":" + leaf.GetName()
430 fxx = fName.replace(
"-ram.root", opt +
".root")
431 N = ROOT.TFile(fxx,
"RECREATE")
432 ntuple = ROOT.TNtuple(
"pythia8-Geant4", opt.replace(
"_only",
"") +
" flux mbias and charm" + opt, tuples)
435 t.Draw(
">>temp", cuts[opt])
436 temp = ROOT.gROOT.FindObjectAny(
"temp")
438 for iev
in range(temp.GetN()):
439 t.GetEntry(temp.GetEntry(iev))
441 for n
in range(leaves.GetSize()):
442 vlist.append(leaves.At(n).GetValue())
444 if "Neutrinos" in opt:
445 pt2 = t.px**2 + t.py**2
446 ptot = ROOT.TMath.Sqrt(pt2 + t.pz**2)
447 l10ptot = min(max(ROOT.TMath.Log10(ptot), -0.3), 1.69999)
448 l10pt = min(ROOT.TMath.Log10(ROOT.TMath.Sqrt(pt2) + 0.01), 0.9999)
452 idhnu = 2000 + abs(idnu)
453 h[str(idhnu)].Fill(ptot, t.w)
454 h[str(idhnu + 100)].Fill(l10ptot, l10pt, t.w)
455 h[str(idhnu + 200)].Fill(l10ptot, l10pt, t.w)
459 if "Neutrinos" in opt:
461 cln = h[akey].Class().GetName()
462 if not cln.find(
"TH") < 0:
465 print(
" progress: split " + opt)
469 h[
"f"] = ROOT.TFile.Open(fname)
470 sTree = h[
"f"].FindObjectAny(
"pythia8-Geant4")
475 test(eospath +
"pythia8_Geant4_onlyMuons.root")
476 for x
in [
"",
"_>E"]:
477 for z
in [
"p",
"pt"]:
478 for ahist
in [
"mu-",
"mu+",
"mu",
"mu-charm",
"mu+charm",
"mucharm"]:
479 h[
"TP" + z + ahist + x] = h[
"T" + z + ahist + x].Clone(
"CT" + ahist + x)
480 test(eospath +
"pythia8_Geant4_Yandex_onlyNeutrinos.root")
481 for x
in [
"",
"_>E"]:
482 for z
in [
"p",
"pt"]:
497 h[
"TP" + z + ahist + x] = h[
"T" + z + ahist + x].Clone(
"CT" + ahist + x)
498 test(eospath +
"Mbias/pythia8_Geant4-withCharm-ram.root")
499 for x
in [
"",
"_>E"]:
500 for z
in [
"p",
"pt"]:
506 h[
"T" + p + x].SetTitle(
"musum")
507 h[
"T" + p + x].Draw()
508 h[
"T" + p +
"charm" + x].Draw(
"same")
509 h[
"TP" + p + x].Draw(
"same")
510 h[
"TP" + p + x].SetLineColor(6)
511 h[
"TP" + p +
"charm" + x].Draw(
"same")
512 h[
"TP" + p +
"charm" + x].SetLineColor(3)
513 h[
"T" + p +
"charm" + x].SetLineColor(2)
514 h[
"T" + p + x].SetLineColor(4)
515 h[
"L" + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
516 h[
"L" + p + x].AddEntry(h[
"T" + p + x],
"muon new with charm, cascade, k-fac",
"PL")
517 h[
"L" + p + x].AddEntry(h[
"T" + p +
"charm" + x],
"muon from charm new with charm, cascade, k-fac",
"PL")
518 h[
"L" + p + x].AddEntry(h[
"TP" + p + x],
"muon old CERN-Cracow prod",
"PL")
519 h[
"L" + p + x].AddEntry(h[
"TP" + p +
"charm" + x],
"muon from charm old CERN-Cracow prod",
"PL")
520 h[
"L" + p + x].Draw()
523 h[
"T" + p + x].Draw()
524 h[
"T" + p +
"charm" + x].Draw(
"same")
525 h[
"TP" + p + x].Draw(
"same")
526 h[
"TP" + p + x].SetLineColor(6)
527 h[
"TP" + p +
"charm" + x].Draw(
"same")
528 h[
"TP" + p +
"charm" + x].SetLineColor(3)
529 h[
"T" + p +
"charm" + x].SetLineColor(2)
530 h[
"T" + p + x].SetLineColor(4)
531 h[
"L" + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
532 h[
"L" + p + x].AddEntry(h[
"T" + p + x],
"nu_mu new with charm, cascade, k-fac",
"PL")
533 h[
"L" + p + x].AddEntry(h[
"T" + p +
"charm" + x],
"nu_mu from charm new with charm, cascade, k-fac",
"PL")
534 h[
"L" + p + x].AddEntry(h[
"TP" + p + x],
"nu_mu old CERN-Cracow prod",
"PL")
535 h[
"L" + p + x].AddEntry(h[
"TP" + p +
"charm" + x],
"nu_mu from charm old CERN-Cracow prod",
"PL")
536 h[
"L" + p + x].Draw()
540 h[
"T" + p + x].Draw()
541 h[
"T" + p +
"charm" + x].Draw(
"same")
542 h[
"TP" + p + x].Draw(
"same")
543 h[
"TP" + p + x].SetLineColor(6)
544 h[
"TP" + p +
"charm" + x].Draw(
"same")
545 h[
"TP" + p +
"charm" + x].SetLineColor(3)
546 h[
"T" + p +
"charm" + x].SetLineColor(2)
547 h[
"T" + p + x].SetLineColor(4)
548 h[
"L" + p + x] = ROOT.TLegend(0.33, 0.69, 0.99, 0.94)
549 h[
"L" + p + x].AddEntry(h[
"T" + p + x],
"nu_e new with charm, cascade, k-fac",
"PL")
550 h[
"L" + p + x].AddEntry(h[
"T" + p +
"charm" + x],
"nu_e from charm new with charm, cascade, k-fac",
"PL")
551 h[
"L" + p + x].AddEntry(h[
"TP" + p + x],
"nu_e old CERN-Cracow prod",
"PL")
552 h[
"L" + p + x].AddEntry(h[
"TP" + p +
"charm" + x],
"nu_e from charm old CERN-Cracow prod",
"PL")
553 h[
"L" + p + x].Draw()
557 h[
"Lmuc" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
559 h[
"T" + p + x].SetTitle(
"mu-/mu+")
560 h[
"T" + p + x].Draw()
561 h[
"TP" + p + x].Draw(
"same")
562 h[
"TP" + p + x].SetLineColor(6)
563 h[
"T" + p + x].SetLineColor(4)
564 h[
"Lmuc" + z + x].AddEntry(h[
"T" + p + x],
"mu- new with charm, cascade, k-fac",
"PL")
565 h[
"Lmuc" + z + x].AddEntry(h[
"TP" + p + x],
"mu- old Yandex prod",
"PL")
567 h[
"T" + p + x].Draw(
"same")
568 h[
"TP" + p + x].Draw(
"same")
569 h[
"TP" + p + x].SetLineColor(3)
570 h[
"T" + p + x].SetLineColor(2)
571 h[
"Lmuc" + z + x].AddEntry(h[
"T" + p + x],
"mu+ new with charm, cascade, k-fac",
"PL")
572 h[
"Lmuc" + z + x].AddEntry(h[
"TP" + p + x],
"mu+ old Yandex prod",
"PL")
573 h[
"Lmuc" + z + x].Draw()
577 h[
"Lnumu" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
579 h[
"T" + p + x].SetTitle(
"numu/numubar")
580 h[
"T" + p + x].Draw()
581 h[
"TP" + p + x].Draw(
"same")
582 h[
"TP" + p + x].SetLineColor(6)
583 h[
"T" + p + x].SetLineColor(4)
584 h[
"Lnumu" + z + x].AddEntry(h[
"T" + p + x],
"nu_mu new with charm, cascade, k-fac",
"PL")
585 h[
"Lnumu" + z + x].AddEntry(h[
"TP" + p + x],
"nu_mu old Yandex prod",
"PL")
587 h[
"T" + p + x].Draw(
"same")
588 h[
"TP" + p + x].Draw(
"same")
589 h[
"TP" + p + x].SetLineColor(3)
590 h[
"T" + p + x].SetLineColor(2)
591 h[
"Lnumu" + z + x].AddEntry(h[
"T" + p + x],
"anti nu_mu new with charm, cascade, k-fac",
"PL")
592 h[
"Lnumu" + z + x].AddEntry(h[
"TP" + p + x],
"anti nu_mu old Yandex prod",
"PL")
593 h[
"Lnumu" + z + x].Draw()
597 h[
"Lnue" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
598 h[
"T" + p + x].SetTitle(
"nue/nuebar")
599 h[
"T" + p + x].Draw()
600 h[
"TP" + p + x].Draw(
"same")
601 h[
"TP" + p + x].SetLineColor(6)
602 h[
"T" + p + x].SetLineColor(4)
603 h[
"Lnue" + z + x].AddEntry(h[
"T" + p + x],
"nu_e new with charm, cascade, k-fac",
"PL")
604 h[
"Lnue" + z + x].AddEntry(h[
"TP" + p + x],
"nu_e old Yandex prod",
"PL")
606 h[
"T" + p + x].Draw(
"same")
607 h[
"TP" + p + x].Draw(
"same")
608 h[
"TP" + p + x].SetLineColor(3)
609 h[
"T" + p + x].SetLineColor(2)
610 h[
"Lnue" + z + x].AddEntry(h[
"T" + p + x],
"anti nu_e new with charm, cascade, k-fac",
"PL")
611 h[
"Lnue" + z + x].AddEntry(h[
"TP" + p + x],
"anti nu_e old Yandex prod",
"PL")
612 h[
"Lnue" + z + x].Draw()
614 h[t].Print(
"comparison" + z + x.replace(
"_>",
"") +
".png")
615 h[t].Print(
"comparison" + z + x.replace(
"_>",
"") +
".pdf")
618 for z
in [
"p",
"pt"]:
619 h[z +
"muRatio" + x] = h[
"T" + z +
"mu" + x].Clone(z +
"muRatio" + x)
620 h[z +
"muRatio" + x].Divide(h[
"TP" + z +
"mu" + x])
621 h[z +
"numuRatio" + x] = h[
"T" + z +
"numusum" + x].Clone(z +
"numuRatio" + x)
622 h[z +
"numuRatio" + x].Divide(h[
"TP" + z +
"numusum" + x])
623 h[z +
"nueRatio" + x] = h[
"T" + z +
"nuesum" + x].Clone(z +
"nueRatio" + x)
624 h[z +
"nueRatio" + x].Divide(h[
"TP" + z +
"nuesum" + x])
625 ut.bookCanvas(h, key=
"ratios", title=
"ratios", nx=1800, ny=600, cx=2, cy=1)
627 for z
in [
"p",
"pt"]:
628 h[
"Lratio" + z + x] = ROOT.TLegend(0.21, 0.74, 0.71, 0.85)
631 h[z +
"muRatio" + x].SetLineColor(2)
632 h[z +
"muRatio" + x].SetMaximum(max(h[z +
"muRatio" + x].GetMaximum(), h[z +
"numuRatio" + x].GetMaximum()))
633 h[z +
"muRatio" + x].SetMinimum(0)
634 h[z +
"muRatio" + x].SetStats(0)
635 h[z +
"muRatio" + x].Draw()
636 h[z +
"numuRatio" + x].SetLineColor(3)
637 h[z +
"numuRatio" + x].SetStats(0)
638 h[z +
"numuRatio" + x].Draw(
"same")
641 h[
"Lratio" + z + x].AddEntry(h[z +
"muRatio" + x],
"muon flux new / old ",
"PL")
642 h[
"Lratio" + z + x].AddEntry(h[z +
"numuRatio" + x],
"nu_mu flux new / old ",
"PL")
644 h[
"Lratio" + z + x].Draw()
645 h[
"ratios"].Print(
"comparisonRatios.png")
646 h[
"ratios"].Print(
"comparisonRatios.pdf")
649print(
"+ merging with charm events using existing charmless Mbias file: mergeWithCharm()")
650print(
"+ removeCharm(p) from mbias file")
651print(
"+ testing output: test('pythia8_Geant4-noOpenCharm.root')")
652print(
"+ not used anymore: to start the full production, including merging of Mbias files: runProduction()")
def create_config(str DecayVolumeMedium="helium", float Yheight=6.0, int strawDesign=10, muShieldGeo=None, str shieldName="New_HA_Design", int nuTargetPassive=1, bool SND=True, SND_design=None, TARGET_YAML=None)
None mergeWithCharm(bool splitOnly=False, bool ramOnly=False)
None mergeMinBias(pot, norm=5.0e13, opt="")
None runProduction(str opts="")