FairShip
Loading...
Searching...
No Matches
mergeMbias Namespace Reference

Functions

 fillPart (t)
 fillWeights ()
None TplotP (sTree)
None mergeMinBias (pot, norm=5.0e13, opt="")
None runProduction (str opts="")
None removeCharm (p)
None mergeWithCharm (bool splitOnly=False, bool ramOnly=False)
None test (fname)
None compare ()

Variables

 pdg = ROOT.TDatabasePDG()
 mu = ut.get_particle(13)
 Mmu = mu.Mass()
 Mmu2 = Mmu * Mmu
 rnr = ROOT.TRandom()
str eospath = ROOT.gSystem.Getenv("EOSSHIP") + "/eos/experiment/ship/data/"
 ship_geo = geometry_config.create_config(Yheight=10.0)
tuple endOfHadronAbsorber = (ship_geo["muShield"].Entrance[0] + 2 * ship_geo["muShield"].half_length[0]) / 100.0
float startOfTarget = -50.0
dict productions = {}
bool allProds = False
str fnew = "pythia8_Geant4-noOpenCharm.root"
tuple noOpCharm
tuple OpCharm
dict cuts = {"": "abs(id)>0", "_onlyMuons": "abs(id)==13", "_onlyNeutrinos": "abs(id)==12||abs(id)==14||abs(id)==16"}
dict h = {}

Function Documentation

◆ compare()

None mergeMbias.compare ( )

Definition at line 475 of file mergeMbias.py.

475def compare() -> None:
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"]:
484 for ahist in [
485 "numusum",
486 "nuesum",
487 "numusumcharm",
488 "nuesumcharm",
489 "numu",
490 "numubar",
491 "nue",
492 "nuebar",
493 "numucharm",
494 "numubarcharm",
495 "nuecharm",
496 "nuebarcharm",
497 ]:
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"]:
502 t = z.upper()
503 if x != "":
504 t = ">" + t
505 h[t].cd(1)
506 p = z + "mu"
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()
522 h[t].cd(2)
523 p = z + "numusum"
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()
538 t3 = h[t].cd(3)
539 t3.SetLogy(1)
540 p = z + "nuesum"
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()
555 #
556 t4 = h[t].cd(4)
557 t4.SetLogy(1)
558 h["Lmuc" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
559 p = z + "mu-"
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")
567 p = z + "mu+"
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()
575 #
576 t5 = h[t].cd(5)
577 t5.SetLogy(1)
578 h["Lnumu" + z + x] = ROOT.TLegend(0.33, 0.73, 0.99, 0.94)
579 p = z + "numu"
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")
587 p = z + "numubar"
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()
595 t6 = h[t].cd(6)
596 t6.SetLogy(1)
597 p = z + "nue"
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")
606 p = z + "nuebar"
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()
614 #
615 h[t].Print("comparison" + z + x.replace("_>", "") + ".png")
616 h[t].Print("comparison" + z + x.replace("_>", "") + ".pdf")
617 # make ratio plots
618 x = "_>E"
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)
627 n = 1
628 for z in ["p", "pt"]:
629 h["Lratio" + z + x] = ROOT.TLegend(0.21, 0.74, 0.71, 0.85)
630 h["ratios"].cd(n)
631 n += 1
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")
640 # h[z+'nueRatio'+x].SetLineColor(4)
641 # h[z+'nueRatio'+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")
644 # h['Lratio'+z+x].AddEntry(h[z+'nueRatio'+x],'nu_e flux new / old ','PL')
645 h["Lratio" + z + x].Draw()
646 h["ratios"].Print("comparisonRatios.png")
647 h["ratios"].Print("comparisonRatios.pdf")
648
649

◆ fillPart()

mergeMbias.fillPart ( t)

Definition at line 24 of file mergeMbias.py.

24def fillPart(t):
25 particles = {}
26 for n in range(t.GetEntries()):
27 t.GetEvent(n)
28 if t.parentid not in particles:
29 particles[t.parentid] = 0
30 particles[t.parentid] += 1
31 return particles
32
33
34#

◆ fillWeights()

mergeMbias.fillWeights ( )

Definition at line 35 of file mergeMbias.py.

