FTLSEG COMMENTS
*-- Author : I.O. Skillicorn
      SUBROUTINE FTLSEG(NSS,IM)
**: FTLSEG 40000 SM. New monitoring histos.                                                                   
**----------------------------------------------------------------------                                      
C     AUTHOR:      I.O.SKILLICORN                                                                             
*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,FSGPAR.                                                                                                 
*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...)                                       
*KEND.                                                                                                        
*    LOCAL ARRAYS                                                                                             
*                                                                                                             
C     MODS 13/5/91 FOLLOW TO SAVE SPACE   VVVVVVVVVVVVVVVVVVVVVVVVV                                           
C     ADD                                                                                                     
C                                                                                                             
CEND ADDITION  ********************************************                                                   
*                                                                                                             
*     >  Chard                                                                                                
*     Hard-wired cuts if wanted, else take from COMMON/FSGPAR/ filled                                         
*     by FPTINT from the FRCP bank.                                                                           
*                                                                                                             
C     MINIMUM SIZE OF CLUSTER FOR STARTING TRIPLE       FINDING                                               
Chard MINHTS=3                                                                                                
C     MINIMUM NUMBER OF POINTS/TRACK SEGMENT                                                                  
Chard MINPTS=4                                                                                                
*     but keep this to avoid array size problems!!                                                            
C     MAX SIZE OF CLUSTER FOR ANALYSIS                                                                        
C                                                                                                             
Chard NWIRES= 8                                                                                               
C                                                                                                             
C                                                                                                             
C                                                                                                             
C***********************************************************************                                      
C     IPLOT=0 FOR NO DIAGNOSTIC T0, RMS TO LINE SEG,  PLOTS: MAX SPEED                                        
Chard IPLOT=0                                                                                                 
C***********************************************************************                                      
C                                                                                                             
C     WRITE(*,*)' NDP ',NDP                                                                                   
C     DO 4999 IP=1,36                                                                                         
C     DO 5000 I=1,NDP(IP)                                                                                     
C     WRITE(*,*)' DRI,RM,NW',DRI(I,IP),RM(I,IP),NW(I,IP),I,IP                                                 
C000  CONTINUE                                                                                                
C999  CONTINUE                                                                                                
C     ENSURE ONLY 1 HIT/WIRE - TAKE MIN DRIFT HIT                                                             
C     SAME WIRE - KILL LONGER  DRIFT                                                                          
C                                                                                                             
C     SUM WIRE HITS - ALL PLANES IN Z                                                                         
C     CLUSTER SIZE                                                                                            
C     I=NW(J,IP)+1                                                                                            
C     CHANGE 9/12/92                                                                                          
C     NOW HAVE STARTING CLUSTERS                                                                              
C     IWC= # HITS/WIRE                                                                                        
C     WRITE(*,*)' CLUSTERS '                                                                                  
C     PRINT 1000,IWC                                                                                          
C     CALL HFILL(70001,FLOAT(KK)+0.1,0.,1.)                                                                   
C     IRN = HIT #                                                                                             
CDEB  PRINT 1001,IM,I,(IRN(K,I),K=1,KK)                                                                       
C     IPN = PLANE #                                                                                           
C      PRINT 1002,IM,I,(IPN(K,I),K=1,KK)                                                                      
C     SEARCH FOR LARGEST CLUSTER                                                                              
C     IF(IC.NE.0)CALL HFILL(70002,FLOAT(MAXC)+0.1,0.,1.)                                                      
C     WRITE(*,*)' CLUSTER FOUND  IC,MAXC ',IC,MAXC                                                            
C     CHECK FOR SUFFICIENT POINTS FOR LARGEST CLUSTER                                                         
C     FINISHED FOR THIS MODULE                                                                                
CDEB  WRITE(*,*)' ANALYSE FOUND CLUSTER IC,MAXC ',IC,MAXC                                                     
C     CHECK MAX SIZE OF CLUSTER                                                                               
*                                                                                                             
*                                                                                                             
*     DIAGNOSTIC PLOTS FOR LOW MULTIPLICITY CLUSTERS ONLY                                                     
C                                                                                                             
      CALL FTLISA(IRN(1,1),IPN(1,1),IWC(1),IC,MAXC,NSS,IM,IDIAG)
