Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pysspa.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pysspa.f
1 
2 C*********************************************************************
3 
4 C...PYSSPA
5 C...Generates spacelike parton showers.
6 
7  SUBROUTINE pysspa(IPU1,IPU2)
8 
9 C...Double precision and integer declarations.
10  IMPLICIT DOUBLE PRECISION(a-h, o-z)
11  IMPLICIT INTEGER(i-n)
12  INTEGER pyk,pychge,pycomp
13 C...Commonblocks.
14  common/pyjets/n,npad,k(4000,5),p(4000,5),v(4000,5)
15  common/pydat1/mstu(200),paru(200),mstj(200),parj(200)
16  common/pydat2/kchg(500,4),pmas(500,4),parf(2000),vckm(4,4)
17  common/pysubs/msel,mselpd,msub(500),kfin(2,-40:40),ckin(200)
18  common/pypars/mstp(200),parp(200),msti(200),pari(200)
19  common/pyint1/mint(400),vint(400)
20  common/pyint2/iset(500),kfpr(500,2),coef(500,20),icol(40,4,2)
21  common/pyint3/xsfx(2,-40:40),isig(1000,3),sigh(1000)
22  SAVE /pyjets/,/pydat1/,/pydat2/,/pysubs/,/pypars/,/pyint1/,
23  &/pyint2/,/pyint3/
24 C...Local arrays and data.
25  dimension kfls(4),is(2),xs(2),zs(2),q2s(2),tevcsv(2),tevesv(2),
26  &xfs(2,-25:25),xfa(-25:25),xfb(-25:25),xfn(-25:25),wtapc(-25:25),
27  &wtape(-25:25),wtsf(-25:25),the2(2),alam(2),dq2(3),dpc(3),dpd(4),
28  &dpb(4),robo(5),more(2),kfbeam(2),q2mncs(2),kcfi(2),nfis(2),
29  &thefis(2,2),isfi(2),dphi(2),mcesv(2)
30  DATA is/2*0/
31 
32 C...Read out basic information; set global Q^2 scale.
33  ipus1=ipu1
34  ipus2=ipu2
35  isub=mint(1)
36  q2mx=vint(56)
37  vint2r=vint(2)*vint(143)*vint(144)
38  IF(iset(isub).EQ.2.OR.iset(isub).EQ.9.OR.iset(isub).EQ.11) q2mx=
39  &min(vint2r,parp(67)*vint(56))
40  fcq2mx=1d0
41 
42 C...Define which processes ME corrections have been implemented for.
43  mecor=0
44  IF(mstp(68).EQ.1.OR.mstp(68).EQ.3) THEN
45  IF(isub.EQ.1.OR.isub.EQ.2.OR.isub.EQ.141.OR.isub.EQ.142.OR.
46  & isub.EQ.144) mecor=1
47  IF(isub.EQ.102.OR.isub.EQ.152.OR.isub.EQ.157) mecor=2
48  IF(isub.EQ.3.OR.isub.EQ.151.OR.isub.EQ.156) mecor=3
49  ENDIF
50 
51 C...Initialize QCD evolution and check phase space.
52  q2mnc=parp(62)**2
53  q2mncs(1)=q2mnc
54  q2mncs(2)=q2mnc
55  IF(mint(107).EQ.2.AND.mstp(66).EQ.2) THEN
56  q0s=parp(15)**2
57  ps=vint(3)**2
58  q2eff=vint(54)*((q0s+ps)/(vint(54)+ps))*
59  & exp(ps*(vint(54)-q0s)/((vint(54)+ps)*(q0s+ps)))
60  q2int=sqrt(q0s*q2eff)
61  q2mncs(1)=max(q2mnc,q2int)
62  ELSEIF(mint(107).EQ.3.AND.mstp(66).GE.1) THEN
63  q2mncs(1)=max(q2mnc,vint(283))
64  ENDIF
65  IF(mint(108).EQ.2.AND.mstp(66).EQ.2) THEN
66  q0s=parp(15)**2
67  ps=vint(4)**2
68  q2eff=vint(54)*((q0s+ps)/(vint(54)+ps))*
69  & exp(ps*(vint(54)-q0s)/((vint(54)+ps)*(q0s+ps)))
70  q2int=sqrt(q0s*q2eff)
71  q2mncs(2)=max(q2mnc,q2int)
72  ELSEIF(mint(108).EQ.3.AND.mstp(66).GE.1) THEN
73  q2mncs(2)=max(q2mnc,vint(284))
74  ENDIF
75  mcev=0
76  alams=paru(112)
77  paru(112)=parp(61)
78  fq2c=1d0
79  tcmx=0d0
80  IF(mint(47).GE.2.AND.(mint(47).LT.5.OR.mstp(12).GE.1)) THEN
81  mcev=1
82  IF(mstp(64).EQ.1) fq2c=parp(63)
83  IF(mstp(64).EQ.2) fq2c=parp(64)
84  tcmx=log(fq2c*q2mx/parp(61)**2)
85  IF(q2mx.LT.max(q2mnc,2d0*parp(61)**2).OR.tcmx.LT.0.2d0)
86  & mcev=0
87  ENDIF
88 
89 C...Initialize QED evolution and check phase space.
90  meev=0
91  xee=1d-10
92  spme=pmas(11,1)**2
93  IF(iabs(mint(11)).EQ.13.OR.iabs(mint(12)).EQ.13)
94  &spme=pmas(13,1)**2
95  IF(iabs(mint(11)).EQ.15.OR.iabs(mint(12)).EQ.15)
96  &spme=pmas(15,1)**2
97  q2mne=max(parp(68)**2,2d0*spme)
98  temx=0d0
99  fwte=10d0
100  IF(mint(45).EQ.3.OR.mint(46).EQ.3) THEN
101  meev=1
102  temx=log(q2mx/spme)
103  IF(q2mx.LE.q2mne.OR.temx.LT.0.2d0) meev=0
104  ENDIF
105  IF(mstp(61).GE.2.AND.mcev.EQ.1.AND.meev.EQ.0) THEN
106  meev=2
107  temx=tcmx
108  fwte=1d0
109  ENDIF
110  IF(mcev.EQ.0.AND.meev.EQ.0) RETURN
111 
112 C...Loopback point in case of failure to reconstruct kinematics.
113  ns=n
114  loop=0
115  mnt352=mint(352)
116  mnt353=mint(353)
117  vnt352=vint(352)
118  vnt353=vint(353)
119  100 loop=loop+1
120  IF(loop.GT.100) THEN
121  mint(51)=1
122  RETURN
123  ENDIF
124  n=ns
125  mint(352)=mnt352
126  mint(353)=mnt353
127  vint(352)=vnt352
128  vint(353)=vnt353
129 
130 C...Initial values: flavours, momenta, virtualities.
131  DO 120 jt=1,2
132  more(jt)=1
133  kfbeam(jt)=mint(10+jt)
134  IF(mint(18+jt).EQ.1)kfbeam(jt)=22
135  kfls(jt)=mint(14+jt)
136  kfls(jt+2)=kfls(jt)
137  xs(jt)=vint(40+jt)
138  IF(mint(18+jt).EQ.1) xs(jt)=vint(40+jt)/vint(154+jt)
139  IF(mint(31).GE.2) xs(jt)=xs(jt)/vint(142+jt)
140  zs(jt)=1d0
141  q2s(jt)=fcq2mx*q2mx
142  dq2(jt)=0d0
143  tevcsv(jt)=tcmx
144  alam(jt)=parp(61)
145  the2(jt)=1d0
146  tevesv(jt)=temx
147  mcesv(jt)=0
148 C...Calculate initial parton distribution weights.
149  mint(105)=mint(102+jt)
150  mint(109)=mint(106+jt)
151  vint(120)=vint(2+jt)
152  IF(xs(jt).LT.1d0-xee) THEN
153  IF(mint(31).GE.2) mint(30)=jt
154  IF(mstp(57).LE.1) THEN
155  CALL pypdfu(kfbeam(jt),xs(jt),q2s(jt),xfb)
156  ELSE
157  CALL pypdfl(kfbeam(jt),xs(jt),q2s(jt),xfb)
158  ENDIF
159  ENDIF
160  DO 110 kfl=-25,25
161  xfs(jt,kfl)=xfb(kfl)
162  110 CONTINUE
163 C...Special kinematics check for c/b quarks (that g -> c cbar or
164 C...b bbar kinematically possible).
165  kflcb=iabs(kfls(jt))
166  IF(kfbeam(jt).NE.22.AND.(kflcb.EQ.4.OR.kflcb.EQ.5)) THEN
167  IF(xs(jt).GT.0.9d0*q2s(jt)/(pmas(kflcb,1)**2+q2s(jt))) THEN
168  mint(51)=1
169  RETURN
170  ENDIF
171  ENDIF
172  120 CONTINUE
173  dsh=vint(44)
174  IF(iset(isub).GE.3.AND.iset(isub).LE.5) dsh=vint(26)*vint(2)
175 
176 C...Find if interference with final state partons.
177  mfis=0
178  IF(mstp(67).GE.1.AND.mstp(67).LE.3) mfis=mstp(67)
179  IF(mfis.NE.0) THEN
180  DO 140 i=1,2
181  kcfi(i)=0
182  kca=pycomp(iabs(kfls(i)))
183  IF(kca.NE.0) kcfi(i)=kchg(kca,2)*isign(1,kfls(i))
184  nfis(i)=0
185  IF(kcfi(i).NE.0) THEN
186  IF(i.EQ.1) ipfs=ipus1
187  IF(i.EQ.2) ipfs=ipus2
188  DO 130 j=1,2
189  icsi=mod(k(ipfs,3+j),mstu(5))
190  IF(icsi.GT.0.AND.icsi.NE.ipus1.AND.icsi.NE.ipus2.AND.
191  & (kcfi(i).EQ.(-1)**(j+1).OR.kcfi(i).EQ.2)) THEN
192  nfis(i)=nfis(i)+1
193  thefis(i,nfis(i))=pyangl(p(icsi,3),sqrt(p(icsi,1)**2+
194  & p(icsi,2)**2))
195  IF(i.EQ.2) thefis(i,nfis(i))=paru(1)-thefis(i,nfis(i))
196  ENDIF
197  130 CONTINUE
198  ENDIF
199  140 CONTINUE
200  IF(nfis(1)+nfis(2).EQ.0) mfis=0
201  ENDIF
202 
203 C...Pick up leg with highest virtuality.
204  jtold=1
205  150 n=n+1
206  jt=1
207  IF(n.GT.ns+1.AND.q2s(2).GT.q2s(1)) jt=2
208  IF(n.EQ.ns+2.AND.jt.EQ.jtold) jt=3-jt
209  IF(more(jt).EQ.0) jt=3-jt
210  jtold=jt
211  kflb=kfls(jt)
212  xb=xs(jt)
213  DO 160 kfl=-25,25
214  xfb(kfl)=xfs(jt,kfl)
215  160 CONTINUE
216  dshr=2d0*sqrt(dsh)
217  dshz=dsh/zs(jt)
218 
219 C...Check if allowed to branch.
220  mcev=0
221  IF(iabs(kflb).LE.10.OR.kflb.EQ.21) THEN
222  mcev=1
223  xec=max(parp(65)*dshr/vint2r,xb*(1d0/(1d0-parp(66))-1d0))
224  IF(xb.GE.1d0-2d0*xec) mcev=0
225  ENDIF
226  meev=0
227  IF(mint(44+jt).EQ.3) THEN
228  meev=1
229  IF(xb.GE.1d0-2d0*xee) meev=0
230  IF((iabs(kflb).LE.10.OR.kflb.EQ.21).AND.xb.GE.1d0-2d0*xec)
231  & meev=0
232 C***Currently kill QED shower for resolved photoproduction.
233  IF(mint(18+jt).EQ.1) meev=0
234 C***Currently kill shower for W inside electron.
235  IF(iabs(kflb).EQ.24) THEN
236  mcev=0
237  meev=0
238  ENDIF
239  ENDIF
240  IF(mstp(61).GE.2.AND.mcev.EQ.1.AND.meev.EQ.0.AND.iabs(kflb).LE.10)
241  &meev=2
242  IF(mcev.EQ.0.AND.meev.EQ.0) THEN
243  q2b=0d0
244  goto 260
245  ENDIF
246 
247 C...Maximum Q2 with or without Q2 ordering. Effective Lambda and n_f.
248  q2b=q2s(jt)
249  tevcb=tevcsv(jt)
250  teveb=tevesv(jt)
251  IF(mstp(62).LE.1) THEN
252  IF(zs(jt).GT.0.99999d0) THEN
253  q2b=q2s(jt)
254  ELSE
255  q2b=0.5d0*(1d0/zs(jt)+1d0)*q2s(jt)+0.5d0*(1d0/zs(jt)-1d0)*
256  & (q2s(3-jt)-dsh+sqrt((dsh+q2s(1)+q2s(2))**2+
257  & 8d0*q2s(1)*q2s(2)*zs(jt)/(1d0-zs(jt))))
258  ENDIF
259  IF(mcev.EQ.1) tevcb=log(fq2c*q2b/alam(jt)**2)
260  IF(meev.EQ.1) teveb=log(q2b/spme)
261  ENDIF
262  IF(mcev.EQ.1) THEN
263  alsdum=pyalps(fq2c*q2b)
264  tevcb=tevcb+2d0*log(alam(jt)/paru(117))
265  alam(jt)=paru(117)
266  b0=(33d0-2d0*mstu(118))/6d0
267  ENDIF
268  IF(meev.EQ.2) teveb=tevcb
269  tevcbs=tevcb
270  tevebs=teveb
271 
272 C...Select side for interference with final state partons.
273  IF(mfis.GE.1.AND.n.LE.ns+2) THEN
274  ifi=n-ns
275  isfi(ifi)=0
276  IF(iabs(kcfi(ifi)).EQ.1.AND.nfis(ifi).EQ.1) THEN
277  isfi(ifi)=1
278  ELSEIF(kcfi(ifi).EQ.2.AND.nfis(ifi).EQ.1) THEN
279  IF(pyr(0).GT.0.5d0) isfi(ifi)=1
280  ELSEIF(kcfi(ifi).EQ.2.AND.nfis(ifi).EQ.2) THEN
281  isfi(ifi)=1
282  IF(pyr(0).GT.0.5d0) isfi(ifi)=2
283  ENDIF
284  ENDIF
285 
286 C...Calculate preweighting factor for ME-corrected processes.
287  IF(mecor.GE.1) CALL pymemx(mecor,wtff,wtgf,wtfg,wtgg)
288 
289 C...Calculate Altarelli-Parisi weights.
290  DO 170 kfl=-25,25
291  wtapc(kfl)=0d0
292  wtape(kfl)=0d0
293  wtsf(kfl)=0d0
294  170 CONTINUE
295 C...q -> q (g or gamma emission), g -> q.
296  IF(iabs(kflb).LE.10) THEN
297  wtapc(kflb)=(8d0/3d0)*log((1d0-xec-xb)*(xb+xec)/(xec*(1d0-xec)))
298  wtapc(21)=0.5d0*(xb/(xb+xec)-xb/(1d0-xec))
299  eq2=1d0/9d0
300  IF(mod(iabs(kflb),2).EQ.0) eq2=4d0*eq2
301  IF(meev.EQ.2) wtape(kflb)=2.*eq2*log((1d0-xec-xb)*(xb+xec)/
302  & (xec*(1d0-xec)))
303  IF(mecor.GE.1.AND.(n.EQ.ns+1.OR.n.EQ.ns+2)) THEN
304  wtapc(kflb)=wtff*wtapc(kflb)
305  wtapc(21)=wtgf*wtapc(21)
306  wtape(kflb)=wtff*wtape(kflb)
307  ENDIF
308 C...f -> f, gamma -> f.
309  ELSEIF(iabs(kflb).LE.20) THEN
310  wtapf1=log((1d0-xee-xb)*(xb+xee)/(xee*(1d0-xee)))
311  wtapf2=log((1d0-xee-xb)*(1d0-xee)/(xee*(xb+xee)))
312  wtape(kflb)=2d0*(wtapf1+wtapf2)
313  IF(mstp(12).GE.1) wtape(22)=xb/(xb+xee)-xb/(1d0-xee)
314  IF(mecor.GE.1.AND.(n.EQ.ns+1.OR.n.EQ.ns+2)) THEN
315  wtape(kflb)=wtff*wtape(kflb)
316  wtape(22)=wtgf*wtape(22)
317  ENDIF
318 C...f -> g, g -> g.
319  ELSEIF(kflb.EQ.21) THEN
320  wtapq=(16d0/3d0)*(sqrt((1d0-xec)/xb)-sqrt((xb+xec)/xb))
321  DO 180 kfl=1,mstp(58)
322  wtapc(kfl)=wtapq
323  wtapc(-kfl)=wtapq
324  180 CONTINUE
325  wtapc(21)=6d0*log((1d0-xec-xb)/xec)
326  IF(mecor.GE.1.AND.(n.EQ.ns+1.OR.n.EQ.ns+2)) THEN
327  DO 190 kfl=1,mstp(58)
328  wtapc(kfl)=wtfg*wtapc(kfl)
329  wtapc(-kfl)=wtfg*wtapc(-kfl)
330  190 CONTINUE
331  wtapc(21)=wtgg*wtapc(21)
332  ENDIF
333 C...f -> gamma, W+, W-.
334  ELSEIF(kflb.EQ.22) THEN
335  wtapf=log((1d0-xee-xb)*(1d0-xee)/(xee*(xb+xee)))/xb
336  wtape(11)=wtapf
337  wtape(-11)=wtapf
338  IF(mecor.GE.1.AND.(n.EQ.ns+1.OR.n.EQ.ns+2)) THEN
339  wtape(11)=wtfg*wtape(11)
340  wtape(-11)=wtfg*wtape(-11)
341  ENDIF
342  ELSEIF(kflb.EQ.24) THEN
343  wtape(-11)=1d0/(4d0*paru(102))*log((1d0-xee-xb)*(1d0-xee)/
344  & (xee*(xb+xee)))/xb
345  ELSEIF(kflb.EQ.-24) THEN
346  wtape(11)=1d0/(4d0*paru(102))*log((1d0-xee-xb)*(1d0-xee)/
347  & (xee*(xb+xee)))/xb
348  ENDIF
349 
350 C...Calculate parton distribution weights and sum.
351  ntry=0
352  200 ntry=ntry+1
353  IF(ntry.GT.500) THEN
354  mint(51)=1
355  RETURN
356  ENDIF
357  wtsumc=0d0
358  wtsume=0d0
359  xfbo=max(1d-10,xfb(kflb))
360  DO 210 kfl=-25,25
361  wtsf(kfl)=xfb(kfl)/xfbo
362  wtsumc=wtsumc+wtapc(kfl)*wtsf(kfl)
363  wtsume=wtsume+wtape(kfl)*wtsf(kfl)
364  210 CONTINUE
365  wtsumc=max(0.0001d0,wtsumc)
366  wtsume=max(0.0001d0/fwte,wtsume)
367 
368 C...Choose new t: fix alpha_s, alpha_s(Q^2), alpha_s(k_T^2).
369  ntry2=0
370  220 ntry2=ntry2+1
371  IF(ntry2.GT.500) THEN
372  mint(51)=1
373  RETURN
374  ENDIF
375  IF(mcev.EQ.1) THEN
376  IF(mstp(64).LE.0) THEN
377  tevcb=tevcb+log(pyr(0))*paru(2)/(paru(111)*wtsumc)
378  ELSEIF(mstp(64).EQ.1) THEN
379  tevcb=tevcb*exp(max(-50d0,log(pyr(0))*b0/wtsumc))
380  ELSE
381  tevcb=tevcb*exp(max(-50d0,log(pyr(0))*b0/(5d0*wtsumc)))
382  ENDIF
383  ENDIF
384  IF(meev.EQ.1) THEN
385  teveb=teveb*exp(max(-50d0,log(pyr(0))*paru(2)/
386  & (paru(101)*fwte*wtsume*temx)))
387  ELSEIF(meev.EQ.2) THEN
388  teveb=teveb+log(pyr(0))*paru(2)/(paru(101)*wtsume)
389  ENDIF
390 
391 C...Translate t into Q2 scale; choose between QCD and QED evolution.
392  230 IF(mcev.EQ.1) q2cb=alam(jt)**2*exp(max(-50d0,tevcb))/fq2c
393  IF(meev.EQ.1) q2eb=spme*exp(max(-50d0,teveb))
394  IF(meev.EQ.2) q2eb=alam(jt)**2*exp(max(-50d0,teveb))/fq2c
395 C...Ensure that Q2 is above threshold for charm/bottom.
396  kflcb=iabs(kflb)
397  IF(kfbeam(jt).NE.22.AND.(kflcb.EQ.4.OR.kflcb.EQ.5).AND.
398  &mcev.EQ.1) THEN
399  IF(q2cb.LT.pmas(kflcb,1)**2) THEN
400  q2cb=1.1d0*pmas(kflcb,1)**2
401  tevcb=log(fq2c*q2b/alam(jt)**2)
402  fcq2mx=min(2d0,1.05d0*fcq2mx)
403  ENDIF
404  ENDIF
405  IF(kfbeam(jt).NE.22.AND.(kflcb.EQ.4.OR.kflcb.EQ.5).AND.
406  &meev.EQ.2) THEN
407  IF(q2eb.LT.pmas(kflcb,1)**2) meev=0
408  ENDIF
409  mce=0
410  IF(mcev.EQ.0.AND.meev.EQ.0) THEN
411  ELSEIF(mcev.EQ.1.AND.meev.EQ.0) THEN
412  IF(q2cb.GT.q2mncs(jt)) mce=1
413  ELSEIF(mcev.EQ.0.AND.meev.EQ.1) THEN
414  IF(q2eb.GT.q2mne) mce=2
415  ELSEIF(mcev.EQ.0.AND.meev.EQ.2) THEN
416  IF(q2eb.GT.q2mncs(jt)) mce=2
417  ELSEIF(mcev.EQ.1.AND.meev.EQ.2) THEN
418  IF(q2cb.GT.q2eb.AND.q2cb.GT.q2mncs(jt)) mce=1
419  IF(q2eb.GT.q2cb.AND.q2eb.GT.q2mncs(jt)) mce=2
420  ELSEIF(q2mncs(jt).GT.q2mne) THEN
421  mce=1
422  IF(q2eb.GT.q2cb.OR.q2cb.LE.q2mncs(jt)) mce=2
423  IF(mce.EQ.2.AND.q2eb.LE.q2mne) mce=0
424  ELSE
425  mce=2
426  IF(q2cb.GT.q2eb.OR.q2eb.LE.q2mne) mce=1
427  IF(mce.EQ.1.AND.q2cb.LE.q2mncs(jt)) mce=0
428  ENDIF
429 
430 C...Evolution possibly ended. Update t values.
431  IF(mce.EQ.0) THEN
432  q2b=0d0
433  goto 260
434  ELSEIF(mce.EQ.1) THEN
435  q2b=q2cb
436  q2ref=fq2c*q2b
437  IF(meev.EQ.1) teveb=log(q2b/spme)
438  IF(meev.EQ.2) teveb=log(fq2c*q2b/alam(jt)**2)
439  ELSE
440  q2b=q2eb
441  q2ref=q2b
442  IF(mcev.EQ.1) tevcb=log(fq2c*q2b/alam(jt)**2)
443  ENDIF
444 
445 C...Select flavour for branching parton.
446  IF(mce.EQ.1) wtran=pyr(0)*wtsumc
447  IF(mce.EQ.2) wtran=pyr(0)*wtsume
448  kfla=-25
449  240 kfla=kfla+1
450  IF(mce.EQ.1) wtran=wtran-wtapc(kfla)*wtsf(kfla)
451  IF(mce.EQ.2) wtran=wtran-wtape(kfla)*wtsf(kfla)
452  IF(kfla.LE.24.AND.wtran.GT.0d0) goto 240
453  IF(kfla.EQ.25) THEN
454  q2b=0d0
455  goto 260
456  ENDIF
457 
458 C...Choose z value and corrective weight.
459  wtz=0d0
460 C...q -> q + g or q -> q + gamma.
461  IF(iabs(kfla).LE.10.AND.iabs(kflb).LE.10) THEN
462  z=1d0-((1d0-xb-xec)/(1d0-xec))*
463  & (xec*(1d0-xec)/((xb+xec)*(1d0-xb-xec)))**pyr(0)
464  wtz=0.5d0*(1d0+z**2)
465 C...q -> g + q.
466  ELSEIF(iabs(kfla).LE.10.AND.kflb.EQ.21) THEN
467  z=xb/(sqrt(xb+xec)+pyr(0)*(sqrt(1d0-xec)-sqrt(xb+xec)))**2
468  wtz=0.5d0*(1d0+(1d0-z)**2)*sqrt(z)
469 C...f -> f + gamma.
470  ELSEIF(iabs(kfla).LE.20.AND.iabs(kflb).LE.20) THEN
471  IF(wtapf1.GT.pyr(0)*(wtapf1+wtapf2)) THEN
472  z=1d0-((1d0-xb-xee)/(1d0-xee))*
473  & (xee*(1d0-xee)/((xb+xee)*(1d0-xb-xee)))**pyr(0)
474  ELSE
475  z=xb+xb*(xee/(1d0-xee))*
476  & ((1d0-xb-xee)*(1d0-xee)/(xee*(xb+xee)))**pyr(0)
477  ENDIF
478  wtz=0.5d0*(1d0+z**2)*(z-xb)/(1d0-xb)
479 C...f -> gamma + f.
480  ELSEIF(iabs(kfla).LE.20.AND.kflb.EQ.22) THEN
481  z=xb+xb*(xee/(1d0-xee))*
482  & ((1d0-xb-xee)*(1d0-xee)/(xee*(xb+xee)))**pyr(0)
483  wtz=0.5d0*(1d0+(1d0-z)**2)*xb*(z-xb)/z
484 C...f -> W+- + f.
485  ELSEIF(iabs(kfla).LE.20.AND.iabs(kflb).EQ.24) THEN
486  z=xb+xb*(xee/(1d0-xee))*
487  & ((1d0-xb-xee)*(1d0-xee)/(xee*(xb+xee)))**pyr(0)
488  wtz=0.5d0*(1d0+(1d0-z)**2)*(xb*(z-xb)/z)*
489  & (q2b/(q2b+pmas(24,1)**2))
490 C...g -> q + qbar.
491  ELSEIF(kfla.EQ.21.AND.iabs(kflb).LE.10) THEN
492  z=xb/(1d0-xec)+pyr(0)*(xb/(xb+xec)-xb/(1d0-xec))
493  wtz=1d0-2d0*z*(1d0-z)
494 C...g -> g + g.
495  ELSEIF(kfla.EQ.21.AND.kflb.EQ.21) THEN
496  z=1d0/(1d0+((1d0-xec-xb)/xb)*(xec/(1d0-xec-xb))**pyr(0))
497  wtz=(1d0-z*(1d0-z))**2
498 C...gamma -> f + fbar.
499  ELSEIF(kfla.EQ.22.AND.iabs(kflb).LE.20) THEN
500  z=xb/(1d0-xee)+pyr(0)*(xb/(xb+xee)-xb/(1d0-xee))
501  wtz=1d0-2d0*z*(1d0-z)
502  ENDIF
503  IF(mce.EQ.2.AND.meev.EQ.1) wtz=(wtz/fwte)*(teveb/temx)
504 
505 C...Option with resummation of soft gluon emission as effective z shift.
506  IF(mce.EQ.1) THEN
507  IF(mstp(65).GE.1) THEN
508  rsoft=6d0
509  IF(kflb.NE.21) rsoft=8d0/3d0
510  z=z*(tevcb/tevcsv(jt))**(rsoft*xec/((xb+xec)*b0))
511  IF(z.LE.xb) goto 220
512  ENDIF
513 
514 C...Option with alpha_s(k_T^2): demand k_T^2 > cutoff, reweight.
515  IF(mstp(64).GE.2) THEN
516  IF((1d0-z)*q2b.LT.q2mncs(jt)) goto 220
517  alprat=tevcb/(tevcb+log(1d0-z))
518  IF(alprat.LT.5d0*pyr(0)) goto 220
519  IF(alprat.GT.5d0) wtz=wtz*alprat/5d0
520  ENDIF
521  ENDIF
522 
523 C...Remove kinematically impossible branchings.
524  uhat=q2b-dsh*(1d0-z)/z
525  IF(mstp(68).GE.0.AND.uhat.GT.0d0) goto 220
526 
527 C...Select phi angle of branching at random.
528  phibr=paru(2)*pyr(0)
529 
530 C...Matrix-element corrections for some processes.
531  IF(mecor.GE.1.AND.(n.EQ.ns+1.OR.n.EQ.ns+2)) THEN
532  IF(iabs(kfla).LE.20.AND.iabs(kflb).LE.20) THEN
533  CALL pymewt(mecor,1,q2b,z,phibr,wtme)
534  wtz=wtz*wtme/wtff
535  ELSEIF((kfla.EQ.21.OR.kfla.EQ.22).AND.iabs(kflb).LE.20) THEN
536  CALL pymewt(mecor,2,q2b,z,phibr,wtme)
537  wtz=wtz*wtme/wtgf
538  ELSEIF(iabs(kfla).LE.20.AND.(kflb.EQ.21.OR.kflb.EQ.22)) THEN
539  CALL pymewt(mecor,3,q2b,z,phibr,wtme)
540  wtz=wtz*wtme/wtfg
541  ELSEIF(kfla.EQ.21.AND.kflb.EQ.21) THEN
542  CALL pymewt(mecor,4,q2b,z,phibr,wtme)
543  wtz=wtz*wtme/wtgg
544  ENDIF
545  ENDIF
546 
547 C...Impose angular constraint in first branching from interference
548 C...with final state partons.
549  IF(mce.EQ.1) THEN
550  IF(mfis.GE.1.AND.n.LE.ns+2.AND.ntry2.LT.200) THEN
551  the2d=(4d0*q2b)/(dsh*(1d0-z))
552  IF(n.EQ.ns+1.AND.isfi(1).GE.1) THEN
553  IF(the2d.GT.thefis(1,isfi(1))**2) goto 220
554  ELSEIF(n.EQ.ns+2.AND.isfi(2).GE.1) THEN
555  IF(the2d.GT.thefis(2,isfi(2))**2) goto 220
556  ENDIF
557  ENDIF
558 
559 C...Option with angular ordering requirement.
560  IF(mstp(62).GE.3.AND.ntry2.LT.200) THEN
561  the2t=(4d0*z**2*q2b)/(4d0*z**2*q2b+(1d0-z)*xb**2*vint2r)
562  IF(the2t.GT.the2(jt)) goto 220
563  ENDIF
564  ENDIF
565 
566 C...Weighting with new parton distributions.
567  mint(105)=mint(102+jt)
568  mint(109)=mint(106+jt)
569  vint(120)=vint(2+jt)
570  IF(mint(31).GE.2) mint(30)=jt
571  IF(mstp(57).LE.1) THEN
572  CALL pypdfu(kfbeam(jt),xb,q2ref,xfn)
573  ELSE
574  CALL pypdfl(kfbeam(jt),xb,q2ref,xfn)
575  ENDIF
576  xfbn=xfn(kflb)
577  IF(xfbn.LT.1d-20) THEN
578  IF(kfla.EQ.kflb) THEN
579  tevcb=tevcbs
580  teveb=tevebs
581  wtapc(kflb)=0d0
582  wtape(kflb)=0d0
583  goto 200
584  ELSEIF(mce.EQ.1.AND.tevcbs-tevcb.GT.0.2d0) THEN
585  tevcb=0.5d0*(tevcbs+tevcb)
586  goto 230
587  ELSEIF(mce.EQ.2.AND.tevebs-teveb.GT.0.2d0) THEN
588  teveb=0.5d0*(tevebs+teveb)
589  goto 230
590  ELSE
591  xfbn=1d-10
592  xfn(kflb)=xfbn
593  ENDIF
594  ENDIF
595  DO 250 kfl=-25,25
596  xfb(kfl)=xfn(kfl)
597  250 CONTINUE
598  xa=xb/z
599  IF(mint(31).GE.2) mint(30)=jt
600  IF(mstp(57).LE.1) THEN
601  CALL pypdfu(kfbeam(jt),xa,q2ref,xfa)
602  ELSE
603  CALL pypdfl(kfbeam(jt),xa,q2ref,xfa)
604  ENDIF
605  xfan=xfa(kfla)
606  IF(xfan.LT.1d-20) goto 200
607  wtsfa=wtsf(kfla)
608  IF(wtz*xfan/xfbn.LT.pyr(0)*wtsfa) goto 200
609 
610 C...Define two hard scatterers in their CM-frame.
611  260 IF(n.EQ.ns+2) THEN
612  dq2(jt)=q2b
613  dplcm=sqrt((dsh+dq2(1)+dq2(2))**2-4d0*dq2(1)*dq2(2))/dshr
614  DO 280 jr=1,2
615  i=ns+jr
616  IF(jr.EQ.1) ipo=ipus1
617  IF(jr.EQ.2) ipo=ipus2
618  DO 270 j=1,5
619  k(i,j)=0
620  p(i,j)=0d0
621  v(i,j)=0d0
622  270 CONTINUE
623  k(i,1)=14
624  k(i,2)=kfls(jr+2)
625  k(i,4)=ipo
626  k(i,5)=ipo
627  p(i,3)=dplcm*(-1)**(jr+1)
628  p(i,4)=(dsh+dq2(3-jr)-dq2(jr))/dshr
629  p(i,5)=-sqrt(dq2(jr))
630  k(ipo,1)=14
631  k(ipo,3)=i
632  k(ipo,4)=mod(k(ipo,4),mstu(5))+mstu(5)*i
633  k(ipo,5)=mod(k(ipo,5),mstu(5))+mstu(5)*i
634  280 CONTINUE
635 
636 C...Find maximum allowed mass of timelike parton.
637  ELSEIF(n.GT.ns+2) THEN
638  jr=3-jt
639  dq2(3)=q2b
640  dpc(1)=p(is(1),4)
641  dpc(2)=p(is(2),4)
642  dpc(3)=0.5d0*(abs(p(is(1),3))+abs(p(is(2),3)))
643  dpd(1)=dsh+dq2(jr)+dq2(jt)
644  dpd(2)=dshz+dq2(jr)+dq2(3)
645  dpd(3)=sqrt(dpd(1)**2-4d0*dq2(jr)*dq2(jt))
646  dpd(4)=sqrt(dpd(2)**2-4d0*dq2(jr)*dq2(3))
647  ikin=0
648  IF(q2s(jr).GE.0.25d0*q2mnc.AND.dpd(1)-dpd(3).GE.
649  & 1d-10*dpd(1)) ikin=1
650  IF(ikin.EQ.0) dmsma=(dq2(jt)/zs(jt)-dq2(3))*
651  & (dsh/(dsh+dq2(jt))-dsh/(dshz+dq2(3)))
652  IF(ikin.EQ.1) dmsma=(dpd(1)*dpd(2)-dpd(3)*dpd(4))/
653  & (2d0*dq2(jr))-dq2(jt)-dq2(3)
654 
655 C...Generate timelike parton shower (if required).
656  it=n
657  DO 290 j=1,5
658  k(it,j)=0
659  p(it,j)=0d0
660  v(it,j)=0d0
661  290 CONTINUE
662 C...f -> f + g (gamma).
663  IF(iabs(kflb).LE.20.AND.iabs(kfls(jt+2)).LE.20) THEN
664  k(it,2)=21
665  IF(mcesv(jt).EQ.2.OR.iabs(kflb).GE.11) k(it,2)=22
666 C...f -> g (gamma, W+-) + f.
667  ELSEIF(iabs(kflb).LE.20.AND.iabs(kfls(jt+2)).GT.20) THEN
668  k(it,2)=kflb
669  IF(kfls(jt+2).EQ.24) THEN
670  k(it,2)=-12
671  ELSEIF(kfls(jt+2).EQ.-24) THEN
672  k(it,2)=12
673  ENDIF
674 C...g (gamma) -> f + fbar, g + g.
675  ELSE
676  k(it,2)=-kfls(jt+2)
677  IF(kfls(jt+2).GT.20) k(it,2)=kfls(jt+2)
678  ENDIF
679  k(it,1)=3
680  IF((iabs(k(it,2)).GE.11.AND.iabs(k(it,2)).LE.18).OR.
681  & iabs(k(it,2)).EQ.22) k(it,1)=1
682  p(it,5)=pymass(k(it,2))
683  IF(dmsma.LE.p(it,5)**2) goto 100
684  IF(mstp(63).GE.1.AND.mcesv(jt).EQ.1) THEN
685  mstj48=mstj(48)
686  parj85=parj(85)
687  p(it,4)=(dshz-dsh-p(it,5)**2)/dshr
688  p(it,3)=sqrt(p(it,4)**2-p(it,5)**2)
689  IF(mstp(63).EQ.1) THEN
690  q2tim=dmsma
691  ELSEIF(mstp(63).EQ.2) THEN
692  q2tim=min(dmsma,parp(71)*q2s(jt))
693  ELSE
694  q2tim=dmsma
695  mstj(48)=1
696  IF(ikin.EQ.0) dpt2=dmsma*(dshz+dq2(3))/(dsh+dq2(jt))
697  IF(ikin.EQ.1) dpt2=dmsma*(0.5d0*dpd(1)*dpd(2)+0.5d0*dpd(3)*
698  & dpd(4)-dq2(jr)*(dq2(jt)+dq2(3)))/(4d0*dsh*dpc(3)**2)
699  parj(85)=sqrt(max(0d0,dpt2))*
700  & (1d0/p(it,4)+1d0/p(is(jt),4))
701  ENDIF
702  CALL pyshow(it,0,sqrt(q2tim))
703  mstj(48)=mstj48
704  parj(85)=parj85
705  IF(n.GE.it+1) p(it,5)=p(it+1,5)
706  ENDIF
707 
708 C...Reconstruct kinematics of branching: timelike parton shower.
709  dms=p(it,5)**2
710  IF(ikin.EQ.0) dpt2=(dmsma-dms)*(dshz+dq2(3))/(dsh+dq2(jt))
711  IF(ikin.EQ.1) dpt2=(dmsma-dms)*(0.5d0*dpd(1)*dpd(2)+
712  & 0.5d0*dpd(3)*dpd(4)-dq2(jr)*(dq2(jt)+dq2(3)+dms))/
713  & (4d0*dsh*dpc(3)**2)
714  IF(dpt2.LT.0d0) goto 100
715  dpb(1)=(0.5d0*dpd(2)-dpc(jr)*(dshz+dq2(jr)-dq2(jt)-dms)/
716  & dshr)/dpc(3)-dpc(3)
717  p(it,1)=sqrt(dpt2)
718  p(it,3)=dpb(1)*(-1)**(jt+1)
719  p(it,4)=sqrt(dpt2+dpb(1)**2+dms)
720  IF(n.GE.it+1) THEN
721  dpb(1)=sqrt(dpb(1)**2+dpt2)
722  dpb(2)=sqrt(dpb(1)**2+dms)
723  dpb(3)=p(it+1,3)
724  dpb(4)=sqrt(dpb(3)**2+dms)
725  dbez=(dpb(4)*dpb(1)-dpb(3)*dpb(2))/(dpb(4)*dpb(2)-dpb(3)*
726  & dpb(1))
727  CALL pyrobo(it+1,n,0d0,0d0,0d0,0d0,dbez)
728  the=pyangl(p(it,3),p(it,1))
729  CALL pyrobo(it+1,n,the,0d0,0d0,0d0,0d0)
730  ENDIF
731 
732 C...Reconstruct kinematics of branching: spacelike parton.
733  DO 300 j=1,5
734  k(n+1,j)=0
735  p(n+1,j)=0d0
736  v(n+1,j)=0d0
737  300 CONTINUE
738  k(n+1,1)=14
739  k(n+1,2)=kflb
740  p(n+1,1)=p(it,1)
741  p(n+1,3)=p(it,3)+p(is(jt),3)
742  p(n+1,4)=p(it,4)+p(is(jt),4)
743  p(n+1,5)=-sqrt(dq2(3))
744 
745 C...Define colour flow of branching.
746  k(is(jt),3)=n+1
747  k(it,3)=n+1
748  im1=n+1
749  im2=n+1
750 C...f -> f + gamma (Z, W).
751  IF(iabs(k(it,2)).GE.22) THEN
752  k(it,1)=1
753  id1=is(jt)
754  id2=is(jt)
755 C...f -> gamma (Z, W) + f.
756  ELSEIF(iabs(k(is(jt),2)).GE.22) THEN
757  id1=it
758  id2=it
759 C...gamma -> q + qbar, g + g.
760  ELSEIF(k(n+1,2).EQ.22) THEN
761  id1=is(jt)
762  id2=it
763  im1=id2
764  im2=id1
765 C...q -> q + g.
766  ELSEIF(k(n+1,2).GT.0.AND.k(n+1,2).NE.21.AND.k(it,2).EQ.21) THEN
767  id1=it
768  id2=is(jt)
769 C...q -> g + q.
770  ELSEIF(k(n+1,2).GT.0.AND.k(n+1,2).NE.21) THEN
771  id1=is(jt)
772  id2=it
773 C...qbar -> qbar + g.
774  ELSEIF(k(n+1,2).LT.0.AND.k(it,2).EQ.21) THEN
775  id1=is(jt)
776  id2=it
777 C...qbar -> g + qbar.
778  ELSEIF(k(n+1,2).LT.0) THEN
779  id1=it
780  id2=is(jt)
781 C...g -> g + g; g -> q + qbar.
782  ELSEIF((k(it,2).EQ.21.AND.pyr(0).GT.0.5d0).OR.k(it,2).LT.0) THEN
783  id1=is(jt)
784  id2=it
785  ELSE
786  id1=it
787  id2=is(jt)
788  ENDIF
789  IF(im1.EQ.n+1) k(im1,4)=k(im1,4)+id1
790  IF(im2.EQ.n+1) k(im2,5)=k(im2,5)+id2
791  k(id1,4)=k(id1,4)+mstu(5)*im1
792  k(id2,5)=k(id2,5)+mstu(5)*im2
793  IF(id1.NE.id2) THEN
794  k(id1,5)=k(id1,5)+mstu(5)*id2
795  k(id2,4)=k(id2,4)+mstu(5)*id1
796  ENDIF
797  n=n+1
798  IF(k(it,1).EQ.1) THEN
799  k(it,4)=0
800  k(it,5)=0
801  ENDIF
802 
803 C...Boost to new CM-frame.
804  dbsvx=(p(n,1)+p(is(jr),1))/(p(n,4)+p(is(jr),4))
805  dbsvz=(p(n,3)+p(is(jr),3))/(p(n,4)+p(is(jr),4))
806  IF(dbsvx**2+dbsvz**2.GE.1d0) goto 100
807  CALL pyrobo(ns+1,n,0d0,0d0,-dbsvx,0d0,-dbsvz)
808  ir=n+(jt-1)*(is(1)-n)
809  CALL pyrobo(ns+1,n,-pyangl(p(ir,3),p(ir,1)),dphi(jt),
810  & 0d0,0d0,0d0)
811 
812 C...Global statistics.
813  mint(352)=mint(352)+1
814  vint(352)=vint(352)+sqrt(p(it,1)**2+p(it,2)**2)
815  IF (mint(352).EQ.1) vint(357)=sqrt(p(it,1)**2+p(it,2)**2)
816  ENDIF
817 
818 C...Update kinematics variables.
819  is(jt)=n
820  dq2(jt)=q2b
821  IF(mstp(62).GE.3.AND.ntry2.LT.200) the2(jt)=the2t
822  dsh=dshz
823 
824 C...Save quantities; loop back.
825  q2s(jt)=q2b
826  dphi(jt)=phibr
827  mcesv(jt)=mce
828  IF((mcev.EQ.1.AND.q2b.GE.0.25d0*q2mnc).OR.
829  &(meev.EQ.1.AND.q2b.GE.q2mne)) THEN
830  kfls(jt+2)=kfls(jt)
831  kfls(jt)=kfla
832  xs(jt)=xa
833  zs(jt)=z
834  DO 310 kfl=-25,25
835  xfs(jt,kfl)=xfa(kfl)
836  310 CONTINUE
837  tevcsv(jt)=tevcb
838  tevesv(jt)=teveb
839  ELSE
840  more(jt)=0
841  IF(jt.EQ.1) ipu1=n
842  IF(jt.EQ.2) ipu2=n
843  ENDIF
844  IF(n.GT.mstu(4)-mstu(32)-10) THEN
845  CALL pyerrm(11,'(PYSSPA:) no more memory left in PYJETS')
846  IF(mstu(21).GE.1) n=ns
847  IF(mstu(21).GE.1) RETURN
848  ENDIF
849  IF(more(1).EQ.1.OR.more(2).EQ.1) goto 150
850 
851 C...Boost hard scattering partons to frame of shower initiators.
852  DO 320 j=1,3
853  robo(j+2)=(p(ns+1,j)+p(ns+2,j))/(p(ns+1,4)+p(ns+2,4))
854  320 CONTINUE
855  k(n+2,1)=1
856  DO 330 j=1,5
857  p(n+2,j)=p(ns+1,j)
858  330 CONTINUE
859  CALL pyrobo(n+2,n+2,0d0,0d0,-robo(3),-robo(4),-robo(5))
860  robo(2)=pyangl(p(n+2,1),p(n+2,2))
861  robo(1)=pyangl(p(n+2,3),sqrt(p(n+2,1)**2+p(n+2,2)**2))
862  imin=mint(83)+5
863  IF(mint(31).GE.2) imin=min(ipus1,ipus2)
864  CALL pyrobo(imin,ns,0d0,-robo(2),0d0,0d0,0d0)
865  CALL pyrobo(imin,ns,robo(1),robo(2),robo(3),robo(4),robo(5))
866 
867 C...Store user information. Reset Lambda value.
868  IF(mint(31).LE.1) THEN
869  k(ipu1,3)=mint(83)+3
870  k(ipu2,3)=mint(83)+4
871  ELSE
872  k(ipu1,3)=mint(83)+1
873  k(ipu2,3)=mint(83)+2
874  ENDIF
875  DO 340 jt=1,2
876  mint(12+jt)=kfls(jt)
877  vint(140+jt)=xs(jt)
878  IF(mint(18+jt).EQ.1) vint(140+jt)=vint(154+jt)*xs(jt)
879  IF(mint(31).GE.2) vint(140+jt)=vint(140+jt)*vint(142+jt)
880  340 CONTINUE
881  paru(112)=alams
882 
883  RETURN
884  END