-
Notifications
You must be signed in to change notification settings - Fork 122
/
SCDCalibratePanels2.h
146 lines (113 loc) · 6.32 KB
/
SCDCalibratePanels2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2020 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidAPI/Algorithm.h"
#include "MantidCrystal/DllConfig.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidDataObjects/TableWorkspace.h"
#include <boost/container/flat_set.hpp>
#include <limits>
namespace Mantid {
namespace Crystal {
/** SCDCalibratePanels2 :
* Using input peakworkspace with indexation results to calibrate each
* individual panels.
* The target calibration properties include:
* - T0: micro seconds
* time for proton to travel from reactor to target to generate neutron
* - L1: meters
* distance between target and sample
* - L2: meters (also known as z_shift)
* distance between sample and the center of each panel
* - Rot: degrees
* Euler angles (xyz )
*
* Spirit successor of ISAW and its reincarnation: SCDCalibratePanels
*/
class MANTID_CRYSTAL_DLL SCDCalibratePanels2 : public Mantid::API::Algorithm {
public:
/// Algorithm's name for identification
const std::string name() const override { return "SCDCalibratePanels"; }
/// Summary of algorithm's purpose
const std::string summary() const override {
return "Panel parameters and L1 are optimized to "
"minimize errors between theoretical and actual q values for the "
"peaks";
}
/// Algorithm's version, overriding a virtual method
int version() const override { return 2; }
/// Algorithm's category, overriding a virtual method
const std::string category() const override { return "Crystal\\Corrections"; }
/// Extra help info
const std::vector<std::string> seeAlso() const override { return {"CalculateUMatrix"}; }
private:
/// Overwrites Algorithm method. Does nothing at present
void init() override;
/// Overwrites Algorithm method
void exec() override;
/// Private validator for inputs
std::map<std::string, std::string> validateInputs() override;
/// Cache TOF equivalent to those measured from experiment
std::vector<double> captureTOF(Mantid::API::IPeaksWorkspace_sptr pws);
/// Private function dedicated for parsing lattice constant
void parseLatticeConstant(Mantid::API::IPeaksWorkspace_sptr pws);
/// Update the UB matrix
void updateUBMatrix(Mantid::API::IPeaksWorkspace_sptr pws);
/// Remove unindexed peaks from workspace
Mantid::API::IPeaksWorkspace_sptr removeUnindexedPeaks(Mantid::API::IPeaksWorkspace_sptr pws);
/// Private function for getting names of banks to be calibrated
void getBankNames(Mantid::API::IPeaksWorkspace_sptr pws);
/// Private function for calibrating T0
void optimizeT0(Mantid::API::IPeaksWorkspace_sptr pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
/// Private function for calibrating L1
void optimizeL1(Mantid::API::IPeaksWorkspace_sptr pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
/// Private function for calibrating banks
void optimizeBanks(Mantid::API::IPeaksWorkspace_sptr pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
/// Private function for fine tunning sample position
void optimizeSamplePos(Mantid::API::IPeaksWorkspace_sptr pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
/// Helper function for selecting peaks based on given bank name
Mantid::API::IPeaksWorkspace_sptr selectPeaksByBankName(Mantid::API::IPeaksWorkspace_sptr pws,
const std::string bankname, const std::string outputwsn);
/// Helper function that calculates the ideal qSample based on
/// integer HKL
Mantid::API::MatrixWorkspace_sptr getIdealQSampleAsHistogram1D(Mantid::API::IPeaksWorkspace_sptr pws);
/// Helper functions for adjusting components
void adjustComponent(double dx, double dy, double dz, double drx, double dry, double drz, std::string cmptName,
Mantid::API::IPeaksWorkspace_sptr &pws);
/// Generate a Table workspace to store the calibration results
Mantid::API::ITableWorkspace_sptr generateCalibrationTable(std::shared_ptr<Geometry::Instrument> &instrument);
/// Save to xml file for Mantid to load by manual crafting
void saveXmlFile(const std::string &FileName, boost::container::flat_set<std::string> &AllBankNames,
std::shared_ptr<Geometry::Instrument> &instrument);
/// Save to ISAW type det calibration output for backward compatiblity
void saveIsawDetCal(const std::string &filename, boost::container::flat_set<std::string> &AllBankName,
std::shared_ptr<Geometry::Instrument> &instrument, double T0);
/// Save the calibration table to a CSV file
void saveCalibrationTable(const std::string &FileName, Mantid::API::ITableWorkspace_sptr &tws);
/// Profile related functions
void profileL1(Mantid::API::IPeaksWorkspace_sptr &pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
void profileBanks(Mantid::API::IPeaksWorkspace_sptr &pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
void profileT0(Mantid::API::IPeaksWorkspace_sptr &pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
void profileL1T0(Mantid::API::IPeaksWorkspace_sptr &pws, Mantid::API::IPeaksWorkspace_sptr pws_original);
/// unique vars for a given instance of calibration
double m_a, m_b, m_c, m_alpha, m_beta, m_gamma;
double m_T0 = 0.0;
bool LOGCHILDALG{true};
const int MINIMUM_PEAKS_PER_BANK{6};
const double PI{3.1415926535897932384626433832795028841971693993751058209};
static constexpr double Tolerance = std::numeric_limits<double>::epsilon();
// Column names and types
const std::string calibrationTableColumnNames[8] = {"ComponentName", "Xposition", "Yposition",
"Zposition", "XdirectionCosine", "YdirectionCosine",
"ZdirectionCosine", "RotationAngle"};
const std::string calibrationTableColumnTypes[8] = {"str", "double", "double", "double",
"double", "double", "double", "double"};
boost::container::flat_set<std::string> m_BankNames;
Mantid::API::ITableWorkspace_sptr mCaliTable;
};
} // namespace Crystal
} // namespace Mantid