5import multiprocessing
as mp
7from io
import TextIOWrapper
10from ShipGeoConfig
import load_from_root_file
12ROOT.gInterpreter.ProcessLine(
"typedef double Double32_t")
14if not os.uname()[1].lower().find(
"ubuntu") < 0:
22processes: list[mp.Process | str] = []
319xx = os.path.abspath(
".").lower()
320if not xx.find(
"neutrino") < 0:
322if not xx.find(
"vdis") < 0:
324elif not xx.find(
"clby") < 0:
326elif not xx.find(
"dis") < 0:
329if len(os.sys.argv) > 1:
330 for i
in range(1, len(os.sys.argv)):
331 for prefix
in os.sys.argv[i].split(
","):
332 if prefix.find(pref) < 0:
333 prefix = pref + prefix
334 prefixes.append(prefix)
343 testdir = path + prefixes[0] +
"1"
348for f
in os.listdir(testdir):
349 if not f.find(
"geofile_full") < 0:
350 fgeo = ROOT.TFile(testdir +
"/" + f)
351 sGeo = fgeo.Get(
"FAIRGeom")
352 inputFile = f.replace(
"geofile_full",
"ship")
354if fgeo
is None or not sGeo
or inputFile
is None:
355 raise RuntimeError(
"No geofile_full found in " + testdir)
357tmp = inputFile.split(
".")
359 dy = float(tmp[1] +
"." + tmp[2])
363if not inputFile.find(
"_D.") < 0:
364 inputFile1 = inputFile.replace(
"_D.",
".")
365 inputFile2 = inputFile
367 inputFile1 = inputFile
368 inputFile2 = inputFile.replace(
".root",
"_D.root")
370import rootUtils
as ut
373PDG = ROOT.TDatabasePDG.Instance()
374import geometry_config
377if not fgeo.FindKey(
"ShipGeo"):
383 ShipGeo = load_from_root_file(fgeo,
"ShipGeo")
388run = ROOT.FairRunSim()
393 """Return (r, z) of the ancestor track produced by the primary muon.
395 Returns the sentinel (-1.0, 0.0) if the mother chain does not end at the
396 primary muon (track 0).
398 at = sTree.MCTrack[it]
399 im = at.GetMotherId()
403 return ROOT.TMath.Sqrt(at.GetStartX() ** 2 + at.GetStartY() ** 2), at.GetStartZ()
412top = sGeo.GetTopVolume()
413muon = top.GetNode(
"MuonDetector_1")
414mvol = muon.GetVolume()
415zmuon = muon.GetMatrix().GetTranslation()[2]
416totl = (zmuon + mvol.GetShape().GetDZ()) / u.m
426 for prefix
in prefixes:
427 for i
in range(1, 10):
428 if prefix + str(i)
not in os.listdir(testdir):
430 q1 = inputFile1
in os.listdir(path + prefix + str(i))
431 q2 = inputFile2
in os.listdir(path + prefix + str(i))
432 recFile1 = inputFile1.replace(
".root",
"_rec.root")
433 recFile2 = inputFile2.replace(
".root",
"_rec.root")
434 r1 = recFile1
in os.listdir(path + prefix + str(i))
435 r2 = recFile2
in os.listdir(path + prefix + str(i))
437 inputFile = inputFile1
439 inputFile = inputFile2
442 fname = path + prefix + str(i) +
"/" + inputFile
443 recFile = inputFile.replace(
".root",
"_rec.root")
444 if recFile
not in os.listdir(path + prefix + str(i)):
447 fname = path + prefix + str(i) +
"/" + recFile
448 fchainRec.append(fname)
451 fchain.append(inputFile)
458 n3 = int(ntot / ncpu)
459 cmd =
"python $FAIRSHIP/macro/run_simScript.py --MuonBack -f $SHIPSOFT/data/pythia8_Geant4_onlyMuons.root "
462 for i
in range(1, ncpu + 1):
464 if d
not in os.listdir(
"."):
465 os.system(
"mkdir " + d)
466 os.chdir(
"./" + prefix +
"1")
467 for i
in range(1, ncpu + 1):
470 os.system(
"cp $FAIRSHIP/macro/run_simScript.py .")
471 os.system(cmd +
" -n " + str(n3) +
" -i " + str(ns) +
" > log &")
476 os.chdir(
"../" + prefix + str(i + 1))
480 sGeo = ROOT.gGeoManager
482 for v
in sGeo.GetListOfVolumes():
484 i = sGeo.FindVolumeFast(nm).GetNumber()
490 name =
"myGauss_" + x
491 myGauss = h[x].GetListOfFunctions().FindObject(name)
494 ba = h[x].GetBinCenter(1)
496 be = h[x].GetBinCenter(h[x].GetNbinsX())
497 bw = h[x].GetBinWidth(1)
498 mean = h[x].GetMean()
499 sigma = h[x].GetRMS()
500 norm = h[x].GetEntries() * 0.3
501 myGauss = ROOT.TF1(name,
"[0]*" + str(bw) +
"/([2]*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+[3]", 4)
502 myGauss.SetParameter(0, norm)
503 myGauss.SetParameter(1, mean)
504 myGauss.SetParameter(2, sigma)
505 myGauss.SetParameter(3, 1.0)
506 myGauss.SetParName(0,
"Signal")
507 myGauss.SetParName(1,
"Mean")
508 myGauss.SetParName(2,
"Sigma")
509 h[x].Fit(myGauss,
"",
"", ba, be)
520 for mu
in [
"",
"_mu",
"_muV0"]:
522 if detName.find(
"LS") < 0:
523 ut.bookHist(h, tag,
"x/y " + detName, 100, -3.0, 3.0, 100, -6.0, 6.0)
525 ut.bookHist(h, tag,
"z phi " + detName, 100, -50.0, 50.0, 100, -1.0, 1.0)
526 ut.bookHist(h, tag +
"_E",
"deposited energy MeV " + detName, 100, 0.0, 2.0)
527 ut.bookHist(h, tag +
"_P",
"particle mom GeV " + detName, 500, 0.0, 50.0)
528 ut.bookHist(h, tag +
"_LP",
"particle mom GeV " + detName, 100, 0.0, 1.0)
529 ut.bookHist(h, tag +
"_OP",
"original particle mom GeV " + detName, 400, 0.0, 400.0)
530 ut.bookHist(h, tag +
"_id",
"particle id " + detName, 5001, -2499.5, 2499.5)
531 ut.bookHist(h, tag +
"_mul",
"multiplicity of hits/tracks " + detName, 100, -0.5, 99.5)
532 ut.bookHist(h, tag +
"_evmul",
"multiplicity of hits/event " + detName, 100, -0.5, 9999.5)
533 ut.bookHist(h, tag +
"_origin",
"r vs z", 100, ztarget, totl, 100, 0.0, 12.0)
534 ut.bookHist(h, tag +
"_originmu",
"r vs z", 100, ztarget, totl, 100, 0.0, 12.0)
537ut.bookHist(h,
"origin",
"r vs z", 100, ztarget, totl, 100, 0.0, 15.0)
538ut.bookHist(h,
"borigin",
"r vs z", 100, ztarget, totl, 500, 0.0, 30.0)
539ut.bookHist(h,
"porigin",
"r vs z secondary", 100, ztarget, totl, 500, 0.0, 30.0)
540ut.bookHist(h,
"mu-inter",
"r vs z", 100, ztarget, totl, 50, 0.0, 3.0)
541ut.bookHist(h,
"muonP",
"muon momentum", 100, 0.0, 400.0)
542ut.bookHist(h,
"weight",
"muon weight", 1000, 1.0e3, 1.0e6)
543ut.bookHist(h,
"delx13",
"x diff first and last point, mu-", 100, -10.0, 10.0)
544ut.bookHist(h,
"delx-13",
"x diff first and last point, mu+", 100, -10.0, 10.0)
545ut.bookHist(h,
"deltaElec",
"energy of delta electrons", 100, 0.0, 10.0)
546ut.bookHist(h,
"secondaries",
"energy of delta electrons", 100, 0.0, 10.0)
547ut.bookHist(h,
"prop_deltaElec",
"energy of delta elec / muon energy", 100, 0.0, 1.0)
548ut.bookHist(h,
"dummy",
"", 10, 0.0, 1.0)
549ut.bookHist(h,
"dE",
"", 100, 0.0, 10.0, 100, 0.0, 10.0)
550h[
"dummy"].SetMaximum(10.0)
571 hLiSc[1][i] =
"T1LiSc_" + str(i)
573for i
in range(1, 48):
574 hLiSc[2][i] =
"T2LiSc_" + str(i)
577 hLiSc[3][i] =
"T3LiSc_" + str(i)
580 hLiSc[5][i] =
"T5LiSc_" + str(i)
583 hMuon[i] =
"muondet" + str(i)
594 if os.path.islink(fn):
595 rfn = os.path.realpath(fn).split(
"eos")[1]
596 fn = ROOT.gSystem.Getenv(
"EOSSHIP") +
"/eos/" + rfn
597 elif not os.path.isfile(fn):
598 raise RuntimeError(
"Don't know what to do with " + fn)
601 processes.append(mp.Process(target=executeOneFile, args=(fn, output, pid)))
608 if isinstance(p, mp.Process):
616 if isinstance(p, mp.Process):
621 print(
"now, collect the output")
624 ut.readHists(h,
"tmpHists_" + str(pid) +
".root")
627 for mu
in [
"",
"_mu",
"_muV0"]:
628 for x
in [
"",
"_E",
"_P",
"_LP",
"_OP",
"_id",
"_mul",
"_evmul",
"_origin",
"_originmu"]:
629 for k
in [1, 2, 3, 5]:
632 detName = hLiSc[k][j]
633 tag = detName + mu + x
634 newh = detName[0:2] +
"LiSc" + mu + x
638 h[newh] = h[tag].Clone(newh)
639 h[newh].SetTitle(h[tag].GetTitle().split(
"_")[0])
644 for mu
in [
"",
"_mu",
"_muV0"]:
645 for x
in [
"",
"_E",
"_P",
"_LP",
"_OP",
"_id",
"_mul",
"_evmul",
"_origin",
"_originmu"]:
649 tag = detName + mu + x
650 newh =
"muondet" + mu + x
652 h[newh] = h[tag].Clone(newh)
653 h[newh].SetTitle(h[tag].GetTitle().split(
" ")[0] +
" " + newh)
660 for x
in histlistAll:
661 if histlistAll[x]
in h:
662 histlist[k] = histlistAll[x]
664 for c
in [
"",
"_E",
"_P",
"_LP",
"_OP",
"_id",
"_mul",
"_evmul",
"_origin",
"_originmu"]:
665 h[histlist[k] +
"_mu" + c].Add(h[histlist[k] +
"_muV0" + c])
666 h[histlist[k] + c].Add(h[histlist[k] +
"_mu" + c])
667 h[histlist[k] + c].SetMinimum(0.0)
668 h[histlist[k] +
"_mu" + c].SetMinimum(0.0)
669 h[histlist[k] +
"_muV0" + c].SetMinimum(0.0)
671 nstations = len(histlist)
676 f = ROOT.TFile.Open(fn)
677 sTree = f.Get(
"cbmsim")
678 nEvents = sTree.GetEntries()
679 if sTree.GetBranch(
"GeoTracks"):
680 sTree.SetBranchStatus(
"GeoTracks", 0)
686 sTree.strawtubesPoint,
691 for n
in range(nEvents):
693 theMuon = sTree.MCTrack[0]
694 if len(sTree.MCTrack) > 1:
695 w = sTree.MCTrack[1].GetWeight()
697 print(
"should not happen with new files", n, fn)
698 w = sTree.MCTrack[0].GetWeight()
702 h[
"muonP"].Fill(theMuon.GetP() / u.GeV, w)
704 if ntot % 10000 == 0:
705 print(
"read event", f.GetName(), n)
708 for mcp
in sTree.MCTrack:
709 if mcp.GetMotherId() == 0:
711 if mcp.GetPdgCode() == 11:
712 h[
"deltaElec"].Fill(E, w)
714 h[
"secondaries"].Fill(E, w)
715 h[
"prop_deltaElec"].Fill(
716 esum / sTree.MCTrack[0].GetP(), w
718 for c
in hitContainers:
720 if not ahit.GetEnergyLoss() > 0:
722 detID = ahit.GetDetectorID()
723 if ahit.GetName() ==
"strawtubesPoint":
724 detName =
"strawstation_" + str(ahit.GetStationNumber())
727 E = ahit.GetEnergyLoss()
729 if detID
not in logVols:
730 detName = c.GetName().replace(
"Points",
"")
731 if detName
not in histlistAll.values():
732 print(detID, detName, c.GetName())
734 detName = logVols[detID]
738 E = ahit.GetEnergyLoss()
743 if "PdgCode" in dir(ahit):
744 pdgID = ahit.PdgCode()
745 trackID = ahit.GetTrackID()
747 mom = ROOT.TVector3()
750 aTrack = sTree.MCTrack[trackID]
751 pdgID = aTrack.GetPdgCode()
752 aTrack.GetMomentum(mom)
753 phit = mom.Mag() / u.GeV
756 if phit > 3
and abs(pdgID) == 13:
758 detName = detName + mu
759 if detName.find(
"LS") < 0:
760 h[detName].Fill(x / u.m, y / u.m, w)
762 h[detName].Fill(ahit.GetZ() / u.m, ROOT.TMath.ATan2(y, x) / ROOT.TMath.Pi(), w)
763 h[detName +
"_E"].Fill(E / u.MeV, w)
764 if detName
not in hitmult:
765 hitmult[detName] = {-1: 0}
766 if trackID
not in hitmult[detName]:
767 hitmult[detName][trackID] = 0
768 hitmult[detName][trackID] += 1
769 hitmult[detName][-1] += 1
770 h[detName +
"_id"].Fill(pdgID, w)
771 h[detName +
"_P"].Fill(phit, w)
772 h[detName +
"_LP"].Fill(phit, w)
773 if aTrack
is not None:
774 r = ROOT.TMath.Sqrt(aTrack.GetStartX() ** 2 + aTrack.GetStartY() ** 2) / u.m
775 h[
"origin"].Fill(aTrack.GetStartZ() / u.m, r, w)
776 h[detName +
"_origin"].Fill(aTrack.GetStartZ() / u.m, r, w)
778 h[detName +
"_originmu"].Fill(aTrack.GetStartZ() / u.m, r, w)
779 h[
"borigin"].Fill(aTrack.GetStartZ() / u.m, r, w)
780 aTrack.GetMomentum(mom)
781 h[detName +
"_OP"].Fill(mom.Mag() / u.GeV, w)
784 rz_inter =
origin(sTree, trackID)
786 aTrack.GetStartZ() / u.m,
787 ROOT.TMath.Sqrt(aTrack.GetStartX() ** 2 + aTrack.GetStartY() ** 2) / u.m,
790 h[
"mu-inter"].Fill(rz_inter[1] / u.m, rz_inter[0] / u.m, w)
791 for detName
in hitmult:
792 h[detName +
"_evmul"].Fill(hitmult[detName][-1], w)
793 for tr
in hitmult[detName]:
794 h[detName +
"_mul"].Fill(hitmult[detName][tr], w)
796 ut.writeHists(h,
"tmpHists_" + str(pid) +
".root")
823 title=
"hit occupancies",
825 ny=600 * cxcy[nstations][1],
826 cx=cxcy[nstations][0],
827 cy=cxcy[nstations][1],
832 title=
"hit occupancies",
834 ny=600 * cxcy[nstations][1],
835 cx=cxcy[nstations][0],
836 cy=cxcy[nstations][1],
841 title=
"hit occupancies",
843 ny=600 * cxcy[nstations][1],
844 cx=cxcy[nstations][0],
845 cy=cxcy[nstations][1],
850 title=
"deposited energies",
852 ny=600 * cxcy[nstations][1],
853 cx=cxcy[nstations][0],
854 cy=cxcy[nstations][1],
861 ny=600 * cxcy[nstations][1],
862 cx=cxcy[nstations][0],
863 cy=cxcy[nstations][1],
870 ny=600 * cxcy[nstations][1],
871 cx=cxcy[nstations][0],
872 cy=cxcy[nstations][1],
874 ut.bookCanvas(h, key=
"ResultsV", title=
"origin info", nx=600, ny=400, cx=1, cy=1)
875 txt[0] =
"occupancy 1sec 5E13pot "
877 nSpills = len(prefixes)
879 tc = h[
"ResultsI"].cd(i)
885 txt[i] =
"%5.2G" % (h[hn].GetSumOfWeights() / nSpills)
886 labels[i] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i])
888 hn = histlist[i] +
"_mu"
889 tc = h[
"ResultsImu"].cd(i)
892 txt[i + 100] =
"%5.2G" % (h[hn].GetSumOfWeights() / nSpills)
893 labels[i + 100] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i + 100])
895 hn = histlist[i] +
"_muV0"
896 tc = h[
"ResultsImuV0"].cd(i)
899 txt[i + 200] =
"%5.2G" % (h[hn].GetSumOfWeights() / nSpills)
900 labels[i + 200] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i + 200])
903 tc = h[
"ResultsII"].cd(i)
904 h[histlist[i] +
"_E"].Draw(
"colz")
907 tc = h[
"ResultsIII"].cd(i)
912 print(
"particle statistics for " + histlist[i])
913 for k
in range(hid.GetNbinsX()):
914 ncont = hid.GetBinContent(k + 1)
915 pid = hid.GetBinCenter(k + 1)
917 temp = int(abs(pid) + 0.5) * int(pid / abs(pid))
918 _p = ut.get_particle(temp)
920 print(f
"{nm} :{ncont:5.2g}")
921 hid = h[histlist[i] +
"_mu_id"]
922 for k
in range(hid.GetNbinsX()):
923 ncont = hid.GetBinContent(k + 1)
924 pid = hid.GetBinCenter(k + 1)
926 temp = int(abs(pid) + 0.5) * int(pid / abs(pid))
927 _p = ut.get_particle(temp)
929 print(f
"{nm} :{ncont:5.2g}")
931 tc = h[
"ResultsV"].cd(1)
932 h[
"origin"].SetStats(0)
933 h[
"origin"].Draw(
"colz")
936 tc = h[
"ResultsIV"].cd(i)
945 fout = open(
"rareEvents.txt",
"w")
948 if not f.FindObjectAny(
"cbmsim"):
949 print(
"skip file ", f.GetName())
951 sTree = f.Get(
"cbmsim")
953 if sTree.GetBranch(
"GeoTracks"):
954 sTree.SetBranchStatus(
"GeoTracks", 0)
955 nEvents = sTree.GetEntries()
956 for n
in range(nEvents):
959 print(
"now at event ", n, f.GetName())
960 if len(sTree.MCTrack) > 1:
961 wg = sTree.MCTrack[1].GetWeight()
963 wg = sTree.MCTrack[0].GetWeight()
965 for atrack
in sTree.FitTracks:
967 fitStatus = atrack.getFitStatus()
968 if not fitStatus.isFitConverged():
970 nmeas = atrack.getNumPoints()
971 chi2 = fitStatus.getChi2() / nmeas
972 fittedState = atrack.getFittedState()
973 P = fittedState.getMomMag()
974 fout.write(
"rare event with track %i, %s, %8.2F \n" % (n, f.GetName(), wg))
976 fout.write(
"reco %i,%5.3F,%8.2F \n" % (nmeas, chi2, P))
977 mcPartKey = sTree.fitTrack2MC[i]
978 mcPart = sTree.MCTrack[mcPartKey]
979 for ahit
in sTree.strawtubesPoint:
980 if ahit.GetTrackID() == mcPartKey:
982 "P when making hit %i, %8.2F \n"
985 ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2 + ahit.GetPz() ** 2) / u.GeV,
991 Ptruth = mcPart.GetP()
992 fout.write(
"Ptruth %i %8.2F \n" % (mcPart.GetPdgCode(), Ptruth / u.GeV))
998 fout = ROOT.TFile(
"muDISVetoCounter.root",
"recreate")
999 h[
"ntuple"] = ROOT.TNtuple(
"muons",
"muon flux VetoCounter",
"id:px:py:pz:x:y:z:w")
1001 sTree = f.Get(
"cbmsim")
1002 nEvents = sTree.GetEntries()
1003 for n
in range(nEvents):
1005 if len(sTree.MCTrack) > 1:
1006 wg = sTree.MCTrack[1].GetWeight()
1008 wg = sTree.MCTrack[0].GetWeight()
1009 for ahit
in sTree.vetoPoint:
1010 detID = ahit.GetDetectorID()
1011 if logVols[detID] !=
"VetoTimeDet":
1013 pid = ahit.PdgCode()
1016 P = ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2 + ahit.GetPz() ** 2)
1020 float(ahit.GetPx() / u.GeV),
1021 float(ahit.GetPy() / u.GeV),
1022 float(ahit.GetPz() / u.GeV),
1023 float(ahit.GetX() / u.m),
1024 float(ahit.GetY() / u.m),
1025 float(ahit.GetZ() / u.m),
1033 h[
"fout"] = ROOT.TFile(
"muConcrete.root",
"recreate")
1034 h[
"ntuple"] = ROOT.TNtuple(
"muons",
"muon flux concrete",
"id:px:py:pz:x:y:z:w")
1035 for m
in [
"",
"mu",
"V0"]:
1036 ut.bookHist(h,
"conc_hitz" + m,
"concrete hit z " + m, 100, -100.0, 100.0)
1037 ut.bookHist(h,
"conc_hitzP" + m,
"concrete hit z vs P" + m, 100, -100.0, 100.0, 100, 0.0, 25.0)
1038 ut.bookHist(h,
"conc_hity" + m,
"concrete hit y " + m, 100, -15.0, 15.0)
1039 ut.bookHist(h,
"conc_p" + m,
"concrete hit p " + m, 1000, 0.0, 400.0)
1040 ut.bookHist(h,
"conc_pt" + m,
"concrete hit pt " + m, 100, 0.0, 20.0)
1041 ut.bookHist(h,
"conc_hitzy" + m,
"concrete hit zy " + m, 100, -100.0, 100.0, 100, -15.0, 15.0)
1042 top = sGeo.GetTopVolume()
1043 magn = top.GetNode(
"magyoke_1")
1044 z0 = magn.GetMatrix().GetTranslation()[2] / u.m
1047 if not f.FindObjectAny(
"cbmsim"):
1048 print(
"skip file ", f.GetName())
1050 sTree = f.Get(
"cbmsim")
1051 nEvents = sTree.GetEntries()
1053 for n
in range(nEvents):
1055 if len(sTree.MCTrack) > 1:
1056 wg = sTree.MCTrack[1].GetWeight()
1058 wg = sTree.MCTrack[0].GetWeight()
1059 for ahit
in sTree.vetoPoint:
1060 detID = ahit.GetDetectorID()
1061 if logVols[detID] !=
"rockD":
1064 pid = ahit.PdgCode()
1067 P = ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2 + ahit.GetPz() ** 2)
1068 if abs(pid) == 13
and 3 / u.GeV < P:
1072 float(ahit.GetPx() / u.GeV),
1073 float(ahit.GetPy() / u.GeV),
1074 float(ahit.GetPz() / u.GeV),
1075 float(ahit.GetX() / u.m),
1076 float(ahit.GetY() / u.m),
1077 float(ahit.GetZ() / u.m),
1080 h[
"conc_hitz" + m].Fill(ahit.GetZ() / u.m - z0, wg)
1081 h[
"conc_hity" + m].Fill(ahit.GetY() / u.m, wg)
1082 h[
"conc_p" + m].Fill(P / u.GeV, wg)
1083 h[
"conc_hitzP" + m].Fill(ahit.GetZ() / u.m, P / u.GeV, wg)
1084 Pt = ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2)
1085 h[
"conc_pt" + m].Fill(Pt / u.GeV, wg)
1086 h[
"conc_hitzy" + m].Fill(ahit.GetZ() / u.m - z0, ahit.GetY() / u.m, wg)
1092 ut.bookCanvas(h, key=
"ResultsV0", title=
"muons hitting concrete, p>3GeV", nx=1000, ny=600, cx=2, cy=2)
1093 ut.bookCanvas(h, key=
"Resultsmu", title=
"muons hitting concrete", nx=1000, ny=600, cx=2, cy=2)
1094 ut.bookCanvas(h, key=
"Results", title=
"hitting concrete", nx=1000, ny=600, cx=2, cy=2)
1095 for m
in [
"",
"mu",
"V0"]:
1096 tc = h[
"Results" + m].cd(1)
1097 h[
"conc_hity" + m].Draw()
1098 tc = h[
"Results" + m].cd(2)
1099 h[
"conc_hitz" + m].Draw()
1100 tc = h[
"Results" + m].cd(3)
1102 h[
"conc_pt" + m].Draw()
1103 tc = h[
"Results" + m].cd(4)
1105 h[
"conc_p" + m].Draw()
1111 fout = open(fname,
"w")
1112 for fn
in fchainRec:
1114 if not f.FindObjectAny(
"cbmsim"):
1115 print(
"skip file ", f.GetName())
1117 sTree = f.Get(
"cbmsim")
1119 if sTree.GetBranch(
"GeoTracks"):
1120 sTree.SetBranchStatus(
"GeoTracks", 0)
1121 nEvents = sTree.GetEntries()
1122 for n
in range(nEvents):
1125 print(
"now at event ", n, f.GetName())
1126 for ahit
in sTree.vetoPoint:
1127 detID = ahit.GetDetectorID()
1128 if logVols[detID] !=
"Emulsion":
1133 if len(sTree.MCTrack) > 1:
1134 wg = sTree.MCTrack[1].GetWeight()
1136 wg = sTree.MCTrack[0].GetWeight()
1137 fout.write(
"rare emulsion hit %i, %s, %8.3F, %i \n" % (n, f.GetName(), wg, ahit.PdgCode()))
1138 if ahit.GetPz() / u.GeV > 1.0:
1140 "V,P when making hit %8.3F,%8.3F,%8.3F %8.3F,%8.3F,%8.3F (GeV) \n"
1145 ahit.GetPx() / u.GeV,
1146 ahit.GetPy() / u.GeV,
1147 ahit.GetPz() / u.GeV,
1152 "V,P when making hit %8.3F,%8.3F,%8.3F %8.3F,%8.3F,%8.3F (MeV)\n"
1157 ahit.GetPx() / u.MeV,
1158 ahit.GetPy() / u.MeV,
1159 ahit.GetPz() / u.MeV,
1167 for fn
in fchainRec:
1169 if fn.find(str(single)) < 0:
1172 if not f.FindObjectAny(
"cbmsim"):
1173 print(
"skip file ", f.GetName())
1175 sTree = f.Get(
"cbmsim")
1176 nEvents = sTree.GetEntries()
1177 raref = ROOT.TFile(fn.replace(
".root",
"_rare.root"),
"recreate")
1178 newTree = sTree.CloneTree(0)
1179 for n
in range(nEvents):
1182 print(
"now at event ", n, f.GetName())
1185 for fT
in sTree.FitTracks:
1186 fst = fT.getFitStatus()
1187 if not fst.isFitConverged():
1189 if fst.getNdf() < 20:
1194 print(
"filled newTree", rc)
1197 print(
" --> events saved:", newTree.GetEntries())
1204 mom = ROOT.TVector3()
1205 pos = ROOT.TVector3()
1207 goliath_node = top.GetNode(
"volGoliath_1")
1209 golmx = goliath_node.GetMatrix()
1210 zGol = golmx.GetTranslation()[2]
1213 for fn
in fchainRec:
1215 if fn.find(str(single)) < 0:
1218 if not f.FindObjectAny(
"cbmsim"):
1219 print(
"skip file ", f.GetName())
1221 sTree = f.Get(
"cbmsim")
1222 nEvents = sTree.GetEntries()
1223 raref = ROOT.TFile(fn.replace(
".root",
"_clby.root"),
"recreate")
1224 newTree = sTree.CloneTree(0)
1225 for n
in range(nEvents):
1228 print(
"now at event ", n, f.GetName())
1231 for c
in [sTree.vetoPoint, sTree.strawtubesPoint, sTree.ShipRpcPoint]:
1233 if abs(ahit.PdgCode()) != 13:
1247 print(
" --> events saved:", newTree.GetEntries())
1257 cmd =
"$ROOTSYS/bin/hadd rareEvents_" + prefix +
".root -f "
1258 for fn
in fchainRec:
1259 if fn.find(
"muon" + prefix) < 0:
1261 fr = fn.replace(
".root",
"_rare.root")
1262 cmd = cmd +
" " + fr
1269 ut.writeHists(h, prefix +
".root", plusCanvas=
True)
1273 if fn.find(
"root") < 0:
1276 h[
"tc"] = ROOT.TFile(fn)
1277 for x
in [
"ResultsI",
"ResultsII",
"ResultsImu",
"ResultsImuV0",
"ResultsIII",
"ResultsIV",
"ResultsV"]:
1278 h[x] = h[
"tc"].FindObjectAny(x)
1284 prefix = (h[
"tc"].GetName()).replace(
".root",
"")
1285 for x
in [
"ResultsI",
"ResultsII",
"ResultsImu",
"ResultsImuV0",
"ResultsIII",
"ResultsIV",
"ResultsV"]:
1287 if prefix
not in os.listdir(
"."):
1290 h[
"ResultsI"].Print(prefix +
"Back_occ.png")
1291 h[
"ResultsII"].Print(prefix +
"Back_depE.png")
1292 h[
"ResultsImu"].Print(prefix +
"muBack_occ.png")
1293 h[
"ResultsImuV0"].Print(prefix +
"muV0Back_occ.png")
1294 h[
"ResultsIII"].Print(prefix +
"Back_P.png")
1295 h[
"ResultsIV"].Print(prefix +
"Back_OP.png")
1296 h[
"ResultsV"].Print(prefix +
"origin.png")
1301 n1 = h[hn +
"_mu" + tag].GetMaximum()
1302 n2 = h[hn + tag].GetMaximum()
1304 h[hn + tag].SetMaximum(n1)
1305 h[hn +
"_mu" + tag].SetLineColor(4)
1306 h[hn + tag].SetLineColor(3)
1307 h[hn +
"_mu" + tag].Draw()
1308 h[hn + tag].Draw(
"same")
1312 for i
in range(sTree.GetEntries()):
1315 for gt
in sTree.GeoTracks:
1317 i, n, gt.GetFirstPoint()[2], gt.GetLastPoint()[2], gt.GetParticle().GetPdgCode(), gt.GetParticle().P()
1323 f = ROOT.TFile.Open(fchain[i])
1324 sTree = f.Get(
"cbmsim")
1325 mom = ROOT.TVector3()
1326 for i
in range(sTree.GetEntries()):
1328 nS = len(sTree.strawtubesPoint)
1330 mu = sTree.MCTrack[0]
1334 sp = sTree.strawtubesPoint[(max(0, nS - 3))]
1337 print(
"-----------------------")
1342 f = ROOT.TFile.Open(fchain[i])
1343 sTree = f.Get(
"cbmsim")
1344 mom = ROOT.TVector3()
1345 for i
in range(sTree.GetEntries()):
1348 for vp
in sTree.vetoPoint:
1349 detName = logVols[vp.GetDetectorID()]
1350 if detName ==
"VetoTimeDet":
1353 print(i, detName, vp.PdgCode())
1355 print(
"-----------------------")
1360 for n
in range(sTree.GetEntries()):
1362 for ahit
in sTree.strawtubesPoint:
1363 dE = ahit.GetEnergyLoss() / u.keV
1365 pa = ut.get_particle(ahit.PdgCode())
1367 E = ROOT.TMath.Sqrt(mom.Mag2() + mpa**2)
1369 h[
"dE"].Fill(dE, ekin / u.MeV)
1370 h[
"dE"].SetXTitle(
"keV")
1371 h[
"dE"].SetYTitle(
"MeV")
1378 ni = int(fn[x - 1 : x]) - 1
1379 if nEvents < 100000:
1380 fm =
"$SHIPSOFT/data/pythia8_Geant4_onlyMuons.root"
1382 fm =
"$SHIPSOFT/data/pythia8_Geant4_Yandex_onlyMuons.root"
1383 fmuon = ROOT.TFile(fm)
1384 ntupl = fmuon.Get(
"pythia8-Geant4")
1385 ntot = ntupl.GetEntries()
1386 n3 = int(ntot / ncpu)
1389 P = ROOT.TMath.Sqrt(ntupl.pz * ntupl.pz + ntupl.py * ntupl.py + ntupl.px * ntupl.px)
1390 fout.write(
"original muon %i, %i, %8.2F \n" % (ntupl.parentid, ntupl.pythiaid, P))
1402 xdisk =
"/media/Work/HNL/"
1404 if isinstance(h[x], ROOT.TCanvas):
1406 tn = h[x].GetName() +
".png"
1408 rpath = os.path.abspath(
".").split(
"/HNL/")[1]
1409 lp = rpath.split(
"/")
1411 for i
in range(len(lp)):
1412 if lp[i]
not in os.listdir(prefix):
1413 os.system(
"mkdir " + prefix +
"/" + lp[i])
1414 prefix = prefix +
"/" + lp[i]
1415 os.system(
"cp " + tn +
" " + xdisk + rpath)
1418from operator
import itemgetter
1423 x = [
"rareEvents_61-62.txt",
"rareEvents_71-72.txt"]
1424 result: list[dict[str, str | float]] = []
1428 recTrack: dict[str, str | float] |
None =
None
1429 if fn ==
"rareEvents_81-102.txt":
1431 for lx
in f.readlines():
1432 line = lx.replace(
"\n",
"")
1433 if not line.find(
"rare event") < 0:
1435 result.append(recTrack)
1436 tmp = line.split(
",")
1437 w = tmp[2].replace(
" ",
"")
1438 ff = tmp[1].split(
"/")[0].replace(
" ",
"")
1439 recTrack = {
"w": w,
"file": ff}
1440 elif recTrack
is None:
1443 elif not line.find(
"original") < 0:
1444 tmp = line.split(
",")
1445 recTrack[
"origin"] = tmp[0].split(
" ")[2]
1446 recTrack[
"pytiaid"] = tmp[1].replace(
" ",
"")
1447 recTrack[
"o-mom"] = tmp[2].replace(
" ",
"")
1448 elif not line.find(
"reco ") < 0:
1449 tmp = line.split(
",")
1450 recTrack[
"nmeas"] = tmp[0].split(
" ")[1]
1451 recTrack[
"chi2"] = tmp[1]
1452 recTrack[
"p_rec"] = tmp[2].replace(
" ",
"")
1453 elif not line.find(
"making") < 0:
1454 tmp = line.split(
",")
1455 recTrack[
"p_hit"] = tmp[1].replace(
" ",
"")
1456 recTrack[
"fp_hit"] = float(tmp[1].replace(
" ",
""))
1457 elif not line.find(
"Ptruth") < 0:
1458 tmp = line.split(
" ")
1459 recTrack[
"id_hit"] = tmp[1].replace(
" ",
"")
1462 result.append(recTrack)
1465 "%4s %8s %8s %4s %8s %8s %8s %8s %8s %8s "
1466 % (
"nr",
"origin",
"pythiaID",
"ID",
"p_orig",
"p_hit",
"chi2",
"weight",
"file",
"cor w")
1469 tmp = sorted(result, key=itemgetter(
"fp_hit"))
1473 for i
in range(len(tmp)):
1475 corw = float(tr[
"w"]) / cor
1476 if float(tr[
"p_hit"]) > 1:
1478 if float(tr[
"p_hit"]) > 2:
1480 if float(tr[
"p_hit"]) > 3:
1483 "%4i %8s %8s %4s %8s %8s %8s %8s %8s %8s "
1497 print(
"guestimate for muonrate above 1GeV = ", muonrate1)
1498 print(
"guestimate for muonrate above 2GeV = ", muonrate2)
1499 print(
"guestimate for muonrate above 3GeV = ", muonrate3)
1510 if p.find(
".root") < 0:
1515 for x
in histlistAll:
1516 if histlistAll[x]
in h:
1517 histlist[k] = histlistAll[x]
1519 nstations = len(histlist)
1520 print(
"make plots for ", nstations)
None eventsWithEntryPoints(i)
None rareEventEmulsion(str fname="rareEmulsion.txt")
None originOfMuon(TextIOWrapper fout, int n, fn, nEvents)
None MergeRareEvents(list[str]|None runs=None)
None makePlots(int nstations)
None fitSingleGauss(x, ba=None, be=None)
None debugGeoTracks(sTree)
None eventsWithStrawPoints(i)
None readAndMergeHistos(prods)
None extractRareEvents(single=None)
makeNicePrintout(list[str]|None x=None)
None executeOneFile(fn, output=None, pid=None)
None drawBoth(str tag, hn)
None printAndCopy(str|None prefix=None)
None extractMuCloseByEvents(single=None)
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)
configure(run, ship_geo, str|None geofile=None)