C   15/03/79 C9090901   MEMBER NAME  LGCLPC   (SOURCE)      FORTRAN
C   13/03/79 C9031501   MEMBER NAME  LGCLPCN  (S)           FORTRAN
      SUBROUTINE LGCLPC
C
C     MODIFIED TO CALCULATE THE CLUSTER SHAPE
C     BY R.EICHLER       15-03-78  12:00
C     LAST MODIFICATION    16-08-79  19:40      Y.WATANABE
C
C     ORGNL. S.YAMADA      13-01-78 VERSION 2 (LAST MOD.08-02-79,23:30)
C
C---- LEAD GLASS CLUSTERS IN THE ENDCAP PART ARE PROCESSED.
C---- TOTAL PULSE HEIGHT,AVERAGE POSITION AND SPATIAL SPREAD ARE
C     CALCULATED FOR EACH CLUSTER.
C
      IMPLICIT INTEGER *2 (H)
C
      COMMON /CLGDMS/ X0,RADIUS(6),RADSX0(6),THX0(4),
     1                ZEND(2),ZENDX0(2),ZWID(2),ZGAP(2),PHWID(2),
     2                ZECAP(4),ZECAPX(4),THECPX(2),
     3                ECXLST(24), ECYLST(24)
      COMMON /CLGPRM/ ITHADC,MAXCLS
      COMMON/LGSHP/WW(50),YY(50),XX(50),EW(2),AVX,AVY,SIGX,SIGY,EV,KK
C
      COMMON /CLGMSB/ MSGVAL(5)
      DIMENSION AMSGVL(5)
      EQUIVALENCE (MSGVAL(1),AMSGVL(1))
C
#include "clgwork1.for"
C
C     ICLSPR(1,I)=JBC, 0 FOR BARREL, -1 FOR BOTTOM, 1 FOR TOP
C     CLSPRP(2,I)=ENERGY IN GEV
C     CLSPRP(3,I)=SIG(ENERGY)
C     CLSPRP(4,I)=WEIGHTED AVERAGE X
C     CLSPRP(5,I)=WEIGHTED AVERAGE Y
C     CLSPRP(6,I)=SIGMA X (WEIGHTED)
C     CLSPRP(7,I)=SIGMA Y (WEIGHTED)
C     ICLSPR(8,I)=CHARGE,IF THERE IS A CHARGED NEIGHBOUR
C                  TRACK,ITS CHARGE IS COPIED.
C     CLSPRP(9--11,I)=DIRECTION COSIGNS OF THE CLUSTER
C     CLSPRP(12-14,I)=CLUSTER SHAPE: ELLIPS EIGENVALUES AND DIRECTION
C     CLSPRP(15,I)=FRACTION OF ENERGY IN EDGE COUNTERS IN THE CLUSTER
C
      COMMON/ CLGVRN/ NVRSN(20)
      DATA NVCODE/279071617/
      NVRSN(10) = NVCODE
C
      IF(NCLBEC(2)+NCLBEC(3).LE.0) RETURN
      N1 = NCLBEC(1)+1
      N2 = NCLST
      IF(N2 .GT. MAXCLS) N2=MAXCLS
        DO 1 N=N1,N2
        NS = HMAPCL(1,N)
        NL = HMAPCL(2,N)
        WSUM = 0.
        KK=NL-NS+1
        IF(KK.GT.50) KK = 50
          DO 2 NN=NS,NL
          ID = HLGADC(1,NN)
          ID = ID-2687
          IPART = -1
          IF(ID.LE.96) GO TO 3
          ID = ID-96
          IPART = 1
          IF(ID.LE.96) GO TO 3
C-----    ILLEGAL COMPONENT NO.
          MSGVAL(1) = NN
          MSGVAL(2) = ID
          MSGVAL(3) = HLGADC(1,NN)
          CALL LGMESG( 6, 1)
C-----    BAD DATA IS SKIPPED.
          GO TO 2
C
    3     MB = (ID-1)/24
          ID = ID-24*MB
          U = ECXLST(ID)
          V = ECYLST(ID)
          MB = MB+1
          GO TO (4,5,6,7),MB
    4     X = U
          Y = V
          GO TO 8
    5     X = -V
          Y = U
          GO TO 8
    6     X = -U
          Y = -V
          GO TO 8
    7     X = V
          Y = -U
C----     PULSE HEIGHT OF THE NN-TH HIT IS CALIBRATED TO GIVE MEV.
C         CHANGE IT TO GEV.
C
    8     W = HLGADC(2,NN)
          WSUM = WSUM+W
C
          IF(W) 90,9,9
C----     NEGATIVE ENERGY,   CLEARED TO PROTECT 'LGEIGN'.
   90     AMSGVL(1) = W
          CALL LGMESG( 6, 2)
          W = 0.
C
C----     FILL ARRAYS FOR CLUSTER SHAPE ANALYSIS
    9     NM=NN-NS+1
          IF(NM.GT.50) GO TO 14
          WW(NM)=W
          YY(NM)=Y
          XX(NM)=X
C
C----     CORNER CHECK
   14     CALL LGCRNR( IPART, ID, ID, ICLS)
          IF(ICLS.EQ.1) CLSPRP(15,N)=CLSPRP(15,N)+W
    2   CONTINUE
C
        CALL LGEIGN(1.)
C       CHANGE SIGZ AND SIGPH IN LINEAR DIMENSION.(Y.WATANABE 8/9/79)
        IF(SIGX.GT.0.) SIGX=SQRT(SIGX)
        IF(ABS(AVX-XX(1)).LT.0.1) SIGX=140./3.4641
C       WHEN ONLY ONE ROW OF THAT DIMENSION FIRE,
C       SIGMA=COUNTER WIDTH/2/SQRT(3).
        IF(SIGY.GT.0.) SIGY=SQRT(SIGY)
        IF(ABS(AVY-YY(1)).LT.0.1) SIGY=140./3.4641
C
C
C----   FILL RESULTS
        ICLSPR(1,N) = IPART
        WSUM = WSUM*0.001
        CLSPRP(2,N) = WSUM
        CALL LGEERR(IPART,WSUM,CLSPRP(3,N))
        CLSPRP(4,N) = AVX
        CLSPRP(5,N) = AVY
        CLSPRP(6,N) = SIGX
        CLSPRP(7,N) = SIGY
        CLSPRP(12,N)=EW(2)/EW(1)
        CLSPRP(13,N)=EW(1)+EW(2)
        CLSPRP(14,N)=EV
        CLSPRP(15,N)=0.001*CLSPRP(15,N)/WSUM
C
C----   ENERGY SUM
        IF(IPART) 10,1,20
   10   ETOT(3) = ETOT(3)+WSUM
        GO TO 1
   20   ETOT(4) = ETOT(4)+WSUM
C
    1   CONTINUE
  100 RETURN
      END