35def fillWeights():
36 weights = {}
37 for p in productions:
38 f = ROOT.TFile.Open(eospath + productions[p]["file"])
39 t = f.FindObjectAny("pythia8-Geant4")
40 weights[p] = {}
41 for n in range(t.GetEntries()):
42 t.GetEvent(n)
43 if t.w not in weights[p]:
44 weights[p][t.w] = [t.ecut, 0]
45 weights[p][t.w][1] += 1
46 if t.ecut > weights[p][t.w][0]:
47 weights[p][t.w][0] = t.ecut
48 return weights
49
50

◆ mergeMinBias()

None mergeMbias.mergeMinBias ( pot,
norm = 5.0e13,
opt = "" )

Definition at line 172 of file mergeMbias.py.

172def mergeMinBias(pot, norm=5.0e13, opt="") -> None:
173 storeCharm = False
174 if opt != "":
175 storeCharm = True
176 opt = ""
177 first = True
178 for p in productions:
179 f = ROOT.TFile.Open(eospath + productions[p]["file"])
180 t = f.FindObjectAny("pythia8-Geant4")
181 if first:
182 first = False
183 tuples = ""
184 for leaf in t.GetListOfLeaves():
185 if tuples == "":
186 tuples += leaf.GetName()
187 else:
188 tuples += ":" + leaf.GetName()
189 fxx = fnew.replace(".root", opt + ".root")
190 if storeCharm:
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)
195 ROOT.gROOT.cd()
196 t.SetEventList(0)
197 if storeCharm:
198 t.Draw(">>temp", cuts[opt] + "&" + OpCharm)
199 else:
200 t.Draw(">>temp", cuts[opt] + "&" + noOpCharm)
201 temp = ROOT.gROOT.FindObjectAny("temp")
202 t.SetEventList(temp)
203 nev = temp.GetN()
204 leaves = t.GetListOfLeaves()
205 nL = leaves.GetEntries()
206 for iev in range(nev):
207 t.GetEntry(temp.GetEntry(iev))
208 vlist = []
209 k = -1
210 for x in range(nL):
211 k += 1
212 if nL > 11 and (k == 7 or k == 8 or k == 9):
213 continue
214 vlist.append(leaves.At(x).GetValue())
215 if len(vlist) != 11:
216 print("this should never happen, big error", len(vlist), k, p, iev, nev)
217 raise RuntimeError(f"unexpected vlist length: {len(vlist)}")
218 # "id:px:py:pz:x:y:z:pythiaid:parentid:w:ecut"
219 # yandex productions have
220 # "id:px:py:pz:x:y:z:ox:oy:oz:pythiaid:parentid:w:ecut"
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
224 else:
225 Ekin = ROOT.TMath.Sqrt(Psq)
226 # re calculate weights
227 # pot = 5E13/w
228 # E > 100 GeV: add all pots -> w = 5E13/pot
229 # w = norm/( pot["CERN-Cracow"][100.] + productions["Yandex"][5.] + productions["Yandex2"][10.] )
230 # E < 100 & E > 10 GeV
231 # w = norm/( pot["CERN-Cracow"][10.] + productions["Yandex"][5.] + productions["Yandex2"][10.] )
232 # E < 10 & E > 5 GeV
233 # w = norm/( pot["CERN-Cracow"][1.] + productions["Yandex"][5.] )
234 # E < 5 GeV & E > 1 GeV
235 # w = norm/( pot["CERN-Cracow"][1.] + productions["Yandex"][0.5] )
236 # E < 1 GeV & E > 0.5 GeV
237 # w = norm/( productions["Yandex"][0.5] )
238 if Ekin > 100.0:
239 vlist[9] = norm / (pot["CERN-Cracow"][100.0] + pot["Yandex"][5.0] + pot["Yandex2"][10.0])
240 elif Ekin > 10.0:
241 vlist[9] = norm / (pot["CERN-Cracow"][10.0] + pot["Yandex"][5.0] + pot["Yandex2"][10.0])
242 elif Ekin > 5.0:
243 vlist[9] = norm / (pot["CERN-Cracow"][1.0] + pot["Yandex"][5.0])
244 elif Ekin > 1.0:
245 vlist[9] = norm / (pot["CERN-Cracow"][1.0] + pot["Yandex"][0.5])
246 elif Ekin > 0.5:
247 vlist[9] = norm / (pot["Yandex"][0.5])
248 else:
249 print("this should not happen, except some rounding errors", p, Ekin, vlist[9])
250 vlist[6] = endOfHadronAbsorber
251 h["ntuple"].Fill(
252 vlist[0],
253 vlist[1],
254 vlist[2],
255 vlist[3],
256 vlist[4],
257 vlist[5],
258 vlist[6],
259 vlist[7],
260 vlist[8],
261 vlist[9],
262 vlist[10],
263 )
264 h["N"].cd()
265 h["ntuple"].Write()
266 h["N"].Close()
267
268

