FPOKEM COMMENTS
*-- Author :    Stephen J. Maxfield
      SUBROUTINE FPOKEM(NRUN0)
**----------------------------------------------------------------------                                      
*                                                                                                             
*--------------------------------------------------------------------                                         
*     Get number of events...                                                                                 
      CALL SAREA('FTREC', 0)                                                                           
      CALL GHSTAT('HS', 1, 0, NENT, SUMW, RNEFF, XST, YST)                                             
      CALL SAREA('FPOKE', 0)                                                                           
*     Book histograms...                                                                                      
      CALL BVEC(100, 0, 6)                                                                             
      CALL STEXT(100, 4,'D-time (scaled) vs. Dist(predicted)')                                         
*     Lorentz Angle stuff...                                                                                  
      CALL BVEC(7500, 0, 6)                                                                            
      CALL BHD(7501, 0, 100, -25., 25., 100, -25., 25.)                                                
      CALL STEXT(7501, 4,' Delta R-perp vs. Pred drift')                                               
*     Analyse the data.                                                                                       
*     ------- --- ----                                                                                        
*     Analysis of histogram results.                                                                          
*     Write(6,*) ' Fpkanl >> Begin peaks analysis...'                                                         
*     Do peakparm analysis of the pred drift histograms...                                                    
*      Get average predicted drift distance in the slice...                                                   
       CALL GHSTAT('HS', JHIS2, 0, NENT, SUMW, RNEFF, XST, YST)                                        
       CALL HPEAK('HS',JHIS1, 0, NPK, PDAT)                                                            
*          peak position and error on...                                                                      
*          comment out next line for 'full width errors'                                                      
*          Hence Drift distance vs. drift time:-                                                              
           CALL SVEC(100, 0, CVEC)                                                                     
*      Now purge figures - no longer needed.                                                                  
       CALL PURGEF(JHIS1)                                                                              
       CALL PURGEF(JHIS2)                                                                              
*     Lorentz Angle stuff...                                                                                  
*      Get average predicted drift distance in the slice...                                                   
       CALL GHSTAT('HS', JHIS2, 0, NENT, SUMW, RNEFF, XST, YST)                                        
*      Write(6,*) KBIN, NENT, DMAV                                                                            
       CALL HPEAK('HS',JHIS1, 0, NPK, PDAT)                                                            
*          peak position and error on...                                                                      
*          comment out next line for 'full width errors'                                                      
*          Hence Delta R vs. predicted drift...                                                               
           CALL SVEC(7500, 0, CVEC)                                                                    
*     Extraction of calibration data. Not for online at moment...                                             
*     Now fit the drift stuff to two straight lines...                                                        
*     Set x-ranges.                                                                                           
      CALL SAREA('FPOKE', 0)                                                                           
      CALL LKFPAR (2,PAR,PMIN,PMAX,IERR)                                                               
      CALL LKFITY(KKHIS, 0, 1, XMI, XMA, 'P1', IERRP)                                                  
      CALL LKFGET(IFLAG,CHIS,NPT,NPAR,PAR,EPAR,COV)                                                    
      CALL LKFPAR (2,PAR,PMIN,PMAX,IERR)                                                               
      CALL LKFITY(KKHIS, 0, 2, -XMA, -XMI, 'P1', IERRM)                                                
      CALL LKFGET(IFLAG,CHIS,NPT,NPAR,PAR,EPAR,COV)                                                    
*     Compute mean of +/- sides and F0R8 value...                                                             
*     ( entry in f0r8 bank is 10**-4 times this)                                                              
*     Fit the Lorentz Angle data...                                                                           
*                                                                                                             
*     Set x-ranges...                                                                                         
      CALL LKFPAR (2,PAR,PMIN,PMAX,IERR)                                                               
      CALL LKFITY(7500, 0, 1, XMI, XMA, 'P1', IERRL)                                                   
      CALL LKFGET(IFLAG,CHIS,NPT,NPAR,PAR,EPAR,COV)                                                    
*     Set some attributes...                                                                                  
*     CALL SATTR('VEC',7500,0,'full curv')                                                                    
*     Output to history n-tuple.                                                                              
        CALL SAREA('FPOKER',0)                                                                         
*     Fill Ntuples...                                                                                         
      CALL SVEC(1, 0, AVEC)                                                                            
      CALL SVEC(2, 0, AVEC)                                                                            
      CALL SVEC(3, 0, AVEC)                                                                            
      CALL SVEC(4, 0, AVEC)                                                                            
*-------------------------------------------------------------                                                
*                                                                                                             
* Normalised Wiebull Function                                                                                 
* P(1) = area                                                                                                 
* P(2) = x-position of the maximum [1050.0]                                                                   
* P(3) = decay parameter [2.5]                                                                                
* P(4) = x-threshold [1000.0]                                                                                 
* The values in [square] brackets are for typical Planar back-edge DOS.                                       
* JVM 24/4/95