Skip to content

Commit

Permalink
Merge pull request #725 from HEXRD/physics-package-pinhole-area-fix
Browse files Browse the repository at this point in the history
don't compute correction if no pinhole.
  • Loading branch information
psavery authored Nov 15, 2024
2 parents 9c595e1 + 59a8462 commit ff0a76e
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions hexrd/instrument/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def beam_position(self):
"""
raise NotImplementedError


@property
def extra_config_kwargs(self):
return {}
Expand Down Expand Up @@ -289,7 +288,8 @@ def __init__(
self.group = group

if detector_filter is None:
detector_filter = detector_coatings.Filter(**FILTER_DEFAULTS.TARDIS)
detector_filter = detector_coatings.Filter(
**FILTER_DEFAULTS.TARDIS)
self.filter = detector_filter

if detector_coating is None:
Expand Down Expand Up @@ -1709,7 +1709,7 @@ def calc_physics_package_transmission(self, energy: np.floating,
need to consider HED and HEDM samples separately
"""
bvec = self.bvec
sample_normal = np.dot(rMat_s, [0.,0.,-1.])
sample_normal = np.dot(rMat_s, [0., 0., -1.])
seca = 1./np.dot(bvec, sample_normal)

tth, eta = self.pixel_angles()
Expand All @@ -1720,7 +1720,8 @@ def calc_physics_package_transmission(self, energy: np.floating,

secb = np.abs(1./np.dot(dvecs, sample_normal).reshape(self.shape))

T_sample = self.calc_transmission_sample(seca, secb, energy, physics_package)
T_sample = self.calc_transmission_sample(
seca, secb, energy, physics_package)
T_window = self.calc_transmission_window(secb, energy, physics_package)

transmission_physics_package = T_sample * T_window
Expand All @@ -1729,45 +1730,53 @@ def calc_physics_package_transmission(self, energy: np.floating,
def calc_transmission_sample(self, seca: np.array,
secb: np.array, energy: np.floating,
physics_package: AbstractPhysicsPackage) -> np.array:
thickness_s = physics_package.sample_thickness # in microns
mu_s = 1./physics_package.sample_absorption_length(energy) # in microns^-1
thickness_s = physics_package.sample_thickness # in microns
# in microns^-1
mu_s = 1./physics_package.sample_absorption_length(energy)
x = (mu_s*thickness_s)
pre = 1./x/(secb - seca)
num = np.exp(-x*seca) - np.exp(-x*secb)
return pre * num

def calc_transmission_window(self, secb: np.array, energy: np.floating,
physics_package: AbstractPhysicsPackage) -> np.array:
thickness_w = physics_package.window_thickness # in microns
mu_w = 1./physics_package.window_absorption_length(energy) # in microns^-1
thickness_w = physics_package.window_thickness # in microns
# in microns^-1
mu_w = 1./physics_package.window_absorption_length(energy)
return np.exp(-thickness_w*mu_w*secb)

def calc_effective_pinhole_area(self, physics_package: AbstractPhysicsPackage) -> np.array:
"""get the effective pinhole area correction
"""
hod = (physics_package.pinhole_thickness /
physics_package.pinhole_diameter)
bvec = self.bvec
effective_pinhole_area = np.ones(self.shape)

tth, eta = self.pixel_angles()
angs = np.vstack((tth.flatten(), eta.flatten(),
np.zeros(tth.flatten().shape))).T
dvecs = angles_to_dvec(angs, beam_vec=bvec)
if (not np.isclose(physics_package.pinhole_diameter, 0)
and not np.isclose(physics_package.pinhole_thickness, 0)):

hod = (physics_package.pinhole_thickness /
physics_package.pinhole_diameter)
bvec = self.bvec

tth, eta = self.pixel_angles()
angs = np.vstack((tth.flatten(), eta.flatten(),
np.zeros(tth.flatten().shape))).T
dvecs = angles_to_dvec(angs, beam_vec=bvec)

cth = -dvecs[:, 2].reshape(self.shape)
tanth = np.tan(np.arccos(cth))
f = hod*tanth
f[np.abs(f) > 1.] = np.nan
asinf = np.arcsin(f)
effective_pinhole_area = (
(2/np.pi) * cth * (np.pi/2 - asinf - f*np.cos(asinf)))

cth = -dvecs[:,2].reshape(self.shape)
tanth = np.tan(np.arccos(cth))
f = hod*tanth
f[np.abs(f) > 1.] = np.nan
asinf = np.arcsin(f)
effective_pinhole_area = (
(2/np.pi) * cth * (np.pi/2 - asinf - f*np.cos(asinf)))
return effective_pinhole_area

def calc_transmission_generic(self,
secb: np.array,
thickness: np.floating,
absorption_length: np.floating) -> np.array:
mu = 1./absorption_length # in microns^-1
mu = 1./absorption_length # in microns^-1
return np.exp(-thickness*mu*secb)

def calc_transmission_phosphor(self,
Expand Down

0 comments on commit ff0a76e

Please sign in to comment.