FPPJN3 COMMENTS
*-- Author :    I. O. Skillicorn      16/11/92
      SUBROUTINE FPPJN3
**: FPPJN3 40000 IS. New linking code.                                                                        
**----------------------------------------------------------------------                                      
**: FPPJN3 30907 RP. Farm changes.                                                                            
**----------------------------------------------------------------------                                      
C     JOIN 3 PLANAR MODULES                                                                                   
C     1MM ERRORS USED IN CHI .                                                                                
*KEEP,FRDIMS.                                                                                                 
*KEEP,FPPRAM.                                                                                                 
C                                                                                                             
C---  MAXSEG is maximum number of segments per supermodule                                                    
C---  MAXCON is maximum number of amibiguous segments associatable with                                       
C---         one segment                                                                                      
C---  LIMSTO is maximum number of 2 cluster planes intersections to be                                        
C---         stored per supermodule                                                                           
C---  MSEGLM is maximum number of clusters that can be found before                                           
C---         connectivity considered                                                                          
C---  MAXCLU is maximum number of clusters that can be found after                                            
C---         forming non-connected set    MUST BE 50 IF RUN WITH OLD RCW                                      
C---         (cluster = 3/4 digits found in a straight line in one                                            
C---          4-wire orientation)                                                                             
C                                                                                                             
C---                                                                                                          
*KEEP,FH1WORK.                                                                                                
*    Planar geometry                                                                                          
*                                                                                                             
*    Radial geometry                                                                                          
*                                                                                                             
*    Radial data...                                                                                           
*                                                                                                             
*    Planar Data                                                                                              
*                                                                                                             
*    Pointers into DIGI bank for IOS labelled hits                                                            
*                                                                                                             
*    Track segment data                                                                                       
*                                                                                                             
*    Fit data                                                                                                 
*                                                                                                             
*                                                                                                             
*KEEP,FPTVTX.                                                                                                 
**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...)                                       
*KEEP,FPFVTX.                                                                                                 
*                                                                                                             
*KEEP,FPJPAR.                                                                                                 
*KEND.                                                                                                        
*     RRCUT=5.0                                                                                               
C     PLANAR SEGMENTS ARE JOINED BY PROJECTING THE SEGMENTS TO A                                              
C     PLANE MIDWAY BETWEEN THE SEGMENTS. THE DISTANCE**2 BETWEEN                                              
C     THE PROJECTIONS,RR, ON THIS PLANE IS USED AS A MEASURE OF                                               
C     THE GOODNESS OF LINKAGE.  IF RR IS LESS THAN RCUT THE                                                   
C     LINK IS ACCEPTED.                                                                                       
      IF (ABS(Y1M-Y2M).LT.2.0) CALL SHS(907,0,X1M-X2M)                                                 
      IF (ABS(X1M-X2M).LT.2.0) CALL SHS(908,0,Y1M-Y2M)                                                 
      CALL SHS(904,0,RR)                                                                               
      CALL SHS(905,0,RR)                                                                               
C     POTENTIAL LINK - CALCULATE CHI BETWEEN PARABOLA AND                                                     
C     FITTED LINE SEGMENTS                                                                                    
C     PARABOLA IS THRU CENTRE OF SEGMENTS                                                                     
C     DRIFT COORDS FOR PLANARS                                                                                
      XP=FPARAB(ZA,X1,X2,X3,Z1,Z2,Z3)
*     CHI=CHI+(XF-XP)**2/(0.10)**2                                                                            
      YP=FPARAB(ZA,Y1,Y2,Y3,Z1,Z2,Z3)
*     CHI=CHI+(YF-YP)**2/(0.10)**2                                                                            
******ADDED   IOS   16/11/93**************************************                                            
C     CALCULATE MEAN PHI FOR PARABOLA                                                                         
******END ADD  16/11/93*******************************************                                            
C     FIT PHI-Z                                                                                               
      CALL FTLFTW(XX,YY,WP,IC,0,2,PS,PI,D1,D2,D3,D4)
C     FIT R-Z                                                                                                 
      CALL FTLFTW(XX,ZZ,WPP,IC,0,2,RS,RI,D1,D2,D3,D4)