◆ mergeWithCharm()

None mergeMbias.mergeWithCharm ( bool splitOnly = False,
bool ramOnly = False )

Definition at line 315 of file mergeMbias.py.

315def mergeWithCharm(splitOnly: bool = False, ramOnly: bool = False) -> None:
316 # Ntup.Fill(par.id(),par.px(),par.py(),par.pz(),par.e(),par.m(),wspill,sTree.id,sTree.px,sTree.py,sTree.pz,sTree.E,sTree.M)
317 # i.e. the par. is for the neutrino, and the sTree. is for its mother.
318 # wspill is the weight for this file normalised/5e13.
319 if not splitOnly:
320 fcascade = ROOT.TFile.Open(eospath + "/Charm/Decay-Cascade-parp16-MSTP82-1-MSEL4-76Mpot_1.root")
321 t = fcascade.Decay
322 newFile = ROOT.TFile("pythia8_Charm.root", "RECREATE")
323 nt = ROOT.TNtuple(
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"
325 )
326 for n in range(t.GetEntries()):
327 t.GetEntry(n)
328 ztarget = rnr.Exp(0.16) + startOfTarget
329 vlist = array("f")
330 x = (
331 t.id,
332 t.px,
333 t.py,
334 t.pz,
335 0.0,
336 0.0,
337 ztarget,
338 t.px,
339 t.py,
340 t.pz,
341 0.0,
342 0.0,
343 ztarget,
344 t.id,
345 t.mid,
346 t.weight,
347 0.0,
348 )
349 for ax in x:
350 vlist.append(ax)
351 nt.Fill(vlist)
352 newFile.cd()
353 nt.Write()
354 newFile.Close()
355 fcascade.Close()
356 os.system("hadd -f pythia8_Geant4-withCharm.root pythia8_Geant4-noOpenCharm.root pythia8_Charm.root")
357 print(" progress: minbias and charm merged")
358 ramOnly = True
359 if ramOnly:
360 # put all events in memory, otherwise will take years to finish
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()
366 m = 0
367 allEvents = []
368 for n in range(t.GetEntries()):
369 t.GetEvent(n)
370 if m % 1000000 == 0:
371 print("status read", m)
372 m += 1
373 a = event()
374 for idx in range(L):
375 a.push_back(leaves.At(idx).GetValue())
376 allEvents.append(a)
377 # distribute events randomly
378 evList = []
379 for n in range(len(allEvents)):
380 evList.append(n)
381 random.shuffle(evList)
382 leaves = t.GetListOfLeaves()
383 tuples = ""
384 for leaf in leaves:
385 if tuples == "":
386 tuples += leaf.GetName()
387 else:
388 tuples += ":" + leaf.GetName()
389 newFile = ROOT.TFile("pythia8_Geant4-withCharm-ram.root", "RECREATE")
390 randomTuple = ROOT.TNtuple(t.GetName(), t.GetTitle(), tuples)
391 m = 0
392 for n in evList:
393 a = allEvents[n]
394 if m % 1000000 == 0:
395 print("status write", m)
396 m += 1
397 vlist = array("f")
398 for x in a:
399 vlist.append(x)
400 randomTuple.Fill(vlist)
401 newFile.cd()
402 randomTuple.Write()
403 newFile.Close()
404 f.Close()
405 allEvents = []
406 print(" progress: order of events randomized")
407 if 1 > 0:
408 # split in muons and neutrinos
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")
413 tuples = ""
414 # add histograms
415 for idnu in [16, -16, 14, -14, 12, -12]:
416 _p = ut.get_particle(idnu)
417 name = _p.GetName()
418 idhnu = 1000 + idnu
419 if idnu < 0:
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()
425 for leaf in leaves:
426 if tuples == "":
427 tuples += leaf.GetName()
428 else:
429 tuples += ":" + leaf.GetName()
430 for opt in cuts:
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)
434 ROOT.gROOT.cd()
435 t.SetEventList(0)
436 t.Draw(">>temp", cuts[opt])
437 temp = ROOT.gROOT.FindObjectAny("temp")
438 t.SetEventList(temp)
439 for iev in range(temp.GetN()):
440 t.GetEntry(temp.GetEntry(iev))
441 vlist = array("f")
442 for n in range(leaves.GetSize()):
443 vlist.append(leaves.At(n).GetValue())
444 ntuple.Fill(vlist)
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)
450 idnu = int(t.id)
451 idhnu = 1000 + idnu
452 if idnu < 0:
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)
457 #
458 N.cd()
459 ntuple.Write()
460 if "Neutrinos" in opt:
461 for akey in h:
462 cln = h[akey].Class().GetName()
463 if not cln.find("TH") < 0:
464 h[akey].Write()
465 N.Close()
466 print(" progress: split " + opt)
467
468

