12pdg = ROOT.TDatabasePDG()
29globalPath =
"/eos/experiment/ship/skygrid/background-prod-2018-1gev/"
30fnames =
"pythia8_Geant4_1_1.0.root"
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
100def addRuns(goodRuns, Nstart: int = 0) ->
None:
104 for i
in range(N, min(N + 1000, len(goodRuns))):
105 cmd +=
" $EOSSHIP" + goodRuns[i]
106 tmpFile =
"pythia8_Geant4_" + ecut +
"_c" + str(N + Nstart) +
".root"
107 rc = os.system(
"hadd -j 10 -O " + tmpFile +
" " + cmd)
109 print(
"hadd failed, stop", N)
111 rc = os.system(
"xrdcp " + tmpFile +
" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/" + tmpFile)
113 print(
"copy to EOS failed, stop", N, N + Nstart)
115 rc = os.system(
"rm " + tmpFile)
117 if len(goodRuns) < N:
145 + startDate.__str__().split(
" ")[0]
147 + endDate.__str__().split(
" ")[0]
150 with open(pName,
"w")
as fpi:
152 database[
"goodruns"] = goodRuns
153 database[
"badRuns"] = badRuns
154 pickle.dump(database, fpi)
155 with open(pName)
as fpi:
156 database = pickle.load(fpi)
157 addRuns(database[
"goodruns"], 20000)
164 path = os.environ[
"EOSSHIP"] +
"/eos/experiment/ship/data/Mbias/background-prod-2018/"
165 ut.bookCanvas(h, key=
"canvas", title=
"debug", nx=1600, ny=1200, cx=1, cy=1)
166 h[
"canvas"].SetLogy(1)
167 for i
in range(0, Nmax, 1000):
168 fname =
"pythia8_Geant4_" + ecut +
"_c" + str(i) +
".root"
169 ut.readHists(h, path + fname)
173 if h[x].GetName().find(
"proj") > 0:
175 ut.writeHists(h,
"pythia8_Geant4_" + ecut +
"_c" + str(Nmax) +
"-histos.root")
180 path =
"/afs/cern.ch/project/lbcern/vol1/truf/charm/"
184 for i
in range(cycle, cycle + ncpus):
185 fName = path +
"run" + str(i) +
"/Cascade-run" + str(i) +
"-parp16-MSTP82-1-MSEL4.root"
186 with open(path +
"run" + str(i) +
"/log" + str(i))
as f:
188 for line
in f.readlines():
189 if not line.find(
"Macro finished successfully") < 0:
192 print(
"job not finished properly", fName)
196 if cmd.find(
"root") < 0:
197 print(
"no file found, exit")
199 stat = str(int(Ntot / 1e6)) +
"Mpot"
200 outFile =
"Cascade-run" + str(cycle) +
"-" + str(cycle + ncpus - 1) +
"-parp16-MSTP82-1-MSEL4-" + stat +
".root"
201 rc = os.system(
"hadd -O " + outFile +
" " + cmd)
202 rc = os.system(
"xrdcp " + outFile +
" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/" + outFile)
204 print(
"copy to EOS failed, stop", outFile)
206 rc = os.system(
"rm " + outFile)
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 name = pdg.GetParticle(moPid).GetName()
313 name = procID +
" " + name
315 h[name] = h[
"test"].Clone(name)
316 h[name].Fill(t.GetP(), t.GetPt())
318 h[procID] = h[
"test"].Clone(procID)
319 h[procID].Fill(t.GetP(), t.GetPt())
321 h[x].Scale(1.0 / nTot)
322 tmp = rfile.split(
"/")
323 hname = tmp[len(tmp) - 1].replace(
"pythia8_Geant4",
"Histos")
324 ut.writeHists(h, hname)
334 ut.readHists(hunbiased,
"/media/microdisk/HNL/muonBackground/Histos_1000000-1000600_10.0.root")
335 ut.readHists(hbiased,
"hadded_Histos_1_10.0.root")
339 for key
in hunbiased:
340 unbiased[key] = hunbiased[key].GetSumOfWeights()
342 if key.find(
"proj") < 0
and key.find(
"test") < 0
and key.find(
"pids") < 0:
343 biased[key] = hbiased[key].GetSumOfWeights()
345 for i
in range(1, hbiased[
"pids"].GetNbinsX() + 1):
346 c = hbiased[
"pids"].GetBinContent(i)
348 p[int(hbiased[
"pids"].GetBinCenter(i))] = c
350 sorted_p = sorted(p.items(), key=operator.itemgetter(1))
352 print(
"%25s : %5.2G" % (pdg.GetParticle(p[0]).GetName(), float(p[1])))
353 sorted_pr = sorted(biased.items(), key=operator.itemgetter(1))
354 print(
"origin of muons")
356 if not p[0].find(
"Hadronic inelastic") < 0:
357 if len(p[0]) > len(
"Hadronic inelastic"):
361 denom = unbiased[p[0]]
363 fac = float(p[1]) / denom
364 print(
"%40s : %5.2G %5.1F" % (p[0], float(p[1]), fac))
366 print(
"%40s : %5.2G " % (p[0], float(p[1])))
372 if len(sys.argv) > 3:
383 print(
"methods to run: makeHistos(rfile),makePrintout()")
405 path =
"/eos/experiment/ship/data/Mbias/background-prod-2018"
406 for f
in os.listdir(path):
408 x = os.path.getsize(ff)
415 "goodAndBadRuns_2018-01-01_2018-02-01.pkl",
416 "goodAndBadRuns_2018-02-01_2018-02-06.pkl",
417 "goodAndBadRuns_2018-02-06_2018-02-12.pkl",
418 "goodAndBadRuns_2018-02-12_2018-02-15.pkl",
419 "goodAndBadRuns_2018-02-15_2018-02-21.pkl",
420 "goodAndBadRuns_2018-02-21_2018-02-26.pkl",
426 Nruns += len(dn[
"goodruns"])
427 print(
"Total number of runs:", Nruns)
429 for n
in range(len(allRuns) - 1):
430 with open(allRuns[n])
as fn:
432 for m
in range(n + 1, len(allRuns)):
433 with open(allRuns[m])
as fm:
435 for rn
in dn[
"goodruns"]:
436 for rm
in dm[
"goodruns"]:
438 print(
"double entry found", rn, allRuns[n], allRuns[m])
None compactify(bool|str charm, runMin=0, runMax=0, checkOnly=False)
None YandexProd(startDate, endDate)
None addRuns(goodRuns, int Nstart=0)
None compactifyCascade(cycle)
tuple[list[str], list[int]] GetGoodAndBadRuns(startDate, endDate)
None makeHistos(str rfile)
int open(const char *, int)
Opens a file descriptor.