13charmExtern = [4332, 4232, 4132, 4232, 4122, 431, 411, 421]
32 for v
in sTree.vetoPoint:
35 if abs(t.GetPdgCode()) != 13:
37 moID = abs(sTree.MCTrack[t.GetMotherId()].GetPdgCode())
38 if moID
in charmExtern
and noCharm:
41 pName = t.GetProcName().Data()
43 if not pName.find(
"Hadronic inelastic") < 0:
44 t.MultiplyWeight(1.0 / diMuboost)
45 elif not pName.find(
"Lepton pair") < 0
or not pName.find(
"Positron annihilation") < 0:
46 t.MultiplyWeight(1.0 / xSecboost)
47 elif not pName.find(
"Primary particle") < 0
or not pName.find(
"Decay") < 0:
48 if moID
in muSources.values():
49 t.MultiplyWeight(1.0 / diMuboost)
53def PoT(f) -> tuple[float | int, float, float]:
59 for k
in f.GetListOfKeys():
60 if k.GetName() ==
"FileHeader":
62 tmp = txt.split(
"=")[1]
63 tmp2 = tmp.split(
"with")[0]
64 if tmp2.find(
"E") < 0:
73 diMuboost += float(txt[i + 4 :].split(
" ")[0])
78 xSecboost += float(txt[i + 1 :].split(
" ")[0])
79 diMuboost = diMuboost / float(ncycles)
80 xSecboost = xSecboost / float(ncycles)
85 f.Get(
"cbmsim").GetEntries(),
91 return nTot, diMuboost, xSecboost
104def processFile(fin: str, noCharm: bool =
True, process_muons_only: bool =
False) -> int:
105 f = ROOT.TFile.Open(os.environ[
"EOSSHIP"] + path + fin)
106 nPot, diMuboost, xSecboost =
PoT(f)
107 sTree = f.Get(
"cbmsim")
108 outFile = fin.replace(
".root",
"_mu.root")
109 fmu = ROOT.TFile(outFile,
"recreate")
110 newTree = sTree.CloneTree(0)
111 for n
in range(sTree.GetEntries()):
114 if nMu > 0
or not process_muons_only:
116 ff = f.FileHeader.Clone(
"Extracted Muon Background File")
118 tmp = txt.split(
"=")[1]
119 newTxt = txt.replace(tmp.split(
"with")[0].replace(
" ",
""), str(nPot))
122 ff.Write(
"FileHeader", ROOT.TObject.kSingleKey)
197 timer = ROOT.TStopwatch()
199 pp = os.environ[
"EOSSHIP"] + path
200 Rndm = ROOT.TRandom3()
202 if flavour ==
"charm":
203 allFiles = {
"charm":
"pythia8_Geant4_charm_102.2B_10.0_mu.root"}
204 tmp =
"pythia8_Geant4_10.0_cXX_mu.root"
206 allFiles = {
"beauty":
"pythia8_Geant4_beauty_5336B_10.0_mu.root"}
207 tmp =
"pythia8_Geant4_10.0_withCharmXX_mu.root"
208 for run
in range(0, 67000, 1000):
209 allFiles[str(run)] = tmp.replace(
"XX", str(run))
213 f = ROOT.TFile.Open(pp + allFiles[x])
214 nEntries[x] = f.Get(
"cbmsim").GetEntries()
217 frac = nEntries[flavour] / float(Nall)
219 os.system(
"xrdcp " + pp + allFiles[flavour] +
" " + allFiles[flavour])
225 os.system(
"xrdcp " + pp + allFiles[k] +
" " + allFiles[k])
226 os.system(
"hadd -f tmp.root " + allFiles[flavour] +
" " + allFiles[k])
227 os.system(
"rm " + allFiles[k])
228 f = ROOT.TFile(
"tmp.root")
229 sTree = f.Get(
"cbmsim")
230 sTree.LoadBaskets(30000000000)
231 if flavour ==
"charm":
232 outFile = tmp.replace(
"cXX",
"withCharm" + k)
234 outFile = tmp.replace(
"XX",
"andBeauty" + k)
235 fmu = ROOT.TFile(outFile,
"recreate")
236 newTree = sTree.CloneTree(0)
241 while nMbias < nEntries[k]:
242 if Rndm.Rndm() > frac:
244 myList.append(nMbias + nEntries[flavour])
247 if nEntries[flavour] > nCharm:
249 myList.append(nCharm)
256 print(
"start:", outFile, nev)
257 for iev
in range(nev):
258 rc = sTree.GetEntry(myList[iev])
260 if (iev) % 100000 == 0:
262 print(
"status:", timer.RealTime(), k, iev)
265 print(
"finished one file", outFile, nMbias, nCharm)
266 if flavour ==
"charm":
267 ff = f.FileHeader.Clone(
"With Charm Merged Muon Background File")
269 ff = f.FileHeader.Clone(
"With Charm and Beauty Merged Muon Background File")
272 ff.Write(
"FileHeader", ROOT.TObject.kSingleKey)
275 rc = os.system(
"xrdcp " + outFile +
" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/" + outFile)
277 print(
"copy to EOS failed", outFile)
279 rc = os.system(
"rm " + outFile)