forked from alisw/ampt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhipyset1.35.f
executable file
·15266 lines (14186 loc) · 552 KB
/
hipyset1.35.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
c.................... hipyset1.35.f
C
C
C
C Modified for HIJING program
c
c modification July 22, 1997 In pyremnn put an upper limit
c on the total pt kick the parton can accumulate via multiple
C scattering. Set the upper limit to be the sqrt(s)/2,
c this is fix cronin bug for Pb+Pb events at SPS energy.
c
C
C Last modification Oct. 1993 to comply with non-vax
C machines' compiler
C
C*********************************************************************
SUBROUTINE LU2ENT(IP,KF1,KF2,PECM)
C...Purpose: to store two partons/particles in their CM frame,
C...with the first along the +z axis.
COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
SAVE /LUJETS/
COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
SAVE /LUDAT1/
COMMON/LUDAT2/KCHG(500,3),PMAS(500,4),PARF(2000),VCKM(4,4)
SAVE /LUDAT2/
C...Standard checks.
MSTU(28)=0
IF(MSTU(12).GE.1) CALL LULIST(0)
IPA=MAX(1,IABS(IP))
IF(IPA.GT.MSTU(4)-1) CALL LUERRM(21,
&'(LU2ENT:) writing outside LUJETS memory')
KC1=LUCOMP(KF1)
KC2=LUCOMP(KF2)
IF(KC1.EQ.0.OR.KC2.EQ.0) CALL LUERRM(12,
&'(LU2ENT:) unknown flavour code')
C...Find masses. Reset K, P and V vectors.
PM1=0.
IF(MSTU(10).EQ.1) PM1=P(IPA,5)
IF(MSTU(10).GE.2) PM1=ULMASS(KF1)
PM2=0.
IF(MSTU(10).EQ.1) PM2=P(IPA+1,5)
IF(MSTU(10).GE.2) PM2=ULMASS(KF2)
DO 100 I=IPA,IPA+1
DO 100 J=1,5
K(I,J)=0
P(I,J)=0.
100 V(I,J)=0.
C...Check flavours.
KQ1=KCHG(KC1,2)*ISIGN(1,KF1)
KQ2=KCHG(KC2,2)*ISIGN(1,KF2)
IF(KQ1+KQ2.NE.0.AND.KQ1+KQ2.NE.4) CALL LUERRM(2,
&'(LU2ENT:) unphysical flavour combination')
K(IPA,2)=KF1
K(IPA+1,2)=KF2
C...Store partons/particles in K vectors for normal case.
IF(IP.GE.0) THEN
K(IPA,1)=1
IF(KQ1.NE.0.AND.KQ2.NE.0) K(IPA,1)=2
K(IPA+1,1)=1
C...Store partons in K vectors for parton shower evolution.
ELSE
IF(KQ1.EQ.0.OR.KQ2.EQ.0) CALL LUERRM(2,
& '(LU2ENT:) requested flavours can not develop parton shower')
K(IPA,1)=3
K(IPA+1,1)=3
K(IPA,4)=MSTU(5)*(IPA+1)
K(IPA,5)=K(IPA,4)
K(IPA+1,4)=MSTU(5)*IPA
K(IPA+1,5)=K(IPA+1,4)
ENDIF
C...Check kinematics and store partons/particles in P vectors.
IF(PECM.LE.PM1+PM2) CALL LUERRM(13,
&'(LU2ENT:) energy smaller than sum of masses')
PA=SQRT(MAX(0.,(PECM**2-PM1**2-PM2**2)**2-(2.*PM1*PM2)**2))/
&(2.*PECM)
P(IPA,3)=PA
P(IPA,4)=SQRT(PM1**2+PA**2)
P(IPA,5)=PM1
P(IPA+1,3)=-PA
P(IPA+1,4)=SQRT(PM2**2+PA**2)
P(IPA+1,5)=PM2
C...Set N. Optionally fragment/decay.
N=IPA+1
IF(IP.EQ.0) CALL LUEXEC
RETURN
END
C*********************************************************************
SUBROUTINE LUGIVE(CHIN)
C...Purpose: to set values of commonblock variables.
COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
SAVE /LUJETS/
COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
SAVE /LUDAT1/
COMMON/LUDAT2/KCHG(500,3),PMAS(500,4),PARF(2000),VCKM(4,4)
SAVE /LUDAT2/
COMMON/LUDAT3/MDCY(500,3),MDME(2000,2),BRAT(2000),KFDP(2000,5)
SAVE /LUDAT3/
COMMON/LUDAT4/CHAF(500)
CHARACTER CHAF*8
SAVE /LUDAT4/
CHARACTER CHIN*(*),CHFIX*104,CHBIT*104,CHOLD*8,CHNEW*8,
&CHNAM*4,CHVAR(17)*4,CHALP(2)*26,CHIND*8,CHINI*10,CHINR*16
DATA CHVAR/'N','K','P','V','MSTU','PARU','MSTJ','PARJ','KCHG',
&'PMAS','PARF','VCKM','MDCY','MDME','BRAT','KFDP','CHAF'/
DATA CHALP/'abcdefghijklmnopqrstuvwxyz',
&'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
C...Length of character variable. Subdivide it into instructions.
IF(MSTU(12).GE.1) CALL LULIST(0)
CHBIT=CHIN//' '
LBIT=101
100 LBIT=LBIT-1
IF(CHBIT(LBIT:LBIT).EQ.' ') GOTO 100
LTOT=0
DO 110 LCOM=1,LBIT
IF(CHBIT(LCOM:LCOM).EQ.' ') GOTO 110
LTOT=LTOT+1
CHFIX(LTOT:LTOT)=CHBIT(LCOM:LCOM)
110 CONTINUE
LLOW=0
120 LHIG=LLOW+1
130 LHIG=LHIG+1
IF(LHIG.LE.LTOT.AND.CHFIX(LHIG:LHIG).NE.';') GOTO 130
LBIT=LHIG-LLOW-1
CHBIT(1:LBIT)=CHFIX(LLOW+1:LHIG-1)
C...Identify commonblock variable.
LNAM=1
140 LNAM=LNAM+1
IF(CHBIT(LNAM:LNAM).NE.'('.AND.CHBIT(LNAM:LNAM).NE.'='.AND.
&LNAM.LE.4) GOTO 140
CHNAM=CHBIT(1:LNAM-1)//' '
DO 150 LCOM=1,LNAM-1
DO 150 LALP=1,26
150 IF(CHNAM(LCOM:LCOM).EQ.CHALP(1)(LALP:LALP)) CHNAM(LCOM:LCOM)=
&CHALP(2)(LALP:LALP)
IVAR=0
DO 160 IV=1,17
160 IF(CHNAM.EQ.CHVAR(IV)) IVAR=IV
IF(IVAR.EQ.0) THEN
CALL LUERRM(18,'(LUGIVE:) do not recognize variable '//CHNAM)
LLOW=LHIG
IF(LLOW.LT.LTOT) GOTO 120
RETURN
ENDIF
C...Identify any indices.
I=0
J=0
IF(CHBIT(LNAM:LNAM).EQ.'(') THEN
LIND=LNAM
170 LIND=LIND+1
IF(CHBIT(LIND:LIND).NE.')'.AND.CHBIT(LIND:LIND).NE.',') GOTO 170
CHIND=' '
IF((CHBIT(LNAM+1:LNAM+1).EQ.'C'.OR.CHBIT(LNAM+1:LNAM+1).EQ.'c').
& AND.(IVAR.EQ.9.OR.IVAR.EQ.10.OR.IVAR.EQ.13.OR.IVAR.EQ.17)) THEN
CHIND(LNAM-LIND+11:8)=CHBIT(LNAM+2:LIND-1)
READ(CHIND,'(I8)') I1
I=LUCOMP(I1)
ELSE
CHIND(LNAM-LIND+10:8)=CHBIT(LNAM+1:LIND-1)
READ(CHIND,'(I8)') I
ENDIF
LNAM=LIND
IF(CHBIT(LNAM:LNAM).EQ.')') LNAM=LNAM+1
ENDIF
IF(CHBIT(LNAM:LNAM).EQ.',') THEN
LIND=LNAM
180 LIND=LIND+1
IF(CHBIT(LIND:LIND).NE.')'.AND.CHBIT(LIND:LIND).NE.',') GOTO 180
CHIND=' '
CHIND(LNAM-LIND+10:8)=CHBIT(LNAM+1:LIND-1)
READ(CHIND,'(I8)') J
LNAM=LIND+1
ENDIF
C...Check that indices allowed and save old value.
IERR=1
IF(CHBIT(LNAM:LNAM).NE.'=') GOTO 190
IF(IVAR.EQ.1) THEN
IF(I.NE.0.OR.J.NE.0) GOTO 190
IOLD=N
ELSEIF(IVAR.EQ.2) THEN
IF(I.LT.1.OR.I.GT.MSTU(4).OR.J.LT.1.OR.J.GT.5) GOTO 190
IOLD=K(I,J)
ELSEIF(IVAR.EQ.3) THEN
IF(I.LT.1.OR.I.GT.MSTU(4).OR.J.LT.1.OR.J.GT.5) GOTO 190
ROLD=P(I,J)
ELSEIF(IVAR.EQ.4) THEN
IF(I.LT.1.OR.I.GT.MSTU(4).OR.J.LT.1.OR.J.GT.5) GOTO 190
ROLD=V(I,J)
ELSEIF(IVAR.EQ.5) THEN
IF(I.LT.1.OR.I.GT.200.OR.J.NE.0) GOTO 190
IOLD=MSTU(I)
ELSEIF(IVAR.EQ.6) THEN
IF(I.LT.1.OR.I.GT.200.OR.J.NE.0) GOTO 190
ROLD=PARU(I)
ELSEIF(IVAR.EQ.7) THEN
IF(I.LT.1.OR.I.GT.200.OR.J.NE.0) GOTO 190
IOLD=MSTJ(I)
ELSEIF(IVAR.EQ.8) THEN
IF(I.LT.1.OR.I.GT.200.OR.J.NE.0) GOTO 190
ROLD=PARJ(I)
ELSEIF(IVAR.EQ.9) THEN
IF(I.LT.1.OR.I.GT.MSTU(6).OR.J.LT.1.OR.J.GT.3) GOTO 190
IOLD=KCHG(I,J)
ELSEIF(IVAR.EQ.10) THEN
IF(I.LT.1.OR.I.GT.MSTU(6).OR.J.LT.1.OR.J.GT.4) GOTO 190
ROLD=PMAS(I,J)
ELSEIF(IVAR.EQ.11) THEN
IF(I.LT.1.OR.I.GT.2000.OR.J.NE.0) GOTO 190
ROLD=PARF(I)
ELSEIF(IVAR.EQ.12) THEN
IF(I.LT.1.OR.I.GT.4.OR.J.LT.1.OR.J.GT.4) GOTO 190
ROLD=VCKM(I,J)
ELSEIF(IVAR.EQ.13) THEN
IF(I.LT.1.OR.I.GT.MSTU(6).OR.J.LT.1.OR.J.GT.3) GOTO 190
IOLD=MDCY(I,J)
ELSEIF(IVAR.EQ.14) THEN
IF(I.LT.1.OR.I.GT.MSTU(7).OR.J.LT.1.OR.J.GT.2) GOTO 190
IOLD=MDME(I,J)
ELSEIF(IVAR.EQ.15) THEN
IF(I.LT.1.OR.I.GT.MSTU(7).OR.J.NE.0) GOTO 190
ROLD=BRAT(I)
ELSEIF(IVAR.EQ.16) THEN
IF(I.LT.1.OR.I.GT.MSTU(7).OR.J.LT.1.OR.J.GT.5) GOTO 190
IOLD=KFDP(I,J)
ELSEIF(IVAR.EQ.17) THEN
IF(I.LT.1.OR.I.GT.MSTU(6).OR.J.NE.0) GOTO 190
CHOLD=CHAF(I)
ENDIF
IERR=0
190 IF(IERR.EQ.1) THEN
CALL LUERRM(18,'(LUGIVE:) unallowed indices for '//
& CHBIT(1:LNAM-1))
LLOW=LHIG
IF(LLOW.LT.LTOT) GOTO 120
RETURN
ENDIF
C...Print current value of variable. Loop back.
IF(LNAM.GE.LBIT) THEN
CHBIT(LNAM:14)=' '
CHBIT(15:60)=' has the value '
IF(IVAR.EQ.1.OR.IVAR.EQ.2.OR.IVAR.EQ.5.OR.IVAR.EQ.7.OR.
& IVAR.EQ.9.OR.IVAR.EQ.13.OR.IVAR.EQ.14.OR.IVAR.EQ.16) THEN
WRITE(CHBIT(51:60),'(I10)') IOLD
ELSEIF(IVAR.NE.17) THEN
WRITE(CHBIT(47:60),'(F14.5)') ROLD
ELSE
CHBIT(53:60)=CHOLD
ENDIF
IF(MSTU(13).GE.1) WRITE(MSTU(11),1000) CHBIT(1:60)
LLOW=LHIG
IF(LLOW.LT.LTOT) GOTO 120
RETURN
ENDIF
C...Read in new variable value.
IF(IVAR.EQ.1.OR.IVAR.EQ.2.OR.IVAR.EQ.5.OR.IVAR.EQ.7.OR.
&IVAR.EQ.9.OR.IVAR.EQ.13.OR.IVAR.EQ.14.OR.IVAR.EQ.16) THEN
CHINI=' '
CHINI(LNAM-LBIT+11:10)=CHBIT(LNAM+1:LBIT)
READ(CHINI,'(I10)') INEW
ELSEIF(IVAR.NE.17) THEN
CHINR=' '
CHINR(LNAM-LBIT+17:16)=CHBIT(LNAM+1:LBIT)
READ(CHINR,'(F16.2)') RNEW
ELSE
CHNEW=CHBIT(LNAM+1:LBIT)//' '
ENDIF
C...Store new variable value.
IF(IVAR.EQ.1) THEN
N=INEW
ELSEIF(IVAR.EQ.2) THEN
K(I,J)=INEW
ELSEIF(IVAR.EQ.3) THEN
P(I,J)=RNEW
ELSEIF(IVAR.EQ.4) THEN
V(I,J)=RNEW
ELSEIF(IVAR.EQ.5) THEN
MSTU(I)=INEW
ELSEIF(IVAR.EQ.6) THEN
PARU(I)=RNEW
ELSEIF(IVAR.EQ.7) THEN
MSTJ(I)=INEW
ELSEIF(IVAR.EQ.8) THEN
PARJ(I)=RNEW
ELSEIF(IVAR.EQ.9) THEN
KCHG(I,J)=INEW
ELSEIF(IVAR.EQ.10) THEN
PMAS(I,J)=RNEW
ELSEIF(IVAR.EQ.11) THEN
PARF(I)=RNEW
ELSEIF(IVAR.EQ.12) THEN
VCKM(I,J)=RNEW
ELSEIF(IVAR.EQ.13) THEN
MDCY(I,J)=INEW
ELSEIF(IVAR.EQ.14) THEN
MDME(I,J)=INEW
ELSEIF(IVAR.EQ.15) THEN
BRAT(I)=RNEW
ELSEIF(IVAR.EQ.16) THEN
KFDP(I,J)=INEW
ELSEIF(IVAR.EQ.17) THEN
CHAF(I)=CHNEW
ENDIF
C...Write old and new value. Loop back.
CHBIT(LNAM:14)=' '
CHBIT(15:60)=' changed from to '
IF(IVAR.EQ.1.OR.IVAR.EQ.2.OR.IVAR.EQ.5.OR.IVAR.EQ.7.OR.
&IVAR.EQ.9.OR.IVAR.EQ.13.OR.IVAR.EQ.14.OR.IVAR.EQ.16) THEN
WRITE(CHBIT(33:42),'(I10)') IOLD
WRITE(CHBIT(51:60),'(I10)') INEW
ELSEIF(IVAR.NE.17) THEN
WRITE(CHBIT(29:42),'(F14.5)') ROLD
WRITE(CHBIT(47:60),'(F14.5)') RNEW
ELSE
CHBIT(35:42)=CHOLD
CHBIT(53:60)=CHNEW
ENDIF
IF(MSTU(13).GE.1) WRITE(MSTU(11),1000) CHBIT(1:60)
LLOW=LHIG
IF(LLOW.LT.LTOT) GOTO 120
C...Format statement for output on unit MSTU(11) (by default 6).
1000 FORMAT(5X,A60)
RETURN
END
C*********************************************************************
SUBROUTINE LUEXEC
C...Purpose: to administrate the fragmentation and decay chain.
COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
SAVE /LUJETS/
COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
SAVE /LUDAT1/
COMMON/LUDAT2/KCHG(500,3),PMAS(500,4),PARF(2000),VCKM(4,4)
SAVE /LUDAT2/
COMMON/LUDAT3/MDCY(500,3),MDME(2000,2),BRAT(2000),KFDP(2000,5)
SAVE /LUDAT3/
DIMENSION PS(2,6)
C...Initialize and reset.
MSTU(24)=0
IF(MSTU(12).GE.1) CALL LULIST(0)
MSTU(31)=MSTU(31)+1
MSTU(1)=0
MSTU(2)=0
MSTU(3)=0
MCONS=1
C...Sum up momentum, energy and charge for starting entries.
NSAV=N
DO 100 I=1,2
DO 100 J=1,6
100 PS(I,J)=0.
DO 120 I=1,N
IF(K(I,1).LE.0.OR.K(I,1).GT.10) GOTO 120
DO 110 J=1,4
110 PS(1,J)=PS(1,J)+P(I,J)
PS(1,6)=PS(1,6)+LUCHGE(K(I,2))
120 CONTINUE
PARU(21)=PS(1,4)
C...Prepare system for subsequent fragmentation/decay.
CALL LUPREP(0)
C...Loop through jet fragmentation and particle decays.
MBE=0
130 MBE=MBE+1
IP=0
140 IP=IP+1
KC=0
IF(K(IP,1).GT.0.AND.K(IP,1).LE.10) KC=LUCOMP(K(IP,2))
IF(KC.EQ.0) THEN
C...Particle decay if unstable and allowed. Save long-lived particle
C...decays until second pass after Bose-Einstein effects.
ELSEIF(KCHG(KC,2).EQ.0) THEN
clin-4/2008 break up compound IF statements:
c IF(MSTJ(21).GE.1.AND.MDCY(KC,1).GE.1.AND.(MSTJ(51).LE.0.OR.MBE.
c & EQ.2.OR.PMAS(KC,2).GE.PARJ(91).OR.IABS(K(IP,2)).EQ.311))
c & CALL LUDECY(IP)
if(MSTJ(21).GE.1.AND.MDCY(KC,1).GE.1) then
if(MSTJ(51).LE.0.OR.MBE.EQ.2.OR.PMAS(KC,2).GE.PARJ(91)
& .OR.IABS(K(IP,2)).EQ.311)
& CALL LUDECY(IP)
endif
c
C...Decay products may develop a shower.
IF(MSTJ(92).GT.0) THEN
IP1=MSTJ(92)
QMAX=SQRT(MAX(0.,(P(IP1,4)+P(IP1+1,4))**2-(P(IP1,1)+P(IP1+1,
& 1))**2-(P(IP1,2)+P(IP1+1,2))**2-(P(IP1,3)+P(IP1+1,3))**2))
CALL LUSHOW(IP1,IP1+1,QMAX)
CALL LUPREP(IP1)
MSTJ(92)=0
ELSEIF(MSTJ(92).LT.0) THEN
IP1=-MSTJ(92)
clin-8/19/02 avoid actual argument in common blocks of LUSHOW:
c CALL LUSHOW(IP1,-3,P(IP,5))
pip5=P(IP,5)
CALL LUSHOW(IP1,-3,pip5)
CALL LUPREP(IP1)
MSTJ(92)=0
ENDIF
C...Jet fragmentation: string or independent fragmentation.
ELSEIF(K(IP,1).EQ.1.OR.K(IP,1).EQ.2) THEN
MFRAG=MSTJ(1)
IF(MFRAG.GE.1.AND.K(IP,1).EQ.1) MFRAG=2
IF(MSTJ(21).GE.2.AND.K(IP,1).EQ.2.AND.N.GT.IP) THEN
IF(K(IP+1,1).EQ.1.AND.K(IP+1,3).EQ.K(IP,3).AND.
& K(IP,3).GT.0.AND.K(IP,3).LT.IP) THEN
IF(KCHG(LUCOMP(K(K(IP,3),2)),2).EQ.0) MFRAG=MIN(1,MFRAG)
ENDIF
ENDIF
IF(MFRAG.EQ.1) then
CALL LUSTRF(IP)
endif
IF(MFRAG.EQ.2) CALL LUINDF(IP)
IF(MFRAG.EQ.2.AND.K(IP,1).EQ.1) MCONS=0
IF(MFRAG.EQ.2.AND.(MSTJ(3).LE.0.OR.MOD(MSTJ(3),5).EQ.0)) MCONS=0
ENDIF
C...Loop back if enough space left in LUJETS and no error abort.
IF(MSTU(24).NE.0.AND.MSTU(21).GE.2) THEN
ELSEIF(IP.LT.N.AND.N.LT.MSTU(4)-20-MSTU(32)) THEN
GOTO 140
ELSEIF(IP.LT.N) THEN
CALL LUERRM(11,'(LUEXEC:) no more memory left in LUJETS')
ENDIF
C...Include simple Bose-Einstein effect parametrization if desired.
IF(MBE.EQ.1.AND.MSTJ(51).GE.1) THEN
CALL LUBOEI(NSAV)
GOTO 130
ENDIF
C...Check that momentum, energy and charge were conserved.
DO 160 I=1,N
IF(K(I,1).LE.0.OR.K(I,1).GT.10) GOTO 160
DO 150 J=1,4
150 PS(2,J)=PS(2,J)+P(I,J)
PS(2,6)=PS(2,6)+LUCHGE(K(I,2))
160 CONTINUE
PDEV=(ABS(PS(2,1)-PS(1,1))+ABS(PS(2,2)-PS(1,2))+ABS(PS(2,3)-
&PS(1,3))+ABS(PS(2,4)-PS(1,4)))/(1.+ABS(PS(2,4))+ABS(PS(1,4)))
IF(MCONS.EQ.1.AND.PDEV.GT.PARU(11)) CALL LUERRM(15,
&'(LUEXEC:) four-momentum was not conserved')
c IF(MCONS.EQ.1.AND.PDEV.GT.PARU(11)) then
c CALL LUERRM(15,
c &'(LUEXEC:) four-momentum was not conserved')
c write(6,*) 'PS1,2=',PS(1,1),PS(1,2),PS(1,3),PS(1,4),
c 1 '*',PS(2,1),PS(2,2),PS(2,3),PS(2,4)
c endif
IF(MCONS.EQ.1.AND.ABS(PS(2,6)-PS(1,6)).GT.0.1) CALL LUERRM(15,
&'(LUEXEC:) charge was not conserved')
RETURN
END
C*********************************************************************
SUBROUTINE LUPREP(IP)
C...Purpose: to rearrange partons along strings, to allow small systems
C...to collapse into one or two particles and to check flavours.
IMPLICIT DOUBLE PRECISION(D)
COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
SAVE /LUJETS/
COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
SAVE /LUDAT1/
COMMON/LUDAT2/KCHG(500,3),PMAS(500,4),PARF(2000),VCKM(4,4)
SAVE /LUDAT2/
COMMON/LUDAT3/MDCY(500,3),MDME(2000,2),BRAT(2000),KFDP(2000,5)
SAVE /LUDAT3/
DIMENSION DPS(5),DPC(5),UE(3)
C...Rearrange parton shower product listing along strings: begin loop.
I1=N
DO 130 MQGST=1,2
DO 120 I=MAX(1,IP),N
IF(K(I,1).NE.3) GOTO 120
KC=LUCOMP(K(I,2))
IF(KC.EQ.0) GOTO 120
KQ=KCHG(KC,2)
IF(KQ.EQ.0.OR.(MQGST.EQ.1.AND.KQ.EQ.2)) GOTO 120
C...Pick up loose string end.
KCS=4
IF(KQ*ISIGN(1,K(I,2)).LT.0) KCS=5
IA=I
NSTP=0
100 NSTP=NSTP+1
IF(NSTP.GT.4*N) THEN
CALL LUERRM(14,'(LUPREP:) caught in infinite loop')
RETURN
ENDIF
C...Copy undecayed parton.
IF(K(IA,1).EQ.3) THEN
IF(I1.GE.MSTU(4)-MSTU(32)-5) THEN
CALL LUERRM(11,'(LUPREP:) no more memory left in LUJETS')
RETURN
ENDIF
I1=I1+1
K(I1,1)=2
IF(NSTP.GE.2.AND.IABS(K(IA,2)).NE.21) K(I1,1)=1
K(I1,2)=K(IA,2)
K(I1,3)=IA
K(I1,4)=0
K(I1,5)=0
DO 110 J=1,5
P(I1,J)=P(IA,J)
110 V(I1,J)=V(IA,J)
K(IA,1)=K(IA,1)+10
IF(K(I1,1).EQ.1) GOTO 120
ENDIF
C...Go to next parton in colour space.
IB=IA
IF(MOD(K(IB,KCS)/MSTU(5)**2,2).EQ.0.AND.MOD(K(IB,KCS),MSTU(5)).
&NE.0) THEN
IA=MOD(K(IB,KCS),MSTU(5))
K(IB,KCS)=K(IB,KCS)+MSTU(5)**2
MREV=0
ELSE
IF(K(IB,KCS).GE.2*MSTU(5)**2.OR.MOD(K(IB,KCS)/MSTU(5),MSTU(5)).
& EQ.0) KCS=9-KCS
IA=MOD(K(IB,KCS)/MSTU(5),MSTU(5))
K(IB,KCS)=K(IB,KCS)+2*MSTU(5)**2
MREV=1
ENDIF
IF(IA.LE.0.OR.IA.GT.N) THEN
CALL LUERRM(12,'(LUPREP:) colour rearrangement failed')
RETURN
ENDIF
IF(MOD(K(IA,4)/MSTU(5),MSTU(5)).EQ.IB.OR.MOD(K(IA,5)/MSTU(5),
&MSTU(5)).EQ.IB) THEN
IF(MREV.EQ.1) KCS=9-KCS
IF(MOD(K(IA,KCS)/MSTU(5),MSTU(5)).NE.IB) KCS=9-KCS
K(IA,KCS)=K(IA,KCS)+2*MSTU(5)**2
ELSE
IF(MREV.EQ.0) KCS=9-KCS
IF(MOD(K(IA,KCS),MSTU(5)).NE.IB) KCS=9-KCS
K(IA,KCS)=K(IA,KCS)+MSTU(5)**2
ENDIF
IF(IA.NE.I) GOTO 100
K(I1,1)=1
120 CONTINUE
130 CONTINUE
N=I1
C...Find lowest-mass colour singlet jet system, OK if above thresh.
IF(MSTJ(14).LE.0) GOTO 320
NS=N
140 NSIN=N-NS
PDM=1.+PARJ(32)
IC=0
DO 190 I=MAX(1,IP),NS
IF(K(I,1).NE.1.AND.K(I,1).NE.2) THEN
ELSEIF(K(I,1).EQ.2.AND.IC.EQ.0) THEN
NSIN=NSIN+1
IC=I
DO 150 J=1,4
150 DPS(J)=dble(P(I,J))
MSTJ(93)=1
DPS(5)=dble(ULMASS(K(I,2)))
ELSEIF(K(I,1).EQ.2) THEN
DO 160 J=1,4
160 DPS(J)=DPS(J)+dble(P(I,J))
ELSEIF(IC.NE.0.AND.KCHG(LUCOMP(K(I,2)),2).NE.0) THEN
DO 170 J=1,4
170 DPS(J)=DPS(J)+dble(P(I,J))
MSTJ(93)=1
DPS(5)=DPS(5)+dble(ULMASS(K(I,2)))
PD=sngl(SQRT(MAX(0D0,DPS(4)**2
1 -DPS(1)**2-DPS(2)**2-DPS(3)**2))-DPS(5))
IF(PD.LT.PDM) THEN
PDM=PD
DO 180 J=1,5
180 DPC(J)=DPS(J)
IC1=IC
IC2=I
ENDIF
IC=0
ELSE
NSIN=NSIN+1
ENDIF
190 CONTINUE
IF(PDM.GE.PARJ(32)) GOTO 320
C...Fill small-mass system as cluster.
NSAV=N
PECM=sngl(SQRT(MAX(0D0,DPC(4)**2-DPC(1)**2-DPC(2)**2-DPC(3)**2)))
K(N+1,1)=11
K(N+1,2)=91
K(N+1,3)=IC1
K(N+1,4)=N+2
K(N+1,5)=N+3
P(N+1,1)=sngl(DPC(1))
P(N+1,2)=sngl(DPC(2))
P(N+1,3)=sngl(DPC(3))
P(N+1,4)=sngl(DPC(4))
P(N+1,5)=PECM
C...Form two particles from flavours of lowest-mass system, if feasible.
K(N+2,1)=1
K(N+3,1)=1
IF(MSTU(16).NE.2) THEN
K(N+2,3)=N+1
K(N+3,3)=N+1
ELSE
K(N+2,3)=IC1
K(N+3,3)=IC2
ENDIF
K(N+2,4)=0
K(N+3,4)=0
K(N+2,5)=0
K(N+3,5)=0
IF(IABS(K(IC1,2)).NE.21) THEN
KC1=LUCOMP(K(IC1,2))
KC2=LUCOMP(K(IC2,2))
IF(KC1.EQ.0.OR.KC2.EQ.0) GOTO 320
KQ1=KCHG(KC1,2)*ISIGN(1,K(IC1,2))
KQ2=KCHG(KC2,2)*ISIGN(1,K(IC2,2))
IF(KQ1+KQ2.NE.0) GOTO 320
200 CALL LUKFDI(K(IC1,2),0,KFLN,K(N+2,2))
CALL LUKFDI(K(IC2,2),-KFLN,KFLDMP,K(N+3,2))
IF(K(N+2,2).EQ.0.OR.K(N+3,2).EQ.0) GOTO 200
ELSE
IF(IABS(K(IC2,2)).NE.21) GOTO 320
210 CALL LUKFDI(1+INT((2.+PARJ(2))*RLU(0)),0,KFLN,KFDMP)
CALL LUKFDI(KFLN,0,KFLM,K(N+2,2))
CALL LUKFDI(-KFLN,-KFLM,KFLDMP,K(N+3,2))
IF(K(N+2,2).EQ.0.OR.K(N+3,2).EQ.0) GOTO 210
ENDIF
P(N+2,5)=ULMASS(K(N+2,2))
P(N+3,5)=ULMASS(K(N+3,2))
IF(P(N+2,5)+P(N+3,5)+PARJ(64).GE.PECM.AND.NSIN.EQ.1) GOTO 320
IF(P(N+2,5)+P(N+3,5)+PARJ(64).GE.PECM) GOTO 260
C...Perform two-particle decay of jet system, if possible.
clin-5/2012:
c IF(PECM.GE.0.02d0*DPC(4)) THEN
IF(dble(PECM).GE.0.02d0*DPC(4)) THEN
PA=SQRT((PECM**2-(P(N+2,5)+P(N+3,5))**2)*(PECM**2-
& (P(N+2,5)-P(N+3,5))**2))/(2.*PECM)
UE(3)=2.*RLU(0)-1.
PHI=PARU(2)*RLU(0)
UE(1)=SQRT(1.-UE(3)**2)*COS(PHI)
UE(2)=SQRT(1.-UE(3)**2)*SIN(PHI)
DO 220 J=1,3
P(N+2,J)=PA*UE(J)
220 P(N+3,J)=-PA*UE(J)
P(N+2,4)=SQRT(PA**2+P(N+2,5)**2)
P(N+3,4)=SQRT(PA**2+P(N+3,5)**2)
CALL LUDBRB(N+2,N+3,0.,0.,DPC(1)/DPC(4),DPC(2)/DPC(4),
& DPC(3)/DPC(4))
ELSE
NP=0
DO 230 I=IC1,IC2
230 IF(K(I,1).EQ.1.OR.K(I,1).EQ.2) NP=NP+1
HA=P(IC1,4)*P(IC2,4)-P(IC1,1)*P(IC2,1)-P(IC1,2)*P(IC2,2)-
& P(IC1,3)*P(IC2,3)
IF(NP.GE.3.OR.HA.LE.1.25*P(IC1,5)*P(IC2,5)) GOTO 260
HD1=0.5*(P(N+2,5)**2-P(IC1,5)**2)
HD2=0.5*(P(N+3,5)**2-P(IC2,5)**2)
HR=SQRT(MAX(0.,((HA-HD1-HD2)**2-(P(N+2,5)*P(N+3,5))**2)/
& (HA**2-(P(IC1,5)*P(IC2,5))**2)))-1.
HC=P(IC1,5)**2+2.*HA+P(IC2,5)**2
HK1=((P(IC2,5)**2+HA)*HR+HD1-HD2)/HC
HK2=((P(IC1,5)**2+HA)*HR+HD2-HD1)/HC
DO 240 J=1,4
P(N+2,J)=(1.+HK1)*P(IC1,J)-HK2*P(IC2,J)
240 P(N+3,J)=(1.+HK2)*P(IC2,J)-HK1*P(IC1,J)
ENDIF
DO 250 J=1,4
V(N+1,J)=V(IC1,J)
V(N+2,J)=V(IC1,J)
250 V(N+3,J)=V(IC2,J)
V(N+1,5)=0.
V(N+2,5)=0.
V(N+3,5)=0.
N=N+3
GOTO 300
C...Else form one particle from the flavours available, if possible.
260 K(N+1,5)=N+2
IF(IABS(K(IC1,2)).GT.100.AND.IABS(K(IC2,2)).GT.100) THEN
GOTO 320
ELSEIF(IABS(K(IC1,2)).NE.21) THEN
CALL LUKFDI(K(IC1,2),K(IC2,2),KFLDMP,K(N+2,2))
ELSE
KFLN=1+INT((2.+PARJ(2))*RLU(0))
CALL LUKFDI(KFLN,-KFLN,KFLDMP,K(N+2,2))
ENDIF
IF(K(N+2,2).EQ.0) GOTO 260
P(N+2,5)=ULMASS(K(N+2,2))
C...Find parton/particle which combines to largest extra mass.
IR=0
HA=0.
DO 280 MCOMB=1,3
IF(IR.NE.0) GOTO 280
DO 270 I=MAX(1,IP),N
IF(K(I,1).LE.0.OR.K(I,1).GT.10.OR.(I.GE.IC1.AND.I.LE.IC2.
&AND.K(I,1).GE.1.AND.K(I,1).LE.2)) GOTO 270
IF(MCOMB.EQ.1) KCI=LUCOMP(K(I,2))
IF(MCOMB.EQ.1.AND.KCI.EQ.0) GOTO 270
IF(MCOMB.EQ.1.AND.KCHG(KCI,2).EQ.0.AND.I.LE.NS) GOTO 270
IF(MCOMB.EQ.2.AND.IABS(K(I,2)).GT.10.AND.IABS(K(I,2)).LE.100)
&GOTO 270
HCR=sngl(DPC(4))*P(I,4)-sngl(DPC(1))*P(I,1)
1 -sngl(DPC(2))*P(I,2)-sngl(DPC(3))*P(I,3)
IF(HCR.GT.HA) THEN
IR=I
HA=HCR
ENDIF
270 CONTINUE
280 CONTINUE
C...Shuffle energy and momentum to put new particle on mass shell.
HB=PECM**2+HA
HC=P(N+2,5)**2+HA
HD=P(IR,5)**2+HA
C******************CHANGES BY HIJING************
HK2=0.0
IF(HA**2-(PECM*P(IR,5))**2.EQ.0.0.OR.HB+HD.EQ.0.0) GO TO 285
C******************
HK2=0.5*(HB*SQRT(((HB+HC)**2-4.*(HB+HD)*P(N+2,5)**2)/
&(HA**2-(PECM*P(IR,5))**2))-(HB+HC))/(HB+HD)
285 HK1=(0.5*(P(N+2,5)**2-PECM**2)+HD*HK2)/HB
DO 290 J=1,4
P(N+2,J)=(1.+HK1)*sngl(DPC(J))-HK2*P(IR,J)
P(IR,J)=(1.+HK2)*P(IR,J)-HK1*sngl(DPC(J))
V(N+1,J)=V(IC1,J)
290 V(N+2,J)=V(IC1,J)
V(N+1,5)=0.
V(N+2,5)=0.
N=N+2
C...Mark collapsed system and store daughter pointers. Iterate.
300 DO 310 I=IC1,IC2
IF((K(I,1).EQ.1.OR.K(I,1).EQ.2).AND.KCHG(LUCOMP(K(I,2)),2).NE.0)
&THEN
K(I,1)=K(I,1)+10
IF(MSTU(16).NE.2) THEN
K(I,4)=NSAV+1
K(I,5)=NSAV+1
ELSE
K(I,4)=NSAV+2
K(I,5)=N
ENDIF
ENDIF
310 CONTINUE
IF(N.LT.MSTU(4)-MSTU(32)-5) GOTO 140
C...Check flavours and invariant masses in parton systems.
320 NP=0
KFN=0
KQS=0
DO 330 J=1,5
330 DPS(J)=0d0
DO 360 I=MAX(1,IP),N
IF(K(I,1).LE.0.OR.K(I,1).GT.10) GOTO 360
KC=LUCOMP(K(I,2))
IF(KC.EQ.0) GOTO 360
KQ=KCHG(KC,2)*ISIGN(1,K(I,2))
IF(KQ.EQ.0) GOTO 360
NP=NP+1
IF(KQ.NE.2) THEN
KFN=KFN+1
KQS=KQS+KQ
MSTJ(93)=1
DPS(5)=DPS(5)+dble(ULMASS(K(I,2)))
ENDIF
DO 340 J=1,4
340 DPS(J)=DPS(J)+dble(P(I,J))
clin-4/12/01:
c np: # of partons, KFN: number of quarks and diquarks,
c KC=0 for color singlet system, -1 for quarks and anti-diquarks,
c 1 for quarks and anti-diquarks, and 2 for gluons:
IF(K(I,1).EQ.1) THEN
clin-4/12/01 end of color singlet system.
IF(NP.NE.1.AND.(KFN.EQ.1.OR.KFN.GE.3.OR.KQS.NE.0)) CALL
& LUERRM(2,'(LUPREP:) unphysical flavour combination')
clin-4/16/01: 'jet system' should be defined as np.ne.2:
c IF(NP.NE.1.AND.DPS(4)**2-DPS(1)**2-DPS(2)**2-DPS(3)**2.LT.
c & (0.9*PARJ(32)+DPS(5))**2) CALL LUERRM(3,
c & '(LUPREP:) too small mass in jet system')
IF(NP.NE.2.AND.DPS(4)**2-DPS(1)**2-DPS(2)**2-DPS(3)**2.LT.
& (0.9d0*dble(PARJ(32))+DPS(5))**2) then
CALL LUERRM(3,
& '(LUPREP:) too small mass in jet system')
write (6,*) 'DPS(1-5),KI1-5=',DPS(1),DPS(2),DPS(3),DPS(4),
1 DPS(5),'*',K(I,1),K(I,2),K(I,3),K(I,4),K(I,5)
endif
NP=0
KFN=0
KQS=0
DO 350 J=1,5
350 DPS(J)=0d0
ENDIF
360 CONTINUE
RETURN
END
C*********************************************************************
SUBROUTINE LUSTRF(IP)
C...Purpose: to handle the fragmentation of an arbitrary colour singlet
C...jet system according to the Lund string fragmentation model.
IMPLICIT DOUBLE PRECISION(D)
COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
SAVE /LUJETS/
COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
SAVE /LUDAT1/
COMMON/LUDAT2/KCHG(500,3),PMAS(500,4),PARF(2000),VCKM(4,4)
SAVE /LUDAT2/
DIMENSION DPS(5),KFL(3),PMQ(3),PX(3),PY(3),GAM(3),IE(2),PR(2),
&IN(9),DHM(4),DHG(4),DP(5,5),IRANK(2),MJU(4),IJU(3),PJU(5,5),
&TJU(5),KFJH(2),NJS(2),KFJS(2),PJS(4,5)
C...Function: four-product of two vectors.
FOUR(I,J)=P(I,4)*P(J,4)-P(I,1)*P(J,1)-P(I,2)*P(J,2)-P(I,3)*P(J,3)
DFOUR(I,J)=DP(I,4)*DP(J,4)-DP(I,1)*DP(J,1)-DP(I,2)*DP(J,2)-
&DP(I,3)*DP(J,3)
C...Reset counters. Identify parton system.
MSTJ(91)=0
NSAV=N
NP=0
KQSUM=0
DO 100 J=1,5
100 DPS(J)=0d0
MJU(1)=0
MJU(2)=0
I=IP-1
110 I=I+1
IF(I.GT.MIN(N,MSTU(4)-MSTU(32))) THEN
CALL LUERRM(12,'(LUSTRF:) failed to reconstruct jet system')
IF(MSTU(21).GE.1) RETURN
ENDIF
IF(K(I,1).NE.1.AND.K(I,1).NE.2.AND.K(I,1).NE.41) GOTO 110
KC=LUCOMP(K(I,2))
IF(KC.EQ.0) GOTO 110
KQ=KCHG(KC,2)*ISIGN(1,K(I,2))
IF(KQ.EQ.0) GOTO 110
IF(N+5*NP+11.GT.MSTU(4)-MSTU(32)-5) THEN
CALL LUERRM(11,'(LUSTRF:) no more memory left in LUJETS')
IF(MSTU(21).GE.1) RETURN
ENDIF
C...Take copy of partons to be considered. Check flavour sum.
NP=NP+1
DO 120 J=1,5
K(N+NP,J)=K(I,J)
P(N+NP,J)=P(I,J)
120 DPS(J)=DPS(J)+dble(P(I,J))
K(N+NP,3)=I
IF(P(N+NP,4)**2.LT.P(N+NP,1)**2+P(N+NP,2)**2+P(N+NP,3)**2) THEN
P(N+NP,4)=SQRT(P(N+NP,1)**2+P(N+NP,2)**2+P(N+NP,3)**2+
& P(N+NP,5)**2)
DPS(4)=DPS(4)+dble(MAX(0.,P(N+NP,4)-P(I,4)))
ENDIF
IF(KQ.NE.2) KQSUM=KQSUM+KQ
IF(K(I,1).EQ.41) THEN
KQSUM=KQSUM+2*KQ
IF(KQSUM.EQ.KQ) MJU(1)=N+NP
IF(KQSUM.NE.KQ) MJU(2)=N+NP
ENDIF
IF(K(I,1).EQ.2.OR.K(I,1).EQ.41) GOTO 110
IF(KQSUM.NE.0) THEN
CALL LUERRM(12,'(LUSTRF:) unphysical flavour combination')
IF(MSTU(21).GE.1) RETURN
ENDIF
C...Boost copied system to CM frame (for better numerical precision).
CALL LUDBRB(N+1,N+NP,0.,0.,-DPS(1)/DPS(4),-DPS(2)/DPS(4),
&-DPS(3)/DPS(4))
C...Search for very nearby partons that may be recombined.
NTRYR=0
PARU12=PARU(12)
PARU13=PARU(13)
MJU(3)=MJU(1)
MJU(4)=MJU(2)
NR=NP
130 IF(NR.GE.3) THEN
PDRMIN=2.*PARU12
DO 140 I=N+1,N+NR
IF(I.EQ.N+NR.AND.IABS(K(N+1,2)).NE.21) GOTO 140
I1=I+1
IF(I.EQ.N+NR) I1=N+1
IF(K(I,1).EQ.41.OR.K(I1,1).EQ.41) GOTO 140
IF(MJU(1).NE.0.AND.I1.LT.MJU(1).AND.IABS(K(I1,2)).NE.21)
& GOTO 140
IF(MJU(2).NE.0.AND.I.GT.MJU(2).AND.IABS(K(I,2)).NE.21) GOTO 140
PAP=SQRT((P(I,1)**2+P(I,2)**2+P(I,3)**2)*(P(I1,1)**2+
& P(I1,2)**2+P(I1,3)**2))
PVP=P(I,1)*P(I1,1)+P(I,2)*P(I1,2)+P(I,3)*P(I1,3)
PDR=4.*(PAP-PVP)**2/(PARU13**2*PAP+2.*(PAP-PVP))
IF(PDR.LT.PDRMIN) THEN
IR=I
PDRMIN=PDR
ENDIF
140 CONTINUE
C...Recombine very nearby partons to avoid machine precision problems.
IF(PDRMIN.LT.PARU12.AND.IR.EQ.N+NR) THEN
DO 150 J=1,4
150 P(N+1,J)=P(N+1,J)+P(N+NR,J)
P(N+1,5)=SQRT(MAX(0.,P(N+1,4)**2-P(N+1,1)**2-P(N+1,2)**2-
& P(N+1,3)**2))
NR=NR-1
GOTO 130
ELSEIF(PDRMIN.LT.PARU12) THEN
DO 160 J=1,4
160 P(IR,J)=P(IR,J)+P(IR+1,J)
P(IR,5)=SQRT(MAX(0.,P(IR,4)**2-P(IR,1)**2-P(IR,2)**2-
& P(IR,3)**2))
DO 170 I=IR+1,N+NR-1
K(I,2)=K(I+1,2)
DO 170 J=1,5
170 P(I,J)=P(I+1,J)
IF(IR.EQ.N+NR-1) K(IR,2)=K(N+NR,2)
NR=NR-1
IF(MJU(1).GT.IR) MJU(1)=MJU(1)-1
IF(MJU(2).GT.IR) MJU(2)=MJU(2)-1
GOTO 130
ENDIF
ENDIF
NTRYR=NTRYR+1
C...Reset particle counter. Skip ahead if no junctions are present;
C...this is usually the case!
NRS=MAX(5*NR+11,NP)
NTRY=0
180 NTRY=NTRY+1
IF(NTRY.GT.100.AND.NTRYR.LE.4) THEN
PARU12=4.*PARU12
PARU13=2.*PARU13
GOTO 130
ELSEIF(NTRY.GT.100) THEN
CALL LUERRM(14,'(LUSTRF:) caught in infinite loop')
IF(MSTU(21).GE.1) RETURN
ENDIF
I=N+NRS
IF(MJU(1).EQ.0.AND.MJU(2).EQ.0) GOTO 500
DO 490 JT=1,2
NJS(JT)=0
IF(MJU(JT).EQ.0) GOTO 490
JS=3-2*JT
C...Find and sum up momentum on three sides of junction. Check flavours.
DO 190 IU=1,3
IJU(IU)=0
DO 190 J=1,5
190 PJU(IU,J)=0.
IU=0
DO 200 I1=N+1+(JT-1)*(NR-1),N+NR+(JT-1)*(1-NR),JS
IF(K(I1,2).NE.21.AND.IU.LE.2) THEN
IU=IU+1
IJU(IU)=I1
ENDIF
DO 200 J=1,4
200 PJU(IU,J)=PJU(IU,J)+P(I1,J)
DO 210 IU=1,3
210 PJU(IU,5)=SQRT(PJU(IU,1)**2+PJU(IU,2)**2+PJU(IU,3)**2)
IF(K(IJU(3),2)/100.NE.10*K(IJU(1),2)+K(IJU(2),2).AND.
&K(IJU(3),2)/100.NE.10*K(IJU(2),2)+K(IJU(1),2)) THEN
CALL LUERRM(12,'(LUSTRF:) unphysical flavour combination')
IF(MSTU(21).GE.1) RETURN
ENDIF