Mantid
Loading...
Searching...
No Matches
IntegrateQLabEvents.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
12#include "MantidKernel/Matrix.h"
13#include "MantidKernel/V3D.h"
14#include "MantidMDAlgorithms/DllConfig.h"
15
16#include <memory>
17#include <tuple>
18#include <unordered_map>
19#include <vector>
20
21namespace Mantid {
22
23namespace Geometry {
24class PeakShape;
25}
26
27namespace MDAlgorithms {
31
33struct CellCoords {
34 int64_t a;
35 int64_t b;
36 int64_t c;
37
38 CellCoords(const V3D &q, const double cellSize)
39 : a(static_cast<int64_t>(q[0] / cellSize)), b(static_cast<int64_t>(q[1] / cellSize)),
40 c(static_cast<int64_t>(q[2] / cellSize)) {}
41
43 bool isOrigin() { return !(a || b || c); }
44
46 int64_t getHash() { return 1000000000000 * a + 100000000 * b + 10000 * c; }
47
50 std::vector<int64_t> nearbyCellHashes() {
51 std::vector<int64_t> neighbors;
52 for (int64_t ia = a - 1; ia <= a + 1; ia++)
53 for (int64_t ib = b - 1; ib <= b + 1; ib++)
54 for (int64_t ic = c - 1; ic <= c + 1; ic++) {
55 int64_t key = 1000000000000 * ia + 100000000 * ib + 10000 * ic;
56 neighbors.emplace_back(key);
57 }
58 return neighbors;
59 }
60};
61
62// [(weight, error), Q-vector], trimmed-down info for an event
63using SlimEvent = std::pair<std::pair<double, double>, V3D>;
64using SlimEvents = std::vector<SlimEvent>;
65
66// A cell in partitioned QLab space containing one peak
68 size_t peakIndex; // index of the peak within this cell
69 V3D peakQ; // QLab vector of the peak within this cell
70 SlimEvents events; // events potentially closer than m_radius to the peak
71};
72
88class MANTID_MDALGORITHMS_DLL IntegrateQLabEvents {
89public:
98 IntegrateQLabEvents(const SlimEvents &peak_q_list, double radius,
99 const bool useOnePercentBackgroundCorrection = true);
100
102 static bool isOrigin(const V3D &q, const double &cellSize);
103
105 void setRadius(const double &radius);
106
114 void addEvents(SlimEvents const &event_qs);
115
147 PeakShape_const_sptr ellipseIntegrateEvents(const std::vector<V3D> &E1Vec, V3D const &peak_q, bool specify_size,
148 double peak_radius, double back_inner_radius, double back_outer_radius,
149 std::vector<double> &axes_radii, double &inti, double &sigi,
150 std::pair<double, double> &backi);
151
158 void populateCellsWithPeaks();
159
160private:
172 static std::pair<double, double> numInEllipsoid(SlimEvents const &events, std::vector<V3D> const &directions,
173 std::vector<double> const &sizes);
174
190 static std::pair<double, double> numInEllipsoidBkg(SlimEvents const &events, std::vector<V3D> const &directions,
191 std::vector<double> const &sizes,
192 std::vector<double> const &sizesIn,
193 const bool useOnePercentBackgroundCorrection);
194
214 static void makeCovarianceMatrix(SlimEvents const &events, Kernel::DblMatrix &matrix, double radius);
215
222 static void getEigenVectors(Kernel::DblMatrix const &cov_matrix, std::vector<V3D> &eigen_vectors,
223 std::vector<double> &eigen_values);
224
228 void addEvent(const SlimEvent event);
229
260 PeakShapeEllipsoid_const_sptr ellipseIntegrateEvents(const std::vector<V3D> &E1Vec, V3D const &peak_q,
261 SlimEvents const &ev_list, std::vector<V3D> const &directions,
262 std::vector<double> const &sigmas, bool specify_size,
263 double peak_radius, double back_inner_radius,
264 double back_outer_radius, std::vector<double> &axes_radii,
265 double &inti, double &sigi, std::pair<double, double> &backi);
266
278 double detectorQ(const std::vector<V3D> &E1Vec, const V3D &QLabFrame, const std::vector<double> &r);
279
280 // Private data members
281 double m_radius; // size of sphere to use for events around a peak
287 std::unordered_map<size_t, OccupiedCell> m_cellsWithPeaks;
289 std::unordered_map<size_t, SlimEvents> m_cellsWithEvents;
290};
291
292} // namespace MDAlgorithms
293
294} // namespace Mantid
double radius
Definition: Rasterize.cpp:31
Class for 3D vectors.
Definition: V3D.h:34
This is a low-level class to construct a map with lists of events near each peak Q-vector in the lab ...
std::unordered_map< size_t, SlimEvents > m_cellsWithEvents
list of cells occupied with events
double m_cellSize
size of the square cell unit, holding at most one single peak
const bool m_useOnePercentBackgroundCorrection
if one percent culling of the background should be performed.
std::unordered_map< size_t, OccupiedCell > m_cellsWithPeaks
list the occupied cells in an unordered map for fast searching
std::shared_ptr< const PeakShapeEllipsoid > PeakShapeEllipsoid_const_sptr
std::shared_ptr< const PeakShape > PeakShape_const_sptr
Definition: PeakShape.h:43
std::vector< SlimEvent > SlimEvents
std::pair< std::pair< double, double >, V3D > SlimEvent
Helper class which provides the Collimation Length for SANS instruments.
Partition QLab space into a cubic lattice.
bool isOrigin()
Check if all cell coords are zero.
std::vector< int64_t > nearbyCellHashes()
Hashes for the 26 first neighbor coordinates plus the coordinates themselves.
CellCoords(const V3D &q, const double cellSize)
int64_t getHash()
cast coordinates to scalar, to be used as key in an unordered map