-
Notifications
You must be signed in to change notification settings - Fork 122
/
SaveGSASInstrumentFile.h
148 lines (116 loc) · 5.09 KB
/
SaveGSASInstrumentFile.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
147
148
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2013 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 "MantidAPI/ITableWorkspace_fwd.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidKernel/System.h"
namespace Mantid {
namespace DataHandling {
class ChopperConfiguration;
/** SaveGSASInstrumentFile : Convert Fullprof"s instrument resolution file
(.irf) to GSAS"s instrument
file (.iparm/.prm).
*/
class DLLExport SaveGSASInstrumentFile final : public API::Algorithm {
public:
SaveGSASInstrumentFile();
/// Algorithm's name
const std::string name() const override { return "SaveGSASInstrumentFile"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "Generate a GSAS instrument file from either a table workspace "
"containing profile parameters or a Fullprof's instrument "
"resolution file (.irf file). ";
}
/// Algorithm's version
int version() const override { return (1); }
const std::vector<std::string> seeAlso() const override { return {"LoadGSASInstrumentFile", "SaveGSS"}; }
/// Algorithm's category for identification
const std::string category() const override { return "Diffraction\\DataHandling"; }
private:
/// Initialisation code
void init() override;
/// Execution code
void exec() override;
/// Process properties
void processProperties();
/// Set up some constant by default
void initConstants(const std::map<unsigned int, std::map<std::string, double>> &profmap);
/// Set up chopper/instrument constant parameters from profile map
std::shared_ptr<ChopperConfiguration>
setupInstrumentConstants(const std::map<unsigned int, std::map<std::string, double>> &profmap);
/// Set up for PG3 chopper constants
std::shared_ptr<ChopperConfiguration> setupPG3Constants(int intfrequency);
/// Set up for NOM chopper constants
std::shared_ptr<ChopperConfiguration> setupNOMConstants(int intfrequency);
/// Parse profile table workspace to a map
void parseProfileTableWorkspace(const API::ITableWorkspace_sptr &ws,
std::map<unsigned int, std::map<std::string, double>> &profilemap);
/// Convert to GSAS instrument file
void convertToGSAS(const std::vector<unsigned int> &outputbankids, const std::string &gsasinstrfilename,
const std::map<unsigned int, std::map<std::string, double>> &bankprofilemap);
/// Build a data structure for GSAS's tabulated peak profile
void buildGSASTabulatedProfile(const std::map<unsigned int, std::map<std::string, double>> &bankprofilemap,
unsigned int bankid);
/// Write the header of the file
void writePRMHeader(const std::vector<unsigned int> &banks, const std::string &prmfilename);
/// Write out .prm/.iparm file
void writePRMSingleBank(const std::map<unsigned int, std::map<std::string, double>> &bankprofilemap,
unsigned int bankid, const std::string &prmfilename);
/// Caclualte L2 from DIFFC and L1
double calL2FromDtt1(double difc, double L1, double twotheta);
/// Calculate TOF difference
double calTOF(double n, double ep, double eq, double er, double tp, double tq, double tr, double dsp);
/// Calculate a value related to (alph0, alph1, alph0t, alph1t) or (beta0,
/// beta1, beta0t, beta1t)
double aaba(double n, double ea1, double ea2, double ta1, double ta2, double dsp);
/// Get parameter value from a map
double getValueFromMap(const std::map<std::string, double> &profilemap, const std::string &parname);
/// Get parameter value from class storage
double getProfileParameterValue(const std::map<std::string, double> &profilemap, const std::string ¶mname);
/// Load fullprof resolution file.
void loadFullprofResolutionFile(const std::string &irffilename);
/// Calcualte d-space value.
double calDspRange(double dtt1, double zero, double tof);
// TODO Replace it with gsl's erfc()
double erfc(double xx);
/// Input workspace
API::ITableWorkspace_sptr m_inpWS;
// DataObjects::TableWorkspace_sptr m_inpWS;
/// Instrument
std::string m_instrument;
/// L1
double m_L1;
/// L2
double m_L2;
/// 2Theta
double m_2theta;
/// Frequency
int m_frequency;
/// User input ID line
std::string m_id_line;
/// Sample
std::string m_sample;
/// Banks IDs to process
std::vector<unsigned int> m_vecBankID2File;
/// Output file name
std::string m_gsasFileName;
/// Chopper configuration
std::shared_ptr<ChopperConfiguration> m_configuration;
/// Profile parameter map
std::map<unsigned int, std::map<std::string, double>> m_profileMap;
//
std::vector<double> m_gdsp;
std::vector<double> m_gdt;
std::vector<double> m_galpha;
std::vector<double> m_gbeta;
std::map<unsigned int, double> m_bank_mndsp;
std::map<unsigned int, double> m_bank_mxtof;
};
} // namespace DataHandling
} // namespace Mantid