Mantid
Loading...
Searching...
No Matches
GridDetector.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
20#include "MantidKernel/Matrix.h"
21#include <algorithm>
22#include <boost/regex.hpp>
23#include <memory>
24#include <ostream>
25#include <stdexcept>
26#include <utility>
27
28namespace Mantid::Geometry {
29
30using Kernel::Matrix;
31using Kernel::V3D;
32
38 : CompAssembly(base, map), IObjComponent(nullptr), m_gridBase(base), m_minDetId(0), m_maxDetId(0) {
39 init();
41}
42
52GridDetector::GridDetector(const std::string &n, IComponent *reference)
53 : CompAssembly(n, reference), IObjComponent(nullptr), m_gridBase(nullptr), m_minDetId(0), m_maxDetId(0) {
54 init();
55 this->setName(n);
57}
58
59bool GridDetector::compareName(const std::string &proposedMatch) {
60 static const boost::regex exp("grid_?detector", boost::regex::icase);
61 return boost::regex_match(proposedMatch, exp);
62}
63
66 m_xsize = m_ysize = m_zsize = 0;
68 m_xstep = m_ystep = m_zstep = 0;
70 m_idstart = 0;
71 m_idfillbyfirst_y = false;
72 m_idstepbyrow = 0;
73 m_idstep = 0;
74}
75
80GridDetector *GridDetector::clone() const { return new GridDetector(*this); }
81
82//-------------------------------------------------------------------------------------------------
94std::shared_ptr<Detector> GridDetector::getAtXYZ(const int x, const int y, const int z) const {
95 if ((xpixels() <= 0) || (ypixels() <= 0))
96 throw std::runtime_error("GridDetector::getAtXY: invalid X or Y "
97 "width set in the object.");
98 if ((x < 0) || (x >= xpixels()))
99 throw std::runtime_error("GridDetector::getAtXYZ: x specified is out of range.");
100 if ((y < 0) || (y >= ypixels()))
101 throw std::runtime_error("GridDetector::getAtXYZ: y specified is out of range.");
102 if (zpixels() > 0) {
103 if ((z < 0) || (z >= zpixels()))
104 throw std::runtime_error("GridDetector::getAtXYZ: z specified is out of range.");
105 }
106
107 // Find the index and return that.
108 std::shared_ptr<ICompAssembly> xCol;
109 // Get to layer
110 if (this->zpixels() > 0) {
111 auto zLayer = std::dynamic_pointer_cast<ICompAssembly>(this->getChild(z));
112 if (!zLayer)
113 throw std::runtime_error("GridDetector::getAtXYZ: z specified is out of range.");
114
115 xCol = std::dynamic_pointer_cast<ICompAssembly>(zLayer->getChild(x));
116 } else
117 xCol = std::dynamic_pointer_cast<ICompAssembly>(this->getChild(x));
118
119 if (!xCol)
120 throw std::runtime_error("GridDetector::getAtXYZ: x specified is out of range.");
121 return std::dynamic_pointer_cast<Detector>(xCol->getChild(y));
122}
123
124namespace {
125detid_t getFillFirstZ(const GridDetector *me, int x, int y, int z) {
126 if (me->idFillOrder()[1] == 'y')
127 return me->idstart() + z * me->idstep() + y * me->idstepbyrow() + x * (me->ypixels() * me->idstepbyrow());
128 else
129 return me->idstart() + z * me->idstep() + x * me->idstepbyrow() + y * (me->xpixels() * me->idstepbyrow());
130}
131
132detid_t getFillFirstY(const GridDetector *me, int x, int y, int z) {
133 if (me->idFillOrder()[1] == 'x')
134 return me->idstart() + y * me->idstep() + x * me->idstepbyrow() + z * (me->xpixels() * me->idstepbyrow());
135 else
136 return me->idstart() + y * me->idstep() + z * me->idstepbyrow() + x * (me->zpixels() * me->idstepbyrow());
137}
138
139detid_t getFillFirstX(const GridDetector *me, int x, int y, int z) {
140 if (me->idFillOrder()[1] == 'y')
141 return me->idstart() + x * me->idstep() + y * me->idstepbyrow() + z * (me->ypixels() * me->idstepbyrow());
142 else
143 return me->idstart() + x * me->idstep() + z * me->idstepbyrow() + y * (me->zpixels() * me->idstepbyrow());
144}
145} // end namespace
146
147//-------------------------------------------------------------------------------------------------
158detid_t GridDetector::getDetectorIDAtXYZ(const int x, const int y, const int z) const {
159 const GridDetector *me = this;
160 if (isParametrized())
161 me = this->m_gridBase;
162
163 if (me->idFillOrder()[0] == 'z')
164 return getFillFirstZ(me, x, y, z);
165 else if (me->idFillOrder()[0] == 'y')
166 return getFillFirstY(me, x, y, z);
167 else
168 return getFillFirstX(me, x, y, z);
169}
170
171namespace {
172std::tuple<int, int, int> getXYZFillFirstZ(const GridDetector *me, int col, int id) {
173 if (me->idFillOrder()[1] == 'y') {
174 int row = (id / me->idstepbyrow()) % me->ypixels();
175 auto layer = (id / me->idstepbyrow()) / me->ypixels();
176 return std::tuple<int, int, int>(layer, row, col);
177 } else {
178 int row = (id / me->idstepbyrow()) % me->xpixels();
179 auto layer = (id / me->idstepbyrow()) / me->xpixels();
180 return std::tuple<int, int, int>(row, layer, col);
181 }
182}
183
184std::tuple<int, int, int> getXYZFillFirstY(const GridDetector *me, int col, int id) {
185 if (me->idFillOrder()[1] == 'z') {
186 int row = (id / me->idstepbyrow()) % me->zpixels();
187 auto layer = (id / me->idstepbyrow()) / me->zpixels();
188 return std::tuple<int, int, int>(layer, col, row);
189 } else {
190 int row = (id / me->idstepbyrow()) % me->xpixels();
191 auto layer = (id / me->idstepbyrow()) / me->xpixels();
192 return std::tuple<int, int, int>(row, col, layer);
193 }
194}
195
196std::tuple<int, int, int> getXYZFillFirstX(const GridDetector *me, int col, int id) {
197 if (me->idFillOrder()[1] == 'y') {
198 int row = (id / me->idstepbyrow()) % me->ypixels();
199 auto layer = (id / me->idstepbyrow()) / me->ypixels();
200 return std::tuple<int, int, int>(col, row, layer);
201 } else {
202 int row = (id / me->idstepbyrow()) % me->zpixels();
203 auto layer = (id / me->idstepbyrow()) / me->zpixels();
204 return std::tuple<int, int, int>(col, layer, row);
205 }
206}
207} // end namespace
208
209//-------------------------------------------------------------------------------------------------
215std::tuple<int, int, int> GridDetector::getXYZForDetectorID(const detid_t detectorID) const {
216 const GridDetector *me = this;
217 if (isParametrized())
218 me = this->m_gridBase;
219
220 int id = detectorID - me->m_idstart;
221 if ((me->m_idstepbyrow == 0) || (me->m_idstep == 0))
222 return std::tuple<int, int, int>(-1, -1, -1);
223 int col = (id % me->m_idstepbyrow) / me->m_idstep;
224
225 if (me->m_idFillOrder[0] == 'z')
226 return getXYZFillFirstZ(me, col, id);
227 else if (me->m_idFillOrder[0] == 'y')
228 return getXYZFillFirstY(me, col, id);
229 else
230 return getXYZFillFirstX(me, col, id);
231}
232
233//-------------------------------------------------------------------------------------------------
237 if (isParametrized())
238 return m_gridBase->xpixels();
239 else
240 return this->m_xpixels;
241}
242
243//-------------------------------------------------------------------------------------------------
247 if (isParametrized())
248 return m_gridBase->ypixels();
249 else
250 return this->m_ypixels;
251}
252
253//-------------------------------------------------------------------------------------------------
257 if (isParametrized())
258 return m_gridBase->zpixels();
259 else
260 return this->m_zpixels;
261}
262
263//-------------------------------------------------------------------------------------------------
265double GridDetector::xstep() const {
266 if (isParametrized()) {
267 double scaling = 1.0;
268 if (m_map->contains(m_gridBase, "scalex"))
269 scaling = m_map->get(m_gridBase, "scalex")->value<double>();
270 return m_gridBase->xstep() * scaling;
271 } else
272 return this->m_xstep;
273}
274
275//-------------------------------------------------------------------------------------------------
277double GridDetector::ystep() const {
278 if (isParametrized()) {
279 double scaling = 1.0;
280 if (m_map->contains(m_gridBase, "scaley"))
281 scaling = m_map->get(m_gridBase, "scaley")->value<double>();
282 return m_gridBase->ystep() * scaling;
283 } else
284 return this->m_ystep;
285}
286
287//-------------------------------------------------------------------------------------------------
289double GridDetector::zstep() const {
290 if (isParametrized()) {
291 double scaling = 1.0;
292 if (m_map->contains(m_gridBase, "scalez"))
293 scaling = m_map->get(m_gridBase, "scalez")->value<double>();
294 return m_gridBase->zstep() * scaling;
295 } else
296 return this->m_zstep;
297}
298
299//-------------------------------------------------------------------------------------------------
301double GridDetector::xstart() const {
302 if (isParametrized()) {
303 double scaling = 1.0;
304 if (m_map->contains(m_gridBase, "scalex"))
305 scaling = m_map->get(m_gridBase, "scalex")->value<double>();
306 return m_gridBase->xstart() * scaling;
307 } else
308 return this->m_xstart;
309}
310
311//-------------------------------------------------------------------------------------------------
313double GridDetector::ystart() const {
314 if (isParametrized()) {
315 double scaling = 1.0;
316 if (m_map->contains(m_gridBase, "scaley"))
317 scaling = m_map->get(m_gridBase, "scaley")->value<double>();
318 return m_gridBase->ystart() * scaling;
319 } else
320 return this->m_ystart;
321}
322
323//-------------------------------------------------------------------------------------------------
325double GridDetector::zstart() const {
326 if (isParametrized()) {
327 double scaling = 1.0;
328 if (m_map->contains(m_gridBase, "scalez"))
329 scaling = m_map->get(m_gridBase, "scalez")->value<double>();
330 return m_gridBase->zstart() * scaling;
331 } else
332 return this->m_zstart;
333}
334
335//-------------------------------------------------------------------------------------------------
337double GridDetector::xsize() const {
338 if (isParametrized()) {
339 double scaling = 1.0;
340 if (m_map->contains(m_gridBase, "scalex"))
341 scaling = m_map->get(m_gridBase, "scalex")->value<double>();
342 return m_gridBase->xsize() * scaling;
343 } else
344 return this->m_xsize;
345}
346
347//-------------------------------------------------------------------------------------------------
349double GridDetector::ysize() const {
350 if (isParametrized()) {
351 double scaling = 1.0;
352 if (m_map->contains(m_gridBase, "scaley"))
353 scaling = m_map->get(m_gridBase, "scaley")->value<double>();
354 return m_gridBase->ysize() * scaling;
355 } else
356 return this->m_ysize;
357}
358
359//-------------------------------------------------------------------------------------------------
361double GridDetector::zsize() const {
362 if (isParametrized()) {
363 double scaling = 1.0;
364 if (m_map->contains(m_gridBase, "scalez"))
365 scaling = m_map->get(m_gridBase, "scalez")->value<double>();
366 return m_gridBase->zsize() * scaling;
367 } else
368 return this->m_zsize;
369}
370
371//-------------------------------------------------------------------------------------------------
374 if (isParametrized())
375 return m_gridBase->idstart();
376 else
377 return this->m_idstart;
378}
379
380//-------------------------------------------------------------------------------------------------
383 if (isParametrized())
384 return m_gridBase->idfillbyfirst_y();
385 else
386 return this->m_idfillbyfirst_y;
387}
388
390std::string GridDetector::idFillOrder() const {
391 if (isParametrized())
392 return m_gridBase->idFillOrder();
393 else
394 return this->m_idFillOrder;
395}
396
397//-------------------------------------------------------------------------------------------------
400 if (isParametrized())
401 return m_gridBase->idstepbyrow();
402 else
403 return this->m_idstepbyrow;
404}
405
406//-------------------------------------------------------------------------------------------------
409 if (isParametrized())
410 return m_gridBase->idstep();
411 else
412 return this->m_idstep;
413}
414
415//-------------------------------------------------------------------------------------------------
426 if (isParametrized()) {
427 double scalex = 1.0;
428 if (m_map->contains(m_gridBase, "scalex"))
429 scalex = m_map->get(m_gridBase, "scalex")->value<double>();
430 double scaley = 1.0;
431 if (m_map->contains(m_gridBase, "scaley"))
432 scaley = m_map->get(m_gridBase, "scaley")->value<double>();
433 double scalez = 1.0;
434 if (m_map->contains(m_gridBase, "scalez"))
435 scalez = m_map->get(m_gridBase, "scalez")->value<double>();
436 return m_gridBase->getRelativePosAtXYZ(x, y, z) * V3D(scalex, scaley, scalez);
437 } else
438 return V3D(m_xstart + m_xstep * x, m_ystart + m_ystep * y, m_zstart + m_zstep * z);
439}
440
441void GridDetector::createLayer(const std::string &name, CompAssembly *parent, int iz, int &minDetID, int &maxDetID) {
442 const double z = m_zstart + iz * m_zstep;
443 const std::string z_pixel_str = (m_zpixels > 0) ? "," + std::to_string(iz) + ")" : ")";
444 const std::string z_layer_str = (m_zpixels > 0) ? name + "(z=" + std::to_string(iz) + ",x=" : name + "(x=";
445 for (int ix = 0; ix < m_xpixels; ++ix) {
446 const std::string x_pixel_str = name + "(" + std::to_string(ix) + ",";
447 const std::string name_layer = z_layer_str + std::to_string(ix) + ")";
448
449 // Create an ICompAssembly for each x-column
450 auto *xColumn = new CompAssembly(name_layer, parent);
451
452 const double x = m_xstart + ix * m_xstep;
453 for (int iy = 0; iy < m_ypixels; ++iy) {
454 // Make the name
455 const std::string name_pixel = x_pixel_str + std::to_string(iy) + z_pixel_str;
456
457 // Calculate its id and set it.
458 const auto id = this->getDetectorIDAtXYZ(ix, iy, iz);
459
460 // minimum grid detector id
461 if (id < minDetID) {
462 minDetID = id;
463 }
464 // maximum grid detector id
465 if (id > maxDetID) {
466 maxDetID = id;
467 }
468 // Create the detector from the given id & shape and with xColumn as the parent
469 auto *detector =
470 new GridDetectorPixel(name_pixel, id, m_shape, xColumn, this, size_t(ix), size_t(iy), size_t(iz));
471
472 const double y = m_ystart + iy * m_ystep;
473 // Translate (relative to parent). This gives the un-parametrized position
474 detector->translate(x, y, z);
475
476 // Add it to the x-column
477 xColumn->add(detector);
478 }
479 }
480}
481
482bool checkValidOrderString(const std::string &order) {
483 static const boost::regex exp("xyz|xzy|yzx|yxz|zyx|zxy");
484
485 return boost::regex_match(order, exp);
486}
487
489 // Some safety checks
491 throw std::invalid_argument(
492 "GridDetector::initialize(): order string should only comprise exactly 3 letters x, y, and z in any order.");
493 if (m_xpixels <= 0)
494 throw std::invalid_argument("GridDetector::initialize(): xpixels should be > 0");
495 if (m_ypixels <= 0)
496 throw std::invalid_argument("GridDetector::initialize(): ypixels should be > 0");
497}
498
499void GridDetector::initializeValues(std::shared_ptr<IObject> shape, int xpixels, double xstart, double xstep,
500 int ypixels, double ystart, double ystep, int zpixels, double zstart, double zstep,
501 int idstart, const std::string &idFillOrder, int idstepbyrow, int idstep) {
502
512 m_xstep = xstep;
513 m_ystep = ystep;
514 m_zstep = zstep;
515 m_shape = std::move(shape);
516
520 m_idfillbyfirst_y = idFillOrder[0] == 'y';
527
529}
530
531//-------------------------------------------------------------------------------------------------
565void GridDetector::initialize(std::shared_ptr<IObject> shape, int xpixels, double xstart, double xstep, int ypixels,
566 double ystart, double ystep, int zpixels, double zstart, double zstep, int idstart,
567 const std::string &idFillOrder, int idstepbyrow, int idstep) {
568
569 if (isParametrized())
570 throw std::runtime_error("GridDetector::initialize() called for a parametrized GridDetector");
571
574
575 std::string name = this->getName();
576 int minDetId = idstart, maxDetId = idstart;
577 // Loop through all the pixels
578 if (m_zpixels > 0) {
579 for (int iz = 0; iz < m_zpixels; ++iz) {
580 // Create an ICompAssembly for each z-layer
581 std::ostringstream oss_layer;
582 oss_layer << name << "(z=" << iz << ")";
583 createLayer(name, new CompAssembly(oss_layer.str(), this), iz, minDetId, maxDetId);
584 }
585 } else
586 createLayer(name, this, 0, minDetId, maxDetId);
587
588 m_minDetId = minDetId;
589 m_maxDetId = maxDetId;
590}
591
592//-------------------------------------------------------------------------------------------------
597 if (isParametrized())
598 return m_gridBase->minDetectorID();
599 return m_minDetId;
600}
601
602//-------------------------------------------------------------------------------------------------
607 if (isParametrized())
608 return m_gridBase->maxDetectorID();
609 return m_maxDetId;
610}
611
612//-------------------------------------------------------------------------------------------------
614std::shared_ptr<const IComponent> GridDetector::getComponentByName(const std::string &cname, int nlevels) const {
615 // exact matches
616 if (cname == this->getName())
617 return std::shared_ptr<const IComponent>(this);
618
619 // cache the detector's name as all the other names are longer
620 // The extra ( is because all children of this have that as the next character
621 // and this prevents Bank11 matching Bank 1
622 const std::string MEMBER_NAME = this->getName() + "(";
623
624 // check that the searched for name starts with the detector's
625 // name as they are generated
626 if (cname.substr(0, MEMBER_NAME.length()) != MEMBER_NAME) {
627 return std::shared_ptr<const IComponent>();
628 } else {
629 return CompAssembly::getComponentByName(cname, nlevels);
630 }
631}
632
633//------------------------------------------------------------------------------------------------
644 std::deque<IComponent_const_sptr> & /*searchQueue*/) const {
646 V3D const basePoint = getRelativePosAtXYZ(0, 0, 0);
647
649 V3D const vertical = getRelativePosAtXYZ(0, ypixels() - 1, 0) - basePoint;
650
652 V3D horizontal = getRelativePosAtXYZ(xpixels() - 1, 0, 0) - basePoint;
653
654 // The beam direction
655 V3D const beam = testRay.direction() * (-1.0);
656
657 // From: http://en.wikipedia.org/wiki/Line-plane_intersection (taken on May 4,
658 // 2011),
659 // We build a matrix to solve the linear equation:
660 Matrix<double> mat(3, 3);
661 mat.setColumn(0, beam);
662 mat.setColumn(1, horizontal);
663 mat.setColumn(2, vertical);
664 mat.Invert();
665
666 // Multiply by the inverted matrix to find t,u,v
667 V3D const tuv = mat * (testRay.startPoint() - basePoint);
668 // std::cout << tuv << "\n";
669
670 // Intersection point
671 V3D const intersec = beam * (tuv[0] * -1.0);
672
673 // t = coordinate along the line
674 // u,v = coordinates along horizontal, vertical
675 // (and correct for it being between 0, xpixels-1). The +0.5 is because the
676 // base point is at the CENTER of pixel 0,0.
677 double u = (double(xpixels() - 1) * tuv[1] + 0.5);
678 double v = (double(ypixels() - 1) * tuv[2] + 0.5);
679
680 // std::cout << u << ", " << v << "\n";
681
682 // In indices
683 auto xIndex = int(u);
684 auto yIndex = int(v);
685
686 // Out of range?
687 if (xIndex < 0)
688 return;
689 if (yIndex < 0)
690 return;
691 if (xIndex >= xpixels())
692 return;
693 if (yIndex >= ypixels())
694 return;
695
696 // TODO: Do I need to put something smart here for the first 3 parameters?
697 auto comp = getAtXYZ(xIndex, yIndex, 0);
698 testRay.addLink(intersec, intersec, 0.0, *(comp->shape()), comp->getComponentID());
699}
700
701//-------------------------------------------------------------------------------------------------
702//-------------------------------------------------------------------------------------------------
703// ------------ IObjComponent methods ----------------
704//-------------------------------------------------------------------------------------------------
705//-------------------------------------------------------------------------------------------------
706
707//-------------------------------------------------------------------------------------------------
709bool GridDetector::isValid(const V3D & /*point*/) const {
710 throw Kernel::Exception::NotImplementedError("GridDetector::isValid() is not implemented.");
711}
712
713//-------------------------------------------------------------------------------------------------
715bool GridDetector::isOnSide(const V3D & /*point*/) const {
716 throw Kernel::Exception::NotImplementedError("GridDetector::isOnSide() is not implemented.");
717}
718
719//-------------------------------------------------------------------------------------------------
721int GridDetector::interceptSurface(Track & /*track*/) const {
722 throw Kernel::Exception::NotImplementedError("GridDetector::interceptSurface() is not implemented.");
723}
724
725//-------------------------------------------------------------------------------------------------
728double GridDetector::solidAngle(const Geometry::SolidAngleParams & /*params*/) const {
729 throw Kernel::Exception::NotImplementedError("GridDetector::solidAngle() is not implemented.");
730}
731
732//-------------------------------------------------------------------------------------------------
734int GridDetector::getPointInObject(V3D & /*point*/) const {
735 throw Kernel::Exception::NotImplementedError("GridDetector::getPointInObject() is not implemented.");
736}
737
738//-------------------------------------------------------------------------------------------------
745 if (isParametrized()) {
746 if (hasComponentInfo()) {
747 assemblyBox = m_map->componentInfo().boundingBox(index(), &assemblyBox);
748 return;
749 }
750 }
751 BoundingBox bb;
752 BoundingBox compBox;
753 getAtXYZ(0, 0, 0)->getBoundingBox(compBox);
754 bb.grow(compBox);
755 getAtXYZ(this->xpixels() - 1, 0, 0)->getBoundingBox(compBox);
756 bb.grow(compBox);
757 getAtXYZ(this->xpixels() - 1, this->ypixels() - 1, 0)->getBoundingBox(compBox);
758 bb.grow(compBox);
759 getAtXYZ(0, this->ypixels() - 1, 0)->getBoundingBox(compBox);
760 bb.grow(compBox);
761 getAtXYZ(0, 0, this->zpixels() - 1)->getBoundingBox(compBox);
762 bb.grow(compBox);
763 getAtXYZ(this->xpixels() - 1, 0, this->zpixels() - 1)->getBoundingBox(compBox);
764 bb.grow(compBox);
765 getAtXYZ(this->xpixels() - 1, this->ypixels() - 1, this->zpixels() - 1)->getBoundingBox(compBox);
766 bb.grow(compBox);
767 getAtXYZ(0, this->ypixels() - 1, this->zpixels() - 1)->getBoundingBox(compBox);
768 bb.grow(compBox);
769
770 assemblyBox = bb;
771}
772
777void GridDetector::draw() const {
778 if (Handle() == nullptr)
779 return;
780 Handle()->render();
781}
782
787
793 if (Handle() == nullptr)
794 return;
795 Handle()->initialize();
796}
797
798//-------------------------------------------------------------------------------------------------
800const std::shared_ptr<const IObject> GridDetector::shape() const {
801 // --- Create a cuboid shape for your pixels ----
802 double szX = xpixels();
803 double szY = ypixels();
804 double szZ = zpixels() == 0 ? 0.5 : zpixels();
805 std::ostringstream xmlShapeStream;
806 xmlShapeStream << " <cuboid id=\"detector-shape\"> "
807 << "<left-front-bottom-point x=\"" << szX << "\" y=\"" << -szY << "\" z=\"" << -szZ << "\" /> "
808 << "<left-front-top-point x=\"" << szX << "\" y=\"" << -szY << "\" z=\"" << szZ << "\" /> "
809 << "<left-back-bottom-point x=\"" << -szX << "\" y=\"" << -szY << "\" z=\"" << -szZ << "\" /> "
810 << "<right-front-bottom-point x=\"" << szX << "\" y=\"" << szY << "\" z=\"" << -szZ << "\" /> "
811 << "</cuboid>";
812
813 std::string xmlCuboidShape(xmlShapeStream.str());
814 Geometry::ShapeFactory shapeCreator;
815 std::shared_ptr<Geometry::IObject> cuboidShape = shapeCreator.createShape(xmlCuboidShape);
816
817 return cuboidShape;
818}
819
821
822size_t GridDetector::registerContents(ComponentVisitor &componentVisitor) const {
823 return componentVisitor.registerGridBank(*this);
824}
825
826//-------------------------------------------------------------------------------------------------
827//-------------------------------------------------------------------------------------------------
828// ------------ END OF IObjComponent methods ----------------
829//-------------------------------------------------------------------------------------------------
830//-------------------------------------------------------------------------------------------------
831
842std::ostream &operator<<(std::ostream &os, const GridDetector &ass) {
843 ass.printSelf(os);
844 os << "************************\n";
845 os << "Number of children :" << ass.nelements() << '\n';
846 ass.printChildren(os);
847 return os;
848}
849
850} // namespace Mantid::Geometry
std::string name
Definition Run.cpp:60
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition BoundingBox.h:33
void grow(const BoundingBox &other)
Grow the bounding box so that it also encompasses the given box.
Class for Assembly of geometric components.
void printChildren(std::ostream &) const override
Print information about all children.
std::shared_ptr< const IComponent > getComponentByName(const std::string &cname, int nlevels=0) const override
Returns a pointer to the first component of assembly encountered with the given name.
std::shared_ptr< IComponent > getChild(const int i) const override
Get a pointer to the ith component within the assembly. Easier to use than.
CompAssembly()
Empty constructor.
int nelements() const override
Return the number of elements in the assembly.
BoundingBox boundingBox(const size_t componentIndex, const BoundingBox *reference=nullptr, const bool excludeMonitors=false) const
Compute the bounding box for the component with componentIndex taking into account all sub components...
ComponentVisitor : Visitor for IComponents.
virtual size_t registerGridBank(const ICompAssembly &bank)=0
const ParameterMap * m_map
A pointer to const ParameterMap containing the parameters.
Definition Component.h:316
size_t index() const
Helper for legacy access mode. Returns the index of the component.
void render() const
Render Object or ObjComponent.
void initialize() const
Prepare/Initialize Object/ObjComponent to be rendered.
GridDetector is a type of CompAssembly, an assembly of components.
static bool compareName(const std::string &proposedMatch)
Matches name to Structured Detector.
double m_zstart
Z position of the 0-th pixel.
bool m_idfillbyfirst_y
IDs are filled in Y fastest.
double ystart() const
Returns the start position in the Y direction.
std::tuple< int, int, int > getXYZForDetectorID(const detid_t detectorID) const
Given a detector ID, return the X,Y,Z coords into the grid detector.
const std::shared_ptr< const IObject > shape() const override
Returns the shape of the Object.
GridDetector * clone() const override
Make a clone of the present component.
std::shared_ptr< Detector > getAtXYZ(const int x, const int y, const int z) const
Return a pointer to the component in the assembly at the (X,Y) pixel position.
int m_xpixels
The number of pixels in the X (horizontal) direction.
bool isParametrized() const override
Returns true if the Component is parametrized (has a parameter map)
double m_ysize
Size in Y of the detector.
std::shared_ptr< IObject > m_shape
Pointer to the shape of the pixels in this detector array.
std::shared_ptr< const IComponent > getComponentByName(const std::string &cname, int nlevels=0) const override
Returns a pointer to the first component of assembly encountered with the given name.
int m_ypixels
The number of pixels in the Y (vertical) direction.
void initializeValues(std::shared_ptr< IObject > shape, int xpixels, double xstart, double xstep, int ypixels, double ystart, double ystep, int zpixels, double zstart, double zstep, int idstart, const std::string &idFillOrder, int idstepbyrow, int idstep)
double ysize() const
Size in Y of the detector.
double m_ystart
Y position of the 0-th pixel.
int m_idstep
Step size in ID in each col.
double m_zstep
Step size in the Z direction of the detector.
double xsize() const
Size in X of the detector.
void draw() const override
Draws the objcomponent.
void initialize(std::shared_ptr< IObject > shape, int xpixels, double xstart, double xstep, int ypixels, double ystart, double ystep, int zpixels, double zstart, double zstep, int idstart, const std::string &idFillOrder, int idstepbyrow, int idstep=1)
Create all the detector pixels of this grid detector.
bool idfillbyfirst_y() const
Returns the idfillbyfirst_y.
int xpixels() const
Returns the number of pixels in the X direction.
void getBoundingBox(BoundingBox &assemblyBox) const override
Retrieve the cached bounding box.
detid_t m_minDetId
minimum detector id
double m_ystep
Step size in the Y direction of detector.
std::string idFillOrder() const
Returns the id fill order.
int idstep() const
Returns the idstep.
int idstart() const
Returns the idstart.
detid_t maxDetectorID() const
maximum detector id
void initDraw() const override
Initializes the ObjComponent for rendering, this function should be called before rendering.
double m_xsize
Size in X of the detector.
double ystep() const
Returns the step size in the Y direction.
double xstep() const
Returns the step size in the X direction.
void init()
initialize members to bare defaults
bool isValid(const Kernel::V3D &point) const override
Does the point given lie within this object component?
detid_t minDetectorID() const
minimum detector id
int interceptSurface(Track &track) const override
Checks whether the track given will pass through this Component.
bool isOnSide(const Kernel::V3D &point) const override
Does the point given lie on the surface of this object component?
GridDetector(const std::string &name, IComponent *reference=nullptr)
Constructor with a name and parent reference.
std::string m_idFillOrder
The order in which to fill IDs.
const GridDetector * m_gridBase
Pointer to the base GridDetector, for parametrized instruments.
double m_xstart
X position of the 0-th pixel.
const Kernel::Material material() const override
Returns the material of the detector.
void createLayer(const std::string &name, CompAssembly *parent, int iz, int &minDetID, int &maxDetID)
Kernel::V3D getRelativePosAtXYZ(int x, int y, int z) const
Returns the position of the center of the pixel at x,y, relative to the center of the GridDetector,...
int ypixels() const
Returns the number of pixels in the Y direction.
void testIntersectionWithChildren(Track &testRay, std::deque< IComponent_const_sptr > &searchQueue) const override
Test the intersection of the ray with the children of the component assembly, for InstrumentRayTracer...
double m_zsize
Size in Z of the detector.
double xstart() const
Returns the start position in the X direction.
detid_t getDetectorIDAtXYZ(const int x, const int y, const int z) const
Return the detector ID corresponding to the component in the assembly at the (X,Y) pixel position.
virtual size_t registerContents(class ComponentVisitor &componentVisitor) const override
int idstepbyrow() const
Returns the idstepbyrow.
double zstart() const
Returns the start position in the Z direction.
double solidAngle(const Geometry::SolidAngleParams &params) const override
Finds the approximate solid angle covered by the component when viewed from the point given.
double zsize() const
Size in Z of the detector.
double m_xstep
Step size in the X direction of detector.
void drawObject() const override
Draws the Object.
int m_idstepbyrow
Step size in ID in each row.
int zpixels() const
Returns the number of pixels in the Z direction.
int m_zpixels
The number of pixels in the Z (usually beam) direction.
int getPointInObject(Kernel::V3D &point) const override
Try to find a point that lies within (or on) the object.
double zstep() const
Returns the step size in the Z direction.
detid_t m_maxDetId
maximum detector id
base class for Geometric IComponent
Definition IComponent.h:53
virtual void printSelf(std::ostream &) const =0
Prints a text representation of itself.
virtual void setName(const std::string &)=0
Set the IComponent name.
virtual std::string getName() const =0
Get the IComponent name.
Object Component class, this class brings together the physical attributes of the component to the po...
void setGeometryHandler(GeometryHandler *h)
Reset the current geometry handler.
GeometryHandler * Handle() const
Gets the GeometryHandler.
bool contains(const IComponent *comp, const std::string &name, const std::string &type="") const
Does the named parameter exist for the given component and type (std::string version)
std::shared_ptr< Parameter > get(const IComponent *comp, const std::string &name, const std::string &type="") const
Get a parameter with a given name and type (std::string version)
const Geometry::ComponentInfo & componentInfo() const
Only for use by ExperimentInfo. Returns a reference to the ComponentInfo.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
Defines a track as a start point and a direction.
Definition Track.h:165
const Kernel::V3D & startPoint() const
Returns the starting point.
Definition Track.h:191
int addLink(const Kernel::V3D &firstPoint, const Kernel::V3D &secondPoint, const double distanceAlongTrack, const IObject &obj, const ComponentID compID=nullptr)
Adds a link to the track.
Definition Track.cpp:152
const Kernel::V3D & direction() const
Returns the direction as a unit vector.
Definition Track.h:193
Marks code as not implemented yet.
Definition Exception.h:138
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
Definition Material.h:50
Numerical Matrix class.
Definition Matrix.h:42
T Invert()
LU inversion routine.
Definition Matrix.cpp:924
void setColumn(const size_t nCol, const std::vector< T > &newCol)
Definition Matrix.cpp:675
Class for 3D vectors.
Definition V3D.h:34
bool checkValidOrderString(const std::string &order)
MANTID_GEOMETRY_DLL std::ostream & operator<<(std::ostream &stream, const PointGroup &self)
Returns a streamed representation of the PointGroup object.
int32_t detid_t
Typedef for a detector ID.
adjust instrument component position and orientation
: detector size scale at y-direction
std::string to_string(const wide_integer< Bits, Signed > &n)