AngleCalibration¶
Class to calibrate the mythen detector parameters used for conversion. For the calibration the “Best computing” BC parameters are used. However, as initial parameters or for conversion it expects the “historic detector group” DG parameters. See Different Parameter Sets for a more detailed description of the different detector parameters.
Example Usage for Calibration:¶
std::shared_ptr<MythenDetector> mythen_detector_ptr =
std::make_shared<MythenDetector>();
mythen_detector_ptr->read_bad_channels_from_file("bad_channels.txt");
std::shared_ptr<FlatField> flat_field_ptr =
std::make_shared<FlatField>(mythen_detector_ptr);
flat_field_ptr->read_normalized_flatfield_from_file("flatfield.raw");
AngleCalibration anglecalibration(mythen_detector_ptr, flat_field_ptr);
anglecalibration.read_initial_calibration_from_file(
"initial_DG_parameters.off");
//dummy acquisitions
std::vector<std::string> filelist{"file_01.hdf5", "file_02.hdf5", "file_03.hdf5"};
double base_peak_angle = 19.5;
//calibrate parameters for module 10
anglecalibration.calibrate<true>(filelist, base_peak_angle, 10); // calibrate with visualization of the fit results
API:¶
Note
The method read_bad_channels_from_file expects a text file using the format below. Each line denotes the index of a bad channel. Consecutive bad channels can be stored on one line e.g. channels with 20-42 are bad channels.
1
2
20-42
100
1002-1004
If youre file format deviates from the above format implement your custom file reader inheriting from the class SimpleFileInterface (SimpleFileInterface) and pass it to the function.
-
class AngleCalibration¶
Public Functions
Constructor for AngleCalibration class.
- Parameters:
mythen_detector_ – ptr to MythenDetector storing all mythen specific parameters and methods to calculate diffraction angles
flat_field_ – ptr to FlatField class storing inverse normalized flat field
-
void set_histogram_bin_width(double bin_width = 0.0036)¶
set the histogram bin width [degrees] default ‘0.0036°’
-
double get_histogram_bin_width() const¶
get histogram bin width [degrees]
-
ssize_t num_fixed_angle_width_bins() const¶
number of bins of fixed angle width bin histogram
-
ssize_t get_base_peak_ROI_num_bins() const¶
number of bins covered by base peak region of interest default ‘101’ bins
-
void set_base_peak_ROI_width(const double base_peak_roi_ = 0.05)¶
set base peak region of interest
- Parameters:
base_peak_roi_ – width of base peak ROI [degrees] e.g. [base_peak - base_peak_ROI, base_peak + base_peak_ROI] given in angles defaults to ‘0.05°’
-
double get_base_peak_ROI_width() const¶
half odf the width of base peak region of interest
- Returns:
width of base peak ROI [degrees] e.g. [base_peak - base_peak_ROI, base_peak + base_peak_ROI] given in angles [degrees]
-
double get_base_peak_angle() const¶
get base peak angle
- Returns:
angle of base peak [degrees]
-
void set_base_peak_angle(const double base_peak_angle_)¶
set base peak angle
- Parameters:
base_peak_angle_ – angle of base peak [degrees]
-
inline const std::shared_ptr<MythenDetector> get_mythen_detector() const¶
get detector geometry used for angular conversion
- Returns:
shared pointer to MythenDetector
read bad channels from file
- Parameters:
filename – bad channels filename
file_reader – file_reader to read bad channels file (default: CustomBadChannelsFile bad channel file is expected to be a text file where each line stores the channel index of a bad channel. Consecutive bad channels can be stored in one line by seperating the first and last channel index of the bad channel block e.g. bad_channel_index0-bad_channel_index1.))
-
NDView<bool, 1> get_bad_channels()¶
-
void set_bad_channels(const NDView<bool, 1> bad_channels_)¶
set bad channels
- Parameters:
bad_channels_ – boolean NDView of size of total number of strips/channels in detector, stores ‘TRUE’ if strip is a bad channel otherwise ‘FALSE’
-
const DGParameters &get_DGparameters() const¶
get the current DG parameters
-
const BCParameters &get_BCparameters() const¶
get the current BC parameters
-
template<bool visualize_calibration = false>
void calibrate(const NDView<uint32_t, 2> frames, const NDView<double, 1> detector_angles, const double base_peak_angle)¶ calibrates the BC (best computing) parameters for all modules
- Template Parameters:
visualize_calibration – if true visualize calibration process (default: false)
- Parameters:
frames – 2D NDView of frames (rows: acquisitions, cols: channels) - need to be sorted by detector angle
detector_angles – 1D NDView of monitor positions for acquisitions
base_peak_angle – angle of the selcted base peak [degrees]
-
template<bool visualize_calibration = false>
void calibrate(const NDView<uint32_t, 2> frames, const NDView<double, 1> detector_angles, const double base_peak_angle_, const size_t module_index)¶ calibrates the BC (best computing) parameters for one module
- Template Parameters:
visualize_calibration – if true visualize calibration process (default: false)
- Parameters:
frames – 2D NDView of frames (rows: acquisitions, cols: channels) - need to be sorted by detector angle
detector_angles – 1D NDView of monitor positions for the acquisitions
base_peak_angle_ – angle of the selected base peak given in degrees
module_index – index of module to be calibrated
-
bool base_peak_is_in_module(const size_t module_index, const double detector_angle) const¶
check if base peak ROI is contained within module region
- Parameters:
module_index – index of module
detector_angle – detector position (offset of first strip from default detector position) [degrees]
- Returns:
true if [base_peak - base_peak_ROI, base_peak + base_peak_ROI] is fully contained within the module region
-
bool module_is_disconnected(const size_t module_index) const¶
check if a module only has bad channels
-
void set_angular_range(const double min_angle, const double max_angle)¶
sets the angular range for the diffraction pattern e.g. diffraction pattern calculated for [min_angle, max_angle]
- Parameters:
min_angle – minimum angle [degrees]
max_angle – maximum angle [degrees]
-
std::pair<double, double> get_angular_range() const¶
gets the angular range for the diffraction pattern e.g. diffraction pattern calculated for [min_angle, max_angle]
- Returns:
pair of (min_angle, max_angle) [degrees]
Private Functions
-
std::tuple<NDView<uint32_t, 2>, NDView<double, 1>> get_frames_with_base_peak_overlap(const NDView<uint32_t, 2> frames, const NDView<double, 1> detector_angles, const size_t module_index) const¶
calculates the frames for which the base peak ROI is covered by the respective module region
- Parameters:
frames – 2D NDView of frames (rows: acquisitions, cols: channels) - need to be sorted by detector angle
detector_angles – 1D NDView of monitor positions for acquisition
module_index – index of module
-
void process_photon_counts(const size_t module_index, const NDView<uint32_t, 1> frame, const double detector_angle, NDView<double, 2> weighted_moments, NDView<size_t, 1> num_contributing_photons)¶
applies flatfield correction for a given module and redistributes them to fixed angle width bins
- Parameters:
module_index – index of module
frame – data from acquisition (storing detector position and photon counts)
weighted_moments – weighted photon counts of order 0-2 eg. order k: sum of photon_count_i^k*weight_i counts for fixed angle width bin and the corresponding variance
num_contributing_photons – number of photons contributing to the fixed angle width bin
detector_angle – detector axis motor position [degrees]
redistributes photon counts to fixed angle width bins around base peak for all acquisitions in passed frames and calculates the similarity between the found base peaks regions
- Parameters:
module_index – index of module
frames_with_base_peak_overlap – vector of frames from acquisitions for which the base peak ROI is covered by the respective module region
detector_angles_with_base_peak_overlap – 1D NDView of monitor positions for acquisitions
plot – plot wrapper to visualize calibration process (default nullptr)
- Returns:
similarity of peaks
redistributes photon counts to fixed angle width bins around base peak for all acquisitions in passed frames and calculates the similarity between the found base peaks regions of two modules
- Parameters:
module_index – index of module
frames_with_base_peak_overlap_module – vector of frames from acquisitions for which the base peak ROI is covered by the respective module region
detector_angles_with_base_peak_overlap_module – 1D NDView of monitor positions for acquisitions for the module
frames_with_base_peak_overlap_prev_module – vector of frames from acquisitions for which the base peak ROI is covered by the respective previous module region
detector_angles_with_base_peak_overlap_prev_module – 1D NDView of monitor positions for acquisitions for the previous module
plot – plot wrapper to visualize calibration process (default nullptr)
- Returns:
similarity of peaks
-
template<bool visualize_calibration = false>
void calibrate_coupled_parameters(const size_t module_index, const NDView<uint32_t, 2> frames_width_base_peak_overlap, const NDView<double, 1> detector_angles)¶ calibrates distance to module center and angle of module center and normal (L and delta) for a specific module
- Template Parameters:
visualize_calibration – if true visualize calibration process (default: false)
- Parameters:
module_index – index of module to be calibrated
frames_width_base_peak_overlap – frames with base peak overlap for the module
detector_angles – 1D NDView of monitor positions for acquisitions
-
template<bool visualize_calibration = false>
void calibrate_offset(const size_t module_index, const NDView<uint32_t, 2> frames_with_base_peak_overlap, const NDView<double, 1> detector_angles_with_base_peak_overlap, const NDView<uint32_t, 2> frames_with_base_peak_overlap_prev_module, const NDView<double, 1> detector_angles_with_base_peak_overlap_prev_module)¶ calibrates the angle between center of module and beam (phi) for a specific module
- Template Parameters:
visualize_calibration – if true visualize calibration process (default: false)
- Parameters:
module_index – index of module to be calibrated
frames_with_base_peak_overlap – frames with base peak overlap module to be calibrated
detector_angles_with_base_peak_overlap – 1D NDView of monitor positions for acquisitions
frames_with_base_peak_overlap_prev_module – frames with base peak overlap prev module
detector_angles_with_base_peak_overlap_prev_module – 1D NDView of monitor positions for acquisitions for the previous module
-
double center_base_peak(const size_t module_index, const NDView<uint32_t, 2> frames_with_base_peak_overlap, const NDView<double, 1> detector_angles_with_base_peak_overlap)¶
calculates the average angle of the base peak center over several acquisitions for a given module index
- Parameters:
module_index – index of module to calculate base peak center for
frames_with_base_peak_overlap – frames with base peak overlap for the given module index
detector_angles_with_base_peak_overlap – 1D NDView of monitor positions for acquisitions
- Returns:
average angle of base peak center [degrees]
-
double chi_similarity_criterion(const NDView<double, 2> weighted_sums, const NDView<size_t, 1> num_contributing_photons) const¶
compares multiple base peak ROIS from different acquisitions and calculate error based on goodness_of_fit and weighted average
- Parameters:
weighted_sums – weighted photon counts of order 0-2 eg. order k: sum of photon_count_i^k*weight_i
num_contributing_photons – number of photons contributing to the fixed angle width bin
- Returns:
similarity criterion
-
NDArray<double, 2> computeErrorandMean(const NDView<double, 2> weighted_sums, const NDView<size_t, 1> num_contributing_photons) const¶
averages redistributed photon counts and calculates error based on weighted average and goodness of fit
- Parameters:
weighted_sums – weighted photon counts of order 0-2 eg. order k: sum of photon_count_i^k*weight_i
num_contributing_photons – number of photons contributing to the fixed angle width bin
- Returns:
ndarray of size (num_bins_in_ROI, 2) where first dimension corresponds to average redistributed photon counts and second dimension corresponds to error of average redistributed photon counts
optimizes module center distance L and angle center module normal delta of BC parameters of given module based on chi similarity criterion
- Parameters:
module_index – index of module to be calibrated
frames_with_base_peak_overlap – vector of frames from acquisitions for which the base peak ROI is covered by the respective module region
detector_angles_with_base_peak_overlap – 1D NDView of monitor positions for acquisitions
plot – plot wrapper to visualize calibration process (default nullptr)
delta_parameter1 – parameter step for parameter module center distance L (default ‘0.5’)
delta_parameter2 – parameter step for parameter angle between center of module and module normal (delta) (default ‘1.0e-6’)
optimizes angle between center of module and beam ( \(\psi\)) of BC parameters of given module based on chi similarity criterion and center of base peak
- Parameters:
module_index – index of module to be calibrated
frames_with_base_peak_overlap – vector of frames with base peak overlap for module
detector_angles_with_base_peak_overlap – 1D NDView of monitor positions for acquisitions for the module
frames_with_base_peak_overlap_prev_module – vector of frames with base peak overlap for previous module
detector_angles_with_base_peak_overlap_prev_module – 1D NDView of monitor positions for acquisitions for the previous module
plot – plot wrapper to visualize calibration process (default nullptr)
delta_parameter – parameter step for angle between center of module and beam (default ‘0.005’)
Private Members
-
NDArray<bool, 1> bad_channels = {}¶
Array of size strips/channels in detector, stores ‘TRUE’ if strip is a bad channel otherwise ‘FALSE’.
-
std::shared_ptr<MythenDetector> m_mythen_detector = {}¶
detector geometry
-
double histogram_bin_width = 0.0036¶
bin width of fixed angle bin histogram [degrees]
-
double base_peak_roi_width = 0.05¶
half the width of region of interest of base peak e.g. [base_peak_angle - base_peak_roi, base_peak_angle + base_peak_roi] [degrees]
-
double base_peak_angle = {}¶
center of base peak to use for calibration [degrees]
-
double m_min_angle = -180.0¶
minimum angle for angular conversion [degrees]
-
double m_max_angle = 180.0¶
maximum angle for angular conversion [degrees]