mcutils/xray/xray.py

50 lines
1.8 KiB
Python
Raw Normal View History

from __future__ import print_function,division
import numpy as np
import os
def xrayAttLenght(*args,**kw):
from periodictable import xsf
n = xsf.index_of_refraction(*args,**kw)
if not "wavelength" in kw:
wavelength = 12.398/np.asarray(kw["energy"])
else:
wavelength = np.asarray(kw["wavelength"])
attenuation_length = np.abs( (wavelength*1e-10)/ (4*np.pi*np.imag(n)) )
return attenuation_length
def xrayFluo(atom,density,energy=7.,length=30.,I0=1e10,\
det_radius=1.,det_dist=10.,det_material="Si",det_thick=300,verbose=True):
""" compound: anything periodictable would understand
density: in mM
length: sample length in um
energy: in keV, could be array
"""
import periodictable
from periodictable import xsf
wavelength = 12.398/energy
atom = periodictable.__dict__[atom]
# 1e3 -> from mM to M
# 1e3 -> from L to cm3
# so 1 mM = 1e-3M/L = 1e-6 M/cm3
density_g_cm3 = density*1e-6*atom.mass
n = xsf.index_of_refraction(atom,density=density_g_cm3,wavelength=wavelength)
attenuation_length = xrayAttLenght( atom,density=density_g_cm3,energy=energy )
# um-> m: 1e-6
fraction_absorbed = 1.-np.exp(-length*1e-6/attenuation_length)
if verbose:
print("Fraction of x-ray photons absorbed by the sample:",fraction_absorbed)
## detector ##
det_area = np.pi*det_radius**2
det_solid_angle = det_area/(4*np.pi*det_dist**2)
if verbose:
print("Detector fraction of solid angle:",det_solid_angle)
det_att_len = xrayAttLenght(det_material,wavelength=atom.K_alpha)
det_abs = 1-np.exp(-det_thick*1e-6/det_att_len)
if verbose:
print("Detector efficiency (assuming E fluo = E_K_alpha):",det_abs)
eff = fraction_absorbed*det_solid_angle*det_abs
if verbose:
print("Overall intensity (as ratio to incoming one):",eff)
return eff