Skip to content

Instantly share code, notes, and snippets.

@ggggggggg
Created January 27, 2015 22:52
Show Gist options
  • Save ggggggggg/1842639d3dc8c14a6d30 to your computer and use it in GitHub Desktop.
Save ggggggggg/1842639d3dc8c14a6d30 to your computer and use it in GitHub Desktop.
xray emission calculations
# see https://www.evernote.com/l/AHCKsZl_vf9Kx4r4YCt4M0iKF_3lD5qnhzs
# μₑfrac absoprtion coeffiecient due to the edge of interest, as a fraction of μt
# μt mu total for incident xrays
# μf mu total for fluoresced xray
# note that all 3 μ's are energy dependent
# θ angle of detector relative to sample surface
# ϕ angle of incident beam relative to sample surface
# t sample thickness
# ϵ probability of fluoresecnce given incident x-ray absorption
# A detector area
# r detector distance from sample, assumes accurate for r>>t
# returns something porportional to the ratio I_f/I_i where
# I_f is xrays/s at the detector and I_i is monochromatic x-rays/second incident on the sample
# the results are most meaningful when comparing two different setups, though
# if you provide accurate numbers for all inputs it may be reasonable accurate
# /
# -----------/\
# / \
# detector
abstract EmissionGemoThru
function emissionfraction(::Type{EmissionGemoThru},t; μₑfrac=1, μt=1, μf=1, θ=pi/2, ϕ=pi/2, ϵ=1, A=1, r=1)
a=μt/sin(ϕ)
b=μf/sin(θ)
prefactor = μt*μₑfrac*ϵ*A/(4*pi*r^2)
if isapprox(a,b)
prefactor*t.*exp(-a*t)
else
(prefactor/(b-a))*(exp(-a*t)-exp(-b*t))
end
end
# see http://journals.aps.org/prb/pdf/10.1103/PhysRevB.60.9335
# \
#-----------------\
# / \
# /
# detector
abstract EmissionGeomReflect
function emissionfraction(::Type{EmissionGeomReflect},t; μₑfrac=1, μt=1, μf=1, θ=pi/4, ϕ=pi/4, ϵ=1, A=1, r=1)
a=μt/sin(ϕ)
b=μf/sin(θ)
prefactor = μt*μₑfrac*ϵ*A/(4*pi*r^2)
prefactor*(1/(a+b))*(1-exp(-(a+b)*t))
end
using PyPlot
figure()
fes2_8500=261+79 # cm^2/gm
fes2_7060=54+134 # cm^2/gm
fes2_7150=402+130
fes2_10000=170+50
thruangle = 10
t = [0:100]*1e-4
plot(t*1e3, emissionfraction(EmissionGemoThru,t;μt=fes2_8500,μf=fes2_7060,ϕ=deg2rad(90-sampletilt),θ=deg2rad(90+thruangle-sampletilt)),label="8500 eV incident")
plot(t*1e3, emissionfraction(EmissionGemoThru,t;μt=fes2_7150,μf=fes2_7060,ϕ=deg2rad(90-sampletilt),θ=deg2rad(90+thruangle-sampletilt)),label="7150 eV")
plot(t*1e3, emissionfraction(EmissionGemoThru,t;μt=fes2_10000,μf=fes2_7060,ϕ=deg2rad(90-sampletilt),θ=deg2rad(90+thruangle-sampletilt)),label="10000 eV")
legend(loc="lower right")
xlabel("thickness * density (mg/cm^2)")
ylabel("relative x-ray emission at detector (Ein=8500 eV, Ef=7060 eV)")
title("FeS2 emission thru with detector 10 degreee of axis")
grid("on")
close("all")
t2 = [0:0.01:6]
for f = 0.1:0.3:2
ef=emissionfraction(EmissionGemoThru, t2;μt=f,μf=1,θ=deg2rad(90+thruangle))
plot(t2,ef,label="uf/ut="*@sprintf("%0.2f",1/f))
i = indmax(ef)
plot(t2[i], ef[i],"o")
end
title("optimal sample thicknesses")
xlabel("t*mu_f (absorption lengths of fluoresced x-rays)")
ylabel("relative emission counts")
grid("on")
legend()
close("all")
t2 = [0:0.01:20]
for f = 0.1:0.3:2
uf = 1
ut = f
ef=emissionfraction(EmissionGemoThru, t2;μt=ut,μf=ut,θ=deg2rad(90+thruangle))
plot(t2,ef,label=@sprintf("ut=%0.1f,uf=%0.1f", ut, uf))
i = indmax(ef)
plot(t2[i], ef[i],"o")
end
title("optimal sample thicknesses")
xlabel("t")
ylabel("relative emission counts")
grid("on")
legend()
# find the maximum thickness for an emission sample
# a = mu for incident radiation*sin(phi)
# b = mu for fluorescent xray*sin(theta)
# t has units of 1/b, so either cm or g/cm^2 depending on if you use aborption or mass absorption coeffecient
maxt(a,b) = a==b?1/b:(log(a)-log(b))/(a-b)
close("all")
aoverb = [0.20001:0.01:3]
for b = 1:4
plot(aoverb, b*[maxt(aob*b,b) for aob in aoverb])
end
xlabel("mu for incident radiation*sin(phi)/mu for fluorescent xray*sin(theta)")
ylabel("mu for fluorescent xray*thickness for maximum emission")
legend()
grid("on")
close("all")
a = [10:10:600] # cm^2/g
b = [10:10:600] # cm^2/g
mt = 1000*[maxt(aa,bb) for aa=a,bb=b] #mg/cm^2
contour_locs = [mt[i,i] for i=1:int(length(a)/20):length(a)]
cs = contour(a,b,mt,contour_locs,vmin=1, vmax=7)
# xscale("log")
# yscale("log")
plt.clabel(cs, inline=1, fontsize=10,fmt="%1.1f mg/cm\$^2\$")
xlabel("mass absorption coeffecient for incident xrays*sin(phi) (cm\$^2\$/g)")
ylabel("mass absorption coeffecient for fluorescent xrays*sin(phi) (cm\$^2\$/g)")
title("optimal x-ray emission target thickness*density")
grid("on")
plot([fes2_7150,fes2_10000],[fes2_7050,fes2_7050],"r",lw=3)
xlim(first(a), last(a))
ylim(first(a), last(a))
fes2_8500=261+79 # cm^2/g
fes2_7060=54+134 # cm^2/g
maxt(fes2_8500,fes2_7060/sin(deg2rad(80))) # g/cm^2
fes2_8500/fes2_7060
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment