FPFSEG COMMENTS
*-- Author :  R. Henderson
      SUBROUTINE FPFSEG(NSMLS)
**: FPFSEG.......SM. Add diagnostic histograms                                                                
C-------------------------------------------------------------                                                
C---                                                                                                          
C---                                                                                                          
*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---                                                                                                          
*KEND.                                                                                                        
C---                                                                                                          
*KEEP,FPLGEO.                                                                                                 
C---                                                                                                          
C---                                                                                                          
*KEND.                                                                                                        
C---                                                                                                          
*KEEP,FPCLUS.                                                                                                 
C---                                                                                                          
*KEND.                                                                                                        
C---                                                                                                          
*KEEP,FPH1WRK.                                                                                                
C--    *KEEP,FPCSEG.                                                                                          
C---                                                                                                          
C---                                                                                                          
C--    *KEEP,FPDIGI.                                                                                          
C---                                                                                                          
C--    *KEEP,FPDGI.                                                                                           
C---                                                                                                          
C--    *KEEP,FPSTID.                                                                                          
C---                                                                                                          
C--    *interface to real data                                                                                
C---.                                                                                                         
*KEND.                                                                                                        
C---                                                                                                          
*KEEP,FPLSEG.                                                                                                 
C---                                                                                                          
C---                                                                                                          
*KEND.                                                                                                        
C---                                                                                                          
C---                                                                                                          
C      DIMENSION IUCLU(50,9)                                                                                  
C---                                                                                                          
C                                                                                                             
C---  Set segment finding resolution cut                                                                      
C                                                                                                             
C                                                                                                             
C---  loop over all combinations of planes formed by clusters                                                 
C---  in each orientation per supermodule and                                                                 
C---  find any three which are coincident to within an                                                        
C---  arbitary tolerance acut                                                                                 
C                                                                                                             
C                                                                                                             
C---  Loop on supermodules                                                                                    
C                                                                                                             
C                                                                                                             
C---  Zero number of segments found                                                                           
C                                                                                                             
C                                                                                                             
C---  skip if less than three present                                                                         
C                                                                                                             
C                                                                                                             
C---  sort the segments according to their front face x values                                                
C                                                                                                             
C                                                                                                             
C---  call cern library routine to return sorted list                                                         
C---  their ascending order is stored in ioxfv                                                                
C                                                                                                             
     1     CALL SORTZV(XFV , IOXFV , NSMLS(ISM) , 1 , 0 , 0)                                           
C                                                                                                             
C---  Loop on tracks                                                                                          
C                                                                                                             
C                                                                                                             
C---  Second Plane                                                                                            
C                                                                                                             
C                                                                                                             
C---  Test 1/2 front x and then y and rear x then y projections                                               
C                                                                                                             
*     Call Hfill(403, DFX1, 0., 1.)                                                                           
*     Call Hfill(403, DFY1, 0., 1.)                                                                           
*     Call Hfill(403, DRX1, 0., 1.)                                                                           
*     Call Hfill(403, DRY1, 0., 1.)                                                                           
C                                                                                                             
C---  third plane                                                                                             
C                                                                                                             
C                                                                                                             
C---  Now test 1/3 x projection combinations                                                                  
C                                                                                                             
*     Call Hfill(403, DFX2, 0., 1.)                                                                           
C                                                                                                             
C---  In an ordered sequence this next tests adds nothing                                                     
C                                                                                                             
*      Call Hfill(403, DFX1, 0., 1.)                                                                          
C      if (ABS( dfx3) .gt. acut ) go to 20                                                                    
C                                                                                                             
C---  Now test front 1/3 and 2/3 y projection combinations                                                    
C                                                                                                             
*     Call Hfill(403, DFY2, 0., 1.)                                                                           
*     Call Hfill(403, DFY3, 0., 1.)                                                                           
C                                                                                                             
C---  Now test the rear 1/3 combinations                                                                      
C                                                                                                             
*     Call Hfill(403, DRX2, 0., 1.)                                                                           
*     Call Hfill(403, DRY2, 0., 1.)                                                                           
C                                                                                                             
C---  Now test the rear 2/3 combination                                                                       
C                                                                                                             
*     Call Hfill(403, DRX3, 0., 1.)                                                                           
*     Call Hfill(403, DRY3, 0., 1.)                                                                           
C                                                                                                             
C---  ensure that candiate segments have track/plane in common                                                
C                                                                                                             
C                                                                                                             
C---  ensure that track/plane assignments are self consistent                                                 
C                                                                                                             
C---  The diagram desribes the functioning of the                                                             
C---  following block of code. The brackets represent a candidate                                             
C---  line segment made from two candidate clusters each (  1 | 2  ).                                         
C---  That is id(1,1) etc.                                                                                    
C---  For the segment to be valid each of the three links must be in pla                                      
C---  The code finds the two outermost  links and remembers ipn1,ipn2                                         
C---  imn1,imn2 which constrain the final link.                                                               
C---                                                                                                          
C---                                                                                                          
C---                 (     |     )                                                                            
C---                  /         \                                                                             
C---                 /           \                                                                            
C---                /             \                                                                           
C---               /               \                                                                          
C---           (    |imn2)---(imn1|    )                                                                      
C---              ipn2          ipn1                                                                          
C                                                                                                             
C---                                                                                                          
C---                                                                                                          
C                                                                                                             
C---  the first track/plane id(1,1) not equal to any of the others rejec                                      
C                                                                                                             
C                                                                                                             
C---  the first track/plane link found                                                                        
C                                                                                                             
C                                                                                                             
C--- now find second link for a(1,2)                                                                          
C                                                                                                             
C                                                                                                             
C--- now test last remaining link                                                                             
C                                                                                                             
C                                                                                                             
C---  Now test absolute lengths                                                                               
C                                                                                                             
C                                                                                                             
C---  find the three yuv sets involved in this combination                                                    
C                                                                                                             
C                                                                                                             
C---  do direct lsq fit to yuv to give alternate parseg and errseg                                            
C                                                                                                             
      CALL FPFYUV(ID1,ID2,ID3,ISM,PCHI,CHISQ,NDF,PARSGN,ERRSGN)
C                                                                                                             
C---  end of loops                                                                                            
C                                                                                                             
C                                                                                                             
C---  Remove connectivity between segments                                                                    
C                                                                                                             
      CALL FPSGRF
*