C   28/06/78 509272143  MEMBER NAME  CERGNR6  (JADEMC2)     FORTRAN
      SUBROUTINE CERGNR( XYZ, DIR, T, PENUM)
C     S.YAMADA    12-05-81
C     COPIED FROM CERNKV
C     LAST MODIFICATION  12-05-81  15:45
C
C---- THE POSITION DEPENDENCE ON THE PMT SURFACE IS INCLUDED.
C I.E.  TRACE CERENKOV LIGHT TO THE BACK SURFACE OF THE LEAD GLASS
C     COUNTER AND EXAMINE PHOTOELECTRIC CONVERSION ONLY IF THE LIGHT
C     GOES INTO THE LIGHT GUIDE.
C---- XYZ = INITIAL POINT DEPTH OF THE SOURCE  ELECTRON IN RAD LNG.
C---- DIR = DIRECTION COSIGNS OF THE  SOURCE ELECTRON.
C---- T  =  PATH LENGTH OF  THE SOURCE TRACK IN RAD LENGTH.
C
      DIMENSION  XYZ(3),DIR(3),PHDIR(3)
C
      DATA CONVMX/0.28/,   TOTL/30.0/, WID/10.47/, HWID/5.235/
C---- CONVMX=MAX CONVERSION EFFICIENCY OF R594.
C     TOTL = TOTAL LENGTH OF THE LEAD GLASS IN CM.
C
      DATA RAD/1.53/,  COST/0.55411/,SINT/0.83244/
C
C---- CALCULATE TOTAL CERENKOV QUANTA NUMBER.
C     NL=(2*3.14/137.)/C*(1-1/N**2)*(DELTA  NEU)*T(IN CM)
C     DELTA NEU =  FREQUENCY RANGE,HERE BETWEEN  429000 AND 882000
C                  GHZ,DNEU=453000GHZ.
C     N =  REFLACTIVE INDEX (=1.8047 IS USED)
C     (1-1/N**2)=0.69296
C     C=LIGHT VELOCITY(=30CM/NSEC)
C
      X = RAD*XYZ(1)
      Y = RAD*XYZ(2)
      Z = RAD*XYZ(3)
C
 1000 TCM =  RAD*T
      ANL = 479.55*TCM
      NL = ANL
      ANL1 = NL
      NL = NL+1
      FRCANL = ANL-ANL1
C
      TCMZ = TCM*ABS(DIR(3))
      NACP = 0
C
C---- REPEAT FOR NL-PHOTONS
        DO 1 I=1,NL
C----   RANDUMLY CORRECT FRACTIONAL TRIAL NUMBERS.
        IF(I.EQ.NL.AND.RN(DUM).GT.FRCANL) GO TO 1
C
C       CALCULATE  PHOTON DIRECTION COSIGN Z-COMPONENT.
          DO 2 K=1,3
    2     PHDIR(K) = DIR(K)
        CALL NEWDR1(PHDIR,COST,SINT)
C
C----    CHECK TOTAL REFLECTION CONDITION BETWEEN NORMAL GLASS(N=1.52)
        ABSANN = ABS(PHDIR(3))
C           STYCAST CASE
        IF(ABSANN.LT.0.5624) GO TO 1
        TRNS = 1.-0.0084/(ABSANN-0.554)
CCC         RTV  CASE
CCC     IF(ABSANN.LT.0.6264) GO TO 1
CCC     TRNS = 1.-0.0084/(ABSANN-0.618)
C
        IF(RN(DUM).GT.TRNS) GO TO 1
C
C        SET  FREQUENCY
        FREQ = 429000.+RN(DUM)*453000.
C
C----    ALAMDA=WAVE LENGTH IN NANO-METER.
        ALAMDA = 3.E8/FREQ
C
C----    EMMITTED POSITION Z-CORDINATE IN CM.
        ZS = Z+RN(DUM)*TCMZ
        IF(PHDIR(3).LT.0.) ZS = -ZS
    3   PATHL = (TOTL-ZS)/ABSANN
C       ABSORPTION LENGTH TO THE BACK SURFACE
        ABSL = PATHL/AVABS(ALAMDA)
        IF(ABSL.LT.0.) GO TO 1
        IF(ABSL.GT.14.) GO TO  1
C        ABSORPTION  PROBABILITY  CHECK
        IF(RN(DUM).GT.EXP(-ABSL)) GO TO 1
C
C       REFLECTION AT THE SIDE SURFACE,  NREF IS NUMBER OF REFLECTIONS.
        NREF = 0
C       X
        ABSALL = ABS(PHDIR(1))
        IF(ABSALL.LT.0.8324) GO TO 4
        NREF = PATHL*ABSALL/WID
C       Y
    4   ABSAMM = ABS(PHDIR(2))
        IF(ABSAMM.LT.0.8324) GO TO 5
        NREF = NREF + PATHL*ABSAMM/WID
    5   IF( NREF.EQ. 0 ) GO TO 6
        IF( RN(DUM).GT. 0.85**NREF ) GO TO 1
    6   CONTINUE
C
C-----  HIT POSITION CHECK ON THE REAR SURFACE
  1000  XHIT = X+PHDIR(1)*PATHL
        YHIT = Y+PHDIR(2)*PATHL
        IF(XHIT) 10,20,11
   10   IF(XHIT.GE.-HWID) GO TO 20
        XHIT = XHIT+WID
        GO TO 10
   11   IF(XHIT.LE. HWID) GO TO 20
        XHIT = XHIT-WID
        GO TO 11
   20   IF(YHIT) 21,30,22
   21   IF(YHIT.GE.-HWID) GO TO 30
        YHIT = YHIT+WID
        GO TO 21
   22   IF(YHIT.LE. HWID) GO TO 30
        YHIT = YHIT-WID
        GO TO 22
   30   RHIT = SQRT(XHIT**2+YHIT**2)
C----   THE LIGHT GUIDE DIAMETER IS 7.5CM.
        IF(RHIT.GT.3.75) GO TO 1
C
C       CHECK CONVERSION EFFICIENCY.
C----   TO KEEP MONTE CARLO EFFICIENCY CONVMX IS MULTIPLIED TO THE RANDU
   40    IF(CONVMX*RN(DUM).GT.CONVEF(ALAMDA)) GO TO 1
C
C       PHOTON  IS DETECTED.
        NACP = NACP+1
    1   CONTINUE
C
      PENUM = NACP*CONVMX
C
      RETURN
      END
