9charmExtern = [4332,4232,4132,4232,4122,431,411,421]
23 for v
in sTree.vetoPoint:
26 if abs(t.GetPdgCode())!=13:
continue
27 moID = abs(sTree.MCTrack[t.GetMotherId()].GetPdgCode())
28 if moID
in charmExtern
and noCharm:
continue
30 pName = t.GetProcName().Data()
32 if not pName.find(
'Hadronic inelastic')<0:
33 t.MultiplyWeight(1./diMuboost)
34 elif not pName.find(
'Lepton pair')<0:
35 t.MultiplyWeight(1./xSecboost)
36 elif not pName.find(
'Positron annihilation')<0:
37 t.MultiplyWeight(1./xSecboost)
38 elif not pName.find(
'Primary particle')<0
or not pName.find(
'Decay')<0:
39 if moID
in muSources.values():
40 t.MultiplyWeight(1./diMuboost)
82 f = ROOT.TFile.Open(os.environ[
'EOSSHIP']+path+fin)
83 nPot,diMuboost,xSecboost =
PoT(f)
85 outFile = fin.replace(
".root",
"_mu.root")
86 fmu = ROOT.TFile(outFile,
"recreate")
87 newTree = sTree.CloneTree(0)
88 for n
in range(sTree.GetEntries()):
93 ff = f.FileHeader.Clone(
'Extracted Muon Background File')
95 tmp = txt.split(
'=')[1]
96 newTxt = txt.replace(tmp.split(
'with')[0].replace(
' ',
''),str(nPot))
99 ff.Write(
"FileHeader", ROOT.TObject.kSingleKey)
169 timer = ROOT.TStopwatch()
171 pp = os.environ[
'EOSSHIP']+path
175 allFiles = {
'charm':
"pythia8_Geant4_charm_102.2B_10.0_mu.root"}
176 tmp =
"pythia8_Geant4_10.0_cXX_mu.root"
178 allFiles = {
'beauty':
"pythia8_Geant4_beauty_5336B_10.0_mu.root"}
179 tmp =
"pythia8_Geant4_10.0_withCharmXX_mu.root"
180 for run
in range(0,67000,1000):
181 allFiles[str(run)] = tmp.replace(
'XX',str(run))
185 f=ROOT.TFile.Open(pp+allFiles[x])
186 nEntries[x]=f.cbmsim.GetEntries()
190 frac = nEntries[flavour]/float(Nall)
192 os.system(
'xrdcp '+pp +allFiles[flavour] +
' '+allFiles[flavour])
194 if k==flavour:
continue
195 if k
in done:
continue
196 os.system(
'xrdcp '+pp +allFiles[k] +
' ' +allFiles[k])
197 os.system(
'hadd -f tmp.root '+ allFiles[flavour] +
' '+ allFiles[k] )
198 os.system(
'rm '+allFiles[k])
199 f = ROOT.TFile(
'tmp.root')
201 sTree.LoadBaskets(30000000000)
203 outFile = tmp.replace(
'cXX',
'withCharm'+k)
205 outFile = tmp.replace(
'XX',
'andBeauty'+k)
206 fmu = ROOT.TFile(outFile,
"recreate")
207 newTree = sTree.CloneTree(0)
212 while nMbias<nEntries[k]:
214 if Rndm.Rndm() > frac:
216 myList.append( nMbias+nEntries[flavour] )
219 if nEntries[flavour]>nCharm:
221 myList.append( nCharm )
223 else: copyEvent =
False
227 print(
"start:",outFile,nev)
228 for iev
in range(nev) :
229 rc =sTree.GetEntry(myList[iev])
233 print(
"status:",timer.RealTime(),k,iev)
236 print(
"finished one file",outFile,nMbias,nCharm)
238 ff = f.FileHeader.Clone(
'With Charm Merged Muon Background File')
240 ff = f.FileHeader.Clone(
'With Charm and Beauty Merged Muon Background File')
243 ff.Write(
"FileHeader", ROOT.TObject.kSingleKey)
246 rc = os.system(
"xrdcp "+outFile+
" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/"+outFile)
248 print(
"copy to EOS failed",outFile)
250 rc = os.system(
"rm "+outFile)