13from method_logger
import MethodLogger
14from pythia8_conf_utils
import (
21 fill_missing_channels,
27 make_particles_stable,
33 P8gen, mass, couplings, sfermionmass, benchmark, inclusive, deepCopy: bool =
False, debug: bool =
True
36 _exit_stack = contextlib.ExitStack()
38 pythia_log = _exit_stack.enter_context(
open(
"pythia8_conf.txt",
"w"))
40 h = make_interpolators(os.path.expandvars(f
"$FAIRSHIP/shipgen/branchingratiosrpvsusybench{benchmark}.dat"))
45 ROOT.TDatabasePDG.Instance()
47 make_particles_stable(P8gen, above_lifetime=1)
49 if inclusive ==
"True":
54 P8gen.SetParameters(
"HardQCD::hardccbar = on")
56 rpvsusy_instance =
rpvsusy.RPVSUSY(mass, couplings, sfermionmass, benchmark, debug=
True)
57 ctau = rpvsusy_instance.computeNLifetime(system=
"FairShip") * u.c_light * u.cm
58 print(
"RPVSUSY ctau ", ctau)
59 P8gen.SetParameters(f
"9900015:new = N2 N2 2 0 0 {mass:.12} 0.0 0.0 0.0 {ctau / u.mm:.12} 0 1 0 1 0")
60 P8gen.SetParameters(
"9900015:isResonance = false")
61 P8gen.SetParameters(
"Next:numberCount = 0")
63 rpvsusy_instance.AddChannelsToPythia(P8gen)
66 P8gen.SetParameters(
"9900015:mayDecay = on")
67 P8gen.SetHNLId(9900015)
69 gamma = u.hbarc / float(ctau)
70 addHNLtoROOT(pid=9900015, m=mass, g=gamma)
72 charmhistograms = [
"d_mu",
"ds_mu"]
74 maxsumBR = getmaxsumbrrpvsusy(h, charmhistograms, mass, couplings)
75 exit_if_zero_br(maxsumBR, inclusive, mass, particle=
"RPV neutralino")
76 gettotalbrrpvsusy(h, charmhistograms, mass, couplings)
80 "431:new D_s+ D_s- 1 3 0 1.96849"
81 " 0.00000 0.00000 0.00000 1.49900e-01 0 1 0 1 0"
84 if getbr_rpvsusy(h,
"ds_mu", mass, couplings[1]) > 0.0:
86 "431:addChannel 1 {:.12} 0 -13 9900015".format(
87 getbr_rpvsusy(h,
"ds_mu", mass, couplings[1]) / maxsumBR
90 sumBR += float(getbr_rpvsusy(h,
"ds_mu", mass, couplings[1]) / maxsumBR)
91 if sumBR < 1.0
and sumBR > 0.0:
92 P8gen.SetParameters(f
"431:addChannel 1 {1.0 - sumBR:.12} 0 22 -11")
96 "411:new D+ D- 1 3 0 1.86962 0.00000 0.00000 0.00000 3.11800e-01 0 1 0 1 0"
99 if getbr_rpvsusy(h,
"d_mu", mass, couplings[1]) > 0.0:
101 "411:addChannel 1 {:.12} 0 -13 9900015".format(
102 getbr_rpvsusy(h,
"d_mu", mass, couplings[1]) / maxsumBR
105 sumBR += float(getbr_rpvsusy(h,
"d_mu", mass, couplings[1]) / maxsumBR)
106 if sumBR < 1.0
and sumBR > 0.0:
107 P8gen.SetParameters(f
"411:addChannel 1 {1.0 - sumBR:.12} 0 22 -11")
112 P8gen.SetParameters(
"HardQCD::hardbbbar = on")
114 rpvsusy_instance =
rpvsusy.RPVSUSY(mass, couplings, sfermionmass, benchmark, debug=
True)
115 ctau = rpvsusy_instance.computeNLifetime(system=
"FairShip") * u.c_light * u.cm
116 P8gen.SetParameters(f
"9900015:new = N2 N2 2 0 0 {mass:.12} 0.0 0.0 0.0 {ctau / u.mm:.12} 0 1 0 1 0")
117 P8gen.SetParameters(
"9900015:isResonance = false")
119 rpvsusy_instance.AddChannelsToPythia(P8gen)
121 P8gen.SetParameters(
"9900015:mayDecay = on")
122 P8gen.SetHNLId(9900015)
124 gamma = u.hbarc / float(ctau)
125 addHNLtoROOT(pid=9900015, m=mass, g=gamma)
127 beautyhistograms = [
"b_mu",
"b_tau",
"b0_nu_mu",
"b0_nu_tau"]
128 maxsumBR = getmaxsumbrrpvsusy(h, beautyhistograms, mass, couplings)
129 exit_if_zero_br(maxsumBR, inclusive, mass, particle=
"RPV neutralino")
130 gettotalbrrpvsusy(h, beautyhistograms, mass, couplings)
134 "521:new B+ B- 1 3 0 5.27925"
135 " 0.00000 0.00000 0.00000 4.91100e-01 0 1 0 1 0"
138 if getbr_rpvsusy(h,
"b_tau", mass, couplings[1]) > 0.0:
140 "521:addChannel 1 {:.12} 0 9900015 -15".format(
141 getbr_rpvsusy(h,
"b_tau", mass, couplings[1]) / maxsumBR
144 sumBR += float(getbr_rpvsusy(h,
"b_tau", mass, couplings[1]) / maxsumBR)
145 if sumBR < 1.0
and sumBR > 0.0:
146 P8gen.SetParameters(f
"521:addChannel 1 {1.0 - sumBR:.12} 0 22 22")
150 "511:new B0 Bbar0 1 0 0 5.27958"
151 " 0.00000 0.00000 0.00000 4.58700e-01 0 1 0 1 0"
154 if getbr_rpvsusy(h,
"b0_nu_tau", mass, couplings[1]) > 0.0:
156 "511:addChannel 1 {:.12} 22 9900015 16".format(
157 getbr_rpvsusy(h,
"b0_nu_tau", mass, couplings[1]) / maxsumBR
160 if sumBR < 1.0
and sumBR > 0.0:
161 P8gen.SetParameters(f
"511:addChannel 1 {1.0 - sumBR:.12} 0 22 22")
169 P8gen, mass, production_couplings, decay_couplings, process_selection, deepCopy: bool =
False, debug: bool =
True
172 This function configures a HNLPythia8Generator instance for SHiP usage.
175 if process_selection
is True:
176 process_selection =
"inclusive"
179 _exit_stack = contextlib.ExitStack()
181 pythia_log = _exit_stack.enter_context(
open(
"pythia8_conf.txt",
"w"))
184 fairship_root = os.environ[
"FAIRSHIP"]
185 histograms = make_interpolators(fairship_root +
"/shipgen/branchingratios.dat")
190 ROOT.TDatabasePDG.Instance()
191 P8gen.SetParameters(
"Next:numberCount = 0")
193 make_particles_stable(P8gen, above_lifetime=1)
198 datafile = fairship_root +
"/python/hnl_production.yaml"
199 with open(datafile)
as f:
200 data = yaml.load(f, Loader=yaml.FullLoader)
201 all_channels = data[
"channels"]
206 if process_selection ==
"inclusive":
212 if process_selection ==
"c":
213 selection = data[
"selections"][
"c"]
214 for cmd
in selection[
"parameters"]:
215 P8gen.SetParameters(cmd)
216 add_hnl(P8gen, mass, decay_couplings)
222 c_particles = selection[
"particles"]
224 add_particles(P8gen, c_particles + [tau_id], data)
230 c_channels = [ch
for ch
in all_channels
if ch[
"id"]
in c_particles]
231 tau_channels = [ch
for ch
in all_channels
if ch[
"id"] == tau_id]
242 primary_decays = [(ch[
"id"], [get_br(histograms, ch, mass, production_couplings)])
for ch
in c_channels]
245 (ds_id, [ds_tau_br, get_br(histograms, ch, mass, production_couplings)])
for ch
in tau_channels
247 all_decays = primary_decays + secondary_decays
250 max_total_br = compute_max_total_br(all_decays)
251 exit_if_zero_br(max_total_br, process_selection, mass)
252 print_scale_factor(1 / max_total_br)
255 for ch
in c_channels:
256 add_channel(P8gen, ch, histograms, mass, production_couplings, 1 / max_total_br)
262 total_tau_br = sum(branching_ratios[1]
for (_, branching_ratios)
in secondary_decays)
263 assert ds_tau_br * total_tau_br <= max_total_br + 1e-12
265 f
"431:addChannel 1 {ds_tau_br * total_tau_br / max_total_br:.12} 0 -15 16"
268 for ch
in tau_channels:
270 add_tau_channel(P8gen, ch, histograms, mass, production_couplings, 1 / (total_tau_br
or 1))
273 fill_missing_channels(P8gen, max_total_br, all_decays)
281 if process_selection
in [
"b",
"bc"]:
282 selection = data[
"selections"][process_selection]
283 for cmd
in selection[
"parameters"]:
284 P8gen.SetParameters(cmd)
285 add_hnl(P8gen, mass, decay_couplings)
288 particles = selection[
"particles"]
289 add_particles(P8gen, particles, data)
292 channels = [ch
for ch
in all_channels
if ch[
"id"]
in particles]
293 decays = [(ch[
"id"], [get_br(histograms, ch, mass, production_couplings)])
for ch
in channels]
296 max_total_br = compute_max_total_br(decays)
297 exit_if_zero_br(max_total_br, process_selection, mass)
298 print_scale_factor(1 / max_total_br)
302 add_channel(P8gen, ch, histograms, mass, production_couplings, 1 / max_total_br)
305 fill_missing_channels(P8gen, max_total_br, decays)
312def add_hnl(P8gen, mass, decay_couplings) -> None:
313 "Adds the HNL to Pythia and ROOT"
314 hnl_instance =
hnl.HNL(mass, decay_couplings, debug=
True)
315 ctau = hnl_instance.computeNLifetime(system=
"FairShip") * u.c_light * u.cm
316 print(f
"HNL ctau {ctau}")
317 P8gen.SetParameters(f
"9900015:new = N2 N2 2 0 0 {mass:.12} 0.0 0.0 0.0 {ctau / u.mm:.12} 0 1 0 1 0")
318 P8gen.SetParameters(
"9900015:isResonance = false")
321 P8gen, hnl_instance, conffile=os.path.expandvars(
"$FAIRSHIP/python/DecaySelection.conf"), verbose=
False
324 P8gen.SetParameters(
"9900015:mayDecay = on")
325 P8gen.SetHNLId(9900015)
327 gamma = u.hbarc / float(ctau)
328 addHNLtoROOT(pid=9900015, m=mass, g=gamma)
332 P8gen.SetParameters(
"SoftQCD:inelastic = on")
333 P8gen.SetParameters(
"PhotonCollision:gmgm2mumu = on")
334 P8gen.SetParameters(
"PromptPhoton:all = on")
335 P8gen.SetParameters(
"WeakBosonExchange:all = on")
None add_hnl(P8gen, mass, decay_couplings)
None setup_pythia_inclusive(P8gen)
None configurerpvsusy(P8gen, mass, couplings, sfermionmass, benchmark, inclusive, bool deepCopy=False, bool debug=True)
None configure(P8gen, mass, production_couplings, decay_couplings, process_selection, bool deepCopy=False, bool debug=True)
def addHNLdecayChannels(P8Gen, hnl, conffile=os.path.expandvars("$FAIRSHIP/python/DecaySelection.conf"), verbose=True)
int open(const char *, int)
Opens a file descriptor.