/
DiffractionEventCalibrateDetectors.cpp
558 lines (489 loc) · 21.5 KB
/
DiffractionEventCalibrateDetectors.cpp
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 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 +
#include "MantidAlgorithms/DiffractionEventCalibrateDetectors.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/IFunction.h"
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/TextAxis.h"
#include "MantidAlgorithms/GSLFunctions.h"
#include "MantidDataObjects/EventList.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/GroupingWorkspace.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidGeometry/Instrument/RectangularDetector.h"
#include "MantidKernel/ArrayProperty.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidKernel/CPUTimer.h"
#include "MantidKernel/Exception.h"
#include "MantidKernel/UnitFactory.h"
#include <Poco/File.h>
#include <cmath>
#include <fstream>
#include <numeric>
#include <sstream>
namespace Mantid::Algorithms {
// Register the class into the algorithm factory
DECLARE_ALGORITHM(DiffractionEventCalibrateDetectors)
using namespace Kernel;
using namespace API;
using namespace Geometry;
using namespace DataObjects;
using Types::Core::DateAndTime;
/**
* The gsl_costFunction is optimized by GSL simplex
* @param v :: vector containing center position and rotations
* @param params :: names of detector, workspace, and instrument
*/
static double gsl_costFunction(const gsl_vector *v, void *params) {
double x, y, z, rotx, roty, rotz;
std::string detname, inname, outname, peakOpt, rb_param, groupWSName;
auto *p = reinterpret_cast<std::string *>(params);
detname = p[0];
inname = p[1];
outname = p[2];
peakOpt = p[3];
rb_param = p[4];
groupWSName = p[5];
x = gsl_vector_get(v, 0);
y = gsl_vector_get(v, 1);
z = gsl_vector_get(v, 2);
rotx = gsl_vector_get(v, 3);
roty = gsl_vector_get(v, 4);
rotz = gsl_vector_get(v, 5);
Mantid::Algorithms::DiffractionEventCalibrateDetectors u;
return u.intensity(x, y, z, rotx, roty, rotz, detname, inname, outname, peakOpt, rb_param, groupWSName);
}
/**
* The movedetector function changes detector position and angles
* @param x :: The shift along the X-axis
* @param y :: The shift along the Y-axis
* @param z :: The shift along the Z-axis
* @param rotx :: The rotation around the X-axis
* @param roty :: The rotation around the Y-axis
* @param rotz :: The rotation around the Z-axis
* @param detname :: The detector name
* @param inputW :: The workspace
*/
void DiffractionEventCalibrateDetectors::movedetector(double x, double y, double z, double rotx, double roty,
double rotz, const std::string &detname,
const EventWorkspace_sptr &inputW) {
auto alg1 = createChildAlgorithm("MoveInstrumentComponent");
alg1->setProperty<EventWorkspace_sptr>("Workspace", inputW);
alg1->setPropertyValue("ComponentName", detname);
// Move in cm for small shifts
alg1->setProperty("X", x * 0.01);
alg1->setProperty("Y", y * 0.01);
alg1->setProperty("Z", z * 0.01);
alg1->setPropertyValue("RelativePosition", "1");
alg1->executeAsChildAlg();
auto algx = createChildAlgorithm("RotateInstrumentComponent");
algx->setProperty<EventWorkspace_sptr>("Workspace", inputW);
algx->setPropertyValue("ComponentName", detname);
algx->setProperty("X", 1.0);
algx->setProperty("Y", 0.0);
algx->setProperty("Z", 0.0);
algx->setProperty("Angle", rotx);
algx->setPropertyValue("RelativeRotation", "1");
algx->executeAsChildAlg();
auto algy = createChildAlgorithm("RotateInstrumentComponent");
algy->setProperty<EventWorkspace_sptr>("Workspace", inputW);
algy->setPropertyValue("ComponentName", detname);
algy->setProperty("X", 0.0);
algy->setProperty("Y", 1.0);
algy->setProperty("Z", 0.0);
algy->setProperty("Angle", roty);
algy->setPropertyValue("RelativeRotation", "1");
algy->executeAsChildAlg();
auto algz = createChildAlgorithm("RotateInstrumentComponent");
algz->setProperty<EventWorkspace_sptr>("Workspace", inputW);
algz->setPropertyValue("ComponentName", detname);
algz->setProperty("X", 0.0);
algz->setProperty("Y", 0.0);
algz->setProperty("Z", 1.0);
algz->setProperty("Angle", rotz);
algz->setPropertyValue("RelativeRotation", "1");
algz->executeAsChildAlg();
}
/**
* The intensity function calculates the intensity as a function of detector
* position and angles
* @param x :: The shift along the X-axis
* @param y :: The shift along the Y-axis
* @param z :: The shift along the Z-axis
* @param rotx :: The rotation around the X-axis
* @param roty :: The rotation around the Y-axis
* @param rotz :: The rotation around the Z-axis
* @param detname :: The detector name
* @param inname :: The workspace name
* @param outname :: The workspace name
* @param peakOpt :: Location of optimized peak
* @param rb_param :: Bin boundary string
* @param groupWSName :: GroupingWorkspace for this detector only.
* */
double DiffractionEventCalibrateDetectors::intensity(double x, double y, double z, double rotx, double roty,
double rotz, const std::string &detname, const std::string &inname,
const std::string &outname, const std::string &peakOpt,
const std::string &rb_param, const std::string &groupWSName) {
EventWorkspace_sptr inputW =
std::dynamic_pointer_cast<EventWorkspace>(AnalysisDataService::Instance().retrieve(inname));
CPUTimer tim;
movedetector(x, y, z, rotx, roty, rotz, detname, inputW);
g_log.debug() << tim << " to movedetector()\n";
auto alg3 = createChildAlgorithm("ConvertUnits");
alg3->setProperty<EventWorkspace_sptr>("InputWorkspace", inputW);
alg3->setPropertyValue("OutputWorkspace", outname);
alg3->setPropertyValue("Target", "dSpacing");
alg3->executeAsChildAlg();
MatrixWorkspace_sptr outputW = alg3->getProperty("OutputWorkspace");
g_log.debug() << tim << " to ConvertUnits\n";
auto alg4 = createChildAlgorithm("DiffractionFocussing");
alg4->setProperty<MatrixWorkspace_sptr>("InputWorkspace", outputW);
alg4->setProperty<MatrixWorkspace_sptr>("OutputWorkspace", outputW);
alg4->setPropertyValue("GroupingFileName", "");
alg4->setPropertyValue("GroupingWorkspace", groupWSName);
alg4->executeAsChildAlg();
outputW = alg4->getProperty("OutputWorkspace");
// Remove file
g_log.debug() << tim << " to DiffractionFocussing\n";
auto alg5 = createChildAlgorithm("Rebin");
alg5->setProperty<MatrixWorkspace_sptr>("InputWorkspace", outputW);
alg5->setProperty<MatrixWorkspace_sptr>("OutputWorkspace", outputW);
alg5->setPropertyValue("Params", rb_param);
alg5->executeAsChildAlg();
outputW = alg5->getProperty("OutputWorkspace");
g_log.debug() << tim << " to Rebin\n";
// Find point of peak centre
const MantidVec &yValues = outputW->readY(0);
auto it = std::max_element(yValues.begin(), yValues.end());
double peakHeight = *it;
if (peakHeight == 0)
return -0.000;
double peakLoc = outputW->readX(0)[it - yValues.begin()];
IAlgorithm_sptr fit_alg;
try {
// set the ChildAlgorithm no to log as this will be run once per spectra
fit_alg = createChildAlgorithm("Fit", -1, -1, false);
} catch (Exception::NotFoundError &) {
g_log.error("Can't locate Fit algorithm");
throw;
}
std::ostringstream fun_str;
fun_str << "name=Gaussian,Height=" << peakHeight << ",Sigma=0.01,PeakCentre=" << peakLoc;
fit_alg->setProperty("Function", fun_str.str());
fit_alg->setProperty("InputWorkspace", outputW);
fit_alg->setProperty("WorkspaceIndex", 0);
fit_alg->setProperty("StartX", outputW->readX(0)[0]);
fit_alg->setProperty("EndX", outputW->readX(0)[outputW->blocksize()]);
fit_alg->setProperty("MaxIterations", 200);
fit_alg->setProperty("Output", "fit");
fit_alg->executeAsChildAlg();
g_log.debug() << tim << " to Fit\n";
std::vector<double> params; // = fit_alg->getProperty("Parameters");
Mantid::API::IFunction_sptr fun_res = fit_alg->getProperty("Function");
for (size_t i = 0; i < fun_res->nParams(); ++i) {
params.emplace_back(fun_res->getParameter(i));
}
peakHeight = params[0];
peakLoc = params[1];
movedetector(-x, -y, -z, -rotx, -roty, -rotz, detname, inputW);
g_log.debug() << tim << " to movedetector()\n";
// Optimize C/peakheight + |peakLoc-peakOpt| where C is scaled by number of
// events
EventWorkspace_const_sptr inputE = std::dynamic_pointer_cast<const EventWorkspace>(inputW);
return (static_cast<int>(inputE->getNumberEvents()) / 1.e6) / peakHeight +
std::fabs(peakLoc - boost::lexical_cast<double>(peakOpt));
}
/** Initialisation method
*/
void DiffractionEventCalibrateDetectors::init() {
declareProperty(std::make_unique<WorkspaceProperty<EventWorkspace>>("InputWorkspace", "", Direction::Input,
std::make_shared<InstrumentValidator>()),
"The workspace containing the geometry to be calibrated.");
declareProperty("Params", "",
"A comma separated list of first bin boundary, width, last "
"bin boundary. Optionally "
"this can be followed by a comma and more widths and last "
"boundary pairs. "
"Use bin boundaries close to peak you wish to maximize. "
"Negative width values indicate logarithmic binning.");
auto mustBePositive = std::make_shared<BoundedValidator<int>>();
declareProperty("MaxIterations", 10, mustBePositive,
"Stop after this number of iterations if a good fit is not found");
auto dblmustBePositive = std::make_shared<BoundedValidator<double>>();
declareProperty("LocationOfPeakToOptimize", 2.0308, dblmustBePositive,
"Optimize this location of peak by moving detectors");
declareProperty(std::make_unique<API::FileProperty>("DetCalFilename", "", API::FileProperty::Save, ".DetCal"),
"The output filename of the ISAW DetCal file");
declareProperty(std::make_unique<PropertyWithValue<std::string>>("BankName", "", Direction::Input),
"Optional: To only calibrate one bank. Any bank whose name does not "
"match the given string will have no events.");
// Disable default gsl error handler (which is to call abort!)
gsl_set_error_handler_off();
}
/** Executes the algorithm
*
* @throw runtime_error Thrown if algorithm cannot execute
*/
void DiffractionEventCalibrateDetectors::exec() {
// Try to retrieve optional properties
const int maxIterations = getProperty("MaxIterations");
const double peakOpt = getProperty("LocationOfPeakToOptimize");
// Get the input workspace
EventWorkspace_sptr inputW = getProperty("InputWorkspace");
// retrieve the properties
const std::string rb_params = getProperty("Params");
// Get some stuff from the input workspace
// We make a copy of the instrument since we will be moving detectors in
// `inputW` but want to access original positions (etc.) via `detList` below.
const auto &dummyW = create<EventWorkspace>(*inputW, 1, inputW->binEdges(0));
Instrument_const_sptr inst = dummyW->getInstrument();
// Build a list of Rectangular Detectors
std::vector<std::shared_ptr<RectangularDetector>> detList;
// --------- Loading only one bank ----------------------------------
std::string onebank = getProperty("BankName");
bool doOneBank = (!onebank.empty());
for (int i = 0; i < inst->nelements(); i++) {
std::shared_ptr<RectangularDetector> det;
std::shared_ptr<ICompAssembly> assem;
std::shared_ptr<ICompAssembly> assem2;
det = std::dynamic_pointer_cast<RectangularDetector>((*inst)[i]);
if (det) {
if (det->getName() == onebank)
detList.emplace_back(det);
if (!doOneBank)
detList.emplace_back(det);
} else {
// Also, look in the first sub-level for RectangularDetectors (e.g. PG3).
// We are not doing a full recursive search since that will be very long
// for lots of pixels.
assem = std::dynamic_pointer_cast<ICompAssembly>((*inst)[i]);
if (assem) {
for (int j = 0; j < assem->nelements(); j++) {
det = std::dynamic_pointer_cast<RectangularDetector>((*assem)[j]);
if (det) {
if (det->getName() == onebank)
detList.emplace_back(det);
if (!doOneBank)
detList.emplace_back(det);
} else {
// Also, look in the second sub-level for RectangularDetectors (e.g.
// PG3).
// We are not doing a full recursive search since that will be very
// long for lots of pixels.
assem2 = std::dynamic_pointer_cast<ICompAssembly>((*assem)[j]);
if (assem2) {
for (int k = 0; k < assem2->nelements(); k++) {
det = std::dynamic_pointer_cast<RectangularDetector>((*assem2)[k]);
if (det) {
if (det->getName() == onebank)
detList.emplace_back(det);
if (!doOneBank)
detList.emplace_back(det);
}
}
}
}
}
}
}
}
// set-up minimizer
std::string inname = getProperty("InputWorkspace");
std::string outname = inname + "2"; // getProperty("OutputWorkspace");
auto algS = createChildAlgorithm("SortEvents");
algS->setProperty("InputWorkspace", inputW);
algS->setPropertyValue("SortBy", "X Value");
algS->executeAsChildAlg();
// Write DetCal File
std::string filename = getProperty("DetCalFilename");
std::fstream outfile;
outfile.open(filename.c_str(), std::ios::out);
if (detList.size() > 1) {
outfile << "#\n";
outfile << "# Mantid Optimized .DetCal file for SNAP with TWO detector "
"panels\n";
outfile << "# Old Panel, nominal size and distance at -90 degrees.\n";
outfile << "# New Panel, nominal size and distance at +90 degrees.\n";
outfile << "#\n";
outfile << "# Lengths are in centimeters.\n";
outfile << "# Base and up give directions of unit vectors for a local\n";
outfile << "# x,y coordinate system on the face of the detector.\n";
outfile << "#\n";
outfile << "# " << DateAndTime::getCurrentTime().toFormattedString("%c") << "\n";
outfile << "#\n";
outfile << "6 L1 T0_SHIFT\n";
IComponent_const_sptr source = inst->getSource();
IComponent_const_sptr sample = inst->getSample();
outfile << "7 " << source->getDistance(*sample) * 100 << " 0\n";
outfile << "4 DETNUM NROWS NCOLS WIDTH HEIGHT DEPTH DETD "
"CenterX CenterY CenterZ BaseX BaseY BaseZ "
"UpX UpY UpZ\n";
}
Progress prog(this, 0.0, 1.0, detList.size());
for (int det = 0; det < static_cast<int>(detList.size()); det++) {
std::string par[6];
par[0] = detList[det]->getName();
par[1] = inname;
par[2] = outname;
std::ostringstream strpeakOpt;
strpeakOpt << peakOpt;
par[3] = strpeakOpt.str();
par[4] = rb_params;
// --- Create a GroupingWorkspace for this detector name ------
CPUTimer tim;
auto alg2 = AlgorithmFactory::Instance().create("CreateGroupingWorkspace", 1);
alg2->initialize();
alg2->setProperty("InputWorkspace", inputW);
alg2->setPropertyValue("GroupNames", detList[det]->getName());
std::string groupWSName = "group_" + detList[det]->getName();
alg2->setPropertyValue("OutputWorkspace", groupWSName);
alg2->executeAsChildAlg();
par[5] = groupWSName;
std::cout << tim << " to CreateGroupingWorkspace\n";
const gsl_multimin_fminimizer_type *T = gsl_multimin_fminimizer_nmsimplex;
gsl_vector *ss, *x;
gsl_multimin_function minex_func;
// finally do the fitting
int nopt = 6;
int iter = 0;
int status = 0;
/* Starting point */
x = gsl_vector_alloc(nopt);
gsl_vector_set(x, 0, 0.0);
gsl_vector_set(x, 1, 0.0);
gsl_vector_set(x, 2, 0.0);
gsl_vector_set(x, 3, 0.0);
gsl_vector_set(x, 4, 0.0);
gsl_vector_set(x, 5, 0.0);
/* Set initial step sizes to 0.1 */
ss = gsl_vector_alloc(nopt);
gsl_vector_set_all(ss, 0.1);
/* Initialize method and iterate */
minex_func.n = nopt;
minex_func.f = &Mantid::Algorithms::gsl_costFunction;
minex_func.params = ∥
gsl_multimin_fminimizer *s = gsl_multimin_fminimizer_alloc(T, nopt);
gsl_multimin_fminimizer_set(s, &minex_func, x, ss);
do {
iter++;
status = gsl_multimin_fminimizer_iterate(s);
if (status)
break;
double size = gsl_multimin_fminimizer_size(s);
status = gsl_multimin_test_size(size, 1e-2);
} while (status == GSL_CONTINUE && iter < maxIterations && s->fval != -0.000);
// Output summary to log file
if (s->fval != -0.000)
movedetector(gsl_vector_get(s->x, 0), gsl_vector_get(s->x, 1), gsl_vector_get(s->x, 2), gsl_vector_get(s->x, 3),
gsl_vector_get(s->x, 4), gsl_vector_get(s->x, 5), par[0], getProperty("InputWorkspace"));
else {
gsl_vector_set(s->x, 0, 0.0);
gsl_vector_set(s->x, 1, 0.0);
gsl_vector_set(s->x, 2, 0.0);
gsl_vector_set(s->x, 3, 0.0);
gsl_vector_set(s->x, 4, 0.0);
gsl_vector_set(s->x, 5, 0.0);
}
std::string reportOfDiffractionEventCalibrateDetectors = gsl_strerror(status);
if (s->fval == -0.000)
reportOfDiffractionEventCalibrateDetectors = "No events";
g_log.information() << "Detector = " << det << "\n"
<< "Method used = "
<< "Simplex"
<< "\n"
<< "Iteration = " << iter << "\n"
<< "Status = " << reportOfDiffractionEventCalibrateDetectors << "\n"
<< "Minimize PeakLoc-" << peakOpt << " = " << s->fval << "\n";
// Move in cm for small shifts
g_log.information() << "Move (X) = " << gsl_vector_get(s->x, 0) * 0.01 << " \n";
g_log.information() << "Move (Y) = " << gsl_vector_get(s->x, 1) * 0.01 << " \n";
g_log.information() << "Move (Z) = " << gsl_vector_get(s->x, 2) * 0.01 << " \n";
g_log.information() << "Rotate (X) = " << gsl_vector_get(s->x, 3) << " \n";
g_log.information() << "Rotate (Y) = " << gsl_vector_get(s->x, 4) << " \n";
g_log.information() << "Rotate (Z) = " << gsl_vector_get(s->x, 5) << " \n";
Kernel::V3D CalCenter =
V3D(gsl_vector_get(s->x, 0) * 0.01, gsl_vector_get(s->x, 1) * 0.01, gsl_vector_get(s->x, 2) * 0.01);
Kernel::V3D Center = detList[det]->getPos() + CalCenter;
int pixmax = detList[det]->xpixels() - 1;
int pixmid = (detList[det]->ypixels() - 1) / 2;
BoundingBox box;
detList[det]->getAtXY(pixmax, pixmid)->getBoundingBox(box);
double baseX = box.xMax();
double baseY = box.yMax();
double baseZ = box.zMax();
Kernel::V3D Base = V3D(baseX, baseY, baseZ) + CalCenter;
pixmid = (detList[det]->xpixels() - 1) / 2;
pixmax = detList[det]->ypixels() - 1;
detList[det]->getAtXY(pixmid, pixmax)->getBoundingBox(box);
double upX = box.xMax();
double upY = box.yMax();
double upZ = box.zMax();
Kernel::V3D Up = V3D(upX, upY, upZ) + CalCenter;
Base -= Center;
Up -= Center;
// Rotate around x
baseX = Base[0];
baseY = Base[1];
baseZ = Base[2];
double deg2rad = M_PI / 180.0;
double angle = gsl_vector_get(s->x, 3) * deg2rad;
Base = V3D(baseX, baseY * cos(angle) - baseZ * sin(angle), baseY * sin(angle) + baseZ * cos(angle));
upX = Up[0];
upY = Up[1];
upZ = Up[2];
Up = V3D(upX, upY * cos(angle) - upZ * sin(angle), upY * sin(angle) + upZ * cos(angle));
// Rotate around y
baseX = Base[0];
baseY = Base[1];
baseZ = Base[2];
angle = gsl_vector_get(s->x, 4) * deg2rad;
Base = V3D(baseZ * sin(angle) + baseX * cos(angle), baseY, baseZ * cos(angle) - baseX * sin(angle));
upX = Up[0];
upY = Up[1];
upZ = Up[2];
Up = V3D(upZ * cos(angle) - upX * sin(angle), upY, upZ * sin(angle) + upX * cos(angle));
// Rotate around z
baseX = Base[0];
baseY = Base[1];
baseZ = Base[2];
angle = gsl_vector_get(s->x, 5) * deg2rad;
Base = V3D(baseX * cos(angle) - baseY * sin(angle), baseX * sin(angle) + baseY * cos(angle), baseZ);
upX = Up[0];
upY = Up[1];
upZ = Up[2];
Up = V3D(upX * cos(angle) - upY * sin(angle), upX * sin(angle) + upY * cos(angle), upZ);
Base.normalize();
Up.normalize();
Center *= 100.0;
// << det+1 << " "
outfile << "5 " << detList[det]->getName().substr(4) << " " << detList[det]->xpixels() << " "
<< detList[det]->ypixels() << " " << 100.0 * detList[det]->xsize() << " " << 100.0 * detList[det]->ysize()
<< " "
<< "0.2000"
<< " " << Center.norm() << " ";
Center.write(outfile);
outfile << " ";
Base.write(outfile);
outfile << " ";
Up.write(outfile);
outfile << "\n";
// clean up dynamically allocated gsl stuff
gsl_vector_free(x);
gsl_vector_free(ss);
gsl_multimin_fminimizer_free(s);
// Remove the now-unneeded grouping workspace
AnalysisDataService::Instance().remove(groupWSName);
prog.report(detList[det]->getName());
}
// Closing
outfile.close();
}
} // namespace Mantid::Algorithms