FTCHKH COMMENTS
*-- Author :    I.O. Skillicorn   18/08/93
      SUBROUTINE FTCHKH(PS,PI,RS,RI,II,JJ,KK,CHID)
**: FTCHKH 40000 IS. New linking routine.                                                                     
**----------------------------------------------------------------------                                      
*                                                                                                             
*                                                                                                             
C     CALCULATES PS,PI,RS,RI ,CHID                                                                            
C     PARABOLA PHI-Z R-Z FOR THREE MODULE TRACKS                                                              
C     HELIX PHI-Z R-Z FOR TWO MODULE TRACKS                                                                   
C     ADDITIONAL PLOTS ARE MADE WRT STR LINES IN PHI-S R-Z.                                                   
C     WITH THESE WE CAN OPTIMISE PARAMETERS FOR TRACK                                                         
C     ORIGINATING  FROM THE IP                                                                                
C                                                                                                             
*KEEP,FRDIMS.                                                                                                 
*KEEP,FH1WORK.                                                                                                
*    Planar geometry                                                                                          
*                                                                                                             
*    Radial geometry                                                                                          
*                                                                                                             
*    Radial data...                                                                                           
*                                                                                                             
*    Planar Data                                                                                              
*                                                                                                             
*    Pointers into DIGI bank for IOS labelled hits                                                            
*                                                                                                             
*    Track segment data                                                                                       
*                                                                                                             
*    Fit data                                                                                                 
*                                                                                                             
*                                                                                                             
*KEEP,FDIFLG.                                                                                                 
*KEND.                                                                                                        
*                                                                                                             
*******************************************************************                                           
C     OPTION TO USE LINEAR TRACK MODEL:-                                                                      
C     IF USED, TRACKS ORIGINATING FROM IP WILL BE SELECTED                                                    
C     PREFERENTIALLY                                                                                          
       CALL STEXT(1201,4,' FTCHKH: CHI DRIFT RAD 123' )                                                
       CALL BHS(1201,0,50, 0.00,25.0)                                                                  
       CALL STEXT(1202,4,' FTCHKH: CHI DRIFT RAD 12 ')                                                 
       CALL BHS(1202,0,50, 0.00,25.0)                                                                  
       CALL STEXT(1203,4,' FTCHKH: CHI DRIFT RAD 13 ')                                                 
       CALL BHS(1203,0,50, 0.00,25.0)                                                                  
       CALL STEXT(1204,4,' FTCHKH: CHI DRIFT RAD 23 ')                                                 
       CALL BHS(1204,0,50, 0.00,25.0)                                                                  
       CALL STEXT(1205,4,' FTCHKH: RESIDUAL 3RAD M1 ')                                                 
       CALL BHS(1205,0,50, -.50,0.50)                                                                  
       CALL STEXT(1206,4,' FTCHKH: RESIDUAL 3RAD M2 ')                                                 
       CALL BHS(1206,0,50, -.50,0.50)                                                                  
       CALL STEXT(1207,4,' FTCHKH: RESIDUAL 3RAD M3 ')                                                 
       CALL BHS(1207,0,50, -.50,0.50)                                                                  
       CALL STEXT(1208,4,' FTCHKH: RESIDUAL 2RAD M1 ')                                                 
       CALL BHS(1208,0,50, -.50,0.50)                                                                  
       CALL STEXT(1209,4,' FTCHKH: RESIDUAL 2RAD M2 ')                                                 
       CALL BHS(1209,0,50, -.50,0.50)                                                                  
       CALL STEXT(1210,4,' FTCHKH: RESIDUAL 2RAD M3 ')                                                 
       CALL BHS(1210,0,50, -.50,0.50)                                                                  
*******************************************************************                                           
C     FIT R  -Z IN LAB   FRAME                                                                                
C     FIT R  -Z IN LAB   FRAME                                                                                
      CALL FTLFTW(XX,ZZ,WPR,IC,0,2,RS,RI,D1,D2,D3,D4)
C     FIT PHI-Z LAB FRAME USING FITTED R                                                                      
C     PRINT 1001,IM,NT,IPL,JPL,J                                                                              
C     FIT PHI-Z IN LAB   FRAME                                                                                
      CALL FTLFTW(XX,YY,WP,IC,0,2,PS,PI,D1,D2,D3,D4)
C     WRITE(*,*)' FTCHKH LT ',LT                                                                              
C     FIND VERTEX - FIRST POINT , FIRST SEGMENT                                                               
C     PRINT 1000,IM,NT,(IRPT(JKL,NT,IM),JKL=1,12)                                                             
C     WRITE(*,*)XFFF,YFFF,ZFFF                                                                                
C     WRITE(*,*)PS,PI,RS,RI                                                                                   
C     FIT PHI-Z , R-Z  IN HELIX FRAME                                                                         
C     PRINT 1001,IM,NT,IPL,JPL,J                                                                              
C     ERROR IN PHI DEPENDS ON 1/RH                                                                            
C     FIT PHI-Z IN HELIX FRAME                                                                                
      CALL FTLFTW(XX,YY,WP,IC,0,2,PSH,PIH,D1,D2,D3,D4)
C     WRITE(*,*)' IC PSH PIH ',IC,PSH,PIH                                                                     
C     FIT R  -Z IN HELIX FRAME                                                                                
      CALL FTLFTW(XX,ZZ,WPR,IC,0,2,RSH,RIH,D1,D2,D3,D4)
C     WRITE(*,*)' IC RSH RIH ',IC,RSH,RIH                                                                     
C     GET CHI**2 WRT TO HELIX PHI-Z ,R-Z                                                                      
C     CHI FOR PARABOLAE - THREE MODULE TRACKS                                                                 
C     CHI FOR PHI-Z,R-Z HELIX FRAME - TWO MODULE TRACKS                                                       
C     MEASURED DRIFT                                                                                          
C     PREDICTED DRIFT                                                                                         
C     WRITE(*,*)' DRIFTS ',LL,DRM,DEH                                                                         
C     PARABOLA FOR CHI AND RESIDUALS                                                                          
      PHIP=FPARAB(ZED,PHA(1),PHA(2),PHA(3),
      RRP =FPARAB(ZED, RA(1), RA(2), RA(3),
C     PHI-Z HELIX FRAME                                                                                       
C     PCHID=PROB(CHID*FLOAT(LL),LL)                                                                           
C     WRITE(*,*)' CHID ',CHID                                                                                 
C      PARABOLA FOR CHI AND RESIDUALS                                                                         
C      PHI-Z HELIX FRAME                                                                                      
*