2import os,ROOT,sys,subprocess,pickle,time,datetime
30 fileName =
"pythia8_Geant4_1_"+ecut+
".root"
31 os.system(
"ls -l --full-time "+globalPath+
" >inventory.lst")
32 f=open(
"inventory.lst")
39 print(
"wrong format",tmp)
41 date = tmp[5].split(
'-')
42 time = tmp[6].split(
':')
43 fileDate = datetime.datetime(int(date[0]),int(date[1]),int(date[2]),int(time[0]),int(time[1]),int(time[2].split(
'.')[0]))
44 if fileDate < startDate
or fileDate>endDate:
continue
45 theRun = int(tmp[8].replace(
'\n',
''))
46 test = os.listdir(globalPath+str(theRun))
47 if len(test)<2:
continue
49 rc = os.system(
'grep -q "Number of events produced with activity after hadron absorber" '+globalPath+str(theRun)+
"/stdout")
51 badRuns.append(theRun)
54 if x.find(
'run_fixedTarget')>0:
55 test2 = os.listdir(globalPath+str(theRun)+
'/'+x)
58 f = globalPath+str(theRun)+
"/"+x+
"/"+fileName
59 if fnames+
"tmp" in test2:
65 badRuns.append(theRun)
68 t = ROOT.TFile.Open(os.environ[
"EOSSHIP"]+f)
70 badRuns.append(theRun)
72 if N%1000 == 0: print(N,t.GetName())
75 badRuns.append(theRun)
77 if t.FindObjectAny(
'cbmsim'):
82 badRuns.append(theRun)
84 return goodRuns,badRuns
254 f=ROOT.TFile.Open(rfile)
257 for k
in f.GetListOfKeys():
258 if k.GetName() ==
'FileHeader':
259 tmp = k.GetTitle().split(
'=')[1]
260 tmp2 = tmp.split(
'with')[0]
261 if tmp2.find(
'E')<0: nTot += int(tmp2)
262 else: nTot += float(tmp2)
263 print(
"POT = ",nTot,
" number of events:",sTree.GetEntries())
266 ut.bookHist(h,
'pids',
'pid',19999,-9999.5,9999.5)
267 ut.bookHist(h,
'test',
'muon p/pt',100,0.,400.,100,0.,5.)
268 diMuonDecays = [221, 223, 113, 331, 333]
271 for n
in range(sTree.GetEntries()):
272 rc = sTree.GetEvent(n)
273 for p
in sTree.vetoPoint:
274 t = sTree.MCTrack[p.GetTrackID()]
276 rc = h[
'pids'].Fill(pid)
278 procID = t.GetProcName().Data()
279 mother = t.GetMotherId()
281 moPid = sTree.MCTrack[mother].GetPdgCode()
282 name = pdg.GetParticle(moPid).GetName()
283 name = procID+
' '+name
284 if name
not in h: h[name]=h[
'test'].Clone(name)
285 rc=h[name].Fill(t.GetP(),t.GetPt())
286 if procID
not in h: h[procID]=h[
'test'].Clone(procID)
287 rc=h[procID].Fill(t.GetP(),t.GetPt())
290 tmp = rfile.split(
'/')
291 hname = tmp[len(tmp)-1].replace(
'pythia8_Geant4',
'Histos')
292 ut.writeHists(h,hname)
299 ut.readHists(hunbiased,
'/media/microdisk/HNL/muonBackground/Histos_1000000-1000600_10.0.root')
300 ut.readHists(hbiased,
'hadded_Histos_1_10.0.root')
305 unbiased[l]=hunbiased[l].GetSumOfWeights()
307 if l.find(
'proj') < 0
and l.find(
'test') < 0
and l.find(
'pids') < 0 : biased[l]=hbiased[l].GetSumOfWeights()
309 for i
in range( 1,hbiased[
'pids'].GetNbinsX() + 1 ):
310 c = hbiased[
'pids'].GetBinContent(i)
311 if c>0: p[int(hbiased[
'pids'].GetBinCenter(i))]=c
313 sorted_p = sorted(p.items(), key=operator.itemgetter(1))
315 print(
"%25s : %5.2G"%(pdg.GetParticle(p[0]).GetName(),float(p[1])))
316 sorted_pr = sorted(biased.items(), key=operator.itemgetter(1))
317 print(
"origin of muons")
319 if not p[0].find(
'Hadronic inelastic')<0:
320 if len(p[0])>len(
'Hadronic inelastic' ):
continue
322 if p[0]
in unbiased: denom = unbiased[p[0]]
324 fac = float(p[1])/denom
325 print(
"%40s : %5.2G %5.1F"%(p[0],float(p[1]),fac))
327 print(
"%40s : %5.2G "%(p[0],float(p[1])))