C     PRINT1002,JJ,(YY(JJ)-PS*XX(JJ)-PI)**2*WP(JJ)**2,YY(JJ),DIFF                                             
      CALL SHS(500,0,CHIP)                                                                             
C     CHI FOR DRIFT RELATIVE TO PARABOLAE IN PHI-Z , R-Z                                                      
      PHI=FPARAB(ZED,PPP(1),PPP(2),PPP(3),
      RRP=FPARAB(ZED,RRR(1),RRR(2),RRR(3),
      CALL SHS(571,0,CHID)                                                                             
*     Remove Links with poor Chisq...  18/11/93                                                               
*                                                                                                             
*     II=LINK                                                                                                 
C     PRINT 1001,II,LNK(1,II),LNK(2,II),LNK(3,II),CHIL(II)                                                    
C     CALCULATE   A CURVATURE IN THE X,Y PLANE HENCE MOMENTUM                                                 
C     SS=SAGITTA SQUARED   USE R=L**2/(8*S)                                                                   
C     WORKS OK 1 GEV AND ABOVE. BELOW OVERESTIMATES P DUE TO                                                  
C     WRONG SLOPE PROBABLY                                                                                    
*     SS=(X2-0.5*(X1+X3))**2+(Y2-0.5*(Y1+Y3))**2                                                              
*     RAD=((X3-X1)**2+(Y3-Y1)**2)/(8.0*SQRT(SS))                                                              
*     TANT=(SQRT(X2**2+Y2**2)-SQRT(X1**2+Y1**2))/(Z2-Z1)                                                      
*     THET=ATAN(TANT)                                                                                         
*     TH(LINK)=THET                                                                                           
*     RAD=RAD/SIN(THET)                                                                                       
*     PP=12.*0.0002998*RAD                                                                                    
*     PH1=ATAN2(Y1,X1)                                                                                        
*     PH2=ATAN2(Y2,X2)                                                                                        
*    IF(PH1.LT.0.0)PH1=PH1+PI2                                                                                
*     IF(PH2.LT.0.0)PH2=PH2+PI2                                                                               
*     SIGN=1.0                                                                                                
*     DIFF=PH2-PH1                                                                                            
*     IF(DIFF.LT.-3.14)DIFF=DIFF+PI2                                                                          
*     IF(DIFF.GT.3.14)DIFF=DIFF-PI2                                                                           
*     IF(DIFF.GT.0.)SIGN=-1.                                                                                  
*     PP=PP*SIGN                                                                                              
C      IF(ABS(PP).LT.1.0)THEN                                                                                 
C      WRITE(*,*)' PP  XYZ 123 ',PP ,X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3                                               
C      WRITE(*,*)' SS LL**2  ',SQRT(SS),(X3-X1)**2+(Y3-Y1)**2                                                 
C      ENDIF                                                                                                  
*     PPP(LINK)=PP                                                                                            
C     NEW COMPARE SECTION                                                                                     
C     SELECT BEST                                                                                             
*      WRITE(*,*)' K ,CHI  ',K,CH(K),LNK(1,K),LNK(2,K),LNK(3,K)                                               
*      WRITE(*,*)' KB,CHIB ',KB,CHB                                                                           
C     COMPARE BEST WITH REMAINDER                                                                             
C     REMOVE LINK                                                                                             
*      WRITE(*,*)' REMOVE ',K                                                                                 
C     COMPARE FINISHED , MARK BEST SEGMENT USED                                                               
C     RESET CHI WHEN COMPARE FINISHED                                                                         
C                                                                                                             
C                                                                                                             
C                                                                                                             
C     SET USED FLAG                                                                                           
C      PRINT 1000,I,LNK(1,I),LNK(2,I),LNK(3,I),CHIL(I)                                                        
C     PRINT 1000,I,(IPT(III,L1,1),III=1,12)                                                                   
C    1,(IPT(III,L2,2),III=1,12)                                                                               
C    1,(IPT(III,L3,3),III=1,12),CHIL(I)                                                                       
      CALL SHS(575,0,PROD )                                                                            
      CALL SHS(550,0,2.001)                                                                            
      CALL SHS(550,0,10.001)                                                                           
CIOS  CALL PLAFIT(TH)                                                                                         
*