52 const V3D samplePos = inst->getSample()->getPos();
53 const V3D pos = inst->getSource()->getPos() - samplePos;
54 double l1 = pos.
norm();
59 infile.open(spectraFile.c_str());
62 std::vector<std::vector<double>> spectra;
63 std::vector<std::vector<double>> time;
65 for (
int wi = 0; wi < 8; wi++)
70 spectra.resize(a + 1);
74 std::stringstream ss(
STRING);
75 if (
STRING.find(
"Bank") == std::string::npos) {
76 double time0, spectra0;
77 ss >> time0 >> spectra0;
78 time[a].emplace_back(time0);
79 spectra[a].emplace_back(spectra0);
87 if (spectra.size() < 1)
88 throw std::runtime_error(
"The number of spectra in the loaded file is zero.");
92 outWS->setInstrument(inst);
93 outWS->getAxis(0)->setUnit(
"TOF");
94 outWS->setYUnit(
"Counts");
95 outWS->setDistribution(
true);
96 outWS->rebuildSpectraMapping(
false);
98 const auto &componentInfo = outWS->componentInfo();
99 const auto &detectorInfo = outWS->detectorInfo();
103 std::vector<size_t> detList;
104 for (
const size_t i : componentInfo.children(componentInfo.root())) {
105 if (componentInfo.isGridDetector(i)) {
106 detList.emplace_back(i);
111 for (
const size_t j : componentInfo.children(i)) {
112 if (componentInfo.isGridDetector(j)) {
113 detList.emplace_back(j);
119 const auto &grandchildren = componentInfo.children(j);
120 std::copy_if(grandchildren.begin(), grandchildren.end(), std::back_inserter(detList),
121 [&componentInfo](
size_t k) { return componentInfo.isGridDetector(k); });
128 for (
size_t i = 0; i < spectra.size(); i++) {
129 auto &outSpec = outWS->getSpectrum(i);
130 outSpec.clearDetectorIDs();
131 const size_t bankIndex = detList[i];
132 const auto grid = componentInfo.pixelGridComponent(bankIndex);
133 for (
int j = 0; j < grid.nX; j++) {
134 for (
int k = 0; k < grid.nY; k++) {
135 outSpec.addDetectorID(detectorInfo.detid(componentInfo.detectorIndexAtXYZ(bankIndex, j, k, 0)));
138 auto &outX = outSpec.mutableX();
139 auto &outY = outSpec.mutableY();
140 auto &outE = outSpec.mutableE();
142 V3D dir = componentInfo.position(bankIndex) - samplePos;
145 std::vector<double> xdata(1, 1.0);
146 std::vector<double> ydata;
150 double theta2 = dir.
angle(
V3D(0.0, 0.0, 1.0));
153 unit->toTOF(xdata, ydata, l1, 0,
155 {UnitParams::l2,
l2},
156 {UnitParams::twoTheta, theta2},
158 double one = xdata[0];
159 double spect1 =
spectrumCalc(one, iSpec, time, spectra, i);
161 for (
size_t j = 0; j < spectra[i].size(); j++) {
162 double spect = spectra[i][j];
164 double relSigSpect = std::sqrt((1.0 / spect) + (1.0 / spect1));
167 outX[j] = time[i][j];
169 outE[j] = relSigSpect;
171 throw std::runtime_error(
"Wavelength for normalizing to spectrum is out of range.");
179 convertAlg->execute();
180 outWS = convertAlg->getProperty(
"OutputWorkspace");
186 const std::vector<std::vector<double>> &spectra,
size_t id) {
191 double T =
TOF / 1000.;
193 double c1 = spectra[id][0];
194 double c2 = spectra[id][1];
195 double c3 = spectra[id][2];
196 double c4 = spectra[id][3];
197 double c5 = spectra[id][4];
198 double c6 = spectra[id][5];
199 double c7 = spectra[id][6];
200 double c8 = spectra[id][7];
201 double c9 = spectra[id][8];
202 double c10 = spectra[id][9];
203 double c11 = spectra[id][10];
205 spect = c1 + c2 * exp(-c3 / std::pow(T, 2)) / std::pow(T, 5) + c4 * exp(-c5 * std::pow(T, 2)) +
206 c6 * exp(-c7 * std::pow(T, 3)) + c8 * exp(-c9 * std::pow(T, 4)) + c10 * exp(-c11 * std::pow(T, 5));
209 for (i = 1; i < spectra[0].size() - 1; ++i)
210 if (
TOF < time[
id][i])
212 spect = spectra[id][i - 1] +
213 (
TOF - time[id][i - 1]) / (time[
id][i] - time[
id][i - 1]) * (spectra[id][i] - spectra[id][i - 1]);
251 std::string InstrumentFilename = alg->
getPropertyValue(
"InstrumentFilename");
257 if (!InstrumentName.empty())
259 if (!InstrumentFilename.empty())
263 throw std::invalid_argument(
"You must specify exactly ONE way to get an "
264 "instrument (workspace, instrument name, or "
265 "IDF file). You specified more than one.");
267 throw std::invalid_argument(
"You must specify exactly ONE way to get an "
268 "instrument (workspace, instrument name, or "
269 "IDF file). You specified none.");
274 inst = inWS->getInstrument();
279 childAlg->setPropertyValue(
"Filename", InstrumentFilename);
280 childAlg->setPropertyValue(
"InstrumentName", InstrumentName);
282 childAlg->executeAsChildAlg();
283 inst = tempWS->getInstrument();