◆ removeCharm()

None mergeMbias.removeCharm ( p)

Definition at line 281 of file mergeMbias.py.

281def removeCharm(p) -> None:
282 f = ROOT.TFile.Open(eospath + productions[p]["file"])
283 t = f.FindObjectAny("pythia8-Geant4")
284 first = True
285 if first:
286 first = False
287 tuples = ""
288 for leaf in t.GetListOfLeaves():
289 if tuples == "":
290 tuples += leaf.GetName()
291 else:
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)
296 ROOT.gROOT.cd()
297 t.SetEventList(0)
298 t.Draw(">>temp", noOpCharm)
299 temp = ROOT.gROOT.FindObjectAny("temp")
300 t.SetEventList(temp)
301 nev = temp.GetN()
302 leaves = t.GetListOfLeaves()
303 leaves.GetEntries()
304 for iev in range(nev):
305 t.GetEntry(temp.GetEntry(iev))
306 vlist = array("f")
307 for x in range(leaves.GetEntries()):
308 vlist.append(leaves.At(x).GetValue())
309 h["ntuple"].Fill(vlist)
310 h["N"].cd()
311 h["ntuple"].Write()
312 h["N"].Close()
313
314

◆ runProduction()

None mergeMbias.runProduction ( str opts = "")

Definition at line 269 of file mergeMbias.py.

269def runProduction(opts: str = "") -> None:
270 we = fillWeights()
271 pot = {}
272 for p in we:
273 pot[p] = {}
274 for w in we[p]:
275 pot[p][we[p][w][0]] = 5.0e13 / w
276 print("pots:", pot)
277 #
278 mergeMinBias(pot, norm=5.0e13, opt=opts)
279
280

◆ test()

None mergeMbias.test ( fname)

Definition at line 469 of file mergeMbias.py.

469def test(fname) -> None:
470 h["f"] = ROOT.TFile.Open(fname)
471 sTree = h["f"].FindObjectAny("pythia8-Geant4")
472 TplotP(sTree)
473
474

◆ TplotP()

None mergeMbias.TplotP ( sTree)

Definition at line 51 of file mergeMbias.py.

