Response¶
-
class
ompy.
Response
(path)[source]¶ Bases:
object
Interpolates response read from file for current setup
Implementaion of following method Guttormsen et al., NIM A 374 (1996) 371–376. DOI:10.1016/0168-9002(96)00197-0
Throughout the class, be aware that “compton” mat refer to all non-discrete structures (instead of the real Compton effect only).
- Variables
resp (pd.DataFrame) – Information of the response table
compton_matrix (np.ndarray) – array with compton counts. Shape is (N_incident, N_cmp).
Ecmp_array (np.ndarray) – energy array for the compton counts
smooth_compton (bool) – If True, the compoton array is smoothed before further processing. defaults to False
truncate (float) – After how many sigma to truncate gaussian smoothing. Defaults to 6.
The resonse object is initialized with the path to the source files required to perform the interpolation. The path varaiable can either be a folder (assuming “old” format) or a zip file containing the files otherwise found in the folder in the “old” format.
- Parameters
path (str or Path) – Path to the required file(s)
Todo
adapt rutines for the possibility that not all cmp spectra have the same binning
Methods Summary
E_compton
(Eg, theta)Calculates the energy of an electron that is scattered an angle theta by a gamma-ray of energy Eg.
LoadDir
(path[, resp_name, spec_prefix])Method for loading response file and compton spectra from a folder.
LoadZip
(path[, resp_name, spec_prefix])Method for loading response file and compton spectra from zipfile.
dE_dtheta
(Eg, theta)Function to correct number of counts due to delta(theta) Adapted from MAMA in the file kelvin.f It is dE/dtheta of the E(theta) in Eq.
discrete_peaks
(i_response, fwhm_abs_array)Add discrete peaks for a given channel and smooth them
fan_method
(E, compton, i_start, i_stop)Fan method
Find and rebin closest energies from available response functions
Interpolate full-energy peak probabilities (…)
interpolate
([Eout, fwhm_abs, return_table])Interpolated the response matrix
Check on the inputs to interpolate
linear_backscatter
(E, compton)Interpolate one-to-one up to the backscatter peak
linear_cmp_interpolation
(E, compton[, …])Linear interpolation between the compton spectra
linear_to_end
(E, compton, i_start, i_stop)Interpolate one-to-one from the last fan energy to the Emax
two_channel_split
(E_centroid, E_array)When E_centroid is between two bins in E_array, this function returns the indices of the two nearest bins and the distance to the lower bin.
Methods Documentation
-
static
E_compton
(Eg, theta)[source]¶ Calculates the energy of an electron that is scattered an angle theta by a gamma-ray of energy Eg. Adapted from MAMA, file “folding.f”, which references Canberra catalog ed.7, p.2.
Note
For Eg <= 0.1 it returns Eg. (workaround)
- Parameters
Eg – Energy of gamma-ray in keV
theta – Angle of scatter in radians
- Returns
Energy Ee of scattered electron
-
LoadDir
(path, resp_name='resp.dat', spec_prefix='cmp')[source]¶ Method for loading response file and compton spectra from a folder.
- Parameters
- Returns
- (tuple) containing
resp (DataFrame): Information of the response table.
- compton_matrix (ndarray): matrix with compton counts.
Shape is (N_incident, N_cmp)
last.E (ndarray): energy array
-
LoadZip
(path, resp_name='resp.csv', spec_prefix='cmp')[source]¶ Method for loading response file and compton spectra from zipfile.
Is assumes that path is a zip file that constains at least XX files. At least one has to be a special summary table to be named resp_name.
- Parameters
- Returns
- (tuple) containing
resp (DataFrame): Information of the response table.
- compton_matrix (ndarray): matrix with compton counts.
Shape is (N_incident, N_cmp)
last.E (ndarray): energy array
-
static
dE_dtheta
(Eg, theta)[source]¶ Function to correct number of counts due to delta(theta) Adapted from MAMA in the file kelvin.f It is dE/dtheta of the E(theta) in Eq. (2) in Guttormsen 1996.
- Parameters
Eg – Energy of gamma-ray in keV
theta – Angle of scatter in radians
- Returns
dE_dtheta
- Return type
TYPE
-
discrete_peaks
(i_response, fwhm_abs_array)[source]¶ Add discrete peaks for a given channel and smooth them
-
fan_method
(E, compton, i_start, i_stop)[source]¶ Fan method
- Parameters
E (float) – Incident energy
compton (dict) – Dict. with information about the compton spectra to interpolate between
i_start (int) – Index where to start (usually end of backscatter)
i_stop (int) – Index where to stop (usually E+n*resolution). Note that it can be stopped earlier, which will be reported through i_last
- Returns
- R is Response for E, and i_last last
index of fan-method
- Return type
Tuple[np.ndarray, int]
-
get_closest_compton
(E)[source]¶ Find and rebin closest energies from available response functions
If E < self.resp[‘Eg’].min() the compton matrix will be replaced by an array of zeros.
-
interpolate
(Eout=None, fwhm_abs=None, return_table=False)[source]¶ Interpolated the response matrix
Perform the interpolation for the energy range specified in Eout with FWHM at 1332 keV given by FWHM_abs (in keV).
The interpolation is split into energy regions. Below the back-scattering energy Ebsc we interpolate linearly, then we apply the “fan method” (Guttormsen 1996) in the region from Ebsc up to the Compton edge, then linear extrapolation again the rest of the way.
- Parameters
folderpath – The path to the folder containing Compton spectra and
resp.dat –
Eout_array – The desired energies of the output response matrix.
fwhm_abs (
Optional
[float
]) – The experimental absolute full-width-half-max at 1.33 MeV. Note: In the article it is recommended to use 1/10 of the real FWHM for unfolding.return_table (optional) – Returns “all” output, see below
- Returns
response (Matrix): Response matrix with incident energy on the “Ex” axis and the spectral response on the “Eg” axis
response_table (DataFrame, optional): Table with efficiencies, FE, SE (…) probabilities, and so on
- Return type
-
linear_cmp_interpolation
(E, compton, fill_value='extrapolate')[source]¶ Linear interpolation between the compton spectra
-
linear_to_end
(E, compton, i_start, i_stop)[source]¶ Interpolate one-to-one from the last fan energy to the Emax
-
static
two_channel_split
(E_centroid, E_array)[source]¶ When E_centroid is between two bins in E_array, this function returns the indices of the two nearest bins and the distance to the lower bin. The distance to the higher bin is 1-floor_distance
- Parameters
E_centroid (double) – The energy of the centroid (mid-bin)
E_array (np.array, double) – The energy grid to distribute
-
static
E_compton
(Eg, theta)[source] Calculates the energy of an electron that is scattered an angle theta by a gamma-ray of energy Eg. Adapted from MAMA, file “folding.f”, which references Canberra catalog ed.7, p.2.
Note
For Eg <= 0.1 it returns Eg. (workaround)
- Parameters
Eg – Energy of gamma-ray in keV
theta – Angle of scatter in radians
- Returns
Energy Ee of scattered electron
-
LoadDir
(path, resp_name='resp.dat', spec_prefix='cmp')[source] Method for loading response file and compton spectra from a folder.
- Parameters
- Returns
- (tuple) containing
resp (DataFrame): Information of the response table.
- compton_matrix (ndarray): matrix with compton counts.
Shape is (N_incident, N_cmp)
last.E (ndarray): energy array
-
LoadZip
(path, resp_name='resp.csv', spec_prefix='cmp')[source] Method for loading response file and compton spectra from zipfile.
Is assumes that path is a zip file that constains at least XX files. At least one has to be a special summary table to be named resp_name.
- Parameters
- Returns
- (tuple) containing
resp (DataFrame): Information of the response table.
- compton_matrix (ndarray): matrix with compton counts.
Shape is (N_incident, N_cmp)
last.E (ndarray): energy array
-
static
dE_dtheta
(Eg, theta)[source] Function to correct number of counts due to delta(theta) Adapted from MAMA in the file kelvin.f It is dE/dtheta of the E(theta) in Eq. (2) in Guttormsen 1996.
- Parameters
Eg – Energy of gamma-ray in keV
theta – Angle of scatter in radians
- Returns
dE_dtheta
- Return type
TYPE
-
discrete_peaks
(i_response, fwhm_abs_array)[source] Add discrete peaks for a given channel and smooth them
-
fan_method
(E, compton, i_start, i_stop)[source] Fan method
- Parameters
E (float) – Incident energy
compton (dict) – Dict. with information about the compton spectra to interpolate between
i_start (int) – Index where to start (usually end of backscatter)
i_stop (int) – Index where to stop (usually E+n*resolution). Note that it can be stopped earlier, which will be reported through i_last
- Returns
- R is Response for E, and i_last last
index of fan-method
- Return type
Tuple[np.ndarray, int]
-
get_closest_compton
(E)[source] Find and rebin closest energies from available response functions
If E < self.resp[‘Eg’].min() the compton matrix will be replaced by an array of zeros.
-
get_probabilities
()[source] Interpolate full-energy peak probabilities (…)
-
interpolate
(Eout=None, fwhm_abs=None, return_table=False)[source] Interpolated the response matrix
Perform the interpolation for the energy range specified in Eout with FWHM at 1332 keV given by FWHM_abs (in keV).
The interpolation is split into energy regions. Below the back-scattering energy Ebsc we interpolate linearly, then we apply the “fan method” (Guttormsen 1996) in the region from Ebsc up to the Compton edge, then linear extrapolation again the rest of the way.
- Parameters
folderpath – The path to the folder containing Compton spectra and
resp.dat –
Eout_array – The desired energies of the output response matrix.
fwhm_abs (
Optional
[float
]) – The experimental absolute full-width-half-max at 1.33 MeV. Note: In the article it is recommended to use 1/10 of the real FWHM for unfolding.return_table (optional) – Returns “all” output, see below
- Returns
response (Matrix): Response matrix with incident energy on the “Ex” axis and the spectral response on the “Eg” axis
response_table (DataFrame, optional): Table with efficiencies, FE, SE (…) probabilities, and so on
- Return type
-
iterpolate_checks
()[source] Check on the inputs to interpolate
-
linear_backscatter
(E, compton)[source] Interpolate one-to-one up to the backscatter peak
-
linear_cmp_interpolation
(E, compton, fill_value='extrapolate')[source] Linear interpolation between the compton spectra
-
linear_to_end
(E, compton, i_start, i_stop)[source] Interpolate one-to-one from the last fan energy to the Emax
-
static
two_channel_split
(E_centroid, E_array)[source] When E_centroid is between two bins in E_array, this function returns the indices of the two nearest bins and the distance to the lower bin. The distance to the higher bin is 1-floor_distance
- Parameters
E_centroid (double) – The energy of the centroid (mid-bin)
E_array (np.array, double) – The energy grid to distribute