159 double l1 = this->
getProperty(
"PrimaryFlightPath");
162 if (!originstrument) {
163 std::string errmsg(
"It is not supported that L1 is not given, ",
164 "while there is no instrument associated to input workspace.");
166 throw std::runtime_error(errmsg);
170 l1 = source->getDistance(*sample);
176 std::vector<int32_t> specids = this->
getProperty(
"SpectrumIDs");
179 size_t numHist =
workspace->getNumberHistograms();
180 for (
size_t i = 0; i < numHist; ++i) {
181 specids.emplace_back(
workspace->getSpectrum(i).getSpectrumNo());
187 const vector<int> vec_detids =
getProperty(
"DetectorIDs");
188 const bool renameDetID(!vec_detids.empty());
191 const std::vector<double> l2s = this->
getProperty(
"L2");
192 const std::vector<double> tths = this->
getProperty(
"Polar");
193 std::vector<double> phis = this->
getProperty(
"Azimuthal");
197 throw std::runtime_error(
"User must specify L2 for all spectra. ");
200 throw std::runtime_error(
"User must specify 2theta for all spectra.");
205 phis.assign(l2s.size(), 0.);
209 for (
size_t ib = 0; ib < l2s.size(); ib++) {
210 g_log.
information() <<
"Detector " << specids[ib] <<
" L2 = " << l2s[ib] <<
" 2Theta = " << tths[ib] <<
'\n';
211 if (specids[ib] < 0) {
213 stringstream errmsgss;
214 errmsgss <<
"Spectrum ID[" << ib <<
"] = " << specids[ib] <<
": cannot be less than 0.";
215 throw std::invalid_argument(errmsgss.str());
217 if (l2s[ib] <= 0.0) {
218 throw std::invalid_argument(
"L2 cannot be less or equal to 0");
223 const auto spec2indexmap =
workspace->getSpectrumToWorkspaceIndexMap();
226 size_t nspec =
workspace->getNumberHistograms();
230 std::vector<double> storL2s(nspec, 0.);
231 std::vector<double> stor2Thetas(nspec, 0.);
232 std::vector<double> storPhis(nspec, 0.);
233 vector<int> storDetIDs(nspec, 0);
236 for (
size_t i = 0; i < specids.size(); i++) {
238 auto it = spec2indexmap.find(specids[i]);
239 if (it == spec2indexmap.end()) {
241 errss <<
"Spectrum Number " << specids[i] <<
" is not present in the input workspace.";
243 throw std::runtime_error(errss.str());
247 size_t workspaceindex = it->second;
249 storL2s[workspaceindex] = l2s[i];
250 stor2Thetas[workspaceindex] = tths[i];
251 storPhis[workspaceindex] = phis[i];
253 storDetIDs[workspaceindex] = vec_detids[i];
255 g_log.
debug() <<
"workspace index = " << workspaceindex <<
" is for Spectrum " << specids[i] <<
'\n';
260 std::string instrumentName = std::string(
getProperty(
"InstrumentName"));
261 if (instrumentName.empty()) {
263 if (!originstrument) {
264 std::string errmsg(
"If there's no instrument associated with the input workspace, "
265 "then an instrument name must be specified.");
267 throw std::runtime_error(errmsg);
269 instrumentName = originstrument->getName();
273 auto instrument = std::make_shared<Geometry::Instrument>(instrumentName);
277 instrument->add(samplepos);
278 instrument->markAsSamplePos(samplepos);
279 samplepos->
setPos(0.0, 0.0, 0.0);
282 instrument->add(source);
283 instrument->markAsSource(source);
284 source->
setPos(0.0, 0.0, -1.0 * l1);
293 for (
size_t i = 0; i <
workspace->getNumberHistograms(); i++) {
298 newdetid = storDetIDs[i];
304 double l2 = storL2s[i];
305 double tth = stor2Thetas[i];
306 double phi = storPhis[i];
313 auto &spectrum =
workspace->getSpectrum(i);
315 g_log.
debug() <<
"Original spectrum " << spectrum.getSpectrumNo() <<
"has " << spectrum.getDetectorIDs().size()
318 spectrum.clearDetectorIDs();
319 spectrum.addDetectorID(newdetid);
321 instrument->markAsDetector(detector);
325 instrument->add(bank);
void setPos(double, double, double) override
Set the IComponent position, x, y, z respective to parent (if present)