      SUBROUTINE PAIR
C                                VERSION 4.00  --  26 JAN 1986/1900
C******************************************************************
C   FOR A PHOTON ENERGY LESS THAN 2.1 MEV, THE APPROXIMATION IS
C   MADE THAT ONE PAIR ELECTRON (OR POSITRON) HAS ONLY ITS REST
C   MASS ENERGY.   FOR PHOTON ENERGY BETWEEN 2.1 MEV AND 50 MEV THE
C   BETHE-HEITLER CROSS SECTION IS EMPLOYED.  ABOVE 50 MEV THE
C   COULOMB CORRECTED BETHE-HEITLER CROSS SECTION IS USED.
C   (BUTCHER AND MESSEL, OP. CIT., P. 17-19, 22).
C******************************************************************
      DOUBLE PRECISION PEIG,PESE1,PESE2
      COMMON/BREMPR/DL1(6),DL2(6),DL3(6),DL4(6),DL5(6),DL6(6),DELCM, ALP
     *HI(2),BPAR(2),DELPOS(2),PWR2I(50)
*KEEP,RANDPA.
      COMMON /RANDPA/  FAC,U1,U2,RD,NSEQ,ISEED,KNOR
      DOUBLE PRECISION FAC,U1,U2
      REAL             RD(3000)
      INTEGER          ISEED(103,10),NSEQ
      LOGICAL          KNOR
*KEEP,RUNPAR.
      COMMON /RUNPAR/  FIXHEI,THICK0,HILOECM,HILOELB,
     *                 STEPFC,NRRUN,NSHOW,PATAPE,MONIIN,
     *                 MONIOU,MDEBUG,NUCNUC,
     *                 CETAPE,
     *                 SHOWNO,ISHW,NOPART,NRECS,NBLKS,MAXPRT,NDEBDL,
     *                 N1STTR,MDBASE,
     *                 DEBDEL,DEBUG,FDECAY,FEGS,FIRSTI,FIXINC,FIXTAR,
     *                 FIX1I,FMUADD,FNKG,FPRINT,FDBASE
     *                ,GHEISH,GHESIG
      COMMON /RUNPAC/  DSN,HOST,USER
      DOUBLE PRECISION FIXHEI,THICK0,HILOECM,HILOELB
      REAL             STEPFC
      INTEGER          NRRUN,NSHOW,PATAPE,MONIIN,MONIOU,MDEBUG,NUCNUC,
     *                 SHOWNO,ISHW,NOPART,NRECS,NBLKS,MAXPRT,NDEBDL,
     *                 N1STTR,MDBASE
      INTEGER          CETAPE
      CHARACTER*79     DSN
      CHARACTER*20     HOST,USER
 
      LOGICAL          DEBDEL,DEBUG,FDECAY,FEGS,FIRSTI,FIXINC,FIXTAR,
     *                 FIX1I,FMUADD,FNKG,FPRINT,FDBASE
     *                ,GHEISH,GHESIG
*KEEP,STACKE.
      COMMON/STACKE/   E,TIME,X,Y,Z,U,V,W,DNEAR,IQ,IGEN,IR,IOBS,LPCTE,NP
      DOUBLE PRECISION E(60),TIME(60)
      REAL             X(60),Y(60),Z(60),U(60),V(60),W(60),DNEAR(60)
      INTEGER          IQ(60),IGEN(60),IR(60),IOBS(60),LPCTE(60),NP
*KEND.
      COMMON/THRESH/RMT2,RMSQ,ESCD2,AP,API,AE,UP,UE,TE,THMOLL
      COMMON/UPHIOT/THETA,SINTHE,COSTHE,SINPHI, COSPHI,PI,TWOPI,PI5D2
      DOUBLE PRECISION PZERO,PRM,PRMT2,RMI,VC
      COMMON/USEFUL/PZERO,PRM,PRMT2,RMI,VC,RM,MEDIUM,MEDOLD,IBLOBE,ICALL
      COMMON/ACLOCK/NCLOCK,JCLOCK
C_____IF (NCLOCK.GT.JCLOCK) THEN
C______WRITE(MDEBUG,* )' PAIR:  NP=',NP,' IR=',IR(NP),' IOBS=',IOBS(NP)
C______CALL AUSGB2
C_____END IF
      PEIG=E(NP)
      EIG=PEIG
      IF (EIG.LE.2.1) THEN
       ESE2=PRM
      ELSE
       IF (EIG.LT.50.) THEN
        LVX=1
        LVL0=0
       ELSE
        LVX=2
        LVL0=3
       END IF
961    CONTINUE
        CALL RMMAR(RD,2,2)
        RNNO30=RD(1)
        RNNO31=RD(2)
        IF (RNNO31.GE.BPAR(LVX)) THEN
         LVL=LVL0+1
         CALL RMMAR(RD,2,2)
         RNNO32=RD(1)
         RNNO33=RD(2)
         BR=0.5*(1.0-MAX(RNNO32,RNNO33,RNNO30))
        ELSE
         LVL=LVL0+3
         BR=RNNO30*0.5
        END IF
        IF((BR.EQ.0.0))GO TO961
        DEL=1.0/(EIG*BR*(1.0-BR))
        IF((DEL.GE.DELPOS(LVX)))GO TO961
        DELTA=DELCM*DEL
        IF (DELTA.LT.1.0) THEN
         REJF=DL1(LVL)+DELTA*(DL2(LVL)+DELTA*DL3(LVL))
        ELSE
         REJF=DL4(LVL)+DL5(LVL)*LOG(DELTA+DL6(LVL))
        END IF
        CALL RMMAR(RNSCRN,1,2)
        IF((RNSCRN.LE.REJF))GO TO962
       GO TO 961
962    CONTINUE
       ESE2=BR*EIG
      END IF
      PESE2=ESE2
      PESE1=PEIG-PESE2
      E(NP)=PESE1
      E(NP+1)=PESE2
      THETA=RM/EIG
      CALL UPHI(1,1)
      NP=NP+1
      SINTHE=-SINTHE
      CALL UPHI(3,2)
      CALL RMMAR(RNNO34,1,2)
      IF (RNNO34.LE.0.5) THEN
       IQ(NP)=2
       IQ(NP-1)=3
      ELSE
       IQ(NP)=3
       IQ(NP-1)=2
      END IF
      RETURN
      END
