SUBROUTINE FKHBK
*-- Author : Stephen Burke
      SUBROUTINE FKHBK
*-----------------------------------------Updates 24/01/92-------                                             
**: FKHBK 30205.SB.  Phi histograms added.                                                                    
*-----------------------------------------Updates----------------                                             
**********************************************************************                                        
*                                                                    *                                        
* Book diagnostic histograms                                         *                                        
*                                                                    *                                        
**********************************************************************                                        
                                                                        
*KEEP,FKNPL.                                                                                                  
      CHARACTER*5 CKDBG                                                 
      PARAMETER (CKDBG='FKDBG')                                         
      PARAMETER (NPL=72)                                                
      LOGICAL LTRUE,LFIRST,LTRPL,LTRPLD                                 
      DOUBLE PRECISION TRUE,RTRUE,CHITRU,SPRO,CPRO,SFIL,CFIL            
     &,                SSMT,CSMT,SSMTR,CSMTR,DPRO,CBPRO,QPRO,QGAIN      
     &,                RPRO,CRPRO,RFIL,CRFIL,RSMT,CRSMT,CHIFIL,CHISMT   
*                                                                                                             
* Per-track values can go in H1WORK; note that LTRUE and LFIRST must                                          
* be set at least per event.                                                                                  
*                                                                                                             
* This is about 36k words long; the remaining common blocks are                                               
* about 3.6k in total. Some of this could be in /H1WORK/, but the                                             
* blocks would have to be reorganised.                                                                        
*                                                                                                             
      COMMON /H1WORK/                                                   
* /FKPROJ/                                                                                                    
     &                SPRO(5,NPL),CPRO(5,5,NPL)                         
* /FKFILT/                                                                                                    
     &,               SFIL(5,NPL),CFIL(5,5,NPL)                         
* /FKSMTH/                                                                                                    
     &,               SSMT(5,NPL),CSMT(5,5,NPL)                         
     &,               SSMTR(5,NPL),CSMTR(5,5,NPL)                       
* /FKINT/                                                                                                     
     &,               DPRO(5,5,NPL),CBPRO(5,5,NPL),QPRO(5,5,NPL)        
     &,               QGAIN(5,5,NPL),IAPROX,LFIRST                      
* /FKRSID/                                                                                                    
     &,               RPRO(2,NPL),CRPRO(2,2,NPL),RFIL(2,NPL)            
     &,               CRFIL(2,2,NPL),RSMT(2,NPL),CRSMT(2,2,NPL)         
     &,               CHIFIL(NPL),CHISMT(NPL)                           
* /FKTRUE/                                                                                                    
     &,               TRUE(5,NPL),RTRUE(5,NPL),CHITRU(NPL),LTRUE        
* /FKDBG/                                                                                                     
     &,               LTRPL(NPL),LTRPLD(NPL)                            
*KEEP,FFSTEE.                                                                                                 
      PARAMETER (NFT=72)                                                
      LOGICAL LRISV,LWMAP,LGRAPH,LTRUTH                                 
      REAL DSX,DSY,DSQOP,DSTTH,DSPHI,PMCUT,PCUT,CHPCUT                  
     &,    QOPMAX,THEMAX,RFTMIN,RFTMAX,CEMAX                            
      COMMON /FFSTEE/ DSX,DSY,DSQOP,DSTTH,DSPHI                         
     &,               PMCUT,IDIAG,JPLRSV,LRISV,LWMAP(NFT),JPLMAX        
     &,               IRP(NPL),JPLFT(NPL),JFTPL(NFT)                    
     &,               LUNGKS,IWKGKS,IDGKS,LUNHB,LUNGKM,IWKGKM,IDGKM     
     &,               LGRAPH,LTRUTH,IHFF,IHFK,ISRJCT,PCUT,CHPCUT        
     &,               QOPMAX,THEMAX,RFTMIN,RFTMAX,CEMAX                 
*KEEP,FKFLAG.                                                                                                 
      LOGICAL LPRO,LFIL,LSMT,LMES,LRAD,LRPRO,LRFIL,LRSMT,LPOINT,LBLOCK  
      COMMON /FKFLAG/ LPRO(NPL),LFIL(NPL),LSMT(NPL),LMES(NPL)           
     &,               LRAD(NPL),LRPRO,LRFIL,LRSMT,LPOINT,LBLOCK         
