      REAL FUNCTION smear_had(ehad,iPart,part_mass_true)
c smears energy for a particle
#include "ntuple.inc"
#include "hb_common.inc"
      real pro_mass/0.9383/
      real smrhad_c/0.1327/
      real smrhad_e/0.2829/
      real smr_theta_c/0.70568/
      real smr_theta_t/0.0076756/
      real smr_sinth_c/0.43628/
      real smr_sinth_t/0.73588/
      real smr_vtx_c/1.23787/
      real smr_vtx_v/-0.0024773/
      real dir(3)
c
c ****************
c
      smr_had=0
      if(ehad-part_mass_true.ge.0.001)then
        smr_had = (ehad-part_mass_true)*smrhad_c
     1     +smrhad_e*sqrt(ehad-part_mass_true)
      endif
c need the theta dependence
c do default
      if(iPart.eq.0)then      
       smear_ang = smr_theta_c
      else
       dir(1) = startdir(1,iPart) ! reconstructed angles
       dir(2) = startdir(2,iPart)
       dir(3) = startdir(3,iPart)
       veclength = sqrt(dir(1)**2+dir(2)**2+dir(3)**2)
       if (veclength.gt.0) then
        cos_angle = startdir(3,iPart)/veclength
        sin_angle = sqrt(dir(1)**2+dir(2)**2)/veclength
        angle = acos(cos_angle)*180./3.141592654
        if(angle.le.30)then
         smear_ang = smr_theta_c+smr_theta_t*angle
        else
         smear_ang = smr_sinth_c+smr_sinth_t*sin_angle
        endif   
       endif
      endif 
c now need the vertex dependence
      CentralU =-138.25000
      CentralD = 89.75000
      if(iPart.eq.0)then      
        xL = (CentralD - CentralU)/2.
      else
       zv = startpos(3,iPart)
       xL = CentralD - zv ! I think this is what Jaewon wants
      endif
      smear_zvtx = smr_vtx_c+smr_vtx_v*xL
      smear_had=smr_had*smear_ang*smear_zvtx 
      n_wrt=nwrt ! print varibles from "hb_common.inc"
       if(nev.le.n_wrt)then 
       write(6,290)iPart
290    format(' In smear_had, iPart = ',i2)
       write(6,300)ehad,smear_had,smr_had,smear_ang,smear_zvtx
300    format(' ehad = ',f8.4,' smear_had = ',f7.4,' smr_had = ',f7.4 
     1 ,' smear_ang = ',f7.4,' smear_zvtx = ',f7.4 ) 
       write(6,310)ehad,ipart,angle,sin_angle,xL,part_mass_true
310    format(' ehad = ',f7.4,' ipart = ',i4,' angle = '
     1 ,f7.4,' sin_angle = ',f7.4,' xL = ',f8.2,' part_mass_true = ',f7.4)
       write(6,320)
320    format(' end of  smear_had')
      endif
      return
      end
