      double precision function constraint(var,ndim,z,x1,x2,s13,s23,
     & s14,s24,s34,s1v,s2v,s3v,s4v,s1l1,s2l1,s3l1,s4l1,s1l2,s2l2,
     & s3l2,s4l2)
C      implicit double precision(a-h,o-z)
      implicit none
      INTEGER ndim
      double precision var(ndim)
      double precision z,x1,x2,s13,s23,s14,s24,s34,
     & s1v,s2v,s3v,s4v,s1l1,s2l1,s3l1,s4l1,s1l2,s2l2,
     & s3l2,s4l2

      double precision zn, s34n, s1vn, s2vn, s3vn, s4vn

      double precision rapu,rapd,pTu,pTd,m2,scm
      INTEGER gnjet

      double precision pi
      double precision aux, aux1, aux2
      
      double precision pt3, pt4, pT
      double precision En3, En4, En
      double precision pz3, pz4, pZ

      double precision Y, eta3, eta4
      double precision etar, ptr

      double precision ptbuf, topflag
      double precision photonflag 

      double precision cosr, cos3, cos4, cos34
      double precision phi3, phi4, phi34, phir
      
      double precision xlambda, B1, B2, Ome
      double precision FFF, Discr 
      double precision s2anorm, s2bnorm, s1anorm, s1bnorm
      double precision s2a, s2b, s1a, s1b
      double precision Ena, Enb, pza, pzb
      double precision ptga, ptgb, etaa, etab
      double precision cosa, cosb, phia, phib
      double precision djack

      double precision inactive, active

      double precision Rmax, ptveto, R34, ptjet
      double precision ptlead, ptfoll
      double precision Etmax, Risol
      double precision Rar, Rbr
      double precision Gamma, Gammagg
      double precision R3a, R3b, R4a, R4b
      double precision xlambda4
      double precision Ethada, Ethadb
      double precision pt34
      double precision etag1, etag2, ptg1, ptg2
      double precision phira, phirb, phi3a, phi3b, phi4a, phi4b

      double precision pt_sym, pt_sym_min, pt_sym_max
      double precision eta_diff, eta_diff_min, eta_diff_max
      double precision weight
      double precision pTmax, pTmin, Ymax, Ymin
      double precision ptg1m, ptg2m, etagM
      integer i,j
      double precision etal2,clab,ptl2,ptl1,ptw,ptdp,mT

      COMMON/const/ rapu,rapd,pTu,pTd,gnjet
      COMMON/params/ m2,scm
      COMMON/decay/ Gamma,Gammagg
      pi = 3.1415926536d0

CCC   Note that z should not be used to form constraints; it is used as the 
CCC   convolution variable also, not just the mass

      constraint=1.0d0

CCC   ptl2,etal2 are the lepton transverse momentum and pseudirapidity
CCC   ptl1 is the neutrino momentum
CCC   ptw is the W momentum      
CCC   mT is the transverse mass

      etal2 = 0.5d0*dlog(dabs(x1*s2l2/x2/s1l2))
      ptl2 = dsqrt(dabs(x1*x2*scm*s1l2*s2l2))
      ptl1 = dsqrt(dabs(x1*x2*scm*s1l1*s2l1))
      ptw = dsqrt(dabs((m2-x1*x2*scm*s1v)*(m2-x1*x2*scm*s2v)
     & /x1/x2/scm-m2))

CCC   Dot product between pte,ptv
      
      ptdp = 0.5d0*((s1l1*s2l2+s1l2*s2l1)*x1*x2*scm-m2)
      mT = dsqrt(dabs(2.0d0*(ptl1*ptl2-ptdp)))

CCC   Transverse mass cut
      
      if (mT.lt.(500.0d0)) then
         constraint = 0.0d0
      endif

CCC   Missing Et cut for forward, central

      if (ptl1.lt.(25.0d0)) then
         constraint = 0.0d0
      endif

CCC   Electron cuts central

      if ((ptl2.lt.(25.0d0)).or.(dabs(etal2).gt.(2.5d0))) then
         constraint = 0.0d0
      endif

CCC   Electron cuts forward
      
C      if ((ptl2.lt.(20.0d0)).or.(dabs(etal2).gt.(2.8d0))
c     &   .or.(dabs(etal2).lt.(1.2d0))) then
c         constraint = 0.0d0
c      endif

      END	
