Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyptfs.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pyptfs.f
1 
2 C*********************************************************************
3 
4 C...PYPTFS
5 C...Generates pT-ordered timelike final-state parton showers.
6 
7 C...MODE defines how to find radiators and recoilers.
8 C... = 0 : based on colour flow between undecayed partons.
9 C... = 1 : for IPART <= NPARTD only consider primary partons,
10 C... whether decayed or not; else as above.
11 C... = 2 : based on common history, whether decayed or not.
12 
13  SUBROUTINE pyptfs(MODE,PTMAX,PTMIN,PTGEN)
14 
15 C...Double precision and integer declarations.
16  IMPLICIT DOUBLE PRECISION(a-h, o-z)
17  IMPLICIT INTEGER(i-n)
18  INTEGER pyk,pychge,pycomp
19 C...Parameter statement to help give large particle numbers.
20  parameter(ksusy1=1000000,ksusy2=2000000,ktechn=3000000,
21  &kexcit=4000000,kdimen=5000000)
22 C...Parameter statement for maximum size of showers.
23  parameter(maxnur=1000)
24 C...Commonblocks.
25  common/pypart/npart,npartd,ipart(maxnur),ptpart(maxnur)
26  common/pyjets/n,npad,k(4000,5),p(4000,5),v(4000,5)
27  common/pyctag/nct,mct(4000,2)
28  common/pydat1/mstu(200),paru(200),mstj(200),parj(200)
29  common/pydat2/kchg(500,4),pmas(500,4),parf(2000),vckm(4,4)
30  common/pypars/mstp(200),parp(200),msti(200),pari(200)
31  common/pyint1/mint(400),vint(400)
32  SAVE /pypart/,/pyjets/,/pyctag/,/pydat1/,/pydat2/,/pypars/,
33  &/pyint1/
34 C...Local arrays.
35  dimension ipos(2*maxnur),irec(2*maxnur),iflg(2*maxnur),
36  &iscol(2*maxnur),ischg(2*maxnur),ptsca(2*maxnur),imesav(2*maxnur),
37  &pt2sav(2*maxnur),zsav(2*maxnur),shtsav(2*maxnur),
38  &mesys(maxnur,0:2),psum(5),dpt(5,4)
39 C...Statement functions.
40  shat(i,j)=(p(i,4)+p(j,4))**2-(p(i,1)+p(j,1))**2-
41  &(p(i,2)+p(j,2))**2-(p(i,3)+p(j,3))**2
42 
43 C...Initial values. Check that valid system.
44  ptgen=0d0
45  IF(mstj(41).NE.1.AND.mstj(41).NE.2.AND.mstj(41).NE.11.AND.
46  &mstj(41).NE.12) RETURN
47  IF(npart.LE.0) THEN
48  CALL pyerrm(2,'(PYPTFS:) showering system too small')
49  RETURN
50  ENDIF
51  pt2cmx=ptmax**2
52 
53 C...Mass thresholds and Lambda for QCD evolution.
54  pmb=pmas(5,1)
55  pmc=pmas(4,1)
56  alam5=parj(81)
57  alam4=alam5*(pmb/alam5)**(2d0/25d0)
58  alam3=alam4*(pmc/alam4)**(2d0/27d0)
59  pmbs=pmb**2
60  pmcs=pmc**2
61  alam5s=alam5**2
62  alam4s=alam4**2
63  alam3s=alam3**2
64 
65 C...Cutoff scale for QCD evolution. Starting pT2.
66  nflav=max(0,min(5,mstj(45)))
67  pt0c=0.5d0*parj(82)
68  pt2cmn=max(ptmin,pt0c,1.1d0*alam3)**2
69 
70 C...Parameters for QED evolution.
71  aem2pi=paru(101)/paru(2)
72  pt0eq=0.5d0*parj(83)
73  pt0el=0.5d0*parj(90)
74 
75 C...Reset. Remove irrelevant colour tags.
76  nevol=0
77  DO 100 j=1,4
78  psum(j)=0d0
79  100 CONTINUE
80  DO 110 i=mint(84)+1,n
81  IF(k(i,2).GT.0.AND.k(i,2).LT.6) THEN
82  k(i,5)=0
83  mct(i,2)=0
84  ENDIF
85  IF(k(i,2).LT.0.AND.k(i,2).GT.-6) THEN
86  k(i,4)=0
87  mct(i,1)=0
88  ENDIF
89  110 CONTINUE
90  nparts=npart
91 
92 C...Begin loop to set up showering partons. Sum four-momenta.
93  DO 210 ip=1,npart
94  i=ipart(ip)
95  IF(mode.NE.1.OR.i.GT.npartd) THEN
96  IF(k(i,1).GT.10) goto 210
97  ELSEIF(k(i,3).GT.mint(84)) THEN
98  IF(k(i,3).GT.mint(84)+2) goto 210
99  ELSE
100  IF(k(k(i,3),3).GT.mint(83)+6) goto 210
101  ENDIF
102  DO 120 j=1,4
103  psum(j)=psum(j)+p(i,j)
104  120 CONTINUE
105 
106 C...Find colour and charge, but skip diquarks.
107  IF(iabs(k(i,2)).GT.1000.AND.iabs(k(i,2)).LT.10000) goto 210
108  kcol=isign(kchg(pycomp(k(i,2)),2),k(i,2))
109  kcha=isign(kchg(pycomp(k(i,2)),1),k(i,2))
110 
111 C...Either colour or anticolour charge radiates; for gluon both.
112  DO 160 jsgcol=1,-1,-2
113  IF(kcol.EQ.jsgcol.OR.kcol.EQ.2) THEN
114  jcol=4+(1-jsgcol)/2
115  jcolr=9-jcol
116 
117 C...Basic info about radiating parton.
118  nevol=nevol+1
119  ipos(nevol)=i
120  iflg(nevol)=0
121  iscol(nevol)=jsgcol
122  ischg(nevol)=0
123  ptsca(nevol)=ptpart(ip)
124 
125 C...Begin search for colour recoiler when MODE = 0 or 1.
126  IF(mode.LE.1) THEN
127 C...Find sister with matching anticolour to the radiating parton.
128  irold=i
129  irnew=k(irold,jcol)/mstu(5)
130  move=1
131 
132 C...The following will add MCT colour tracing for unprepped events
133 C...If not done, trace Les Houches colour tags for this dipole
134 C IF (MCT(I,JCOL-3).EQ.0) THEN
135 C CALL PYCTTR(I,JCOL,INEW)
136 C...Clean up mother/daughter 'read' tags set by PYCTTR
137 C DO 125 IR=1,N
138 C K(IR,4)=MOD(K(IR,4),MSTU(5)**2)
139 C K(IR,5)=MOD(K(IR,5),MSTU(5)**2)
140 C 125 CONTINUE
141 C ENDIF
142 
143 C...Skip radiation off loose colour ends.
144  130 IF(irnew.EQ.0) THEN
145  nevol=nevol-1
146  goto 160
147 
148 C...Optionally skip radiation on dipole to beam remnant.
149  ELSEIF(mstp(72).LE.1.AND.irnew.GT.mint(53)) THEN
150  nevol=nevol-1
151  goto 160
152 
153 C...For now always skip radiation on dipole to junction.
154  ELSEIF(k(irnew,2).EQ.88) THEN
155  nevol=nevol-1
156  goto 160
157 
158 C...For MODE=1: if reached primary then done.
159  ELSEIF(mode.EQ.1.AND.irnew.GT.mint(84)+2.AND.
160  & irnew.LE.npartd) THEN
161 
162 C...If sister stable and points back then done.
163  ELSEIF(move.EQ.1.AND.k(irnew,jcolr)/mstu(5).EQ.irold)
164  & THEN
165  IF(k(irnew,1).LT.10) THEN
166 
167 C...If sister unstable then go to her daughter.
168  ELSE
169  irold=irnew
170  irnew=mod(k(irnew,jcolr),mstu(5))
171  move=2
172  goto 130
173  ENDIF
174 
175 C...If found mother then look for aunt.
176  ELSEIF(move.EQ.1.AND.mod(k(irnew,jcol),mstu(5)).EQ.
177  & irold) THEN
178  irold=irnew
179  irnew=k(irold,jcol)/mstu(5)
180  goto 130
181 
182 C...If daughter stable then done.
183  ELSEIF(move.EQ.2.AND.k(irnew,jcolr)/mstu(5).EQ.irold)
184  & THEN
185  IF(k(irnew,1).LT.10) THEN
186 
187 C...If daughter unstable then go to granddaughter.
188  ELSE
189  irold=irnew
190  irnew=mod(k(irnew,jcolr),mstu(5))
191  move=2
192  goto 130
193  ENDIF
194 
195 C...If daughter points to another daughter then done or move up.
196  ELSEIF(move.EQ.2.AND.mod(k(irnew,jcol),mstu(5)).EQ.
197  & irold) THEN
198  IF(k(irnew,1).LT.10) THEN
199  ELSE
200  irold=irnew
201  irnew=k(irnew,jcol)/mstu(5)
202  move=1
203  goto 130
204  ENDIF
205  ENDIF
206 
207 C...Begin search for colour recoiler when MODE = 2.
208  ELSE
209  irold=i
210  irnew=k(irold,jcol)/mstu(5)
211  140 IF(k(irnew,jcolr)/mstu(5).NE.irold) THEN
212 C...Step up to mother if radiating parton already branched.
213  IF(k(irnew,2).EQ.k(irold,2)) THEN
214  irold=irnew
215  irnew=k(irold,jcol)/mstu(5)
216  goto 140
217 C...Pick sister by history if no anticolour available.
218  ELSE
219  IF(irold.GT.1.AND.k(irold-1,3).EQ.k(irold,3)) THEN
220  irnew=irold-1
221  ELSEIF(irold.LT.n.AND.k(irold+1,3).EQ.k(irold,3))
222  & THEN
223  irnew=irold+1
224 C...Last resort: pick at random among other primaries.
225  ELSE
226  istep=max(1,min(npart-1,int(1d0+(npart-1)*pyr(0))))
227  irnew=ipart(1+mod(ip+istep-1,npart))
228  ENDIF
229  ENDIF
230  ENDIF
231 C...Trace down if sister branched.
232  150 IF(k(irnew,1).GT.10) THEN
233  irnew=mod(k(irnew,jcolr),mstu(5))
234  goto 150
235  ENDIF
236  ENDIF
237 
238 C...Now found other end of colour dipole.
239  irec(nevol)=irnew
240  ENDIF
241  160 CONTINUE
242 
243 C...Also electrical charge may radiate; so far only quarks and leptons.
244  IF((mstj(41).EQ.2.OR.mstj(41).EQ.12).AND.kcha.NE.0.AND.
245  & iabs(k(i,2)).LE.18) THEN
246 
247 C...Basic info about radiating parton.
248  nevol=nevol+1
249  ipos(nevol)=i
250  iflg(nevol)=0
251  iscol(nevol)=0
252  ischg(nevol)=kcha
253  ptsca(nevol)=ptpart(ip)
254 
255 C...Pick nearest (= smallest invariant mass) charged particle
256 C...as recoiler when MODE = 0 or 1 (but for latter among primaries).
257  IF(mode.LE.1) THEN
258  irnew=0
259  pm2min=vint(2)
260  DO 170 ip2=1,npart+n-mint(53)
261  IF(ip2.EQ.ip) goto 170
262  IF(ip2.LE.npart) THEN
263  i2=ipart(ip2)
264  IF(mode.NE.1.OR.i2.GT.npartd) THEN
265  IF(k(i2,1).GT.10) goto 170
266  ELSEIF(k(i2,3).GT.mint(84)) THEN
267  IF(k(i2,3).GT.mint(84)+2) goto 170
268  ELSE
269  IF(k(k(i2,3),3).GT.mint(83)+6) goto 170
270  ENDIF
271  ELSE
272  i2=mint(53)+ip2-npart
273  ENDIF
274  IF(kchg(pycomp(k(i2,2)),1).EQ.0) goto 170
275  pm2inv=(p(i,4)+p(i2,4))**2-(p(i,1)+p(i2,1))**2-
276  & (p(i,2)+p(i2,2))**2-(p(i,3)+p(i2,3))**2
277  IF(pm2inv.LT.pm2min) THEN
278  irnew=i2
279  pm2min=pm2inv
280  ENDIF
281  170 CONTINUE
282  IF(irnew.EQ.0) THEN
283  nevol=nevol-1
284  goto 210
285  ENDIF
286 
287 C...Begin search for charge recoiler when MODE = 2.
288  ELSE
289  irold=i
290 C...Pick sister by history; step up if parton already branched.
291  180 IF(k(irold,3).GT.0.AND.k(k(irold,3),2).EQ.k(irold,2)) THEN
292  irold=k(irold,3)
293  goto 180
294  ENDIF
295  IF(irold.GT.1.AND.k(irold-1,3).EQ.k(irold,3)) THEN
296  irnew=irold-1
297  ELSEIF(irold.LT.n.AND.k(irold+1,3).EQ.k(irold,3)) THEN
298  irnew=irold+1
299 C...Last resort: pick at random among other primaries.
300  ELSE
301  istep=max(1,min(npart-1,int(1d0+(npart-1)*pyr(0))))
302  irnew=ipart(1+mod(ip+istep-1,npart))
303  ENDIF
304 C...Trace down if sister branched.
305  190 IF(k(irnew,1).GT.10) THEN
306  DO 200 ir=irnew+1,n
307  IF(k(ir,3).EQ.irnew.AND.k(ir,2).EQ.k(irnew,2)) THEN
308  irnew=ir
309  goto 190
310  ENDIF
311  200 CONTINUE
312  ENDIF
313  ENDIF
314  irec(nevol)=irnew
315  ENDIF
316 
317 C...End loop to set up showering partons. System invariant mass.
318  210 CONTINUE
319  IF(nevol.LE.0) RETURN
320  psum(5)=sqrt(max(0d0,psum(4)**2-psum(1)**2-psum(2)**2-psum(3)**2))
321 
322 C...Check if 3-jet matrix elements to be used.
323  m3jc=0
324  alpha=0.5d0
325  nmesys=0
326  IF(mstj(47).GE.1) THEN
327 
328 C...Identify source: q(1), ~q(2), V(3), S(4), chi(5), ~g(6), unknown(0).
329  kfsrce=0
330  ipart1=k(ipart(1),3)
331  ipart2=k(ipart(2),3)
332  220 IF(ipart1.EQ.ipart2.AND.ipart1.GT.0) THEN
333  kfsrce=iabs(k(ipart1,2))
334  ELSEIF(ipart1.GT.ipart2.AND.ipart2.GT.0) THEN
335  ipart1=k(ipart1,3)
336  goto 220
337  ELSEIF(ipart2.GT.ipart1.AND.ipart1.GT.0) THEN
338  ipart2=k(ipart2,3)
339  goto 220
340  ENDIF
341  itypes=0
342  IF(kfsrce.GE.1.AND.kfsrce.LE.8) itypes=1
343  IF(kfsrce.GE.ksusy1+1.AND.kfsrce.LE.ksusy1+8) itypes=2
344  IF(kfsrce.GE.ksusy2+1.AND.kfsrce.LE.ksusy2+8) itypes=2
345  IF(kfsrce.GE.21.AND.kfsrce.LE.24) itypes=3
346  IF(kfsrce.GE.32.AND.kfsrce.LE.34) itypes=3
347  IF(kfsrce.EQ.25.OR.(kfsrce.GE.35.AND.kfsrce.LE.37)) itypes=4
348  IF(kfsrce.GE.ksusy1+22.AND.kfsrce.LE.ksusy1+37) itypes=5
349  IF(kfsrce.EQ.ksusy1+21) itypes=6
350 
351 C...Identify two primary showerers.
352  kfla1=iabs(k(ipart(1),2))
353  itype1=0
354  IF(kfla1.GE.1.AND.kfla1.LE.8) itype1=1
355  IF(kfla1.GE.ksusy1+1.AND.kfla1.LE.ksusy1+8) itype1=2
356  IF(kfla1.GE.ksusy2+1.AND.kfla1.LE.ksusy2+8) itype1=2
357  IF(kfla1.GE.21.AND.kfla1.LE.24) itype1=3
358  IF(kfla1.GE.32.AND.kfla1.LE.34) itype1=3
359  IF(kfla1.EQ.25.OR.(kfla1.GE.35.AND.kfla1.LE.37)) itype1=4
360  IF(kfla1.GE.ksusy1+22.AND.kfla1.LE.ksusy1+37) itype1=5
361  IF(kfla1.EQ.ksusy1+21) itype1=6
362  kfla2=iabs(k(ipart(2),2))
363  itype2=0
364  IF(kfla2.GE.1.AND.kfla2.LE.8) itype2=1
365  IF(kfla2.GE.ksusy1+1.AND.kfla2.LE.ksusy1+8) itype2=2
366  IF(kfla2.GE.ksusy2+1.AND.kfla2.LE.ksusy2+8) itype2=2
367  IF(kfla2.GE.21.AND.kfla2.LE.24) itype2=3
368  IF(kfla2.GE.32.AND.kfla2.LE.34) itype2=3
369  IF(kfla2.EQ.25.OR.(kfla2.GE.35.AND.kfla2.LE.37)) itype2=4
370  IF(kfla2.GE.ksusy1+22.AND.kfla2.LE.ksusy1+37) itype2=5
371  IF(kfla2.EQ.ksusy1+21) itype2=6
372 
373 C...Order of showerers. Presence of gluino.
374  itypmn=min(itype1,itype2)
375  itypmx=max(itype1,itype2)
376  iord=1
377  IF(itype1.GT.itype2) iord=2
378  iglui=0
379  IF(itype1.EQ.6.OR.itype2.EQ.6) iglui=1
380 
381 C...Require exactly two primary showerers for ME corrections.
382  nprim=0
383  DO 230 i=1,n
384  IF(k(i,3).EQ.ipart1.AND.k(i,2).NE.k(ipart1,2)) nprim=nprim+1
385  230 CONTINUE
386  IF(nprim.NE.2) THEN
387 
388 C...Predetermined and default matrix element kinds.
389  ELSEIF(mstj(38).NE.0) THEN
390  m3jc=mstj(38)
391  alpha=parj(80)
392  mstj(38)=0
393  ELSEIF(mstj(47).GE.6) THEN
394  m3jc=mstj(47)
395  ELSE
396  iclass=1
397  icombi=4
398 
399 C...Vector/axial vector -> q + qbar; q -> q + V.
400  IF(itypmn.EQ.1.AND.itypmx.EQ.1.AND.(itypes.EQ.0.OR.
401  & itypes.EQ.3)) THEN
402  iclass=2
403  IF(kfsrce.EQ.21.OR.kfsrce.EQ.22) THEN
404  icombi=1
405  ELSEIF(kfsrce.EQ.23.OR.(kfsrce.EQ.0.AND.
406  & k(ipart(1),2)+k(ipart(2),2).EQ.0)) THEN
407 C...gamma*/Z0: assume e+e- initial state if unknown.
408  ei=-1d0
409  IF(kfsrce.EQ.23) THEN
410  iannfl=ipart1
411  IF(k(iannfl,2).EQ.23) iannfl=k(iannfl,3)
412  IF(iannfl.GT.0) THEN
413  IF(k(iannfl,2).EQ.23) iannfl=k(iannfl,3)
414  ENDIF
415  IF(iannfl.NE.0) THEN
416  kannfl=iabs(k(iannfl,2))
417  IF(kannfl.GE.1.AND.kannfl.LE.18) ei=kchg(kannfl,1)/3d0
418  ENDIF
419  ENDIF
420  ai=sign(1d0,ei+0.1d0)
421  vi=ai-4d0*ei*paru(102)
422  ef=kchg(kfla1,1)/3d0
423  af=sign(1d0,ef+0.1d0)
424  vf=af-4d0*ef*paru(102)
425  xwc=1d0/(16d0*paru(102)*(1d0-paru(102)))
426  sh=psum(5)**2
427  sqmz=pmas(23,1)**2
428  sqwz=psum(5)*pmas(23,2)
429  sbwz=1d0/((sh-sqmz)**2+sqwz**2)
430  vect=ei**2*ef**2+2d0*ei*vi*ef*vf*xwc*sh*(sh-sqmz)*sbwz+
431  & (vi**2+ai**2)*vf**2*xwc**2*sh**2*sbwz
432  axiv=(vi**2+ai**2)*af**2*xwc**2*sh**2*sbwz
433  icombi=3
434  alpha=vect/(vect+axiv)
435  ELSEIF(kfsrce.EQ.24.OR.kfsrce.EQ.0) THEN
436  icombi=4
437  ENDIF
438 C...For chi -> chi q qbar, use V/A -> q qbar as first approximation.
439  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.1.AND.itypes.EQ.5) THEN
440  iclass=2
441  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.3.AND.(itypes.EQ.0.OR.
442  & itypes.EQ.1)) THEN
443  iclass=3
444 
445 C...Scalar/pseudoscalar -> q + qbar; q -> q + S.
446  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.1.AND.itypes.EQ.4) THEN
447  iclass=4
448  IF(kfsrce.EQ.25.OR.kfsrce.EQ.35.OR.kfsrce.EQ.37) THEN
449  icombi=1
450  ELSEIF(kfsrce.EQ.36) THEN
451  icombi=2
452  ENDIF
453  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.4.AND.(itypes.EQ.0.OR.
454  & itypes.EQ.1)) THEN
455  iclass=5
456 
457 C...V -> ~q + ~qbar; ~q -> ~q + V; S -> ~q + ~qbar; ~q -> ~q + S.
458  ELSEIF(itypmn.EQ.2.AND.itypmx.EQ.2.AND.(itypes.EQ.0.OR.
459  & itypes.EQ.3)) THEN
460  iclass=6
461  ELSEIF(itypmn.EQ.2.AND.itypmx.EQ.3.AND.(itypes.EQ.0.OR.
462  & itypes.EQ.2)) THEN
463  iclass=7
464  ELSEIF(itypmn.EQ.2.AND.itypmx.EQ.2.AND.itypes.EQ.4) THEN
465  iclass=8
466  ELSEIF(itypmn.EQ.2.AND.itypmx.EQ.4.AND.(itypes.EQ.0.OR.
467  & itypes.EQ.2)) THEN
468  iclass=9
469 
470 C...chi -> q + ~qbar; ~q -> q + chi; q -> ~q + chi.
471  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.2.AND.(itypes.EQ.0.OR.
472  & itypes.EQ.5)) THEN
473  iclass=10
474  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.5.AND.(itypes.EQ.0.OR.
475  & itypes.EQ.2)) THEN
476  iclass=11
477  ELSEIF(itypmn.EQ.2.AND.itypmx.EQ.5.AND.(itypes.EQ.0.OR.
478  & itypes.EQ.1)) THEN
479  iclass=12
480 
481 C...~g -> q + ~qbar; ~q -> q + ~g; q -> ~q + ~g.
482  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.2.AND.itypes.EQ.6) THEN
483  iclass=13
484  ELSEIF(itypmn.EQ.1.AND.itypmx.EQ.6.AND.(itypes.EQ.0.OR.
485  & itypes.EQ.2)) THEN
486  iclass=14
487  ELSEIF(itypmn.EQ.2.AND.itypmx.EQ.6.AND.(itypes.EQ.0.OR.
488  & itypes.EQ.1)) THEN
489  iclass=15
490 
491 C...g -> ~g + ~g (eikonal approximation).
492  ELSEIF(itypmn.EQ.6.AND.itypmx.EQ.6.AND.itypes.EQ.0) THEN
493  iclass=16
494  ENDIF
495  m3jc=5*iclass+icombi
496  ENDIF
497 
498 C...Store pair that together define matrix element treatment.
499  IF(m3jc.NE.0) THEN
500  nmesys=1
501  mesys(nmesys,0)=m3jc
502  mesys(nmesys,1)=ipart(1)
503  mesys(nmesys,2)=ipart(2)
504  ENDIF
505 
506 C...Store qqbar or l+l- pairs for QED radiation.
507  IF(kfla1.LE.18.AND.kfla2.LE.18) THEN
508  nmesys=nmesys+1
509  mesys(nmesys,0)=101
510  IF(k(ipart(1),2)+k(ipart(2),2).EQ.0) mesys(nmesys,0)=102
511  mesys(nmesys,1)=ipart(1)
512  mesys(nmesys,2)=ipart(2)
513  ENDIF
514 
515 C...Store other qqbar/l+l- pairs from g/gamma branchings.
516  DO 270 i1=1,n
517  IF(k(i1,1).GT.10.OR.iabs(k(i1,2)).GT.18) goto 270
518  i1m=k(i1,3)
519  240 IF(i1m.GT.0.AND.k(i1m,2).EQ.k(i1,2)) THEN
520  i1m=k(i1m,3)
521  goto 240
522  ENDIF
523 C...Move up this check to avoid out-of-bounds.
524  IF(i1m.EQ.0) goto 270
525  IF(k(i1m,2).NE.21.AND.k(i1m,2).NE.22) goto 270
526  DO 260 i2=i1+1,n
527  IF(k(i2,1).GT.10.OR.k(i2,2)+k(i1,2).NE.0) goto 260
528  i2m=k(i2,3)
529  250 IF(i2m.GT.0.AND.k(i2m,2).EQ.k(i2,2)) THEN
530  i2m=k(i2m,3)
531  goto 250
532  ENDIF
533  IF(i1m.EQ.i2m.AND.i1m.GT.0) THEN
534  nmesys=nmesys+1
535  mesys(nmesys,0)=66
536  mesys(nmesys,1)=i1
537  mesys(nmesys,2)=i2
538  nmesys=nmesys+1
539  mesys(nmesys,0)=102
540  mesys(nmesys,1)=i1
541  mesys(nmesys,2)=i2
542  ENDIF
543  260 CONTINUE
544  270 CONTINUE
545  ENDIF
546 
547 C..Loopback point for counting number of emissions.
548  ngen=0
549  280 ngen=ngen+1
550 
551 C...Begin loop to evolve all existing partons, if required.
552  290 imx=0
553  pt2mx=0d0
554  DO 360 ievol=1,nevol
555  IF(iflg(ievol).EQ.0) THEN
556 
557 C...Basic info on radiator and recoil.
558  i=ipos(ievol)
559  ir=irec(ievol)
560  sht=shat(i,ir)
561  pm2i=p(i,5)**2
562  pm2r=p(ir,5)**2
563 
564 C...Invariant mass of "dipole".Starting value for pT evolution.
565  shtcor=(sqrt(sht)-p(ir,5))**2-pm2i
566  pt2=min(pt2cmx,0.25d0*shtcor,ptsca(ievol)**2)
567 
568 C...Case of evolution by QCD branching.
569  IF(iscol(ievol).NE.0) THEN
570 
571 C...Parton-by-parton maximum scale from initial conditions.
572  IF(mstp(72).EQ.0) THEN
573  DO 300 iprt=1,nparts
574  IF(ir.EQ.ipart(iprt)) pt2=min(pt2,ptpart(iprt)**2)
575  300 CONTINUE
576  ENDIF
577 
578 C...If kinematically impossible then do not evolve.
579  IF(pt2.LT.pt2cmn) THEN
580  iflg(ievol)=-1
581  goto 360
582  ENDIF
583 
584 C...Check if part of system for which ME corrections should be applied.
585  imesys=0
586  DO 310 ime=1,nmesys
587  IF((i.EQ.mesys(ime,1).OR.i.EQ.mesys(ime,2)).AND.
588  & mesys(ime,0).LT.100) imesys=ime
589  310 CONTINUE
590 
591 C...Special flag for colour octet states.
592  moct=0
593  IF(k(i,2).EQ.21) moct=1
594  IF(k(i,2).EQ.ksusy1+21) moct=2
595 
596 C...Upper estimate for matrix element weighting and colour factor.
597 C...Note that g->gg and g->qqbar is split on two sides = "dipoles".
598  wtpsgl=2d0
599  colfac=4d0/3d0
600  IF(moct.GE.1) colfac=3d0/2d0
601  IF(iglui.EQ.1.AND.imesys.EQ.1.AND.moct.EQ.0) colfac=3d0
602  wtpsqq=0.5d0*0.5d0*nflav
603 
604 C...Determine overestimated z range: switch at c and b masses.
605  320 izrg=1
606  pt2mne=pt2cmn
607  b0=27d0/6d0
608  alams=alam3s
609  IF(pt2.GT.1.01d0*pmcs) THEN
610  izrg=2
611  pt2mne=pmcs
612  b0=25d0/6d0
613  alams=alam4s
614  ENDIF
615  IF(pt2.GT.1.01d0*pmbs) THEN
616  izrg=3
617  pt2mne=pmbs
618  b0=23d0/6d0
619  alams=alam5s
620  ENDIF
621  zmncut=0.5d0-sqrt(max(0d0,0.25d0-pt2mne/shtcor))
622  IF(zmncut.LT.1d-8) zmncut=pt2mne/shtcor
623 
624 C...Find evolution coefficients for q->qg/g->gg and g->qqbar.
625  evemgl=wtpsgl*colfac*log(1d0/zmncut-1d0)/b0
626  evcoef=evemgl
627  IF(moct.EQ.1) THEN
628  evemqq=wtpsqq*(1d0-2d0*zmncut)/b0
629  evcoef=evcoef+evemqq
630  ENDIF
631 
632 C...Pick pT2 (in overestimated z range).
633  330 pt2=alams*(pt2/alams)**(pyr(0)**(1d0/evcoef))
634 
635 C...Loopback if crossed c/b mass thresholds.
636  IF(izrg.EQ.3.AND.pt2.LT.pmbs) THEN
637  pt2=pmbs
638  goto 320
639  ENDIF
640  IF(izrg.EQ.2.AND.pt2.LT.pmcs) THEN
641  pt2=pmcs
642  goto 320
643  ENDIF
644 
645 C...Finish if below lower cutoff.
646  IF(pt2.LT.pt2cmn) THEN
647  iflg(ievol)=-1
648  goto 360
649  ENDIF
650 
651 C...Pick kind of branching: q->qg/g->gg/X->Xg or g->qqbar.
652  iflag=1
653  IF(moct.EQ.1.AND.evemgl.LT.pyr(0)*evcoef) iflag=2
654 
655 C...Pick z: dz/(1-z) or dz.
656  IF(iflag.EQ.1) THEN
657  z=1d0-zmncut*(1d0/zmncut-1d0)**pyr(0)
658  ELSE
659  z=zmncut+pyr(0)*(1d0-2d0*zmncut)
660  ENDIF
661 
662 C...Loopback if outside allowed range for given pT2.
663  zmnnow=0.5d0-sqrt(max(0d0,0.25d0-pt2/shtcor))
664  IF(zmnnow.LT.1d-8) zmnnow=pt2/shtcor
665  IF(z.LE.zmnnow.OR.z.GE.1d0-zmnnow) goto 330
666  pm2=pm2i+pt2/(z*(1d0-z))
667  IF(z*(1d0-z).LE.pm2*sht/(sht+pm2-pm2r)**2) goto 330
668 
669 C...No weighting for primary partons; to be done later on.
670  IF(imesys.GT.0) THEN
671 
672 C...Weighting of q->qg/X->Xg branching.
673  ELSEIF(iflag.EQ.1.AND.moct.NE.1) THEN
674  IF(1d0+z**2.LT.wtpsgl*pyr(0)) goto 330
675 
676 C...Weighting of g->gg branching.
677  ELSEIF(iflag.EQ.1) THEN
678  IF(1d0+z**3.LT.wtpsgl*pyr(0)) goto 330
679 
680 C...Flavour choice and weighting of g->qqbar branching.
681  ELSE
682  kfq=min(5,1+int(nflav*pyr(0)))
683  pmq=pmas(kfq,1)
684  rootqq=sqrt(max(0d0,1d0-4d0*pmq**2/pm2))
685  wtme=rootqq*(z**2+(1d0-z)**2)
686  IF(wtme.LT.pyr(0)) goto 330
687  iflag=10+kfq
688  ENDIF
689 
690 C...Case of evolution by QED branching.
691  ELSEIF(ischg(ievol).NE.0) THEN
692 
693 C...If kinematically impossible then do not evolve.
694  pt2emn=pt0eq**2
695  IF(iabs(k(i,2)).GT.10) pt2emn=pt0el**2
696  IF(pt2.LT.pt2emn) THEN
697  iflg(ievol)=-1
698  goto 360
699  ENDIF
700 
701 C...Check if part of system for which ME corrections should be applied.
702  imesys=0
703  DO 340 ime=1,nmesys
704  IF((i.EQ.mesys(ime,1).OR.i.EQ.mesys(ime,2)).AND.
705  & mesys(ime,0).GT.100) imesys=ime
706  340 CONTINUE
707 
708 C...Charge. Matrix element weighting factor.
709  chg=ischg(ievol)/3d0
710  wtpsga=2d0
711 
712 C...Determine overestimated z range. Find evolution coefficient.
713  zmncut=0.5d0-sqrt(max(0d0,0.25d0-pt2emn/shtcor))
714  IF(zmncut.LT.1d-8) zmncut=pt2emn/shtcor
715  evcoef=aem2pi*chg**2*wtpsga*log(1d0/zmncut-1d0)
716 
717 C...Pick pT2 (in overestimated z range).
718  350 pt2=pt2*pyr(0)**(1d0/evcoef)
719 
720 C...Finish if below lower cutoff.
721  IF(pt2.LT.pt2emn) THEN
722  iflg(ievol)=-1
723  goto 360
724  ENDIF
725 
726 C...Pick z: dz/(1-z).
727  z=1d0-zmncut*(1d0/zmncut-1d0)**pyr(0)
728 
729 C...Loopback if outside allowed range for given pT2.
730  zmnnow=0.5d0-sqrt(max(0d0,0.25d0-pt2/shtcor))
731  IF(zmnnow.LT.1d-8) zmnnow=pt2/shtcor
732  IF(z.LE.zmnnow.OR.z.GE.1d0-zmnnow) goto 350
733  pm2=pm2i+pt2/(z*(1d0-z))
734  IF(z*(1d0-z).LE.pm2*sht/(sht+pm2-pm2r)**2) goto 350
735 
736 C...Weighting by branching kernel, except if ME weighting later.
737  IF(imesys.EQ.0) THEN
738  IF(1d0+z**2.LT.wtpsga*pyr(0)) goto 350
739  ENDIF
740  iflag=3
741  ENDIF
742 
743 C...Save acceptable branching.
744  iflg(ievol)=iflag
745  imesav(ievol)=imesys
746  pt2sav(ievol)=pt2
747  zsav(ievol)=z
748  shtsav(ievol)=sht
749  ENDIF
750 
751 C...Check if branching has highest pT.
752  IF(iflg(ievol).GE.1.AND.pt2sav(ievol).GT.pt2mx) THEN
753  imx=ievol
754  pt2mx=pt2sav(ievol)
755  ENDIF
756  360 CONTINUE
757 
758 C...Finished if no more branchings to be done.
759  IF(imx.EQ.0) goto 480
760 
761 C...Restore info on hardest branching to be processed.
762  i=ipos(imx)
763  ir=irec(imx)
764  kcol=iscol(imx)
765  kcha=ischg(imx)
766  imesys=imesav(imx)
767  pt2=pt2sav(imx)
768  z=zsav(imx)
769  sht=shtsav(imx)
770  pm2i=p(i,5)**2
771  pm2r=p(ir,5)**2
772  pm2=pm2i+pt2/(z*(1d0-z))
773 
774 C...Special flag for colour octet states.
775  moct=0
776  IF(k(i,2).EQ.21) moct=1
777  IF(k(i,2).EQ.ksusy1+21) moct=2
778 
779 C...Restore further info for g->qqbar branching.
780  kfq=0
781  IF(iflg(imx).GT.10) THEN
782  kfq=iflg(imx)-10
783  pmq=pmas(kfq,1)
784  rootqq=sqrt(max(0d0,1d0-4d0*pmq**2/pm2))
785  ENDIF
786 
787 C...For branching g include azimuthal asymmetries from polarization.
788  asypol=0d0
789  IF(moct.EQ.1.AND.mod(mstj(46),2).EQ.1) THEN
790 C...Trace grandmother via intermediate recoil copies.
791  kfgm=0
792  im=i
793  370 IF(k(im,3).NE.k(im-1,3).AND.k(im,3).NE.k(im+1,3).AND.
794  & k(im,3).GT.0) THEN
795  im=k(im,3)
796  IF(im.GT.mint(84)) goto 370
797  ENDIF
798  igm=k(im,3)
799  IF(igm.GT.mint(84).AND.igm.LT.im.AND.im.LE.i)
800  & kfgm=iabs(k(igm,2))
801 C...Define approximate energy sharing by identifying aunt.
802  iau=im+1
803  IF(iau.GT.n-3.OR.k(iau,3).NE.igm) iau=im-1
804  IF(kfgm.NE.0.AND.(kfgm.LE.6.OR.kfgm.EQ.21)) THEN
805  zold=p(im,4)/(p(im,4)+p(iau,4))
806 C...Coefficient from gluon production.
807  IF(kfgm.LE.6) THEN
808  asypol=2d0*(1d0-zold)/(1d0+(1d0-zold)**2)
809  ELSE
810  asypol=((1d0-zold)/(1d0-zold*(1d0-zold)))**2
811  ENDIF
812 C...Coefficient from gluon decay.
813  IF(kfq.EQ.0) THEN
814  asypol=asypol*(z*(1d0-z)/(1d0-z*(1d0-z)))**2
815  ELSE
816  asypol=-asypol*2d0*z*(1d0-z)/(1d0-2d0*z*(1d0-z))
817  ENDIF
818  ENDIF
819  ENDIF
820 
821 C...Create new slots for branching products and recoil.
822  inew=n+1
823  ignew=n+2
824  irnew=n+3
825  n=n+3
826 
827 C...Set status, flavour and mother of new ones.
828  k(inew,1)=k(i,1)
829  k(ignew,1)=3
830  IF(kcha.NE.0) k(ignew,1)=1
831  k(irnew,1)=k(ir,1)
832  IF(kfq.EQ.0) THEN
833  k(inew,2)=k(i,2)
834  k(ignew,2)=21
835  IF(kcha.NE.0) k(ignew,2)=22
836  ELSE
837  k(inew,2)=-isign(kfq,kcol)
838  k(ignew,2)=-k(inew,2)
839  ENDIF
840  k(irnew,2)=k(ir,2)
841  k(inew,3)=i
842  k(ignew,3)=i
843  k(irnew,3)=ir
844 
845 C...Find rest frame and angles of branching+recoil.
846  DO 380 j=1,5
847  p(inew,j)=p(i,j)
848  p(ignew,j)=0d0
849  p(irnew,j)=p(ir,j)
850  380 CONTINUE
851  betax=(p(inew,1)+p(irnew,1))/(p(inew,4)+p(irnew,4))
852  betay=(p(inew,2)+p(irnew,2))/(p(inew,4)+p(irnew,4))
853  betaz=(p(inew,3)+p(irnew,3))/(p(inew,4)+p(irnew,4))
854  CALL pyrobo(inew,irnew,0d0,0d0,-betax,-betay,-betaz)
855  phi=pyangl(p(inew,1),p(inew,2))
856  theta=pyangl(p(inew,3),sqrt(p(inew,1)**2+p(inew,2)**2))
857 
858 C...Derive kinematics of branching: generics (like g->gg).
859  DO 390 j=1,4
860  p(inew,j)=0d0
861  p(irnew,j)=0d0
862  390 CONTINUE
863  pem=0.5d0*(sht+pm2-pm2r)/sqrt(sht)
864  pzm=0.5d0*sqrt(max(0d0,(sht-pm2-pm2r)**2-4d0*pm2*pm2r)/sht)
865  pt2cor=pm2*(pem**2*z*(1d0-z)-0.25d0*pm2)/pzm**2
866  ptcor=sqrt(max(0d0,pt2cor))
867  pzn=(pem**2*z-0.5d0*pm2)/pzm
868  pzg=(pem**2*(1d0-z)-0.5d0*pm2)/pzm
869 C...Specific kinematics reduction for q->qg with m_q > 0.
870  IF(moct.NE.1) THEN
871  ptcor=(1d0-pm2i/pm2)*ptcor
872  pzn=pzn+pm2i*pzg/pm2
873  pzg=(1d0-pm2i/pm2)*pzg
874 C...Specific kinematics reduction for g->qqbar with m_q > 0.
875  ELSEIF(kfq.NE.0) THEN
876  p(inew,5)=pmq
877  p(ignew,5)=pmq
878  ptcor=rootqq*ptcor
879  pzn=0.5d0*((1d0+rootqq)*pzn+(1d0-rootqq)*pzg)
880  pzg=pzm-pzn
881  ENDIF
882 
883 C...Pick phi and construct kinematics of branching.
884  400 phirot=paru(2)*pyr(0)
885  p(inew,1)=ptcor*cos(phirot)
886  p(inew,2)=ptcor*sin(phirot)
887  p(inew,3)=pzn
888  p(inew,4)=sqrt(ptcor**2+p(inew,3)**2+p(inew,5)**2)
889  p(ignew,1)=-p(inew,1)
890  p(ignew,2)=-p(inew,2)
891  p(ignew,3)=pzg
892  p(ignew,4)=sqrt(ptcor**2+p(ignew,3)**2+p(ignew,5)**2)
893  p(irnew,1)=0d0
894  p(irnew,2)=0d0
895  p(irnew,3)=-pzm
896  p(irnew,4)=0.5d0*(sht+pm2r-pm2)/sqrt(sht)
897 
898 C...Boost branching system to lab frame.
899  CALL pyrobo(inew,irnew,theta,phi,betax,betay,betaz)
900 
901 C...Renew choice of phi angle according to polarization asymmetry.
902  IF(abs(asypol).GT.1d-3) THEN
903  DO 410 j=1,3
904  dpt(1,j)=p(i,j)
905  dpt(2,j)=p(iau,j)
906  dpt(3,j)=p(inew,j)
907  410 CONTINUE
908  dpma=dpt(1,1)*dpt(2,1)+dpt(1,2)*dpt(2,2)+dpt(1,3)*dpt(2,3)
909  dpmd=dpt(1,1)*dpt(3,1)+dpt(1,2)*dpt(3,2)+dpt(1,3)*dpt(3,3)
910  dpmm=dpt(1,1)**2+dpt(1,2)**2+dpt(1,3)**2
911  DO 420 j=1,3
912  dpt(4,j)=dpt(2,j)-dpma*dpt(1,j)/max(1d-10,dpmm)
913  dpt(5,j)=dpt(3,j)-dpmd*dpt(1,j)/max(1d-10,dpmm)
914  420 CONTINUE
915  dpt(4,4)=sqrt(dpt(4,1)**2+dpt(4,2)**2+dpt(4,3)**2)
916  dpt(5,4)=sqrt(dpt(5,1)**2+dpt(5,2)**2+dpt(5,3)**2)
917  IF(min(dpt(4,4),dpt(5,4)).GT.0.1d0*parj(82)) THEN
918  cad=(dpt(4,1)*dpt(5,1)+dpt(4,2)*dpt(5,2)+
919  & dpt(4,3)*dpt(5,3))/(dpt(4,4)*dpt(5,4))
920  IF(1d0+asypol*(2d0*cad**2-1d0).LT.pyr(0)*(1d0+abs(asypol)))
921  & goto 400
922  ENDIF
923  ENDIF
924 
925 C...Matrix element corrections for primary partons when requested.
926  IF(imesys.GT.0) THEN
927  m3jc=mesys(imesys,0)
928 
929 C...Identify recoiling partner and set up three-body kinematics.
930  irp=mesys(imesys,1)
931  IF(irp.EQ.i) irp=mesys(imesys,2)
932  IF(irp.EQ.ir) irp=irnew
933  DO 430 j=1,4
934  psum(j)=p(inew,j)+p(irp,j)+p(ignew,j)
935  430 CONTINUE
936  psum(5)=sqrt(max(0d0,psum(4)**2-psum(1)**2-psum(2)**2-
937  & psum(3)**2))
938  x1=2d0*(psum(4)*p(inew,4)-psum(1)*p(inew,1)-psum(2)*p(inew,2)-
939  & psum(3)*p(inew,3))/psum(5)**2
940  x2=2d0*(psum(4)*p(irp,4)-psum(1)*p(irp,1)-psum(2)*p(irp,2)-
941  & psum(3)*p(irp,3))/psum(5)**2
942  x3=2d0-x1-x2
943  r1me=p(inew,5)/psum(5)
944  r2me=p(irp,5)/psum(5)
945 
946 C...Matrix elements for gluon emission.
947  IF(m3jc.LT.100) THEN
948 
949 C...Call ME, with right order important for two inequivalent showerers.
950  IF(mesys(imesys,iord).EQ.i) THEN
951  wme=pymael(m3jc,x1,x2,r1me,r2me,alpha)
952  ELSE
953  wme=pymael(m3jc,x2,x1,r2me,r1me,alpha)
954  ENDIF
955 
956 C...Split up total ME when two radiating partons.
957  isprad=1
958  IF((m3jc.GE.16.AND.m3jc.LE.19).OR.(m3jc.GE.26.AND.m3jc.LE.29)
959  & .OR.(m3jc.GE.36.AND.m3jc.LE.39).OR.(m3jc.GE.46.AND.m3jc.LE.49)
960  & .OR.(m3jc.GE.56.AND.m3jc.LE.64)) isprad=0
961  IF(isprad.EQ.1) wme=wme*max(1d-10,1d0+r1me**2-r2me**2-x1)/
962  & max(1d-10,2d0-x1-x2)
963 
964 C...Evaluate shower rate.
965  wps=2d0/(max(1d-10,2d0-x1-x2)*
966  & max(1d-10,1d0+r2me**2-r1me**2-x2))
967  IF(iglui.EQ.1) wps=(9d0/4d0)*wps
968 
969 C...Matrix elements for photon emission: still rather primitive.
970  ELSE
971 
972 C...For generic charge combination currently only massless expression.
973  IF(m3jc.EQ.101) THEN
974  chg1=kchg(pycomp(k(i,2)),1)*isign(1,k(i,2))/3d0
975  chg2=kchg(pycomp(k(irp,2)),1)*isign(1,k(irp,2))/3d0
976  wme=(chg1*(1d0-x1)/x3-chg2*(1d0-x2)/x3)**2*(x1**2+x2**2)
977  wps=2d0*(chg1**2*(1d0-x1)/x3+chg2**2*(1d0-x2)/x3)
978 
979 C...For flavour neutral system assume vector source and include masses.
980  ELSE
981  wme=pymael(11,x1,x2,r1me,r2me,0d0)*max(1d-10,
982  & 1d0+r1me**2-r2me**2-x1)/max(1d-10,2d0-x1-x2)
983  wps=2d0/(max(1d-10,2d0-x1-x2)*
984  & max(1d-10,1d0+r2me**2-r1me**2-x2))
985  ENDIF
986  ENDIF
987 
988 C...Perform weighting with W_ME/W_PS.
989  IF(wme.LT.pyr(0)*wps) THEN
990  n=n-3
991  iflg(imx)=0
992  goto 290
993  ENDIF
994  ENDIF
995 
996 C...Now for sure accepted branching. Save highest pT.
997  IF(ngen.EQ.1) ptgen=sqrt(pt2)
998 
999 C...Update status for obsolete ones. Bookkkep the moved original parton
1000 C...and new daughter (arbitrary choice for g->gg or g->qqbar).
1001 C...Do not bookkeep radiated photon, since it cannot radiate further.
1002  k(i,1)=k(i,1)+10
1003  k(ir,1)=k(ir,1)+10
1004  DO 440 ip=1,npart
1005  IF(ipart(ip).EQ.i) ipart(ip)=inew
1006  IF(ipart(ip).EQ.ir) ipart(ip)=irnew
1007  440 CONTINUE
1008  IF(kcha.EQ.0) THEN
1009  npart=npart+1
1010  ipart(npart)=ignew
1011  ENDIF
1012 
1013 C...Initialize colour flow of branching.
1014 C...Use both old and new style colour tags for flexibility.
1015  k(inew,4)=0
1016  k(ignew,4)=0
1017  k(inew,5)=0
1018  k(ignew,5)=0
1019  jcolp=4+(1-kcol)/2
1020  jcoln=9-jcolp
1021  mct(inew,1)=0
1022  mct(inew,2)=0
1023  mct(ignew,1)=0
1024  mct(ignew,2)=0
1025  mct(irnew,1)=0
1026  mct(irnew,2)=0
1027 
1028 C...Trivial colour flow for l->lgamma and q->qgamma.
1029  IF(iabs(kcha).EQ.3) THEN
1030  k(i,4)=inew
1031  k(i,5)=ignew
1032  ELSEIF(kcha.NE.0) THEN
1033  IF(k(i,4).NE.0) THEN
1034  k(i,4)=k(i,4)+inew
1035  k(inew,4)=mstu(5)*i
1036  mct(inew,1)=mct(i,1)
1037  ENDIF
1038  IF(k(i,5).NE.0) THEN
1039  k(i,5)=k(i,5)+inew
1040  k(inew,5)=mstu(5)*i
1041  mct(inew,2)=mct(i,2)
1042  ENDIF
1043 
1044 C...Set colour flow for q->qg and g->gg.
1045  ELSEIF(kfq.EQ.0) THEN
1046  k(i,jcolp)=k(i,jcolp)+ignew
1047  k(ignew,jcolp)=mstu(5)*i
1048  k(inew,jcolp)=mstu(5)*ignew
1049  k(ignew,jcoln)=mstu(5)*inew
1050  mct(ignew,jcolp-3)=mct(i,jcolp-3)
1051  nct=nct+1
1052  mct(inew,jcolp-3)=nct
1053  mct(ignew,jcoln-3)=nct
1054  IF(moct.GE.1) THEN
1055  k(i,jcoln)=k(i,jcoln)+inew
1056  k(inew,jcoln)=mstu(5)*i
1057  mct(inew,jcoln-3)=mct(i,jcoln-3)
1058  ENDIF
1059 
1060 C...Set colour flow for g->qqbar.
1061  ELSE
1062  k(i,jcoln)=k(i,jcoln)+inew
1063  k(inew,jcoln)=mstu(5)*i
1064  k(i,jcolp)=k(i,jcolp)+ignew
1065  k(ignew,jcolp)=mstu(5)*i
1066  mct(inew,jcoln-3)=mct(i,jcoln-3)
1067  mct(ignew,jcolp-3)=mct(i,jcolp-3)
1068  ENDIF
1069 
1070 C...Daughter info for colourless recoiling parton.
1071  IF(k(ir,4).EQ.0.AND.k(ir,5).EQ.0) THEN
1072  k(ir,4)=irnew
1073  k(ir,5)=irnew
1074  k(irnew,4)=0
1075  k(irnew,5)=0
1076 
1077 C...Colour of recoiling parton sails through unchanged.
1078  ELSE
1079  IF(k(ir,4).NE.0) THEN
1080  k(ir,4)=k(ir,4)+irnew
1081  k(irnew,4)=mstu(5)*ir
1082  mct(irnew,1)=mct(ir,1)
1083  ENDIF
1084  IF(k(ir,5).NE.0) THEN
1085  k(ir,5)=k(ir,5)+irnew
1086  k(irnew,5)=mstu(5)*ir
1087  mct(irnew,2)=mct(ir,2)
1088  ENDIF
1089  ENDIF
1090 
1091 C...Vertex information trivial.
1092  DO 450 j=1,5
1093  v(inew,j)=v(i,j)
1094  v(ignew,j)=v(i,j)
1095  v(irnew,j)=v(ir,j)
1096  450 CONTINUE
1097 
1098 C...Update list of old radiators.
1099  DO 460 ievol=1,nevol
1100  IF(ipos(ievol).EQ.i.AND.irec(ievol).EQ.ir) THEN
1101  ipos(ievol)=inew
1102  IF(kcol.NE.0.AND.iscol(ievol).EQ.kcol) ipos(ievol)=ignew
1103  irec(ievol)=irnew
1104  iflg(ievol)=0
1105  ELSEIF(ipos(ievol).EQ.i) THEN
1106  ipos(ievol)=inew
1107  iflg(ievol)=0
1108  ELSEIF(ipos(ievol).EQ.ir.AND.irec(ievol).EQ.i) THEN
1109  ipos(ievol)=irnew
1110  irec(ievol)=inew
1111  IF(kcol.NE.0.AND.iscol(ievol).NE.kcol) irec(ievol)=ignew
1112  iflg(ievol)=0
1113  ELSEIF(ipos(ievol).EQ.ir) THEN
1114  ipos(ievol)=irnew
1115  iflg(ievol)=0
1116  ENDIF
1117 C...Update links of old connected partons.
1118  IF(irec(ievol).EQ.i) THEN
1119  irec(ievol)=inew
1120  iflg(ievol)=0
1121  ELSEIF(irec(ievol).EQ.ir) THEN
1122  irec(ievol)=irnew
1123  iflg(ievol)=0
1124  ENDIF
1125  460 CONTINUE
1126 
1127 C...q->qg or g->gg: create new gluon radiators.
1128  IF(kcol.NE.0.AND.kfq.EQ.0) THEN
1129  nevol=nevol+1
1130  ipos(nevol)=inew
1131  irec(nevol)=ignew
1132  iflg(nevol)=0
1133  iscol(nevol)=kcol
1134  ischg(nevol)=0
1135  ptsca(nevol)=sqrt(pt2)
1136  nevol=nevol+1
1137  ipos(nevol)=ignew
1138  irec(nevol)=inew
1139  iflg(nevol)=0
1140  iscol(nevol)=-kcol
1141  ischg(nevol)=0
1142  ptsca(nevol)=ptsca(nevol-1)
1143  ENDIF
1144 
1145 C...Update matrix elements parton list and add new for g/gamma->qqbar.
1146  DO 470 ime=1,nmesys
1147  IF(mesys(ime,1).EQ.i) mesys(ime,1)=inew
1148  IF(mesys(ime,2).EQ.i) mesys(ime,2)=inew
1149  IF(mesys(ime,1).EQ.ir) mesys(ime,1)=irnew
1150  IF(mesys(ime,2).EQ.ir) mesys(ime,2)=irnew
1151  470 CONTINUE
1152  IF(kfq.NE.0) THEN
1153  nmesys=nmesys+1
1154  mesys(nmesys,0)=66
1155  mesys(nmesys,1)=inew
1156  mesys(nmesys,2)=ignew
1157  nmesys=nmesys+1
1158  mesys(nmesys,0)=102
1159  mesys(nmesys,1)=inew
1160  mesys(nmesys,2)=ignew
1161  ENDIF
1162 
1163 C...Global statistics.
1164  mint(353)=mint(353)+1
1165  vint(353)=vint(353)+ptcor
1166  IF (mint(353).EQ.1) vint(358)=ptcor
1167 
1168 C...Loopback for more emissions if enough space.
1169  pt2cmx=pt2
1170  IF(npart.LT.maxnur-1.AND.nevol.LT.2*maxnur-2.AND.
1171  &nmesys.LT.maxnur-2.AND.n.LT.mstu(4)-mstu(32)-5) THEN
1172  goto 280
1173  ELSE
1174  CALL pyerrm(11,'(PYPTFS:) no more memory left for shower')
1175  ENDIF
1176 
1177 C...Done.
1178  480 CONTINUE
1179 
1180  RETURN
1181  END