Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-04 08:05:07

0001 c     Version 1.383
0002 c     The variables I_SNG in HIJSFT and JL in ATTRAD were not initialized.
0003 c     The version initialize them. (as found by Fernando Marroquim)
0004 c
0005 c
0006 c
0007 c     Version 1.382
0008 c     Nuclear distribution for deuteron is taken as the Hulthen wave
0009 c     function as provided by Brian Cole (Columbia)
0010 c
0011 c
0012 c     Version 1.381
0013 c
0014 c     The parameters for Wood-Saxon distribution for deuteron are
0015 c     constrained to give the right rms ratius 2.116 fm
0016 c     (R=0.0, D=0.5882)
0017 c
0018 c
0019 c     Version 1.38
0020 c
0021 c     The following common block is added to record the number of elastic
0022 c     (NELT, NELP) and inelastic (NINT, NINP) participants
0023 c
0024 c        COMMON/HIJGLBR/NELT,NINT,NELP,NINP
0025 c        SAVE  /HIJGLBR/
0026 c
0027 c     Version 1.37
0028 c
0029 c     A bug in the quenching subroutine is corrected. When calculating the
0030 c     distance between two wounded nucleons, the displacement of the
0031 c     impact parameter was not inculded. This bug was discovered by
0032 c     Dr. V.Uzhinskii JINR, Dubna, Russia
0033 c
0034 c
0035 C     Version 1.36
0036 c
0037 c     Modification Oct. 8, 1998. In hijing, log(ran(nseed)) occasionally
0038 c     causes overfloat. It is modified to log(max(ran(nseed),1.0e-20)).
0039 c
0040 c
0041 C     Nothing important has been changed here. A few 'garbage' has been
0042 C     cleaned up here, like common block HIJJET3 for the sea quark strings
0043 C     which were originally created to implement the DPM scheme which
0044 C     later was abadoned in the final version. The lines which operate
0045 C     on these data are also deleted in the program.
0046 C
0047 C
0048 C     Version 1.35
0049 C     There are some changes in the program: subroutine HARDJET is now
0050 C     consolidated with HIJHRD. HARDJET is used to re-initiate PYTHIA
0051 C     for the triggered hard processes. Now that is done  altogether
0052 C     with other normal hard processes in modified JETINI. In the new
0053 C     version one calls JETINI every time one calls HIJHRD. In the new
0054 C     version the effect of the isospin of the nucleon on hard processes,
0055 C     especially direct photons is correctly considered.
0056 C     For A+A collisions, one has to initilize pythia
0057 C     separately for each type of collisions, pp, pn,np and nn,
0058 C     or hp and hn for hA collisions. In JETINI we use the following
0059 C     catalogue for different types of collisions:
0060 C     h+h: h+h (I_TYPE=1)
0061 C     h+A: h+p (I_TYPE=1), h+n (I_TYPE=2)
0062 C     A+h: p+h (I_TYPE=1), n+h (I_TYPE=2)
0063 C     A+A: p+p (I_TYPE=1), p+n (I_TYPE=2), n+p (I_TYPE=3), n+n (I_TYPE=4)
0064 C*****************************************************************
0065 c
0066 C
0067 C     Version 1.34
0068 C     Last modification on January 5, 1998. Two mistakes are corrected in
0069 C     function G. A Mistake in the subroutine Parton is also corrected.
0070 C     (These are pointed out by Ysushi Nara).
0071 C
0072 C
0073 C       Last modifcation on April 10, 1996. To conduct final
0074 C       state radiation, PYTHIA reorganize the two scattered
0075 C       partons and their final momenta will be a little
0076 C       different. The summed total momenta of the partons
0077 C       from the final state radiation are stored in HINT1(26-29)
0078 C       and HINT1(36-39) which are little different from 
0079 C       HINT1(21-24) and HINT1(41-44).
0080 C
0081 C       Version 1.33
0082 C
0083 C       Last modfication  on September 11, 1995. When HIJING and
0084 C       PYTHIA are initialized, the shadowing is evaluated at
0085 C       b=0 which is the maximum. This will cause overestimate
0086 C       of shadowing for peripheral interactions. To correct this
0087 C       problem, shadowing is set to zero when initializing. Then
0088 C       use these maximum  cross section without shadowing as a
0089 C       normalization of the Monte Carlo. This however increase
0090 C       the computing time. IHNT2(16) is used to indicate whether
0091 C       the sturcture function is called for (IHNT2(16)=1) initialization
0092 C       or for (IHNT2(16)=0)normal collisions simulation
0093 C
0094 C       Last modification on Aagust 28, 1994. Two bugs associate
0095 C       with the impact parameter dependence of the shadowing is
0096 C       corrected.
0097 C
0098 C
0099 c       Last modification on October 14, 1994. One bug is corrected
0100 c       in the direct photon production option in subroutine
0101 C       HIJHRD.( this problem was reported by Jim Carroll and Mike Beddo).
0102 C       Another bug associated with keeping the decay history
0103 C       in the particle information is also corrected.(this problem
0104 C       was reported by Matt Bloomer)
0105 C
0106 C
0107 C       Last modification on July 15, 1994. The option to trig on
0108 C       heavy quark production (charm IHPR2(18)=0 or beauty IHPR2(18)=1) 
0109 C       is added. To do this, set IHPR2(3)=3. For inclusive production,
0110 C       one should reset HIPR1(10)=0.0. One can also trig larger pt
0111 C       QQbar production by giving HIPR1(10) a nonvanishing value.
0112 C       The mass of the heavy quark in the calculation of the cross
0113 C       section (HINT1(59)--HINT1(65)) is given by HIPR1(7) (the
0114 C       default is the charm mass D=1.5). We also include a separate
0115 C       K-factor for heavy quark and direct photon production by
0116 C       HIPR1(23)(D=2.0).
0117 C
0118 C       Last modification on May 24, 1994.  The option to
0119 C       retain the information of all particles including those
0120 C       who have decayed is IHPR(21)=1 (default=0). KATT(I,3) is 
0121 C       added to contain the line number of the parent particle 
0122 C       of the current line which is produced via a decay. 
0123 C       KATT(I,4) is the status number of the particle: 11=particle
0124 C       which has decayed; 1=finally produced particle.
0125 C
0126 C
0127 C       Last modification on May 24, 1994( in HIJSFT when valence quark
0128 C       is quenched, the following error is corrected. 1.2*IHNT2(1) --> 
0129 C       1.2*IHNT2(1)**0.333333, 1.2*IHNT2(3) -->1.2*IHNT(3)**0.333333)
0130 C
0131 C
0132 C       Last modification on March 16, 1994 (heavy flavor production
0133 C       processes MSUB(81)=1 MSUB(82)=1 have been switched on,
0134 C       charm production is the default, B-quark option is
0135 C       IHPR2(18), when it is switched on, charm quark is 
0136 C       automatically off)
0137 C
0138 C
0139 C       Last modification on March 23, 1994 (an error is corrected
0140 C       in the impact parameter dependence of the jet cross section)
0141 C
0142 C       Last modification Oct. 1993 to comply with non-vax
0143 C       machines' compiler 
0144 C
0145 C*********************************************
0146 C       LAST MODIFICATION April 5, 1991
0147 CQUARK DISTRIBUTIOIN (1-X)**A/(X**2+C**2/S)**B 
0148 C(A=HIPR1(44),B=HIPR1(46),C=HIPR1(45))
0149 C STRING FLIP, VENUS OPTION IHPR2(15)=1,IN WHICH ONE CAN HAVE ONE AND
0150 C TWO COLOR CHANGES, (1-W)**2,W*(1-W),W*(1-W),AND W*2, W=HIPR1(18), 
0151 C AMONG PT DISTRIBUTION OF SEA QUARKS IS CONTROLLED BY HIPR1(42)
0152 C
0153 C       gluon jets can form a single string system
0154 C
0155 C       initial state radiation is included
0156 C       
0157 C       all QCD subprocesses are included
0158 c
0159 c       direct particles production is included(currently only direct
0160 C               photon)
0161 c
0162 C       Effect of high P_T trigger bias on multiple jets distribution
0163 c
0164 C******************************************************************
0165 C                               HIJING.10                         *
0166 C                 Heavy Ion Jet INteraction Generator             *
0167 C                                  by                             *
0168 C                  X. N. Wang      and   M. Gyulassy              *
0169 C                     Lawrence Berkeley Laboratory                *
0170 C                                                                 *
0171 C******************************************************************
0172 C
0173 C******************************************************************
0174 C NFP(K,1),NFP(K,2)=flavor of q and di-q, NFP(K,3)=present ID of  *
0175 C proj, NFP(K,4) original ID of proj.  NFP(K,5)=colli status(0=no,*
0176 C 1=elastic,2=the diffrac one in single-diffrac,3= excited string.*
0177 C |NFP(K,6)| is the total # of jet production, if NFP(K,6)<0 it   *
0178 C can not produce jet anymore. NFP(K,10)=valence quarks scattering*
0179 C (0=has not been,1=is going to be, -1=has already been scattered *
0180 C NFP(k,11) total number of interactions this proj has suffered   *
0181 C PP(K,1)=PX,PP(K,2)=PY,PP(K,3)=PZ,PP(K,4)=E,PP(K,5)=M(invariant  *
0182 C mass), PP(K,6,7),PP(K,8,9)=transverse momentum of quark and     *
0183 C diquark,PP(K,10)=PT of the hard scattering between the valence  *
0184 C quarks; PP(K,14,15)=the mass of quark,diquark.                  * 
0185 C******************************************************************
0186 C
0187 C****************************************************************
0188 C
0189 C       SUBROUTINE HIJING
0190 C
0191 C****************************************************************
0192 c       SUBROUTINE HIJING(FRAME,BMIN0,BMAX0)   !khaled
0193         SUBROUTINE HIJING(BMIN0,BMAX0)
0194 
0195         CHARACTER FRAME*8
0196         DIMENSION SCIP(300,300),RNIP(300,300),SJIP(300,300),JTP(3),
0197      &                  IPCOL(90000),ITCOL(90000)
0198         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
0199         SAVE  /HIPARNT/
0200 C
0201         COMMON/HIJCRDN/YP(3,300),YT(3,300)
0202         SAVE  /HIJCRDN/
0203         COMMON/HIJGLBR/NELT,NINT,NELP,NINP
0204         SAVE  /HIJGLBR/
0205         COMMON/HIMAIN1/NATT,EATT,JATT,NT,NP,N0,N01,N10,N11
0206         SAVE  /HIMAIN1/
0207         COMMON/HIMAIN2/KATT(130000,4),PATT(130000,4)
0208         SAVE  /HIMAIN2/
0209         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
0210         SAVE  /HISTRNG/
0211         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
0212      &                PJPY(300,500),PJPZ(300,500),PJPE(300,500),
0213      &                PJPM(300,500),NTJ(300),KFTJ(300,500),
0214      &                PJTX(300,500),PJTY(300,500),PJTZ(300,500),
0215      &                PJTE(300,500),PJTM(300,500)
0216         SAVE  /HIJJET1/
0217         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
0218      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
0219      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
0220         SAVE  /HIJJET2/
0221         COMMON/HIJJET4/NDR,IADR(900,2),KFDR(900),PDR(900,5)
0222         SAVE  /HIJJET4/
0223         COMMON/RANSEED/NSEED
0224         SAVE  /RANSEED/
0225 C
0226         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)   
0227         SAVE  /LUJETS/
0228         COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
0229         SAVE  /LUDAT1/
0230 
0231         BMAX=MIN(BMAX0,HIPR1(34)+HIPR1(35))
0232         BMIN=MIN(BMIN0,BMAX)
0233         IF(IHNT2(1).LE.1 .AND. IHNT2(3).LE.1) THEN
0234                 BMIN=0.0
0235                 BMAX=2.5*SQRT(HIPR1(31)*0.1/HIPR1(40))
0236 c        write(*,*)"HIJING bmin bmax",BMIN,"=====", BMAX
0237         ENDIF
0238 c       ----------------------------
0239         FRAME='CMS'      !khaled    //CMS
0240 C                       ********HIPR1(31) is in mb =0.1fm**2
0241 C*******THE FOLLOWING IS TO SELECT THE COORDINATIONS OF NUCLEONS 
0242 C       BOTH IN PROJECTILE AND TARGET NUCLEAR( in fm)
0243 C
0244         YP(1,1)=0.0
0245         YP(2,1)=0.0
0246         YP(3,1)=0.0
0247         IF(IHNT2(1).LE.1) GO TO 14
0248         DO 10 KP=1,IHNT2(1)
0249 5       R=HIRND(1)
0250 c
0251         if(IHNT2(1).EQ.2) then
0252            rnd1=max(RLU(0),1.0e-20)
0253            rnd2=max(RLU(0),1.0e-20)
0254            rnd3=max(RLU(0),1.0e-20)
0255            R=-0.5*(log(rnd1)*4.38/2.0+log(rnd2)*0.85/2.0
0256      &          +4.38*0.85*log(rnd3)/(4.38+0.85))
0257         endif
0258 c
0259         X=RLU(0)
0260         CX=2.0*X-1.0
0261         SX=SQRT(1.0-CX*CX)
0262 C               ********choose theta from uniform cos(theta) distr
0263         PHI=RLU(0)*2.0*HIPR1(40)
0264 C               ********choose phi form uniform phi distr 0 to 2*pi
0265         YP(1,KP)=R*SX*COS(PHI)
0266         YP(2,KP)=R*SX*SIN(PHI)
0267         YP(3,KP)=R*CX
0268         IF(HIPR1(29).EQ.0.0) GO TO 10
0269         DO 8  KP2=1,KP-1
0270                 DNBP1=(YP(1,KP)-YP(1,KP2))**2
0271                 DNBP2=(YP(2,KP)-YP(2,KP2))**2
0272                 DNBP3=(YP(3,KP)-YP(3,KP2))**2
0273                 DNBP=DNBP1+DNBP2+DNBP3
0274                 IF(DNBP.LT.HIPR1(29)*HIPR1(29)) GO TO 5
0275 C                       ********two neighbors cannot be closer than 
0276 C                               HIPR1(29)
0277 8       CONTINUE
0278 10      CONTINUE
0279 c*******************************
0280         if(IHNT2(1).EQ.2) then
0281            YP(1,2)=-YP(1,1)
0282            YP(2,2)=-YP(2,1)
0283            YP(3,2)=-YP(3,1)
0284         endif
0285 c********************************
0286         DO 12 I=1,IHNT2(1)-1
0287         DO 12 J=I+1,IHNT2(1)
0288         IF(YP(3,I).GT.YP(3,J)) GO TO 12
0289         Y1=YP(1,I)
0290         Y2=YP(2,I)
0291         Y3=YP(3,I)
0292         YP(1,I)=YP(1,J)
0293         YP(2,I)=YP(2,J)
0294         YP(3,I)=YP(3,J)
0295         YP(1,J)=Y1
0296         YP(2,J)=Y2
0297         YP(3,J)=Y3
0298 12      CONTINUE
0299 C
0300 C******************************
0301 14      YT(1,1)=0.0
0302         YT(2,1)=0.0
0303         YT(3,1)=0.0
0304         IF(IHNT2(3).LE.1) GO TO 24
0305         DO 20 KT=1,IHNT2(3)
0306 15      R=HIRND(2)
0307 c
0308         if(IHNT2(3).EQ.2) then
0309            rnd1=max(RLU(0),1.0e-20)
0310            rnd2=max(RLU(0),1.0e-20)
0311            rnd3=max(RLU(0),1.0e-20)
0312            R=-0.5*(log(rnd1)*4.38/2.0+log(rnd2)*0.85/2.0
0313      &          +4.38*0.85*log(rnd3)/(4.38+0.85))
0314         endif
0315 c
0316         X=RLU(0)
0317         CX=2.0*X-1.0
0318         SX=SQRT(1.0-CX*CX)
0319 C               ********choose theta from uniform cos(theta) distr
0320         PHI=RLU(0)*2.0*HIPR1(40)
0321 C               ********chose phi form uniform phi distr 0 to 2*pi
0322         YT(1,KT)=R*SX*COS(PHI)
0323         YT(2,KT)=R*SX*SIN(PHI)
0324         YT(3,KT)=R*CX
0325         IF(HIPR1(29).EQ.0.0) GO TO 20
0326         DO 18  KT2=1,KT-1
0327                 DNBT1=(YT(1,KT)-YT(1,KT2))**2
0328                 DNBT2=(YT(2,KT)-YT(2,KT2))**2
0329                 DNBT3=(YT(3,KT)-YT(3,KT2))**2
0330                 DNBT=DNBT1+DNBT2+DNBT3
0331                 IF(DNBT.LT.HIPR1(29)*HIPR1(29)) GO TO 15
0332 C                       ********two neighbors cannot be closer than 
0333 C                               HIPR1(29)
0334 18      CONTINUE
0335 20      CONTINUE
0336 c**********************************
0337         if(IHNT2(3).EQ.2) then
0338            YT(1,2)=-YT(1,1)
0339            YT(2,2)=-YT(2,1)
0340            YT(3,2)=-YT(3,1)
0341         endif
0342 c*********************************
0343         DO 22 I=1,IHNT2(3)-1
0344         DO 22 J=I+1,IHNT2(3)
0345         IF(YT(3,I).LT.YT(3,J)) GO TO 22
0346         Y1=YT(1,I)
0347         Y2=YT(2,I)
0348         Y3=YT(3,I)
0349         YT(1,I)=YT(1,J)
0350         YT(2,I)=YT(2,J)
0351         YT(3,I)=YT(3,J)
0352         YT(1,J)=Y1
0353         YT(2,J)=Y2
0354         YT(3,J)=Y3
0355 22      CONTINUE
0356 C********************
0357 24      MISS=-1
0358 
0359 50      MISS=MISS+1
0360         IF(MISS.GT.50) THEN
0361            WRITE(6,*) 'infinite loop happened in  HIJING'
0362            STOP
0363         ENDIF
0364 
0365         NATT=0
0366         JATT=0
0367         EATT=0.0
0368         CALL HIJINI
0369         NLOP=0
0370 C                       ********Initialize for a new event
0371 60      NT=0
0372         NP=0
0373         N0=0
0374         N01=0
0375         N10=0
0376         N11=0
0377         NELT=0
0378         NINT=0
0379         NELP=0
0380         NINP=0
0381         NSG=0
0382         NCOLT=0
0383 
0384 C****   BB IS THE ABSOLUTE VALUE OF IMPACT PARAMETER,BB**2 IS 
0385 C       RANDOMLY GENERATED AND ITS ORIENTATION IS RANDOMLY SET 
0386 C       BY THE ANGLE PHI  FOR EACH COLLISION.******************
0387 C
0388 
0389         BB=SQRT(BMIN**2+RLU(0)*(BMAX**2-BMIN**2))
0390 c        write(*,*)"HIJING bmin bmax bb", bmin, bmax,bb
0391         PHI=2.0*HIPR1(40)*RLU(0)
0392         BBX=BB*COS(PHI)
0393         BBY=BB*SIN(PHI)
0394         HINT1(19)=BB
0395         HINT1(20)=PHI
0396 C
0397         DO 70 JP=1,IHNT2(1)
0398         DO 70 JT=1,IHNT2(3)
0399            SCIP(JP,JT)=-1.0
0400            B2=(YP(1,JP)+BBX-YT(1,JT))**2+(YP(2,JP)+BBY-YT(2,JT))**2
0401            R2=B2*HIPR1(40)/HIPR1(31)/0.1
0402 C               ********mb=0.1*fm, YP is in fm,HIPR1(31) is in mb
0403            RRB1=MIN((YP(1,JP)**2+YP(2,JP)**2)
0404      &          /1.2**2/REAL(IHNT2(1))**0.6666667,1.0)
0405            RRB2=MIN((YT(1,JT)**2+YT(2,JT)**2)
0406      &          /1.2**2/REAL(IHNT2(3))**0.6666667,1.0)
0407            APHX1=HIPR1(6)*4.0/3.0*(IHNT2(1)**0.3333333-1.0)
0408      &           *SQRT(1.0-RRB1)
0409            APHX2=HIPR1(6)*4.0/3.0*(IHNT2(3)**0.3333333-1.0)
0410      &           *SQRT(1.0-RRB2)
0411            HINT1(18)=HINT1(14)-APHX1*HINT1(15)
0412      &                  -APHX2*HINT1(16)+APHX1*APHX2*HINT1(17)
0413 
0414            IF(IHPR2(14).EQ.0.OR.
0415      &          (IHNT2(1).EQ.1.AND.IHNT2(3).EQ.1)) THEN
0416 c           write(*,*)'R2 ROMG(R2)',R2, ROMG(R2), OMG0(R2)  KHal
0417               GS=1.0-EXP(-(HIPR1(30)+HINT1(18))*ROMG(R2)/HIPR1(31))
0418               RANTOT=RLU(0)
0419               
0420               IF(RANTOT.GT.GS) GO TO 70
0421               GO TO 65
0422            ENDIF
0423 c           write(*,*)'ROMG(0.0)'  !kha
0424            GSTOT_0=2.0*(1.0-EXP(-(HIPR1(30)+HINT1(18))
0425      &             /HIPR1(31)/2.0*ROMG(0.0)))
0426 c           write(*,*)GSTOT_0, ROMG(0.0)
0427            R2=R2/GSTOT_0
0428            GS=1.0-EXP(-(HIPR1(30)+HINT1(18))/HIPR1(31)*ROMG(R2))
0429            GSTOT=2.0*(1.0-SQRT(1.0-GS))
0430            RANTOT=RLU(0)*GSTOT_0
0431 c           write(*,*)'rantot, gstot',rantot, gstot
0432            IF(RANTOT.GT.GSTOT) GO TO 70
0433            IF(RANTOT.GT.GS) THEN
0434 c              write(*,*)"----------------------------------start HIJCSC"
0435               CALL HIJCSC(JP,JT)
0436 c              write(*,*)"----------------------------------end HIJCSC"
0437               GO TO 70
0438 C                       ********perform elastic collisions
0439            ENDIF
0440  65        SCIP(JP,JT)=R2
0441            RNIP(JP,JT)=RANTOT
0442            SJIP(JP,JT)=HINT1(18)
0443            NCOLT=NCOLT+1
0444            IPCOL(NCOLT)=JP
0445            ITCOL(NCOLT)=JT
0446 70      CONTINUE
0447 C               ********total number interactions proj and targ has
0448 C                               suffered
0449         IF(NCOLT.EQ.0) THEN
0450            NLOP=NLOP+1
0451            IF(NLOP.LE.20.OR.
0452      &           (IHNT2(1).EQ.1.AND.IHNT2(3).EQ.1)) GO TO 60
0453            RETURN
0454         ENDIF
0455 C               ********At large impact parameter, there maybe no
0456 C                       interaction at all. For NN collision
0457 C                       repeat the event until interaction happens
0458 C
0459         IF(IHPR2(3).NE.0) THEN
0460            NHARD=1+INT(RLU(0)*(NCOLT-1)+0.5)
0461            NHARD=MIN(NHARD,NCOLT)
0462            JPHARD=IPCOL(NHARD)
0463            JTHARD=ITCOL(NHARD)
0464         ENDIF
0465 C
0466         IF(IHPR2(9).EQ.1) THEN
0467                 NMINI=1+INT(RLU(0)*(NCOLT-1)+0.5)
0468                 NMINI=MIN(NMINI,NCOLT)
0469                 JPMINI=IPCOL(NMINI)
0470                 JTMINI=ITCOL(NMINI)
0471         ENDIF
0472 C               ********Specifying the location of the hard and
0473 C                       minijet if they are enforced by user
0474 C
0475         DO 200 JP=1,IHNT2(1)
0476         DO 200 JT=1,IHNT2(3)
0477         IF(SCIP(JP,JT).EQ.-1.0) GO TO 200
0478                 NFP(JP,11)=NFP(JP,11)+1
0479                 NFT(JT,11)=NFT(JT,11)+1
0480         IF(NFP(JP,5).LE.1 .AND. NFT(JT,5).GT.1) THEN
0481                 NP=NP+1
0482                 N01=N01+1
0483         ELSE IF(NFP(JP,5).GT.1 .AND. NFT(JT,5).LE.1) THEN
0484                 NT=NT+1
0485                 N10=N10+1
0486         ELSE IF(NFP(JP,5).LE.1 .AND. NFT(JT,5).LE.1) THEN
0487                 NP=NP+1
0488                 NT=NT+1
0489                 N0=N0+1
0490         ELSE IF(NFP(JP,5).GT.1 .AND. NFT(JT,5).GT.1) THEN
0491                 N11=N11+1
0492         ENDIF
0493 c
0494         JOUT=0
0495         NFP(JP,10)=0
0496         NFT(JT,10)=0
0497 C*****************************************************************
0498         IF(IHPR2(8).EQ.0 .AND. IHPR2(3).EQ.0) GO TO 160
0499 C               ********When IHPR2(8)=0 no jets are produced
0500         IF(NFP(JP,6).LT.0 .OR. NFT(JT,6).LT.0) GO TO 160
0501 C               ********jets can not be produced for (JP,JT)
0502 C                       because not enough energy avaible for 
0503 C                               JP or JT 
0504         R2=SCIP(JP,JT)
0505         HINT1(18)=SJIP(JP,JT)
0506         TT=ROMG(R2)*HINT1(18)/HIPR1(31)
0507         TTS=HIPR1(30)*ROMG(R2)/HIPR1(31)
0508         NJET=0
0509         IF(IHPR2(3).NE.0 .AND. JP.EQ.JPHARD .AND. JT.EQ.JTHARD) THEN
0510            CALL JETINI(JP,JT,1)
0511            CALL HIJHRD(JP,JT,0,JFLG,0)
0512            HINT1(26)=HINT1(47)
0513            HINT1(27)=HINT1(48)
0514            HINT1(28)=HINT1(49)
0515            HINT1(29)=HINT1(50)
0516            HINT1(36)=HINT1(67)
0517            HINT1(37)=HINT1(68)
0518            HINT1(38)=HINT1(69)
0519            HINT1(39)=HINT1(70)
0520 C
0521            IF(ABS(HINT1(46)).GT.HIPR1(11).AND.JFLG.EQ.2) NFP(JP,7)=1
0522            IF(ABS(HINT1(56)).GT.HIPR1(11).AND.JFLG.EQ.2) NFT(JT,7)=1
0523            IF(MAX(ABS(HINT1(46)),ABS(HINT1(56))).GT.HIPR1(11).AND.
0524      &                          JFLG.GE.3) IASG(NSG,3)=1
0525            IHNT2(9)=IHNT2(14)
0526            IHNT2(10)=IHNT2(15)
0527            DO 105 I05=1,5
0528               HINT1(20+I05)=HINT1(40+I05)
0529               HINT1(30+I05)=HINT1(50+I05)
0530  105       CONTINUE
0531            JOUT=1
0532            IF(IHPR2(8).EQ.0) GO TO 160
0533            RRB1=MIN((YP(1,JP)**2+YP(2,JP)**2)/1.2**2
0534      &          /REAL(IHNT2(1))**0.6666667,1.0)
0535            RRB2=MIN((YT(1,JT)**2+YT(2,JT)**2)/1.2**2
0536      &          /REAL(IHNT2(3))**0.6666667,1.0)
0537            APHX1=HIPR1(6)*4.0/3.0*(IHNT2(1)**0.3333333-1.0)
0538      &           *SQRT(1.0-RRB1)
0539            APHX2=HIPR1(6)*4.0/3.0*(IHNT2(3)**0.3333333-1.0)
0540      &           *SQRT(1.0-RRB2)
0541            HINT1(65)=HINT1(61)-APHX1*HINT1(62)
0542      &                  -APHX2*HINT1(63)+APHX1*APHX2*HINT1(64)
0543            TTRIG=ROMG(R2)*HINT1(65)/HIPR1(31)
0544            NJET=-1
0545 C               ********subtract the trigger jet from total number
0546 C                       of jet production  to be done since it has
0547 C                               already been produced here
0548            XR1=-ALOG(EXP(-TTRIG)+RLU(0)*(1.0-EXP(-TTRIG)))
0549  106       NJET=NJET+1
0550            XR1=XR1-ALOG(max(RLU(0),1.0e-20))
0551            IF(XR1.LT.TTRIG) GO TO 106
0552            XR=0.0
0553  107       NJET=NJET+1
0554            XR=XR-ALOG(max(RLU(0),1.0e-20))
0555            IF(XR.LT.TT-TTRIG) GO TO 107
0556            NJET=NJET-1
0557            GO TO 112
0558         ENDIF
0559 C               ********create a hard interaction with specified P_T
0560 c                                when IHPR2(3)>0
0561         IF(IHPR2(9).EQ.1.AND.JP.EQ.JPMINI.AND.JT.EQ.JTMINI) GO TO 110
0562 C               ********create at least one pair of mini jets 
0563 C                       when IHPR2(9)=1
0564 C
0565         IF(IHPR2(8).GT.0 .AND.RNIP(JP,JT).LT.EXP(-TT)*
0566      &          (1.0-EXP(-TTS))) GO TO 160
0567 C               ********this is the probability for no jet production
0568 110     XR=-ALOG(EXP(-TT)+RLU(0)*(1.0-EXP(-TT)))
0569 111     NJET=NJET+1
0570         XR=XR-ALOG(max(RLU(0),1.0e-20))
0571         IF(XR.LT.TT) GO TO 111
0572 112     NJET=MIN(NJET,IHPR2(8))
0573         IF(IHPR2(8).LT.0)  NJET=ABS(IHPR2(8))
0574 C               ******** Determine number of mini jet production
0575 C
0576         DO 150 I_JET=1,NJET
0577            CALL JETINI(JP,JT,0)
0578            CALL HIJHRD(JP,JT,JOUT,JFLG,1)
0579 C               ********JFLG=1 jets valence quarks, JFLG=2 with 
0580 C                       gluon jet, JFLG=3 with q-qbar prod for
0581 C                       (JP,JT). If JFLG=0 jets can not be produced 
0582 C                       this time. If JFLG=-1, error occured abandon
0583 C                       this event. JOUT is the total hard scat for
0584 C                       (JP,JT) up to now.
0585            IF(JFLG.EQ.0) GO TO 160
0586            IF(JFLG.LT.0) THEN
0587               IF(IHPR2(10).NE.0) WRITE(6,*) 'error occured in HIJHRD'
0588               GO TO 50
0589            ENDIF
0590            JOUT=JOUT+1
0591            IF(ABS(HINT1(46)).GT.HIPR1(11).AND.JFLG.EQ.2) NFP(JP,7)=1
0592            IF(ABS(HINT1(56)).GT.HIPR1(11).AND.JFLG.EQ.2) NFT(JT,7)=1
0593            IF(MAX(ABS(HINT1(46)),ABS(HINT1(56))).GT.HIPR1(11).AND.
0594      &                  JFLG.GE.3) IASG(NSG,3)=1
0595 C               ******** jet with PT>HIPR1(11) will be quenched
0596  150    CONTINUE
0597  160    CONTINUE
0598         CALL HIJSFT(JP,JT,JOUT,IERROR)
0599         IF(IERROR.NE.0) THEN
0600            IF(IHPR2(10).NE.0) WRITE(6,*) 'error occured in HIJSFT'
0601            GO TO 50
0602         ENDIF
0603 C
0604 C               ********conduct soft scattering between JP and JT
0605         JATT=JATT+JOUT
0606 
0607 200     CONTINUE
0608 c
0609 c**************************
0610 c
0611         DO 201 JP=1,IHNT2(1)
0612            IF(NFP(JP,5).GT.2) THEN
0613               NINP=NINP+1
0614            ELSE IF(NFP(JP,5).EQ.2.OR.NFP(JP,5).EQ.1) THEN
0615               NELP=NELP+1
0616            ENDIF
0617  201    continue
0618         DO 202 JT=1,IHNT2(3)
0619            IF(NFT(JT,5).GT.2) THEN
0620               NINT=NINT+1
0621            ELSE IF(NFT(JT,5).EQ.2.OR.NFT(JT,5).EQ.1) THEN
0622               NELT=NELT+1
0623            ENDIF
0624  202    continue
0625 c     
0626 c*******************************
0627 
0628 
0629 C********perform jet quenching for jets with PT>HIPR1(11)**********
0630 
0631         IF((IHPR2(8).NE.0.OR.IHPR2(3).NE.0).AND.IHPR2(4).GT.0.AND.
0632      &                  IHNT2(1).GT.1.AND.IHNT2(3).GT.1) THEN
0633                 DO 271 I=1,IHNT2(1)
0634                         IF(NFP(I,7).EQ.1) CALL QUENCH(I,1)
0635 271             CONTINUE
0636                 DO 272 I=1,IHNT2(3)
0637                         IF(NFT(I,7).EQ.1) CALL QUENCH(I,2)
0638 272             CONTINUE
0639                 DO 273 ISG=1,NSG
0640                         IF(IASG(ISG,3).EQ.1) CALL QUENCH(ISG,3)
0641 273             CONTINUE
0642         ENDIF
0643 C
0644 C**************fragment all the string systems in the following*****
0645 C
0646 C********N_ST is where particle information starts
0647 C********N_STR+1 is the number of strings in fragmentation
0648 C********the number of strings before a line is stored in K(I,4)
0649 C********IDSTR is id number of the string system (91,92 or 93)
0650 C
0651         IF(IHPR2(20).NE.0) THEN
0652            DO 360 ISG=1,NSG
0653                 CALL HIJFRG(ISG,3,IERROR)
0654                 IF(MSTU(24).NE.0 .OR.IERROR.GT.0) THEN
0655                    MSTU(24)=0
0656                    MSTU(28)=0
0657                    IF(IHPR2(10).NE.0) THEN
0658                       call lulist(1)
0659                       WRITE(6,*) 'error occured, repeat the event'
0660                    ENDIF
0661                    GO TO 50
0662                 ENDIF
0663 C                       ********Check errors
0664 C
0665                 N_ST=1
0666                 IDSTR=92
0667                 IF(IHPR2(21).EQ.0) THEN
0668                    CALL LUEDIT(2)
0669                 ELSE
0670 351                N_ST=N_ST+1
0671                    IF(K(N_ST,2).LT.91.OR.K(N_ST,2).GT.93) GO TO  351
0672                    IDSTR=K(N_ST,2)
0673                    N_ST=N_ST+1
0674                 ENDIF
0675 C
0676                 IF(FRAME.EQ.'LAB') THEN
0677                         CALL HIBOOST
0678                 ENDIF
0679 C               ******** boost back to lab frame(if it was in)
0680 C
0681                 N_STR=0
0682                 DO 360 I=N_ST,N
0683                    IF(K(I,2).EQ.IDSTR) THEN
0684                       N_STR=N_STR+1
0685                       GO TO 360
0686                    ENDIF
0687                    K(I,4)=N_STR
0688                    NATT=NATT+1
0689                    KATT(NATT,1)=K(I,2)
0690                    KATT(NATT,2)=20
0691                    KATT(NATT,4)=K(I,1)
0692                    IF(K(I,3).EQ.0 .OR. K(K(I,3),2).EQ.IDSTR) THEN
0693                       KATT(NATT,3)=0
0694                    ELSE
0695                       KATT(NATT,3)=NATT-I+K(I,3)+N_STR-K(K(I,3),4)
0696                    ENDIF
0697 C       ****** identify the mother particle
0698                    PATT(NATT,1)=P(I,1)
0699                    PATT(NATT,2)=P(I,2)
0700                    PATT(NATT,3)=P(I,3)
0701                    PATT(NATT,4)=P(I,4)
0702                    EATT=EATT+P(I,4)
0703 360        CONTINUE
0704 C               ********Fragment the q-qbar jets systems *****
0705 C
0706            JTP(1)=IHNT2(1)
0707            JTP(2)=IHNT2(3)
0708            DO 400 NTP=1,2
0709            DO 400 J_JTP=1,JTP(NTP)
0710                 CALL HIJFRG(J_JTP,NTP,IERROR)
0711                 IF(MSTU(24).NE.0 .OR. IERROR.GT.0) THEN
0712                    MSTU(24)=0
0713                    MSTU(28)=0
0714                    IF(IHPR2(10).NE.0) THEN
0715                       call lulist(1)
0716                       WRITE(6,*) 'error occured, repeat the event'
0717                    ENDIF
0718                    GO TO 50
0719                 ENDIF
0720 C                       ********check errors
0721 C
0722                 N_ST=1
0723                 IDSTR=92
0724                 IF(IHPR2(21).EQ.0) THEN
0725                    CALL LUEDIT(2)
0726                 ELSE
0727 381                N_ST=N_ST+1
0728                    IF(K(N_ST,2).LT.91.OR.K(N_ST,2).GT.93) GO TO  381
0729                    IDSTR=K(N_ST,2)
0730                    N_ST=N_ST+1
0731                 ENDIF
0732                 IF(FRAME.EQ.'LAB') THEN
0733                         CALL HIBOOST
0734                 ENDIF
0735 C               ******** boost back to lab frame(if it was in)
0736 C
0737                 NFTP=NFP(J_JTP,5)
0738                 IF(NTP.EQ.2) NFTP=10+NFT(J_JTP,5)
0739                 N_STR=0
0740                 DO 390 I=N_ST,N
0741                    IF(K(I,2).EQ.IDSTR) THEN
0742                       N_STR=N_STR+1
0743                       GO TO 390
0744                    ENDIF
0745                    K(I,4)=N_STR
0746                    NATT=NATT+1
0747                    KATT(NATT,1)=K(I,2)
0748                    KATT(NATT,2)=NFTP
0749                    KATT(NATT,4)=K(I,1)
0750                    IF(K(I,3).EQ.0 .OR. K(K(I,3),2).EQ.IDSTR) THEN
0751                       KATT(NATT,3)=0
0752                    ELSE
0753                       KATT(NATT,3)=NATT-I+K(I,3)+N_STR-K(K(I,3),4)
0754                    ENDIF
0755 C       ****** identify the mother particle
0756                    PATT(NATT,1)=P(I,1)
0757                    PATT(NATT,2)=P(I,2)
0758                    PATT(NATT,3)=P(I,3)
0759                    PATT(NATT,4)=P(I,4)
0760                    EATT=EATT+P(I,4)
0761 390             CONTINUE 
0762 400        CONTINUE
0763 C               ********Fragment the q-qq related string systems
0764         ENDIF
0765 
0766         DO 450 I=1,NDR
0767                 NATT=NATT+1
0768                 KATT(NATT,1)=KFDR(I)
0769                 KATT(NATT,2)=40
0770                 KATT(NATT,3)=0
0771                 PATT(NATT,1)=PDR(I,1)
0772                 PATT(NATT,2)=PDR(I,2)
0773                 PATT(NATT,3)=PDR(I,3)
0774                 PATT(NATT,4)=PDR(I,4)
0775                 EATT=EATT+PDR(I,4)
0776 450     CONTINUE
0777 C                       ********store the direct-produced particles
0778 C
0779         DENGY=EATT/(IHNT2(1)*HINT1(6)+IHNT2(3)*HINT1(7))-1.0
0780         IF(ABS(DENGY).GT.HIPR1(43).AND.IHPR2(20).NE.0
0781      &     .AND.IHPR2(21).EQ.0) THEN
0782         IF(IHPR2(10).NE.0) THEN
0783         WRITE(6,*) 'Energy not conserved, repeat the event'
0784         ENDIF
0785 C               call lulist(1)
0786                 GO TO 50
0787         ENDIF
0788         RETURN
0789         END
0790 C
0791 C
0792 C
0793 c       SUBROUTINE HIJSET(EFRM,FRAME,PROJ,TARG,IAP,IZP,IAT,IZT)  !khaled
0794 c        SUBROUTINE HIJSET(EFRM,IAP,IZP,IAT,IZT)  !khaled
0795         SUBROUTINE hijset(efrm)
0796 
0797 c        real*4 efrm
0798         CHARACTER FRAME*4,PROJ*4,TARG*4,EFRAME*4
0799         DOUBLE PRECISION  DD1,DD2,DD3,DD4
0800         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
0801         SAVE  /HISTRNG/
0802         COMMON/HIJCRDN/YP(3,300),YT(3,300)
0803         SAVE  /HIJCRDN/
0804         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
0805         SAVE  /HIPARNT/
0806         COMMON/HIJDAT/HIDAT0(10,10),HIDAT(10)
0807         SAVE  /HIJDAT/
0808         COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
0809         SAVE  /LUDAT1/
0810         EXTERNAL FNKICK,FNKICK2,FNSTRU,FNSTRUM,FNSTRUS
0811         CALL TITLE
0812 c       ---------->khaled
0813         FRAME='CMS'   
0814 c        FRAME='LAB'
0815         PROJ="A"
0816         TARG="B"
0817 c        write(*,*)"Fortran    khaled"
0818 c       write(*,*)EFRM, IHNT2(1),IHNT2(2),IHNT2(3),IHNT2(4)
0819 c        write(*,*)IHNT2(5), IHNT2(6), HINT1(8), HINT1(9)
0820 c        write(*,*)iap, izp, iat,izt
0821 c        write(*,*)hipr1(1), hipr1(2),hipr1(3),hipr1(4), ihpr2(12)
0822 c      ---------> closed by khaled-------------->
0823 c          ------------------------------------
0824 c       IHNT2(1)=IAP
0825 c       IHNT2(2)=IZP
0826 c       IHNT2(3)=IAT
0827 c       IHNT2(4)=IZT
0828 c       IHNT2(5)=0
0829 c       IHNT2(6)=0
0830 C
0831 
0832         
0833 c       HINT1(8)=MAX(ULMASS(2112),ULMASS(2212))
0834 c       HINT1(9)=HINT1(8)
0835 C
0836 c      ---------> closed by khaled
0837 c       IF(PROJ.NE.'A') THEN
0838 c               IF(PROJ.EQ.'P') THEN
0839 c                   IHNT2(5)=2212
0840 c               ELSE IF(PROJ.EQ.'PBAR') THEN 
0841 c                   IHNT2(5)=-2212
0842 c               ELSE IF(PROJ.EQ.'PI+') THEN
0843 c                   IHNT2(5)=211
0844 c               ELSE IF(PROJ.EQ.'PI-') THEN
0845 c                   IHNT2(5)=-211
0846 c               ELSE IF(PROJ.EQ.'K+') THEN
0847 c                   IHNT2(5)=321
0848 c               ELSE IF(PROJ.EQ.'K-') THEN
0849 c                   IHNT2(5)=-321
0850 c               ELSE IF(PROJ.EQ.'N') THEN
0851 c                   IHNT2(5)=2112
0852 c               ELSE IF(PROJ.EQ.'NBAR') THEN
0853 c                   IHNT2(5)=-2112
0854 c               ELSE
0855 c                   WRITE(6,*) PROJ, 'wrong or unavailable proj name'
0856 c                   STOP
0857 c               ENDIF
0858 c               HINT1(8)=ULMASS(IHNT2(5))
0859 c       ENDIF
0860 c       IF(TARG.NE.'A') THEN
0861 c               IF(TARG.EQ.'P') THEN
0862 c                   IHNT2(6)=2212
0863 c               ELSE IF(TARG.EQ.'PBAR') THEN 
0864 c                   IHNT2(6)=-2212
0865 c               ELSE IF(TARG.EQ.'PI+') THEN
0866 c                   IHNT2(6)=211
0867 c               ELSE IF(TARG.EQ.'PI-') THEN
0868 c                   IHNT2(6)=-211
0869 c               ELSE IF(TARG.EQ.'K+') THEN
0870 c                   IHNT2(6)=321
0871 c               ELSE IF(TARG.EQ.'K-') THEN
0872 c                   IHNT2(6)=-321
0873 c               ELSE IF(TARG.EQ.'N') THEN
0874 c                   IHNT2(6)=2112
0875 c               ELSE IF(TARG.EQ.'NBAR') THEN
0876 c                   IHNT2(6)=-2112
0877 c               ELSE
0878 c                   WRITE(6,*) TARG,'wrong or unavailable targ name'
0879 c                   STOP
0880 c               ENDIF
0881 c               HINT1(9)=ULMASS(IHNT2(6))
0882 c       ENDIF
0883 c         ------------------------>end close by khaled
0884 
0885 C...Switch off decay of pi0, K0S, Lambda, Sigma+-, Xi0-, Omega-.
0886         IF(IHPR2(12).GT.0) THEN
0887         CALL LUGIVE('MDCY(C111,1)=0')
0888         CALL LUGIVE('MDCY(C310,1)=0')
0889            CALL LUGIVE('MDCY(C411,1)=0;MDCY(C-411,1)=0')
0890            CALL LUGIVE('MDCY(C421,1)=0;MDCY(C-421,1)=0')
0891            CALL LUGIVE('MDCY(C431,1)=0;MDCY(C-431,1)=0')
0892            CALL LUGIVE('MDCY(C511,1)=0;MDCY(C-511,1)=0')
0893            CALL LUGIVE('MDCY(C521,1)=0;MDCY(C-521,1)=0')
0894            CALL LUGIVE('MDCY(C531,1)=0;MDCY(C-531,1)=0')
0895         CALL LUGIVE('MDCY(C3122,1)=0;MDCY(C-3122,1)=0')
0896         CALL LUGIVE('MDCY(C3112,1)=0;MDCY(C-3112,1)=0')
0897         CALL LUGIVE('MDCY(C3212,1)=0;MDCY(C-3212,1)=0')
0898         CALL LUGIVE('MDCY(C3222,1)=0;MDCY(C-3222,1)=0')
0899         CALL LUGIVE('MDCY(C3312,1)=0;MDCY(C-3312,1)=0')
0900         CALL LUGIVE('MDCY(C3322,1)=0;MDCY(C-3322,1)=0')
0901         CALL LUGIVE('MDCY(C3334,1)=0;MDCY(C-3334,1)=0')
0902         ENDIF
0903         MSTU(12)=0
0904         MSTU(21)=1
0905         IF(IHPR2(10).EQ.0) THEN
0906                 MSTU(22)=0
0907                 MSTU(25)=0
0908                 MSTU(26)=0
0909         ENDIF
0910         MSTJ(12)=IHPR2(11)
0911         PARJ(21)=HIPR1(2)
0912         PARJ(41)=HIPR1(3)
0913         PARJ(42)=HIPR1(4)
0914 C                       ******** set up for jetset
0915         IF(FRAME.EQ.'LAB') THEN
0916            DD1=EFRM
0917            DD2=HINT1(8)
0918            DD3=HINT1(9)
0919            HINT1(1)=SQRT(HINT1(8)**2+2.0*HINT1(9)*EFRM+HINT1(9)**2)
0920            DD4=DSQRT(DD1**2-DD2**2)/(DD1+DD3)
0921            HINT1(2)=DD4
0922            HINT1(3)=0.5*DLOG((1.D0+DD4)/(1.D0-DD4))
0923            DD4=DSQRT(DD1**2-DD2**2)/DD1
0924            HINT1(4)=0.5*DLOG((1.D0+DD4)/(1.D0-DD4))
0925            HINT1(5)=0.0
0926            HINT1(6)=EFRM
0927            HINT1(7)=HINT1(9)
0928         ELSE IF(FRAME.EQ.'CMS') THEN
0929            HINT1(1)=EFRM
0930            HINT1(2)=0.0
0931            HINT1(3)=0.0
0932            DD1=HINT1(1)
0933            DD2=HINT1(8)
0934            DD3=HINT1(9)
0935            DD4=DSQRT(1.D0-4.D0*DD2**2/DD1**2)
0936            HINT1(4)=0.5*DLOG((1.D0+DD4)/(1.D0-DD4))
0937            DD4=DSQRT(1.D0-4.D0*DD3**2/DD1**2)
0938            HINT1(5)=-0.5*DLOG((1.D0+DD4)/(1.D0-DD4))
0939            HINT1(6)=HINT1(1)/2.0
0940            HINT1(7)=HINT1(1)/2.0
0941         ENDIF
0942 C               ********define Lorentz transform to lab frame
0943 c
0944 C               ********calculate the cross sections involved with
0945 C                       nucleon collisions.
0946         IF(IHNT2(1).GT.1) THEN
0947                 CALL HIJWDS(IHNT2(1),1,RMAX)
0948                 HIPR1(34)=RMAX
0949 C                       ********set up Wood-Sax distr for proj.
0950         ENDIF
0951         IF(IHNT2(3).GT.1) THEN
0952                 CALL HIJWDS(IHNT2(3),2,RMAX)
0953                 HIPR1(35)=RMAX
0954 C                       ********set up Wood-Sax distr for  targ.
0955         ENDIF
0956 c        write(*,*)"radii hipr1(34--35)", hipr1(34),"<------>", hipr1(35)  !khaled
0957 c        write(*,*)"hint1(6)--Hint1(7)", hint1(6),"<------>", hint1(7)  !khaled
0958 C
0959 C
0960         I=0
0961 20      I=I+1
0962         IF(I.EQ.10) GO TO 30
0963         IF(HIDAT0(10,I).LE.HINT1(1)) GO TO 20
0964 30      IF(I.EQ.1) I=2
0965         DO 40 J=1,9
0966            HIDAT(J)=HIDAT0(J,I-1)+(HIDAT0(J,I)-HIDAT0(J,I-1))
0967      &     *(HINT1(1)-HIDAT0(10,I-1))/(HIDAT0(10,I)-HIDAT0(10,I-1))
0968 40      CONTINUE
0969         HIPR1(31)=HIDAT(5)
0970         HIPR1(30)=2.0*HIDAT(5)
0971 c       write(*,*)"hipr1(31--30)", hipr1(31),"<------>", hipr1(30)  !khaled 
0972 C
0973 C
0974         
0975          CALL HIJCRS
0976        
0977 C
0978         IF(IHPR2(5).NE.0) THEN
0979                 CALL HIFUN(3,0.0,36.0,FNKICK)
0980 C               ********booking for generating pt**2 for pt kick
0981         ENDIF
0982         CALL HIFUN(7,0.0,6.0,FNKICK2)
0983         CALL HIFUN(4,0.0,1.0,FNSTRU)
0984         CALL HIFUN(5,0.0,1.0,FNSTRUM)
0985         CALL HIFUN(6,0.0,1.0,FNSTRUS)
0986 C               ********booking for x distribution of valence quarks
0987         EFRAME='Ecm'
0988         IF(FRAME.EQ.'LAB') EFRAME='Elab'
0989         WRITE(6,100) EFRAME,EFRM,PROJ,IHNT2(1),IHNT2(2),
0990      &               TARG,IHNT2(3),IHNT2(4) 
0991 100     FORMAT(//10X,'****************************************
0992      &  **********'/
0993      &  10X,'*',48X,'*'/
0994      &  10X,'*         HIJING has been initialized at         *'/
0995      &  10X,'*',13X,A4,'= ',F10.2,' GeV/n',13X,'*'/
0996      &  10X,'*',48X,'*'/
0997      &  10X,'*',8X,'for ',
0998      &  A4,'(',I3,',',I3,')',' + ',A4,'(',I3,',',I3,')',7X,'*'/
0999      &  10X,'**************************************************')
1000         RETURN
1001         END
1002 C
1003 C
1004 C
1005         FUNCTION FNKICK(X)
1006         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1007         SAVE  /HIPARNT/
1008         FNKICK=1.0/(X+HIPR1(19)**2)/(X+HIPR1(20)**2)
1009      &          /(1+EXP((SQRT(X)-HIPR1(20))/0.4))
1010         RETURN
1011         END
1012 C
1013 C
1014         FUNCTION FNKICK2(X)
1015         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1016         SAVE  /HIPARNT/
1017         FNKICK2=X*EXP(-2.0*X/HIPR1(42))
1018         RETURN
1019         END
1020 C
1021 C
1022 C
1023         FUNCTION FNSTRU(X)
1024         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1025         SAVE  /HIPARNT/
1026         FNSTRU=(1.0-X)**HIPR1(44)/
1027      &          (X**2+HIPR1(45)**2/HINT1(1)**2)**HIPR1(46)
1028         RETURN
1029         END
1030 C
1031 C
1032 C
1033         FUNCTION FNSTRUM(X)
1034         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1035         SAVE  /HIPARNT/
1036         FNSTRUM=1.0/((1.0-X)**2+HIPR1(45)**2/HINT1(1)**2)**HIPR1(46)
1037      &          /(X**2+HIPR1(45)**2/HINT1(1)**2)**HIPR1(46)
1038         RETURN
1039         END
1040 C
1041 C
1042         FUNCTION FNSTRUS(X)
1043         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1044         SAVE  /HIPARNT/
1045         FNSTRUS=(1.0-X)**HIPR1(47)/
1046      &          (X**2+HIPR1(45)**2/HINT1(1)**2)**HIPR1(48)
1047         RETURN
1048         END
1049 C
1050 C
1051 C
1052 C
1053         SUBROUTINE HIBOOST
1054         IMPLICIT DOUBLE PRECISION(D)  
1055         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5) 
1056         SAVE /LUJETS/ 
1057         COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200) 
1058         SAVE /LUDAT1/ 
1059         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1060         SAVE  /HIPARNT/
1061         DO 100 I=1,N
1062            DBETA=P(I,3)/P(I,4)
1063            IF(ABS(DBETA).GE.1.D0) THEN
1064               DB=HINT1(2)
1065               IF(DB.GT.0.99999999D0) THEN 
1066 C               ********Rescale boost vector if too close to unity. 
1067                  WRITE(6,*) '(HIBOOT:) boost vector too large' 
1068                  DB=0.99999999D0
1069               ENDIF 
1070               DGA=1D0/SQRT(1D0-DB**2)
1071               DP3=P(I,3)
1072               DP4=P(I,4)
1073               P(I,3)=(DP3+DB*DP4)*DGA  
1074               P(I,4)=(DP4+DB*DP3)*DGA  
1075               GO TO 100
1076            ENDIF
1077            Y=0.5*DLOG((1.D0+DBETA)/(1.D0-DBETA))
1078            AMT=SQRT(P(I,1)**2+P(I,2)**2+P(I,5)**2)
1079            P(I,3)=AMT*SINH(Y+HINT1(3))
1080            P(I,4)=AMT*COSH(Y+HINT1(3))
1081 100     CONTINUE
1082         RETURN
1083         END
1084 C
1085 C
1086 C
1087 C
1088         SUBROUTINE QUENCH(JPJT,NTP)
1089         DIMENSION RDP(300),LQP(300),RDT(300),LQT(300)
1090         COMMON/HIJCRDN/YP(3,300),YT(3,300)
1091         SAVE  /HIJCRDN/
1092         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1093         SAVE  /HIPARNT/
1094 C
1095         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
1096      &                PJPY(300,500),PJPZ(300,500),PJPE(300,500),
1097      &                PJPM(300,500),NTJ(300),KFTJ(300,500),
1098      &                PJTX(300,500),PJTY(300,500),PJTZ(300,500),
1099      &                PJTE(300,500),PJTM(300,500)
1100         SAVE  /HIJJET1/
1101         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
1102      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
1103      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
1104         SAVE  /HIJJET2/
1105         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
1106         SAVE  /HISTRNG/
1107         COMMON/RANSEED/NSEED
1108         SAVE  /RANSEED/
1109 C
1110         BB=HINT1(19)                                            ! Uzhi
1111         PHI=HINT1(20)                                           ! Uzhi
1112         BBX=BB*COS(PHI)                                         ! Uzhi
1113         BBY=BB*SIN(PHI)                                         ! Uzhi
1114 c
1115         IF(NTP.EQ.2) GO TO 400
1116         IF(NTP.EQ.3) GO TO 2000 
1117 C*******************************************************
1118 C Jet interaction for proj jet in the direction PHIP
1119 C******************************************************
1120 C
1121         IF(NFP(JPJT,7).NE.1) RETURN
1122 
1123         JP=JPJT
1124         DO 290 I=1,NPJ(JP)
1125            PTJET0=SQRT(PJPX(JP,I)**2+PJPY(JP,I)**2)
1126            IF(PTJET0.LE.HIPR1(11)) GO TO 290
1127            PTOT=SQRT(PTJET0*PTJET0+PJPZ(JP,I)**2)
1128            IF(PTOT.LT.HIPR1(8)) GO TO 290
1129            PHIP=ULANGL(PJPX(JP,I),PJPY(JP,I))
1130 C******* find the wounded proj which can interact with jet***
1131            KP=0
1132            DO 100 I2=1,IHNT2(1)
1133               IF(NFP(I2,5).NE.3 .OR. I2.EQ.JP) GO TO 100
1134               DX=YP(1,I2)-YP(1,JP)
1135               DY=YP(2,I2)-YP(2,JP)
1136               PHI=ULANGL(DX,DY)
1137               DPHI=ABS(PHI-PHIP)
1138               IF(DPHI.GE.HIPR1(40)) DPHI=2.*HIPR1(40)-DPHI      ! Uzhi
1139               IF(DPHI.GE.HIPR1(40)/2.0) GO TO 100
1140               RD0=SQRT(DX*DX+DY*DY)
1141               IF(RD0*SIN(DPHI).GT.HIPR1(12)) GO TO 100
1142               KP=KP+1
1143               LQP(KP)=I2
1144               RDP(KP)=COS(DPHI)*RD0
1145  100       CONTINUE
1146 C*******        rearrange according decending rd************
1147            DO 110 I2=1,KP-1
1148               DO 110 J2=I2+1,KP
1149                  IF(RDP(I2).LT.RDP(J2)) GO TO 110
1150                  RD=RDP(I2)
1151                  LQ=LQP(I2)
1152                  RDP(I2)=RDP(J2)
1153                  LQP(I2)=LQP(J2)
1154                  RDP(J2)=RD
1155                  LQP(J2)=LQ
1156  110          CONTINUE
1157 C****** find wounded targ which can interact with jet********
1158               KT=0
1159               DO 120 I2=1,IHNT2(3)
1160                  IF(NFT(I2,5).NE.3) GO TO 120
1161                  DX=YT(1,I2)-YP(1,JP)-BBX
1162                  DY=YT(2,I2)-YP(2,JP)-BBY
1163                  PHI=ULANGL(DX,DY)
1164                  DPHI=ABS(PHI-PHIP)
1165                  IF(DPHI.GE.HIPR1(40)) DPHI=2.*HIPR1(40)-DPHI   ! Uzhi
1166                  IF(DPHI.GT.HIPR1(40)/2.0) GO TO 120
1167                  RD0=SQRT(DX*DX+DY*DY)
1168                  IF(RD0*SIN(DPHI).GT.HIPR1(12)) GO TO 120
1169                  KT=KT+1
1170                  LQT(KT)=I2
1171                  RDT(KT)=COS(DPHI)*RD0
1172  120          CONTINUE
1173 C*******        rearrange according decending rd************
1174               DO 130 I2=1,KT-1
1175                  DO 130 J2=I2+1,KT
1176                     IF(RDT(I2).LT.RDT(J2)) GO TO 130
1177                     RD=RDT(I2)
1178                     LQ=LQT(I2)
1179                     RDT(I2)=RDT(J2)
1180                     LQT(I2)=LQT(J2)
1181                     RDT(J2)=RD
1182                     LQT(J2)=LQ
1183  130             CONTINUE
1184                 
1185                  MP=0
1186                  MT=0
1187                  R0=0.0
1188                  NQ=0
1189                  DP=0.0
1190                  PTOT=SQRT(PJPX(JP,I)**2+PJPY(JP,I)**2+PJPZ(JP,I)**2)
1191                  V1=PJPX(JP,I)/PTOT
1192                  V2=PJPY(JP,I)/PTOT
1193                  V3=PJPZ(JP,I)/PTOT
1194 
1195  200             RN=RLU(0)
1196  210             IF(MT.GE.KT .AND. MP.GE.KP) GO TO 290
1197                  IF(MT.GE.KT) GO TO 220
1198                  IF(MP.GE.KP) GO TO 240
1199                  IF(RDP(MP+1).GT.RDT(MT+1)) GO TO 240
1200  220             MP=MP+1
1201                  DRR=RDP(MP)-R0
1202                  IF(RN.GE.1.0-EXP(-DRR/HIPR1(13))) GO TO 210
1203                  DP=DRR*HIPR1(14)
1204                  IF(KFPJ(JP,I).NE.21) DP=0.5*DP
1205 C       ********string tension of quark jet is 0.5 of gluon's 
1206                  IF(DP.LE.0.2) GO TO 210
1207                  IF(PTOT.LE.0.4) GO TO 290
1208                  IF(PTOT.LE.DP) DP=PTOT-0.2
1209                  DE=DP
1210 
1211                  IF(KFPJ(JP,I).NE.21) THEN
1212                     PRSHU=PP(LQP(MP),1)**2+PP(LQP(MP),2)**2
1213      &                   +PP(LQP(MP),3)**2
1214                     DE=SQRT(PJPM(JP,I)**2+PTOT**2)
1215      &                  -SQRT(PJPM(JP,I)**2+(PTOT-DP)**2)
1216                     ERSHU=(PP(LQP(MP),4)+DE-DP)**2
1217                     AMSHU=ERSHU-PRSHU
1218                     IF(AMSHU.LT.HIPR1(1)*HIPR1(1)) GO TO 210
1219                     PP(LQP(MP),4)=SQRT(ERSHU)
1220                     PP(LQP(MP),5)=SQRT(AMSHU)
1221                  ENDIF
1222 C               ********reshuffle the energy when jet has mass
1223                  R0=RDP(MP)
1224                  DP1=DP*V1
1225                  DP2=DP*V2
1226                  DP3=DP*V3
1227 C               ********momentum and energy transfer from jet
1228                  
1229                  NPJ(LQP(MP))=NPJ(LQP(MP))+1
1230                  KFPJ(LQP(MP),NPJ(LQP(MP)))=21
1231                  PJPX(LQP(MP),NPJ(LQP(MP)))=DP1
1232                  PJPY(LQP(MP),NPJ(LQP(MP)))=DP2
1233                  PJPZ(LQP(MP),NPJ(LQP(MP)))=DP3
1234                  PJPE(LQP(MP),NPJ(LQP(MP)))=DP
1235                  PJPM(LQP(MP),NPJ(LQP(MP)))=0.0
1236                  GO TO 260
1237 
1238  240             MT=MT+1
1239                  DRR=RDT(MT)-R0
1240                  IF(RN.GE.1.0-EXP(-DRR/HIPR1(13))) GO TO 210
1241                  DP=DRR*HIPR1(14)
1242                  IF(DP.LE.0.2) GO TO 210
1243                  IF(PTOT.LE.0.4) GO TO 290
1244                  IF(PTOT.LE.DP) DP=PTOT-0.2
1245                  DE=DP
1246 
1247                  IF(KFPJ(JP,I).NE.21) THEN
1248                     PRSHU=PT(LQT(MT),1)**2+PT(LQT(MT),2)**2
1249      &                   +PT(LQT(MT),3)**2
1250                     DE=SQRT(PJPM(JP,I)**2+PTOT**2)
1251      &                  -SQRT(PJPM(JP,I)**2+(PTOT-DP)**2)
1252                     ERSHU=(PT(LQT(MT),4)+DE-DP)**2
1253                     AMSHU=ERSHU-PRSHU
1254                     IF(AMSHU.LT.HIPR1(1)*HIPR1(1)) GO TO 210
1255                     PT(LQT(MT),4)=SQRT(ERSHU)
1256                     PT(LQT(MT),5)=SQRT(AMSHU)
1257                  ENDIF
1258 C               ********reshuffle the energy when jet has mass
1259 
1260                  R0=RDT(MT)
1261                  DP1=DP*V1
1262                  DP2=DP*V2
1263                  DP3=DP*V3
1264 C               ********momentum and energy transfer from jet
1265                  NTJ(LQT(MT))=NTJ(LQT(MT))+1
1266                  KFTJ(LQT(MT),NTJ(LQT(MT)))=21
1267                  PJTX(LQT(MT),NTJ(LQT(MT)))=DP1
1268                  PJTY(LQT(MT),NTJ(LQT(MT)))=DP2
1269                  PJTZ(LQT(MT),NTJ(LQT(MT)))=DP3
1270                  PJTE(LQT(MT),NTJ(LQT(MT)))=DP
1271                  PJTM(LQT(MT),NTJ(LQT(MT)))=0.0
1272 
1273  260             PJPX(JP,I)=(PTOT-DP)*V1
1274                  PJPY(JP,I)=(PTOT-DP)*V2
1275                  PJPZ(JP,I)=(PTOT-DP)*V3
1276                  PJPE(JP,I)=PJPE(JP,I)-DE
1277 
1278                  PTOT=PTOT-DP
1279                  NQ=NQ+1
1280                  GO TO 200
1281  290          CONTINUE
1282 
1283               RETURN
1284 
1285 C*******************************************************
1286 C Jet interaction for target jet in the direction PHIT
1287 C******************************************************
1288 C
1289 C******* find the wounded proj which can interact with jet***
1290 
1291  400          IF(NFT(JPJT,7).NE.1) RETURN
1292               JT=JPJT
1293               DO 690 I=1,NTJ(JT)
1294                  PTJET0=SQRT(PJTX(JT,I)**2+PJTY(JT,I)**2)
1295                  IF(PTJET0.LE.HIPR1(11)) GO TO 690
1296                  PTOT=SQRT(PTJET0*PTJET0+PJTZ(JT,I)**2)
1297                  IF(PTOT.LT.HIPR1(8)) GO TO 690
1298                  PHIT=ULANGL(PJTX(JT,I),PJTY(JT,I))
1299                  KP=0
1300                  DO 500 I2=1,IHNT2(1)
1301                     IF(NFP(I2,5).NE.3) GO TO 500
1302                     DX=YP(1,I2)+BBX-YT(1,JT)
1303                     DY=YP(2,I2)+BBY-YT(2,JT)
1304                     PHI=ULANGL(DX,DY)
1305                     DPHI=ABS(PHI-PHIT)
1306                     IF(DPHI.GE.HIPR1(40)) DPHI=2.*HIPR1(40)-DPHI ! Uzhi
1307                     IF(DPHI.GT.HIPR1(40)/2.0) GO TO 500
1308                     RD0=SQRT(DX*DX+DY*DY)
1309                     IF(RD0*SIN(DPHI).GT.HIPR1(12)) GO TO 500
1310                     KP=KP+1
1311                     LQP(KP)=I2
1312                     RDP(KP)=COS(DPHI)*RD0
1313  500             CONTINUE
1314 C*******        rearrange according to decending rd************
1315                  DO 510 I2=1,KP-1
1316                     DO 510 J2=I2+1,KP
1317                        IF(RDP(I2).LT.RDP(J2)) GO TO 510
1318                        RD=RDP(I2)
1319                        LQ=LQP(I2)
1320                        RDP(I2)=RDP(J2)
1321                        LQP(I2)=LQP(J2)
1322                        RDP(J2)=RD
1323                        LQP(J2)=LQ
1324  510                CONTINUE
1325 C****** find wounded targ which can interact with jet********
1326                     KT=0
1327                     DO 520 I2=1,IHNT2(3)
1328                        IF(NFT(I2,5).NE.3 .OR. I2.EQ.JT) GO TO 520
1329                        DX=YT(1,I2)-YT(1,JT)
1330                        DY=YT(2,I2)-YT(2,JT)
1331                        PHI=ULANGL(DX,DY)
1332                        DPHI=ABS(PHI-PHIT)
1333                        IF(DPHI.GE.HIPR1(40)) DPHI=2.*HIPR1(40)-DPHI ! Uzhi
1334                        IF(DPHI.GT.HIPR1(40)/2.0) GO TO 520
1335                        RD0=SQRT(DX*DX+DY*DY)
1336                        IF(RD0*SIN(DPHI).GT.HIPR1(12)) GO TO 520
1337                        KT=KT+1
1338                        LQT(KT)=I2
1339                        RDT(KT)=COS(DPHI)*RD0
1340  520                CONTINUE
1341 C*******        rearrange according to decending rd************
1342                     DO 530 I2=1,KT-1
1343                        DO 530 J2=I2+1,KT
1344                           IF(RDT(I2).LT.RDT(J2)) GO TO 530
1345                           RD=RDT(I2)
1346                           LQ=LQT(I2)
1347                           RDT(I2)=RDT(J2)
1348                           LQT(I2)=LQT(J2)
1349                           RDT(J2)=RD
1350                           LQT(J2)=LQ
1351  530                   CONTINUE
1352                        
1353                        MP=0
1354                        MT=0
1355                        NQ=0
1356                        DP=0.0
1357                        R0=0.0
1358                 PTOT=SQRT(PJTX(JT,I)**2+PJTY(JT,I)**2+PJTZ(JT,I)**2)
1359                 V1=PJTX(JT,I)/PTOT
1360                 V2=PJTY(JT,I)/PTOT
1361                 V3=PJTZ(JT,I)/PTOT
1362 
1363  600            RN=RLU(0)
1364  610            IF(MT.GE.KT .AND. MP.GE.KP) GO TO 690
1365                 IF(MT.GE.KT) GO TO 620
1366                 IF(MP.GE.KP) GO TO 640
1367                 IF(RDP(MP+1).GT.RDT(MT+1)) GO TO 640
1368 620             MP=MP+1
1369                 DRR=RDP(MP)-R0
1370                 IF(RN.GE.1.0-EXP(-DRR/HIPR1(13))) GO TO 610
1371                 DP=DRR*HIPR1(14)
1372                 IF(KFTJ(JT,I).NE.21) DP=0.5*DP
1373 C       ********string tension of quark jet is 0.5 of gluon's 
1374                 IF(DP.LE.0.2) GO TO 610
1375                 IF(PTOT.LE.0.4) GO TO 690
1376                 IF(PTOT.LE.DP) DP=PTOT-0.2
1377                 DE=DP
1378 C
1379                 IF(KFTJ(JT,I).NE.21) THEN
1380                    PRSHU=PP(LQP(MP),1)**2+PP(LQP(MP),2)**2
1381      &                   +PP(LQP(MP),3)**2
1382                    DE=SQRT(PJTM(JT,I)**2+PTOT**2)
1383      &               -SQRT(PJTM(JT,I)**2+(PTOT-DP)**2)
1384                    ERSHU=(PP(LQP(MP),4)+DE-DP)**2
1385                    AMSHU=ERSHU-PRSHU
1386                    IF(AMSHU.LT.HIPR1(1)*HIPR1(1)) GO TO 610
1387                    PP(LQP(MP),4)=SQRT(ERSHU)
1388                    PP(LQP(MP),5)=SQRT(AMSHU)
1389                 ENDIF
1390 C               ********reshuffle the energy when jet has mass
1391 C
1392                 R0=RDP(MP)
1393                 DP1=DP*V1
1394                 DP2=DP*V2
1395                 DP3=DP*V3
1396 C               ********momentum and energy transfer from jet
1397                 NPJ(LQP(MP))=NPJ(LQP(MP))+1
1398                 KFPJ(LQP(MP),NPJ(LQP(MP)))=21
1399                 PJPX(LQP(MP),NPJ(LQP(MP)))=DP1
1400                 PJPY(LQP(MP),NPJ(LQP(MP)))=DP2
1401                 PJPZ(LQP(MP),NPJ(LQP(MP)))=DP3
1402                 PJPE(LQP(MP),NPJ(LQP(MP)))=DP
1403                 PJPM(LQP(MP),NPJ(LQP(MP)))=0.0
1404 
1405                 GO TO 660
1406 
1407 640             MT=MT+1
1408                 DRR=RDT(MT)-R0
1409                 IF(RN.GE.1.0-EXP(-DRR/HIPR1(13))) GO TO 610
1410                 DP=DRR*HIPR1(14)
1411                 IF(DP.LE.0.2) GO TO 610
1412                 IF(PTOT.LE.0.4) GO TO 690
1413                 IF(PTOT.LE.DP) DP=PTOT-0.2
1414                 DE=DP
1415 
1416                 IF(KFTJ(JT,I).NE.21) THEN
1417                    PRSHU=PT(LQT(MT),1)**2+PT(LQT(MT),2)**2
1418      &                   +PT(LQT(MT),3)**2
1419                    DE=SQRT(PJTM(JT,I)**2+PTOT**2)
1420      &               -SQRT(PJTM(JT,I)**2+(PTOT-DP)**2)
1421                    ERSHU=(PT(LQT(MT),4)+DE-DP)**2
1422                    AMSHU=ERSHU-PRSHU
1423                    IF(AMSHU.LT.HIPR1(1)*HIPR1(1)) GO TO 610
1424                    PT(LQT(MT),4)=SQRT(ERSHU)
1425                    PT(LQT(MT),5)=SQRT(AMSHU)
1426                 ENDIF
1427 C               ********reshuffle the energy when jet has mass
1428 
1429                 R0=RDT(MT)
1430                 DP1=DP*V1
1431                 DP2=DP*V2
1432                 DP3=DP*V3
1433 C               ********momentum and energy transfer from jet
1434                 NTJ(LQT(MT))=NTJ(LQT(MT))+1
1435                 KFTJ(LQT(MT),NTJ(LQT(MT)))=21
1436                 PJTX(LQT(MT),NTJ(LQT(MT)))=DP1
1437                 PJTY(LQT(MT),NTJ(LQT(MT)))=DP2
1438                 PJTZ(LQT(MT),NTJ(LQT(MT)))=DP3
1439                 PJTE(LQT(MT),NTJ(LQT(MT)))=DP
1440                 PJTM(LQT(MT),NTJ(LQT(MT)))=0.0
1441 
1442 660             PJTX(JT,I)=(PTOT-DP)*V1
1443                 PJTY(JT,I)=(PTOT-DP)*V2
1444                 PJTZ(JT,I)=(PTOT-DP)*V3
1445                 PJTE(JT,I)=PJTE(JT,I)-DE
1446 
1447                 PTOT=PTOT-DP
1448                 NQ=NQ+1
1449                 GO TO 600
1450 690     CONTINUE
1451         RETURN
1452 C********************************************************
1453 C       Q-QBAR jet interaction
1454 C********************************************************
1455 2000    ISG=JPJT
1456         IF(IASG(ISG,3).NE.1) RETURN
1457 C
1458         JP=IASG(ISG,1)
1459         JT=IASG(ISG,2)
1460         XJ=(YP(1,JP)+BBX+YT(1,JT))/2.0
1461         YJ=(YP(2,JP)+BBY+YT(2,JT))/2.0
1462         DO 2690 I=1,NJSG(ISG)
1463            PTJET0=SQRT(PXSG(ISG,I)**2+PYSG(ISG,I)**2)
1464            IF(PTJET0.LE.HIPR1(11).OR.PESG(ISG,I).LT.HIPR1(1))
1465      &            GO TO 2690
1466            PTOT=SQRT(PTJET0*PTJET0+PZSG(ISG,I)**2)
1467            IF(PTOT.LT.MAX(HIPR1(1),HIPR1(8))) GO TO 2690
1468            PHIQ=ULANGL(PXSG(ISG,I),PYSG(ISG,I))
1469            KP=0
1470            DO 2500 I2=1,IHNT2(1)
1471               IF(NFP(I2,5).NE.3.OR.I2.EQ.JP) GO TO 2500
1472               DX=YP(1,I2)+BBX-XJ
1473               DY=YP(2,I2)+BBY-YJ
1474               PHI=ULANGL(DX,DY)
1475               DPHI=ABS(PHI-PHIQ)
1476               IF(DPHI.GE.HIPR1(40)) DPHI=2.*HIPR1(40)-DPHI      ! Uzhi
1477               IF(DPHI.GT.HIPR1(40)/2.0) GO TO 2500
1478               RD0=SQRT(DX*DX+DY*DY)
1479               IF(RD0*SIN(DPHI).GT.HIPR1(12)) GO TO 2500
1480               KP=KP+1
1481               LQP(KP)=I2
1482               RDP(KP)=COS(DPHI)*RD0
1483  2500      CONTINUE
1484 C*******        rearrange according to decending rd************
1485            DO 2510 I2=1,KP-1
1486               DO 2510 J2=I2+1,KP
1487                  IF(RDP(I2).LT.RDP(J2)) GO TO 2510
1488                  RD=RDP(I2)
1489                  LQ=LQP(I2)
1490                  RDP(I2)=RDP(J2)
1491                  LQP(I2)=LQP(J2)
1492                  RDP(J2)=RD
1493                  LQP(J2)=LQ
1494  2510         CONTINUE
1495 C****** find wounded targ which can interact with jet********
1496               KT=0
1497               DO 2520 I2=1,IHNT2(3)
1498                  IF(NFT(I2,5).NE.3 .OR. I2.EQ.JT) GO TO 2520
1499                  DX=YT(1,I2)-XJ
1500                  DY=YT(2,I2)-YJ
1501                  PHI=ULANGL(DX,DY)
1502                  DPHI=ABS(PHI-PHIQ)
1503                  IF(DPHI.GE.HIPR1(40)) DPHI=2.*HIPR1(40)-DPHI ! Uzhi
1504                  IF(DPHI.GT.HIPR1(40)/2.0) GO TO 2520
1505                  RD0=SQRT(DX*DX+DY*DY)
1506                  IF(RD0*SIN(DPHI).GT.HIPR1(12)) GO TO 2520
1507                  KT=KT+1
1508                  LQT(KT)=I2
1509                  RDT(KT)=COS(DPHI)*RD0
1510  2520         CONTINUE
1511 C*******        rearrange according to decending rd************
1512               DO 2530 I2=1,KT-1
1513                  DO 2530 J2=I2+1,KT
1514                     IF(RDT(I2).LT.RDT(J2)) GO TO 2530
1515                     RD=RDT(I2)
1516                     LQ=LQT(I2)
1517                     RDT(I2)=RDT(J2)
1518                     LQT(I2)=LQT(J2)
1519                     RDT(J2)=RD
1520                     LQT(J2)=LQ
1521  2530            CONTINUE
1522                 
1523                  MP=0
1524                  MT=0
1525                  NQ=0
1526                  DP=0.0
1527                  R0=0.0
1528                  PTOT=SQRT(PXSG(ISG,I)**2+PYSG(ISG,I)**2
1529      &                +PZSG(ISG,I)**2)
1530                  V1=PXSG(ISG,I)/PTOT
1531                  V2=PYSG(ISG,I)/PTOT
1532                  V3=PZSG(ISG,I)/PTOT
1533 
1534  2600            RN=RLU(0)
1535  2610            IF(MT.GE.KT .AND. MP.GE.KP) GO TO 2690
1536                  IF(MT.GE.KT) GO TO 2620
1537                  IF(MP.GE.KP) GO TO 2640
1538                  IF(RDP(MP+1).GT.RDT(MT+1)) GO TO 2640
1539  2620            MP=MP+1
1540                  DRR=RDP(MP)-R0
1541                  IF(RN.GE.1.0-EXP(-DRR/HIPR1(13))) GO TO 2610
1542                  DP=DRR*HIPR1(14)/2.0
1543                  IF(DP.LE.0.2) GO TO 2610
1544                  IF(PTOT.LE.0.4) GO TO 2690
1545                  IF(PTOT.LE.DP) DP=PTOT-0.2
1546                  DE=DP
1547 C
1548                  IF(K2SG(ISG,I).NE.21) THEN
1549                     IF(PTOT.LT.DP+HIPR1(1)) GO TO 2690
1550                     PRSHU=PP(LQP(MP),1)**2+PP(LQP(MP),2)**2
1551      &                    +PP(LQP(MP),3)**2
1552                     DE=SQRT(PMSG(ISG,I)**2+PTOT**2)
1553      &                 -SQRT(PMSG(ISG,I)**2+(PTOT-DP)**2)
1554                     ERSHU=(PP(LQP(MP),4)+DE-DP)**2
1555                     AMSHU=ERSHU-PRSHU
1556                     IF(AMSHU.LT.HIPR1(1)*HIPR1(1)) GO TO 2610
1557                     PP(LQP(MP),4)=SQRT(ERSHU)
1558                     PP(LQP(MP),5)=SQRT(AMSHU)
1559                  ENDIF
1560 C               ********reshuffle the energy when jet has mass
1561 C
1562                  R0=RDP(MP)
1563                  DP1=DP*V1
1564                  DP2=DP*V2
1565                  DP3=DP*V3
1566 C               ********momentum and energy transfer from jet
1567                  NPJ(LQP(MP))=NPJ(LQP(MP))+1
1568                  KFPJ(LQP(MP),NPJ(LQP(MP)))=21
1569                  PJPX(LQP(MP),NPJ(LQP(MP)))=DP1
1570                  PJPY(LQP(MP),NPJ(LQP(MP)))=DP2
1571                  PJPZ(LQP(MP),NPJ(LQP(MP)))=DP3
1572                  PJPE(LQP(MP),NPJ(LQP(MP)))=DP
1573                  PJPM(LQP(MP),NPJ(LQP(MP)))=0.0
1574 
1575                  GO TO 2660
1576 
1577  2640            MT=MT+1
1578                  DRR=RDT(MT)-R0
1579                  IF(RN.GE.1.0-EXP(-DRR/HIPR1(13))) GO TO 2610
1580                  DP=DRR*HIPR1(14)
1581                  IF(DP.LE.0.2) GO TO 2610
1582                  IF(PTOT.LE.0.4) GO TO 2690
1583                  IF(PTOT.LE.DP) DP=PTOT-0.2
1584                  DE=DP
1585 
1586                  IF(K2SG(ISG,I).NE.21) THEN
1587                     IF(PTOT.LT.DP+HIPR1(1)) GO TO 2690
1588                     PRSHU=PT(LQT(MT),1)**2+PT(LQT(MT),2)**2
1589      &                    +PT(LQT(MT),3)**2
1590                     DE=SQRT(PMSG(ISG,I)**2+PTOT**2)
1591      &                 -SQRT(PMSG(ISG,I)**2+(PTOT-DP)**2)
1592                     ERSHU=(PT(LQT(MT),4)+DE-DP)**2
1593                     AMSHU=ERSHU-PRSHU
1594                     IF(AMSHU.LT.HIPR1(1)*HIPR1(1)) GO TO 2610
1595                     PT(LQT(MT),4)=SQRT(ERSHU)
1596                     PT(LQT(MT),5)=SQRT(AMSHU)
1597                  ENDIF
1598 C               ********reshuffle the energy when jet has mass
1599 
1600                  R0=RDT(MT)
1601                  DP1=DP*V1
1602                  DP2=DP*V2
1603                  DP3=DP*V3
1604 C               ********momentum and energy transfer from jet
1605                  NTJ(LQT(MT))=NTJ(LQT(MT))+1
1606                  KFTJ(LQT(MT),NTJ(LQT(MT)))=21
1607                  PJTX(LQT(MT),NTJ(LQT(MT)))=DP1
1608                  PJTY(LQT(MT),NTJ(LQT(MT)))=DP2
1609                  PJTZ(LQT(MT),NTJ(LQT(MT)))=DP3
1610                  PJTE(LQT(MT),NTJ(LQT(MT)))=DP
1611                  PJTM(LQT(MT),NTJ(LQT(MT)))=0.0
1612 
1613  2660            PXSG(ISG,I)=(PTOT-DP)*V1
1614                  PYSG(ISG,I)=(PTOT-DP)*V2
1615                  PZSG(ISG,I)=(PTOT-DP)*V3
1616                  PESG(ISG,I)=PESG(ISG,I)-DE
1617 
1618                  PTOT=PTOT-DP
1619                  NQ=NQ+1
1620                  GO TO 2600
1621  2690   CONTINUE
1622         RETURN
1623         END
1624 
1625 C
1626 C
1627 C
1628 C
1629         SUBROUTINE HIJFRG(JTP,NTP,IERROR)
1630 C       NTP=1, fragment proj string, NTP=2, targ string, 
1631 C       NTP=3, independent 
1632 C       strings from jets.  JTP is the line number of the string
1633 C*******Fragment all leading strings of proj and targ**************
1634 C       IHNT2(1)=atomic #, IHNT2(2)=proton #(=-1 if anti-proton)  *
1635 C******************************************************************
1636         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
1637         SAVE  /HIPARNT/
1638         COMMON/HIJDAT/HIDAT0(10,10),HIDAT(10)
1639         SAVE  /HIJDAT/
1640         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
1641         SAVE  /HISTRNG/
1642         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
1643      &                PJPY(300,500),PJPZ(300,500),PJPE(300,500),
1644      &                PJPM(300,500),NTJ(300),KFTJ(300,500),
1645      &                PJTX(300,500),PJTY(300,500),PJTZ(300,500),
1646      &                PJTE(300,500),PJTM(300,500)
1647         SAVE  /HIJJET1/
1648         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
1649      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
1650      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
1651         SAVE  /HIJJET2/
1652 C
1653         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
1654         SAVE  /LUJETS/
1655         COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
1656         SAVE  /LUDAT1/
1657         COMMON/RANSEED/NSEED
1658         SAVE  /RANSEED/
1659         
1660         IERROR=0
1661         CALL LUEDIT(0)
1662         N=0
1663 C                       ********initialize the document lines
1664         IF(NTP.EQ.3) THEN
1665                 ISG=JTP
1666                 N=NJSG(ISG)
1667                 DO 100 I=1,NJSG(ISG)
1668                         K(I,1)=K1SG(ISG,I)
1669                         K(I,2)=K2SG(ISG,I)
1670                         P(I,1)=PXSG(ISG,I)
1671                         P(I,2)=PYSG(ISG,I)
1672                         P(I,3)=PZSG(ISG,I)
1673                         P(I,4)=PESG(ISG,I)
1674                         P(I,5)=PMSG(ISG,I)
1675 100             CONTINUE
1676 C               IF(IHPR2(1).GT.0) CALL ATTRAD(IERROR)
1677 c               IF(IERROR.NE.0) RETURN
1678 C               CALL LULIST(1)
1679                 CALL LUEXEC
1680                 RETURN
1681         ENDIF
1682 C
1683         IF(NTP.EQ.2) GO TO 200
1684         IF(JTP.GT.IHNT2(1))   RETURN
1685         IF(NFP(JTP,5).NE.3.AND.NFP(JTP,3).NE.0
1686      &      .AND.NPJ(JTP).EQ.0.AND.NFP(JTP,10).EQ.0) GO TO 1000
1687         IF(NFP(JTP,15).EQ.-1) THEN
1688                 KF1=NFP(JTP,2)
1689                 KF2=NFP(JTP,1)
1690                 PQ21=PP(JTP,6)
1691                 PQ22=PP(JTP,7)
1692                 PQ11=PP(JTP,8)
1693                 PQ12=PP(JTP,9)
1694                 AM1=PP(JTP,15)
1695                 AM2=PP(JTP,14)
1696         ELSE
1697                 KF1=NFP(JTP,1)
1698                 KF2=NFP(JTP,2)
1699                 PQ21=PP(JTP,8)
1700                 PQ22=PP(JTP,9)
1701                 PQ11=PP(JTP,6)
1702                 PQ12=PP(JTP,7)
1703                 AM1=PP(JTP,14)
1704                 AM2=PP(JTP,15)  
1705         ENDIF
1706 C       ********for NFP(JTP,15)=-1 NFP(JTP,1) IS IN -Z DIRECTION
1707         PB1=PQ11+PQ21
1708         PB2=PQ12+PQ22
1709         PB3=PP(JTP,3)
1710         PECM=PP(JTP,5)
1711         BTZ=PB3/PP(JTP,4)
1712         IF((ABS(PB1-PP(JTP,1)).GT.0.01.OR.
1713      &    ABS(PB2-PP(JTP,2)).GT.0.01).AND.IHPR2(10).NE.0)
1714      &    WRITE(6,*) '  Pt of Q and QQ do not sum to the total'
1715 
1716         GO TO 300
1717 
1718 200     IF(JTP.GT.IHNT2(3))  RETURN
1719         IF(NFT(JTP,5).NE.3.AND.NFT(JTP,3).NE.0
1720      &     .AND.NTJ(JTP).EQ.0.AND.NFT(JTP,10).EQ.0) GO TO 1200
1721         IF(NFT(JTP,15).EQ.1) THEN
1722                 KF1=NFT(JTP,1)
1723                 KF2=NFT(JTP,2)
1724                 PQ11=PT(JTP,6)
1725                 PQ12=PT(JTP,7)
1726                 PQ21=PT(JTP,8)
1727                 PQ22=PT(JTP,9)
1728                 AM1=PT(JTP,14)
1729                 AM2=PT(JTP,15)
1730         ELSE
1731                 KF1=NFT(JTP,2)
1732                 KF2=NFT(JTP,1)
1733                 PQ11=PT(JTP,8)
1734                 PQ12=PT(JTP,9)
1735                 PQ21=PT(JTP,6)
1736                 PQ22=PT(JTP,7)
1737                 AM1=PT(JTP,15)
1738                 AM2=PT(JTP,14)
1739         ENDIF   
1740 C       ********for NFT(JTP,15)=1 NFT(JTP,1) IS IN +Z DIRECTION
1741         PB1=PQ11+PQ21
1742         PB2=PQ12+PQ22
1743         PB3=PT(JTP,3)
1744         PECM=PT(JTP,5)
1745         BTZ=PB3/PT(JTP,4)
1746 
1747         IF((ABS(PB1-PT(JTP,1)).GT.0.01.OR.
1748      &     ABS(PB2-PT(JTP,2)).GT.0.01).AND.IHPR2(10).NE.0)
1749      &     WRITE(6,*) '  Pt of Q and QQ do not sum to the total'
1750 
1751 300     IF(PECM.LT.HIPR1(1)) THEN
1752            IERROR=1
1753            IF(IHPR2(10).EQ.0) RETURN
1754            WRITE(6,*) ' ECM=',PECM,' energy of the string is too small'
1755            RETURN
1756         ENDIF
1757         AMT=PECM**2+PB1**2+PB2**2
1758         AMT1=AM1**2+PQ11**2+PQ12**2
1759         AMT2=AM2**2+PQ21**2+PQ22**2
1760         PZCM=SQRT(ABS(AMT**2+AMT1**2+AMT2**2-2.0*AMT*AMT1
1761      &       -2.0*AMT*AMT2-2.0*AMT1*AMT2))/2.0/SQRT(AMT)
1762 C               *******PZ of end-partons in c.m. frame of the string
1763         K(1,1)=2
1764         K(1,2)=KF1
1765         P(1,1)=PQ11
1766         P(1,2)=PQ12
1767         P(1,3)=PZCM
1768         P(1,4)=SQRT(AMT1+PZCM**2)
1769         P(1,5)=AM1
1770         K(2,1)=1
1771         K(2,2)=KF2
1772         P(2,1)=PQ21
1773         P(2,2)=PQ22
1774         P(2,3)=-PZCM
1775         P(2,4)=SQRT(AMT2+PZCM**2)
1776         P(2,5)=AM2
1777         N=2
1778 C*****
1779         CALL HIROBO(0.0,0.0,0.0,0.0,BTZ)
1780         JETOT=0
1781         IF((PQ21**2+PQ22**2).GT.(PQ11**2+PQ12**2)) THEN
1782                 PMAX1=P(2,1)
1783                 PMAX2=P(2,2)
1784                 PMAX3=P(2,3)
1785         ELSE
1786                 PMAX1=P(1,1)
1787                 PMAX2=P(1,2)
1788                 PMAX3=P(1,3)
1789         ENDIF
1790         IF(NTP.EQ.1) THEN
1791                 PP(JTP,10)=PMAX1
1792                 PP(JTP,11)=PMAX2
1793                 PP(JTP,12)=PMAX3
1794         ELSE IF(NTP.EQ.2) THEN
1795                 PT(JTP,10)=PMAX1
1796                 PT(JTP,11)=PMAX2
1797                 PT(JTP,12)=PMAX3
1798         ENDIF
1799 C*******************attach produced jets to the leading partons****
1800         IF(NTP.EQ.1.AND.NPJ(JTP).NE.0) THEN
1801                 JETOT=NPJ(JTP)
1802 C               IF(NPJ(JTP).GE.2) CALL HIJSRT(JTP,1)
1803 C                       ********sort jets in order of y
1804                 IEX=0
1805                 IF((ABS(KF1).GT.1000.AND.KF1.LT.0)
1806      &                  .OR.(ABS(KF1).LT.1000.AND.KF1.GT.0)) IEX=1
1807                 DO 520 I=N,2,-1
1808                 DO 520 J=1,5
1809                         II=NPJ(JTP)+I
1810                         K(II,J)=K(I,J)
1811                         P(II,J)=P(I,J)
1812                         V(II,J)=V(I,J)
1813 520             CONTINUE
1814                 DO 540 I=1,NPJ(JTP)
1815                         DO 542 J=1,5
1816                                 K(I+1,J)=0
1817                                 V(I+1,J)=0
1818 542                     CONTINUE                                
1819                         I0=I
1820                         IF(IEX.EQ.1) I0=NPJ(JTP)-I+1
1821 C                               ********reverse the order of jets
1822                         KK1=KFPJ(JTP,I0)
1823                         K(I+1,1)=2
1824                         K(I+1,2)=KK1
1825                         IF(KK1.NE.21 .AND. KK1.NE.0)  K(I+1,1)=
1826      &                    1+(ABS(KK1)+(2*IEX-1)*KK1)/2/ABS(KK1)
1827                         P(I+1,1)=PJPX(JTP,I0)
1828                         P(I+1,2)=PJPY(JTP,I0)
1829                         P(I+1,3)=PJPZ(JTP,I0)
1830                         P(I+1,4)=PJPE(JTP,I0)
1831                         P(I+1,5)=PJPM(JTP,I0)
1832 540             CONTINUE
1833                 N=N+NPJ(JTP)
1834         ELSE IF(NTP.EQ.2.AND.NTJ(JTP).NE.0) THEN
1835                 JETOT=NTJ(JTP)
1836 c               IF(NTJ(JTP).GE.2)  CALL HIJSRT(JTP,2)
1837 C                       ********sort jets in order of y
1838                 IEX=1
1839                 IF((ABS(KF2).GT.1000.AND.KF2.LT.0)
1840      &                  .OR.(ABS(KF2).LT.1000.AND.KF2.GT.0)) IEX=0
1841                 DO 560 I=N,2,-1
1842                 DO 560 J=1,5
1843                         II=NTJ(JTP)+I
1844                         K(II,J)=K(I,J)
1845                         P(II,J)=P(I,J)
1846                         V(II,J)=V(I,J)
1847 560             CONTINUE
1848                 DO 580 I=1,NTJ(JTP)
1849                         DO 582 J=1,5
1850                                 K(I+1,J)=0
1851                                 V(I+1,J)=0
1852 582                     CONTINUE                                
1853                         I0=I
1854                         IF(IEX.EQ.1) I0=NTJ(JTP)-I+1
1855 C                               ********reverse the order of jets
1856                         KK1=KFTJ(JTP,I0)
1857                         K(I+1,1)=2
1858                         K(I+1,2)=KK1
1859                         IF(KK1.NE.21 .AND. KK1.NE.0) K(I+1,1)=
1860      &                     1+(ABS(KK1)+(2*IEX-1)*KK1)/2/ABS(KK1)
1861                         P(I+1,1)=PJTX(JTP,I0)
1862                         P(I+1,2)=PJTY(JTP,I0)
1863                         P(I+1,3)=PJTZ(JTP,I0)
1864                         P(I+1,4)=PJTE(JTP,I0)
1865                         P(I+1,5)=PJTM(JTP,I0)
1866 580             CONTINUE
1867                 N=N+NTJ(JTP)
1868         ENDIF
1869         IF(IHPR2(1).GT.0.AND.RLU(0).LE.HIDAT(3)) THEN
1870              HIDAT20=HIDAT(2)
1871              HIPR150=HIPR1(5)
1872              IF(IHPR2(8).EQ.0.AND.IHPR2(3).EQ.0.AND.IHPR2(9).EQ.0)
1873      &                  HIDAT(2)=2.0
1874              IF(HINT1(1).GE.1000.0.AND.JETOT.EQ.0)THEN
1875                 HIDAT(2)=3.0
1876                 HIPR1(5)=5.0
1877              ENDIF
1878              CALL ATTRAD(IERROR)
1879              HIDAT(2)=HIDAT20
1880              HIPR1(5)=HIPR150
1881         ELSE IF(JETOT.EQ.0.AND.IHPR2(1).GT.0.AND.
1882      &                       HINT1(1).GE.1000.0.AND.
1883      &          RLU(0).LE.0.8) THEN
1884                 HIDAT20=HIDAT(2)
1885                 HIPR150=HIPR1(5)
1886                 HIDAT(2)=3.0
1887                 HIPR1(5)=5.0
1888              IF(IHPR2(8).EQ.0.AND.IHPR2(3).EQ.0.AND.IHPR2(9).EQ.0)
1889      &                  HIDAT(2)=2.0
1890                 CALL ATTRAD(IERROR)
1891                 HIDAT(2)=HIDAT20
1892                 HIPR1(5)=HIPR150
1893         ENDIF
1894         IF(IERROR.NE.0) RETURN
1895 C               ******** conduct soft radiations
1896 C****************************
1897 C
1898 C
1899 C       CALL LULIST(1)
1900         CALL LUEXEC
1901         RETURN
1902 
1903 1000    N=1
1904         K(1,1)=1
1905         K(1,2)=NFP(JTP,3)
1906         DO 1100 JJ=1,5
1907                 P(1,JJ)=PP(JTP,JJ)
1908 1100            CONTINUE
1909 C                       ********proj remain as a nucleon or delta
1910         CALL LUEXEC
1911 C       call lulist(1)
1912         RETURN
1913 C
1914 1200    N=1
1915         K(1,1)=1
1916         K(1,2)=NFT(JTP,3)
1917         DO 1300 JJ=1,5
1918                 P(1,JJ)=PT(JTP,JJ)
1919 1300    CONTINUE
1920 C                       ********targ remain as a nucleon or delta
1921         CALL LUEXEC
1922 C       call lulist(1)
1923         RETURN
1924         END
1925 C
1926 C
1927 C
1928 C********************************************************************
1929 C       Sort the jets associated with a nucleon in order of their
1930 C       rapdities
1931 C********************************************************************
1932         SUBROUTINE HIJSRT(JPJT,NPT)
1933         DIMENSION KF(100),PX(100),PY(100),PZ(100),PE(100),PM(100)
1934         DIMENSION Y(100),IP(100,2)
1935         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
1936      &                PJPY(300,500),PJPZ(300,500),PJPE(300,500),
1937      &                PJPM(300,500),NTJ(300),KFTJ(300,500),
1938      &                PJTX(300,500),PJTY(300,500),PJTZ(300,500),
1939      &                PJTE(300,500),PJTM(300,500)
1940         SAVE  /HIJJET1/
1941         IF(NPT.EQ.2) GO TO 500
1942         JP=JPJT
1943         IQ=0
1944         I=1
1945 100     KF(I)=KFPJ(JP,I)
1946         PX(I)=PJPX(JP,I)
1947         PY(I)=PJPY(JP,I)
1948         PZ(I)=PJPZ(JP,I)
1949         PE(I)=PJPE(JP,I)
1950         PM(I)=PJPM(JP,I)
1951         Y(I-IQ)=0.5*ALOG((ABS(PE(I)+PZ(I))+1.E-5)
1952      &          /(ABS(PE(I)-PZ(I))+1.E-5))
1953         IP(I-IQ,1)=I
1954         IP(I-IQ,2)=0
1955         IF(KF(I).NE.21) THEN
1956                 IP(I-IQ,2)=1
1957                 IQ=IQ+1
1958                 I=I+1
1959                 KF(I)=KFPJ(JP,I)
1960                 PX(I)=PJPX(JP,I)
1961                 PY(I)=PJPY(JP,I)
1962                 PZ(I)=PJPZ(JP,I)
1963                 PE(I)=PJPE(JP,I)
1964                 PM(I)=PJPM(JP,I)
1965         ENDIF
1966         I=I+1
1967         IF(I.LE.NPJ(JP)) GO TO 100
1968                         
1969         DO 200 I=1,NPJ(JP)-IQ
1970         DO 200 J=I+1,NPJ(JP)-IQ
1971                 IF(Y(I).GT.Y(J)) GO TO 200
1972                 IP1=IP(I,1)
1973                 IP2=IP(I,2)
1974                 IP(I,1)=IP(J,1)
1975                 IP(I,2)=IP(J,2)
1976                 IP(J,1)=IP1
1977                 IP(J,2)=IP2
1978 200     CONTINUE
1979 C                       ********sort in decending y
1980         IQQ=0
1981         I=1
1982 300     KFPJ(JP,I)=KF(IP(I-IQQ,1))
1983         PJPX(JP,I)=PX(IP(I-IQQ,1))
1984         PJPY(JP,I)=PY(IP(I-IQQ,1))
1985         PJPZ(JP,I)=PZ(IP(I-IQQ,1))
1986         PJPE(JP,I)=PE(IP(I-IQQ,1))
1987         PJPM(JP,I)=PM(IP(I-IQQ,1))
1988         IF(IP(I-IQQ,2).EQ.1) THEN
1989                 KFPJ(JP,I+1)=KF(IP(I-IQQ,1)+1)
1990                 PJPX(JP,I+1)=PX(IP(I-IQQ,1)+1)
1991                 PJPY(JP,I+1)=PY(IP(I-IQQ,1)+1)
1992                 PJPZ(JP,I+1)=PZ(IP(I-IQQ,1)+1)
1993                 PJPE(JP,I+1)=PE(IP(I-IQQ,1)+1)
1994                 PJPM(JP,I+1)=PM(IP(I-IQQ,1)+1)
1995                 I=I+1
1996                 IQQ=IQQ+1
1997         ENDIF
1998         I=I+1
1999         IF(I.LE.NPJ(JP)) GO TO 300
2000 
2001         RETURN
2002 
2003 500     JT=JPJT
2004         IQ=0
2005         I=1
2006 600     KF(I)=KFTJ(JT,I)
2007         PX(I)=PJTX(JT,I)
2008         PY(I)=PJTY(JT,I)
2009         PZ(I)=PJTZ(JT,I)
2010         PE(I)=PJTE(JT,I)
2011         PM(I)=PJTM(JT,I)
2012         Y(I-IQ)=0.5*ALOG((ABS(PE(I)+PZ(I))+1.E-5)
2013      &          /(ABS(PE(I)-PZ(I))+1.E-5))
2014         IP(I-IQ,1)=I
2015         IP(I-IQ,2)=0
2016         IF(KF(I).NE.21) THEN
2017                 IP(I-IQ,2)=1
2018                 IQ=IQ+1
2019                 I=I+1
2020                 KF(I)=KFTJ(JT,I)
2021                 PX(I)=PJTX(JT,I)
2022                 PY(I)=PJTY(JT,I)
2023                 PZ(I)=PJTZ(JT,I)
2024                 PE(I)=PJTE(JT,I)
2025                 PM(I)=PJTM(JT,I)
2026         ENDIF
2027         I=I+1
2028         IF(I.LE.NTJ(JT)) GO TO 600
2029                         
2030         DO 700 I=1,NTJ(JT)-IQ
2031         DO 700 J=I+1,NTJ(JT)-IQ
2032                 IF(Y(I).LT.Y(J)) GO TO 700
2033                 IP1=IP(I,1)
2034                 IP2=IP(I,2)
2035                 IP(I,1)=IP(J,1)
2036                 IP(I,2)=IP(J,2)
2037                 IP(J,1)=IP1
2038                 IP(J,2)=IP2
2039 700     CONTINUE
2040 C                       ********sort in acending y
2041         IQQ=0
2042         I=1
2043 800     KFTJ(JT,I)=KF(IP(I-IQQ,1))
2044         PJTX(JT,I)=PX(IP(I-IQQ,1))
2045         PJTY(JT,I)=PY(IP(I-IQQ,1))
2046         PJTZ(JT,I)=PZ(IP(I-IQQ,1))
2047         PJTE(JT,I)=PE(IP(I-IQQ,1))
2048         PJTM(JT,I)=PM(IP(I-IQQ,1))
2049         IF(IP(I-IQQ,2).EQ.1) THEN
2050                 KFTJ(JT,I+1)=KF(IP(I-IQQ,1)+1)
2051                 PJTX(JT,I+1)=PX(IP(I-IQQ,1)+1)
2052                 PJTY(JT,I+1)=PY(IP(I-IQQ,1)+1)
2053                 PJTZ(JT,I+1)=PZ(IP(I-IQQ,1)+1)
2054                 PJTE(JT,I+1)=PE(IP(I-IQQ,1)+1)
2055                 PJTM(JT,I+1)=PM(IP(I-IQQ,1)+1)
2056                 I=I+1
2057                 IQQ=IQQ+1
2058         ENDIF
2059         I=I+1
2060         IF(I.LE.NTJ(JT)) GO TO 800
2061         RETURN
2062         END     
2063 
2064 C
2065 C
2066 C
2067 C****************************************************************
2068 C       conduct soft radiation according to dipole approxiamtion
2069 C****************************************************************
2070         SUBROUTINE ATTRAD(IERROR)
2071 C
2072         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
2073         SAVE  /HIPARNT/
2074         COMMON/HIJDAT/HIDAT0(10,10),HIDAT(10)
2075         SAVE  /HIJDAT/
2076         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
2077         SAVE  /LUJETS/
2078         IERROR=0
2079 
2080 C.....S INVARIANT MASS-SQUARED BETWEEN PARTONS I AND I+1......
2081 C.....SM IS THE LARGEST MASS-SQUARED....
2082 
2083 40      SM=0.
2084         JL=1
2085         DO 30 I=1,N-1
2086            S=2.*(P(I,4)*P(I+1,4)-P(I,1)*P(I+1,1)-P(I,2)*P(I+1,2)
2087      &          -P(I,3)*P(I+1,3))+P(I,5)**2+P(I+1,5)**2
2088            IF(S.LT.0.) S=0.
2089            WP=SQRT(S)-1.5*(P(I,5)+P(I+1,5))
2090            IF(WP.GT.SM) THEN
2091               PBT1=P(I,1)+P(I+1,1)
2092               PBT2=P(I,2)+P(I+1,2)
2093               PBT3=P(I,3)+P(I+1,3)
2094               PBT4=P(I,4)+P(I+1,4)
2095               BTT=(PBT1**2+PBT2**2+PBT3**2)/PBT4**2
2096               IF(BTT.GE.1.0-1.0E-10) GO TO 30
2097               IF((I.NE.1.OR.I.NE.N-1).AND.
2098      &             (K(I,2).NE.21.AND.K(I+1,2).NE.21)) GO TO 30
2099               JL=I
2100               SM=WP
2101            ENDIF
2102 30      CONTINUE
2103         S=(SM+1.5*(P(JL,5)+P(JL+1,5)))**2
2104         IF(SM.LT.HIPR1(5)) GOTO 2
2105      
2106 C.....MAKE PLACE FOR ONE GLUON.....
2107         IF(JL+1.EQ.N) GOTO 190
2108         DO 160 J=N,JL+2,-1
2109                 K(J+1,1)=K(J,1)
2110                 K(J+1,2)=K(J,2)
2111                 DO 150 M=1,5
2112 150                     P(J+1,M)=P(J,M)
2113 160             CONTINUE
2114 190     N=N+1
2115      
2116 C.....BOOST TO REST SYSTEM FOR PARTICLES JL AND JL+1.....
2117         P1=P(JL,1)+P(JL+1,1)
2118         P2=P(JL,2)+P(JL+1,2)
2119         P3=P(JL,3)+P(JL+1,3)
2120         P4=P(JL,4)+P(JL+1,4)
2121         BEX=-P1/P4
2122         BEY=-P2/P4
2123         BEZ=-P3/P4
2124         IMIN=JL
2125         IMAX=JL+1
2126         CALL ATROBO(0.,0.,BEX,BEY,BEZ,IMIN,IMAX,IERROR)
2127         IF(IERROR.NE.0) RETURN
2128 C.....ROTATE TO Z-AXIS....
2129         CTH=P(JL,3)/SQRT(P(JL,4)**2-P(JL,5)**2)
2130         IF(ABS(CTH).GT.1.0)  CTH=MAX(-1.,MIN(1.,CTH))
2131         THETA=ACOS(CTH)
2132         PHI=ULANGL(P(JL,1),P(JL,2))
2133         CALL ATROBO(0.,-PHI,0.,0.,0.,IMIN,IMAX,IERROR)
2134         CALL ATROBO(-THETA,0.,0.,0.,0.,IMIN,IMAX,IERROR)
2135      
2136 C.....CREATE ONE GLUON AND ORIENTATE.....
2137      
2138 1       CALL AR3JET(S,X1,X3,JL)
2139         CALL ARORIE(S,X1,X3,JL)         
2140         IF(HIDAT(2).GT.0.0) THEN
2141            PTG1=SQRT(P(JL,1)**2+P(JL,2)**2)
2142            PTG2=SQRT(P(JL+1,1)**2+P(JL+1,2)**2)
2143            PTG3=SQRT(P(JL+2,1)**2+P(JL+2,2)**2)
2144            PTG=MAX(PTG1,PTG2,PTG3)
2145            IF(PTG.GT.HIDAT(2)) THEN
2146               FMFACT=EXP(-(PTG**2-HIDAT(2)**2)/HIPR1(2)**2)
2147               IF(RLU(0).GT.FMFACT) GO TO 1
2148            ENDIF
2149         ENDIF
2150 C.....ROTATE AND BOOST BACK.....
2151         IMIN=JL
2152         IMAX=JL+2
2153         CALL ATROBO(THETA,PHI,-BEX,-BEY,-BEZ,IMIN,IMAX,IERROR)
2154         IF(IERROR.NE.0) RETURN
2155 C.....ENUMERATE THE GLUONS.....
2156         K(JL+2,1)=K(JL+1,1)
2157         K(JL+2,2)=K(JL+1,2)
2158         K(JL+2,3)=K(JL+1,3)
2159         K(JL+2,4)=K(JL+1,4)
2160         K(JL+2,5)=K(JL+1,5)
2161         P(JL+2,5)=P(JL+1,5)
2162         K(JL+1,1)=2
2163         K(JL+1,2)=21
2164         K(JL+1,3)=0
2165         K(JL+1,4)=0
2166         K(JL+1,5)=0
2167         P(JL+1,5)=0.
2168 C----THETA FUNCTION DAMPING OF THE EMITTED GLUONS. FOR HADRON-HADRON.
2169 C----R0=VFR(2)
2170 C       IF(VFR(2).GT.0.) THEN
2171 C       PTG=SQRT(P(JL+1,1)**2+P(JL+1,2)**2)
2172 C       PTGMAX=WSTRI/2.
2173 C       DOPT=SQRT((4.*PAR(71)*VFR(2))/WSTRI)
2174 C       PTOPT=(DOPT*WSTRI)/(2.*VFR(2))
2175 C       IF(PTG.GT.PTOPT) IORDER=IORDER-1
2176 C       IF(PTG.GT.PTOPT) GOTO 1
2177 C       ENDIF
2178 C-----
2179         IF(SM.GE.HIPR1(5)) GOTO 40
2180 
2181 2       K(1,1)=2
2182         K(1,3)=0
2183         K(1,4)=0
2184         K(1,5)=0
2185         K(N,1)=1
2186         K(N,3)=0
2187         K(N,4)=0
2188         K(N,5)=0
2189 
2190         RETURN
2191         END
2192 
2193 
2194         SUBROUTINE AR3JET(S,X1,X3,JL)
2195 C     
2196         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
2197         SAVE  /HIPARNT/
2198         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
2199         SAVE  /LUJETS/
2200         COMMON/RANSEED/NSEED
2201         SAVE  /RANSEED/
2202 C     
2203         C=1./3.
2204         IF(K(JL,2).NE.21 .AND. K(JL+1,2).NE.21) C=8./27.
2205         EXP1=3
2206         EXP3=3
2207         IF(K(JL,2).NE.21) EXP1=2
2208         IF(K(JL+1,2).NE.21) EXP3=2
2209         A=0.24**2/S
2210         YMA=ALOG(.5/SQRT(A)+SQRT(.25/A-1))
2211         D=4.*C*YMA
2212         SM1=P(JL,5)**2/S
2213         SM3=P(JL+1,5)**2/S
2214         XT2M=(1.-2.*SQRT(SM1)+SM1-SM3)*(1.-2.*SQRT(SM3)-SM1+SM3)
2215         XT2M=MIN(.25,XT2M)
2216         NTRY=0
2217 1       IF(NTRY.EQ.5000) THEN
2218                 X1=.5*(2.*SQRT(SM1)+1.+SM1-SM3)
2219                 X3=.5*(2.*SQRT(SM3)+1.-SM1+SM3)
2220                 RETURN
2221         ENDIF
2222         NTRY=NTRY+1
2223      
2224         XT2=A*(XT2M/A)**(RLU(0)**(1./D))
2225      
2226         YMAX=ALOG(.5/SQRT(XT2)+SQRT(.25/XT2-1.))
2227         Y=(2.*RLU(0)-1.)*YMAX
2228         X1=1.-SQRT(XT2)*EXP(Y)
2229         X3=1.-SQRT(XT2)*EXP(-Y)
2230         X2=2.-X1-X3
2231         NEG=0
2232         IF(K(JL,2).NE.21 .OR. K(JL+1,2).NE.21) THEN
2233         IF((1.-X1)*(1.-X2)*(1.-X3)-X2*SM1*(1.-X1)-X2*SM3*(1.-X3).
2234      &  LE.0..OR.X1.LE.2.*SQRT(SM1)-SM1+SM3.OR.X3.LE.2.*SQRT(SM3)
2235      &  -SM3+SM1) NEG=1
2236         X1=X1+SM1-SM3
2237         X3=X3-SM1+SM3
2238         ENDIF
2239         IF(NEG.EQ.1) GOTO 1
2240      
2241         FG=2.*YMAX*C*(X1**EXP1+X3**EXP3)/D
2242         XT2M=XT2
2243         IF(FG.LT.RLU(0)) GOTO 1
2244      
2245         RETURN
2246         END
2247 C*************************************************************
2248 
2249 
2250         SUBROUTINE ARORIE(S,X1,X3,JL)
2251 C     
2252         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
2253         SAVE  /HIPARNT/
2254         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
2255         SAVE  /LUJETS/
2256         COMMON/RANSEED/NSEED
2257         SAVE  /RANSEED/
2258 C     
2259         W=SQRT(S)
2260         X2=2.-X1-X3
2261         E1=.5*X1*W
2262         E3=.5*X3*W
2263         P1=SQRT(E1**2-P(JL,5)**2)
2264         P3=SQRT(E3**2-P(JL+1,5)**2)
2265         CBET=1.
2266         IF(P1.GT.0..AND.P3.GT.0.) CBET=(P(JL,5)**2
2267      &           +P(JL+1,5)**2+2.*E1*E3-S*(1.-X2))/(2.*P1*P3)
2268         IF(ABS(CBET).GT.1.0) CBET=MAX(-1.,MIN(1.,CBET))
2269         BET=ACOS(CBET)
2270      
2271 C.....MINIMIZE PT1-SQUARED PLUS PT3-SQUARED.....
2272         IF(P1.GE.P3) THEN
2273            PSI=.5*ULANGL(P1**2+P3**2*COS(2.*BET),-P3**2*SIN(2.*BET))
2274            PT1=P1*SIN(PSI)
2275            PZ1=P1*COS(PSI)
2276            PT3=P3*SIN(PSI+BET)
2277            PZ3=P3*COS(PSI+BET)
2278         ELSE IF(P3.GT.P1) THEN
2279            PSI=.5*ULANGL(P3**2+P1**2*COS(2.*BET),-P1**2*SIN(2.*BET))
2280            PT1=P1*SIN(BET+PSI)
2281            PZ1=-P1*COS(BET+PSI)
2282            PT3=P3*SIN(PSI)
2283            PZ3=-P3*COS(PSI)
2284         ENDIF
2285      
2286         DEL=2.0*HIPR1(40)*RLU(0)
2287         P(JL,4)=E1
2288         P(JL,1)=PT1*SIN(DEL)
2289         P(JL,2)=-PT1*COS(DEL)
2290         P(JL,3)=PZ1
2291         P(JL+2,4)=E3
2292         P(JL+2,1)=PT3*SIN(DEL)
2293         P(JL+2,2)=-PT3*COS(DEL)
2294         P(JL+2,3)=PZ3
2295         P(JL+1,4)=W-E1-E3
2296         P(JL+1,1)=-P(JL,1)-P(JL+2,1)
2297         P(JL+1,2)=-P(JL,2)-P(JL+2,2)
2298         P(JL+1,3)=-P(JL,3)-P(JL+2,3)
2299         RETURN
2300         END
2301 
2302 
2303 C
2304 C*******************************************************************
2305 C       make  boost and rotation to entries from IMIN to IMAX
2306 C*******************************************************************
2307         SUBROUTINE ATROBO(THE,PHI,BEX,BEY,BEZ,IMIN,IMAX,IERROR)
2308         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
2309         SAVE  /LUJETS/
2310         DIMENSION ROT(3,3),PV(3)
2311         DOUBLE PRECISION DP(4),DBEX,DBEY,DBEZ,DGA,DGA2,DBEP,DGABEP
2312         IERROR=0
2313      
2314         IF(IMIN.LE.0 .OR. IMAX.GT.N .OR. IMIN.GT.IMAX) RETURN
2315 
2316         IF(THE**2+PHI**2.GT.1E-20) THEN
2317 C...ROTATE (TYPICALLY FROM Z AXIS TO DIRECTION THETA,PHI)
2318            ROT(1,1)=COS(THE)*COS(PHI)
2319            ROT(1,2)=-SIN(PHI)
2320            ROT(1,3)=SIN(THE)*COS(PHI)
2321            ROT(2,1)=COS(THE)*SIN(PHI)
2322            ROT(2,2)=COS(PHI)
2323            ROT(2,3)=SIN(THE)*SIN(PHI)
2324            ROT(3,1)=-SIN(THE)
2325            ROT(3,2)=0.
2326            ROT(3,3)=COS(THE)
2327            DO 120 I=IMIN,IMAX
2328 C**************    IF(MOD(K(I,1)/10000,10).GE.6) GOTO 120
2329               DO 100 J=1,3
2330  100             PV(J)=P(I,J)
2331                  DO 110 J=1,3
2332  110                P(I,J)=ROT(J,1)*PV(1)+ROT(J,2)*PV(2)
2333      &                     +ROT(J,3)*PV(3)
2334  120             CONTINUE
2335         ENDIF
2336      
2337         IF(BEX**2+BEY**2+BEZ**2.GT.1E-20) THEN
2338 C...LORENTZ BOOST (TYPICALLY FROM REST TO MOMENTUM/ENERGY=BETA)
2339                 DBEX=BEX
2340                 DBEY=BEY
2341                 DBEZ=BEZ
2342                 DGA2=1D0-DBEX**2-DBEY**2-DBEZ**2
2343                 IF(DGA2.LE.0D0) THEN
2344                         IERROR=1
2345                         RETURN
2346                 ENDIF
2347                 DGA=1D0/DSQRT(DGA2)
2348                 DO 140 I=IMIN,IMAX
2349 C*************     IF(MOD(K(I,1)/10000,10).GE.6) GOTO 140
2350                    DO 130 J=1,4
2351 130                DP(J)=P(I,J)
2352                    DBEP=DBEX*DP(1)+DBEY*DP(2)+DBEZ*DP(3)
2353                    DGABEP=DGA*(DGA*DBEP/(1D0+DGA)+DP(4))
2354                    P(I,1)=DP(1)+DGABEP*DBEX
2355                    P(I,2)=DP(2)+DGABEP*DBEY
2356                    P(I,3)=DP(3)+DGABEP*DBEZ
2357                    P(I,4)=DGA*(DP(4)+DBEP)
2358 140             CONTINUE
2359         ENDIF
2360      
2361         RETURN
2362         END
2363 C
2364 C
2365 C
2366         SUBROUTINE HIJHRD(JP,JT,JOUT,JFLG,IOPJET0)
2367 C
2368 C       IOPTJET=1, ALL JET WILL FORM SINGLE STRING SYSTEM
2369 C               0, ONLY Q-QBAR JET FORM SINGLE STRING SYSTEM
2370 C*******Perform jets production and fragmentation when JP JT *******
2371 C     scatter. JOUT-> number of hard scatterings precede this one  *
2372 C     for the the same pair(JP,JT). JFLG->a flag to show whether   *
2373 C     jets can be produced (with valence quark=1,gluon=2, q-qbar=3)*
2374 C     or not(0). Information of jets are in  COMMON/ATTJET and     *
2375 C     /MINJET. ABS(NFP(JP,6)) is the total number jets produced by *
2376 C    JP. If NFP(JP,6)<0 JP can not produce jet anymore.            *
2377 C*******************************************************************
2378         DIMENSION IP(100,2),IPQ(50),IPB(50),IT(100,2),ITQ(50),ITB(50)
2379         COMMON/HIJCRDN/YP(3,300),YT(3,300)
2380         SAVE  /HIJCRDN/
2381         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
2382         SAVE  /HIPARNT/
2383         COMMON/HIJDAT/HIDAT0(10,10),HIDAT(10)
2384         SAVE  /HIJDAT/
2385         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
2386         SAVE  /HISTRNG/
2387         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
2388      &                PJPY(300,500),PJPZ(300,500),PJPE(300,500),
2389      &                PJPM(300,500),NTJ(300),KFTJ(300,500),
2390      &                PJTX(300,500),PJTY(300,500),PJTZ(300,500),
2391      &                PJTE(300,500),PJTM(300,500)
2392         SAVE  /HIJJET1/
2393         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
2394      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
2395      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
2396         SAVE  /HIJJET2/
2397         COMMON/HIJJET4/NDR,IADR(900,2),KFDR(900),PDR(900,5)
2398         SAVE  /HIJJET4/
2399         COMMON/RANSEED/NSEED
2400         SAVE  /RANSEED/
2401 C************************************ HIJING common block
2402         COMMON/LUJETS/N,K(9000,5),P(9000,5),V(9000,5)
2403         SAVE  /LUJETS/
2404         COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
2405         SAVE  /LUDAT1/
2406         COMMON/PYSUBS/MSEL,MSUB(200),KFIN(2,-40:40),CKIN(200)
2407         SAVE  /PYSUBS/
2408         COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)
2409         SAVE  /PYPARS/
2410         COMMON/PYINT1/MINT(400),VINT(400)
2411         SAVE  /PYINT1/
2412         COMMON/PYINT2/ISET(200),KFPR(200,2),COEF(200,20),ICOL(40,4,2)
2413         SAVE  /PYINT2/
2414         COMMON/PYINT5/NGEN(0:200,3),XSEC(0:200,3)
2415         SAVE  /PYINT5/
2416         COMMON/HIPYINT/MINT4,MINT5,ATCO(200,20),ATXS(0:200)
2417         SAVE  /HIPYINT/
2418 C*********************************** LU common block
2419         MXJT=500
2420 C               SIZE OF COMMON BLOCK FOR # OF PARTON PER STRING
2421         MXSG=900
2422 C               SIZE OF COMMON BLOCK FOR # OF SINGLE STRINGS
2423         MXSJ=100
2424 C               SIZE OF COMMON BLOCK FOR # OF PARTON PER SINGLE
2425 C               STRING
2426         JFLG=0
2427         IHNT2(11)=JP
2428         IHNT2(12)=JT
2429 C
2430         IOPJET=IOPJET0
2431         IF(IOPJET.EQ.1.AND.(NFP(JP,6).NE.0.OR.NFT(JT,6).NE.0))
2432      &                   IOPJET=0
2433         IF(JP.GT.IHNT2(1) .OR. JT.GT.IHNT2(3)) RETURN
2434         IF(NFP(JP,6).LT.0 .OR. NFT(JT,6).LT.0) RETURN
2435 C               ******** JP or JT can not produce jet anymore
2436 C
2437         IF(JOUT.EQ.0) THEN
2438                 EPP=PP(JP,4)+PP(JP,3)
2439                 EPM=PP(JP,4)-PP(JP,3)
2440                 ETP=PT(JT,4)+PT(JT,3)
2441                 ETM=PT(JT,4)-PT(JT,3)
2442                 IF(EPP.LT.0.0) GO TO 1000
2443                 IF(EPM.LT.0.0) GO TO 1000
2444                 IF(ETP.LT.0.0) GO TO 1000
2445                 IF(ETM.LT.0.0) GO TO 1000
2446                 IF(EPP/(EPM+0.01).LE.ETP/(ETM+0.01)) RETURN
2447         ENDIF
2448 C               ********for the first hard scattering of (JP,JT)
2449 C                       have collision only when Ycm(JP)>Ycm(JT)
2450 
2451         ECUT1=HIPR1(1)+HIPR1(8)+PP(JP,14)+PP(JP,15)
2452         ECUT2=HIPR1(1)+HIPR1(8)+PT(JT,14)+PT(JT,15)
2453         IF(PP(JP,4).LE.ECUT1) THEN
2454                 NFP(JP,6)=-ABS(NFP(JP,6))
2455                 RETURN
2456         ENDIF
2457         IF(PT(JT,4).LE.ECUT2) THEN
2458                 NFT(JT,6)=-ABS(NFT(JT,6))
2459                 RETURN
2460         ENDIF
2461 C               *********must have enough energy to produce jets
2462 
2463         MISS=0
2464         MISP=0
2465         MIST=0
2466 C
2467         IF(NFP(JP,10).EQ.0 .AND. NFT(JT,10).EQ.0) THEN
2468                 MINT(44)=MINT4
2469                 MINT(45)=MINT5
2470                 XSEC(0,1)=ATXS(0)
2471                 XSEC(11,1)=ATXS(11)
2472                 XSEC(12,1)=ATXS(12)
2473                 XSEC(28,1)=ATXS(28)
2474                 DO 120 I=1,20
2475                 COEF(11,I)=ATCO(11,I)
2476                 COEF(12,I)=ATCO(12,I)
2477                 COEF(28,I)=ATCO(28,I)
2478 120             CONTINUE
2479         ELSE
2480                 ISUB11=0
2481                 ISUB12=0
2482                 ISUB28=0
2483                 IF(XSEC(11,1).NE.0) ISUB11=1
2484                 IF(XSEC(12,1).NE.0) ISUB12=1
2485                 IF(XSEC(28,1).NE.0) ISUB28=1            
2486                 MINT(44)=MINT4-ISUB11-ISUB12-ISUB28
2487                 MINT(45)=MINT5-ISUB11-ISUB12-ISUB28
2488                 XSEC(0,1)=ATXS(0)-ATXS(11)-ATXS(12)-ATXS(28)
2489                 XSEC(11,1)=0.0
2490                 XSEC(12,1)=0.0
2491                 XSEC(28,1)=0.0  
2492                 DO 110 I=1,20
2493                 COEF(11,I)=0.0
2494                 COEF(12,I)=0.0
2495                 COEF(28,I)=0.0
2496 110             CONTINUE
2497         ENDIF           
2498 C       ********Scatter the valence quarks only once per NN 
2499 C       collision,
2500 C               afterwards only gluon can have hard scattering.
2501  155    CALL PYTHIA
2502         JJ=MINT(31)
2503         IF(JJ.NE.1) GO TO 155
2504 C               *********one hard collision at a time
2505         IF(K(7,2).EQ.-K(8,2)) THEN
2506                 QMASS2=(P(7,4)+P(8,4))**2-(P(7,1)+P(8,1))**2
2507      &                  -(P(7,2)+P(8,2))**2-(P(7,3)+P(8,3))**2
2508                 QM=ULMASS(K(7,2))
2509                 IF(QMASS2.LT.(2.0*QM+HIPR1(1))**2) GO TO 155
2510         ENDIF
2511 C               ********q-qbar jets must has minimum mass HIPR1(1)
2512         PXP=PP(JP,1)-P(3,1)
2513         PYP=PP(JP,2)-P(3,2)
2514         PZP=PP(JP,3)-P(3,3)
2515         PEP=PP(JP,4)-P(3,4)
2516         PXT=PT(JT,1)-P(4,1)
2517         PYT=PT(JT,2)-P(4,2)
2518         PZT=PT(JT,3)-P(4,3)
2519         PET=PT(JT,4)-P(4,4)
2520 
2521         IF(PEP.LE.ECUT1) THEN
2522                 MISP=MISP+1
2523                 IF(MISP.LT.50) GO TO 155
2524                 NFP(JP,6)=-ABS(NFP(JP,6))
2525                 RETURN
2526         ENDIF
2527         IF(PET.LE.ECUT2) THEN
2528                 MIST=MIST+1
2529                 IF(MIST.LT.50) GO TO 155
2530                 NFT(JT,6)=-ABS(NFT(JT,6))
2531                 RETURN
2532         ENDIF
2533 C               ******** if the remain energy<ECUT the proj or targ
2534 C                        can not produce jet anymore
2535 
2536         WP=PEP+PZP+PET+PZT
2537         WM=PEP-PZP+PET-PZT
2538         IF(WP.LT.0.0 .OR. WM.LT.0.0) THEN
2539                 MISS=MISS+1
2540                 IF(MISS.LT.50) GO TO 155
2541                 RETURN
2542         ENDIF
2543 C               ********the total W+, W- must be positive
2544         SW=WP*WM
2545         AMPX=SQRT((ECUT1-HIPR1(8))**2+PXP**2+PYP**2+0.01)
2546         AMTX=SQRT((ECUT2-HIPR1(8))**2+PXT**2+PYT**2+0.01)
2547         SXX=(AMPX+AMTX)**2
2548         IF(SW.LT.SXX.OR.VINT(43).LT.HIPR1(1)) THEN
2549                 MISS=MISS+1
2550                 IF(MISS.LT.50) GO TO 155
2551                 RETURN
2552         ENDIF  
2553 C               ********the proj and targ remnants must have at least
2554 C                       a CM energy that can produce two strings
2555 C                       with minimum mass HIPR1(1)(see HIJSFT HIJFRG)
2556 C
2557         HINT1(41)=P(7,1)
2558         HINT1(42)=P(7,2)
2559         HINT1(43)=P(7,3)
2560         HINT1(44)=P(7,4)
2561         HINT1(45)=P(7,5)
2562         HINT1(46)=SQRT(P(7,1)**2+P(7,2)**2)
2563         HINT1(51)=P(8,1)
2564         HINT1(52)=P(8,2)
2565         HINT1(53)=P(8,3)
2566         HINT1(54)=P(8,4)
2567         HINT1(55)=P(8,5)
2568         HINT1(56)=SQRT(P(8,1)**2+P(8,2)**2) 
2569         IHNT2(14)=K(7,2)
2570         IHNT2(15)=K(8,2)
2571 C
2572         PINIRAD=(1.0-EXP(-2.0*(VINT(47)-HIDAT(1))))
2573      &          /(1.0+EXP(-2.0*(VINT(47)-HIDAT(1))))
2574         I_INIRAD=0
2575         IF(RLU(0).LE.PINIRAD) I_INIRAD=1
2576         IF(K(7,2).EQ.-K(8,2)) GO TO 190
2577         IF(K(7,2).EQ.21.AND.K(8,2).EQ.21.AND.IOPJET.EQ.1) GO TO 190
2578 C*******************************************************************
2579 C       gluon  jets are going to be connectd with
2580 C       the final leading string of quark-aintquark
2581 C*******************************************************************
2582         JFLG=2
2583         JPP=0
2584         LPQ=0
2585         LPB=0
2586         JTT=0
2587         LTQ=0
2588         LTB=0
2589         IS7=0
2590         IS8=0
2591         HINT1(47)=0.0
2592         HINT1(48)=0.0
2593         HINT1(49)=0.0
2594         HINT1(50)=0.0
2595         HINT1(67)=0.0
2596         HINT1(68)=0.0
2597         HINT1(69)=0.0
2598         HINT1(70)=0.0
2599         DO 180 I=9,N
2600            IF(K(I,3).EQ.1 .OR. K(I,3).EQ.2.OR.
2601      &                   ABS(K(I,2)).GT.30) GO TO 180
2602 C************************************************************
2603            IF(K(I,3).EQ.7) THEN
2604               HINT1(47)=HINT1(47)+P(I,1)
2605               HINT1(48)=HINT1(48)+P(I,2)
2606               HINT1(49)=HINT1(49)+P(I,3)
2607               HINT1(50)=HINT1(50)+P(I,4)
2608            ENDIF
2609            IF(K(I,3).EQ.8) THEN
2610               HINT1(67)=HINT1(67)+P(I,1)
2611               HINT1(68)=HINT1(68)+P(I,2)
2612               HINT1(69)=HINT1(69)+P(I,3)
2613               HINT1(70)=HINT1(70)+P(I,4)
2614            ENDIF
2615 C************************modifcation made on Apr 10. 1996*****
2616            IF(K(I,2).GT.21.AND.K(I,2).LE.30) THEN
2617               NDR=NDR+1
2618               IADR(NDR,1)=JP
2619               IADR(NDR,2)=JT
2620               KFDR(NDR)=K(I,2)
2621               PDR(NDR,1)=P(I,1)
2622               PDR(NDR,2)=P(I,2)
2623               PDR(NDR,3)=P(I,3)
2624               PDR(NDR,4)=P(I,4)
2625               PDR(NDR,5)=P(I,5)
2626 C************************************************************
2627               GO TO 180
2628 C************************correction made on Oct. 14,1994*****
2629            ENDIF
2630            IF(K(I,3).EQ.7.OR.K(I,3).EQ.3) THEN
2631               IF(K(I,3).EQ.7.AND.K(I,2).NE.21.AND.K(I,2).EQ.K(7,2)
2632      &               .AND.IS7.EQ.0) THEN
2633                  PP(JP,10)=P(I,1)
2634                  PP(JP,11)=P(I,2)
2635                  PP(JP,12)=P(I,3)
2636                  PZP=PZP+P(I,3)
2637                  PEP=PEP+P(I,4)
2638                  NFP(JP,10)=1
2639                  IS7=1
2640                  GO TO 180
2641               ENDIF
2642               IF(K(I,3).EQ.3.AND.(K(I,2).NE.21.OR.
2643      &                               I_INIRAD.EQ.0)) THEN
2644                  PXP=PXP+P(I,1)
2645                  PYP=PYP+P(I,2)
2646                  PZP=PZP+P(I,3)
2647                  PEP=PEP+P(I,4)
2648                  GO TO 180 
2649               ENDIF
2650               JPP=JPP+1
2651               IP(JPP,1)=I
2652               IP(JPP,2)=0
2653               IF(K(I,2).NE.21) THEN
2654                  IF(K(I,2).GT.0) THEN
2655                     LPQ=LPQ+1
2656                     IPQ(LPQ)=JPP
2657                     IP(JPP,2)=LPQ
2658                  ELSE IF(K(I,2).LT.0) THEN
2659                     LPB=LPB+1
2660                     IPB(LPB)=JPP
2661                     IP(JPP,2)=-LPB
2662                  ENDIF
2663               ENDIF
2664            ELSE IF(K(I,3).EQ.8.OR.K(I,3).EQ.4) THEN
2665               IF(K(I,3).EQ.8.AND.K(I,2).NE.21.AND.K(I,2).EQ.K(8,2)
2666      &                          .AND.IS8.EQ.0) THEN
2667                  PT(JT,10)=P(I,1)
2668                  PT(JT,11)=P(I,2)
2669                  PT(JT,12)=P(I,3)
2670                  PZT=PZT+P(I,3)
2671                  PET=PET+P(I,4)
2672                  NFT(JT,10)=1
2673                  IS8=1
2674                  GO TO 180
2675               ENDIF                     
2676               IF(K(I,3).EQ.4.AND.(K(I,2).NE.21.OR.
2677      &                             I_INIRAD.EQ.0)) THEN
2678                  PXT=PXT+P(I,1)
2679                  PYT=PYT+P(I,2)
2680                  PZT=PZT+P(I,3)
2681                  PET=PET+P(I,4)
2682                  GO TO 180
2683               ENDIF
2684               JTT=JTT+1
2685               IT(JTT,1)=I
2686               IT(JTT,2)=0
2687               IF(K(I,2).NE.21) THEN
2688                  IF(K(I,2).GT.0) THEN
2689                     LTQ=LTQ+1
2690                     ITQ(LTQ)=JTT
2691                     IT(JTT,2)=LTQ
2692                  ELSE IF(K(I,2).LT.0) THEN
2693                     LTB=LTB+1
2694                     ITB(LTB)=JTT
2695                     IT(JTT,2)=-LTB
2696                  ENDIF
2697               ENDIF
2698            ENDIF
2699  180    CONTINUE
2700 c
2701 c
2702         IF(LPQ.NE.LPB .OR. LTQ.NE.LTB) THEN
2703                 MISS=MISS+1
2704                 IF(MISS.LE.50) GO TO 155
2705                 WRITE(6,*) ' Q -QBAR NOT MATCHED IN HIJHRD'
2706                 JFLG=0
2707                 RETURN
2708         ENDIF
2709 C****The following will rearrange the partons so that a quark is***
2710 C****allways followed by an anti-quark ****************************
2711 
2712         J=0
2713 181     J=J+1
2714         IF(J.GT.JPP) GO TO 182
2715         IF(IP(J,2).EQ.0) THEN
2716                 GO TO 181
2717         ELSE IF(IP(J,2).NE.0) THEN
2718                 LP=ABS(IP(J,2))
2719                 IP1=IP(J,1)
2720                 IP2=IP(J,2)
2721                 IP(J,1)=IP(IPQ(LP),1)
2722                 IP(J,2)=IP(IPQ(LP),2)
2723                 IP(IPQ(LP),1)=IP1
2724                 IP(IPQ(LP),2)=IP2
2725                 IF(IP2.GT.0) THEN
2726                         IPQ(IP2)=IPQ(LP)
2727                 ELSE IF(IP2.LT.0) THEN
2728                         IPB(-IP2)=IPQ(LP)
2729                 ENDIF
2730 C               ********replace J with a quark
2731                 IP1=IP(J+1,1)
2732                 IP2=IP(J+1,2)
2733                 IP(J+1,1)=IP(IPB(LP),1)
2734                 IP(J+1,2)=IP(IPB(LP),2)
2735                 IP(IPB(LP),1)=IP1
2736                 IP(IPB(LP),2)=IP2
2737                 IF(IP2.GT.0) THEN
2738                         IPQ(IP2)=IPB(LP)
2739                 ELSE IF(IP2.LT.0) THEN
2740                         IPB(-IP2)=IPB(LP)
2741                 ENDIF
2742 C               ******** replace J+1 with anti-quark
2743                 J=J+1
2744                 GO TO 181
2745         ENDIF
2746 
2747 182     J=0
2748 183     J=J+1
2749         IF(J.GT.JTT) GO TO 184
2750         IF(IT(J,2).EQ.0) THEN
2751                 GO TO 183
2752         ELSE IF(IT(J,2).NE.0) THEN
2753                 LT=ABS(IT(J,2))
2754                 IT1=IT(J,1)
2755                 IT2=IT(J,2)
2756                 IT(J,1)=IT(ITQ(LT),1)
2757                 IT(J,2)=IT(ITQ(LT),2)
2758                 IT(ITQ(LT),1)=IT1
2759                 IT(ITQ(LT),2)=IT2
2760                 IF(IT2.GT.0) THEN
2761                         ITQ(IT2)=ITQ(LT)
2762                 ELSE IF(IT2.LT.0) THEN
2763                         ITB(-IT2)=ITQ(LT)
2764                 ENDIF
2765 C               ********replace J with a quark
2766                 IT1=IT(J+1,1)
2767                 IT2=IT(J+1,2)
2768                 IT(J+1,1)=IT(ITB(LT),1)
2769                 IT(J+1,2)=IT(ITB(LT),2)
2770                 IT(ITB(LT),1)=IT1
2771                 IT(ITB(LT),2)=IT2
2772                 IF(IT2.GT.0) THEN
2773                         ITQ(IT2)=ITB(LT)
2774                 ELSE IF(IT2.LT.0) THEN
2775                         ITB(-IT2)=ITB(LT)
2776                 ENDIF
2777 C               ******** replace J+1 with anti-quark
2778                 J=J+1
2779                 GO TO 183
2780 
2781         ENDIF
2782 
2783 184     CONTINUE
2784         IF(NPJ(JP)+JPP.GT.MXJT.OR.NTJ(JT)+JTT.GT.MXJT) THEN
2785                 JFLG=0
2786                 WRITE(6,*) 'number of partons per string exceeds'
2787                 WRITE(6,*) 'the common block size'
2788                 RETURN
2789         ENDIF
2790 C                       ********check the bounds of common blocks
2791         DO 186 J=1,JPP
2792                 KFPJ(JP,NPJ(JP)+J)=K(IP(J,1),2)
2793                 PJPX(JP,NPJ(JP)+J)=P(IP(J,1),1)
2794                 PJPY(JP,NPJ(JP)+J)=P(IP(J,1),2)
2795                 PJPZ(JP,NPJ(JP)+J)=P(IP(J,1),3)
2796                 PJPE(JP,NPJ(JP)+J)=P(IP(J,1),4)
2797                 PJPM(JP,NPJ(JP)+J)=P(IP(J,1),5)
2798 186     CONTINUE
2799         NPJ(JP)=NPJ(JP)+JPP
2800         DO 188 J=1,JTT
2801                 KFTJ(JT,NTJ(JT)+J)=K(IT(J,1),2)
2802                 PJTX(JT,NTJ(JT)+J)=P(IT(J,1),1)
2803                 PJTY(JT,NTJ(JT)+J)=P(IT(J,1),2)
2804                 PJTZ(JT,NTJ(JT)+J)=P(IT(J,1),3)
2805                 PJTE(JT,NTJ(JT)+J)=P(IT(J,1),4)
2806                 PJTM(JT,NTJ(JT)+J)=P(IT(J,1),5)
2807 188     CONTINUE
2808         NTJ(JT)=NTJ(JT)+JTT
2809         GO TO 900
2810 C*****************************************************************
2811 CThis is the case of a quark-antiquark jet it will fragment alone
2812 C****************************************************************
2813 190     JFLG=3
2814         IF(K(7,2).NE.21.AND.K(8,2).NE.21.AND.
2815      &                   K(7,2)*K(8,2).GT.0) GO TO 155
2816         JPP=0
2817         LPQ=0
2818         LPB=0
2819         DO 200 I=9,N
2820            IF(K(I,3).EQ.1.OR.K(I,3).EQ.2.OR.
2821      &                  ABS(K(I,2)).GT.30) GO TO 200
2822                 IF(K(I,2).GT.21.AND.K(I,2).LE.30) THEN
2823                         NDR=NDR+1
2824                         IADR(NDR,1)=JP
2825                         IADR(NDR,2)=JT
2826                         KFDR(NDR)=K(I,2)
2827                         PDR(NDR,1)=P(I,1)
2828                         PDR(NDR,2)=P(I,2)
2829                         PDR(NDR,3)=P(I,3)
2830                         PDR(NDR,4)=P(I,4)
2831                         PDR(NDR,5)=P(I,5)
2832 C************************************************************
2833                         GO TO 200
2834 C************************correction made on Oct. 14,1994*****
2835                 ENDIF
2836                 IF(K(I,3).EQ.3.AND.(K(I,2).NE.21.OR.
2837      &                              I_INIRAD.EQ.0)) THEN
2838                         PXP=PXP+P(I,1)
2839                         PYP=PYP+P(I,2)
2840                         PZP=PZP+P(I,3)
2841                         PEP=PEP+P(I,4)
2842                         GO TO 200
2843                 ENDIF
2844                 IF(K(I,3).EQ.4.AND.(K(I,2).NE.21.OR.
2845      &                                I_INIRAD.EQ.0)) THEN
2846                         PXT=PXT+P(I,1)
2847                         PYT=PYT+P(I,2)
2848                         PZT=PZT+P(I,3)
2849                         PET=PET+P(I,4)
2850                         GO TO 200
2851                 ENDIF
2852                 JPP=JPP+1
2853                 IP(JPP,1)=I
2854                 IP(JPP,2)=0
2855                 IF(K(I,2).NE.21) THEN
2856                         IF(K(I,2).GT.0) THEN
2857                                 LPQ=LPQ+1
2858                                 IPQ(LPQ)=JPP
2859                                 IP(JPP,2)=LPQ
2860                         ELSE IF(K(I,2).LT.0) THEN
2861                                 LPB=LPB+1
2862                                 IPB(LPB)=JPP
2863                                 IP(JPP,2)=-LPB
2864                         ENDIF
2865                 ENDIF
2866 200     CONTINUE
2867         IF(LPQ.NE.LPB) THEN
2868            MISS=MISS+1
2869            IF(MISS.LE.50) GO TO 155
2870            WRITE(6,*) LPQ,LPB, 'Q-QBAR NOT CONSERVED OR NOT MATCHED'
2871            JFLG=0
2872            RETURN
2873         ENDIF
2874 
2875 C**** The following will rearrange the partons so that a quark is***
2876 C**** allways followed by an anti-quark ****************************
2877         J=0
2878 220     J=J+1
2879         IF(J.GT.JPP) GO TO 222
2880         IF(IP(J,2).EQ.0) GO TO 220
2881                 LP=ABS(IP(J,2))
2882                 IP1=IP(J,1)
2883                 IP2=IP(J,2)
2884                 IP(J,1)=IP(IPQ(LP),1)
2885                 IP(J,2)=IP(IPQ(LP),2)
2886                 IP(IPQ(LP),1)=IP1
2887                 IP(IPQ(LP),2)=IP2
2888                 IF(IP2.GT.0) THEN
2889                         IPQ(IP2)=IPQ(LP)
2890                 ELSE IF(IP2.LT.0) THEN
2891                         IPB(-IP2)=IPQ(LP)
2892                 ENDIF
2893                 IPQ(LP)=J
2894 C               ********replace J with a quark
2895                 IP1=IP(J+1,1)
2896                 IP2=IP(J+1,2)
2897                 IP(J+1,1)=IP(IPB(LP),1)
2898                 IP(J+1,2)=IP(IPB(LP),2)
2899                 IP(IPB(LP),1)=IP1
2900                 IP(IPB(LP),2)=IP2
2901                 IF(IP2.GT.0) THEN
2902                         IPQ(IP2)=IPB(LP)
2903                 ELSE IF(IP2.LT.0) THEN
2904                         IPB(-IP2)=IPB(LP)
2905                 ENDIF
2906 C               ******** replace J+1 with an anti-quark
2907                 IPB(LP)=J+1
2908                 J=J+1
2909                 GO TO 220
2910 
2911 222     CONTINUE
2912         IF(LPQ.GE.1) THEN
2913                 DO 240 L0=2,LPQ
2914                         IP1=IP(2*L0-3,1)
2915                         IP2=IP(2*L0-3,2)
2916                         IP(2*L0-3,1)=IP(IPQ(L0),1)
2917                         IP(2*L0-3,2)=IP(IPQ(L0),2)
2918                         IP(IPQ(L0),1)=IP1
2919                         IP(IPQ(L0),2)=IP2
2920                         IF(IP2.GT.0) THEN
2921                                 IPQ(IP2)=IPQ(L0)
2922                         ELSE IF(IP2.LT.0) THEN
2923                                 IPB(-IP2)=IPQ(L0)
2924                         ENDIF
2925                         IPQ(L0)=2*L0-3
2926 C
2927                         IP1=IP(2*L0-2,1)
2928                         IP2=IP(2*L0-2,2)
2929                         IP(2*L0-2,1)=IP(IPB(L0),1)
2930                         IP(2*L0-2,2)=IP(IPB(L0),2)
2931                         IP(IPB(L0),1)=IP1
2932                         IP(IPB(L0),2)=IP2
2933                         IF(IP2.GT.0) THEN
2934                                 IPQ(IP2)=IPB(L0)
2935                         ELSE IF(IP2.LT.0) THEN
2936                                 IPB(-IP2)=IPB(L0)
2937                         ENDIF
2938                         IPB(L0)=2*L0-2
2939 240             CONTINUE
2940 C               ********move all the qqbar pair to the front of 
2941 C                               the list, except the first pair
2942                 IP1=IP(2*LPQ-1,1)
2943                 IP2=IP(2*LPQ-1,2)
2944                 IP(2*LPQ-1,1)=IP(IPQ(1),1)
2945                 IP(2*LPQ-1,2)=IP(IPQ(1),2)
2946                 IP(IPQ(1),1)=IP1
2947                 IP(IPQ(1),2)=IP2
2948                 IF(IP2.GT.0) THEN
2949                         IPQ(IP2)=IPQ(1)
2950                 ELSE IF(IP2.LT.0) THEN
2951                         IPB(-IP2)=IPQ(1)
2952                 ENDIF
2953                 IPQ(1)=2*LPQ-1
2954 C               ********move the first quark to the beginning of
2955 C                               the last string system
2956                 IP1=IP(JPP,1)
2957                 IP2=IP(JPP,2)
2958                 IP(JPP,1)=IP(IPB(1),1)
2959                 IP(JPP,2)=IP(IPB(1),2)
2960                 IP(IPB(1),1)=IP1
2961                 IP(IPB(1),2)=IP2
2962                 IF(IP2.GT.0) THEN
2963                         IPQ(IP2)=IPB(1)
2964                 ELSE IF(IP2.LT.0) THEN
2965                         IPB(-IP2)=IPB(1)
2966                 ENDIF
2967                 IPB(1)=JPP
2968 C               ********move the first anti-quark to the end of the 
2969 C                       last string system
2970         ENDIF
2971         IF(NSG.GE.MXSG) THEN
2972            JFLG=0
2973            WRITE(6,*) 'number of jets forming single strings exceeds'
2974            WRITE(6,*) 'the common block size'
2975            RETURN
2976         ENDIF
2977         IF(JPP.GT.MXSJ) THEN
2978            JFLG=0
2979            WRITE(6,*) 'number of partons per single jet system'
2980            WRITE(6,*) 'exceeds the common block size'
2981            RETURN
2982         ENDIF
2983 C               ********check the bounds of common block size
2984         NSG=NSG+1
2985         NJSG(NSG)=JPP
2986         IASG(NSG,1)=JP
2987         IASG(NSG,2)=JT
2988         IASG(NSG,3)=0
2989         DO 300 I=1,JPP
2990                 K1SG(NSG,I)=2
2991                 K2SG(NSG,I)=K(IP(I,1),2)
2992                 IF(K2SG(NSG,I).LT.0) K1SG(NSG,I)=1
2993                 PXSG(NSG,I)=P(IP(I,1),1)
2994                 PYSG(NSG,I)=P(IP(I,1),2)
2995                 PZSG(NSG,I)=P(IP(I,1),3)
2996                 PESG(NSG,I)=P(IP(I,1),4)
2997                 PMSG(NSG,I)=P(IP(I,1),5)
2998 300     CONTINUE
2999         K1SG(NSG,1)=2
3000         K1SG(NSG,JPP)=1
3001 C******* reset the energy-momentum of incoming particles ********
3002 900     PP(JP,1)=PXP
3003         PP(JP,2)=PYP
3004         PP(JP,3)=PZP
3005         PP(JP,4)=PEP
3006         PP(JP,5)=0.0
3007         PT(JT,1)=PXT
3008         PT(JT,2)=PYT
3009         PT(JT,3)=PZT
3010         PT(JT,4)=PET
3011         PT(JT,5)=0.0
3012 
3013         NFP(JP,6)=NFP(JP,6)+1
3014         NFT(JT,6)=NFT(JT,6)+1
3015         RETURN
3016 C
3017 1000    JFLG=-1
3018         IF(IHPR2(10).EQ.0) RETURN
3019         WRITE(6,*) 'Fatal HIJHRD error'
3020         WRITE(6,*) JP, ' proj E+,E-',EPP,EPM,' status',NFP(JP,5)
3021         WRITE(6,*) JT, ' targ E+,E_',ETP,ETM,' status',NFT(JT,5)
3022         RETURN
3023         END
3024 C
3025 C
3026 C
3027 C
3028 C
3029         SUBROUTINE JETINI(JP,JT,I_TRIG)
3030 C*******Initialize PYTHIA for jet production**********************
3031 C       I_TRIG=0: for normal processes
3032 C       I_TRIG=1: for triggered processes
3033 C       JP: sequence number of the projectile
3034 C       JT: sequence number of the target
3035 C     For A+A collisions, one has to initilize pythia
3036 C     separately for each type of collisions, pp, pn,np and nn,
3037 C     or hp and hn for hA collisions. In this subroutine we use the following
3038 C     catalogue for different type of collisions:
3039 C     h+h: h+h (I_TYPE=1)
3040 C     h+A: h+p (I_TYPE=1), h+n (I_TYPE=2)
3041 C     A+h: p+h (I_TYPE=1), n+h (I_TYPE=2)
3042 C     A+A: p+p (I_TYPE=1), p+n (I_TYPE=2), n+p (I_TYPE=3), n+n (I_TYPE=4)
3043 C*****************************************************************
3044         CHARACTER BEAM*16,TARG*16
3045         DIMENSION XSEC0(8,0:200),COEF0(8,200,20),INI(8),
3046      &          MINT44(8),MINT45(8)
3047         COMMON/HIJCRDN/YP(3,300),YT(3,300)
3048         SAVE  /HIJCRDN/
3049         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
3050         SAVE  /HIPARNT/
3051         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
3052         SAVE  /HISTRNG/
3053         COMMON/HIPYINT/MINT4,MINT5,ATCO(200,20),ATXS(0:200)
3054         SAVE  /HIPYINT/
3055 C
3056         COMMON/LUDAT1/MSTU(200),PARU(200),MSTJ(200),PARJ(200)
3057         SAVE  /LUDAT1/
3058         COMMON/LUDAT3/MDCY(500,3),MDME(2000,2),BRAT(2000),KFDP(2000,5)    
3059         SAVE  /LUDAT3/
3060         COMMON/PYSUBS/MSEL,MSUB(200),KFIN(2,-40:40),CKIN(200)
3061         SAVE  /PYSUBS/
3062         COMMON/PYPARS/MSTP(200),PARP(200),MSTI(200),PARI(200)
3063         SAVE  /PYPARS/
3064         COMMON/PYINT1/MINT(400),VINT(400)
3065         SAVE  /PYINT1/
3066         COMMON/PYINT2/ISET(200),KFPR(200,2),COEF(200,20),ICOL(40,4,2)
3067         SAVE  /PYINT2/
3068         COMMON/PYINT5/NGEN(0:200,3),XSEC(0:200,3)
3069         SAVE  /PYINT5/
3070         DATA INI/8*0/I_LAST/-1/
3071 
3072         save INI, I_LAST    !uzhi
3073 
3074         IHNT2(11)=JP
3075         IHNT2(12)=JT
3076         IF(IHNT2(5).NE.0 .AND. IHNT2(6).NE.0) THEN
3077            I_TYPE=1
3078         ELSE IF(IHNT2(5).NE.0 .AND. IHNT2(6).EQ.0) THEN
3079            I_TYPE=1
3080            IF(NFT(JT,4).EQ.2112) I_TYPE=2
3081         ELSE IF(IHNT2(5).EQ.0 .AND. IHNT2(6).NE.0) THEN
3082            I_TYPE=1
3083            IF(NFP(JP,4).EQ.2112) I_TYPE=2
3084         ELSE
3085            IF(NFP(JP,4).EQ.2212 .AND. NFT(JT,4).EQ.2212) THEN
3086               I_TYPE=1
3087            ELSE IF(NFP(JP,4).EQ.2212 .AND. NFT(JT,4).EQ.2112) THEN
3088               I_TYPE=2
3089            ELSE IF(NFP(JP,4).EQ.2112 .AND. NFT(JT,4).EQ.2212) THEN
3090               I_TYPE=3
3091            ELSE
3092               I_TYPE=4
3093            ENDIF
3094         ENDIF
3095 c
3096         IF(I_TRIG.NE.0) GO TO 160
3097         IF(I_TRIG.EQ.I_LAST) GO TO 150
3098         MSTP(2)=2
3099 c                       ********second order running alpha_strong
3100         MSTP(33)=1
3101         PARP(31)=HIPR1(17)
3102 C                       ********inclusion of K factor
3103         MSTP(51)=3
3104 C                       ********Duke-Owens set 1 structure functions
3105         MSTP(61)=1
3106 C                       ********INITIAL STATE RADIATION
3107         MSTP(71)=1
3108 C                       ********FINAL STATE RADIATION
3109         IF(IHPR2(2).EQ.0.OR.IHPR2(2).EQ.2) MSTP(61)=0
3110         IF(IHPR2(2).EQ.0.OR.IHPR2(2).EQ.1) MSTP(71)=0
3111 c
3112         MSTP(81)=0
3113 C                       ******** NO MULTIPLE INTERACTION
3114         MSTP(82)=1
3115 C                       *******STRUCTURE OF MUTLIPLE INTERACTION
3116         MSTP(111)=0
3117 C               ********frag off(have to be done by local call)
3118         IF(IHPR2(10).EQ.0) MSTP(122)=0
3119 C               ********No printout of initialization information
3120         PARP(81)=HIPR1(8)
3121         CKIN(5)=HIPR1(8)
3122         CKIN(3)=HIPR1(8)
3123         CKIN(4)=HIPR1(9)
3124         IF(HIPR1(9).LE.HIPR1(8)) CKIN(4)=-1.0
3125         CKIN(9)=-10.0
3126         CKIN(10)=10.0
3127         MSEL=0
3128         DO 100 ISUB=1,200
3129            MSUB(ISUB)=0
3130  100    CONTINUE
3131         MSUB(11)=1
3132         MSUB(12)=1
3133         MSUB(13)=1
3134         MSUB(28)=1
3135         MSUB(53)=1
3136         MSUB(68)=1
3137         MSUB(81)=1
3138         MSUB(82)=1
3139         DO 110 J=1,MIN(8,MDCY(21,3))
3140  110    MDME(MDCY(21,2)+J-1,1)=0
3141         ISEL=4
3142         IF(HINT1(1).GE.20.0 .and. IHPR2(18).EQ.1) ISEL=5
3143         MDME(MDCY(21,2)+ISEL-1,1)=1
3144 C                       ********QCD subprocesses
3145         MSUB(14)=1
3146         MSUB(18)=1
3147         MSUB(29)=1
3148 C                       ******* direct photon production
3149  150    IF(INI(I_TYPE).NE.0) GO TO 800
3150         GO TO 400
3151 C
3152 C       *****triggered subprocesses, jet, photon, heavy quark and DY
3153 C
3154  160    I_TYPE=4+I_TYPE
3155         IF(I_TRIG.EQ.I_LAST) GO TO 260
3156         PARP(81)=ABS(HIPR1(10))-0.25
3157         CKIN(5)=ABS(HIPR1(10))-0.25
3158         CKIN(3)=ABS(HIPR1(10))-0.25
3159         CKIN(4)=ABS(HIPR1(10))+0.25
3160         IF(HIPR1(10).LT.HIPR1(8)) CKIN(4)=-1.0
3161 c
3162         MSEL=0
3163         DO 101 ISUB=1,200
3164            MSUB(ISUB)=0
3165  101    CONTINUE
3166         IF(IHPR2(3).EQ.1) THEN
3167            MSUB(11)=1
3168            MSUB(12)=1
3169            MSUB(13)=1
3170            MSUB(28)=1
3171            MSUB(53)=1
3172            MSUB(68)=1
3173            MSUB(81)=1
3174            MSUB(82)=1
3175            MSUB(14)=1
3176            MSUB(18)=1
3177            MSUB(29)=1
3178            DO 102 J=1,MIN(8,MDCY(21,3))
3179  102       MDME(MDCY(21,2)+J-1,1)=0
3180            ISEL=4
3181            IF(HINT1(1).GE.20.0 .and. IHPR2(18).EQ.1) ISEL=5
3182            MDME(MDCY(21,2)+ISEL-1,1)=1
3183 C                       ********QCD subprocesses
3184         ELSE IF(IHPR2(3).EQ.2) THEN
3185            MSUB(14)=1
3186            MSUB(18)=1
3187            MSUB(29)=1
3188 C               ********Direct photon production
3189 c               q+qbar->g+gamma,q+qbar->gamma+gamma, q+g->q+gamma
3190         ELSE IF(IHPR2(3).EQ.3) THEN
3191            CKIN(3)=MAX(0.0,HIPR1(10))
3192            CKIN(5)=HIPR1(8)
3193            PARP(81)=HIPR1(8)
3194            MSUB(81)=1
3195            MSUB(82)=1
3196            DO 105 J=1,MIN(8,MDCY(21,3))
3197  105       MDME(MDCY(21,2)+J-1,1)=0
3198            ISEL=4
3199            IF(HINT1(1).GE.20.0 .and. IHPR2(18).EQ.1) ISEL=5
3200            MDME(MDCY(21,2)+ISEL-1,1)=1
3201 C             **********Heavy quark production
3202         ENDIF
3203 260     IF(INI(I_TYPE).NE.0) GO TO 800
3204 C
3205 C
3206 400     INI(I_TYPE)=1
3207         IF(IHPR2(10).EQ.0) MSTP(122)=0
3208         IF(NFP(JP,4).EQ.2212) THEN
3209                 BEAM='P'
3210         ELSE IF(NFP(JP,4).EQ.-2212) THEN
3211                 BEAM='P~'
3212         ELSE IF(NFP(JP,4).EQ.2112) THEN
3213                 BEAM='N'
3214         ELSE IF(NFP(JP,4).EQ.-2112) THEN
3215                 BEAM='N~'
3216         ELSE IF(NFP(JP,4).EQ.211) THEN
3217                 BEAM='PI+'
3218         ELSE IF(NFP(JP,4).EQ.-211) THEN
3219                 BEAM='PI-'
3220         ELSE IF(NFP(JP,4).EQ.321) THEN
3221                 BEAM='PI+'
3222         ELSE IF(NFP(JP,4).EQ.-321) THEN
3223                 BEAM='PI-'
3224         ELSE
3225                 WRITE(6,*) 'unavailable beam type', NFP(JP,4)
3226         ENDIF
3227         IF(NFT(JT,4).EQ.2212) THEN
3228                 TARG='P'
3229         ELSE IF(NFT(JT,4).EQ.-2212) THEN
3230                 TARG='P~'
3231         ELSE IF(NFT(JT,4).EQ.2112) THEN
3232                 TARG='N'
3233         ELSE IF(NFT(JT,4).EQ.-2112) THEN
3234                 TARG='N~'
3235         ELSE IF(NFT(JT,4).EQ.211) THEN
3236                 TARG='PI+'
3237         ELSE IF(NFT(JT,4).EQ.-211) THEN
3238                 TARG='PI-'
3239         ELSE IF(NFT(JT,4).EQ.321) THEN
3240                 TARG='PI+'
3241         ELSE IF(NFT(JT,4).EQ.-321) THEN
3242                 TARG='PI-'
3243         ELSE
3244                 WRITE(6,*) 'unavailable target type', NFT(JT,4)
3245         ENDIF
3246 C
3247         IHNT2(16)=1
3248 C       ******************indicate for initialization use when
3249 C                         structure functions are called in PYTHIA
3250 C
3251         CALL PYINIT('CMS',BEAM,TARG,HINT1(1))
3252         MINT4=MINT(44)
3253         MINT5=MINT(45)
3254         MINT44(I_TYPE)=MINT(44)
3255         MINT45(I_TYPE)=MINT(45)
3256         ATXS(0)=XSEC(0,1)
3257         XSEC0(I_TYPE,0)=XSEC(0,1)
3258         DO 500 I=1,200
3259                 ATXS(I)=XSEC(I,1)
3260                 XSEC0(I_TYPE,I)=XSEC(I,1)
3261                 DO 500 J=1,20
3262                         ATCO(I,J)=COEF(I,J)
3263                         COEF0(I_TYPE,I,J)=COEF(I,J)
3264 500     CONTINUE
3265 C
3266         IHNT2(16)=0
3267 C
3268         RETURN
3269 C               ********Store the initialization information for
3270 C                               late use
3271 C
3272 C
3273 800     MINT(44)=MINT44(I_TYPE)
3274         MINT(45)=MINT45(I_TYPE)
3275         MINT4=MINT(44)
3276         MINT5=MINT(45)
3277         XSEC(0,1)=XSEC0(I_TYPE,0)
3278         ATXS(0)=XSEC(0,1)
3279         DO 900 I=1,200
3280                 XSEC(I,1)=XSEC0(I_TYPE,I)
3281                 ATXS(I)=XSEC(I,1)
3282         DO 900 J=1,20
3283                 COEF(I,J)=COEF0(I_TYPE,I,J)
3284                 ATCO(I,J)=COEF(I,J)
3285 900     CONTINUE
3286         I_LAST=I_TRIG
3287         MINT(11)=NFP(JP,4)
3288         MINT(12)=NFT(JT,4)
3289         RETURN
3290         END
3291 C            
3292 C
3293 C
3294         SUBROUTINE HIJINI
3295         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
3296         SAVE  /HIPARNT/
3297         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
3298         SAVE  /HISTRNG/
3299         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
3300      &                PJPY(300,500),PJPZ(300,500),PJPE(300,500),
3301      &                PJPM(300,500),NTJ(300),KFTJ(300,500),
3302      &                PJTX(300,500),PJTY(300,500),PJTZ(300,500),
3303      &                PJTE(300,500),PJTM(300,500)
3304         SAVE  /HIJJET1/
3305         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
3306      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
3307      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
3308         SAVE  /HIJJET2/
3309         COMMON/HIJJET4/NDR,IADR(900,2),KFDR(900),PDR(900,5)
3310         SAVE  /HIJJET4/
3311         COMMON/RANSEED/NSEED
3312         SAVE  /RANSEED/
3313 C****************Reset the momentum of initial particles************
3314 C             and assign flavors to the proj and targ string       *
3315 C*******************************************************************
3316         NSG=0
3317         NDR=0
3318         IPP=2212
3319         IPT=2212
3320         IF(IHNT2(5).NE.0) IPP=IHNT2(5)
3321         IF(IHNT2(6).NE.0) IPT=IHNT2(6)
3322 C               ********in case the proj or targ is a hadron.
3323 C
3324         DO 100 I=1,IHNT2(1)
3325         PP(I,1)=0.0
3326         PP(I,2)=0.0
3327         PP(I,3)=SQRT(HINT1(1)**2/4.0-HINT1(8)**2)
3328         PP(I,4)=HINT1(1)/2
3329         PP(I,5)=HINT1(8)
3330         PP(I,6)=0.0
3331         PP(I,7)=0.0
3332         PP(I,8)=0.0
3333         PP(I,9)=0.0
3334         PP(I,10)=0.0
3335         NFP(I,3)=IPP
3336         NFP(I,4)=IPP
3337         NFP(I,5)=0
3338         NFP(I,6)=0
3339         NFP(I,7)=0
3340         NFP(I,8)=0
3341         NFP(I,9)=0
3342         NFP(I,10)=0
3343         NFP(I,11)=0
3344         NPJ(I)=0
3345         IF(I.GT.ABS(IHNT2(2))) NFP(I,3)=2112
3346         CALL ATTFLV(NFP(I,3),IDQ,IDQQ)
3347         NFP(I,1)=IDQ
3348         NFP(I,2)=IDQQ
3349         NFP(I,15)=-1
3350         IF(ABS(IDQ).GT.1000.OR.(ABS(IDQ*IDQQ).LT.100.AND.
3351      &          RLU(0).LT.0.5)) NFP(I,15)=1
3352         PP(I,14)=ULMASS(IDQ)
3353         PP(I,15)=ULMASS(IDQQ)
3354 100     CONTINUE
3355 C
3356         DO 200 I=1,IHNT2(3)
3357         PT(I,1)=0.0
3358         PT(I,2)=0.0
3359         PT(I,3)=-SQRT(HINT1(1)**2/4.0-HINT1(9)**2)
3360         PT(I,4)=HINT1(1)/2.0
3361         PT(I,5)=HINT1(9)
3362         PT(I,6)=0.0
3363         PT(I,7)=0.0
3364         PT(I,8)=0.0
3365         PT(I,9)=0.0
3366         PT(I,10)=0.0
3367         NFT(I,3)=IPT
3368         NFT(I,4)=IPT
3369         NFT(I,5)=0
3370         NFT(I,6)=0
3371         NFT(I,7)=0
3372         NFT(I,8)=0
3373         NFT(I,9)=0
3374         NFT(I,10)=0
3375         NFT(I,11)=0
3376         NTJ(I)=0
3377         IF(I.GT.ABS(IHNT2(4))) NFT(I,3)=2112
3378         CALL ATTFLV(NFT(I,3),IDQ,IDQQ)
3379         NFT(I,1)=IDQ
3380         NFT(I,2)=IDQQ
3381         NFT(I,15)=1
3382         IF(ABS(IDQ).GT.1000.OR.(ABS(IDQ*IDQQ).LT.100.AND.
3383      &                  RLU(0).LT.0.5)) NFT(I,15)=-1
3384         PT(I,14)=ULMASS(IDQ)
3385         PT(I,15)=ULMASS(IDQQ)
3386 200     CONTINUE
3387         RETURN
3388         END
3389 C
3390 C
3391 C
3392         SUBROUTINE ATTFLV(ID,IDQ,IDQQ)
3393         COMMON/RANSEED/NSEED
3394         SAVE  /RANSEED/
3395 C
3396         IF(ABS(ID).LT.100) THEN
3397                 NSIGN=1
3398                 IDQ=ID/100
3399                 IDQQ=-ID/10+IDQ*10
3400                 IF(ABS(IDQ).EQ.3) NSIGN=-1
3401                 IDQ=NSIGN*IDQ
3402                 IDQQ=NSIGN*IDQQ
3403                 IF(IDQ.LT.0) THEN
3404                         ID0=IDQ
3405                         IDQ=IDQQ
3406                         IDQQ=ID0
3407                 ENDIF
3408                 RETURN
3409         ENDIF
3410 C               ********return ID of quark(IDQ) and anti-quark(IDQQ)
3411 C                       for pions and kaons
3412 c
3413 C       Return LU ID for quarks and diquarks for proton(ID=2212) 
3414 C       anti-proton(ID=-2212) and nuetron(ID=2112)
3415 C       LU ID for d=1,u=2, (ud)0=2101, (ud)1=2103, 
3416 C       (dd)1=1103,(uu)1=2203.
3417 C       Use SU(6)  weight  proton=1/3d(uu)1 + 1/6u(ud)1 + 1/2u(ud)0
3418 C                         nurtron=1/3u(dd)1 + 1/6d(ud)1 + 1/2d(ud)0
3419 C 
3420         IDQ=2
3421         IF(ABS(ID).EQ.2112) IDQ=1
3422         IDQQ=2101
3423         X=RLU(0)
3424         IF(X.LE.0.5) GO TO 30
3425         IF(X.GT.0.666667) GO TO 10
3426         IDQQ=2103
3427         GO TO 30
3428 10      IDQ=1
3429         IDQQ=2203
3430         IF(ABS(ID).EQ.2112) THEN
3431                 IDQ=2
3432                 IDQQ=1103
3433         ENDIF
3434 30      IF(ID.LT.0) THEN
3435                 ID00=IDQQ
3436                 IDQQ=-IDQ
3437                 IDQ=-ID00
3438         ENDIF
3439         RETURN
3440         END     
3441 C
3442 C*******************************************************************
3443 C       This subroutine performs elastic scatterings and possible 
3444 C       elastic cascading within their own nuclei
3445 c*******************************************************************
3446         SUBROUTINE HIJCSC(JP,JT)
3447         DIMENSION PSC1(5),PSC2(5)
3448         COMMON/HIJCRDN/YP(3,300),YT(3,300)
3449         SAVE  /HIJCRDN/
3450         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
3451         SAVE  /HIPARNT/
3452         COMMON/RANSEED/NSEED
3453         SAVE  /RANSEED/
3454         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
3455         SAVE  /HISTRNG/
3456         IF(JP.EQ.0 .OR. JT.EQ.0) GO TO 25
3457         DO 10 I=1,5
3458         PSC1(I)=PP(JP,I)
3459         PSC2(I)=PT(JT,I)
3460 10      CONTINUE
3461         CALL HIJELS(PSC1,PSC2)
3462         DPP1=PSC1(1)-PP(JP,1)
3463         DPP2=PSC1(2)-PP(JP,2)
3464         DPT1=PSC2(1)-PT(JT,1)
3465         DPT2=PSC2(2)-PT(JT,2)
3466         PP(JP,6)=PP(JP,6)+DPP1/2.0
3467         PP(JP,7)=PP(JP,7)+DPP2/2.0
3468         PP(JP,8)=PP(JP,8)+DPP1/2.0
3469         PP(JP,9)=PP(JP,9)+DPP2/2.0
3470         PT(JT,6)=PT(JT,6)+DPT1/2.0
3471         PT(JT,7)=PT(JT,7)+DPT2/2.0
3472         PT(JT,8)=PT(JT,8)+DPT1/2.0
3473         PT(JT,9)=PT(JT,9)+DPT2/2.0
3474         DO 20 I=1,4
3475         PP(JP,I)=PSC1(I)
3476         PT(JT,I)=PSC2(I)
3477 20      CONTINUE
3478         NFP(JP,5)=MAX(1,NFP(JP,5))
3479         NFT(JT,5)=MAX(1,NFT(JT,5))
3480 C               ********Perform elastic scattering between JP and JT
3481         RETURN
3482 C               ********The following is for possible elastic cascade
3483 c
3484 25      IF(JP.EQ.0) GO TO 45
3485         PABS=SQRT(PP(JP,1)**2+PP(JP,2)**2+PP(JP,3)**2)
3486         BX=PP(JP,1)/PABS
3487         BY=PP(JP,2)/PABS
3488         BZ=PP(JP,3)/PABS
3489         DO 40 I=1,IHNT2(1)
3490                 IF(I.EQ.JP) GO TO 40
3491                 DX=YP(1,I)-YP(1,JP)
3492                 DY=YP(2,I)-YP(2,JP)
3493                 DZ=YP(3,I)-YP(3,JP)
3494                 DIS=DX*BX+DY*BY+DZ*BZ
3495                 IF(DIS.LE.0) GO TO 40
3496                 BB=DX**2+DY**2+DZ**2-DIS**2
3497                 R2=BB*HIPR1(40)/HIPR1(31)/0.1
3498 C               ********mb=0.1*fm, YP is in fm,HIPR1(31) is in mb
3499                 GS=1.0-EXP(-(HIPR1(30)+HINT1(11))/HIPR1(31)/2.0
3500      &                  *ROMG(R2))**2
3501                 GS0=1.0-EXP(-(HIPR1(30)+HINT1(11))/HIPR1(31)/2.0
3502      &                  *ROMG(0.0))**2
3503                 IF(RLU(0).GT.GS/GS0) GO TO 40
3504                 DO 30 K=1,5
3505                         PSC1(K)=PP(JP,K)
3506                         PSC2(K)=PP(I,K)
3507 30              CONTINUE
3508                 CALL HIJELS(PSC1,PSC2)
3509                 DPP1=PSC1(1)-PP(JP,1)
3510                 DPP2=PSC1(2)-PP(JP,2)
3511                 DPT1=PSC2(1)-PP(I,1)
3512                 DPT2=PSC2(2)-PP(I,2)
3513                 PP(JP,6)=PP(JP,6)+DPP1/2.0
3514                 PP(JP,7)=PP(JP,7)+DPP2/2.0
3515                 PP(JP,8)=PP(JP,8)+DPP1/2.0
3516                 PP(JP,9)=PP(JP,9)+DPP2/2.0
3517                 PP(I,6)=PP(I,6)+DPT1/2.0
3518                 PP(I,7)=PP(I,7)+DPT2/2.0
3519                 PP(I,8)=PP(I,8)+DPT1/2.0
3520                 PP(I,9)=PP(I,9)+DPT2/2.0
3521                 DO 35 K=1,5
3522                         PP(JP,K)=PSC1(K)
3523                         PP(I,K)=PSC2(K)
3524 35              CONTINUE
3525                 NFP(I,5)=MAX(1,NFP(I,5))
3526                 GO TO 45
3527 40      CONTINUE
3528 45      IF(JT.EQ.0) GO TO 80
3529 50      PABS=SQRT(PT(JT,1)**2+PT(JT,2)**2+PT(JT,3)**2)
3530         BX=PT(JT,1)/PABS
3531         BY=PT(JT,2)/PABS
3532         BZ=PT(JT,3)/PABS
3533         DO 70 I=1,IHNT2(3)
3534                 IF(I.EQ.JT) GO TO 70
3535                 DX=YT(1,I)-YT(1,JT)
3536                 DY=YT(2,I)-YT(2,JT)
3537                 DZ=YT(3,I)-YT(3,JT)
3538                 DIS=DX*BX+DY*BY+DZ*BZ
3539                 IF(DIS.LE.0) GO TO 70
3540                 BB=DX**2+DY**2+DZ**2-DIS**2
3541                 R2=BB*HIPR1(40)/HIPR1(31)/0.1
3542 C               ********mb=0.1*fm, YP is in fm,HIPR1(31) is in mb
3543                 GS=(1.0-EXP(-(HIPR1(30)+HINT1(11))/HIPR1(31)/2.0
3544      &                  *ROMG(R2)))**2
3545                 GS0=(1.0-EXP(-(HIPR1(30)+HINT1(11))/HIPR1(31)/2.0
3546      &                  *ROMG(0.0)))**2
3547                 IF(RLU(0).GT.GS/GS0) GO TO 70
3548                 DO 60 K=1,5
3549                         PSC1(K)=PT(JT,K)
3550                         PSC2(K)=PT(I,K)
3551 60              CONTINUE
3552                 CALL HIJELS(PSC1,PSC2)
3553                 DPP1=PSC1(1)-PT(JT,1)
3554                 DPP2=PSC1(2)-PT(JT,2)
3555                 DPT1=PSC2(1)-PT(I,1)
3556                 DPT2=PSC2(2)-PT(I,2)
3557                 PT(JT,6)=PT(JT,6)+DPP1/2.0
3558                 PT(JT,7)=PT(JT,7)+DPP2/2.0
3559                 PT(JT,8)=PT(JT,8)+DPP1/2.0
3560                 PT(JT,9)=PT(JT,9)+DPP2/2.0
3561                 PT(I,6)=PT(I,6)+DPT1/2.0
3562                 PT(I,7)=PT(I,7)+DPT2/2.0
3563                 PT(I,8)=PT(I,8)+DPT1/2.0
3564                 PT(I,9)=PT(I,9)+DPT2/2.0
3565                 DO 65 K=1,5
3566                         PT(JT,K)=PSC1(K)
3567                         PT(I,K)=PSC2(K)
3568 65              CONTINUE
3569                 NFT(I,5)=MAX(1,NFT(I,5))
3570                 GO TO 80
3571 70      CONTINUE
3572 80      RETURN
3573         END
3574 C
3575 C
3576 C*******************************************************************
3577 CThis subroutine performs elastic scattering between two nucleons
3578 C
3579 C*******************************************************************
3580         SUBROUTINE HIJELS(PSC1,PSC2)
3581         IMPLICIT DOUBLE PRECISION(D)
3582         DIMENSION PSC1(5),PSC2(5)
3583         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
3584         SAVE  /HIPARNT/
3585         COMMON/RANSEED/NSEED
3586         SAVE  /RANSEED/
3587 C
3588         CC=1.0-HINT1(12)/HINT1(13)
3589         RR=(1.0-CC)*HINT1(13)/HINT1(12)/(1.0-HIPR1(33))-1.0
3590         BB=0.5*(3.0+RR+SQRT(9.0+10.0*RR+RR**2))
3591         EP=SQRT((PSC1(1)-PSC2(1))**2+(PSC1(2)-PSC2(2))**2
3592      &          +(PSC1(3)-PSC2(3))**2)
3593         IF(EP.LE.0.1) RETURN
3594         ELS0=98.0/EP+52.0*(1.0+RR)**2
3595         PCM1=PSC1(1)+PSC2(1)
3596         PCM2=PSC1(2)+PSC2(2)
3597         PCM3=PSC1(3)+PSC2(3)
3598         ECM=PSC1(4)+PSC2(4)
3599         AM1=PSC1(5)**2
3600         AM2=PSC2(5)**2
3601         AMM=ECM**2-PCM1**2-PCM2**2-PCM3**2
3602         IF(AMM.LE.PSC1(5)+PSC2(5)) RETURN
3603 C               ********elastic scattering only when approaching
3604 C                               to each other
3605         PMAX=(AMM**2+AM1**2+AM2**2-2.0*AMM*AM1-2.0*AMM*AM2
3606      &                  -2.0*AM1*AM2)/4.0/AMM
3607         PMAX=ABS(PMAX)
3608 20      TT=RLU(0)*MIN(PMAX,1.5)
3609         ELS=98.0*EXP(-2.8*TT)/EP
3610      &          +52.0*EXP(-9.2*TT)*(1.0+RR*EXP(-4.6*(BB-1.0)*TT))**2
3611         IF(RLU(0).GT.ELS/ELS0) GO TO 20
3612         PHI=2.0*HIPR1(40)*RLU(0)
3613 C
3614         DBX=PCM1/ECM
3615         DBY=PCM2/ECM
3616         DBZ=PCM3/ECM
3617         DB=SQRT(DBX**2+DBY**2+DBZ**2)
3618         IF(DB.GT.0.99999999D0) THEN 
3619           DBX=DBX*(0.99999999D0/DB) 
3620           DBY=DBY*(0.99999999D0/DB) 
3621           DBZ=DBZ*(0.99999999D0/DB) 
3622           DB=0.99999999D0   
3623           WRITE(6,*) ' (HIJELS) boost vector too large' 
3624 C               ********Rescale boost vector if too close to unity. 
3625         ENDIF   
3626         DGA=1D0/SQRT(1D0-DB**2)      
3627 C
3628         DP1=SQRT(TT)*SIN(PHI)
3629         DP2=SQRT(TT)*COS(PHI)
3630         DP3=SQRT(PMAX-TT)
3631         DP4=SQRT(PMAX+AM1)
3632         DBP=DBX*DP1+DBY*DP2+DBZ*DP3   
3633         DGABP=DGA*(DGA*DBP/(1D0+DGA)+DP4) 
3634         PSC1(1)=DP1+DGABP*DBX
3635         PSC1(2)=DP2+DGABP*DBY  
3636         PSC1(3)=DP3+DGABP*DBZ  
3637         PSC1(4)=DGA*(DP4+DBP)    
3638 C       
3639         DP1=-SQRT(TT)*SIN(PHI)
3640         DP2=-SQRT(TT)*COS(PHI)
3641         DP3=-SQRT(PMAX-TT)
3642         DP4=SQRT(PMAX+AM2)
3643         DBP=DBX*DP1+DBY*DP2+DBZ*DP3   
3644         DGABP=DGA*(DGA*DBP/(1D0+DGA)+DP4) 
3645         PSC2(1)=DP1+DGABP*DBX
3646         PSC2(2)=DP2+DGABP*DBY  
3647         PSC2(3)=DP3+DGABP*DBZ  
3648         PSC2(4)=DGA*(DP4+DBP)
3649         RETURN
3650         END
3651 C
3652 C       
3653 C*******************************************************************
3654 C                                                                  *
3655 C               Subroutine HIJSFT                                  *
3656 C                                                                  *
3657 C  Scatter two excited strings, JP from proj and JT from target    *
3658 C*******************************************************************
3659         SUBROUTINE HIJSFT(JP,JT,JOUT,IERROR)
3660         COMMON/HIJCRDN/YP(3,300),YT(3,300)
3661         SAVE  /HIJCRDN/
3662         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
3663         SAVE  /HIPARNT/
3664         COMMON/HIJDAT/HIDAT0(10,10),HIDAT(10)
3665         SAVE  /HIJDAT/
3666         COMMON/RANSEED/NSEED
3667         SAVE  /RANSEED/
3668         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
3669      &               PJPY(300,500),PJPZ(300,500),PJPE(300,500),
3670      &               PJPM(300,500),NTJ(300),KFTJ(300,500),
3671      &               PJTX(300,500),PJTY(300,500),PJTZ(300,500),
3672      &               PJTE(300,500),PJTM(300,500)
3673         SAVE  /HIJJET1/
3674         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
3675      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
3676      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
3677         SAVE  /HIJJET2/
3678         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
3679         SAVE  /HISTRNG/
3680         COMMON/DPMCOM1/JJP,JJT,AMP,AMT,APX0,ATX0,AMPN,AMTN,AMP0,AMT0,
3681      &          NFDP,NFDT,WP,WM,SW,XREMP,XREMT,DPKC1,DPKC2,PP11,PP12,
3682      &          PT11,PT12,PTP2,PTT2
3683         SAVE  /DPMCOM1/
3684         COMMON/DPMCOM2/NDPM,KDPM(20,2),PDPM1(20,5),PDPM2(20,5)
3685         SAVE  /DPMCOM2/
3686 C*******************************************************************
3687 C       JOUT-> the number
3688 C       of hard scatterings preceding this soft collision. 
3689 C       IHNT2(13)-> 1=
3690 C       double diffrac 2=single diffrac, 3=non-single diffrac.
3691 C*******************************************************************
3692         IERROR=0
3693         JJP=JP
3694         JJT=JT
3695         NDPM=0
3696         IOPMAIN=0
3697         IF(JP.GT.IHNT2(1) .OR. JT.GT.IHNT2(3)) RETURN
3698 
3699         EPP=PP(JP,4)+PP(JP,3)
3700         EPM=PP(JP,4)-PP(JP,3)
3701         ETP=PT(JT,4)+PT(JT,3)
3702         ETM=PT(JT,4)-PT(JT,3)
3703 
3704         WP=EPP+ETP
3705         WM=EPM+ETM
3706         SW=WP*WM
3707 C               ********total W+,W- and center-of-mass energy
3708 
3709         IF(WP.LT.0.0 .OR. WM.LT.0.0) GO TO 1000
3710 
3711         IF(JOUT.EQ.0) THEN
3712                 IF(EPP.LT.0.0) GO TO 1000
3713                 IF(EPM.LT.0.0) GO TO 1000
3714                 IF(ETP.LT.0.0) GO TO 1000
3715                 IF(ETM.LT.0.0) GO TO 1000    
3716                 IF(EPP/(EPM+0.01).LE.ETP/(ETM+0.01)) RETURN
3717         ENDIF
3718 C               ********For strings which does not follow a jet-prod,
3719 C                       scatter only if Ycm(JP)>Ycm(JT). When jets
3720 C                       are produced just before this collision
3721 C                       this requirement has already be enforced
3722 C                       (see SUBROUTINE HIJHRD)
3723         IHNT2(11)=JP
3724         IHNT2(12)=JT
3725 C
3726 C
3727 C
3728         MISS=0
3729         PKC1=0.0
3730         PKC2=0.0
3731         PKC11=0.0
3732         PKC12=0.0
3733         PKC21=0.0
3734         PKC22=0.0
3735         DPKC11=0.0
3736         DPKC12=0.0
3737         DPKC21=0.0
3738         DPKC22=0.0
3739         IF(NFP(JP,10).EQ.1.OR.NFT(JT,10).EQ.1) THEN
3740            IF(NFP(JP,10).EQ.1) THEN
3741               PHI1=ULANGL(PP(JP,10),PP(JP,11))
3742               PPJET=SQRT(PP(JP,10)**2+PP(JP,11)**2)
3743               PKC1=PPJET
3744               PKC11=PP(JP,10)
3745               PKC12=PP(JP,11)
3746            ENDIF
3747            IF(NFT(JT,10).EQ.1) THEN
3748               PHI2=ULANGL(PT(JT,10),PT(JT,11))
3749               PTJET=SQRT(PT(JT,10)**2+PT(JT,11)**2)
3750               PKC2=PTJET
3751               PKC21=PT(JT,10)
3752               PKC22=PT(JT,11)
3753            ENDIF
3754            IF(IHPR2(4).GT.0.AND.IHNT2(1).GT.1.AND.IHNT2(3).GT.1) THEN
3755               IF(NFP(JP,10).EQ.0) THEN
3756                  PHI=-PHI2
3757               ELSE IF(NFT(JT,10).EQ.0) THEN
3758                  PHI=PHI1
3759               ELSE
3760                  PHI=(PHI1+PHI2-HIPR1(40))/2.0
3761               ENDIF
3762               BX=HINT1(19)*COS(HINT1(20))
3763               BY=HINT1(19)*SIN(HINT1(20))
3764               XP0=YP(1,JP)
3765               YP0=YP(2,JP)
3766               XT0=YT(1,JT)+BX
3767               YT0=YT(2,JT)+BY
3768               R1=MAX(1.2*IHNT2(1)**0.3333333,
3769      &               SQRT(XP0**2+YP0**2))
3770               R2=MAX(1.2*IHNT2(3)**0.3333333,
3771      &               SQRT((XT0-BX)**2+(YT0-BY)**2))
3772               IF(ABS(COS(PHI)).LT.1.0E-5) THEN
3773                  DD1=R1
3774                  DD2=R1
3775                  DD3=ABS(BY+SQRT(R2**2-(XP0-BX)**2)-YP0)
3776                  DD4=ABS(BY-SQRT(R2**2-(XP0-BX)**2)-YP0)
3777                  GO TO 5
3778               ENDIF
3779               BB=2.0*SIN(PHI)*(COS(PHI)*YP0-SIN(PHI)*XP0)
3780               CC=(YP0**2-R1**2)*COS(PHI)**2+XP0*SIN(PHI)*(
3781      &                          XP0*SIN(PHI)-2.0*YP0*COS(PHI))
3782               DD=BB**2-4.0*CC
3783               IF(DD.LT.0.0) GO TO 10
3784               XX1=(-BB+SQRT(DD))/2.0
3785               XX2=(-BB-SQRT(DD))/2.0
3786               DD1=ABS((XX1-XP0)/COS(PHI))
3787               DD2=ABS((XX2-XP0)/COS(PHI))
3788 C                       
3789               BB=2.0*SIN(PHI)*(COS(PHI)*(YT0-BY)-SIN(PHI)*XT0)-2.0*BX
3790               CC=(BX**2+(YT0-BY)**2-R2**2)*COS(PHI)**2+XT0*SIN(PHI)
3791      &           *(XT0*SIN(PHI)-2.0*COS(PHI)*(YT0-BY))
3792      &           -2.0*BX*SIN(PHI)*(COS(PHI)*(YT0-BY)-SIN(PHI)*XT0)
3793               DD=BB**2-4.0*CC
3794               IF(DD.LT.0.0) GO TO 10
3795               XX1=(-BB+SQRT(DD))/2.0
3796               XX2=(-BB-SQRT(DD))/2.0
3797               DD3=ABS((XX1-XT0)/COS(PHI))
3798               DD4=ABS((XX2-XT0)/COS(PHI))
3799 C
3800  5            DD1=MIN(DD1,DD3)
3801               DD2=MIN(DD2,DD4)
3802               IF(DD1.LT.HIPR1(13)) DD1=0.0
3803               IF(DD2.LT.HIPR1(13)) DD2=0.0
3804               IF(NFP(JP,10).EQ.1.AND.PPJET.GT.HIPR1(11)) THEN
3805                  DP1=DD1*HIPR1(14)/2.0
3806                  DP1=MIN(DP1,PPJET-HIPR1(11))
3807                  PKC1=PPJET-DP1
3808                  DPX1=COS(PHI1)*DP1
3809                  DPY1=SIN(PHI1)*DP1
3810                  PKC11=PP(JP,10)-DPX1
3811                  PKC12=PP(JP,11)-DPY1
3812                  IF(DP1.GT.0.0) THEN
3813                     CTHEP=PP(JP,12)/SQRT(PP(JP,12)**2+PPJET**2)
3814                     DPZ1=DP1*CTHEP/SQRT(1.0-CTHEP**2)
3815                     DPE1=SQRT(DPX1**2+DPY1**2+DPZ1**2)
3816                     EPPPRM=PP(JP,4)+PP(JP,3)-DPE1-DPZ1
3817                     EPMPRM=PP(JP,4)-PP(JP,3)-DPE1+DPZ1
3818                     IF(EPPPRM.LE.0.0.OR.EPMPRM.LE.0.0) GO TO 15
3819                     EPP=EPPPRM
3820                     EPM=EPMPRM
3821                     PP(JP,10)=PKC11
3822                     PP(JP,11)=PKC12
3823                     NPJ(JP)=NPJ(JP)+1
3824                     KFPJ(JP,NPJ(JP))=21
3825                     PJPX(JP,NPJ(JP))=DPX1
3826                     PJPY(JP,NPJ(JP))=DPY1
3827                     PJPZ(JP,NPJ(JP))=DPZ1
3828                     PJPE(JP,NPJ(JP))=DPE1
3829                     PJPM(JP,NPJ(JP))=0.0
3830                     PP(JP,3)=PP(JP,3)-DPZ1
3831                     PP(JP,4)=PP(JP,4)-DPE1
3832                  ENDIF
3833               ENDIF
3834  15           IF(NFT(JT,10).EQ.1.AND.PTJET.GT.HIPR1(11)) THEN
3835                  DP2=DD2*HIPR1(14)/2.0
3836                  DP2=MIN(DP2,PTJET-HIPR1(11))
3837                  PKC2=PTJET-DP2
3838                  DPX2=COS(PHI2)*DP2
3839                  DPY2=SIN(PHI2)*DP2
3840                  PKC21=PT(JT,10)-DPX2
3841                  PKC22=PT(JT,11)-DPY2
3842                  IF(DP2.GT.0.0) THEN
3843                     CTHET=PT(JT,12)/SQRT(PT(JT,12)**2+PTJET**2)
3844                     DPZ2=DP2*CTHET/SQRT(1.0-CTHET**2)
3845                     DPE2=SQRT(DPX2**2+DPY2**2+DPZ2**2)
3846                     ETPPRM=PT(JT,4)+PT(JT,3)-DPE2-DPZ2
3847                     ETMPRM=PT(JT,4)-PT(JT,3)-DPE2+DPZ2
3848                     IF(ETPPRM.LE.0.0.OR.ETMPRM.LE.0.0) GO TO 16
3849                     ETP=ETPPRM
3850                     ETM=ETMPRM
3851                     PT(JT,10)=PKC21
3852                     PT(JT,11)=PKC22
3853                     NTJ(JT)=NTJ(JT)+1
3854                     KFTJ(JT,NTJ(JT))=21
3855                     PJTX(JT,NTJ(JT))=DPX2
3856                     PJTY(JT,NTJ(JT))=DPY2
3857                     PJTZ(JT,NTJ(JT))=DPZ2
3858                     PJTE(JT,NTJ(JT))=DPE2
3859                     PJTM(JT,NTJ(JT))=0.0
3860                     PT(JT,3)=PT(JT,3)-DPZ2
3861                     PT(JT,4)=PT(JT,4)-DPE2
3862                  ENDIF
3863               ENDIF
3864  16           DPKC11=-(PP(JP,10)-PKC11)/2.0
3865               DPKC12=-(PP(JP,11)-PKC12)/2.0
3866               DPKC21=-(PT(JT,10)-PKC21)/2.0
3867               DPKC22=-(PT(JT,11)-PKC22)/2.0
3868               WP=EPP+ETP
3869               WM=EPM+ETM
3870               SW=WP*WM
3871            ENDIF
3872         ENDIF
3873 C               ********If jet is quenched the pt from valence quark
3874 C                       hard scattering has to reduced by d*kapa
3875 C
3876 C   
3877 10      PTP02=PP(JP,1)**2+PP(JP,2)**2
3878         PTT02=PT(JT,1)**2+PT(JT,2)**2
3879 C       
3880         AMQ=MAX(PP(JP,14)+PP(JP,15),PT(JT,14)+PT(JT,15))
3881         AMX=HIPR1(1)+AMQ
3882 C               ********consider mass cut-off for strings which
3883 C                       must also include quark's mass
3884         AMP0=AMX
3885         DPM0=AMX
3886         NFDP=0
3887         IF(NFP(JP,5).LE.2.AND.NFP(JP,3).NE.0) THEN
3888                 AMP0=ULMASS(NFP(JP,3))
3889                 NFDP=NFP(JP,3)+2*NFP(JP,3)/ABS(NFP(JP,3))
3890                 DPM0=ULMASS(NFDP)
3891                 IF(DPM0.LE.0.0) THEN
3892                         NFDP=NFDP-2*NFDP/ABS(NFDP)
3893                         DPM0=ULMASS(NFDP)
3894                 ENDIF
3895         ENDIF
3896         AMT0=AMX
3897         DTM0=AMX
3898         NFDT=0
3899         IF(NFT(JT,5).LE.2.AND.NFT(JT,3).NE.0) THEN
3900                 AMT0=ULMASS(NFT(JT,3))
3901                 NFDT=NFT(JT,3)+2*NFT(JT,3)/ABS(NFT(JT,3))
3902                 DTM0=ULMASS(NFDT)
3903                 IF(DTM0.LE.0.0) THEN
3904                         NFDT=NFDT-2*NFDT/ABS(NFDT)
3905                         DTM0=ULMASS(NFDT)
3906                 ENDIF
3907         ENDIF
3908 C       
3909         AMPN=SQRT(AMP0**2+PTP02)
3910         AMTN=SQRT(AMT0**2+PTT02)
3911         SNN=(AMPN+AMTN)**2+0.001
3912 C
3913         IF(SW.LT.SNN+0.001) GO TO 4000
3914 C               ********Scatter only if SW>SNN
3915 C*****give some PT kick to the two exited strings******************
3916 20      SWPTN=4.0*(MAX(AMP0,AMT0)**2+MAX(PTP02,PTT02))
3917         SWPTD=4.0*(MAX(DPM0,DTM0)**2+MAX(PTP02,PTT02))
3918         SWPTX=4.0*(AMX**2+MAX(PTP02,PTT02))
3919         IF(SW.LE.SWPTN) THEN
3920                 PKCMX=0.0
3921         ELSE IF(SW.GT.SWPTN .AND. SW.LE.SWPTD
3922      &          .AND.NPJ(JP).EQ.0.AND.NTJ(JT).EQ.0) THEN
3923            PKCMX=SQRT(SW/4.0-MAX(AMP0,AMT0)**2)
3924      &           -SQRT(MAX(PTP02,PTT02))
3925         ELSE IF(SW.GT.SWPTD .AND. SW.LE.SWPTX
3926      &          .AND.NPJ(JP).EQ.0.AND.NTJ(JT).EQ.0) THEN
3927            PKCMX=SQRT(SW/4.0-MAX(DPM0,DTM0)**2)
3928      &           -SQRT(MAX(PTP02,PTT02))
3929         ELSE IF(SW.GT.SWPTX) THEN
3930            PKCMX=SQRT(SW/4.0-AMX**2)-SQRT(MAX(PTP02,PTT02))
3931         ENDIF
3932 C               ********maximun PT kick
3933 C*********************************************************
3934 C
3935         IF(NFP(JP,10).EQ.1.OR.NFT(JT,10).EQ.1) THEN
3936                 IF(PKC1.GT.PKCMX) THEN
3937                         PKC1=PKCMX
3938                         PKC11=PKC1*COS(PHI1)
3939                         PKC12=PKC1*SIN(PHI1)
3940                         DPKC11=-(PP(JP,10)-PKC11)/2.0
3941                         DPKC12=-(PP(JP,11)-PKC12)/2.0
3942                 ENDIF
3943                 IF(PKC2.GT.PKCMX) THEN
3944                         PKC2=PKCMX
3945                         PKC21=PKC2*COS(PHI2)
3946                         PKC22=PKC2*SIN(PHI2)
3947                         DPKC21=-(PT(JT,10)-PKC21)/2.0
3948                         DPKC22=-(PT(JT,11)-PKC22)/2.0
3949                 ENDIF
3950                 DPKC1=DPKC11+DPKC21
3951                 DPKC2=DPKC12+DPKC22
3952                 NFP(JP,10)=-NFP(JP,10)
3953                 NFT(JT,10)=-NFT(JT,10)
3954                 GO TO 40
3955         ENDIF
3956 C               ********If the valence quarks had a hard-collision
3957 C                       the pt kick is the pt from hard-collision.
3958         I_SNG=0
3959         IF(IHPR2(13).NE.0 .AND. RLU(0).LE.HIDAT(4)) I_SNG=1
3960         IF((NFP(JP,5).EQ.3 .OR.NFT(JT,5).EQ.3).OR.
3961      &          (NPJ(JP).NE.0.OR.NFP(JP,10).NE.0).OR.
3962      &          (NTJ(JT).NE.0.OR.NFT(JT,10).NE.0)) I_SNG=0
3963 C
3964 C               ********decite whether to have single-diffractive
3965         IF(IHPR2(5).EQ.0) THEN
3966                 PKC=HIPR1(2)*SQRT(-ALOG(1.0-RLU(0)
3967      &                  *(1.0-EXP(-PKCMX**2/HIPR1(2)**2))))
3968                 GO TO 30
3969         ENDIF
3970         PKC=HIRND2(3,0.0,PKCMX**2)
3971         PKC=SQRT(PKC)
3972         IF(PKC.GT.HIPR1(20)) 
3973      &     PKC=HIPR1(2)*SQRT(-ALOG(EXP(-HIPR1(20)**2/HIPR1(2)**2)
3974      &         -RLU(0)*(EXP(-HIPR1(20)**2/HIPR1(2)**2)-
3975      &         EXP(-PKCMX**2/HIPR1(2)**2))))
3976 C
3977         IF(I_SNG.EQ.1) PKC=0.65*SQRT(
3978      &          -ALOG(1.0-RLU(0)*(1.0-EXP(-PKCMX**2/0.65**2))))
3979 C                       ********select PT kick
3980 30      PHI0=2.0*HIPR1(40)*RLU(0)
3981         PKC11=PKC*SIN(PHI0)
3982         PKC12=PKC*COS(PHI0)
3983         PKC21=-PKC11
3984         PKC22=-PKC12
3985         DPKC1=0.0
3986         DPKC2=0.0
3987 40      PP11=PP(JP,1)+PKC11-DPKC1
3988         PP12=PP(JP,2)+PKC12-DPKC2
3989         PT11=PT(JT,1)+PKC21-DPKC1
3990         PT12=PT(JT,2)+PKC22-DPKC2
3991         PTP2=PP11**2+PP12**2
3992         PTT2=PT11**2+PT12**2
3993 C
3994         AMPN=SQRT(AMP0**2+PTP2)
3995         AMTN=SQRT(AMT0**2+PTT2)
3996         SNN=(AMPN+AMTN)**2+0.001
3997 C***************************************
3998         WP=EPP+ETP
3999         WM=EPM+ETM
4000         SW=WP*WM
4001 C****************************************
4002         IF(SW.LT.SNN) THEN
4003            MISS=MISS+1
4004            IF(MISS.LE.100) then
4005               PKC=0.0
4006               GO TO 30
4007            ENDIF
4008            IF(IHPR2(10).NE.0) 
4009      &       WRITE(6,*) 'Error occured in Pt kick section of HIJSFT'
4010            GO TO 4000
4011         ENDIF
4012 C******************************************************************
4013         AMPD=SQRT(DPM0**2+PTP2)
4014         AMTD=SQRT(DTM0**2+PTT2)
4015 
4016         AMPX=SQRT(AMX**2+PTP2)
4017         AMTX=SQRT(AMX**2+PTT2)
4018 
4019         DPN=AMPN**2/SW
4020         DTN=AMTN**2/SW
4021         DPD=AMPD**2/SW
4022         DTD=AMTD**2/SW
4023         DPX=AMPX**2/SW
4024         DTX=AMTX**2/SW
4025 C
4026         SPNTD=(AMPN+AMTD)**2
4027         SPNTX=(AMPN+AMTX)**2
4028 C                       ********CM energy if proj=N,targ=N*
4029         SPDTN=(AMPD+AMTN)**2
4030         SPXTN=(AMPX+AMTN)**2
4031 C                       ********CM energy if proj=N*,targ=N
4032         SPDTX=(AMPD+AMTX)**2
4033         SPXTD=(AMPX+AMTD)**2
4034         SDD=(AMPD+AMTD)**2
4035         SXX=(AMPX+AMTX)**2
4036 
4037 C
4038 C       
4039 C               ********CM energy if proj=delta, targ=delta
4040 C****************There are many different cases**********
4041 c       IF(IHPR2(15).EQ.1) GO TO 500
4042 C
4043 C               ********to have DPM type soft interactions
4044 C
4045  45     CONTINUE
4046         IF(SW.GT.SXX+0.001) THEN
4047            IF(I_SNG.EQ.0) THEN
4048               D1=DPX
4049               D2=DTX
4050               NFP3=0
4051               NFT3=0
4052               GO TO 400
4053            ELSE
4054 c**** 5/30/1998 this is identical to the above statement. Added to
4055 c**** avoid questional branching to block.
4056               IF((NFP(JP,5).EQ.3 .AND.NFT(JT,5).EQ.3).OR.
4057      &           (NPJ(JP).NE.0.OR.NFP(JP,10).NE.0).OR.
4058      &           (NTJ(JT).NE.0.OR.NFT(JT,10).NE.0)) THEN
4059                  D1=DPX
4060                  D2=DTX
4061                  NFP3=0
4062                  NFT3=0
4063                  GO TO 400
4064               ENDIF
4065 C               ********do not allow excited strings to have 
4066 C                       single-diffr 
4067               IF(RLU(0).GT.0.5.OR.(NFT(JT,5).GT.2.OR.
4068      &                NTJ(JT).NE.0.OR.NFT(JT,10).NE.0)) THEN
4069                  D1=DPN
4070                  D2=DTX
4071                  NFP3=NFP(JP,3)
4072                  NFT3=0
4073                  GO TO 220
4074               ELSE
4075                  D1=DPX
4076                  D2=DTN
4077                  NFP3=0
4078                  NFT3=NFT(JT,3)
4079                  GO TO 240
4080               ENDIF
4081 C               ********have single diffractive collision
4082            ENDIF
4083         ELSE IF(SW.GT.MAX(SPDTX,SPXTD)+0.001 .AND.
4084      &                          SW.LE.SXX+0.001) THEN
4085            IF(((NPJ(JP).EQ.0.AND.NTJ(JT).EQ.0.AND.
4086      &         RLU(0).GT.0.5).OR.(NPJ(JP).EQ.0
4087      &         .AND.NTJ(JT).NE.0)).AND.NFP(JP,5).LE.2) THEN
4088               D1=DPD
4089               D2=DTX
4090               NFP3=NFDP
4091               NFT3=0
4092               GO TO 220
4093            ELSE IF(NTJ(JT).EQ.0.AND.NFT(JT,5).LE.2) THEN
4094               D1=DPX
4095               D2=DTD
4096               NFP3=0
4097               NFT3=NFDT
4098               GO TO 240
4099            ENDIF
4100            GO TO 4000
4101         ELSE IF(SW.GT.MIN(SPDTX,SPXTD)+0.001.AND.
4102      &                  SW.LE.MAX(SPDTX,SPXTD)+0.001) THEN
4103            IF(SPDTX.LE.SPXTD.AND.NPJ(JP).EQ.0
4104      &                       .AND.NFP(JP,5).LE.2) THEN
4105               D1=DPD
4106               D2=DTX
4107               NFP3=NFDP
4108               NFT3=0
4109               GO TO 220
4110            ELSE IF(SPDTX.GT.SPXTD.AND.NTJ(JT).EQ.0
4111      &                       .AND.NFT(JT,5).LE.2) THEN
4112               D1=DPX
4113               D2=DTD
4114               NFP3=0
4115               NFT3=NFDT
4116               GO TO 240
4117            ENDIF
4118 c*** 5/30/1998 added to avoid questional branching to another block
4119 c*** this is identical to the statement following the next ELSE IF
4120            IF(((NPJ(JP).EQ.0.AND.NTJ(JT).EQ.0
4121      &       .AND.RLU(0).GT.0.5).OR.(NPJ(JP).EQ.0
4122      &        .AND.NTJ(JT).NE.0)).AND.NFP(JP,5).LE.2) THEN
4123               D1=DPN
4124               D2=DTX
4125               NFP3=NFP(JP,3)
4126               NFT3=0
4127               GO TO 220
4128            ELSE IF(NTJ(JT).EQ.0.AND.NFT(JT,5).LE.2) THEN
4129               D1=DPX
4130               D2=DTN
4131               NFP3=0
4132               NFT3=NFT(JT,3)
4133               GO TO 240
4134            ENDIF
4135            GO TO 4000
4136         ELSE IF(SW.GT.MAX(SPNTX,SPXTN)+0.001 .AND.
4137      &                  SW.LE.MIN(SPDTX,SPXTD)+0.001) THEN
4138            IF(((NPJ(JP).EQ.0.AND.NTJ(JT).EQ.0
4139      &       .AND.RLU(0).GT.0.5).OR.(NPJ(JP).EQ.0
4140      &        .AND.NTJ(JT).NE.0)).AND.NFP(JP,5).LE.2) THEN
4141               D1=DPN
4142               D2=DTX
4143               NFP3=NFP(JP,3)
4144               NFT3=0
4145               GO TO 220
4146            ELSE IF(NTJ(JT).EQ.0.AND.NFT(JT,5).LE.2) THEN
4147               D1=DPX
4148               D2=DTN
4149               NFP3=0
4150               NFT3=NFT(JT,3)
4151               GO TO 240
4152            ENDIF
4153            GO TO 4000
4154         ELSE IF(SW.GT.MIN(SPNTX,SPXTN)+0.001 .AND.
4155      &                  SW.LE.MAX(SPNTX,SPXTN)+0.001) THEN
4156            IF(SPNTX.LE.SPXTN.AND.NPJ(JP).EQ.0
4157      &                           .AND.NFP(JP,5).LE.2) THEN
4158               D1=DPN
4159               D2=DTX
4160               NFP3=NFP(JP,3)
4161               NFT3=0
4162               GO TO 220
4163            ELSEIF(SPNTX.GT.SPXTN.AND.NTJ(JT).EQ.0
4164      &                           .AND.NFT(JT,5).LE.2) THEN
4165               D1=DPX
4166               D2=DTN
4167               NFP3=0
4168               NFT3=NFT(JT,3)
4169               GO TO 240
4170            ENDIF
4171            GO TO 4000
4172         ELSE IF(SW.LE.MIN(SPNTX,SPXTN)+0.001 .AND.
4173      &                  (NPJ(JP).NE.0 .OR.NTJ(JT).NE.0)) THEN
4174            GO TO 4000
4175         ELSE IF(SW.LE.MIN(SPNTX,SPXTN)+0.001 .AND.
4176      &          NFP(JP,5).GT.2.AND.NFT(JT,5).GT.2) THEN
4177            GO TO 4000
4178         ELSE IF(SW.GT.SDD+0.001.AND.SW.LE.
4179      &                     MIN(SPNTX,SPXTN)+0.001) THEN
4180            D1=DPD
4181            D2=DTD
4182            NFP3=NFDP
4183            NFT3=NFDT
4184            GO TO 100
4185         ELSE IF(SW.GT.MAX(SPNTD,SPDTN)+0.001 
4186      &                      .AND. SW.LE.SDD+0.001) THEN
4187            IF(RLU(0).GT.0.5) THEN
4188               D1=DPD
4189               D2=DTN
4190               NFP3=NFDP
4191               NFT3=NFT(JT,3)
4192               GO TO 100
4193            ELSE
4194               D1=DPN
4195               D2=DTD
4196               NFP3=NFP(JP,3)
4197               NFT3=NFDT
4198               GO TO 100
4199            ENDIF
4200         ELSE IF(SW.GT.MIN(SPNTD,SPDTN)+0.001
4201      &          .AND. SW.LE.MAX(SPNTD,SPDTN)+0.001) THEN
4202            IF(SPNTD.GT.SPDTN) THEN
4203               D1=DPD
4204               D2=DTN
4205               NFP3=NFDP
4206               NFT3=NFT(JT,3)
4207               GO TO 100
4208            ELSE
4209               D1=DPN
4210               D2=DTD
4211               NFP3=NFP(JP,3)
4212               NFT3=NFDT
4213               GO TO 100
4214            ENDIF
4215         ELSE IF(SW.LE.MIN(SPNTD,SPDTN)+0.001) THEN
4216            D1=DPN
4217            D2=DTN
4218            NFP3=NFP(JP,3)
4219            NFT3=NFT(JT,3)
4220            GO TO 100
4221         ENDIF
4222         WRITE(6,*) ' Error in HIJSFT: There is no path to here'
4223         RETURN
4224 C
4225 C***************  elastic scattering ***************
4226 C       this is like elastic, both proj and targ mass
4227 C       must be fixed
4228 C***************************************************
4229 100     NFP5=MAX(2,NFP(JP,5))
4230         NFT5=MAX(2,NFT(JT,5))
4231         BB1=1.0+D1-D2
4232         BB2=1.0+D2-D1
4233         IF(BB1**2.LT.4.0*D1 .OR. BB2**2.LT.4.0*D2) THEN
4234                 MISS=MISS+1
4235                 IF(MISS.GT.100.OR.PKC.EQ.0.0) GO TO 3000
4236                 PKC=PKC*0.5
4237                 GO TO 30
4238         ENDIF
4239         IF(RLU(0).LT.0.5) THEN
4240                 X1=(BB1-SQRT(BB1**2-4.0*D1))/2.0
4241                 X2=(BB2-SQRT(BB2**2-4.0*D2))/2.0
4242         ELSE
4243                 X1=(BB1+SQRT(BB1**2-4.0*D1))/2.0
4244                 X2=(BB2+SQRT(BB2**2-4.0*D2))/2.0
4245         ENDIF
4246         IHNT2(13)=2
4247         GO TO 600
4248 C
4249 C********** Single diffractive ***********************
4250 C either proj or targ's mass is fixed
4251 C*****************************************************
4252 220     NFP5=MAX(2,NFP(JP,5))
4253         NFT5=3
4254         IF(NFP3.EQ.0) NFP5=3
4255         BB2=1.0+D2-D1
4256         IF(BB2**2.LT.4.0*D2) THEN
4257                 MISS=MISS+1
4258                 IF(MISS.GT.100.OR.PKC.EQ.0.0) GO TO 3000
4259                 PKC=PKC*0.5
4260                 GO TO 30
4261         ENDIF
4262         XMIN=(BB2-SQRT(BB2**2-4.0*D2))/2.0
4263         XMAX=(BB2+SQRT(BB2**2-4.0*D2))/2.0
4264         MISS4=0
4265 222     X2=HIRND2(6,XMIN,XMAX)
4266         X1=D1/(1.0-X2)
4267         IF(X2*(1.0-X1).LT.(D2+1.E-4/SW)) THEN
4268                 MISS4=MISS4+1
4269                 IF(MISS4.LE.1000) GO TO 222
4270                 GO TO 5000
4271         ENDIF
4272         IHNT2(13)=2
4273         GO TO 600
4274 C                       ********Fix proj mass*********
4275 240     NFP5=3
4276         NFT5=MAX(2,NFT(JT,5))
4277         IF(NFT3.EQ.0) NFT5=3
4278         BB1=1.0+D1-D2
4279         IF(BB1**2.LT.4.0*D1) THEN
4280                 MISS=MISS+1
4281                 IF(MISS.GT.100.OR.PKC.EQ.0.0) GO TO 3000
4282                 PKC=PKC*0.5
4283                 GO TO 30
4284         ENDIF
4285         XMIN=(BB1-SQRT(BB1**2-4.0*D1))/2.0
4286         XMAX=(BB1+SQRT(BB1**2-4.0*D1))/2.0
4287         MISS4=0
4288 242     X1=HIRND2(6,XMIN,XMAX)
4289         X2=D2/(1.0-X1)
4290         IF(X1*(1.0-X2).LT.(D1+1.E-4/SW)) THEN
4291                 MISS4=MISS4+1
4292                 IF(MISS4.LE.1000) GO TO 242
4293                 GO TO 5000
4294         ENDIF
4295         IHNT2(13)=2
4296         GO TO 600
4297 C                       ********Fix targ mass*********
4298 C
4299 C*************non-single diffractive**********************
4300 C       both proj and targ may not be fixed in mass 
4301 C*********************************************************
4302 C
4303 400     NFP5=3
4304         NFT5=3
4305         BB1=1.0+D1-D2
4306         BB2=1.0+D2-D1
4307         IF(BB1**2.LT.4.0*D1 .OR. BB2**2.LT.4.0*D2) THEN
4308                 MISS=MISS+1
4309                 IF(MISS.GT.100.OR.PKC.EQ.0.0) GO TO 3000
4310                 PKC=PKC*0.5
4311                 GO TO 30
4312         ENDIF
4313         XMIN1=(BB1-SQRT(BB1**2-4.0*D1))/2.0
4314         XMAX1=(BB1+SQRT(BB1**2-4.0*D1))/2.0
4315         XMIN2=(BB2-SQRT(BB2**2-4.0*D2))/2.0
4316         XMAX2=(BB2+SQRT(BB2**2-4.0*D2))/2.0
4317         MISS4=0 
4318 410     X1=HIRND2(4,XMIN1,XMAX1)
4319         X2=HIRND2(4,XMIN2,XMAX2)
4320         IF(NFP(JP,5).EQ.3.OR.NFT(JT,5).EQ.3) THEN
4321                 X1=HIRND2(6,XMIN1,XMAX1)
4322                 X2=HIRND2(6,XMIN2,XMAX2)
4323         ENDIF
4324 C                       ********
4325         IF(ABS(NFP(JP,1)*NFP(JP,2)).GT.1000000.OR.
4326      &                  ABS(NFP(JP,1)*NFP(JP,2)).LT.100) THEN
4327                 X1=HIRND2(5,XMIN1,XMAX1)
4328         ENDIF
4329         IF(ABS(NFT(JT,1)*NFT(JT,2)).GT.1000000.OR.
4330      &                  ABS(NFT(JT,1)*NFT(JT,2)).LT.100) THEN
4331                 X2=HIRND2(5,XMIN2,XMAX2)
4332         ENDIF
4333 c       IF(IOPMAIN.EQ.3) X1=HIRND2(6,XMIN1,XMAX1)
4334 c       IF(IOPMAIN.EQ.2) X2=HIRND2(6,XMIN2,XMAX2) 
4335 C       ********For q-qbar or (qq)-(qq)bar system use symetric
4336 C               distribution, for q-(qq) or qbar-(qq)bar use
4337 C               unsymetrical distribution
4338 C
4339         IF(ABS(NFP(JP,1)*NFP(JP,2)).GT.1000000) X1=1.0-X1
4340         XXP=X1*(1.0-X2)
4341         XXT=X2*(1.0-X1)
4342         IF(XXP.LT.(D1+1.E-4/SW) .OR. XXT.LT.(D2+1.E-4/SW)) THEN
4343                 MISS4=MISS4+1
4344                 IF(MISS4.LE.1000) GO TO 410
4345                 GO TO 5000
4346         ENDIF
4347         IHNT2(13)=3
4348 C***************************************************
4349 C***************************************************
4350 600     CONTINUE
4351         IF(X1*(1.0-X2).LT.(AMPN**2-1.E-4)/SW.OR.
4352      &                  X2*(1.0-X1).LT.(AMTN**2-1.E-4)/SW) THEN
4353                 MISS=MISS+1
4354                 IF(MISS.GT.100.OR.PKC.EQ.0.0) GO TO 2000
4355                 PKC=0.0
4356                 GO TO 30
4357         ENDIF
4358 C
4359         EPP=(1.0-X2)*WP
4360         EPM=X1*WM
4361         ETP=X2*WP
4362         ETM=(1.0-X1)*WM
4363         PP(JP,3)=(EPP-EPM)/2.0
4364         PP(JP,4)=(EPP+EPM)/2.0
4365         IF(EPP*EPM-PTP2.LT.0.0) GO TO 6000
4366         PP(JP,5)=SQRT(EPP*EPM-PTP2)
4367         NFP(JP,3)=NFP3
4368         NFP(JP,5)=NFP5
4369 
4370         PT(JT,3)=(ETP-ETM)/2.0
4371         PT(JT,4)=(ETP+ETM)/2.0
4372         IF(ETP*ETM-PTT2.LT.0.0) GO TO 6000
4373         PT(JT,5)=SQRT(ETP*ETM-PTT2)
4374         NFT(JT,3)=NFT3
4375         NFT(JT,5)=NFT5
4376 C*****recoil PT from hard-inter is shared by two end-partons 
4377 C       so that pt=p1+p2
4378         PP(JP,1)=PP11-PKC11
4379         PP(JP,2)=PP12-PKC12
4380 
4381         KICKDIP=1
4382         KICKDIT=1
4383         IF(ABS(NFP(JP,1)*NFP(JP,2)).GT.1000000.OR.
4384      &                  ABS(NFP(JP,1)*NFP(JP,2)).LT.100) THEN
4385                 KICKDIP=0
4386         ENDIF
4387         IF(ABS(NFT(JT,1)*NFT(JT,2)).GT.1000000.OR.
4388      &                  ABS(NFT(JT,1)*NFT(JT,2)).LT.100) THEN
4389                 KICKDIT=0
4390         ENDIF
4391         IF((KICKDIP.EQ.0.AND.RLU(0).LT.0.5)
4392      &     .OR.(KICKDIP.NE.0.AND.RLU(0)
4393      &     .LT.0.5/(1.0+(PKC11**2+PKC12**2)/HIPR1(22)**2))) THEN
4394            PP(JP,6)=(PP(JP,1)-PP(JP,6)-PP(JP,8)-DPKC1)/2.0+PP(JP,6)
4395            PP(JP,7)=(PP(JP,2)-PP(JP,7)-PP(JP,9)-DPKC2)/2.0+PP(JP,7)
4396            PP(JP,8)=(PP(JP,1)-PP(JP,6)-PP(JP,8)-DPKC1)/2.0
4397      &              +PP(JP,8)+PKC11
4398            PP(JP,9)=(PP(JP,2)-PP(JP,7)-PP(JP,9)-DPKC2)/2.0
4399      &              +PP(JP,9)+PKC12
4400         ELSE
4401            PP(JP,8)=(PP(JP,1)-PP(JP,6)-PP(JP,8)-DPKC1)/2.0+PP(JP,8)
4402            PP(JP,9)=(PP(JP,2)-PP(JP,7)-PP(JP,9)-DPKC2)/2.0+PP(JP,9)
4403            PP(JP,6)=(PP(JP,1)-PP(JP,6)-PP(JP,8)-DPKC1)/2.0
4404      &              +PP(JP,6)+PKC11
4405            PP(JP,7)=(PP(JP,2)-PP(JP,7)-PP(JP,9)-DPKC2)/2.0
4406      &              +PP(JP,7)+PKC12
4407         ENDIF
4408         PP(JP,1)=PP(JP,6)+PP(JP,8)
4409         PP(JP,2)=PP(JP,7)+PP(JP,9)
4410 C                               ********pt kick for proj
4411         PT(JT,1)=PT11-PKC21
4412         PT(JT,2)=PT12-PKC22
4413         IF((KICKDIT.EQ.0.AND.RLU(0).LT.0.5)
4414      &     .OR.(KICKDIT.NE.0.AND.RLU(0)
4415      &     .LT.0.5/(1.0+(PKC21**2+PKC22**2)/HIPR1(22)**2))) THEN
4416            PT(JT,6)=(PT(JT,1)-PT(JT,6)-PT(JT,8)-DPKC1)/2.0+PT(JT,6)
4417            PT(JT,7)=(PT(JT,2)-PT(JT,7)-PT(JT,9)-DPKC2)/2.0+PT(JT,7)
4418            PT(JT,8)=(PT(JT,1)-PT(JT,6)-PT(JT,8)-DPKC1)/2.0
4419      &              +PT(JT,8)+PKC21
4420            PT(JT,9)=(PT(JT,2)-PT(JT,7)-PT(JT,9)-DPKC2)/2.0
4421      &              +PT(JT,9)+PKC22
4422         ELSE
4423            PT(JT,8)=(PT(JT,1)-PT(JT,6)-PT(JT,8)-DPKC1)/2.0+PT(JT,8)
4424            PT(JT,9)=(PT(JT,2)-PT(JT,7)-PT(JT,9)-DPKC2)/2.0+PT(JT,9)
4425            PT(JT,6)=(PT(JT,1)-PT(JT,6)-PT(JT,8)-DPKC1)/2.0
4426      &              +PT(JT,6)+PKC21
4427            PT(JT,7)=(PT(JT,2)-PT(JT,7)-PT(JT,9)-DPKC2)/2.0
4428      &              +PT(JT,7)+PKC22
4429         ENDIF
4430         PT(JT,1)=PT(JT,6)+PT(JT,8)
4431         PT(JT,2)=PT(JT,7)+PT(JT,9)
4432 C                       ********pt kick for targ
4433 
4434         IF(NPJ(JP).NE.0) NFP(JP,5)=3
4435         IF(NTJ(JT).NE.0) NFT(JT,5)=3
4436 C                       ********jets must be connected to string
4437         IF(EPP/(EPM+0.0001).LT.ETP/(ETM+0.0001).AND.
4438      &                  ABS(NFP(JP,1)*NFP(JP,2)).LT.1000000)THEN
4439                 DO 620 JSB=1,15
4440                 PSB=PP(JP,JSB)
4441                 PP(JP,JSB)=PT(JT,JSB)
4442                 PT(JT,JSB)=PSB
4443                 NSB=NFP(JP,JSB)
4444                 NFP(JP,JSB)=NFT(JT,JSB)
4445                 NFT(JT,JSB)=NSB
4446 620             CONTINUE
4447 C               ********when Ycm(JP)<Ycm(JT) after the collision
4448 C                       exchange the positions of the two   
4449         ENDIF
4450 C
4451         RETURN
4452 C**************************************************
4453 C**************************************************
4454 1000    IERROR=1
4455         IF(IHPR2(10).EQ.0) RETURN
4456         WRITE(6,*) '    Fatal HIJSFT start error,abandon this event'
4457         WRITE(6,*) '    PROJ E+,E-,W+',EPP,EPM,WP
4458         WRITE(6,*) '    TARG E+,E-,W-',ETP,ETM,WM
4459         WRITE(6,*) '    W+*W-, (APN+ATN)^2',SW,SNN
4460         RETURN
4461 2000    IERROR=0
4462         IF(IHPR2(10).EQ.0) RETURN
4463         WRITE(6,*) '    (2)energy partition fail,'
4464         WRITE(6,*) '    HIJSFT not performed, but continue'
4465         WRITE(6,*) '    MP1,MPN',X1*(1.0-X2)*SW,AMPN**2
4466         WRITE(6,*) '    MT2,MTN',X2*(1.0-X1)*SW,AMTN**2
4467         RETURN
4468 3000    IERROR=0
4469         IF(IHPR2(10).EQ.0) RETURN
4470         WRITE(6,*) '    (3)something is wrong with the pt kick, '
4471         WRITE(6,*) '    HIJSFT not performed, but continue'
4472         WRITE(6,*) '    D1=',D1,' D2=',D2,' SW=',SW
4473         WRITE(6,*) '    HISTORY NFP5=',NFP(JP,5),' NFT5=',NFT(JT,5)
4474         WRITE(6,*) '    THIS COLLISON NFP5=',NFP5, ' NFT5=',NFT5
4475         WRITE(6,*) '    # OF JET IN PROJ',NPJ(JP),' IN TARG',NTJ(JT)
4476         RETURN
4477 4000    IERROR=0
4478         IF(IHPR2(10).EQ.0) RETURN
4479         WRITE(6,*) '    (4)unable to choose process, but not harmful'
4480         WRITE(6,*) '    HIJSFT not performed, but continue'
4481         WRITE(6,*) '    PTP=',SQRT(PTP2),' PTT=',SQRT(PTT2),' SW=',SW
4482         WRITE(6,*) '    AMCUT=',AMX,' JP=',JP,' JT=',JT
4483         WRITE(6,*) '    HISTORY NFP5=',NFP(JP,5),' NFT5=',NFT(JT,5)
4484         RETURN
4485 5000    IERROR=0
4486         IF(IHPR2(10).EQ.0) RETURN
4487         WRITE(6,*) '    energy partition failed(5),for limited try'
4488         WRITE(6,*) '    HIJSFT not performed, but continue'
4489         WRITE(6,*) '    NFP5=',NFP5,' NFT5=',NFT5
4490         WRITE(6,*) '    D1',D1,' X1(1-X2)',X1*(1.0-X2)
4491         WRITE(6,*) '    D2',D2,' X2(1-X1)',X2*(1.0-X1)
4492         RETURN
4493 6000    PKC=0.0
4494         MISS=MISS+1
4495         IF(MISS.LT.100) GO TO 30
4496         IERROR=1
4497         IF(IHPR2(10).EQ.0) RETURN
4498         WRITE(6,*) ' ERROR OCCURED, HIJSFT NOT PERFORMED'
4499         WRITE(6,*) ' Abort this event'
4500         WRITE(6,*) 'MTP,PTP2',EPP*EPM,PTP2,'  MTT,PTT2',ETP*ETM,PTT2 
4501         RETURN
4502         END
4503 C
4504 C       
4505 C***************************************
4506         SUBROUTINE HIJFLV(ID)
4507         COMMON/RANSEED/NSEED
4508         SAVE  /RANSEED/
4509         ID=1
4510         RNID=RLU(0)
4511         IF(RNID.GT.0.43478) THEN
4512                 ID=2
4513                 IF(RNID.GT.0.86956) ID=3
4514         ENDIF
4515         RETURN
4516         END
4517 C
4518 C
4519 C
4520         SUBROUTINE HIPTDI(PT,PTMAX,IOPT)
4521         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4522         SAVE  /HIPARNT/
4523         COMMON/RANSEED/NSEED
4524         SAVE  /RANSEED/
4525         IF(IOPT.EQ.2) THEN
4526                 PT=HIRND2(7,0.0,PTMAX)
4527                 IF(PT.GT.HIPR1(8)) 
4528      &          PT=HIPR1(2)*SQRT(-ALOG(EXP(-HIPR1(8)**2/HIPR1(2)**2)
4529      &                  -RLU(0)*(EXP(-HIPR1(8)**2/HIPR1(2)**2)-
4530      &                  EXP(-PTMAX**2/HIPR1(2)**2))))
4531 
4532         ELSE
4533                 PT=HIPR1(2)*SQRT(-ALOG(1.0-RLU(0)*
4534      &                  (1.0-EXP(-PTMAX**2/HIPR1(2)**2))))
4535         ENDIF
4536         PTMAX0=MAX(PTMAX,0.01)
4537         PT=MIN(PTMAX0-0.01,PT)
4538         RETURN
4539         END
4540 C*************************
4541 C
4542 C
4543 C
4544 C
4545 C ********************************************************
4546 C ************************              WOOD-SAX
4547         SUBROUTINE HIJWDS(IA,IDH,XHIGH)
4548 C     SETS UP HISTOGRAM IDH WITH RADII FOR
4549 C     NUCLEUS IA DISTRIBUTED ACCORDING TO THREE PARAM WOOD SAXON
4550         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4551         SAVE  /HIPARNT/
4552         COMMON/WOOD/R,D,FNORM,W
4553         SAVE  /WOOD/
4554         DIMENSION IAA(20),RR(20),DD(20),WW(20),RMS(20)
4555         EXTERNAL RWDSAX,WDSAX
4556 C
4557 C   PARAMETERS OF SPECIAL NUCLEI FROM ATOMIC DATA AND NUC DATA TABLES
4558 C     VOL 14, 5-6 1974
4559         DATA IAA/2,4,12,16,27,32,40,56,63,93,184,197,208,7*0./
4560         DATA RR/0.01,.964,2.355,2.608,2.84,3.458,3.766,3.971,4.214,
4561      1        4.87,6.51,6.38,6.624,7*0./
4562         DATA DD/0.5882,.322,.522,.513,.569,.61,.586,.5935,.586,.573,
4563      1        .535,.535,.549,7*0./
4564         DATA WW/0.0,.517,-0.149,-0.051,0.,-0.208,-0.161,13*0./
4565         DATA RMS/2.11,1.71,2.46,2.73,3.05,3.247,3.482,3.737,3.925,4.31,
4566      1        5.42,5.33,5.521,7*0./
4567       
4568         SAVE IAA, RR, DD, WW, RMS
4569 C
4570         A=IA
4571 C
4572 C               ********SET WOOD-SAX PARAMS FIRST  AS IN DATE ET AL
4573         D=0.54
4574 C                       ********D IS WOOD SAX DIFFUSE PARAM IN FM
4575         R=1.19*A**(1./3.) - 1.61*A**(-1./3.)
4576 C                       ********R IS RADIUS PARAM
4577         W=0.
4578 C               ********W IS The third of three WOOD-SAX PARAM
4579 C
4580 C               ********CHECK TABLE FOR SPECIAL CASES
4581         DO 10 I=1,13
4582                 IF (IA.EQ.IAA(I)) THEN
4583                         R=RR(I)
4584                         D=DD(I)
4585                         W=WW(I)
4586                         RS=RMS(I)
4587                 END IF
4588 10      CONTINUE
4589 C                       ********FNORM is the normalize factor
4590         FNORM=1.0
4591         XLOW=0.
4592         XHIGH=R+ 12.*D
4593         IF (W.LT.-0.01)  THEN
4594                 IF (XHIGH.GT.R/SQRT(ABS(W))) XHIGH=R/SQRT(ABS(W))
4595         END IF
4596         FGAUS=GAUSS1(RWDSAX,XLOW,XHIGH,0.001)
4597         FNORM=1./FGAUS
4598 C
4599         IF (IDH.EQ.1) THEN
4600            HINT1(72)=R
4601            HINT1(73)=D
4602            HINT1(74)=W
4603            HINT1(75)=FNORM/4.0/HIPR1(40)
4604         ELSE IF (IDH.EQ.2) THEN
4605            HINT1(76)=R
4606            HINT1(77)=D
4607            HINT1(78)=W
4608            HINT1(79)=FNORM/4.0/HIPR1(40)
4609         ENDIF
4610 C
4611 C       NOW SET UP HBOOK FUNCTIONS IDH FOR  R**2*RHO(R)
4612 C       THESE HISTOGRAMS ARE USED TO GENERATE RANDOM RADII
4613         CALL HIFUN(IDH,XLOW,XHIGH,RWDSAX)
4614         RETURN
4615         END
4616 C
4617 C
4618         FUNCTION WDSAX(X)
4619 C                       ********THREE PARAMETER WOOD SAXON
4620         COMMON/WOOD/R,D,FNORM,W
4621         SAVE  /WOOD/
4622         WDSAX=FNORM*(1.+W*(X/R)**2)/(1+EXP((X-R)/D))
4623         IF (W.LT.0.) THEN
4624                 IF (X.GE.R/SQRT(ABS(W))) WDSAX=0.
4625         ENDIF
4626         RETURN
4627         END
4628 C
4629 C
4630         FUNCTION RWDSAX(X)
4631         RWDSAX=X*X*WDSAX(X)
4632         RETURN
4633         END
4634 C
4635 C
4636 C
4637 C
4638         FUNCTION WDSAX1(X)
4639 C                       ********THREE PARAMETER WOOD SAXON 
4640 C                               FOR  PROJECTILE
4641 C       HINT1(72)=R, HINT1(73)=D, HINT1(74)=W, HINT1(75)=FNORM
4642 C
4643         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4644         SAVE  /HIPARNT/
4645         WDSAX1=HINT1(75)*(1.+HINT1(74)*(X/HINT1(72))**2)/
4646      &       (1+EXP((X-HINT1(72))/HINT1(73)))
4647         IF (HINT1(74).LT.0.) THEN
4648                 IF (X.GE.HINT1(72)/SQRT(ABS(HINT1(74)))) WDSAX1=0.
4649         ENDIF
4650         RETURN
4651         END
4652 C
4653 C
4654         FUNCTION WDSAX2(X)
4655 C                       ********THREE PARAMETER WOOD SAXON 
4656 C                               FOR  TARGET
4657 C       HINT1(76)=R,HINT1(77)=D, HINT1(78)=W, HINT1(79)=FNORM
4658 C
4659         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4660         SAVE  /HIPARNT/
4661         WDSAX2=HINT1(79)*(1.+HINT1(78)*(X/HINT1(76))**2)/
4662      &       (1+EXP((X-HINT1(76))/HINT1(77)))
4663         IF (HINT1(78).LT.0.) THEN
4664                 IF (X.GE.HINT1(76)/SQRT(ABS(HINT1(78)))) WDSAX2=0.
4665         ENDIF
4666         RETURN
4667         END
4668 C
4669 C
4670 C       THIS FUNCTION IS TO CALCULATE THE NUCLEAR PROFILE FUNCTION
4671 C       OF THE  COLLIDERING SYSTEM (IN UNITS OF 1/mb)
4672 C
4673         FUNCTION  PROFILE(XB)
4674         COMMON/PACT/BB,B1,PHI,Z1
4675         SAVE  /PACT/
4676         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4677         SAVE  /HIPARNT/
4678         EXTERNAL FLAP, FLAP1, FLAP2
4679 C
4680         BB=XB
4681         PROFILE=1.0
4682         IF(IHNT2(1).GT.1 .AND. IHNT2(3).GT.1) THEN
4683            PROFILE=float(IHNT2(1))*float(IHNT2(3))*0.1*
4684      &          GAUSS1(FLAP,0.0,HIPR1(34),0.01)
4685         ELSE IF(IHNT2(1).EQ.1 .AND. IHNT2(3).GT.1) THEN
4686            PROFILE=0.2*float(IHNT2(3))*
4687      &          GAUSS1(FLAP2,0.0,HIPR1(35),0.001)
4688         ELSE IF(IHNT2(1).GT.1 .AND. IHNT2(3).EQ.1) THEN
4689            PROFILE=0.2*float(IHNT2(1))*
4690      &          GAUSS1(FLAP1,0.0,HIPR1(34),0.001)
4691         ENDIF
4692         RETURN
4693         END
4694 C
4695 C
4696         FUNCTION FLAP(X)
4697         COMMON/PACT/BB,B1,PHI,Z1
4698         SAVE  /PACT/
4699         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4700         SAVE  /HIPARNT/
4701         EXTERNAL FGP1
4702         B1=X
4703         FLAP=GAUSS2(FGP1,0.0,2.0*HIPR1(40),0.01)
4704         RETURN
4705         END
4706 C
4707         FUNCTION FGP1(X)
4708         COMMON/PACT/BB,B1,PHI,Z1
4709         SAVE  /PACT/
4710         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4711         SAVE  /HIPARNT/
4712         EXTERNAL FGP2
4713         PHI=X
4714         FGP1=2.0*GAUSS3(FGP2,0.0,HIPR1(34),0.01)
4715         RETURN
4716         END
4717 C
4718         FUNCTION FGP2(X)
4719         COMMON/PACT/BB,B1,PHI,Z1
4720         SAVE  /PACT/
4721         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4722         SAVE  /HIPARNT/
4723         EXTERNAL FGP3
4724         Z1=X
4725         FGP2=2.0*GAUSS4(FGP3,0.0,HIPR1(35),0.01)
4726         RETURN
4727         END
4728 C
4729         FUNCTION FGP3(X)
4730         COMMON/PACT/BB,B1,PHI,Z1
4731         SAVE  /PACT/
4732         R1=SQRT(B1**2+Z1**2)
4733         R2=SQRT(BB**2+B1**2-2.0*B1*BB*COS(PHI)+X**2)
4734         FGP3=B1*WDSAX1(R1)*WDSAX2(R2)
4735         RETURN
4736         END
4737 C
4738 C
4739         FUNCTION FLAP1(X)
4740         COMMON/PACT/BB,B1,PHI,Z1
4741         SAVE  /PACT/
4742         R=SQRT(BB**2+X**2)
4743         FLAP1=WDSAX1(R)
4744         RETURN
4745         END
4746 C
4747 C
4748         FUNCTION FLAP2(X)
4749         COMMON/PACT/BB,B1,PHI,Z1
4750         SAVE  /PACT/
4751         R=SQRT(BB**2+X**2)
4752         FLAP2=WDSAX2(R)
4753         RETURN
4754         END
4755 C
4756 C
4757 C The next three subroutines are for Monte Carlo generation 
4758 C according to a given function FHB. One calls first HIFUN 
4759 C with assigned channel number I, low and up limits. Then to 
4760 C generate the distribution one can call HIRND(I) which gives 
4761 C you a random number generated according to the given function.
4762 C 
4763         SUBROUTINE HIFUN(I,XMIN,XMAX,FHB)
4764         COMMON/HIJHB/RR(10,201),XX(10,201)
4765         SAVE  /HIJHB/
4766         EXTERNAL FHB
4767         FNORM=GAUSS1(FHB,XMIN,XMAX,0.001)
4768         DO 100 J=1,201
4769                 XX(I,J)=XMIN+(XMAX-XMIN)*(J-1)/200.0
4770                 XDD=XX(I,J)
4771                 RR(I,J)=GAUSS1(FHB,XMIN,XDD,0.001)/FNORM
4772 100     CONTINUE
4773         RETURN
4774         END
4775 C
4776 C
4777 C
4778         FUNCTION HIRND(I)
4779         COMMON/HIJHB/RR(10,201),XX(10,201)
4780         SAVE  /HIJHB/
4781         COMMON/RANSEED/NSEED
4782         SAVE  /RANSEED/
4783         RX=RLU(0)
4784         JL=0
4785         JU=202
4786 10      IF(JU-JL.GT.1) THEN
4787            JM=(JU+JL)/2
4788            IF((RR(I,201).GT.RR(I,1)).EQV.(RX.GT.RR(I,JM))) THEN
4789               JL=JM
4790            ELSE
4791               JU=JM
4792            ENDIF
4793         GO TO 10
4794         ENDIF
4795         J=JL
4796         IF(J.LT.1) J=1
4797         IF(J.GE.201) J=200
4798         HIRND=(XX(I,J)+XX(I,J+1))/2.0
4799         RETURN
4800         END     
4801 C
4802 C
4803 C
4804 C
4805 C       This generate random number between XMIN and XMAX
4806         FUNCTION HIRND2(I,XMIN,XMAX)
4807         COMMON/HIJHB/RR(10,201),XX(10,201)
4808         SAVE  /HIJHB/
4809         COMMON/RANSEED/NSEED
4810         SAVE  /RANSEED/
4811         IF(XMIN.LT.XX(I,1)) XMIN=XX(I,1)
4812         IF(XMAX.GT.XX(I,201)) XMAX=XX(I,201)
4813         JMIN=1+200*(XMIN-XX(I,1))/(XX(I,201)-XX(I,1))
4814         JMAX=1+200*(XMAX-XX(I,1))/(XX(I,201)-XX(I,1))
4815         RX=RR(I,JMIN)+(RR(I,JMAX)-RR(I,JMIN))*RLU(0)
4816         JL=0
4817         JU=202
4818 10      IF(JU-JL.GT.1) THEN
4819            JM=(JU+JL)/2
4820            IF((RR(I,201).GT.RR(I,1)).EQV.(RX.GT.RR(I,JM))) THEN
4821               JL=JM
4822            ELSE
4823               JU=JM
4824            ENDIF
4825         GO TO 10
4826         ENDIF
4827         J=JL
4828         IF(J.LT.1) J=1
4829         IF(J.GE.201) J=200
4830         HIRND2=(XX(I,J)+XX(I,J+1))/2.0
4831         RETURN
4832         END     
4833 C
4834 C
4835 C
4836 C
4837         SUBROUTINE HIJCRS
4838 C       THIS IS TO CALCULATE THE CROSS SECTIONS OF JET PRODUCTION AND
4839 C       THE TOTAL INELASTIC CROSS SECTIONS.
4840         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4841         SAVE  /HIPARNT/
4842         COMMON/NJET/N,IP_CRS
4843         SAVE  /NJET/
4844         EXTERNAL FHIN,FTOT,FNJET,FTOTJET,FTOTRIG
4845         IF(HINT1(1).GE.10.0) CALL CRSJET
4846 C                       ********calculate jet cross section(in mb)
4847 C
4848         APHX1=HIPR1(6)*(IHNT2(1)**0.3333333-1.0)
4849         APHX2=HIPR1(6)*(IHNT2(3)**0.3333333-1.0)
4850         HINT1(11)=HINT1(14)-APHX1*HINT1(15)
4851      &                  -APHX2*HINT1(16)+APHX1*APHX2*HINT1(17)
4852         HINT1(10)=GAUSS1(FTOTJET,0.0,20.0,0.01)
4853         HINT1(12)=GAUSS1(FHIN,0.0,20.0,0.01)
4854         HINT1(13)=GAUSS1(FTOT,0.0,20.0,0.01)
4855         HINT1(60)=HINT1(61)-APHX1*HINT1(62)
4856      &                  -APHX2*HINT1(63)+APHX1*APHX2*HINT1(64)
4857         HINT1(59)=GAUSS1(FTOTRIG,0.0,20.0,0.01)
4858         IF(HINT1(59).EQ.0.0) HINT1(59)=HINT1(60)
4859         IF(HINT1(1).GE.10.0) Then
4860            DO 20 I=0,20
4861               N=I
4862               HINT1(80+I)=GAUSS1(FNJET,0.0,20.0,0.01)/HINT1(12)
4863  20        CONTINUE
4864         ENDIF
4865         HINT1(10)=HINT1(10)*HIPR1(31)
4866         HINT1(12)=HINT1(12)*HIPR1(31)
4867         HINT1(13)=HINT1(13)*HIPR1(31)
4868         HINT1(59)=HINT1(59)*HIPR1(31)
4869 C               ********Total and Inel cross section are calculated
4870 C                       by Gaussian integration.
4871         IF(IHPR2(13).NE.0) THEN
4872         HIPR1(33)=1.36*(1.0+36.0/HINT1(1)**2)
4873      &             *ALOG(0.6+0.1*HINT1(1)**2)
4874         HIPR1(33)=HIPR1(33)/HINT1(12)
4875         ENDIF
4876 C               ********Parametrized cross section for single
4877 C                       diffractive reaction(Goulianos)
4878         RETURN
4879         END
4880 C
4881 C
4882 C
4883 C
4884         FUNCTION FTOT(X)
4885         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4886         SAVE  /HIPARNT/
4887         OMG=OMG0(X)*(HIPR1(30)+HINT1(11))/HIPR1(31)/2.0
4888         FTOT=2.0*(1.0-EXP(-OMG))
4889         RETURN
4890         END
4891 C
4892 C
4893 C
4894         FUNCTION FHIN(X)
4895         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4896         SAVE  /HIPARNT/
4897         OMG=OMG0(X)*(HIPR1(30)+HINT1(11))/HIPR1(31)/2.0
4898         FHIN=1.0-EXP(-2.0*OMG)
4899         RETURN
4900         END
4901 C
4902 C
4903 C
4904         FUNCTION FTOTJET(X)
4905         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4906         SAVE  /HIPARNT/
4907         OMG=OMG0(X)*HINT1(11)/HIPR1(31)/2.0
4908         FTOTJET=1.0-EXP(-2.0*OMG)
4909         RETURN
4910         END
4911 C
4912 C
4913 C
4914         FUNCTION FTOTRIG(X)
4915         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4916         SAVE  /HIPARNT/
4917         OMG=OMG0(X)*HINT1(60)/HIPR1(31)/2.0
4918         FTOTRIG=1.0-EXP(-2.0*OMG)
4919         RETURN
4920         END
4921 C
4922 C
4923 C
4924 C
4925         FUNCTION FNJET(X)
4926         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4927         SAVE  /HIPARNT/
4928         COMMON/NJET/N,IP_CRS
4929         SAVE  /NJET/
4930         OMG1=OMG0(X)*HINT1(11)/HIPR1(31)
4931         C0=EXP(N*ALOG(OMG1)-SGMIN(N+1))
4932         IF(N.EQ.0) C0=1.0-EXP(-2.0*OMG0(X)*HIPR1(30)/HIPR1(31)/2.0)
4933         FNJET=C0*EXP(-OMG1)
4934         RETURN
4935         END
4936 C
4937 C
4938 C
4939 C
4940 C
4941         FUNCTION SGMIN(N)
4942         GA=0.
4943         IF(N.LE.2) GO TO 20
4944         DO 10 I=1,N-1
4945         Z=I
4946         GA=GA+ALOG(Z)
4947 10      CONTINUE
4948 20      SGMIN=GA
4949         RETURN
4950         END
4951 C
4952 C
4953 C
4954         FUNCTION OMG0(X)
4955         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
4956         SAVE  /HIPARNT/
4957         COMMON /BESEL/X4
4958         SAVE   /BESEL/
4959         EXTERNAL BK
4960         X4=HIPR1(32)*SQRT(X)
4961         OMG0=HIPR1(32)**2*GAUSS2(BK,X4,X4+20.0,0.01)/96.0
4962 c        write(*,*)'OMG0 start',x,x4,OMG0
4963         RETURN
4964         END
4965 C
4966 C
4967 C
4968         FUNCTION ROMG(X)
4969 C               ********This gives the eikonal function from a table
4970 C                       calculated in the first call
4971         DIMENSION FR(0:1000)
4972 c       --------------Khaled
4973 c       we need to save FR because it is calculated only once
4974         COMMON/EIKONAL/FR             
4975 c       --------------->end Khaled
4976 
4977         DATA I0/0/
4978         save I0    !Uzhi
4979         IF(I0.NE.0) GO TO 100
4980         DO 50 I=1,1001
4981         XR=(I-1)*0.01
4982         FR(I-1)=OMG0(XR)
4983     
4984 50      CONTINUE
4985 100     I0=1                             
4986 
4987         IF(X.GE.10.0) THEN
4988                 ROMG=0.0
4989                 RETURN
4990         ENDIF
4991         IX=INT(X*100)
4992 
4993         ROMG=(FR(IX)*((IX+1)*0.01-X)+FR(IX+1)*(X-IX*0.01))/0.01
4994 
4995         RETURN
4996         END
4997 C
4998 C
4999 C
5000 
5001         FUNCTION BK(X)
5002         COMMON /BESEL/X4
5003         SAVE   /BESEL/
5004         BK=EXP(-X)*(X**2-X4**2)**2.50/15.0
5005         RETURN
5006         END
5007 C
5008 C
5009 C       THIS PROGRAM IS TO CALCULATE THE JET CROSS SECTION
5010 C       THE INTEGRATION IS DONE BY USING VEGAS
5011 C
5012         SUBROUTINE CRSJET
5013         IMPLICIT REAL*8(A-H,O-Z)
5014         REAL HIPR1(100),HINT1(100)
5015         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5016         SAVE  /HIPARNT/
5017         COMMON/NJET/N,IP_CRS
5018         SAVE  /NJET/
5019         COMMON/BVEG1/XL(10),XU(10),ACC,NDIM,NCALL,ITMX,NPRN
5020         SAVE  /BVEG1/
5021         COMMON/BVEG2/XI(50,10),SI,SI2,SWGT,SCHI,NDO,IT
5022         SAVE  /BVEG2/
5023         COMMON/BVEG3/F,TI,TSI
5024         SAVE  /BVEG3/
5025         COMMON/SEEDVAX/NUM1
5026         SAVE  /SEEDVAX/
5027         EXTERNAL FJET,FJETRIG
5028 C
5029 c************************
5030 c       NCALL give the number of inner-iteration, ITMX 
5031 C       gives the limit of out-iteration. Nprn is an option
5032 C       ( 1: print the integration process. 0: do not print)
5033 C
5034         NDIM=3
5035         IP_CRS=0
5036         CALL VEGAS(FJET,AVGI,SD,CHI2A)
5037         HINT1(14)=AVGI/2.5682
5038         IF(IHPR2(6).EQ.1 .AND. IHNT2(1).GT.1) THEN
5039                 IP_CRS=1
5040                 CALL VEGAS(FJET,AVGI,SD,CHI2A)
5041                 HINT1(15)=AVGI/2.5682
5042         ENDIF
5043         IF(IHPR2(6).EQ.1 .AND. IHNT2(3).GT.1) THEN
5044                 IP_CRS=2
5045                 CALL VEGAS(FJET,AVGI,SD,CHI2A)
5046                 HINT1(16)=AVGI/2.5682
5047         ENDIF
5048         IF(IHPR2(6).EQ.1.AND.IHNT2(1).GT.1.AND.IHNT2(3).GT.1) THEN
5049                 IP_CRS=3
5050                 CALL VEGAS(FJET,AVGI,SD,CHI2A)
5051                 HINT1(17)=AVGI/2.5682
5052         ENDIF
5053 C               ********Total inclusive jet cross section(Pt>P0) 
5054 C
5055         IF(IHPR2(3).NE.0) THEN
5056            IP_CRS=0
5057            CALL VEGAS(FJETRIG,AVGI,SD,CHI2A)
5058            HINT1(61)=AVGI/2.5682
5059            IF(IHPR2(6).EQ.1 .AND. IHNT2(1).GT.1) THEN
5060               IP_CRS=1
5061               CALL VEGAS(FJETRIG,AVGI,SD,CHI2A)
5062               HINT1(62)=AVGI/2.5682
5063            ENDIF
5064            IF(IHPR2(6).EQ.1 .AND. IHNT2(3).GT.1) THEN
5065               IP_CRS=2
5066               CALL VEGAS(FJETRIG,AVGI,SD,CHI2A)
5067               HINT1(63)=AVGI/2.5682
5068            ENDIF
5069            IF(IHPR2(6).EQ.1.AND.IHNT2(1).GT.1.AND.IHNT2(3).GT.1) THEN
5070               IP_CRS=3
5071               CALL VEGAS(FJETRIG,AVGI,SD,CHI2A)
5072               HINT1(64)=AVGI/2.5682
5073            ENDIF
5074         ENDIF
5075 C                       ********cross section of trigger jet
5076 C
5077         RETURN
5078         END
5079 C
5080 C
5081 C
5082         FUNCTION FJET(X,WGT)
5083         IMPLICIT REAL*8(A-H,O-Z)
5084         REAL HIPR1(100),HINT1(100)
5085         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5086         SAVE  /HIPARNT/
5087         DIMENSION X(10)
5088         PT2=(HINT1(1)**2/4.0-HIPR1(8)**2)*X(1)+HIPR1(8)**2
5089         XT=2.0*DSQRT(PT2)/HINT1(1)
5090         YMX1=DLOG(1.0/XT+DSQRT(1.0/XT**2-1.0))
5091         Y1=2.0*YMX1*X(2)-YMX1
5092         YMX2=DLOG(2.0/XT-DEXP(Y1))
5093         YMN2=DLOG(2.0/XT-DEXP(-Y1))
5094         Y2=(YMX2+YMN2)*X(3)-YMN2
5095         FJET=2.0*YMX1*(YMX2+YMN2)*(HINT1(1)**2/4.0-HIPR1(8)**2)
5096      &          *G(Y1,Y2,PT2)/2.0
5097         RETURN
5098         END
5099 C
5100 C
5101 C
5102         FUNCTION FJETRIG(X,WGT)
5103         IMPLICIT REAL*8(A-H,O-Z)
5104         REAL HIPR1(100),HINT1(100),PTMAX,PTMIN
5105         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5106         SAVE  /HIPARNT/
5107         DIMENSION X(10)
5108         PTMIN=ABS(HIPR1(10))-0.25
5109         PTMIN=MAX(PTMIN,HIPR1(8))
5110         AM2=0.D0
5111         IF(IHPR2(3).EQ.3) THEN
5112            AM2=HIPR1(7)**2
5113            PTMIN=MAX(0.0,HIPR1(10))
5114         ENDIF
5115         PTMAX=ABS(HIPR1(10))+0.25
5116         IF(HIPR1(10).LE.0.0) PTMAX=HINT1(1)/2.0-AM2
5117         IF(PTMAX.LE.PTMIN) PTMAX=PTMIN+0.25
5118         PT2=(PTMAX**2-PTMIN**2)*X(1)+PTMIN**2
5119         AMT2=PT2+AM2
5120         XT=2.0*DSQRT(AMT2)/HINT1(1)
5121         YMX1=DLOG(1.0/XT+DSQRT(1.0/XT**2-1.0))
5122         Y1=2.0*YMX1*X(2)-YMX1
5123         YMX2=DLOG(2.0/XT-DEXP(Y1))
5124         YMN2=DLOG(2.0/XT-DEXP(-Y1))
5125         Y2=(YMX2+YMN2)*X(3)-YMN2
5126         IF(IHPR2(3).EQ.3) THEN
5127            GTRIG=2.0*GHVQ(Y1,Y2,AMT2)
5128         ELSE IF(IHPR2(3).EQ.2) THEN
5129            GTRIG=2.0*GPHOTON(Y1,Y2,PT2)
5130         ELSE
5131            GTRIG=G(Y1,Y2,PT2)
5132         ENDIF
5133         FJETRIG=2.0*YMX1*(YMX2+YMN2)*(PTMAX**2-PTMIN**2)
5134      &          *GTRIG/2.0
5135         RETURN
5136         END
5137 C
5138 C
5139 C
5140         FUNCTION GHVQ(Y1,Y2,AMT2)
5141         IMPLICIT REAL*8 (A-H,O-Z)
5142         REAL HIPR1(100),HINT1(100)
5143         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5144         SAVE  /HIPARNT/
5145         DIMENSION F(2,7)
5146         XT=2.0*DSQRT(AMT2)/HINT1(1)
5147         X1=0.50*XT*(DEXP(Y1)+DEXP(Y2))
5148         X2=0.50*XT*(DEXP(-Y1)+DEXP(-Y2))
5149         SS=X1*X2*HINT1(1)**2
5150         AF=4.0
5151         IF(IHPR2(18).NE.0) AF=5.0
5152         DLAM=HIPR1(15)
5153         APH=12.0*3.1415926/(33.0-2.0*AF)/DLOG(AMT2/DLAM**2)
5154 C
5155         CALL PARTON(F,X1,X2,AMT2)
5156 C
5157         Gqq=4.0*(COSH(Y1-Y2)+HIPR1(7)**2/AMT2)/(1.D0+COSH(Y1-Y2))/9.0
5158      &      *(F(1,1)*F(2,2)+F(1,2)*F(2,1)+F(1,3)*F(2,4)
5159      &        +F(1,4)*F(2,3)+F(1,5)*F(2,6)+F(1,6)*F(2,5))
5160         Ggg=(8.D0*COSH(Y1-Y2)-1.D0)*(COSH(Y1-Y2)+2.0*HIPR1(7)**2/AMT2
5161      &      -2.0*HIPR1(7)**4/AMT2**2)/(1.0+COSH(Y1-Y2))/24.D0
5162      &      *F(1,7)*F(2,7)
5163 C
5164         GHVQ=(Gqq+Ggg)*HIPR1(23)*3.14159*APH**2/SS**2
5165         RETURN
5166         END
5167 C
5168 C
5169 C
5170         FUNCTION GPHOTON(Y1,Y2,PT2)
5171         IMPLICIT REAL*8 (A-H,O-Z)
5172         REAL HIPR1(100),HINT1(100)
5173         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5174         SAVE  /HIPARNT/
5175         DIMENSION F(2,7)
5176         XT=2.0*DSQRT(PT2)/HINT1(1)
5177         X1=0.50*XT*(DEXP(Y1)+DEXP(Y2))
5178         X2=0.50*XT*(DEXP(-Y1)+DEXP(-Y2))
5179         Z=DSQRT(1.D0-XT**2/X1/X2)
5180         SS=X1*X2*HINT1(1)**2
5181         T=-(1.0-Z)/2.0
5182         U=-(1.0+Z)/2.0
5183         AF=3.0
5184         DLAM=HIPR1(15)
5185         APH=12.0*3.1415926/(33.0-2.0*AF)/DLOG(PT2/DLAM**2)
5186         APHEM=1.0/137.0
5187 C
5188         CALL PARTON(F,X1,X2,PT2)
5189 C
5190         G11=-(U**2+1.0)/U/3.0*F(1,7)*(4.0*F(2,1)+4.0*F(2,2)
5191      &      +F(2,3)+F(2,4)+F(2,5)+F(2,6))/9.0
5192         G12=-(T**2+1.0)/T/3.0*F(2,7)*(4.0*F(1,1)+4.0*F(1,2)
5193      &      +F(1,3)+F(1,4)+F(1,5)+F(1,6))/9.0
5194         G2=8.0*(U**2+T**2)/U/T/9.0*(4.0*F(1,1)*F(2,2)
5195      &     +4.0*F(1,2)*F(2,1)+F(1,3)*F(2,4)+F(1,4)*F(2,3)
5196      &     +F(1,5)*F(2,6)+F(1,6)*F(2,5))/9.0
5197 C
5198         GPHOTON=(G11+G12+G2)*HIPR1(23)*3.14159*APH*APHEM/SS**2
5199         RETURN
5200         END
5201 C
5202 C
5203 C
5204 C
5205         FUNCTION G(Y1,Y2,PT2)
5206         IMPLICIT REAL*8 (A-H,O-Z)
5207         REAL HIPR1(100),HINT1(100)
5208         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5209         SAVE  /HIPARNT/
5210         DIMENSION F(2,7)
5211         XT=2.0*DSQRT(PT2)/HINT1(1)
5212         X1=0.50*XT*(DEXP(Y1)+DEXP(Y2))
5213         X2=0.50*XT*(DEXP(-Y1)+DEXP(-Y2))
5214         Z=DSQRT(1.D0-XT**2/X1/X2)
5215         SS=X1*X2*HINT1(1)**2
5216         T=-(1.0-Z)/2.0
5217         U=-(1.0+Z)/2.0
5218         AF=3.0
5219         DLAM=HIPR1(15)
5220         APH=12.0*3.1415926/(33.0-2.0*AF)/DLOG(PT2/DLAM**2)
5221 C
5222         CALL PARTON(F,X1,X2,PT2)
5223 C
5224         G11=( (F(1,1)+F(1,2))*(F(2,3)+F(2,4)+F(2,5)+F(2,6))
5225      &      +(F(1,3)+F(1,4))*(F(2,5)+F(2,6)) )*SUBCRS1(T,U)
5226 C
5227         G12=( (F(2,1)+F(2,2))*(F(1,3)+F(1,4)+F(1,5)+F(1,6))
5228      &      +(F(2,3)+F(2,4))*(F(1,5)+F(1,6)) )*SUBCRS1(U,T)
5229 C
5230         G13=(F(1,1)*F(2,1)+F(1,2)*F(2,2)+F(1,3)*F(2,3)+F(1,4)*F(2,4)
5231      &      +F(1,5)*F(2,5)+F(1,6)*F(2,6))*(SUBCRS1(U,T)
5232      &      +SUBCRS1(T,U)-8.D0/T/U/27.D0)
5233 C
5234         G2=(AF-1)*(F(1,1)*F(2,2)+F(2,1)*F(1,2)+F(1,3)*F(2,4)
5235      &     +F(2,3)*F(1,4)+F(1,5)*F(2,6)+F(2,5)*F(1,6))*SUBCRS2(T,U)
5236 C
5237         G31=(F(1,1)*F(2,2)+F(1,3)*F(2,4)+F(1,5)*F(2,6))*SUBCRS3(T,U)
5238         G32=(F(2,1)*F(1,2)+F(2,3)*F(1,4)+F(2,5)*F(1,6))*SUBCRS3(U,T)
5239 C
5240         G4=(F(1,1)*F(2,2)+F(2,1)*F(1,2)+F(1,3)*F(2,4)+F(2,3)*F(1,4)+
5241      1  F(1,5)*F(2,6)+F(2,5)*F(1,6))*SUBCRS4(T,U)
5242 C
5243         G5=AF*F(1,7)*F(2,7)*SUBCRS5(T,U)
5244 C
5245         G61=F(1,7)*(F(2,1)+F(2,2)+F(2,3)+F(2,4)+F(2,5)
5246      &      +F(2,6))*SUBCRS6(T,U)
5247         G62=F(2,7)*(F(1,1)+F(1,2)+F(1,3)+F(1,4)+F(1,5)
5248      &      +F(1,6))*SUBCRS6(U,T)
5249 C
5250         G7=F(1,7)*F(2,7)*SUBCRS7(T,U)
5251 C
5252         G=(G11+G12+G13+G2+G31+G32+G4+G5+G61+G62+G7)*HIPR1(17)*
5253      1  3.14159D0*APH**2/SS**2
5254         RETURN
5255         END
5256 C
5257 C
5258 C
5259         FUNCTION SUBCRS1(T,U)
5260         IMPLICIT REAL*8(A-H,O-Z)
5261         SUBCRS1=4.D0/9.D0*(1.D0+U**2)/T**2
5262         RETURN
5263         END
5264 C
5265 C
5266         FUNCTION SUBCRS2(T,U)
5267         IMPLICIT REAL*8(A-H,O-Z)
5268         SUBCRS2=4.D0/9.D0*(T**2+U**2)
5269         RETURN
5270         END
5271 C
5272 C
5273         FUNCTION SUBCRS3(T,U)
5274         IMPLICIT REAL*8(A-H,O-Z)
5275         SUBCRS3=4.D0/9.D0*(T**2+U**2+(1.D0+U**2)/T**2
5276      1  -2.D0*U**2/3.D0/T)
5277         RETURN
5278         END
5279 C
5280 C
5281         FUNCTION SUBCRS4(T,U)
5282         IMPLICIT REAL*8(A-H,O-Z)
5283         SUBCRS4=8.D0/3.D0*(T**2+U**2)*(4.D0/9.D0/T/U-1.D0)
5284         RETURN
5285         END
5286 C
5287 C
5288 C
5289         FUNCTION SUBCRS5(T,U)
5290         IMPLICIT REAL*8(A-H,O-Z)
5291         SUBCRS5=3.D0/8.D0*(T**2+U**2)*(4.D0/9.D0/T/U-1.D0)
5292         RETURN
5293         END
5294 C
5295 C
5296         FUNCTION SUBCRS6(T,U)
5297         IMPLICIT REAL*8(A-H,O-Z)
5298         SUBCRS6=(1.D0+U**2)*(1.D0/T**2-4.D0/U/9.D0)
5299         RETURN
5300         END
5301 C
5302 C
5303         FUNCTION SUBCRS7(T,U)
5304         IMPLICIT REAL*8(A-H,O-Z)
5305         SUBCRS7=9.D0/2.D0*(3.D0-T*U-U/T**2-T/U**2)
5306         RETURN
5307         END
5308 C
5309 C
5310 C
5311         SUBROUTINE PARTON(F,X1,X2,QQ)
5312         IMPLICIT REAL*8(A-H,O-Z)
5313         REAL HIPR1(100),HINT1(100)
5314         COMMON/HIPARNT/HIPR1,IHPR2(50),HINT1,IHNT2(50)
5315         SAVE  /HIPARNT/
5316         COMMON/NJET/N,IP_CRS
5317         SAVE  /NJET/
5318         DIMENSION F(2,7) 
5319         DLAM=HIPR1(15)
5320         Q0=HIPR1(16)
5321         S=DLOG(DLOG(QQ/DLAM**2)/DLOG(Q0**2/DLAM**2))
5322         IF(IHPR2(7).EQ.2) GO TO 200
5323 C*******************************************************
5324         AT1=0.419+0.004*S-0.007*S**2
5325         AT2=3.460+0.724*S-0.066*S**2
5326         GMUD=4.40-4.86*S+1.33*S**2
5327         AT3=0.763-0.237*S+0.026*S**2
5328         AT4=4.00+0.627*S-0.019*S**2
5329         GMD=-0.421*S+0.033*S**2
5330 C*******************************************************
5331         CAS=1.265-1.132*S+0.293*S**2
5332         AS=-0.372*S-0.029*S**2
5333         BS=8.05+1.59*S-0.153*S**2
5334         APHS=6.31*S-0.273*S**2
5335         BTAS=-10.5*S-3.17*S**2
5336         GMS=14.7*S+9.80*S**2
5337 C********************************************************
5338 C       CAC=0.135*S-0.075*S**2
5339 C       AC=-0.036-0.222*S-0.058*S**2
5340 C       BC=6.35+3.26*S-0.909*S**2
5341 C       APHC=-3.03*S+1.50*S**2
5342 C       BTAC=17.4*S-11.3*S**2
5343 C       GMC=-17.9*S+15.6*S**2
5344 C***********************************************************
5345         CAG=1.56-1.71*S+0.638*S**2
5346         AG=-0.949*S+0.325*S**2
5347         BG=6.0+1.44*S-1.05*S**2
5348         APHG=9.0-7.19*S+0.255*S**2
5349         BTAG=-16.5*S+10.9*S**2
5350         GMG=15.3*S-10.1*S**2
5351         GO TO 300
5352 C********************************************************
5353 200     AT1=0.374+0.014*S
5354         AT2=3.33+0.753*S-0.076*S**2
5355         GMUD=6.03-6.22*S+1.56*S**2
5356         AT3=0.761-0.232*S+0.023*S**2
5357         AT4=3.83+0.627*S-0.019*S**2
5358         GMD=-0.418*S+0.036*S**2
5359 C************************************
5360         CAS=1.67-1.92*S+0.582*S**2
5361         AS=-0.273*S-0.164*S**2
5362         BS=9.15+0.530*S-0.763*S**2
5363         APHS=15.7*S-2.83*S**2
5364         BTAS=-101.0*S+44.7*S**2
5365         GMS=223.0*S-117.0*S**2
5366 C*********************************
5367 C       CAC=0.067*S-0.031*S**2
5368 C       AC=-0.120-0.233*S-0.023*S**2
5369 C       BC=3.51+3.66*S-0.453*S**2
5370 C       APHC=-0.474*S+0.358*S**2
5371 C       BTAC=9.50*S-5.43*S**2
5372 C       GMC=-16.6*S+15.5*S**2
5373 C**********************************
5374         CAG=0.879-0.971*S+0.434*S**2
5375         AG=-1.16*S+0.476*S**2
5376         BG=4.0+1.23*S-0.254*S**2
5377         APHG=9.0-5.64*S-0.817*S**2
5378         BTAG=-7.54*S+5.50*S**2
5379         GMG=-0.596*S+1.26*S**2
5380 C*********************************
5381 300     B12=DEXP(GMRE(AT1)+GMRE(AT2+1.D0)-GMRE(AT1+AT2+1.D0))
5382         B34=DEXP(GMRE(AT3)+GMRE(AT4+1.D0)-GMRE(AT3+AT4+1.D0))
5383         CNUD=3.D0/B12/(1.D0+GMUD*AT1/(AT1+AT2+1.D0))
5384         CND=1.D0/B34/(1.D0+GMD*AT3/(AT3+AT4+1.D0))
5385 C********************************************************
5386 C       FUD=X*(U+D)
5387 C       FS=X*2(UBAR+DBAR+SBAR)  AND UBAR=DBAR=SBAR
5388 C*******************************************************
5389         FUD1=CNUD*X1**AT1*(1.D0-X1)**AT2*(1.D0+GMUD*X1)
5390         FS1=CAS*X1**AS*(1.D0-X1)**BS*(1.D0+APHS*X1
5391      &      +BTAS*X1**2+GMS*X1**3)
5392         F(1,3)=CND*X1**AT3*(1.D0-X1)**AT4*(1.D0+GMD*X1)+FS1/6.D0
5393         F(1,1)=FUD1-F(1,3)+FS1/3.D0
5394         F(1,2)=FS1/6.D0
5395         F(1,4)=FS1/6.D0
5396         F(1,5)=FS1/6.D0
5397         F(1,6)=FS1/6.D0
5398         F(1,7)=CAG*X1**AG*(1.D0-X1)**BG*(1.D0+APHG*X1
5399      &         +BTAG*X1**2+GMG*X1**3)
5400 C
5401         FUD2=CNUD*X2**AT1*(1.D0-X2)**AT2*(1.D0+GMUD*X2)
5402         FS2=CAS*X2**AS*(1.D0-X2)**BS*(1.D0+APHS*X2
5403      &      +BTAS*X2**2+GMS*X2**3)
5404         F(2,3)=CND*X2**AT3*(1.D0-X2)**AT4*(1.D0+GMD*X2)+FS2/6.D0
5405         F(2,1)=FUD2-F(2,3)+FS2/3.D0
5406         F(2,2)=FS2/6.D0
5407         F(2,4)=FS2/6.D0
5408         F(2,5)=FS2/6.D0
5409         F(2,6)=FS2/6.D0
5410         F(2,7)=CAG*X2**AG*(1.D0-X2)**BG*(1.D0+APHG*X2
5411      &         +BTAG*X2**2+GMG*X2**3)
5412 C***********Nuclear effect on the structure function****************
5413 C
5414         IF(IHPR2(6).EQ.1 .AND. IHNT2(1).GT.1) THEN
5415            AAX=1.193*ALOG(FLOAT(IHNT2(1)))**0.16666666
5416            RRX=AAX*(X1**3-1.2*X1**2+0.21*X1)+1.0
5417      &         +1.079*(FLOAT(IHNT2(1))**0.33333333-1.0)
5418      &         /DLOG(IHNT2(1)+1.0D0)*DSQRT(X1)*DEXP(-X1**2/0.01)
5419            IF(IP_CRS.EQ.1 .OR.IP_CRS.EQ.3) RRX=DEXP(-X1**2/0.01)
5420            DO 400 I=1,7
5421               F(1,I)=RRX*F(1,I)
5422  400       CONTINUE
5423         ENDIF
5424         IF(IHPR2(6).EQ.1 .AND. IHNT2(3).GT.1) THEN
5425            AAX=1.193*ALOG(FLOAT(IHNT2(3)))**0.16666666
5426            RRX=AAX*(X2**3-1.2*X2**2+0.21*X2)+1.0
5427      &         +1.079*(FLOAT(IHNT2(3))**0.33333-1.0)
5428      &         /DLOG(IHNT2(3)+1.0D0)*DSQRT(X2)*DEXP(-X2**2/0.01)
5429            IF(IP_CRS.EQ.2 .OR. IP_CRS.EQ.3) RRX=DEXP(-X2**2/0.01)
5430            DO 500 I=1,7
5431               F(2,I)=RRX*F(2,I)
5432  500       CONTINUE
5433         ENDIF
5434 c
5435         RETURN
5436         END
5437 C
5438 C
5439 C
5440         FUNCTION GMRE(X)
5441         IMPLICIT REAL*8(A-H,O-Z)
5442         Z=X
5443         IF(X.GT.3.0D0) GO TO 10
5444         Z=X+3.D0
5445 10      GMRE=0.5D0*DLOG(2.D0*3.14159265D0/Z)+Z*DLOG(Z)-Z+DLOG(1.D0
5446      1  +1.D0/12.D0/Z+1.D0/288.D0/Z**2-139.D0/51840.D0/Z**3
5447      1  -571.D0/2488320.D0/Z**4)
5448         IF(Z.EQ.X) GO TO 20
5449         GMRE=GMRE-DLOG(Z-1.D0)-DLOG(Z-2.D0)-DLOG(Z-3.D0)
5450 20      CONTINUE
5451         RETURN
5452         END
5453 c
5454 C
5455 C
5456         FUNCTION GMIN(N)
5457         IMPLICIT REAL*8(A-H,O-Z)
5458         GA=0.
5459         IF(N.LE.2) GO TO 20
5460         DO 10 I=1,N-1
5461         Z=I
5462         GA=GA+DLOG(Z)
5463 10      CONTINUE
5464 20      GMIN=GA
5465         RETURN
5466         END
5467 C
5468 C
5469 C***************************************************************
5470 
5471         BLOCK DATA HIDATA
5472         REAL*8 XL(10),XU(10),ACC
5473         COMMON/BVEG1/XL,XU,ACC,NDIM,NCALL,ITMX,NPRN
5474         SAVE  /BVEG1/
5475         COMMON/SEEDVAX/NUM1
5476         SAVE  /SEEDVAX/
5477         COMMON/HIPARNT/HIPR1(100),IHPR2(50),HINT1(100),IHNT2(50)
5478         SAVE  /HIPARNT/
5479         COMMON/RANSEED/NSEED
5480         SAVE  /RANSEED/
5481         COMMON/HIMAIN1/ NATT,EATT,JATT,NT,NP,N0,N01,N10,N11
5482         SAVE  /HIMAIN1/
5483         COMMON/HIMAIN2/KATT(130000,4),PATT(130000,4)
5484         SAVE  /HIMAIN2/
5485         COMMON/HISTRNG/NFP(300,15),PP(300,15),NFT(300,15),PT(300,15)
5486         SAVE  /HISTRNG/
5487         COMMON/HIJCRDN/YP(3,300),YT(3,300)
5488         SAVE  /HIJCRDN/
5489         COMMON/HIJJET1/NPJ(300),KFPJ(300,500),PJPX(300,500),
5490      &               PJPY(300,500),PJPZ(300,500),PJPE(300,500),
5491      &               PJPM(300,500),NTJ(300),KFTJ(300,500),
5492      &               PJTX(300,500),PJTY(300,500),PJTZ(300,500),
5493      &               PJTE(300,500),PJTM(300,500)
5494         SAVE  /HIJJET1/
5495         COMMON/HIJJET2/NSG,NJSG(900),IASG(900,3),K1SG(900,100),
5496      &          K2SG(900,100),PXSG(900,100),PYSG(900,100),
5497      &          PZSG(900,100),PESG(900,100),PMSG(900,100)
5498         SAVE  /HIJJET2/
5499         COMMON/HIJDAT/HIDAT0(10,10),HIDAT(10)
5500         SAVE  /HIJDAT/
5501         COMMON/HIPYINT/MINT4,MINT5,ATCO(200,20),ATXS(0:200)
5502         SAVE  /HIPYINT/
5503         DATA NUM1/30123984/,XL/10*0.D0/,XU/10*1.D0/
5504         DATA NCALL/1000/ITMX/100/ACC/0.01/NPRN/0/
5505 C...give all the switchs and parameters the default values
5506 
5507         DATA NSEED/74769375/
5508         DATA HIPR1/
5509      &  1.5,  0.35, 0.5,  0.9,  2.0,  0.1,  1.5,  2.0, -1.0, -2.25,
5510      &  2.0,  0.5,  1.0,  2.0,  0.2,  2.0,  2.5,  0.3,  0.1,  1.4,
5511      &  1.6,  1.0,  2.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.4,  57.0,
5512      &  28.5, 3.9,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0,  
5513      &  3.141592654,
5514      &  0.0,  0.4,  0.1,  1.5,  0.1, 0.25, 0.0,  0.5,  0.0,  0.0,
5515      &  50*0.0/
5516 
5517         DATA IHPR2/
5518      &  1,    3,    0,    1,    1,    1,    1,    10,    0,    0,
5519      &  1,    1,    1,    1,    0,    0,    1,     0,    0,    1,
5520      &  30*0/
5521 
5522         DATA HINT1/100*0/
5523         DATA IHNT2/50*0/
5524 
5525 C...initialize all the data common blocks
5526         DATA NATT/0/EATT/0.0/JATT/0/NT/0/NP/0/N0/0/N01/0/N10/0/N11/0/
5527         DATA KATT/520000*0/PATT/520000*0.0/
5528 
5529         DATA NFP/4500*0/PP/4500*0.0/NFT/4500*0/PT/4500*0.0/
5530 
5531         DATA YP/900*0.0/YT/900*0.0/
5532 
5533         DATA NPJ/300*0/KFPJ/150000*0/PJPX/150000*0.0/PJPY/150000*0.0/
5534      &  PJPZ/150000*0.0/PJPE/150000*0.0/PJPM/150000*0.0/
5535         DATA NTJ/300*0/KFTJ/150000*0/PJTX/150000*0.0/PJTY/150000*0.0/
5536      &  PJTZ/150000*0.0/PJTE/150000*0.0/PJTM/150000*0.0/
5537 
5538         DATA NSG/0/NJSG/900*0/IASG/2700*0/K1SG/90000*0/K2SG/90000*0/
5539      &  PXSG/90000*0.0/PYSG/90000*0.0/PZSG/90000*0.0/PESG/90000*0.0/
5540      &  PMSG/90000*0.0/
5541         DATA MINT4/0/MINT5/0/ATCO/4000*0.0/ATXS/201*0.0/
5542         DATA (HIDAT0(1,I),I=1,10)/0.0,0.0,0.0,0.0,0.0,0.0,2.25,
5543      &          2.5,4.0,4.1/
5544         DATA (HIDAT0(2,I),I=1,10)/2.0,3.0,5.0,6.0,7.0,8.0,8.0,10.0,
5545      &          10.0,10.0/
5546         DATA (HIDAT0(3,I),I=1,10)/1.0,0.8,0.8,0.7,0.45,0.215,
5547      &          0.21,0.19,0.19,0.19/
5548         DATA (HIDAT0(4,I),I=1,10)/0.35,0.35,0.3,0.3,0.3,0.3,
5549      &          0.5,0.6,0.6,0.6/
5550         DATA (HIDAT0(5,I),I=1,10)/23.8,24.0,26.0,26.2,27.0,28.5,28.5,
5551      &          28.5,28.5,28.5/
5552         DATA ((HIDAT0(J,I),I=1,10),J=6,9)/40*0.0/
5553         DATA (HIDAT0(10,I),I=1,10)/5.0,20.0,53.0,62.0,100.0,200.0,
5554      &          546.0,900.0,1800.0,4000.0/
5555         DATA HIDAT/10*0.0/
5556         END
5557 C*******************************************************************
5558 C
5559 C
5560 C
5561 C
5562 C*******************************************************************
5563 C   SUBROUTINE PERFORMS N-DIMENSIONAL MONTE CARLO INTEG'N
5564 C      - BY G.P. LEPAGE   SEPT 1976/(REV)APR 1978
5565 C*******************************************************************
5566 C
5567       SUBROUTINE VEGAS(FXN,AVGI,SD,CHI2A)
5568       IMPLICIT REAL*8(A-H,O-Z)
5569       COMMON/BVEG1/XL(10),XU(10),ACC,NDIM,NCALL,ITMX,NPRN
5570       SAVE  /BVEG1/
5571       COMMON/BVEG2/XI(50,10),SI,SI2,SWGT,SCHI,NDO,IT
5572       SAVE  /BVEG2/
5573       COMMON/BVEG3/F,TI,TSI   
5574       SAVE  /BVEG3/
5575       EXTERNAL FXN
5576       DIMENSION D(50,10),DI(50,10),XIN(50),R(50),DX(10),DT(10),X(10)
5577      1   ,KG(10),IA(10)
5578       REAL*4 QRAN(10)
5579       DATA NDMX/50/,ALPH/1.5D0/,ONE/1.D0/,MDS/-1/
5580 
5581        save NDMX, ALPH, ONE, MDS    !uzhi
5582 C
5583       NDO=1
5584       DO 1 J=1,NDIM
5585 1     XI(1,J)=ONE
5586 C
5587       ENTRY VEGAS1(FXN,AVGI,SD,CHI2A)
5588 C         - INITIALIZES CUMMULATIVE VARIABLES, BUT NOT GRID
5589       IT=0
5590       SI=0.
5591       SI2=SI
5592       SWGT=SI
5593       SCHI=SI
5594 C
5595       ENTRY VEGAS2(FXN,AVGI,SD,CHI2A)
5596 C         - NO INITIALIZATION
5597       ND=NDMX
5598       NG=1
5599       IF(MDS.EQ.0) GO TO 2
5600       NG=(NCALL/2.)**(1./NDIM)
5601       MDS=1
5602       IF((2*NG-NDMX).LT.0) GO TO 2
5603       MDS=-1
5604       NPG=NG/NDMX+1
5605       ND=NG/NPG
5606       NG=NPG*ND
5607 2     K=NG**NDIM
5608       NPG=NCALL/K
5609       IF(NPG.LT.2) NPG=2
5610       CALLS=NPG*K
5611       DXG=ONE/NG
5612       DV2G=(CALLS*DXG**NDIM)**2/NPG/NPG/(NPG-ONE)
5613       XND=ND
5614       NDM=ND-1
5615       DXG=DXG*XND
5616       XJAC=ONE/CALLS
5617       DO 3 J=1,NDIM
5618 c***this is the line 50
5619       DX(J)=XU(J)-XL(J)
5620 3     XJAC=XJAC*DX(J)
5621 C
5622 C   REBIN PRESERVING BIN DENSITY
5623 C
5624       IF(ND.EQ.NDO) GO TO 8
5625       RC=NDO/XND
5626       DO 7 J=1,NDIM
5627       K=0
5628       XN=0.
5629       DR=XN
5630       I=K
5631 4     K=K+1
5632       DR=DR+ONE
5633       XO=XN
5634       XN=XI(K,J)
5635 5     IF(RC.GT.DR) GO TO 4
5636       I=I+1
5637       DR=DR-RC
5638       XIN(I)=XN-(XN-XO)*DR
5639       IF(I.LT.NDM) GO TO 5
5640       DO 6 I=1,NDM
5641 6     XI(I,J)=XIN(I)
5642 7     XI(ND,J)=ONE
5643       NDO=ND
5644 C
5645 8     CONTINUE
5646       IF(NPRN.NE.0) WRITE(16,200) NDIM,CALLS,IT,ITMX,ACC,MDS,ND
5647      1                           ,(XL(J),XU(J),J=1,NDIM)
5648 C
5649       ENTRY VEGAS3(FXN,AVGI,SD,CHI2A)
5650 C         - MAIN INTEGRATION LOOP
5651 9     IT=IT+1
5652       TI=0.
5653       TSI=TI
5654       DO 10 J=1,NDIM
5655       KG(J)=1
5656       DO 10 I=1,ND
5657       D(I,J)=TI
5658 10    DI(I,J)=TI
5659 C
5660 11    FB=0.
5661       F2B=FB
5662       K=0
5663 12    K=K+1
5664       CALL ARAN9(QRAN,NDIM)
5665       WGT=XJAC
5666       DO 15 J=1,NDIM
5667       XN=(KG(J)-QRAN(J))*DXG+ONE
5668 c*****this is the line 100
5669       IA(J)=XN
5670       IF(IA(J).GT.1) GO TO 13
5671       XO=XI(IA(J),J)
5672       RC=(XN-IA(J))*XO
5673       GO TO 14
5674 13    XO=XI(IA(J),J)-XI(IA(J)-1,J)
5675       RC=XI(IA(J)-1,J)+(XN-IA(J))*XO
5676 14    X(J)=XL(J)+RC*DX(J)
5677       WGT=WGT*XO*XND
5678 15    CONTINUE
5679 C
5680       F=WGT
5681       F=F*FXN(X,WGT)
5682       F2=F*F
5683       FB=FB+F
5684       F2B=F2B+F2
5685       DO 16 J=1,NDIM
5686       DI(IA(J),J)=DI(IA(J),J)+F
5687 16    IF(MDS.GE.0) D(IA(J),J)=D(IA(J),J)+F2
5688       IF(K.LT.NPG) GO TO 12
5689 C
5690       F2B=DSQRT(F2B*NPG)
5691       F2B=(F2B-FB)*(F2B+FB)
5692       TI=TI+FB
5693       TSI=TSI+F2B
5694       IF(MDS.GE.0) GO TO 18
5695       DO 17 J=1,NDIM
5696 17    D(IA(J),J)=D(IA(J),J)+F2B
5697 18    K=NDIM
5698 19    KG(K)=MOD(KG(K),NG)+1
5699       IF(KG(K).NE.1) GO TO 11
5700       K=K-1
5701       IF(K.GT.0) GO TO 19
5702 C
5703 C   FINAL RESULTS FOR THIS ITERATION
5704 C
5705       TSI=TSI*DV2G
5706       TI2=TI*TI
5707       WGT=TI2/(TSI+1.0d-37)
5708       SI=SI+TI*WGT
5709       SI2=SI2+TI2
5710       SWGT=SWGT+WGT
5711       SWGT=SWGT+1.0D-37
5712       SI2=SI2+1.0D-37
5713       SCHI=SCHI+TI2*WGT
5714       AVGI=SI/(SWGT)
5715       SD=SWGT*IT/(SI2)
5716       CHI2A=SD*(SCHI/SWGT-AVGI*AVGI)/(IT-.999)
5717       SD=DSQRT(ONE/SD)
5718 C****this is the line 150
5719       IF(NPRN.EQ.0) GO TO 21
5720       TSI=DSQRT(TSI)
5721       WRITE(16,201) IT,TI,TSI,AVGI,SD,CHI2A
5722       IF(NPRN.GE.0) GO TO 21
5723       DO 20 J=1,NDIM
5724 20    WRITE(16,202) J,(XI(I,J),DI(I,J),D(I,J),I=1,ND)
5725 C
5726 C   REFINE GRID
5727 C
5728 21    DO 23 J=1,NDIM
5729       XO=D(1,J)
5730       XN=D(2,J)
5731       D(1,J)=(XO+XN)/2.
5732       DT(J)=D(1,J)
5733       DO 22 I=2,NDM
5734       D(I,J)=XO+XN
5735       XO=XN
5736       XN=D(I+1,J)
5737       D(I,J)=(D(I,J)+XN)/3.
5738 22    DT(J)=DT(J)+D(I,J)
5739       D(ND,J)=(XN+XO)/2.
5740 23    DT(J)=DT(J)+D(ND,J)
5741 C
5742       DO 28 J=1,NDIM
5743       RC=0.
5744       DO 24 I=1,ND
5745       R(I)=0.
5746       IF (DT(J).GE.1.0D18) THEN
5747        WRITE(6,*) '************** A SINGULARITY >1.0D18'
5748 C      WRITE(5,1111)
5749 C1111  FORMAT(1X,'**************IMPORTANT NOTICE***************')
5750 C      WRITE(5,1112)
5751 C1112  FORMAT(1X,'THE INTEGRAND GIVES RISE A SINGULARITY >1.0D18')
5752 C      WRITE(5,1113)
5753 C1113  FORMAT(1X,'PLEASE CHECK THE INTEGRAND AND THE LIMITS')
5754 C      WRITE(5,1114)
5755 C1114  FORMAT(1X,'**************END NOTICE*************')
5756       END IF    
5757       IF(D(I,J).LE.1.0D-18) GO TO 24
5758       XO=DT(J)/D(I,J)
5759       R(I)=((XO-ONE)/XO/DLOG(XO))**ALPH
5760 24    RC=RC+R(I)
5761       RC=RC/XND
5762       K=0
5763       XN=0.
5764       DR=XN
5765       I=K
5766 25    K=K+1
5767       DR=DR+R(K)
5768       XO=XN
5769 c****this is the line 200
5770       XN=XI(K,J)
5771 26    IF(RC.GT.DR) GO TO 25
5772       I=I+1
5773       DR=DR-RC
5774       XIN(I)=XN-(XN-XO)*DR/(R(K)+1.0d-30)
5775       IF(I.LT.NDM) GO TO 26
5776       DO 27 I=1,NDM
5777 27    XI(I,J)=XIN(I)
5778 28    XI(ND,J)=ONE
5779 C
5780       IF(IT.LT.ITMX.AND.ACC*DABS(AVGI).LT.SD) GO TO 9
5781 200   FORMAT('0INPUT PARAMETERS FOR VEGAS:  NDIM=',I3,'  NCALL=',F8.0
5782      1    /28X,'  IT=',I5,'  ITMX=',I5/28X,'  ACC=',G9.3
5783      2    /28X,'  MDS=',I3,'   ND=',I4/28X,'  (XL,XU)=',
5784      3    (T40,'( ',G12.6,' , ',G12.6,' )'))
5785 201   FORMAT(///' INTEGRATION BY VEGAS' / '0ITERATION NO.',I3,
5786      1    ':   INTEGRAL =',G14.8/21X,'STD DEV  =',G10.4 /
5787      2    ' ACCUMULATED RESULTS:   INTEGRAL =',G14.8 /
5788      3    24X,'STD DEV  =',G10.4 / 24X,'CHI**2 PER IT''N =',G10.4)
5789 202   FORMAT('0DATA FOR AXIS',I2 / ' ',6X,'X',7X,'  DELT I  ',
5790      1    2X,' CONV''CE  ',11X,'X',7X,'  DELT I  ',2X,' CONV''CE  '
5791      2   ,11X,'X',7X,'  DELT I  ',2X,' CONV''CE  ' /
5792      2    (' ',3G12.4,5X,3G12.4,5X,3G12.4))
5793       RETURN
5794       END
5795 C
5796 C
5797       SUBROUTINE ARAN9(QRAN,NDIM)
5798       DIMENSION QRAN(10)
5799       COMMON/SEEDVAX/NUM1
5800       DO 1 I=1,NDIM
5801     1 QRAN(I)=RLU(0)
5802       RETURN
5803       END
5804 
5805 C
5806 C
5807 C*********GAUSSIAN ONE-DIMENSIONAL INTEGRATION PROGRAM*************
5808 C
5809         FUNCTION GAUSS1(F,A,B,EPS)
5810         EXTERNAL F
5811         DIMENSION W(12),X(12)
5812         DATA CONST/1.0E-12/
5813         DATA W/0.1012285,.2223810,.3137067,.3623838,.0271525,
5814      &         .0622535,0.0951585,.1246290,.1495960,.1691565,
5815      &         .1826034,.1894506/
5816         DATA X/0.9602899,.7966665,.5255324,.1834346,.9894009,
5817      &         .9445750,0.8656312,.7554044,.6178762,.4580168,
5818      &         .2816036,.0950125/
5819         DELTA=CONST*ABS(A-B)
5820         GAUSS1=0.0
5821         AA=A
5822 5       Y=B-AA
5823         IF(ABS(Y).LE.DELTA) RETURN
5824 2       BB=AA+Y
5825         C1=0.5*(AA+BB)
5826         C2=C1-AA
5827         S8=0.0
5828         S16=0.0
5829         DO 1 I=1,4
5830         U=X(I)*C2
5831 1       S8=S8+W(I)*(F(C1+U)+F(C1-U))
5832         DO 3 I=5,12
5833         U=X(I)*C2
5834 3       S16=S16+W(I)*(F(C1+U)+F(C1-U))
5835         S8=S8*C2
5836         S16=S16*C2
5837         IF(ABS(S16-S8).GT.EPS*(1.+ABS(S16))) GOTO 4
5838         GAUSS1=GAUSS1+S16
5839         AA=BB
5840         GOTO 5
5841 4       Y=0.5*Y
5842         IF(ABS(Y).GT.DELTA) GOTO 2
5843         WRITE(6,7)
5844         GAUSS1=0.0
5845         RETURN
5846 7       FORMAT(1X,'GAUSS1....TOO HIGH ACURACY REQUIRED')
5847         END
5848 C
5849 C
5850 C
5851         FUNCTION GAUSS2(F,A,B,EPS)
5852         EXTERNAL F
5853         DIMENSION W(12),X(12)
5854         DATA CONST/1.0E-12/
5855         DATA W/0.1012285,.2223810,.3137067,.3623838,.0271525,
5856      &         .0622535,0.0951585,.1246290,.1495960,.1691565,
5857      &         .1826034,.1894506/
5858         DATA X/0.9602899,.7966665,.5255324,.1834346,.9894009,
5859      &         .9445750,0.8656312,.7554044,.6178762,.4580168,
5860      &         .2816036,.0950125/
5861         DELTA=CONST*ABS(A-B)
5862         GAUSS2=0.0
5863         AA=A
5864 5       Y=B-AA
5865         IF(ABS(Y).LE.DELTA) RETURN
5866 2       BB=AA+Y
5867         C1=0.5*(AA+BB)
5868         C2=C1-AA
5869         S8=0.0
5870         S16=0.0
5871         DO 1 I=1,4
5872         U=X(I)*C2
5873 1       S8=S8+W(I)*(F(C1+U)+F(C1-U))
5874         DO 3 I=5,12
5875         U=X(I)*C2
5876 3       S16=S16+W(I)*(F(C1+U)+F(C1-U))
5877         S8=S8*C2
5878         S16=S16*C2
5879         IF(ABS(S16-S8).GT.EPS*(1.+ABS(S16))) GOTO 4
5880         GAUSS2=GAUSS2+S16
5881         AA=BB
5882         GOTO 5
5883 4       Y=0.5*Y
5884         IF(ABS(Y).GT.DELTA) GOTO 2
5885         WRITE(6,7)
5886         GAUSS2=0.0
5887         RETURN
5888 7       FORMAT(1X,'GAUSS2....TOO HIGH ACURACY REQUIRED')
5889         END
5890 C
5891 C
5892 C
5893         FUNCTION GAUSS3(F,A,B,EPS)
5894         EXTERNAL F
5895         DIMENSION W(12),X(12)
5896         DATA CONST/1.0E-12/
5897         DATA W/0.1012285,.2223810,.3137067,.3623838,.0271525,
5898      &         .0622535,0.0951585,.1246290,.1495960,.1691565,
5899      &         .1826034,.1894506/
5900         DATA X/0.9602899,.7966665,.5255324,.1834346,.9894009,
5901      &         .9445750,0.8656312,.7554044,.6178762,.4580168,
5902      &         .2816036,.0950125/
5903         DELTA=CONST*ABS(A-B)
5904         GAUSS3=0.0
5905         AA=A
5906 5       Y=B-AA
5907         IF(ABS(Y).LE.DELTA) RETURN
5908 2       BB=AA+Y
5909         C1=0.5*(AA+BB)
5910         C2=C1-AA
5911         S8=0.0
5912         S16=0.0
5913         DO 1 I=1,4
5914         U=X(I)*C2
5915 1       S8=S8+W(I)*(F(C1+U)+F(C1-U))
5916         DO 3 I=5,12
5917         U=X(I)*C2
5918 3       S16=S16+W(I)*(F(C1+U)+F(C1-U))
5919         S8=S8*C2
5920         S16=S16*C2
5921         IF(ABS(S16-S8).GT.EPS*(1.+ABS(S16))) GOTO 4
5922         GAUSS3=GAUSS3+S16
5923         AA=BB
5924         GOTO 5
5925 4       Y=0.5*Y
5926         IF(ABS(Y).GT.DELTA) GOTO 2
5927         WRITE(6,7)
5928         GAUSS3=0.0
5929         RETURN
5930 7       FORMAT(1X,'GAUSS3....TOO HIGH ACURACY REQUIRED')
5931         END
5932 C
5933 C
5934 C
5935 C
5936         FUNCTION GAUSS4(F,A,B,EPS)
5937         EXTERNAL F
5938         DIMENSION W(12),X(12)
5939         DATA CONST/1.0E-12/
5940         DATA W/0.1012285,.2223810,.3137067,.3623838,.0271525,
5941      &         .0622535,0.0951585,.1246290,.1495960,.1691565,
5942      &         .1826034,.1894506/
5943         DATA X/0.9602899,.7966665,.5255324,.1834346,.9894009,
5944      &         .9445750,0.8656312,.7554044,.6178762,.4580168,
5945      &         .2816036,.0950125/
5946         DELTA=CONST*ABS(A-B)
5947         GAUSS4=0.0
5948         AA=A
5949 5       Y=B-AA
5950         IF(ABS(Y).LE.DELTA) RETURN
5951 2       BB=AA+Y
5952         C1=0.5*(AA+BB)
5953         C2=C1-AA
5954         S8=0.0
5955         S16=0.0
5956         DO 1 I=1,4
5957         U=X(I)*C2
5958 1       S8=S8+W(I)*(F(C1+U)+F(C1-U))
5959         DO 3 I=5,12
5960         U=X(I)*C2
5961 3       S16=S16+W(I)*(F(C1+U)+F(C1-U))
5962         S8=S8*C2
5963         S16=S16*C2
5964         IF(ABS(S16-S8).GT.EPS*(1.+ABS(S16))) GOTO 4
5965         GAUSS4=GAUSS4+S16
5966         AA=BB
5967         GOTO 5
5968 4       Y=0.5*Y
5969         IF(ABS(Y).GT.DELTA) GOTO 2
5970         WRITE(6,7)
5971         GAUSS4=0.0
5972         RETURN
5973 7       FORMAT(1X,'GAUSS4....TOO HIGH ACURACY REQUIRED')
5974         END
5975 C
5976 C
5977 C
5978 C
5979 C
5980         SUBROUTINE TITLE
5981         WRITE(6,200)
5982 200     FORMAT(//10X,
5983      &  '**************************************************'/10X,
5984      &  '*     |      \\       _______      /  ------/     *'/10X,
5985      &  '*   ----- ------     |_____|     /_/     /       *'/10X,
5986      &  '*    ||\\    /        |_____|      /    / \\       *'/10X,
5987      &  '*    /| \\  /_/       /_______    /_  /    \\_     *'/10X,
5988      &  '*   / |     / /     /  /  / |        -------     *'/10X,
5989      &  '*     |    / /\\       /  /  |     /     |        *'/10X,
5990      &  '*     |   / /  \\     /  / \\_|    /   -------     *'/10X,
5991      &  '*                                                *'/10X,
5992      &  '**************************************************'/10X,
5993      &  '                      HIJING                      '/10X,
5994      &  '       Heavy Ion Jet INteraction Generator        '/10X,
5995      &  '                        by                        '/10X,
5996      &  '           X. N. Wang  and  M. Gyulassy           '/10X,
5997      &  '           Lawrence Berkeley Laboratory           '//) 
5998         RETURN
5999         END