SUBROUTINE FHEPAR
*-- Author :    Stephen J. Maxfield   21/11/92
      SUBROUTINE FHEPAR(K, ILIST, ZF, CU, PH, TH, X0, Y0)
*                                                                                                             
*     Calculate track parameters for the ITRK'th track from the                                               
*     Slopes and intercepts of the R-z and Phi-z fits.                                                        
*     INPUT: Track number K                                                                                   
*            ILIST track type (1-rad-based/2=pla-based)                                                       
*            ZF  z of first measured point                                                                    
*                                                                                                             
*KEEP,FRDIMS.                                                                                                 
      PARAMETER (MAXHTS=200)                                            
      PARAMETER (NUMWPL=36)                                             
      PARAMETER (MAXTRK=200)                                            
      PARAMETER (MXTTRK=900)                                            
      PARAMETER (MAXTR3=200)                                            
      PARAMETER (MAXHPW=2)                                              
      PARAMETER (MAXDIG=2000)                                           
      PARAMETER (NUMRWR=1727)                                           
      PARAMETER (NUMPWR=1151)                                           
*KEEP,FH1WORK.                                                                                                
       COMMON/FGMIOS/                                                   
*    Planar geometry                                                                                          
     + ZPP(140),C(140),S(140),ITYPE(140),WZERO(140),WSPACE,             
*                                                                                                             
*    Radial geometry                                                                                          
     + ZP(36),PHW(36),WS(36)                                            
*                                                                                                             
       COMMON/H1WORK/                                                   
*    Radial data...                                                                                           
     + WW(MAXHTS,36),DRI(MAXHTS,36),RM(MAXHTS,36),                      
     + NDP(36),  NW(MAXHTS,36), DWS(MAXHTS,36),                         
*                                                                                                             
*    Planar Data                                                                                              
     + NDPW(NUMWPL),DW(MAXHTS,NUMWPL),                                  
     + DRIW(MAXHTS,NUMWPL),NDW(MAXHTS,NUMWPL),                          
     + WWP(MAXHTS,NUMWPL),                                              
     + IPHOLE(MAXHTS,NUMWPL),                                           
*                                                                                                             
*    Pointers into DIGI bank for IOS labelled hits                                                            
     +  IPFRRE(MAXHTS,36),IPFRPE(MAXHTS,36),NFRRE,NFRPE,                
     +  IRPIOS(MAXDIG,2), IPPIOS(MAXDIG,2),                             
*                                                                                                             
*    Track segment data                                                                                       
     + NTRAKS(3),IRPT(12,MAXTRK,3),SDRFT(12,MAXTRK,3),                  
*                                                                                                             
*    Fit data                                                                                                 
     + PCOSL(MAXTRK,3),PSINL(MAXTRK,3),PHZL(MAXTRK,3),                  
     + DPCOSL(MAXTRK,3),DPSINL(MAXTRK,3),                               
     + DPHZL(MAXTRK,3),CHSQ(MAXTRK,3),RZI(MAXTRK,3),                    
     + RPCOSG(MAXTRK),RPSING(MAXTRK),                                   
     + PHZG(MAXTRK),CC(3,MAXTRK),ZIG(MAXTRK),                           
     + IRADG(36,MAXTRK),PHIG(36,MAXTRK),                                
     + IG,SDRADG(36,MAXTRK),                                            
     + R1,Z1,RFIT(MAXTRK,3),                                            
     + CHG(MAXTRK),                                                     
     + PPA(MAXTRK,3),  ZZA(MAXTRK,3),                                   
     + GPA(MAXTRK,3),GZA(MAXTRK,3)                                      
*                                                                                                             
*                                                                                                             
*KEEP,FPTVTX.                                                                                                 
      COMMON/VERTVV/ZV ,XVV,YVV                                         
**the common/VERTEX/ becomes /VERTVV/ (in analogy to /VERTFF/) on the                                         
** 17/6/91, since it is in conflict with the VERTEX module (g.bernardi)                                       
** (note that all these common names should start by F in this deck...)                                       
*KEND.                                                                                                        
      COMMON/FPPFIT/PSSS(100),PISS(100),RSSS(100),RISS(100)             
                                                                        
      IF(ILIST .EQ. 1) THEN                                             
        SLPHI =RPCOSG(K)                                                
        SLPR  =RPSING(K)                                                
        PHZER =PHZG(K)                                                  
        RZER  =ZIG(K)                                                   
      ELSE                                                              
        SLPHI =PSSS(K)                                                  
        SLPR  =RSSS(K)                                                  
        PHZER =PISS(K)                                                  
        RZER  =RISS(K)                                                  
      ENDIF                                                             
                                                                        
      RR = SLPR  * ZF + RZER                                            
      PHI= SLPHI * ZF + PHZER                                           
                                                                        
      X0 = RR*COS(PHI) + XVV                                            
      Y0 = RR*SIN(PHI) + YVV                                            
                                                                        
                                                                        
                                                                        
      IF(SLPHI .EQ.0.0)THEN                                             
       CU = 0.0                                                         
      ELSE                                                              
       BETA = SLPR/SLPHI                                                
       U    = SQRT(RR*RR + BETA*BETA)                                   
       CU = SIGN(1.,SLPHI)*(RR*RR + 2.0*BETA*BETA)/(U**3)               
      ENDIF                                                             
                                                                        
      DXDZ = SLPR*COS(PHI) - RR*SLPHI*SIN(PHI)                          
      DYDZ = SLPR*SIN(PHI) + RR*SLPHI*COS(PHI)                          
                                                                        
      TH = ATAN(SQRT(SLPR**2 + (RR*SLPHI)**2))                          
      PH = ATAN2(DYDZ,DXDZ)                                             
                                                                        
      RETURN                                                            
      END                                                               
*