195 def GeneratePrimaries(self,anEvent):
196 global debug,nevTot,particleGun,fullTungsten
197 t_0 = time.time()
198 npart = 0
199 if particleGun:
200
201 ztarget = G4ThreeVector(0*cm, 0*cm, -50.*m)
202 vertex = G4PrimaryVertex(ztarget,0.)
203 G4particle = G4PrimaryParticle( 2212 )
204 G4particle.Set4Momentum( 0,0,400*GeV,400.0011*GeV )
205
206 w = 2212 + 0 * 100000
207 G4particle.SetWeight(w)
208 vertex.SetPrimary( G4particle )
209 npart += 1
210 else:
211 while npart == 0:
212 myPythia.GenerateEvent()
213 nevTot+=1
214 myTimer['pythia']+=time.time()-t_0
215
216
217
218
219
220 particles = myPythia.GetListOfParticles()
221 if fullTungsten: z = rnr.Exp(10*cm) -50.*m
222 else: z = rnr.Exp(16*cm) -50.*m
223 ztarget = G4ThreeVector(0*cm, 0*cm, z)
224 vertex = G4PrimaryVertex(ztarget,0.)
225 v = ROOT.TLorentzVector()
226 for p in particles:
227 if p.GetStatusCode()!=1 : continue
228 pid = p.GetPdgCode()
229 mkey = p.GetMother(0)+1
230 mother = myPythia.GetParticle(mkey)
231 if JpsiMainly and abs(pid) != 13 : continue
232 if tauOnly and abs(pid) != 16 : continue
233 if JpsiMainly and mother.GetPdgCode() != 443 : continue
234 if tauOnly :
235 mmkey = mother.GetMother(0)+1
236 mmother = myPythia.GetParticle(mmkey)
237 if abs(mother.GetPdgCode()) != 431 and abs(mmother.GetPdgCode()) != 431 :
238 myPythia.EventListing()
239 continue
240 qed = pid in qedlist
241 p.Momentum(v)
242 Ekin = (v.E()-v.M())
243 if Ekin*GeV < ecut and (qed or allPart): continue
244 G4particle = G4PrimaryParticle( pid )
245 G4particle.Set4Momentum( v.Px()*GeV,v.Py()*GeV,v.Pz()*GeV,v.E()*GeV )
246
247 curPid = p.GetPdgCode() + 10000
248 moPid = mother.GetPdgCode() + 10000
249 w = curPid + moPid * 100000
250 G4particle.SetWeight(w)
251 vertex.SetPrimary( G4particle )
252 npart += 1
253
254 anEvent.AddPrimaryVertex( vertex )
255 if debug and not particleGun: print('new event at ',ztarget.z/m)
256 myTimer['geant4_conv']+=time.time()-t_0