SND@LHC Software
Loading...
Searching...
No Matches
extractNeutrinosAndUpdateWeight.py
Go to the documentation of this file.
1from __future__ import print_function
2import os,ROOT
3import rootUtils as ut
4path = '/eos/experiment/ship/data/Mbias/background-prod-2018/'
5
6# should fill hisograms with neutrinos, for mbias, exclude neutrinos from charm
7# update weight based on process/decay and PoT
8
9charmExtern = [4332,4232,4132,4232,4122,431,411,421,15]
10neutrinos = [12,14,16]
11
12# for 10GeV Yandex Production 65.041 Billion PoT, weight = 768.75 for 5E13 pot
13weightMbias = 768.75
14# for 1GeV Yandex Production 1.8 Billion PoT, weight = 27778. for 5E13 pot
15weightMbias1GeV = 27778.
16
17# for 10GeV charm Production 153.3 Billion PoT equivalent, weight = 489.24
18# added another cycle
19weightCharm = 326.
20# for 1GeV charm Production 10.2 Billion PoT equivalent, weight = 4895.24
21weightCharm1GeV = 4895.24
22
23# for 10GeV beauty Production 5336 Billion PoT equivalent, weight = 9.37
24weightBeauty = 9.37
25
26import rootUtils as ut
27h={}
28PDG = ROOT.TDatabasePDG.Instance()
29for idnu in range(12,17,2):
30 # nu or anti-nu
31 for idadd in range(-1,2):
32 idw=idnu
33 idhnu=1000+idw
34 if idadd==-1:
35 idhnu+=1000
36 idw=-idnu
37 name=PDG.GetParticle(idw).GetName()
38 title = name+" momentum (GeV)"
39 key = idhnu
40 ut.bookHist(h,key,title,400,0.,400.)
41 title = name+" log10-p vs log10-pt"
42 key = idhnu+100
43 ut.bookHist(h,key,title,100,-0.3,1.7,100,-2.,0.5)
44 title = name+" log10-p vs log10-pt"
45 key = idhnu+200
46 ut.bookHist(h,key,title,25,-0.3,1.7,100,-2.,0.5)
47
48def processFile(fin,noCharm=True):
49 f = ROOT.TFile.Open(os.environ['EOSSHIP']+path+fin)
50 print("opened file ",fin)
51 sTree = f.cbmsim
52 for n in range(sTree.GetEntries()):
53 sTree.GetEntry(n)
54 for v in sTree.vetoPoint:
55 nu = v.GetTrackID()
56 t = sTree.MCTrack[nu]
57 pdgCode = t.GetPdgCode()
58 if abs(pdgCode) not in neutrinos: continue
59 moID = abs(sTree.MCTrack[t.GetMotherId()].GetPdgCode())
60 if moID in charmExtern and noCharm: continue # take heavy flavours from separate production
61 idhnu=abs(pdgCode)+1000
62 if pdgCode<0: idhnu+=1000
63 l10ptot = ROOT.TMath.Min(ROOT.TMath.Max(ROOT.TMath.Log10(t.GetP()),-0.3),1.69999)
64 l10pt = ROOT.TMath.Min(ROOT.TMath.Max(ROOT.TMath.Log10(t.GetPt()),-2.),0.4999)
65 key = idhnu
66 h[key].Fill(t.GetP(),weight)
67 key = idhnu+100
68 h[key].Fill(l10ptot,l10pt,weight)
69 key=idhnu+200
70 h[key].Fill(l10ptot,l10pt,weight)
71
72def run():
73 tmp = "pythia8_Geant4_10.0_cXX.root"
74 global weight
75 weight = weightMbias
76 for run in range(0,67000,1000):
77 rc = processFile(tmp.replace('XX',str(run)))
78 ut.writeHists(h,'pythia8_Geant4_10.0_c0-67000_nu.root')
79
80def run1GeV():
81 tmp = "pythia8_Geant4_1.0_cXX.root"
82 global weight
83 weight = weightMbias1GeV
84 for run in range(0,19000,1000):
85 rc = processFile(tmp.replace('XX',str(run)))
86 ut.writeHists(h,'pythia8_Geant4_1.0_c0-19000_nu.root')
87
89 tmp = "pythia8_Geant4_charm_XX-YY_10.0.root"
90 global weight
91 weight = weightCharm
92 for cycle in [0,1,2]:
93 for run in range(0,100,20):
94 crun = run+cycle*1000
95 fname = tmp.replace('XX',str(crun)).replace('YY',str(crun+19))
96 rc = processFile(fname,False)
97 ut.writeHists(h,'pythia8_Geant4_charm_10.0_nu.root')
98
100 fname = "pythia8_Geant4_charm_0-19_1.0.root" # renamed pythia8_Geant4_charm_XX-YY_10.0.root
101 global weight
102 weight = weightCharm1GeV
103 rc = processFile(fname,False)
104 ut.writeHists(h,'pythia8_Geant4_charm_1.0_nu.root')
105
107 global weight
108 weight = weightBeauty
109 fname = "pythia8_Geant4_beauty_5336B_10.0.root"
110 rc = processFile(fname,False)
111 if rc == 0:
112 fmu = fname.replace('.root',"_mu.root")
113 rc = os.system("xrdcp "+fmu+" $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/"+fmu)
114 if rc != 0:
115 print("copy to EOS failed, stop",fmu)
116 else:
117 rc = os.system("rm "+fmu)
118
120 h10={}
121 ut.readHists(h10,'pythia8_Geant4_10.0_c0-67000_nu.root')
122 h1={}
123 ut.readHists(h1,'pythia8_Geant4_1.0_c0-19000_nu.root')
124 c10={}
125 ut.readHists(c10,'pythia8_Geant4_charm_10.0_nu.root')
126 c1={}
127 ut.readHists(c1,'pythia8_Geant4_charm_1.0_nu.root')
128 cmd = "hadd pythia8_Geant4_10.0_withCharm_nu.root pythia8_Geant4_10.0_c0-67000_nu.root pythia8_Geant4_charm_10.0_nu.root"
129 os.system(cmd)
130 cmd = "hadd pythia8_Geant4_1.0_withCharm_nu.root pythia8_Geant4_1.0_c0-19000_nu.root pythia8_Geant4_charm_1.0_nu.root"
131 os.system(cmd)