19 : m_dimension(1), m_res_function_1d(res_function_1d)
21 setName(
"ConvolutionDetectorResolution");
26 : m_dimension(2), m_res_function_1d(0)
28 setName(
"ConvolutionDetectorResolution");
58 throw std::runtime_error(
59 "ConvolutionDetectorResolution::applyDetectorResolution() -> Error! "
60 "Intensity map must have same dimension as detector resolution function.");
70 throw std::runtime_error(
71 "ConvolutionDetectorResolution::applyDetectorResolution() -> Error! "
72 "Class ConvolutionDetectorResolution must be initialized with dimension 1 or 2.");
85 throw std::runtime_error(
"ConvolutionDetectorResolution::apply1dConvolution() -> Error! "
86 "No 1d resolution function present for convolution of 1d data.");
87 if (p_intensity_map->
rank() != 1)
88 throw std::runtime_error(
89 "ConvolutionDetectorResolution::apply1dConvolution() -> Error! "
90 "Number of axes for intensity map does not correspond to the dimension of the map.");
91 const IAxis& axis = p_intensity_map->
axis(0);
94 size_t data_size = source_vector.size();
98 if (axis.
size() != data_size)
99 throw std::runtime_error(
100 "ConvolutionDetectorResolution::apply1dConvolution() -> Error! "
101 "Size of axis for intensity map does not correspond to size of data in the map.");
102 double step_size = std::abs(axis[0] - axis[axis.
size() - 1]) / (data_size - 1);
103 double mid_value = axis[axis.
size() / 2];
104 std::vector<double> kernel;
105 for (
size_t index = 0; index < data_size; ++index) {
109 std::vector<double> result;
112 std::for_each(result.begin(), result.end(), [](
double& val) { val = std::max(0.0, val); });
120 throw std::runtime_error(
"ConvolutionDetectorResolution::apply2dConvolution() -> Error! "
121 "No 2d resolution function present for convolution of 2d data.");
122 if (p_intensity_map->
rank() != 2)
123 throw std::runtime_error(
124 "ConvolutionDetectorResolution::apply2dConvolution() -> Error! "
125 "Number of axes for intensity map does not correspond to the dimension of the map.");
126 const IAxis& axis_1 = p_intensity_map->
axis(0);
127 const IAxis& axis_2 = p_intensity_map->
axis(1);
128 size_t axis_size_1 = axis_1.
size();
129 size_t axis_size_2 = axis_2.
size();
130 if (axis_size_1 < 2 || axis_size_2 < 2)
133 std::vector<double> raw_source_vector = p_intensity_map->
getRawDataVector();
134 std::vector<std::vector<double>> source;
135 size_t raw_data_size = raw_source_vector.size();
136 if (raw_data_size != axis_size_1 * axis_size_2)
137 throw std::runtime_error(
138 "ConvolutionDetectorResolution::apply2dConvolution() -> Error! "
139 "Intensity map data size does not match the product of its axes' sizes");
140 for (
auto it = raw_source_vector.begin(); it != raw_source_vector.end(); it += axis_size_2) {
141 std::vector<double> row_vector(it, it + axis_size_2);
142 source.push_back(row_vector);
145 std::vector<std::vector<double>> kernel;
146 kernel.resize(axis_size_1);
147 double mid_value_1 = axis_1[axis_size_1 / 2];
148 double mid_value_2 = axis_2[axis_size_2 / 2];
149 double step_size_1 = std::abs(axis_1[0] - axis_1[axis_size_1 - 1]) / (axis_size_1 - 1);
150 double step_size_2 = std::abs(axis_2[0] - axis_2[axis_size_2 - 1]) / (axis_size_2 - 1);
151 for (
size_t index_1 = 0; index_1 < axis_size_1; ++index_1) {
152 double value_1 = axis_1[index_1] - mid_value_1;
153 std::vector<double> row_vector;
154 row_vector.resize(axis_size_2, 0.0);
155 for (
size_t index_2 = 0; index_2 < axis_size_2; ++index_2) {
156 double value_2 = axis_2[index_2] - mid_value_2;
158 row_vector[index_2] = z_value;
160 kernel[index_1] = row_vector;
163 std::vector<std::vector<double>> result;
166 std::vector<double> result_vector;
167 for (
size_t index_1 = 0; index_1 < axis_size_1; ++index_1) {
168 for (
size_t index_2 = 0; index_2 < axis_size_2; ++index_2) {
169 double value = result[index_1][index_2];
170 result_vector.push_back(value);
174 std::for_each(result_vector.begin(), result_vector.end(),
175 [](
double& val) { val = std::max(0.0, val); });
176 for (
auto it = p_intensity_map->
begin(); it != p_intensity_map->
end(); ++it)
177 (*it) = result_vector[it.getIndex()];
182 double halfstep = step / 2.0;
183 double xmin = x - halfstep;
184 double xmax = x + halfstep;
192 double halfstepx = step_x / 2.0;
193 double halfstepy = step_y / 2.0;
194 double xmin = x - halfstepx;
195 double xmax = x + halfstepx;
196 double ymin = y - halfstepy;
197 double ymax = y + halfstepy;
#define ASSERT(condition)
Defines class ConvolutionDetectorResolution.
Defines class Math::Convolve.
Convolutes the intensity in 1 or 2 dimensions with a resolution function.
double getIntegratedPDF1d(double x, double step) const
void setResolutionFunction(const IResolutionFunction2D &resFunc)
virtual ~ConvolutionDetectorResolution()
cumulative_DF_1d m_res_function_1d
void apply1dConvolution(OutputData< double > *p_intensity_map) const
std::unique_ptr< IResolutionFunction2D > m_res_function_2d
void apply2dConvolution(OutputData< double > *p_intensity_map) const
ConvolutionDetectorResolution(cumulative_DF_1d res_function_1d)
Constructor taking a 1 dimensional resolution function as argument.
virtual ConvolutionDetectorResolution * clone() const
virtual void applyDetectorResolution(OutputData< double > *p_intensity_map) const
Convolve given intensities with the encapsulated resolution.
std::vector< const INode * > getChildren() const
Returns a vector of children.
double getIntegratedPDF2d(double x, double step_x, double y, double step_y) const
Convolution of two real vectors (in 1D or 2D) using Fast Fourier Transform.
void fftconvolve(const double1d_t &source, const double1d_t &kernel, double1d_t &result)
convolution in 1D
Interface for one-dimensional axes.
virtual size_t size() const =0
retrieve the number of bins
void registerChild(INode *node)
const std::string & getName() const
void setName(const std::string &name)
Interface providing two-dimensional resolution function.
virtual IResolutionFunction2D * clone() const =0
iterator end()
Returns read/write iterator that points to the one past last element.
size_t rank() const
Returns number of dimensions.
std::vector< T > getRawDataVector() const
Returns copy of raw data vector.
const IAxis & axis(size_t serial_number) const
returns axis with given serial number
void setRawDataVector(const std::vector< T > &data_vector)
Sets new values to raw data vector.
iterator begin()
Returns read/write iterator that points to the first element.