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