FVXTRP COMMENTS
*-- Author :    Stephen Burke   07/05/92
      SUBROUTINE FVXTRP(FTVEC,ZNOM,LPRIM,Z0,WZ0,IERR)
*-----------------------------------------Updates 07/09/93-------                                             
**: FVXTRP 40000 SB. Fix bug in xy vertex histos.                                                             
*-----------------------------------------Updates 26/07/93-------                                             
**: FVXTRP 30907 SB. Change monitoring histograms.                                                            
**: FVXTRP 30907 RP. Farm changes.                                                                            
*-----------------------------------------Updates 30/10/92-------                                             
**: FVXTRP 30907 SB. Separate cut on # of radial and planar hits.                                             
**: FVXTRP 30907 SB. New debug histograms and numbers.                                                        
*-----------------------------------------Updates 03/08/92-------                                             
**: FVXTRP 30907 SB. Redundant calls to FKNORM removed.                                                       
*-----------------------------------------Updates 29/07/92-------                                             
**: FVXTRP 30907 SB. Serious bugs fixed; xy histogram added.                                                  
*-----------------------------------------Updates 02/06/92-------                                             
**: FVXTRP 30907 SB. Protect against divide by 0.                                                             
*-----------------------------------------Updates 06/05/92-------                                             
**: FVXTRP 30907 SB. New deck to extrapolate tracks to vertex.                                                
*-----------------------------------------Updates----------------                                             
**********************************************************************                                        
*                                                                    *                                        
* Extrapolate a forward track to the vertex region, and return z0    *                                        
*                                                                    *                                        
* ERROR CONDITIONS;                                                  *                                        
*       IERR =        0 ; normal termination                         *                                        
*   ->  IERR =      101 ; parameters not at track start (code error) *                                        
*       IERR =        2 ; too few hits                               *                                        
*       IERR =        3 ; initial z0 too large                       *                                        
*       IERR =        4 ; momentum too small                         *                                        
*       IERR =        5 ; too far from xy vertex (dca)               *                                        
*       IERR =        6 ; too far from xy vertex (z0)                *                                        
*                                                                    *                                        
*   ->  Fatal errors                                                 *                                        
*                                                                    *                                        
* The output parameters are undefined after an error.                *                                        
*                                                                    *                                        
* INPUT;                                                             *                                        
*       FTVEC - FT-type (parameterisation 2) track vector            *                                        
*       ZNOM  - the nominal z-vertex position                        *                                        
*       LPRIM - .TRUE. if track is a primary (used for diagnostics)  *                                        
*                                                                    *                                        
* OUTPUT;                                                            *                                        
*       Z0    - z0 of extrapolated track                             *                                        
*       WZ0   - 1/(error on z0)**2                                   *                                        
*                                                                    *                                        
**********************************************************************                                        
*KEEP,FKPIDP.                                                                                                 
*KEEP,FVSTEE.                                                                                                 
*KEEP,FVPAR.                                                                                                  
*KEEP,FVSCAL.                                                                                                 
* Various counters                                                                                            
*KEEP,BCS.                                                                                                    
*KEND.                                                                                                        
**********************************************************************                                        
      CALL UCOPY(FTVEC(19),NX,1)                                                                       
         CALL ERRLOG(541,'F:FVXTRP: Not a starting parameterisation')                                  
*                                                                                                             
* Initial selection criteria                                                                                  
*                                                                                                             
      CALL UCOPY(FTVEC(20),NHIT,1)                                                                     
*                                                                                                             
* This is supposed to be a rough (straight line) estimate of the                                              
* z0, for a quick initial cut (was bugged, hope it's right now)                                               
*                                                                                                             
            CALL HFILL(201,FLOAT(NPLAN),0.,1.)                                                         
            CALL HFILL(203,FLOAT(NRAD),0.,1.)                                                          
            CALL HFILL(205,ZSQ,0.,1.)                                                                  
            CALL HFILL(202,FLOAT(NPLAN),0.,1.)                                                         
            CALL HFILL(204,FLOAT(NRAD),0.,1.)                                                          
            CALL HFILL(206,ZSQ,0.,1.)                                                                  
* Allow for a relative rotation/shift between CT and FT                                                       
      CALL KTROT(FTVEC,FTROT)                                                                          
* Convert into KF internal format                                                                             
      CALL FKETOI(FTROT,S1,C1)
      IF (LCUT .AND. LPRIM) CALL HFILL(207,PMOM,0.,1.)                                                 
      IF (LCUT .AND. .NOT.LPRIM) CALL HFILL(208,PMOM,0.,1.)                                            
* Swim to end wall                                                                                            
      CALL FKTRAN(DZ,Z,S1,S2,DTRAN)
      CALL FKMUL(C1,DTRAN,C2)
* Allow for multiple scattering in the end wall                                                               
      CALL FKTRAN(DZ,ZWALL2,S2,S1,DTRAN)
      CALL FKMUL(C2,DTRAN,C1)
      CALL FKSCAT(DZ,S2,RADLEN,DTRAN,QMS)
      CALL FKQADD(C1,QMS)
* Swim to (notional) vertex                                                                                   
      CALL FKTRAN(DZ,ZWALL1,S1,S2,DTRAN)
      CALL FKMUL(C1,DTRAN,C2)
* Convert to external (IPTYPE 2) format                                                                       
      CALL KTITOE(DBLE(ZNOM),S2,C2,S1,C1)                                                              
* Convert to IPTYPE 1 format                                                                                  
      CALL KTFTCT(S1,C1,DBLE(ZNOM),CTV,CTC)                                                            
            CALL HFILL(209,DCA,0.,1.)                                                                  
            CALL HFILL(211,Z0,0.,1.)                                                                   
            CALL HFILL(210,DCA,0.,1.)                                                                  
            CALL HFILL(212,Z0,0.,1.)                                                                   
* Fill monitoring histograms                                                                                  
      CALL SHS(26,0,DCA)                                                                               
      CALL SHS(27,0,Z0)                                                                                
*                                                                                                             
* Monitor the xy-vertex                                                                                       
*                                                                                                             
      CALL FKTRAN(DZ,DBLE(ZNOM),S2,S1,DTRAN)
            CALL SHS(30,0,SNGL(S1(1)))                                                                 
            CALL SHS(31,0,SNGL(S1(1)))                                                                 
            CALL SHS(32,0,SNGL(S1(1)))                                                                 
            CALL SHS(33,0,SNGL(S1(2)))                                                                 
            CALL SHS(34,0,SNGL(S1(2)))                                                                 
            CALL SHS(35,0,SNGL(S1(2)))                                                                 
*