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, 4322, 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# Active weight, set by the per-source entry points before they call
32# the neutrino histogram fillers.
33weight: float = weightMbias
34
35
36h = {}
37PDG = ROOT.TDatabasePDG.Instance()
38for idnu in range(12, 17, 2):
39 # nu or anti-nu
40 for idadd in range(-1, 2):
41 idw = idnu
42 idhnu = 1000 + idw
43 if idadd == -1:
44 idhnu += 1000
45 idw = -idnu
46 _p = ut.get_particle(idw)
47 name = _p.GetName()
48 title = name + " momentum (GeV)"
49 key = idhnu
50 ut.bookHist(h, key, title, 400, 0.0, 400.0)
51 title = name + " log10-p vs log10-pt"
52 key = idhnu + 100
53 ut.bookHist(h, key, title, 100, -0.3, 1.7, 100, -2.0, 0.5)
54 title = name + " log10-p vs log10-pt"
55 key = idhnu + 200
56 ut.bookHist(h, key, title, 25, -0.3, 1.7, 100, -2.0, 0.5)
57
58
59def processFile(fin: str, noCharm: bool = True) -> None:
60 f = ROOT.TFile.Open(os.environ["EOSSHIP"] + path + fin)
61 print("opened file ", fin)
62 sTree = f.Get("cbmsim")
63 for n in range(sTree.GetEntries()):
64 sTree.GetEntry(n)
65 for v in sTree.vetoPoint:
66 nu = v.GetTrackID()
67 t = sTree.MCTrack[nu]
68 pdgCode = t.GetPdgCode()
69 if abs(pdgCode) not in neutrinos:
70 continue
71 moID = abs(sTree.MCTrack[t.GetMotherId()].GetPdgCode())
72 if moID in charmExtern and noCharm:
73 continue # take heavy flavours from separate production
74 idhnu = abs(pdgCode) + 1000
75 if pdgCode < 0:
76 idhnu += 1000
77 l10ptot = ROOT.TMath.Min(ROOT.TMath.Max(ROOT.TMath.Log10(t.GetP()), -0.3), 1.69999)
78 l10pt = ROOT.TMath.Min(ROOT.TMath.Max(ROOT.TMath.Log10(t.GetPt()), -2.0), 0.4999)
79 key = idhnu
80 h[key].Fill(t.GetP(), weight)
81 key = idhnu + 100
82 h[key].Fill(l10ptot, l10pt, weight)
83 key = idhnu + 200
84 h[key].Fill(l10ptot, l10pt, weight)
85
86
87def run() -> None:
88 tmp = "pythia8_Geant4_10.0_cXX.root"
89 global weight
90 weight = weightMbias
91 for run in range(0, 67000, 1000):
92 processFile(tmp.replace("XX", str(run)))
93 ut.writeHists(h, "pythia8_Geant4_10.0_c0-67000_nu.root")
94
95
96def run1GeV() -> None:
97 tmp = "pythia8_Geant4_1.0_cXX.root"
98 global weight
99 weight = weightMbias1GeV
100 for run in range(0, 19000, 1000):
101 processFile(tmp.replace("XX", str(run)))
102 ut.writeHists(h, "pythia8_Geant4_1.0_c0-19000_nu.root")
103
104
105def run4Charm() -> None:
106 tmp = "pythia8_Geant4_charm_XX-YY_10.0.root"
107 global weight
108 weight = weightCharm
109 for cycle in [0, 1, 2]:
110 for run in range(0, 100, 20):
111 crun = run + cycle * 1000
112 fname = tmp.replace("XX", str(crun)).replace("YY", str(crun + 19))
113 processFile(fname, False)
114 ut.writeHists(h, "pythia8_Geant4_charm_10.0_nu.root")
115
116
117def run4Charm1GeV() -> None:
118 fname = "pythia8_Geant4_charm_0-19_1.0.root" # renamed pythia8_Geant4_charm_XX-YY_10.0.root
119 global weight
120 weight = weightCharm1GeV
121 processFile(fname, False)
122 ut.writeHists(h, "pythia8_Geant4_charm_1.0_nu.root")
123
124
125def run4beauty() -> None:
126 global weight
127 weight = weightBeauty
128 fname = "pythia8_Geant4_beauty_5336B_10.0.root"
129 rc = processFile(fname, False)
130 if rc == 0:
131 fmu = fname.replace(".root", "_mu.root")
132 rc = os.system("xrdcp " + fmu + " $EOSSHIP/eos/experiment/ship/data/Mbias/background-prod-2018/" + fmu)
133 if rc != 0:
134 print("copy to EOS failed, stop", fmu)
135 else:
136 rc = os.system("rm " + fmu)
137
138
139def finalResult() -> None:
140 h10 = {}
141 ut.readHists(h10, "pythia8_Geant4_10.0_c0-67000_nu.root")
142 h1 = {}
143 ut.readHists(h1, "pythia8_Geant4_1.0_c0-19000_nu.root")
144 c10 = {}
145 ut.readHists(c10, "pythia8_Geant4_charm_10.0_nu.root")
146 c1 = {}
147 ut.readHists(c1, "pythia8_Geant4_charm_1.0_nu.root")
148 cmd = "hadd pythia8_Geant4_10.0_withCharm_nu.root pythia8_Geant4_10.0_c0-67000_nu.root pythia8_Geant4_charm_10.0_nu.root"
149 os.system(cmd)
150 cmd = (
151 "hadd pythia8_Geant4_1.0_withCharm_nu.root pythia8_Geant4_1.0_c0-19000_nu.root pythia8_Geant4_charm_1.0_nu.root"
152 )
153 os.system(cmd)
None processFile(str fin, bool noCharm=True)