Skip to content

Commit

Permalink
added Klein-Nishina distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
kylechampley committed Mar 14, 2024
1 parent c607ecf commit 357bab3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
5 changes: 3 additions & 2 deletions demo/xrayphysics_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# The next line prints out the version number and some other information about this package
#physics.about()

whichPlot = 10
whichPlot = 9


#########################################################################################
Expand Down Expand Up @@ -166,10 +166,11 @@
if whichPlot == 9:
plt.figure(figsize=(10,5))
plt.subplot(1, 2, 1)
plt.plot(thetas, dsigma_incoh)
plt.plot(thetas, dsigma_incoh, thetas, physics.KleinNishinaScatterDistribution(60.0, thetas, True))
plt.title('Incoherent (Compton) Scatter Distributions')
plt.xlabel('angle (degrees)')
plt.ylabel('normalized differential cross section')
plt.legend(['true distribution','Klein-Nishina approximation'])
plt.xlim((0.0,180.0))

plt.subplot(1, 2, 2)
Expand Down
6 changes: 3 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to XrayPhysics's documentation!
=======================================
XrayPhysics Library Documentation
=================================

This is a C/C++ library with Python bindings with the following capabilities:
This is a C/C++ library (Linux, Windows, Mac) with Python bindings with the following capabilities:

1. x-ray cross sections (energies from 1 keV to 20 MeV and elements 1-100) specified by chemical formula or element/compound mass fractions
2. incoherent and coherent x-ray scattering angle distributions specified by chemical formula or element/compound mass fractions
Expand Down
24 changes: 23 additions & 1 deletion src/xrayphysics.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,25 @@ def coherentScatterDistribution_normalizationFactor(self, Z, gamma):
self.libxrayphysics.coherentScatterDistribution_normalizationFactor.restype = ctypes.c_float
self.libxrayphysics.coherentScatterDistribution_normalizationFactor.argtypes = [ctypes.c_float, ctypes.c_float]
return self.libxrayphysics.coherentScatterDistribution_normalizationFactor(float(Z), gamma) * self.cross_section_scalar()

def KleinNishinaScatterDistribution(self, gamma, theta, doNormalize=False):
ELECTRON_REST_MASS_ENERGY = 510.975
CLASSICAL_ELECTRON_RADIUS = 2.8179403267e-13
AVOGANDROS_NUMBER = 6.0221414107e23
KNconstant = CLASSICAL_ELECTRON_RADIUS*CLASSICAL_ELECTRON_RADIUS*AVOGANDROS_NUMBER
cos_theta = np.cos(theta*np.pi/180.0)
P = 1.0 / (1.0 + (gamma / ELECTRON_REST_MASS_ENERGY) * (1.0 - cos_theta))
retVal = 0.5 * P * P * (P + 1.0 / P - 1.0 + cos_theta * cos_theta) / (self.ComptonBasis(gamma) / KNconstant)
if doNormalize:
return retVal / self.KleinNishinaScatterDistribution_normalizationFactor(gamma)
else:
return retVal

def KleinNishinaScatterDistribution_normalizationFactor(self, gamma):
thetas = np.linspace(0.0, 180.0, 1800)
KN = self.KleinNishinaScatterDistribution(gamma, thetas, False)
return np.sum(KN*np.sin(thetas*np.pi/180.0)*2.0*np.pi*np.pi/180.0*0.1)

###

def simulateSpectra(self, kV, takeOffAngle=11.0, Z=74, gammas=None):
Expand Down Expand Up @@ -1271,7 +1290,10 @@ def ComptonBasis(self, gammas):
KNconstant = CLASSICAL_ELECTRON_RADIUS*CLASSICAL_ELECTRON_RADIUS*AVOGANDROS_NUMBER
two_PI_KNconstant = 2.0*np.pi*KNconstant

alpha = gammas.copy() / ELECTRON_REST_MASS_ENERGY
if type(gammas) is np.ndarray:
alpha = gammas.copy() / ELECTRON_REST_MASS_ENERGY
else:
alpha = gammas / ELECTRON_REST_MASS_ENERGY
one_plus_two_alpha = 1.0+2.0*alpha
log_term = np.log(one_plus_two_alpha)
basisFcn = (1.0+one_plus_two_alpha)/(2.0*one_plus_two_alpha*one_plus_two_alpha) + ((alpha*alpha-1.0-one_plus_two_alpha)*log_term + 4.0*alpha)/(2.0*alpha*alpha*alpha) * two_PI_KNconstant
Expand Down

0 comments on commit 357bab3

Please sign in to comment.