38 fileName =
"pythia8_Geant4_1_" + ecut +
".root"
39 os.system(
"ls -l --full-time " + globalPath +
" >inventory.lst")
40 with open(
"inventory.lst")
as f:
46 print(
"wrong format", tmp)
48 date = tmp[5].split(
"-")
49 time = tmp[6].split(
":")
50 fileDate = datetime.datetime(
51 int(date[0]), int(date[1]), int(date[2]), int(time[0]), int(time[1]), int(time[2].split(
".")[0])
53 if fileDate < startDate
or fileDate > endDate:
55 theRun = int(tmp[8].replace(
"\n",
""))
56 test = os.listdir(globalPath + str(theRun))
61 'grep -q "Number of events produced with activity after hadron absorber" '
67 badRuns.append(theRun)
70 if x.find(
"run_fixedTarget") > 0:
71 test2 = os.listdir(globalPath + str(theRun) +
"/" + x)
72 f = globalPath + str(theRun) +
"/" + x +
"/" + fileName
73 if fnames +
"tmp" in test2:
78 badRuns.append(theRun)
81 t = ROOT.TFile.Open(os.environ[
"EOSSHIP"] + f)
83 badRuns.append(theRun)
89 badRuns.append(theRun)
91 if t.FindObjectAny(
"cbmsim"):
95 badRuns.append(theRun)
97 return goodRuns, badRuns
145 + startDate.__str__().split(
" ")[0]
147 + endDate.__str__().split(
" ")[0]
150 with open(pName,
"wb")
as fpi:
151 database: dict[str, list] = {}
152 database[
"goodruns"] = goodRuns
153 database[
"badRuns"] = badRuns
154 pickle.dump(database, fpi)
155 with open(pName,
"rb")
as fpi:
156 database = pickle.load(fpi)
157 addRuns(database[
"goodruns"], 20000)
210def compactify(charm: bool | str, runMin=0, runMax=0, checkOnly=
False) ->
None:
211 globalPath =
"/afs/cern.ch/project/lbcern/vol2/truf/muonBackground"
214 allDirs = os.listdir(globalPath +
"/charm")
216 for r
in range(int(runMin), int(runMax) + 1):
224 if not x.find(nr + sr) < 0:
225 if not x.find(
"log") < 0:
227 fn =
"pythia8_Geant4_" + nr + sr +
"_" + ecut +
".root"
228 file_path = globalPath +
"/charm/" + x +
"/" + fn
229 if os.path.exists(file_path):
231 t = ROOT.TFile.Open(file_path)
233 badFiles.append(file_path)
235 if t.ReadKeys() == 0:
236 badFiles.append(file_path)
238 if t.FindObjectAny(
"cbmsim"):
239 subruns.append(file_path)
241 badFiles.append(file_path)
246 outputr =
"pythia8_Geant4_charm_" + nr +
"_" + ecut +
".root"
247 allFiles += outputr +
" "
248 os.system(
"hadd " + outputr +
" " + ldir)
249 output =
"pythia8_Geant4_charm_" + str(runMin) +
"_" + str(runMax) +
"_" + ecut +
".root"
250 os.system(
"hadd " + output +
" " + allFiles)
253 output =
"pythia8_Geant4_" + str(runMin) +
"-" + str(runMax) +
"_" + ecut +
".root"
257 for d
in os.listdir(globalPath):
258 if d.find(
"run_fixedTarget") < 0:
260 srun = d.split(
"run_fixedTarget_")[1]
262 if not run > runMax
and not run < runMin:
263 f = globalPath +
"/" + d +
"/pythia8_Geant4_" + srun +
"_" + ecut +
".root "
264 ftmp = f.replace(
".root ",
".roottmp")
265 if os.path.exists(ftmp):
268 t = ROOT.TFile.Open(f)
272 if t.ReadKeys() == 0:
275 if t.FindObjectAny(
"cbmsim"):
280 os.system(
"hadd " + output +
" " + ldir)
285 f = ROOT.TFile.Open(rfile)
286 sTree = f.Get(
"cbmsim")
288 for k
in f.GetListOfKeys():
289 if k.GetName() ==
"FileHeader":
290 tmp = k.GetTitle().split(
"=")[1]
291 tmp2 = tmp.split(
"with")[0]
292 if tmp2.find(
"E") < 0:
296 print(
"POT = ", nTot,
" number of events:", sTree.GetEntries())
299 ut.bookHist(h,
"pids",
"pid", 19999, -9999.5, 9999.5)
300 ut.bookHist(h,
"test",
"muon p/pt", 100, 0.0, 400.0, 100, 0.0, 5.0)
301 for n
in range(sTree.GetEntries()):
303 for p
in sTree.vetoPoint:
304 t = sTree.MCTrack[p.GetTrackID()]
308 procID = t.GetProcName().Data()
309 mother = t.GetMotherId()
311 moPid = sTree.MCTrack[mother].GetPdgCode()
312 _mo = ut.get_particle(moPid)
314 name = procID +
" " + name
316 h[name] = h[
"test"].Clone(name)
317 h[name].Fill(t.GetP(), t.GetPt())
319 h[procID] = h[
"test"].Clone(procID)
320 h[procID].Fill(t.GetP(), t.GetPt())
322 h[x].Scale(1.0 / nTot)
323 tmp = rfile.split(
"/")
324 hname = tmp[len(tmp) - 1].replace(
"pythia8_Geant4",
"Histos")
325 ut.writeHists(h, hname)
335 ut.readHists(hunbiased,
"/media/microdisk/HNL/muonBackground/Histos_1000000-1000600_10.0.root")
336 ut.readHists(hbiased,
"hadded_Histos_1_10.0.root")
340 for key
in hunbiased:
341 unbiased[key] = hunbiased[key].GetSumOfWeights()
343 if key.find(
"proj") < 0
and key.find(
"test") < 0
and key.find(
"pids") < 0:
344 biased[key] = hbiased[key].GetSumOfWeights()
346 for i
in range(1, hbiased[
"pids"].GetNbinsX() + 1):
347 c = hbiased[
"pids"].GetBinContent(i)
349 p[int(hbiased[
"pids"].GetBinCenter(i))] = c
351 sorted_p = sorted(p.items(), key=operator.itemgetter(1))
353 _p_pdg = ut.get_particle(p[0])
354 print(
"%25s : %5.2G" % (_p_pdg.GetName(), float(p[1])))
355 sorted_pr = sorted(biased.items(), key=operator.itemgetter(1))
356 print(
"origin of muons")
358 if not p[0].find(
"Hadronic inelastic") < 0:
359 if len(p[0]) > len(
"Hadronic inelastic"):
363 denom = unbiased[p[0]]
365 fac = float(p[1]) / denom
366 print(
"%40s : %5.2G %5.1F" % (p[0], float(p[1]), fac))
368 print(
"%40s : %5.2G " % (p[0], float(p[1])))