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:
318xx = os.path.abspath(
".").lower()
319if not xx.find(
"neutrino") < 0:
321if not xx.find(
"vdis") < 0:
323elif not xx.find(
"clby") < 0:
325elif not xx.find(
"dis") < 0:
328if len(os.sys.argv) > 1:
329 for i
in range(1, len(os.sys.argv)):
330 for prefix
in os.sys.argv[i].split(
","):
331 if prefix.find(pref) < 0:
332 prefix = pref + prefix
333 prefixes.append(prefix)
342 testdir = path + prefixes[0] +
"1"
344for f
in os.listdir(testdir):
345 if not f.find(
"geofile_full") < 0:
346 fgeo = ROOT.TFile(testdir +
"/" + f)
347 sGeo = fgeo.Get(
"FAIRGeom")
348 inputFile = f.replace(
"geofile_full",
"ship")
351tmp = inputFile.split(
".")
353 dy = float(tmp[1] +
"." + tmp[2])
357if not inputFile.find(
"_D.") < 0:
358 inputFile1 = inputFile.replace(
"_D.",
".")
359 inputFile2 = inputFile
361 inputFile1 = inputFile
362 inputFile2 = inputFile.replace(
".root",
"_D.root")
364import rootUtils
as ut
367PDG = ROOT.TDatabasePDG.Instance()
368import geometry_config
371if not fgeo.FindKey(
"ShipGeo"):
377 ShipGeo = load_from_root_file(fgeo,
"ShipGeo")
382run = ROOT.FairRunSim()
390 at = sTree.MCTrack[it]
391 im = at.GetMotherId()
399 ROOT.TMath.Sqrt(at.GetStartX() ** 2 + at.GetStartY() ** 2), at.GetStartZ()
406top = sGeo.GetTopVolume()
407muon = top.GetNode(
"MuonDetector_1")
408mvol = muon.GetVolume()
409zmuon = muon.GetMatrix().GetTranslation()[2]
410totl = (zmuon + mvol.GetShape().GetDZ()) / u.m
420 for prefix
in prefixes:
421 for i
in range(1, 10):
422 if prefix + str(i)
not in os.listdir(testdir):
424 q1 = inputFile1
in os.listdir(path + prefix + str(i))
425 q2 = inputFile2
in os.listdir(path + prefix + str(i))
426 recFile1 = inputFile1.replace(
".root",
"_rec.root")
427 recFile2 = inputFile2.replace(
".root",
"_rec.root")
428 r1 = recFile1
in os.listdir(path + prefix + str(i))
429 r2 = recFile2
in os.listdir(path + prefix + str(i))
431 inputFile = inputFile1
433 inputFile = inputFile2
436 fname = path + prefix + str(i) +
"/" + inputFile
437 recFile = inputFile.replace(
".root",
"_rec.root")
438 if recFile
not in os.listdir(path + prefix + str(i)):
441 fname = path + prefix + str(i) +
"/" + recFile
442 fchainRec.append(fname)
445 fchain.append(inputFile)
452 n3 = int(ntot / ncpu)
453 cmd =
"python $FAIRSHIP/macro/run_simScript.py --MuonBack -f $SHIPSOFT/data/pythia8_Geant4_onlyMuons.root "
456 for i
in range(1, ncpu + 1):
458 if d
not in os.listdir(
"."):
459 os.system(
"mkdir " + d)
460 os.chdir(
"./" + prefix +
"1")
461 for i
in range(1, ncpu + 1):
464 os.system(
"cp $FAIRSHIP/macro/run_simScript.py .")
465 os.system(cmd +
" -n " + str(n3) +
" -i " + str(ns) +
" > log &")
470 os.chdir(
"../" + prefix + str(i + 1))
474 sGeo = ROOT.gGeoManager
476 for v
in sGeo.GetListOfVolumes():
478 i = sGeo.FindVolumeFast(nm).GetNumber()
484 name =
"myGauss_" + x
485 myGauss = h[x].GetListOfFunctions().FindObject(name)
488 ba = h[x].GetBinCenter(1)
490 be = h[x].GetBinCenter(h[x].GetNbinsX())
491 bw = h[x].GetBinWidth(1)
492 mean = h[x].GetMean()
493 sigma = h[x].GetRMS()
494 norm = h[x].GetEntries() * 0.3
495 myGauss = ROOT.TF1(name,
"[0]*" + str(bw) +
"/([2]*sqrt(2*pi))*exp(-0.5*((x-[1])/[2])**2)+[3]", 4)
496 myGauss.SetParameter(0, norm)
497 myGauss.SetParameter(1, mean)
498 myGauss.SetParameter(2, sigma)
499 myGauss.SetParameter(3, 1.0)
500 myGauss.SetParName(0,
"Signal")
501 myGauss.SetParName(1,
"Mean")
502 myGauss.SetParName(2,
"Sigma")
503 h[x].Fit(myGauss,
"",
"", ba, be)
514 for mu
in [
"",
"_mu",
"_muV0"]:
516 if detName.find(
"LS") < 0:
517 ut.bookHist(h, tag,
"x/y " + detName, 100, -3.0, 3.0, 100, -6.0, 6.0)
519 ut.bookHist(h, tag,
"z phi " + detName, 100, -50.0, 50.0, 100, -1.0, 1.0)
520 ut.bookHist(h, tag +
"_E",
"deposited energy MeV " + detName, 100, 0.0, 2.0)
521 ut.bookHist(h, tag +
"_P",
"particle mom GeV " + detName, 500, 0.0, 50.0)
522 ut.bookHist(h, tag +
"_LP",
"particle mom GeV " + detName, 100, 0.0, 1.0)
523 ut.bookHist(h, tag +
"_OP",
"original particle mom GeV " + detName, 400, 0.0, 400.0)
524 ut.bookHist(h, tag +
"_id",
"particle id " + detName, 5001, -2499.5, 2499.5)
525 ut.bookHist(h, tag +
"_mul",
"multiplicity of hits/tracks " + detName, 100, -0.5, 99.5)
526 ut.bookHist(h, tag +
"_evmul",
"multiplicity of hits/event " + detName, 100, -0.5, 9999.5)
527 ut.bookHist(h, tag +
"_origin",
"r vs z", 100, ztarget, totl, 100, 0.0, 12.0)
528 ut.bookHist(h, tag +
"_originmu",
"r vs z", 100, ztarget, totl, 100, 0.0, 12.0)
531ut.bookHist(h,
"origin",
"r vs z", 100, ztarget, totl, 100, 0.0, 15.0)
532ut.bookHist(h,
"borigin",
"r vs z", 100, ztarget, totl, 500, 0.0, 30.0)
533ut.bookHist(h,
"porigin",
"r vs z secondary", 100, ztarget, totl, 500, 0.0, 30.0)
534ut.bookHist(h,
"mu-inter",
"r vs z", 100, ztarget, totl, 50, 0.0, 3.0)
535ut.bookHist(h,
"muonP",
"muon momentum", 100, 0.0, 400.0)
536ut.bookHist(h,
"weight",
"muon weight", 1000, 1.0e3, 1.0e6)
537ut.bookHist(h,
"delx13",
"x diff first and last point, mu-", 100, -10.0, 10.0)
538ut.bookHist(h,
"delx-13",
"x diff first and last point, mu+", 100, -10.0, 10.0)
539ut.bookHist(h,
"deltaElec",
"energy of delta electrons", 100, 0.0, 10.0)
540ut.bookHist(h,
"secondaries",
"energy of delta electrons", 100, 0.0, 10.0)
541ut.bookHist(h,
"prop_deltaElec",
"energy of delta elec / muon energy", 100, 0.0, 1.0)
542ut.bookHist(h,
"dummy",
"", 10, 0.0, 1.0)
543ut.bookHist(h,
"dE",
"", 100, 0.0, 10.0, 100, 0.0, 10.0)
544h[
"dummy"].SetMaximum(10.0)
565 hLiSc[1][i] =
"T1LiSc_" + str(i)
567for i
in range(1, 48):
568 hLiSc[2][i] =
"T2LiSc_" + str(i)
571 hLiSc[3][i] =
"T3LiSc_" + str(i)
574 hLiSc[5][i] =
"T5LiSc_" + str(i)
577 hMuon[i] =
"muondet" + str(i)
588 if os.path.islink(fn):
589 rfn = os.path.realpath(fn).split(
"eos")[1]
590 fn = ROOT.gSystem.Getenv(
"EOSSHIP") +
"/eos/" + rfn
591 elif not os.path.isfile(fn):
592 raise RuntimeError(
"Don't know what to do with " + fn)
595 processes.append(mp.Process(target=executeOneFile, args=(fn, output, pid)))
614 print(
"now, collect the output")
617 ut.readHists(h,
"tmpHists_" + str(pid) +
".root")
620 for mu
in [
"",
"_mu",
"_muV0"]:
621 for x
in [
"",
"_E",
"_P",
"_LP",
"_OP",
"_id",
"_mul",
"_evmul",
"_origin",
"_originmu"]:
622 for k
in [1, 2, 3, 5]:
625 detName = hLiSc[k][j]
626 tag = detName + mu + x
627 newh = detName[0:2] +
"LiSc" + mu + x
631 h[newh] = h[tag].Clone(newh)
632 h[newh].SetTitle(h[tag].GetTitle().split(
"_")[0])
637 for mu
in [
"",
"_mu",
"_muV0"]:
638 for x
in [
"",
"_E",
"_P",
"_LP",
"_OP",
"_id",
"_mul",
"_evmul",
"_origin",
"_originmu"]:
642 tag = detName + mu + x
643 newh =
"muondet" + mu + x
645 h[newh] = h[tag].Clone(newh)
646 h[newh].SetTitle(h[tag].GetTitle().split(
" ")[0] +
" " + newh)
653 for x
in histlistAll:
654 if histlistAll[x]
in h:
655 histlist[k] = histlistAll[x]
657 for c
in [
"",
"_E",
"_P",
"_LP",
"_OP",
"_id",
"_mul",
"_evmul",
"_origin",
"_originmu"]:
658 h[histlist[k] +
"_mu" + c].Add(h[histlist[k] +
"_muV0" + c])
659 h[histlist[k] + c].Add(h[histlist[k] +
"_mu" + c])
660 h[histlist[k] + c].SetMinimum(0.0)
661 h[histlist[k] +
"_mu" + c].SetMinimum(0.0)
662 h[histlist[k] +
"_muV0" + c].SetMinimum(0.0)
664 nstations = len(histlist)
669 f = ROOT.TFile.Open(fn)
670 sTree = f.Get(
"cbmsim")
671 nEvents = sTree.GetEntries()
672 if sTree.GetBranch(
"GeoTracks"):
673 sTree.SetBranchStatus(
"GeoTracks", 0)
679 sTree.strawtubesPoint,
684 for n
in range(nEvents):
686 theMuon = sTree.MCTrack[0]
687 if len(sTree.MCTrack) > 1:
688 w = sTree.MCTrack[1].GetWeight()
690 print(
"should not happen with new files", n, fn)
691 w = sTree.MCTrack[0].GetWeight()
695 h[
"muonP"].Fill(theMuon.GetP() / u.GeV, w)
697 if ntot % 10000 == 0:
698 print(
"read event", f.GetName(), n)
701 for mcp
in sTree.MCTrack:
702 if mcp.GetMotherId() == 0:
704 if mcp.GetPdgCode() == 11:
705 h[
"deltaElec"].Fill(E, w)
707 h[
"secondaries"].Fill(E, w)
708 h[
"prop_deltaElec"].Fill(
709 esum / sTree.MCTrack[0].GetP(), w
711 for c
in hitContainers:
713 if not ahit.GetEnergyLoss() > 0:
715 detID = ahit.GetDetectorID()
716 if ahit.GetName() ==
"strawtubesPoint":
717 detName =
"strawstation_" + str(ahit.GetStationNumber())
720 E = ahit.GetEnergyLoss()
722 if detID
not in logVols:
723 detName = c.GetName().replace(
"Points",
"")
724 if detName
not in histlistAll.values():
725 print(detID, detName, c.GetName())
727 detName = logVols[detID]
731 E = ahit.GetEnergyLoss()
736 if "PdgCode" in dir(ahit):
737 pdgID = ahit.PdgCode()
738 trackID = ahit.GetTrackID()
740 mom = ROOT.TVector3()
742 aTrack = sTree.MCTrack[trackID]
743 pdgID = aTrack.GetPdgCode()
744 aTrack.GetMomentum(mom)
745 phit = mom.Mag() / u.GeV
748 if phit > 3
and abs(pdgID) == 13:
750 detName = detName + mu
751 if detName.find(
"LS") < 0:
752 h[detName].Fill(x / u.m, y / u.m, w)
754 h[detName].Fill(ahit.GetZ() / u.m, ROOT.TMath.ATan2(y, x) / ROOT.TMath.Pi(), w)
755 h[detName +
"_E"].Fill(E / u.MeV, w)
756 if detName
not in hitmult:
757 hitmult[detName] = {-1: 0}
758 if trackID
not in hitmult[detName]:
759 hitmult[detName][trackID] = 0
760 hitmult[detName][trackID] += 1
761 hitmult[detName][-1] += 1
762 h[detName +
"_id"].Fill(pdgID, w)
763 h[detName +
"_P"].Fill(phit, w)
764 h[detName +
"_LP"].Fill(phit, w)
766 r = ROOT.TMath.Sqrt(aTrack.GetStartX() ** 2 + aTrack.GetStartY() ** 2) / u.m
767 h[
"origin"].Fill(aTrack.GetStartZ() / u.m, r, w)
768 h[detName +
"_origin"].Fill(aTrack.GetStartZ() / u.m, r, w)
770 h[detName +
"_originmu"].Fill(aTrack.GetStartZ() / u.m, r, w)
771 h[
"borigin"].Fill(aTrack.GetStartZ() / u.m, r, w)
772 aTrack.GetMomentum(mom)
773 h[detName +
"_OP"].Fill(mom.Mag() / u.GeV, w)
777 aTrack.GetStartZ() / u.m,
778 ROOT.TMath.Sqrt(aTrack.GetStartX() ** 2 + aTrack.GetStartY() ** 2) / u.m,
781 h[
"mu-inter"].Fill(rz_inter[1] / u.m, rz_inter[0] / u.m, w)
782 for detName
in hitmult:
783 h[detName +
"_evmul"].Fill(hitmult[detName][-1], w)
784 for tr
in hitmult[detName]:
785 h[detName +
"_mul"].Fill(hitmult[detName][tr], w)
787 ut.writeHists(h,
"tmpHists_" + str(pid) +
".root")
814 title=
"hit occupancies",
816 ny=600 * cxcy[nstations][1],
817 cx=cxcy[nstations][0],
818 cy=cxcy[nstations][1],
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=
"deposited energies",
843 ny=600 * cxcy[nstations][1],
844 cx=cxcy[nstations][0],
845 cy=cxcy[nstations][1],
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],
865 ut.bookCanvas(h, key=
"ResultsV", title=
"origin info", nx=600, ny=400, cx=1, cy=1)
866 txt[0] =
"occupancy 1sec 5E13pot "
868 nSpills = len(prefixes)
870 tc = h[
"ResultsI"].cd(i)
876 txt[i] =
"%5.2G" % (h[hn].GetSumOfWeights() / nSpills)
877 labels[i] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i])
879 hn = histlist[i] +
"_mu"
880 tc = h[
"ResultsImu"].cd(i)
883 txt[i + 100] =
"%5.2G" % (h[hn].GetSumOfWeights() / nSpills)
884 labels[i + 100] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i + 100])
886 hn = histlist[i] +
"_muV0"
887 tc = h[
"ResultsImuV0"].cd(i)
890 txt[i + 200] =
"%5.2G" % (h[hn].GetSumOfWeights() / nSpills)
891 labels[i + 200] = ROOT.TLatex().DrawLatexNDC(0.15, 0.85, txt[i + 200])
894 tc = h[
"ResultsII"].cd(i)
895 h[histlist[i] +
"_E"].Draw(
"colz")
898 tc = h[
"ResultsIII"].cd(i)
903 print(
"particle statistics for " + histlist[i])
904 for k
in range(hid.GetNbinsX()):
905 ncont = hid.GetBinContent(k + 1)
906 pid = hid.GetBinCenter(k + 1)
908 temp = int(abs(pid) + 0.5) * int(pid / abs(pid))
909 nm = PDG.GetParticle(temp).GetName()
910 print(f
"{nm} :{ncont:5.2g}")
911 hid = h[histlist[i] +
"_mu_id"]
912 for k
in range(hid.GetNbinsX()):
913 ncont = hid.GetBinContent(k + 1)
914 pid = hid.GetBinCenter(k + 1)
916 temp = int(abs(pid) + 0.5) * int(pid / abs(pid))
917 nm = PDG.GetParticle(temp).GetName()
918 print(f
"{nm} :{ncont:5.2g}")
920 tc = h[
"ResultsV"].cd(1)
921 h[
"origin"].SetStats(0)
922 h[
"origin"].Draw(
"colz")
925 tc = h[
"ResultsIV"].cd(i)
934 fout =
open(
"rareEvents.txt",
"w")
937 if not f.FindObjectAny(
"cbmsim"):
938 print(
"skip file ", f.GetName())
940 sTree = f.Get(
"cbmsim")
942 if sTree.GetBranch(
"GeoTracks"):
943 sTree.SetBranchStatus(
"GeoTracks", 0)
944 nEvents = sTree.GetEntries()
945 for n
in range(nEvents):
948 print(
"now at event ", n, f.GetName())
949 if len(sTree.MCTrack) > 1:
950 wg = sTree.MCTrack[1].GetWeight()
952 wg = sTree.MCTrack[0].GetWeight()
954 for atrack
in sTree.FitTracks:
956 fitStatus = atrack.getFitStatus()
957 if not fitStatus.isFitConverged():
959 nmeas = atrack.getNumPoints()
960 chi2 = fitStatus.getChi2() / nmeas
961 fittedState = atrack.getFittedState()
962 P = fittedState.getMomMag()
963 fout.write(
"rare event with track %i, %s, %8.2F \n" % (n, f.GetName(), wg))
965 fout.write(
"reco %i,%5.3F,%8.2F \n" % (nmeas, chi2, P))
966 mcPartKey = sTree.fitTrack2MC[i]
967 mcPart = sTree.MCTrack[mcPartKey]
968 for ahit
in sTree.strawtubesPoint:
969 if ahit.GetTrackID() == mcPartKey:
971 "P when making hit %i, %8.2F \n"
974 ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2 + ahit.GetPz() ** 2) / u.GeV,
980 Ptruth = mcPart.GetP()
981 fout.write(
"Ptruth %i %8.2F \n" % (mcPart.GetPdgCode(), Ptruth / u.GeV))
987 fout = ROOT.TFile(
"muDISVetoCounter.root",
"recreate")
988 h[
"ntuple"] = ROOT.TNtuple(
"muons",
"muon flux VetoCounter",
"id:px:py:pz:x:y:z:w")
990 sTree = f.Get(
"cbmsim")
991 nEvents = sTree.GetEntries()
992 for n
in range(nEvents):
994 if len(sTree.MCTrack) > 1:
995 wg = sTree.MCTrack[1].GetWeight()
997 wg = sTree.MCTrack[0].GetWeight()
998 for ahit
in sTree.vetoPoint:
999 detID = ahit.GetDetectorID()
1000 if logVols[detID] !=
"VetoTimeDet":
1002 pid = ahit.PdgCode()
1005 P = ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2 + ahit.GetPz() ** 2)
1009 float(ahit.GetPx() / u.GeV),
1010 float(ahit.GetPy() / u.GeV),
1011 float(ahit.GetPz() / u.GeV),
1012 float(ahit.GetX() / u.m),
1013 float(ahit.GetY() / u.m),
1014 float(ahit.GetZ() / u.m),
1022 h[
"fout"] = ROOT.TFile(
"muConcrete.root",
"recreate")
1023 h[
"ntuple"] = ROOT.TNtuple(
"muons",
"muon flux concrete",
"id:px:py:pz:x:y:z:w")
1024 for m
in [
"",
"mu",
"V0"]:
1025 ut.bookHist(h,
"conc_hitz" + m,
"concrete hit z " + m, 100, -100.0, 100.0)
1026 ut.bookHist(h,
"conc_hitzP" + m,
"concrete hit z vs P" + m, 100, -100.0, 100.0, 100, 0.0, 25.0)
1027 ut.bookHist(h,
"conc_hity" + m,
"concrete hit y " + m, 100, -15.0, 15.0)
1028 ut.bookHist(h,
"conc_p" + m,
"concrete hit p " + m, 1000, 0.0, 400.0)
1029 ut.bookHist(h,
"conc_pt" + m,
"concrete hit pt " + m, 100, 0.0, 20.0)
1030 ut.bookHist(h,
"conc_hitzy" + m,
"concrete hit zy " + m, 100, -100.0, 100.0, 100, -15.0, 15.0)
1031 top = sGeo.GetTopVolume()
1032 magn = top.GetNode(
"magyoke_1")
1033 z0 = magn.GetMatrix().GetTranslation()[2] / u.m
1036 if not f.FindObjectAny(
"cbmsim"):
1037 print(
"skip file ", f.GetName())
1039 sTree = f.Get(
"cbmsim")
1040 nEvents = sTree.GetEntries()
1042 for n
in range(nEvents):
1044 if len(sTree.MCTrack) > 1:
1045 wg = sTree.MCTrack[1].GetWeight()
1047 wg = sTree.MCTrack[0].GetWeight()
1048 for ahit
in sTree.vetoPoint:
1049 detID = ahit.GetDetectorID()
1050 if logVols[detID] !=
"rockD":
1053 pid = ahit.PdgCode()
1056 P = ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2 + ahit.GetPz() ** 2)
1057 if abs(pid) == 13
and 3 / u.GeV < P:
1061 float(ahit.GetPx() / u.GeV),
1062 float(ahit.GetPy() / u.GeV),
1063 float(ahit.GetPz() / u.GeV),
1064 float(ahit.GetX() / u.m),
1065 float(ahit.GetY() / u.m),
1066 float(ahit.GetZ() / u.m),
1069 h[
"conc_hitz" + m].Fill(ahit.GetZ() / u.m - z0, wg)
1070 h[
"conc_hity" + m].Fill(ahit.GetY() / u.m, wg)
1071 h[
"conc_p" + m].Fill(P / u.GeV, wg)
1072 h[
"conc_hitzP" + m].Fill(ahit.GetZ() / u.m, P / u.GeV, wg)
1073 Pt = ROOT.TMath.Sqrt(ahit.GetPx() ** 2 + ahit.GetPy() ** 2)
1074 h[
"conc_pt" + m].Fill(Pt / u.GeV, wg)
1075 h[
"conc_hitzy" + m].Fill(ahit.GetZ() / u.m - z0, ahit.GetY() / u.m, wg)
1081 ut.bookCanvas(h, key=
"ResultsV0", title=
"muons hitting concrete, p>3GeV", nx=1000, ny=600, cx=2, cy=2)
1082 ut.bookCanvas(h, key=
"Resultsmu", title=
"muons hitting concrete", nx=1000, ny=600, cx=2, cy=2)
1083 ut.bookCanvas(h, key=
"Results", title=
"hitting concrete", nx=1000, ny=600, cx=2, cy=2)
1084 for m
in [
"",
"mu",
"V0"]:
1085 tc = h[
"Results" + m].cd(1)
1086 h[
"conc_hity" + m].Draw()
1087 tc = h[
"Results" + m].cd(2)
1088 h[
"conc_hitz" + m].Draw()
1089 tc = h[
"Results" + m].cd(3)
1091 h[
"conc_pt" + m].Draw()
1092 tc = h[
"Results" + m].cd(4)
1094 h[
"conc_p" + m].Draw()
1100 fout =
open(fname,
"w")
1101 for fn
in fchainRec:
1103 if not f.FindObjectAny(
"cbmsim"):
1104 print(
"skip file ", f.GetName())
1106 sTree = f.Get(
"cbmsim")
1108 if sTree.GetBranch(
"GeoTracks"):
1109 sTree.SetBranchStatus(
"GeoTracks", 0)
1110 nEvents = sTree.GetEntries()
1111 for n
in range(nEvents):
1114 print(
"now at event ", n, f.GetName())
1115 for ahit
in sTree.vetoPoint:
1116 detID = ahit.GetDetectorID()
1117 if logVols[detID] !=
"Emulsion":
1122 if len(sTree.MCTrack) > 1:
1123 wg = sTree.MCTrack[1].GetWeight()
1125 wg = sTree.MCTrack[0].GetWeight()
1126 fout.write(
"rare emulsion hit %i, %s, %8.3F, %i \n" % (n, f.GetName(), wg, ahit.PdgCode()))
1127 if ahit.GetPz() / u.GeV > 1.0:
1129 "V,P when making hit %8.3F,%8.3F,%8.3F %8.3F,%8.3F,%8.3F (GeV) \n"
1134 ahit.GetPx() / u.GeV,
1135 ahit.GetPy() / u.GeV,
1136 ahit.GetPz() / u.GeV,
1141 "V,P when making hit %8.3F,%8.3F,%8.3F %8.3F,%8.3F,%8.3F (MeV)\n"
1146 ahit.GetPx() / u.MeV,
1147 ahit.GetPy() / u.MeV,
1148 ahit.GetPz() / u.MeV,
1156 for fn
in fchainRec:
1158 if fn.find(str(single)) < 0:
1161 if not f.FindObjectAny(
"cbmsim"):
1162 print(
"skip file ", f.GetName())
1164 sTree = f.Get(
"cbmsim")
1165 nEvents = sTree.GetEntries()
1166 raref = ROOT.TFile(fn.replace(
".root",
"_rare.root"),
"recreate")
1167 newTree = sTree.CloneTree(0)
1168 for n
in range(nEvents):
1171 print(
"now at event ", n, f.GetName())
1174 for fT
in sTree.FitTracks:
1175 fst = fT.getFitStatus()
1176 if not fst.isFitConverged():
1178 if fst.getNdf() < 20:
1183 print(
"filled newTree", rc)
1186 print(
" --> events saved:", newTree.GetEntries())
1193 mom = ROOT.TVector3()
1194 pos = ROOT.TVector3()
1196 goliath_node = top.GetNode(
"volGoliath_1")
1198 golmx = goliath_node.GetMatrix()
1199 zGol = golmx.GetTranslation()[2]
1202 for fn
in fchainRec:
1204 if fn.find(str(single)) < 0:
1207 if not f.FindObjectAny(
"cbmsim"):
1208 print(
"skip file ", f.GetName())
1210 sTree = f.Get(
"cbmsim")
1211 nEvents = sTree.GetEntries()
1212 raref = ROOT.TFile(fn.replace(
".root",
"_clby.root"),
"recreate")
1213 newTree = sTree.CloneTree(0)
1214 for n
in range(nEvents):
1217 print(
"now at event ", n, f.GetName())
1220 for c
in [sTree.vetoPoint, sTree.strawtubesPoint, sTree.ShipRpcPoint]:
1222 if abs(ahit.PdgCode()) != 13:
1236 print(
" --> events saved:", newTree.GetEntries())
1246 cmd =
"$ROOTSYS/bin/hadd rareEvents_" + prefix +
".root -f "
1247 for fn
in fchainRec:
1248 if fn.find(
"muon" + prefix) < 0:
1250 fr = fn.replace(
".root",
"_rare.root")
1251 cmd = cmd +
" " + fr
1258 ut.writeHists(h, prefix +
".root", plusCanvas=
True)
1262 if fn.find(
"root") < 0:
1265 h[
"tc"] = ROOT.TFile(fn)
1266 for x
in [
"ResultsI",
"ResultsII",
"ResultsImu",
"ResultsImuV0",
"ResultsIII",
"ResultsIV",
"ResultsV"]:
1267 h[x] = h[
"tc"].FindObjectAny(x)
1273 prefix = (h[
"tc"].GetName()).replace(
".root",
"")
1274 for x
in [
"ResultsI",
"ResultsII",
"ResultsImu",
"ResultsImuV0",
"ResultsIII",
"ResultsIV",
"ResultsV"]:
1276 if prefix
not in os.listdir(
"."):
1279 h[
"ResultsI"].Print(prefix +
"Back_occ.png")
1280 h[
"ResultsII"].Print(prefix +
"Back_depE.png")
1281 h[
"ResultsImu"].Print(prefix +
"muBack_occ.png")
1282 h[
"ResultsImuV0"].Print(prefix +
"muV0Back_occ.png")
1283 h[
"ResultsIII"].Print(prefix +
"Back_P.png")
1284 h[
"ResultsIV"].Print(prefix +
"Back_OP.png")
1285 h[
"ResultsV"].Print(prefix +
"origin.png")
1290 n1 = h[hn +
"_mu" + tag].GetMaximum()
1291 n2 = h[hn + tag].GetMaximum()
1293 h[hn + tag].SetMaximum(n1)
1294 h[hn +
"_mu" + tag].SetLineColor(4)
1295 h[hn + tag].SetLineColor(3)
1296 h[hn +
"_mu" + tag].Draw()
1297 h[hn + tag].Draw(
"same")
1301 for i
in range(sTree.GetEntries()):
1304 for gt
in sTree.GeoTracks:
1306 i, n, gt.GetFirstPoint()[2], gt.GetLastPoint()[2], gt.GetParticle().GetPdgCode(), gt.GetParticle().P()
1312 sTree = fchain[i].Get(
"cbmsim")
1313 mom = ROOT.TVector3()
1314 for i
in range(sTree.GetEntries()):
1316 nS = len(sTree.strawtubesPoint)
1318 mu = sTree.MCTrack[0]
1322 sp = sTree.strawtubesPoint[(max(0, nS - 3))]
1325 print(
"-----------------------")
1329 sTree = fchain[i].Get(
"cbmsim")
1330 mom = ROOT.TVector3()
1331 for i
in range(sTree.GetEntries()):
1334 for vp
in sTree.vetoPoint:
1335 detName = logVols[vp.GetDetectorID()]
1336 if detName ==
"VetoTimeDet":
1339 print(i, detName, vp.PdgCode())
1341 print(
"-----------------------")
1345 for n
in range(sTree.GetEntries()):
1347 for ahit
in sTree.strawtubesPoint:
1348 dE = ahit.GetEnergyLoss() / u.keV
1350 pa = PDG.GetParticle(ahit.PdgCode())
1352 E = ROOT.TMath.Sqrt(mom.Mag2() + mpa**2)
1354 h[
"dE"].Fill(dE, ekin / u.MeV)
1355 h[
"dE"].SetXTitle(
"keV")
1356 h[
"dE"].SetYTitle(
"MeV")
1363 ni = int(fn[x - 1 : x]) - 1
1364 if nEvents < 100000:
1365 fm =
"$SHIPSOFT/data/pythia8_Geant4_onlyMuons.root"
1367 fm =
"$SHIPSOFT/data/pythia8_Geant4_Yandex_onlyMuons.root"
1368 fmuon = ROOT.TFile(fm)
1369 ntupl = fmuon.Get(
"pythia8-Geant4")
1370 ntot = ntupl.GetEntries()
1371 n3 = int(ntot / ncpu)
1374 P = ROOT.TMath.Sqrt(ntupl.pz * ntupl.pz + ntupl.py * ntupl.py + ntupl.px * ntupl.px)
1375 fout.write(
"original muon %i, %i, %8.2F \n" % (ntupl.parentid, ntupl.pythiaid, P))
1387 xdisk =
"/media/Work/HNL/"
1389 if isinstance(h[x], ROOT.TCanvas):
1391 tn = h[x].GetName() +
".png"
1393 rpath = os.path.abspath(
".").split(
"/HNL/")[1]
1394 lp = rpath.split(
"/")
1396 for i
in range(len(lp)):
1397 if lp[i]
not in os.listdir(prefix):
1398 os.system(
"mkdir " + prefix +
"/" + lp[i])
1399 prefix = prefix +
"/" + lp[i]
1400 os.system(
"cp " + tn +
" " + xdisk + rpath)
1403from operator
import itemgetter
1408 x = [
"rareEvents_61-62.txt",
"rareEvents_71-72.txt"]
1414 if fn ==
"rareEvents_81-102.txt":
1416 for lx
in f.readlines():
1417 line = lx.replace(
"\n",
"")
1418 if not line.find(
"rare event") < 0:
1420 result.append(recTrack)
1421 tmp = line.split(
",")
1422 w = tmp[2].replace(
" ",
"")
1423 ff = tmp[1].split(
"/")[0].replace(
" ",
"")
1424 recTrack = {
"w": w,
"file": ff}
1425 elif not line.find(
"original") < 0:
1426 tmp = line.split(
",")
1427 recTrack[
"origin"] = tmp[0].split(
" ")[2]
1428 recTrack[
"pytiaid"] = tmp[1].replace(
" ",
"")
1429 recTrack[
"o-mom"] = tmp[2].replace(
" ",
"")
1430 elif not line.find(
"reco ") < 0:
1431 tmp = line.split(
",")
1432 recTrack[
"nmeas"] = tmp[0].split(
" ")[1]
1433 recTrack[
"chi2"] = tmp[1]
1434 recTrack[
"p_rec"] = tmp[2].replace(
" ",
"")
1435 elif not line.find(
"making") < 0:
1436 tmp = line.split(
",")
1437 recTrack[
"p_hit"] = tmp[1].replace(
" ",
"")
1438 recTrack[
"fp_hit"] = float(tmp[1].replace(
" ",
""))
1439 elif not line.find(
"Ptruth") < 0:
1440 tmp = line.split(
" ")
1441 recTrack[
"id_hit"] = tmp[1].replace(
" ",
"")
1444 "%4s %8s %8s %4s %8s %8s %8s %8s %8s %8s "
1445 % (
"nr",
"origin",
"pythiaID",
"ID",
"p_orig",
"p_hit",
"chi2",
"weight",
"file",
"cor w")
1448 tmp = sorted(result, key=itemgetter(
"fp_hit"))
1452 for i
in range(len(tmp)):
1454 corw = float(tr[
"w"]) / cor
1455 if float(tr[
"p_hit"]) > 1:
1457 if float(tr[
"p_hit"]) > 2:
1459 if float(tr[
"p_hit"]) > 3:
1462 "%4i %8s %8s %4s %8s %8s %8s %8s %8s %8s "
1476 print(
"guestimate for muonrate above 1GeV = ", muonrate1)
1477 print(
"guestimate for muonrate above 2GeV = ", muonrate2)
1478 print(
"guestimate for muonrate above 3GeV = ", muonrate3)
1489 if p.find(
".root") < 0:
1494 for x
in histlistAll:
1495 if histlistAll[x]
in h:
1496 histlist[k] = histlistAll[x]
1498 nstations = len(histlist)
1499 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)
def makeNicePrintout(list[str]|None x=None)
None readAndMergeHistos(prods)
None extractRareEvents(single=None)
None executeOneFile(fn, output=None, pid=None)
None drawBoth(str tag, hn)
None printAndCopy(str|None prefix=None)
None extractMuCloseByEvents(single=None)
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)
def configure(run, ship_geo)
int open(const char *, int)
Opens a file descriptor.