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