;+ ;FUNCTION: m_4d(dat,ENERGY=en,ERANGE=er,EBINS=ebins,ANGLE=an,ARANGE=ar,BINS=bins,MASS=ms,m_int=mi,q=q,mincnt=mincnt) ;INPUT: ; dat: structure, 4d data structure filled by themis routines mvn_sta_c6.pro, mvn_sta_d0.pro, etc. ;KEYWORDS ; ENERGY: fltarr(2), optional, min,max energy range for integration ; ERANGE: fltarr(2), optional, min,max energy bin numbers for integration ; EBINS: bytarr(na), optional, energy bins array for integration ; 0,1=exclude,include, ; na = dat.nenergy ; ANGLE: fltarr(2,2), optional, angle range for integration ; theta min,max (0,0),(1,0) -901. ; the minus 0.1 helps account for straggling at low mass endelse mass=dat.mass*dat.mass_arr ;if keyword_set(mincnt) then if total(data) lt mincnt then return,mom_ten if keyword_set(mincnt) then if total(data-bkg) lt mincnt then return, mom_ten if total(data-bkg) lt 1 then return, mom_ten dat.cnts=data dat.bkg=bkg dat = conv_units(dat,"df") ; Use distribution function data=dat.data Const = (1.d*mass)^(-1.5)*(2.)^1.5 charge=dat.charge if keyword_set(q) then charge=q energy=(dat.energy+charge*dat.sc_pot/abs(charge))>0. ; energy/charge analyzer, require positive energy th1=theta-dtheta/2. th2=theta+dtheta/2. ph1=phi-dphi/2. ph2=phi+dphi/2. cth1 = cos(th1) cth2 = cos(th2) sth1 = sin(th1) sth2 = sin(th2) cph1 = cos(ph1) cph2 = cos(ph2) sph1 = sin(ph1) sph2 = sin(ph2) s_2ph1 = sin(2.*ph1) s_2ph2 = sin(2.*ph2) s2_ph1 = sph1^2 s2_ph2 = sph2^2 s3_th1 = sth1^3 s3_th2 = sth2^3 c3_th1 = cth1^3 c3_th2 = cth2^3 if dat.nbins eq 1 then begin m4dxx = total(Const*denergy*(energy^(1.5))*data*((ph2-ph1)/2.+(s_2ph2-s_2ph1)/4.)*(sth2-sth1-(s3_th2-s3_th1)/3.),1) m4dyy = total(Const*denergy*(energy^(1.5))*data*((ph2-ph1)/2.-(s_2ph2-s_2ph1)/4.)*(sth2-sth1-(s3_th2-s3_th1)/3.),1) m4dzz = total(Const*denergy*(energy^(1.5))*data*dphi*(s3_th2-s3_th1)/3.,1) m4dxy = total(Const*denergy*(energy^(1.5))*data*((s2_ph2-s2_ph1)/2.)*(sth2-sth1-(s3_th2-s3_th1)/3.),1) m4dxz = total(Const*denergy*(energy^(1.5))*data*(sph2-sph1)*((c3_th1-c3_th2)/3.),1) m4dyz = total(Const*denergy*(energy^(1.5))*data*(cph1-cph2)*((c3_th1-c3_th2)/3.),1) endif else begin m4dxx = total(total(Const*denergy*(energy^(1.5))*data*((ph2-ph1)/2.+(s_2ph2-s_2ph1)/4.)*(sth2-sth1-(s3_th2-s3_th1)/3.),1),1) m4dyy = total(total(Const*denergy*(energy^(1.5))*data*((ph2-ph1)/2.-(s_2ph2-s_2ph1)/4.)*(sth2-sth1-(s3_th2-s3_th1)/3.),1),1) m4dzz = total(total(Const*denergy*(energy^(1.5))*data*dphi*(s3_th2-s3_th1)/3.,1),1) m4dxy = total(total(Const*denergy*(energy^(1.5))*data*((s2_ph2-s2_ph1)/2.)*(sth2-sth1-(s3_th2-s3_th1)/3.),1),1) m4dxz = total(total(Const*denergy*(energy^(1.5))*data*(sph2-sph1)*((c3_th1-c3_th2)/3.),1),1) m4dyz = total(total(Const*denergy*(energy^(1.5))*data*(cph1-cph2)*((c3_th1-c3_th2)/3.),1),1) endelse if keyword_set(ms) then begin m4dxx = total(m4dxx) m4dyy = total(m4dyy) m4dzz = total(m4dzz) m4dxy = total(m4dxy) m4dxz = total(m4dxz) m4dyz = total(m4dyz) endif ; Momentum tensor M is in units of eV/cm^3, Pressure P = M - mass*vel*flux/1.e10 return, transpose([[m4dxx],[m4dyy],[m4dzz],[m4dxy],[m4dxz],[m4dyz]]) end