C                                                                                                             
*                                                                                                             
*                                                                                                             
*     Make Tzero, Resolution and twin-peaks checksums.                                                        
C     PLANE #                                                                                                 
C     POINT #                                                                                                 
C     STORE FIRST WIRE NUMBER AND DRIFT SIGN                                                                  
C     KEEP TO SAME WIRE FOR DRIFT RESIDUAL                                                                    
C     SIGN CHANGE - STORE WIRE # AT FIRST CROSS                                                               
C     T0 DETERMINATION - 8 WIRES                                                                              
C     CHECK 4 WIRES                                                                                           
C     +++- AND ---+                                                                                           
C     SAME WIRE                                                                                               
*      T-zero...                                                                                              
C     +--- AND -+++                                                                                           
*      T-zero...                                                                                              
C     ++-- AND --++                                                                                           
C     CALL HFILL(90005,TZV,0.,1.)                                                                             
C     IF(TZV.GT.0.0)CALL HFILL(90015,TZV,0.,1.)                                                               
C     ++++ AND ----                                                                                           
*                                                                                                             
*      Twin peaks...                                                                                          
*      Resolution...                                                                                          
C     T0 DETERMINATION - 8 WIRES                                                                              
C     CHECK 5 WIRES TO ENSURE SAFE SIGN CHANGE 13/8/91                                                        
C     +++-- AND ---++                                                                                         
C     SAME WIRE                                                                                               
C     CALL HFILL(90004,TZ,0.,1.)                                                                              
C     ++--- AND --+++                                                                                         
C     CALL HFILL(90004,TZ,0.,1.)                                                                              
C     NO SIGN CHANGE                                                                                          
C     IF(LL.GE.4.AND.NCR.EQ.0)CALLHFILL(90002,0.01,0.,1.)                                                     
C     SIGN CHANGE                                                                                             
C     IF(LL.GE.4.AND.NCR.NE.0)CALLHFILL(90002,WCROSS,0.,1.)                                                   
C     FIT STR. LINE TO SEGMENT IF 4 OR MORE POINTS                                                            
      CALL FTLFT(XX,YY,LL,0,AT,BT,EE)
      CALL FTLFT(XX,YN,LL,0,AR,BR,ER)
C      WRITE(*,*)' EE,ER',EE,ER                                                                               
C     RESIDUAL PLOT 18/7/92                                                                                   
C     CALL HFILL(90000,EE,0.,1.)                                                                              
C     CALL HFILL(90001,ER,0.,1.)                                                                              
C     RMS      TO LINE SEGMENT  DRIFT,RADIUS                                                                  
C      WRITE(*,*)' AT,XX(LL/2),BT',AT,XX(LL/2),BT,EE,ER                                                       
C     DRIFT AT CENTRE OF LINE SEG                                                                             
*                                                                                                             
*                                                                                                             
*   Small farm mod by ?                                                                                       
*   add SEQ BOSMDL so above might work                                                                        
*   initialise RR (else DDMIN*RR test might fail?                                                             
*                                                                                                             
C   21/01/93 301211908  MEMBER NAME  FTLISAA  (FILE46)      FVS                                               
C   06/01/93 301081132  MEMBER NAME  FTLISA5  (FILE46)      FVS                                               
C   08/12/92 301061503  MEMBER NAME  FTLISA2  (FILE46)      FVS                                               
C   06/12/92 212081044  MEMBER NAME  FTLISA   (GRAPHICS)    FVS                                               
C   04/12/92 212061354  MEMBER NAME  LISALIB  (FILE46)      FVS                                               
C   28/11/92 212011534  MEMBER NAME  FTLISA   (FILE46)      FVS                                               
C   28/11/92 211281327  MEMBER NAME  FTLISA   (GRAPHICS)    FVS                                               
C   13/11/92 211281108  MEMBER NAME  FTLSEGO  (GRAPHICS)    FVS                                               
C   13/11/92            MEMBER NAME  FTLSEGO  (FILE46)      FVS                                               
C   04/12/91            MEMBER NAME  NEWSEG   (FILE46)      FVS                                               
C   FROM FILE46(GRFTRAC2)                                                                                     
C                                                                                                             
C   13/11/92                                                                                                  
C   ADD SLOPE CHECK ON TRIPLES - SELECT MINIMUM SLOPE                                                         
C   REMOVE EXTRAPOLATION IN PHI                                                                               
C   RCUT --->  20 CMS                                                                                         
C   SLCUT--->  0.1                                                                                            
C   TSCUT--->  0.08 (WAS 0.1)                                                                                 
C   DMINX--->  0.15 (WAS 0.2)                                                                                 
C                                                                                                             
C   PROJECTION CUT WITH DMINX                                                                                 
C     VERSION FOR TRACK FINDING IN CLUSTER BY TRIPLES