51def TplotP(sTree) -> None:
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)
56 cuts = {
57 "mu": "abs(id)==13",
58 "nu": "abs(id)!=13",
59 "mu-": "id==13",
60 "mu+": "id==-13",
61 "nutau": "id==16",
62 "nutaubar": "id==-16",
63 "numu": "id==14",
64 "numubar": "id==-14",
65 "nue": "id==12",
66 "nuebar": "id==-12",
67 "nuesum": "abs(id)==12",
68 "numusum": "abs(id)==14",
69 "nutausum": "abs(id)==16",
70 }
71 OpenCharm = {
72 "": "",
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) )",
75 }
76 ROOT.gROOT.cd("")
77 for x in ["", "charm"]:
78 for q in cuts:
79 p = q + x
80 hn = "Tp" + p
81 hnt = "Tpt" + p
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")
86 if q == "mu+":
87 h[hn].SetLineColor(3)
88 if q == "mu-":
89 h[hn].SetLineColor(4)
90 # integrated rates
91 for q in ["mu", "mu-", "mu+", "nu", "nue", "nuesum", "nuebar", "numusum", "numu", "numubar", "nutau", "nutaubar"]:
92 for x in ["", "charm"]:
93 for z in ["p", "pt"]:
94 p = z + q + x
95 hi = "T" + p + "_>E"
96 h[hi] = h["T" + p].Clone(hi)
97 h[hi].Reset()
98 nsum = 0
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"]:
103 k = 1
104 for x in ["mu", "nu"]:
105 t = z.upper()
106 p = z + x
107 cv = h[t].cd(k)
108 cv.SetLogy(1)
109 h["T" + p].Draw()
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)
115 cv.SetLogy(1)
116 h["T" + p + "_>E"].Draw()
117 k += 1
118 # plot different nu species:
119 k = 3
120 cv = h[t].cd(k)
121 cv.SetLogy(1)
122 first = True
123 i = 2
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"]:
126 hn = "T" + z + p
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")
131 h[hn + "8"].Rebin(8)
132 i += 1
133 if first:
134 h[hn + "8"].Draw()
135 first = False
136 h[hn + "8"].Draw("same")
137 h["tlnu" + z + str(k)].Draw()
138 k += 1
139
140
141#
142

Variable Documentation

◆ allProds

bool mergeMbias.allProds = False

Definition at line 144 of file mergeMbias.py.

◆ cuts

dict mergeMbias.cuts = {"": "abs(id)>0", "_onlyMuons": "abs(id)==13", "_onlyNeutrinos": "abs(id)==12||abs(id)==14||abs(id)==16"}

Definition at line 167 of file mergeMbias.py.

◆ endOfHadronAbsorber

tuple mergeMbias.endOfHadronAbsorber = (ship_geo["muShield"].Entrance[0] + 2 * ship_geo["muShield"].half_length[0]) / 100.0

Definition at line 20 of file mergeMbias.py.

◆ eospath

str mergeMbias.eospath = ROOT.gSystem.Getenv("EOSSHIP") + "/eos/experiment/ship/data/"

Definition at line 17 of file mergeMbias.py.

◆ fnew

str mergeMbias.fnew = "pythia8_Geant4-noOpenCharm.root"

Definition at line 158 of file mergeMbias.py.

◆ h

dict mergeMbias.h = {}

Definition at line 169 of file mergeMbias.py.

◆ Mmu

mergeMbias.Mmu = mu.Mass()

Definition at line 14 of file mergeMbias.py.

◆ Mmu2

mergeMbias.Mmu2 = Mmu * Mmu

Definition at line 15 of file mergeMbias.py.

◆ mu

mergeMbias.mu = ut.get_particle(13)

Definition at line 13 of file mergeMbias.py.

◆ noOpCharm

tuple mergeMbias.noOpCharm
Initial value:
1= (
2 "!(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
3 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )"
4)

Definition at line 159 of file mergeMbias.py.

◆ OpCharm

tuple mergeMbias.OpCharm
Initial value:
1= (
2 "(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
3 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )"
4)

Definition at line 163 of file mergeMbias.py.

◆ pdg

mergeMbias.pdg = ROOT.TDatabasePDG()

Definition at line 12 of file mergeMbias.py.

◆ productions

dict mergeMbias.productions = {}

Definition at line 143 of file mergeMbias.py.

◆ rnr

mergeMbias.rnr = ROOT.TRandom()

Definition at line 16 of file mergeMbias.py.

◆ ship_geo

mergeMbias.ship_geo = geometry_config.create_config(Yheight=10.0)

Definition at line 18 of file mergeMbias.py.

◆ startOfTarget

float mergeMbias.startOfTarget = -50.0

Definition at line 21 of file mergeMbias.py.