Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pyremn.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file pyremn.f
1 
2 C*********************************************************************
3 
4 C...PYREMN
5 C...Adds on target remnants (one or two from each side) and
6 C...includes primordial kT for hadron beams.
7 
8  SUBROUTINE pyremn(IPU1,IPU2)
9 
10 C...Double precision and integer declarations.
11  IMPLICIT DOUBLE PRECISION(a-h, o-z)
12  IMPLICIT INTEGER(i-n)
13  INTEGER pyk,pychge,pycomp
14 C...Commonblocks.
15  common/pyjets/n,npad,k(4000,5),p(4000,5),v(4000,5)
16  common/pydat1/mstu(200),paru(200),mstj(200),parj(200)
17  common/pydat2/kchg(500,4),pmas(500,4),parf(2000),vckm(4,4)
18  common/pypars/mstp(200),parp(200),msti(200),pari(200)
19  common/pyint1/mint(400),vint(400)
20  SAVE /pyjets/,/pydat1/,/pydat2/,/pypars/,/pyint1/
21 C...Local arrays.
22  dimension kflch(2),kflsp(2),chi(2),pms(0:6),is(2),isn(2),robo(5),
23  &psys(0:2,5),pmin(0:2),qold(4),qnew(4),dbe(3),psum(4)
24 
25 C...Find event type and remaining energy.
26  isub=mint(1)
27  ns=n
28  IF(mint(50).EQ.0.OR.mod(mstp(81),10).LE.0) THEN
29  vint(143)=1d0-vint(141)
30  vint(144)=1d0-vint(142)
31  ENDIF
32 
33 C...Define initial partons.
34  ntry=0
35  100 ntry=ntry+1
36  DO 130 jt=1,2
37  i=mint(83)+jt+2
38  IF(jt.EQ.1) ipu=ipu1
39  IF(jt.EQ.2) ipu=ipu2
40  k(i,1)=21
41  k(i,2)=k(ipu,2)
42  k(i,3)=i-2
43  pms(jt)=0d0
44  vint(156+jt)=0d0
45  vint(158+jt)=0d0
46  IF(mint(47).EQ.1) THEN
47  DO 110 j=1,5
48  p(i,j)=p(i-2,j)
49  110 CONTINUE
50  ELSEIF(isub.EQ.95) THEN
51  k(i,2)=21
52  ELSE
53  p(i,5)=p(ipu,5)
54 
55 C...No primordial kT, or chosen according to truncated Gaussian or
56 C...exponential, or (for photon) predetermined or power law.
57  120 IF(mint(40+jt).EQ.2.AND.mint(10+jt).NE.22) THEN
58  IF(mstp(91).LE.0) THEN
59  pt=0d0
60  ELSEIF(mstp(91).EQ.1) THEN
61  pt=parp(91)*sqrt(-log(pyr(0)))
62  ELSE
63  rpt1=pyr(0)
64  rpt2=pyr(0)
65  pt=-parp(92)*log(rpt1*rpt2)
66  ENDIF
67  IF(pt.GT.parp(93)) goto 120
68  ELSEIF(mint(106+jt).EQ.3) THEN
69  pta=sqrt(vint(282+jt))
70  ptb=0d0
71  IF(mstp(66).EQ.5.AND.mstp(93).EQ.1) THEN
72  ptb=parp(99)*sqrt(-log(pyr(0)))
73  ELSEIF(mstp(66).EQ.5.AND.mstp(93).EQ.2) THEN
74  rpt1=pyr(0)
75  rpt2=pyr(0)
76  ptb=-parp(99)*log(rpt1*rpt2)
77  ENDIF
78  IF(ptb.GT.parp(100)) goto 120
79  pt=sqrt(pta**2+ptb**2+2d0*pta*ptb*cos(paru(2)*pyr(0)))
80  pt=pt*0.8d0**mint(57)
81  IF(ntry.GT.10) pt=pt*0.8d0**(ntry-10)
82  ELSEIF(iabs(mint(14+jt)).LE.8.OR.mint(14+jt).EQ.21) THEN
83  IF(mstp(93).LE.0) THEN
84  pt=0d0
85  ELSEIF(mstp(93).EQ.1) THEN
86  pt=parp(99)*sqrt(-log(pyr(0)))
87  ELSEIF(mstp(93).EQ.2) THEN
88  rpt1=pyr(0)
89  rpt2=pyr(0)
90  pt=-parp(99)*log(rpt1*rpt2)
91  ELSEIF(mstp(93).EQ.3) THEN
92  ha=parp(99)**2
93  hb=parp(100)**2
94  pt=sqrt(max(0d0,ha*(ha+hb)/(ha+hb-pyr(0)*hb)-ha))
95  ELSE
96  ha=parp(99)**2
97  hb=parp(100)**2
98  IF(mstp(93).EQ.5) hb=min(vint(48),parp(100)**2)
99  pt=sqrt(max(0d0,ha*((ha+hb)/ha)**pyr(0)-ha))
100  ENDIF
101  IF(pt.GT.parp(100)) goto 120
102  ELSE
103  pt=0d0
104  ENDIF
105  vint(156+jt)=pt
106  phi=paru(2)*pyr(0)
107  p(i,1)=pt*cos(phi)
108  p(i,2)=pt*sin(phi)
109  pms(jt)=p(i,5)**2+p(i,1)**2+p(i,2)**2
110  ENDIF
111  130 CONTINUE
112  IF(mint(47).EQ.1) RETURN
113 
114 C...Kinematics construction for initial partons.
115  i1=mint(83)+3
116  i2=mint(83)+4
117  IF(isub.EQ.95) THEN
118  shs=0d0
119  shr=0d0
120  ELSE
121  shs=vint(141)*vint(142)*vint(2)+(p(i1,1)+p(i2,1))**2+
122  & (p(i1,2)+p(i2,2))**2
123  shr=sqrt(max(0d0,shs))
124  IF((shs-pms(1)-pms(2))**2-4d0*pms(1)*pms(2).LE.0d0) goto 100
125  p(i1,4)=0.5d0*(shr+(pms(1)-pms(2))/shr)
126  p(i1,3)=sqrt(max(0d0,p(i1,4)**2-pms(1)))
127  p(i2,4)=shr-p(i1,4)
128  p(i2,3)=-p(i1,3)
129 
130 C...Transform partons to overall CM-frame.
131  robo(3)=(p(i1,1)+p(i2,1))/shr
132  robo(4)=(p(i1,2)+p(i2,2))/shr
133  CALL pyrobo(i1,i2,0d0,0d0,-robo(3),-robo(4),0d0)
134  robo(2)=pyangl(p(i1,1),p(i1,2))
135  CALL pyrobo(i1,i2,0d0,-robo(2),0d0,0d0,0d0)
136  robo(1)=pyangl(p(i1,3),p(i1,1))
137  CALL pyrobo(i1,i2,-robo(1),0d0,0d0,0d0,0d0)
138  CALL pyrobo(i2+1,mint(52),0d0,-robo(2),0d0,0d0,0d0)
139  CALL pyrobo(i1,mint(52),robo(1),robo(2),robo(3),robo(4),0d0)
140  robo(5)=(vint(141)-vint(142))/(vint(141)+vint(142))
141  CALL pyrobo(i1,mint(52),0d0,0d0,0d0,0d0,robo(5))
142  ENDIF
143 
144 C...Optionally fix up x and Q2 definitions for leptoproduction.
145  idisxq=0
146  IF((mint(43).EQ.2.OR.mint(43).EQ.3).AND.((isub.EQ.10.AND.
147  &mstp(23).GE.1).OR.(isub.EQ.83.AND.mstp(23).GE.2))) idisxq=1
148  IF(idisxq.EQ.1) THEN
149 
150 C...Find where incoming and outgoing leptons/partons are sitting.
151  lesd=1
152  IF(mint(42).EQ.1) lesd=2
153  lpin=mint(83)+3-lesd
154  lein=mint(84)+lesd
155  lqin=mint(84)+3-lesd
156  leout=mint(84)+2+lesd
157  lqout=mint(84)+5-lesd
158  IF(k(lein,3).GT.lein) lein=k(lein,3)
159  IF(k(lqin,3).GT.lqin) lqin=k(lqin,3)
160  lscms=0
161  DO 140 i=mint(84)+5,n
162  IF(k(i,2).EQ.94) THEN
163  lscms=i
164  leout=i+lesd
165  lqout=i+3-lesd
166  ENDIF
167  140 CONTINUE
168  lqbg=ipu1
169  IF(lesd.EQ.1) lqbg=ipu2
170 
171 C...Calculate actual and wanted momentum transfer.
172  xnom=vint(43-lesd)
173  q2nom=-vint(45)
174  hpk=2d0*(p(lpin,4)*p(lein,4)-p(lpin,1)*p(lein,1)-
175  & p(lpin,2)*p(lein,2)-p(lpin,3)*p(lein,3))*
176  & (p(mint(83)+lesd,4)*vint(40+lesd)/p(lein,4))
177  hpt2=max(0d0,q2nom*(1d0-q2nom/(xnom*hpk)))
178  fac=sqrt(hpt2/(p(leout,1)**2+p(leout,2)**2))
179  p(n+1,1)=fac*p(leout,1)
180  p(n+1,2)=fac*p(leout,2)
181  p(n+1,3)=0.25d0*((hpk-q2nom/xnom)/p(lpin,4)-
182  & q2nom/(p(mint(83)+lesd,4)*vint(40+lesd)))*(-1)**(lesd+1)
183  p(n+1,4)=sqrt(p(leout,5)**2+p(n+1,1)**2+p(n+1,2)**2+
184  & p(n+1,3)**2)
185  DO 150 j=1,4
186  qold(j)=p(lein,j)-p(leout,j)
187  qnew(j)=p(lein,j)-p(n+1,j)
188  150 CONTINUE
189 
190 C...Boost outgoing electron and daughters.
191  IF(lscms.EQ.0) THEN
192  DO 160 j=1,4
193  p(leout,j)=p(n+1,j)
194  160 CONTINUE
195  ELSE
196  DO 170 j=1,3
197  p(n+2,j)=(p(n+1,j)-p(leout,j))/(p(n+1,4)+p(leout,4))
198  170 CONTINUE
199  pinv=2d0/(1d0+p(n+2,1)**2+p(n+2,2)**2+p(n+2,3)**2)
200  DO 180 j=1,3
201  dbe(j)=pinv*p(n+2,j)
202  180 CONTINUE
203  DO 200 i=lscms+1,n
204  iorig=i
205  190 iorig=k(iorig,3)
206  IF(iorig.GT.leout) goto 190
207  IF(i.EQ.leout.OR.iorig.EQ.leout)
208  & CALL pyrobo(i,i,0d0,0d0,dbe(1),dbe(2),dbe(3))
209  200 CONTINUE
210  ENDIF
211 
212 C...Copy shower initiator and all outgoing partons.
213  ncop=n+1
214  k(ncop,3)=lqbg
215  DO 210 j=1,5
216  p(ncop,j)=p(lqbg,j)
217  210 CONTINUE
218  DO 240 i=mint(84)+1,n
219  icop=0
220  IF(k(i,1).GT.10) goto 240
221  IF(i.EQ.lqbg.OR.i.EQ.lqout) THEN
222  icop=i
223  ELSE
224  iorig=i
225  220 iorig=k(iorig,3)
226  IF(iorig.EQ.lqbg.OR.iorig.EQ.lqout) THEN
227  icop=iorig
228  ELSEIF(iorig.GT.mint(84).AND.iorig.LE.n) THEN
229  goto 220
230  ENDIF
231  ENDIF
232  IF(icop.NE.0) THEN
233  ncop=ncop+1
234  k(ncop,3)=i
235  DO 230 j=1,5
236  p(ncop,j)=p(i,j)
237  230 CONTINUE
238  ENDIF
239  240 CONTINUE
240 
241 C...Calculate relative rescaling factors.
242  slc=3-2*lesd
243  plcsum=0d0
244  DO 250 i=n+2,ncop
245  plcsum=plcsum+(p(i,4)+slc*p(i,3))
246  250 CONTINUE
247  DO 260 i=n+2,ncop
248  v(i,1)=(p(i,4)+slc*p(i,3))/plcsum
249  260 CONTINUE
250 
251 C...Transfer extra three-momentum of current.
252  DO 280 i=n+2,ncop
253  DO 270 j=1,3
254  p(i,j)=p(i,j)+v(i,1)*(qnew(j)-qold(j))
255  270 CONTINUE
256  p(i,4)=sqrt(p(i,5)**2+p(i,1)**2+p(i,2)**2+p(i,3)**2)
257  280 CONTINUE
258 
259 C...Iterate change of initiator momentum to get energy right.
260  iter=0
261  290 iter=iter+1
262  peex=-p(n+1,4)-qnew(4)
263  pemv=-p(n+1,3)/p(n+1,4)
264  DO 300 i=n+2,ncop
265  peex=peex+p(i,4)
266  pemv=pemv+v(i,1)*p(i,3)/p(i,4)
267  300 CONTINUE
268  IF(abs(pemv).LT.1d-10) THEN
269  mint(51)=1
270  mint(57)=mint(57)+1
271  RETURN
272  ENDIF
273  pzch=-peex/pemv
274  p(n+1,3)=p(n+1,3)+pzch
275  p(n+1,4)=sqrt(p(n+1,5)**2+p(n+1,1)**2+p(n+1,2)**2+p(n+1,3)**2)
276  DO 310 i=n+2,ncop
277  p(i,3)=p(i,3)+v(i,1)*pzch
278  p(i,4)=sqrt(p(i,5)**2+p(i,1)**2+p(i,2)**2+p(i,3)**2)
279  310 CONTINUE
280  IF(iter.LT.10.AND.abs(peex).GT.1d-6*p(n+1,4)) goto 290
281 
282 C...Modify momenta in event record.
283  hbe=2d0*(p(n+1,4)+p(lqbg,4))*(p(n+1,3)-p(lqbg,3))/
284  & ((p(n+1,4)+p(lqbg,4))**2+(p(n+1,3)-p(lqbg,3))**2)
285  IF(abs(hbe).GE.1d0) THEN
286  mint(51)=1
287  mint(57)=mint(57)+1
288  RETURN
289  ENDIF
290  i=mint(83)+5-lesd
291  CALL pyrobo(i,i,0d0,0d0,0d0,0d0,hbe)
292  DO 330 i=n+1,ncop
293  icop=k(i,3)
294  DO 320 j=1,4
295  p(icop,j)=p(i,j)
296  320 CONTINUE
297  330 CONTINUE
298  ENDIF
299 
300 C...Check minimum invariant mass of remnant system(s).
301  psys(0,4)=p(i1,4)+p(i2,4)+0.5d0*vint(1)*(vint(151)+vint(152))
302  psys(0,3)=p(i1,3)+p(i2,3)+0.5d0*vint(1)*(vint(151)-vint(152))
303  pms(0)=max(0d0,psys(0,4)**2-psys(0,3)**2)
304  pmin(0)=sqrt(pms(0))
305  DO 340 jt=1,2
306  psys(jt,4)=0.5d0*vint(1)*vint(142+jt)
307  psys(jt,3)=psys(jt,4)*(-1)**(jt-1)
308  pmin(jt)=0d0
309  IF(mint(44+jt).EQ.1) goto 340
310  mint(105)=mint(102+jt)
311  mint(109)=mint(106+jt)
312  CALL pyspli(mint(10+jt),mint(12+jt),kflch(jt),kflsp(jt))
313  IF(mint(51).NE.0) THEN
314  mint(57)=mint(57)+1
315  RETURN
316  ENDIF
317  IF(kflch(jt).NE.0) pmin(jt)=pmin(jt)+pymass(kflch(jt))
318  IF(kflsp(jt).NE.0) pmin(jt)=pmin(jt)+pymass(kflsp(jt))
319  IF(kflch(jt)*kflsp(jt).NE.0) pmin(jt)=pmin(jt)+0.5d0*parp(111)
320  pmin(jt)=sqrt(pmin(jt)**2+p(mint(83)+jt+2,1)**2+
321  & p(mint(83)+jt+2,2)**2)
322  340 CONTINUE
323  IF(pmin(0)+pmin(1)+pmin(2).GT.vint(1).OR.(mint(45).GE.2.AND.
324  &pmin(1).GT.psys(1,4)).OR.(mint(46).GE.2.AND.pmin(2).GT.
325  &psys(2,4))) THEN
326  mint(51)=1
327  mint(57)=mint(57)+1
328  RETURN
329  ENDIF
330 
331 C...Loop over two remnants; skip if none there.
332  i=ns
333  DO 410 jt=1,2
334  isn(jt)=0
335  IF(mint(44+jt).EQ.1) goto 410
336  IF(jt.EQ.1) ipu=ipu1
337  IF(jt.EQ.2) ipu=ipu2
338 
339 C...Store first remnant parton.
340  i=i+1
341  is(jt)=i
342  isn(jt)=1
343  DO 350 j=1,5
344  k(i,j)=0
345  p(i,j)=0d0
346  v(i,j)=0d0
347  350 CONTINUE
348  k(i,1)=1
349  k(i,2)=kflsp(jt)
350  k(i,3)=mint(83)+jt
351  p(i,5)=pymass(k(i,2))
352 
353 C...First parton colour connections and kinematics.
354  kcol=kchg(pycomp(kflsp(jt)),2)
355  IF(kcol.EQ.2) THEN
356  k(i,1)=3
357  k(i,4)=mstu(5)*ipu+ipu
358  k(i,5)=mstu(5)*ipu+ipu
359  k(ipu,4)=mod(k(ipu,4),mstu(5))+mstu(5)*i
360  k(ipu,5)=mod(k(ipu,5),mstu(5))+mstu(5)*i
361  ELSEIF(kcol.NE.0) THEN
362  k(i,1)=3
363  kfls=(3-kcol*isign(1,kflsp(jt)))/2
364  k(i,kfls+3)=ipu
365  k(ipu,6-kfls)=mod(k(ipu,6-kfls),mstu(5))+mstu(5)*i
366  ENDIF
367  IF(kflch(jt).EQ.0) THEN
368  p(i,1)=-p(mint(83)+jt+2,1)
369  p(i,2)=-p(mint(83)+jt+2,2)
370  pms(jt)=p(i,5)**2+p(i,1)**2+p(i,2)**2
371  psys(jt,3)=sqrt(max(0d0,psys(jt,4)**2-pms(jt)))*(-1)**(jt-1)
372  p(i,3)=psys(jt,3)
373  p(i,4)=psys(jt,4)
374 
375 C...When extra remnant parton or hadron: store extra remnant.
376  ELSE
377  i=i+1
378  isn(jt)=2
379  DO 360 j=1,5
380  k(i,j)=0
381  p(i,j)=0d0
382  v(i,j)=0d0
383  360 CONTINUE
384  k(i,1)=1
385  k(i,2)=kflch(jt)
386  k(i,3)=mint(83)+jt
387  p(i,5)=pymass(k(i,2))
388 
389 C...Find parton colour connections of extra remnant.
390  kcol=kchg(pycomp(kflch(jt)),2)
391  IF(kcol.EQ.2) THEN
392  k(i,1)=3
393  k(i,4)=mstu(5)*ipu+ipu
394  k(i,5)=mstu(5)*ipu+ipu
395  k(ipu,4)=mod(k(ipu,4),mstu(5))+mstu(5)*i
396  k(ipu,5)=mod(k(ipu,5),mstu(5))+mstu(5)*i
397  ELSEIF(kcol.NE.0) THEN
398  k(i,1)=3
399  kfls=(3-kcol*isign(1,kflch(jt)))/2
400  k(i,kfls+3)=ipu
401  k(ipu,6-kfls)=mod(k(ipu,6-kfls),mstu(5))+mstu(5)*i
402  ENDIF
403 
404 C...Relative transverse momentum when two remnants.
405  loop=0
406  370 loop=loop+1
407  CALL pyptdi(1,p(i-1,1),p(i-1,2))
408  IF(iabs(mint(10+jt)).LT.20) THEN
409  p(i-1,1)=0d0
410  p(i-1,2)=0d0
411  ELSE
412  p(i-1,1)=p(i-1,1)-0.5d0*p(mint(83)+jt+2,1)
413  p(i-1,2)=p(i-1,2)-0.5d0*p(mint(83)+jt+2,2)
414  ENDIF
415  pms(jt+2)=p(i-1,5)**2+p(i-1,1)**2+p(i-1,2)**2
416  p(i,1)=-p(mint(83)+jt+2,1)-p(i-1,1)
417  p(i,2)=-p(mint(83)+jt+2,2)-p(i-1,2)
418  pms(jt+4)=p(i,5)**2+p(i,1)**2+p(i,2)**2
419 
420 C...Meson or baryon; photon as meson. For splitup below.
421  imb=1
422  IF(mod(mint(10+jt)/1000,10).NE.0) imb=2
423 
424 C***Relative distribution for electron into two electrons. Temporary!
425  IF(iabs(mint(10+jt)).LT.20.AND.mint(14+jt).EQ.-mint(10+jt))
426  & THEN
427  chi(jt)=pyr(0)
428 
429 C...Relative distribution of electron energy into electron plus parton.
430  ELSEIF(iabs(mint(10+jt)).LT.20) THEN
431  xhrd=vint(140+jt)
432  xe=vint(154+jt)
433  chi(jt)=(xe-xhrd)/(1d0-xhrd)
434 
435 C...Relative distribution of energy for particle into two jets.
436  ELSEIF(iabs(kflch(jt)).LE.10.OR.kflch(jt).EQ.21) THEN
437  chik=parp(92+2*imb)
438  IF(mstp(92).LE.1) THEN
439  IF(imb.EQ.1) chi(jt)=pyr(0)
440  IF(imb.EQ.2) chi(jt)=1d0-sqrt(pyr(0))
441  ELSEIF(mstp(92).EQ.2) THEN
442  chi(jt)=1d0-pyr(0)**(1d0/(1d0+chik))
443  ELSEIF(mstp(92).EQ.3) THEN
444  cut=2d0*0.3d0/vint(1)
445  380 chi(jt)=pyr(0)**2
446  IF((chi(jt)**2/(chi(jt)**2+cut**2))**0.25d0*
447  & (1d0-chi(jt))**chik.LT.pyr(0)) goto 380
448  ELSEIF(mstp(92).EQ.4) THEN
449  cut=2d0*0.3d0/vint(1)
450  cutr=(1d0+sqrt(1d0+cut**2))/cut
451  390 chir=cut*cutr**pyr(0)
452  chi(jt)=(chir**2-cut**2)/(2d0*chir)
453  IF((1d0-chi(jt))**chik.LT.pyr(0)) goto 390
454  ELSE
455  cut=2d0*0.3d0/vint(1)
456  cuta=cut**(1d0-parp(98))
457  cutb=(1d0+cut)**(1d0-parp(98))
458  400 chi(jt)=(cuta+pyr(0)*(cutb-cuta))**(1d0/(1d0-parp(98)))
459  IF(((chi(jt)+cut)**2/(2d0*(chi(jt)**2+cut**2)))**
460  & (0.5d0*parp(98))*(1d0-chi(jt))**chik.LT.pyr(0)) goto 400
461  ENDIF
462 
463 C...Relative distribution of energy for particle into jet plus particle.
464  ELSE
465  IF(mstp(94).LE.1) THEN
466  IF(imb.EQ.1) chi(jt)=pyr(0)
467  IF(imb.EQ.2) chi(jt)=1d0-sqrt(pyr(0))
468  IF(mod(kflch(jt)/1000,10).NE.0) chi(jt)=1d0-chi(jt)
469  ELSEIF(mstp(94).EQ.2) THEN
470  chi(jt)=1d0-pyr(0)**(1d0/(1d0+parp(93+2*imb)))
471  IF(mod(kflch(jt)/1000,10).NE.0) chi(jt)=1d0-chi(jt)
472  ELSEIF(mstp(94).EQ.3) THEN
473  CALL pyzdis(1,0,pms(jt+4),zz)
474  chi(jt)=zz
475  ELSE
476  CALL pyzdis(1000,0,pms(jt+4),zz)
477  chi(jt)=zz
478  ENDIF
479  ENDIF
480 
481 C...Construct total transverse mass; reject if too large.
482  chi(jt)=max(1d-8,min(1d0-1d-8,chi(jt)))
483  pms(jt)=pms(jt+4)/chi(jt)+pms(jt+2)/(1d0-chi(jt))
484  IF(pms(jt).GT.psys(jt,4)**2) THEN
485  IF(loop.LT.100) THEN
486  goto 370
487  ELSE
488  mint(51)=1
489  mint(57)=mint(57)+1
490  RETURN
491  ENDIF
492  ENDIF
493  psys(jt,3)=sqrt(max(0d0,psys(jt,4)**2-pms(jt)))*(-1)**(jt-1)
494  vint(158+jt)=chi(jt)
495 
496 C...Subdivide longitudinal momentum according to value selected above.
497  pw1=chi(jt)*(psys(jt,4)+abs(psys(jt,3)))
498  p(is(jt)+1,4)=0.5d0*(pw1+pms(jt+4)/pw1)
499  p(is(jt)+1,3)=0.5d0*(pw1-pms(jt+4)/pw1)*(-1)**(jt-1)
500  p(is(jt),4)=psys(jt,4)-p(is(jt)+1,4)
501  p(is(jt),3)=psys(jt,3)-p(is(jt)+1,3)
502  ENDIF
503  410 CONTINUE
504  n=i
505 
506 C...Check if longitudinal boosts needed - if so pick two systems.
507  pdev=abs(psys(0,4)+psys(1,4)+psys(2,4)-vint(1))+
508  &abs(psys(0,3)+psys(1,3)+psys(2,3))
509  IF(pdev.LE.1d-6*vint(1)) RETURN
510  IF(isn(1).EQ.0) THEN
511  ir=0
512  il=2
513  ELSEIF(isn(2).EQ.0) THEN
514  ir=1
515  il=0
516  ELSEIF(vint(143).GT.0.2d0.AND.vint(144).GT.0.2d0) THEN
517  ir=1
518  il=2
519  ELSEIF(vint(143).GT.0.2d0) THEN
520  ir=1
521  il=0
522  ELSEIF(vint(144).GT.0.2d0) THEN
523  ir=0
524  il=2
525  ELSEIF(pms(1)/psys(1,4)**2.GT.pms(2)/psys(2,4)**2) THEN
526  ir=1
527  il=0
528  ELSE
529  ir=0
530  il=2
531  ENDIF
532  ig=3-ir-il
533 
534 C...E+-pL wanted for system to be modified.
535  IF((ig.EQ.1.AND.isn(1).EQ.0).OR.(ig.EQ.2.AND.isn(2).EQ.0)) THEN
536  ppb=vint(1)
537  pnb=vint(1)
538  ELSE
539  ppb=vint(1)-(psys(ig,4)+psys(ig,3))
540  pnb=vint(1)-(psys(ig,4)-psys(ig,3))
541  ENDIF
542 
543 C...To keep x and Q2 in leptoproduction: do not count scattered lepton.
544  IF(idisxq.EQ.1.AND.ig.NE.0) THEN
545  ppb=ppb-(psys(0,4)+psys(0,3))
546  pnb=pnb-(psys(0,4)-psys(0,3))
547  DO 420 j=1,4
548  psys(0,j)=0d0
549  420 CONTINUE
550  DO 450 i=mint(84)+1,ns
551  IF(k(i,1).GT.10) goto 450
552  incl=0
553  iorig=i
554  430 IF(iorig.EQ.lqout.OR.iorig.EQ.lpin+2) incl=1
555  iorig=k(iorig,3)
556  IF(iorig.GT.lpin) goto 430
557  IF(incl.EQ.0) goto 450
558  DO 440 j=1,4
559  psys(0,j)=psys(0,j)+p(i,j)
560  440 CONTINUE
561  450 CONTINUE
562  pms(0)=max(0d0,psys(0,4)**2-psys(0,3)**2)
563  ppb=ppb+(psys(0,4)+psys(0,3))
564  pnb=pnb+(psys(0,4)-psys(0,3))
565  ENDIF
566 
567 C...Construct longitudinal boosts.
568  dpmtb=ppb*pnb
569  dpmtr=pms(ir)
570  dpmtl=pms(il)
571  dsqlam=sqrt(max(0d0,(dpmtb-dpmtr-dpmtl)**2-4d0*dpmtr*dpmtl))
572  IF(dsqlam.LE.1d-6*dpmtb) THEN
573  mint(51)=1
574  mint(57)=mint(57)+1
575  RETURN
576  ENDIF
577  dsqsgn=sign(1d0,psys(ir,3)*psys(il,4)-psys(il,3)*psys(ir,4))
578  drkr=(dpmtb+dpmtr-dpmtl+dsqlam*dsqsgn)/
579  &(2d0*(psys(ir,4)+psys(ir,3))*pnb)
580  drkl=(dpmtb+dpmtl-dpmtr+dsqlam*dsqsgn)/
581  &(2d0*(psys(il,4)-psys(il,3))*ppb)
582  dber=(drkr**2-1d0)/(drkr**2+1d0)
583  dbel=-(drkl**2-1d0)/(drkl**2+1d0)
584 
585 C...Perform longitudinal boosts.
586  IF(ir.EQ.1.AND.isn(1).EQ.1.AND.dber.LE.-0.99999999d0) THEN
587  p(is(1),3)=0d0
588  p(is(1),4)=sqrt(p(is(1),5)**2+p(is(1),1)**2+p(is(1),2)**2)
589  ELSEIF(ir.EQ.1) THEN
590  CALL pyrobo(is(1),is(1)+isn(1)-1,0d0,0d0,0d0,0d0,dber)
591  ELSEIF(idisxq.EQ.1) THEN
592  DO 470 i=i1,ns
593  incl=0
594  iorig=i
595  460 IF(iorig.EQ.lqout.OR.iorig.EQ.lpin+2) incl=1
596  iorig=k(iorig,3)
597  IF(iorig.GT.lpin) goto 460
598  IF(incl.EQ.1) CALL pyrobo(i,i,0d0,0d0,0d0,0d0,dber)
599  470 CONTINUE
600  ELSE
601  CALL pyrobo(i1,ns,0d0,0d0,0d0,0d0,dber)
602  ENDIF
603  IF(il.EQ.2.AND.isn(2).EQ.1.AND.dbel.GE.0.99999999d0) THEN
604  p(is(2),3)=0d0
605  p(is(2),4)=sqrt(p(is(2),5)**2+p(is(2),1)**2+p(is(2),2)**2)
606  ELSEIF(il.EQ.2) THEN
607  CALL pyrobo(is(2),is(2)+isn(2)-1,0d0,0d0,0d0,0d0,dbel)
608  ELSEIF(idisxq.EQ.1) THEN
609  DO 490 i=i1,ns
610  incl=0
611  iorig=i
612  480 IF(iorig.EQ.lqout.OR.iorig.EQ.lpin+2) incl=1
613  iorig=k(iorig,3)
614  IF(iorig.GT.lpin) goto 480
615  IF(incl.EQ.1) CALL pyrobo(i,i,0d0,0d0,0d0,0d0,dbel)
616  490 CONTINUE
617  ELSE
618  CALL pyrobo(i1,ns,0d0,0d0,0d0,0d0,dbel)
619  ENDIF
620 
621 C...Final check that energy-momentum conservation worked.
622  pesum=0d0
623  pzsum=0d0
624  DO 500 i=mint(84)+1,n
625  IF(k(i,1).GT.10) goto 500
626  pesum=pesum+p(i,4)
627  pzsum=pzsum+p(i,3)
628  500 CONTINUE
629  pdev=abs(pesum-vint(1))+abs(pzsum)
630  IF(pdev.GT.1d-4*vint(1)) THEN
631  mint(51)=1
632  mint(57)=mint(57)+1
633  RETURN
634  ENDIF
635 
636 C...Calculate rotation and boost from overall CM frame to
637 C...hadronic CM frame in leptoproduction.
638  mint(91)=0
639  IF(mint(82).EQ.1.AND.(mint(43).EQ.2.OR.mint(43).EQ.3)) THEN
640  mint(91)=1
641  lesd=1
642  IF(mint(42).EQ.1) lesd=2
643  lpin=mint(83)+3-lesd
644 
645 C...Sum upp momenta of everything not lepton or photon to define boost.
646  DO 510 j=1,4
647  psum(j)=0d0
648  510 CONTINUE
649  DO 530 i=1,n
650  IF(k(i,1).LE.0.OR.k(i,1).GT.10) goto 530
651  IF(iabs(k(i,2)).GE.11.AND.iabs(k(i,2)).LE.20) goto 530
652  IF(k(i,2).EQ.22) goto 530
653  DO 520 j=1,4
654  psum(j)=psum(j)+p(i,j)
655  520 CONTINUE
656  530 CONTINUE
657  vint(223)=-psum(1)/psum(4)
658  vint(224)=-psum(2)/psum(4)
659  vint(225)=-psum(3)/psum(4)
660 
661 C...Boost incoming hadron to hadronic CM frame to determine rotations.
662  k(n+1,1)=1
663  DO 540 j=1,5
664  p(n+1,j)=p(lpin,j)
665  v(n+1,j)=v(lpin,j)
666  540 CONTINUE
667  CALL pyrobo(n+1,n+1,0d0,0d0,vint(223),vint(224),vint(225))
668  vint(222)=-pyangl(p(n+1,1),p(n+1,2))
669  CALL pyrobo(n+1,n+1,0d0,vint(222),0d0,0d0,0d0)
670  IF(lesd.EQ.2) THEN
671  vint(221)=-pyangl(p(n+1,3),p(n+1,1))
672  ELSE
673  vint(221)=pyangl(-p(n+1,3),p(n+1,1))
674  ENDIF
675  ENDIF
676 
677  RETURN
678  END