*KEEP,FKTRUE.                                                                                                 
*KEEP,FKHIST.                                                                                                 
      DIMENSION IPLANE(12)                                              
      SAVE IPLANE                                                       
      DATA IPLANE/1,12,13,24,25,36,37,48,49,60,61,72/                   
*KEEP,FKDBG.                                                                                                  
*KEND.                                                                                                        
                                                                        
**********************************************************************                                        
                                                                        
      CALL HCDIR('//PAWC',' ')                                                                         
      CALL HMDIR(CKDBG,'S')                                                                            
                                                                        
* Decode steering                                                                                             
      IDIFF = MOD(IHFK,10)                                              
      IRES  = MOD(IHFK/10,10)                                           
      IPLN  = MOD(IHFK/100,10)                                          
                                                                        
      LRSMT = .TRUE.                                                    
                                                                        
      IF (LTRUTH .AND. IDIFF.GT.0) THEN                                 
         CALL HBOOK1(101,'PULL ON X$',60,-6.,6.,0.)                                                    
         CALL HBOOK1(102,'PULL ON Y$',60,-6.,6.,0.)                                                    
         CALL HBOOK1(103,'PULL ON Q/P$',60,-6.,6.,0.)                                                  
         CALL HBOOK1(104,'PULL ON TAN(THETA)$',60,-6.,6.,0.)                                           
         CALL HBOOK1(105,'PULL ON PHI$',60,-6.,6.,0.)                                                  
         CALL HBOOK2(230,'DELTA(1/P) VS NSEG (LOW p)$',10,0.,10.,                                      
     &               100,-1.0,1.0,0.)                                   
         CALL HBOOK2(231,'DELTA(1/P) VS NSEG (MED P)$',10,0.,10.,                                      
     &               100,-1.0,1.0,0.)                                   
         CALL HBOOK2(232,'DELTA(1/P) VS NSEG (HIGH P)$',10,0.,10.,                                     
     &               100,-1.0,1.0,0.)                                   
         CALL HBOOK2(233,'DELTA(1/P) VS LOG(P)$',60,-3.,3.,                                            
     &               100,-1.0,1.0,0.)                                   
         CALL HBOOK2(234,'DELTA(THETA) VS LOG(P)$',60,-3.,3.,                                          
     &               60,-0.06,0.06,0.)                                  
         CALL HBOOK2(235,'DELTA(PHI) VS LOG(P)$',60,-3.,3.,                                            
     &               60,-0.06,0.06,0.)                                  
         CALL HBOOK2(243,'DELTA(1/P) VS THETA$',80,0.,0.4,                                             
     &               60,-0.6,0.6,0.)                                    
         CALL HBOOK2(244,'DELTA(THETA) VS THETA$',80,0.,0.4,                                           
     &               60,-0.06,0.06,0.)                                  
         CALL HBOOK2(245,'DELTA(PHI) VS THETA$',80,0.,0.4,                                             
     &               60,-0.06,0.06,0.)                                  
         CALL HBOOK2(253,'DELTA(1/P) VS PHI$',64,0.,6.4,                                               
     &               60,-0.6,0.6,0.)                                    
         CALL HBOOK2(254,'DELTA(THETA) VS PHI$',64,0.,6.4,                                             
     &               60,-0.06,0.06,0.)                                  
         CALL HBOOK2(255,'DELTA(PHI) VS PHI$',64,0.,6.4,                                               
     &               60,-0.06,0.06,0.)                                  
      ENDIF                                                             
                                                                        
      IF (IRES.GT.0) THEN                                               
         CALL HBOOK1(301,'DRIFT RESID FOR OLD TRUE POINTS (PLANAR)$'                                   
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(305,'CHISQ FOR OLD TRUE POINTS (PLANAR)$'                                         
     &,              100,0.,10.,0.)                                     
         CALL HBOOK1(306,'DRIFT RESID FOR OLD TRUE POINTS (RADIAL)$'                                   
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(307,'RADIUS RESID FOR OLD TRUE POINTS (RADIAL)$'                                  
     &,              100,-25.,25.,0.)                                   
         CALL HBOOK1(310,'CHISQ FOR OLD TRUE POINTS (RADIAL)$'                                         
     &,              100,0.,10.,0.)                                     
      ENDIF                                                             
                                                                        
      IF (LTRUTH .AND. IRES.GT.0) THEN                                  
         CALL HBOOK1(311,'DRIFT RESID FOR OLD WRONG POINTS (PLANAR)$'                                  
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(315,'CHISQ FOR OLD WRONG POINTS (PLANAR)$'                                        
     &,              100,0.,10.,0.)                                     
         CALL HBOOK1(316,'DRIFT RESID FOR OLD WRONG POINTS (RADIAL)$'                                  
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(317,'RADIUS RESID FOR OLD WRONG POINTS (RADIAL)$'                                 
     &,              100,-25.,25.,0.)                                   
         CALL HBOOK1(320,'CHISQ FOR OLD WRONG POINTS (RADIAL)$'                                        
     &,              100,0.,10.,0.)                                     
      ENDIF                                                             
                                                                        
      IF (LPOINT .AND. IRES.GT.0) THEN                                  
         CALL HBOOK1(321,'DRIFT RESID FOR NEW TRUE POINTS (PLANAR)$'                                   
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(325,'CHISQ FOR NEW TRUE POINTS (PLANAR)$'                                         
     &,              100,0.,10.,0.)                                     
         CALL HBOOK1(326,'DRIFT RESID FOR NEW TRUE POINTS (RADIAL)$'                                   
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(327,'RADIUS RESID FOR NEW TRUE POINTS (RADIAL)$'                                  
     &,              100,-25.,25.,0.)                                   
         CALL HBOOK1(330,'CHISQ FOR NEW TRUE POINTS (RADIAL)$'                                         
     &,              100,0.,10.,0.)                                     
      ENDIF                                                             
                                                                        
      IF (LPOINT .AND. LTRUTH .AND. IRES.GT.0) THEN                     
         CALL HBOOK1(331,'DRIFT RESID FOR NEW WRONG POINTS (PLANAR)$'                                  
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(335,'CHISQ FOR NEW WRONG POINTS (PLANAR)$'                                        
     &,              100,0.,10.,0.)                                     
         CALL HBOOK1(336,'DRIFT RESID FOR NEW WRONG POINTS (RADIAL)$'                                  
     &,              100,-0.25,0.25,0.)                                 
         CALL HBOOK1(337,'RADIUS RESID FOR NEW WRONG POINTS (RADIAL)$'                                 
     &,              100,-25.,25.,0.)                                   
         CALL HBOOK1(340,'CHISQ FOR NEW WRONG POINTS (RADIAL)$'                                        
     &,              100,0.,10.,0.)                                     
      ENDIF                                                             
                                                                        
      IF (IPLN.GT.0) THEN                                               
         LRFIL = .TRUE.                                                 
         DO 100 I=1,12                                                  
            IPL = IPLANE(I)                                             
            CALL HBOOK1(IPL+500,'FILTERED PROB$',100,0.,1.,0.)                                         
            CALL HBOOK1(IPL+600,'SMOOTHED PROB$',100,0.,1.,0.)                                         
            IF (LTRUTH) CALL HBOOK1(IPL+700,'SMOOTHED PROB (TRUE)$'                                    
     &,                             100,0.,1.,0.)                       
            CALL HBOOK1(IPL+800,'DRIFT RESIDUALS$',100,-0.1,0.1,0.)                                    
            CALL HBOOK1(IPL+900,'RADIAL RESIDUALS$',100,-10.,10.,0.)                                   
 100     CONTINUE                                                       
      ENDIF                                                             
                                                                        
      CALL HBPRO(0,0.)                                                                                 
      CALL HMINIM(0,0.)                                                                                
      CALL HIDOPT(0,'INTE')                                                                            
                                                                        
      CALL HCDIR('//PAWC',' ')                                                                         
                                                                        
      RETURN                                                            
      END                                                               
*