FairShip
Loading...
Searching...
No Matches
pythia8darkphoton_conf.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 contextlib
5import os
6
7import darkphoton
8import proton_bremsstrahlung
9import readDecayTable
10import ROOT
11import shipunit as u
12from method_logger import MethodLogger
13from pythia8_conf_utils import make_particles_stable
14
15# Boundaries for production in meson decays
16# mass of the mesons
17pi0mass = 0.1349770
18etamass = 0.547862
19omegamass = 0.78265
20eta1mass = 0.95778
21
22
23def addDPtoROOT(pid=9900015, m=0.2, g=4.866182e-04):
24 pdg = ROOT.TDatabasePDG.Instance()
25 pdg.AddParticle("A", "DarkPhoton", m, False, g, 0.0, "A", pid)
26
27
28def manipulatePhysics(motherMode, mass, P8gen):
29 # changes of the table, now it is deleted and we have each meson mother for each meson production
30 # print motherMode
31 if motherMode == "pi0" and pi0mass - mass >= 0.0000001:
32 # use pi0 -> gamma A'
33 selectedMum = 111
34 P8gen.SetParameters("111:oneChannel = 1 1 0 22 9900015")
35
36 elif motherMode == "eta" and etamass - mass >= 0.000001:
37 # use eta -> gamma A'
38 # print "eta"
39 selectedMum = 221
40 P8gen.SetParameters("221:oneChannel = 1 1 0 22 9900015")
41
42 elif motherMode == "omega" and omegamass - mass >= 0.00001:
43 # use omega -> pi0 A'
44 # print "omega"
45 selectedMum = 223
46 P8gen.SetParameters("223:oneChannel = 1 1 0 111 9900015")
47
48 elif motherMode == "eta1" and eta1mass - mass >= 0.00001:
49 # use eta' -> gamma A'
50 selectedMum = 331
51 P8gen.SetParameters("331:oneChannel = 1 1 0 22 9900015")
52 # should be considered also for mass < 0.188 GeV....
53 # P8gen.SetParameters("331:oneChannel = 1 1 0 223 9900015")29%BR
54 # P8gen.SetParameters("331:oneChannel = 1 1 0 113 9900015")2.75%BR
55
56 elif motherMode == "eta11" and eta1mass - mass >= 0.00001:
57 # use eta' -> gamma A'
58 selectedMum = 331
59 P8gen.SetParameters("331:oneChannel = 1 1 0 113 9900015")
60 # should be considered also for mass < 0.188 GeV....
61 # P8gen.SetParameters("331:oneChannel = 1 1 0 223 9900015")29%BR
62 # P8gen.SetParameters("331:oneChannel = 1 1 0 113 9900015")2.75%BR
63
64 else:
65 # print "ERROR: please enter a nicer mass, for meson production it needs to be between %3.3f and %3.3f."%(pi0Start,eta1Stop)
66 return -1
67 return selectedMum
68
69
70def configure(P8gen, mass, epsilon, inclusive, motherMode, deepCopy=False, debug=True):
71 # configure pythia8 for Ship usage
72 _exit_stack = contextlib.ExitStack()
73 if debug:
74 pythia_log = _exit_stack.enter_context(open("pythia8_conf.txt", "w")) # noqa: SIM115
75 P8gen = MethodLogger(P8gen, sink=pythia_log)
76 P8gen.UseRandom3() # TRandom1 or TRandom3 ?
77 P8gen.SetMom(400) # beam momentum in GeV
78 if deepCopy:
79 P8gen.UseDeepCopy()
80 ROOT.TDatabasePDG.Instance()
81 if inclusive == "meson":
82 # let strange particle decay in Geant4
83 make_particles_stable(P8gen, above_lifetime=1)
84
85 # Configuring production
86 P8gen.SetParameters("SoftQCD:nonDiffractive = on")
87
88 elif inclusive == "qcd":
89 P8gen.SetDY()
90 P8gen.SetMinDPMass(0.7)
91
92 if mass < P8gen.MinDPMass():
93 print("WARNING! Mass is too small, minimum is set to %3.3f GeV." % P8gen.MinDPMass())
94 _exit_stack.close()
95 return 0
96
97 # produce a Z' from hidden valleys model
98 make_particles_stable(P8gen, above_lifetime=1)
99
100 # Configuring production
101 P8gen.SetParameters("HiddenValley:ffbar2Zv = on")
102 P8gen.SetParameters("HiddenValley:Ngauge = 1")
103
104 elif inclusive == "pbrem":
105 P8gen.SetParameters("ProcessLevel:all = off")
106 # Also allow resonance decays, with showers in them
107 # P8gen.SetParameters("Standalone:allowResDec = on")
108
109 # Optionally switch off decays.
110 # P8gen.SetParameters("HadronLevel:Decay = off")
111
112 # Switch off automatic event listing in favour of manual.
113 P8gen.SetParameters("Next:numberShowInfo = 0")
114 P8gen.SetParameters("Next:numberShowProcess = 0")
115 P8gen.SetParameters("Next:numberShowEvent = 0")
116 proton_bremsstrahlung.protonEnergy = P8gen.GetMom()
117 norm = proton_bremsstrahlung.prodRate(mass, epsilon)
118 print("A' production rate per p.o.t: \t %.8g" % norm)
119 P8gen.SetPbrem(proton_bremsstrahlung.hProdPDF(mass, epsilon, norm, 350, 1500))
120
121 # Define dark photon
122 DP_instance = darkphoton.DarkPhoton(mass, epsilon)
123 ctau = DP_instance.cTau()
124 print("ctau p8dpconf file =%3.6f cm" % ctau)
125 print("Initial particle parameters for PDGID %d :" % P8gen.GetDPId())
126 P8gen.List(P8gen.GetDPId())
127 if inclusive == "qcd":
128 dpid = P8gen.GetDPId()
129 P8gen.SetParameters(f"{dpid}:m0 = {mass:.12}")
130 # P8gen.SetParameters(str(P8gen.GetDPId())+":mWidth = "+str(u.mm/ctau))
131 P8gen.SetParameters(f"{dpid}:mWidth = {u.hbarc / ctau:.12}")
132 P8gen.SetParameters(f"{dpid}:mMin = 0.001")
133 P8gen.SetParameters(f"{dpid}:tau0 = {ctau / u.mm:.12}")
134 # P8gen.SetParameters("ParticleData:modeBreitWigner = 0")
135 # P8gen.SetParameters(str(P8gen.GetDPId())+":isResonance = false")
136 # P8gen.SetParameters(str(P8gen.GetDPId())+":all = A A 3 0 0 "+str(mass)+" 0.0 0.0 0.0 "+str(ctau/u.mm)+" 0 1 0 1 0")
137 P8gen.SetParameters(f"{dpid}:onMode = off")
138 else:
139 P8gen.SetParameters(
140 f"{P8gen.GetDPId()}:new = A A 3 0 0 {mass:.12} 0.0 0.0 0.0 {ctau / u.mm:.12} 0 1 0 1 0"
141 )
142 # if (inclusive=="pbrem"):
143
147
148 P8gen.SetParameters("Next:numberCount = 0")
149
150 # Configuring decay modes...
152 P8gen,
153 mass,
154 DP_instance,
155 conffile=os.path.expandvars("$FAIRSHIP/python/darkphotonDecaySelection.conf"),
156 verbose=True,
157 )
158 # Finish DP setup...
159 P8gen.SetParameters(f"{P8gen.GetDPId()}:mayDecay = on")
160 # P8gen.SetDPId(P8gen.GetDPId())
161 # also add to PDG
162 gamma = u.hbarc / float(ctau) # 197.3269631e-16 / float(ctau) # hbar*c = 197 MeV*fm = 197e-16 GeV*cm
163 print("gamma=%e" % gamma)
164 addDPtoROOT(pid=P8gen.GetDPId(), m=mass, g=gamma)
165
166 if inclusive == "meson":
167 # change meson decay to dark photon depending on mass
168 selectedMum = manipulatePhysics(motherMode, mass, P8gen)
169 print("selected mum is : %d" % selectedMum)
170 if selectedMum == -1:
171 _exit_stack.close()
172 return 0
173
174 # P8gen.SetParameters("Check:particleData = on")
175
176 _exit_stack.close()
177
178 return 1
hProdPDF(mDarkPhoton, epsilon, norm, binsp, binstheta, tmin=-0.5 *math.pi, tmax=0.5 *math.pi, suffix="")
prodRate(mDarkPhoton, epsilon, tmin=-0.5 *math.pi, tmax=0.5 *math.pi)
addDPtoROOT(pid=9900015, m=0.2, g=4.866182e-04)
manipulatePhysics(motherMode, mass, P8gen)
configure(P8gen, mass, epsilon, inclusive, motherMode, deepCopy=False, debug=True)
addDarkPhotondecayChannels(P8gen, mDP, DP, conffile=os.path.expandvars("$FAIRSHIP/python/darkphotonDecaySelection.conf"), verbose=True)