        Subroutine ncor

C--------------------------------------------------------------
C 
C   Subroutine Ncor.f
c
C   This code only handle neutral track detected by  barrel shower counter. 
C
C   It is to correct energy and error matrix (errors of phi, z, energy) 
C   for a neutral track.
C   
C   Users are suggested to call this little code BEFORE event selection 
c   and kinematic fit. 
C
C   Input:  none
C   Output: all changes are saved in SUBTYPE 5 of TRKLST.
C   
C   Pls pay attention that TRKLST has been renewed when events logged out
C
C   IMPORTANT:
C   Z correction(0.9587) is determined by 
C   J/psi-->rhopi channel for correct pi0
C   peak,while I also found it almost 
C   needn't Z correction for J/psi-->
C   phi eta channel for eta peak,Z 
C   correction size is determined by 
C   neutral track energy scale,so its
C   size should be adjusted by users 
C   according to concerning neutral 
C   resonance peak position,take their 
C   own risk!
C
C   reference:
C   <<SUMMARY on BESII NEUTRAL CORRECTION>>
C          BES Monthly Meeting, 7/Sep. 2000  
C
C       LU Feng  Sep. 10, 2000
c     
c     LU Feng only give the correction for the BES2 data RUN13500-16844,
c     The correction for the BES2 data RUN17209-19149 have been done by
c                                  WANG Jun, YUAN JianMing, and XU GuoFa
c                                                              May, 2001
c
c    Since the Z and PHI correction for the RUN13500-16844 only include 
c    the data for momentum between 0.4GeV to 1.4(1.5485)GeV, I added 4 
c    points between 0.2GeV to 0.4GeV.
c                          XU GuoFa      Sept. 2001
C---------------------------------------------------------------

      INCLUDE 'trklst.inc'
      INCLUDE 'evlst.inc'

       real dphi, dz, de, xecor 
       integer i, isub5

       if(nneu.le.0) return

        do 999 I=nchrg+1, nchrg+nneu
        ISUB5= TRKSUB(5,I)
        IF(ISUB5.le.0) goto 999
        if(itrk(isub5+20).ne.1) goto 999   ! treat BSC track only

C DATA neutral tracks correction: run13500-16844

       if(irun.gt.0) then
cXU
       if (irun.ge.13500.and.irun.le.16844) then
cXU        
         
cxu        xecor=0.2277*trk(isub5+14)**2+0.6765*trk(isub5+14)
cxu     *        +0.0514
        xecor=0.051334 + 0.67934*trk(isub5+14)
     +        +0.22480*trk(isub5+14)**2

        trk(isub5+14)=xecor        ! corrected Energy

cxu        de=0.2342*sqrt(xecor)-0.001779
        de=0.23359*sqrt(xecor)-0.0010063
        trk(isub5+15)= de          ! corrected E Res.

cxu        dphi=2.174-3.446*xecor+2.573*xecor**2
cxu     +       -0.6918*xecor**3      ! corrected phi Res. in degree
        dphi=4.9427-16.314*xecor+23.562*xecor**2
     +       -15.081*xecor**3+3.5289*xecor**4 ! corrected phi Res. in degree
        dphi=dphi*3.1415926/180.   ! in rad.
        trk(isub5+13)= dphi

cxu        dz =19.07-37.49*xecor+35.24*xecor**2
cxu     +      -11.24*xecor**3        ! corrected Z Res. in cm
        dz =26.748-79.007*xecor+112.96*xecor**2
     +      -71.807*xecor**3+16.778*xecor**4   ! corrected Z Res. in cm
        dz=dz/100.0                  ! in meter
        trk(isub5+9) = dz

C  Z correction Adjust by users for certain channel  
C        trk(isub5+8) = trk(isub5+8)*0.9587        

cXU---------------------  Begin line --------------
       else if (irun.ge.17209.and.irun.le.19149) then
        xecor=0.19679*trk(isub5+14)**2+0.71488*trk(isub5+14)
     *        +0.045854
        trk(isub5+14)=xecor        ! corrected Energy

        de=0.21642*sqrt(xecor)-0.012987
        trk(isub5+15)= de          ! corrected E Res.

        dphi=5.1738-17.407*xecor+26.095*xecor**2
     +       -17.597*xecor**3+4.3879*xecor**4 ! corrected phi Res. in degree
        dphi=dphi*3.1415926/180.   ! in rad.
        trk(isub5+13)= dphi

        dz =28.476-88.026*xecor+130.78*xecor**2
     +      -86.042*xecor**3+20.720*xecor**4  ! corrected Z Res. in cm
        dz=dz/100.0                  ! in meter
        trk(isub5+9) = dz        

c        trk(isub5+8) = trk(isub5+8)*0.9587        

      end if
cXU-----------  End line --------------------------

C MC neutral tracks correction: REAL DEAD Ver. is 022  
c Done by LU Feng, no change.

cxu      if(irun.lt.0) then
       else 

        xecor=0.9874*trk(isub5+14)+0.01222        
        trk(isub5+14)= xecor          ! corrected E 

        de=0.2144*sqrt(xecor)-0.01208
        trk(isub5+15)= de*0.9          ! corrected E Res.

        dphi=0.8113-0.3317*xecor+0.09885*xecor**2 ! phi in degree
        dphi=dphi*3.1415926/180./1.414214
        trk(isub5+13)= dphi*0.92

        dz =7.18-0.8454*xecor+0.3096*xecor**2 ! Z Res. in cm
        dz=dz/141.4214
        trk(isub5+9) = dz*0.9        

      end if

999   continue

      return
      end


