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
124detid_t getFillFirstZ(const GridDetector *me, int x, int y, int z) {
125 if (me->idFillOrder()[1] == 'y')
126 return me->idstart() + z * me->idstep() + y * me->idstepbyrow() + x * (me->ypixels() * me->idstepbyrow());
127 else
128 return me->idstart() + z * me->idstep() + x * me->idstepbyrow() + y * (me->xpixels() * me->idstepbyrow());
129}
130
131detid_t getFillFirstY(const GridDetector *me, int x, int y, int z) {
132 if (me->idFillOrder()[1] == 'x')
133 return me->idstart() + y * me->idstep() + x * me->idstepbyrow() + z * (me->xpixels() * me->idstepbyrow());
134 else
135 return me->idstart() + y * me->idstep() + z * me->idstepbyrow() + x * (me->zpixels() * me->idstepbyrow());
136}
137
138detid_t getFillFirstX(const GridDetector *me, int x, int y, int z) {
139 if (me->idFillOrder()[1] == 'y')
140 return me->idstart() + x * me->idstep() + y * me->idstepbyrow() + z * (me->ypixels() * me->idstepbyrow());
141 else
142 return me->idstart() + x * me->idstep() + z * me->idstepbyrow() + y * (me->zpixels() * me->idstepbyrow());
143}
144
145//-------------------------------------------------------------------------------------------------
156detid_t GridDetector::getDetectorIDAtXYZ(const int x, const int y, const int z) const {
157 const GridDetector *me = this;
158 if (m_map)
159 me = this->m_gridBase;
160
161 if (me->m_idFillOrder[0] == 'z')
162 return getFillFirstZ(me, x, y, z);
163 else if (me->m_idFillOrder[0] == 'y')
164 return getFillFirstY(me, x, y, z);
165 else
166 return getFillFirstX(me, x, y, z);
167}
168
169std::tuple<int, int, int> getXYZFillFirstZ(const GridDetector *me, int col, int id) {
170 if (me->idFillOrder()[1] == 'y') {
171 int row = (id / me->idstepbyrow()) % me->ypixels();
172 auto layer = (id / me->idstepbyrow()) / me->ypixels();
173 return std::tuple<int, int, int>(layer, row, col);
174 } else {
175 int row = (id / me->idstepbyrow()) % me->xpixels();
176 auto layer = (id / me->idstepbyrow()) / me->xpixels();
177 return std::tuple<int, int, int>(row, layer, col);
178 }
179}
180
181std::tuple<int, int, int> getXYZFillFirstY(const GridDetector *me, int col, int id) {
182 if (me->idFillOrder()[1] == 'z') {
183 int row = (id / me->idstepbyrow()) % me->zpixels();
184 auto layer = (id / me->idstepbyrow()) / me->zpixels();
185 return std::tuple<int, int, int>(layer, col, row);
186 } else {
187 int row = (id / me->idstepbyrow()) % me->xpixels();
188 auto layer = (id / me->idstepbyrow()) / me->xpixels();
189 return std::tuple<int, int, int>(row, col, layer);
190 }
191}
192
193std::tuple<int, int, int> getXYZFillFirstX(const GridDetector *me, int col, int id) {
194 if (me->idFillOrder()[1] == 'y') {
195 int row = (id / me->idstepbyrow()) % me->ypixels();
196 auto layer = (id / me->idstepbyrow()) / me->ypixels();
197 return std::tuple<int, int, int>(col, row, layer);
198 } else {
199 int row = (id / me->idstepbyrow()) % me->zpixels();
200 auto layer = (id / me->idstepbyrow()) / me->zpixels();
201 return std::tuple<int, int, int>(col, layer, row);
202 }
203}
204
205//-------------------------------------------------------------------------------------------------
211std::tuple<int, int, int> GridDetector::getXYZForDetectorID(const detid_t detectorID) const {
212 const GridDetector *me = this;
213 if (m_map)
214 me = this->m_gridBase;
215
216 int id = detectorID - me->m_idstart;
217 if ((me->m_idstepbyrow == 0) || (me->m_idstep == 0))
218 return std::tuple<int, int, int>(-1, -1, -1);
219 int col = (id % me->m_idstepbyrow) / me->m_idstep;
220
221 if (me->m_idFillOrder[0] == 'z')
222 return getXYZFillFirstZ(me, col, id);
223 else if (me->m_idFillOrder[0] == 'y')
224 return getXYZFillFirstY(me, col, id);
225 else
226 return getXYZFillFirstX(me, col, id);
227}
228
229//-------------------------------------------------------------------------------------------------
233 if (m_map)
234 return m_gridBase->m_xpixels;
235 else
236 return this->m_xpixels;
237}
238
239//-------------------------------------------------------------------------------------------------
243 if (m_map)
244 return m_gridBase->m_ypixels;
245 else
246 return this->m_ypixels;
247}
248
249//-------------------------------------------------------------------------------------------------
253 if (m_map)
254 return m_gridBase->m_zpixels;
255 else
256 return this->m_zpixels;
257}
258
259//-------------------------------------------------------------------------------------------------
261double GridDetector::xstep() const {
262 if (m_map) {
263 double scaling = 1.0;
264 if (m_map->contains(m_gridBase, "scalex"))
265 scaling = m_map->get(m_gridBase, "scalex")->value<double>();
266 return m_gridBase->m_xstep * scaling;
267 } else
268 return this->m_xstep;
269}
270
271//-------------------------------------------------------------------------------------------------
273double GridDetector::ystep() const {
274 if (m_map) {
275 double scaling = 1.0;
276 if (m_map->contains(m_gridBase, "scaley"))
277 scaling = m_map->get(m_gridBase, "scaley")->value<double>();
278 return m_gridBase->m_ystep * scaling;
279 } else
280 return this->m_ystep;
281}
282
283//-------------------------------------------------------------------------------------------------
285double GridDetector::zstep() const {
286 if (m_map) {
287 double scaling = 1.0;
288 if (m_map->contains(m_gridBase, "scalez"))
289 scaling = m_map->get(m_gridBase, "scalez")->value<double>();
290 return m_gridBase->m_zstep * scaling;
291 } else
292 return this->m_zstep;
293}
294
295//-------------------------------------------------------------------------------------------------
297double GridDetector::xstart() const {
298 if (m_map) {
299 double scaling = 1.0;
300 if (m_map->contains(m_gridBase, "scalex"))
301 scaling = m_map->get(m_gridBase, "scalex")->value<double>();
302 return m_gridBase->m_xstart * scaling;
303 } else
304 return this->m_xstart;
305}
306
307//-------------------------------------------------------------------------------------------------
309double GridDetector::ystart() const {
310 if (m_map) {
311 double scaling = 1.0;
312 if (m_map->contains(m_gridBase, "scaley"))
313 scaling = m_map->get(m_gridBase, "scaley")->value<double>();
314 return m_gridBase->m_ystart * scaling;
315 } else
316 return this->m_ystart;
317}
318
319//-------------------------------------------------------------------------------------------------
321double GridDetector::zstart() const {
322 if (m_map) {
323 double scaling = 1.0;
324 if (m_map->contains(m_gridBase, "scalez"))
325 scaling = m_map->get(m_gridBase, "scalez")->value<double>();
326 return m_gridBase->m_zstart * scaling;
327 } else
328 return this->m_zstart;
329}
330
331//-------------------------------------------------------------------------------------------------
333double GridDetector::xsize() const {
334 if (m_map) {
335 double scaling = 1.0;
336 if (m_map->contains(m_gridBase, "scalex"))
337 scaling = m_map->get(m_gridBase, "scalex")->value<double>();
338 return m_gridBase->m_xsize * scaling;
339 } else
340 return this->m_xsize;
341}
342
343//-------------------------------------------------------------------------------------------------
345double GridDetector::ysize() const {
346 if (m_map) {
347 double scaling = 1.0;
348 if (m_map->contains(m_gridBase, "scaley"))
349 scaling = m_map->get(m_gridBase, "scaley")->value<double>();
350 return m_gridBase->m_ysize * scaling;
351 } else
352 return this->m_ysize;
353}
354
355//-------------------------------------------------------------------------------------------------
357double GridDetector::zsize() const {
358 if (m_map) {
359 double scaling = 1.0;
360 if (m_map->contains(m_gridBase, "scalez"))
361 scaling = m_map->get(m_gridBase, "scalez")->value<double>();
362 return m_gridBase->m_zsize * scaling;
363 } else
364 return this->m_zsize;
365}
366
367//-------------------------------------------------------------------------------------------------
370 if (m_map)
371 return m_gridBase->m_idstart;
372 else
373 return this->m_idstart;
374}
375
376//-------------------------------------------------------------------------------------------------
379 if (m_map)
381 else
382 return this->m_idfillbyfirst_y;
383}
384
386std::string GridDetector::idFillOrder() const {
387 if (m_map)
389 else
390 return this->m_idFillOrder;
391}
392
393//-------------------------------------------------------------------------------------------------
396 if (m_map)
398 else
399 return this->m_idstepbyrow;
400}
401
402//-------------------------------------------------------------------------------------------------
405 if (m_map)
406 return m_gridBase->m_idstep;
407 else
408 return this->m_idstep;
409}
410
411//-------------------------------------------------------------------------------------------------
422 if (m_map) {
423 double scalex = 1.0;
424 if (m_map->contains(m_gridBase, "scalex"))
425 scalex = m_map->get(m_gridBase, "scalex")->value<double>();
426 double scaley = 1.0;
427 if (m_map->contains(m_gridBase, "scaley"))
428 scaley = m_map->get(m_gridBase, "scaley")->value<double>();
429 double scalez = 1.0;
430 if (m_map->contains(m_gridBase, "scalez"))
431 scalez = m_map->get(m_gridBase, "scalez")->value<double>();
432 return m_gridBase->getRelativePosAtXYZ(x, y, z) * V3D(scalex, scaley, scalez);
433 } else
434 return V3D(m_xstart + m_xstep * x, m_ystart + m_ystep * y, m_zstart + m_zstep * z);
435}
436
437void GridDetector::createLayer(const std::string &name, CompAssembly *parent, int iz, int &minDetID, int &maxDetID) {
438 const double z = m_zstart + iz * m_zstep;
439 const std::string z_pixel_str = (m_zpixels > 0) ? "," + std::to_string(iz) + ")" : ")";
440 const std::string z_layer_str = (m_zpixels > 0) ? name + "(z=" + std::to_string(iz) + ",x=" : name + "(x=";
441 for (int ix = 0; ix < m_xpixels; ++ix) {
442 const std::string x_pixel_str = name + "(" + std::to_string(ix) + ",";
443 const std::string name_layer = z_layer_str + std::to_string(ix) + ")";
444
445 // Create an ICompAssembly for each x-column
446 auto *xColumn = new CompAssembly(name_layer, parent);
447
448 const double x = m_xstart + ix * m_xstep;
449 for (int iy = 0; iy < m_ypixels; ++iy) {
450 // Make the name
451 const std::string name_pixel = x_pixel_str + std::to_string(iy) + z_pixel_str;
452
453 // Calculate its id and set it.
454 const auto id = this->getDetectorIDAtXYZ(ix, iy, iz);
455
456 // minimum grid detector id
457 if (id < minDetID) {
458 minDetID = id;
459 }
460 // maximum grid detector id
461 if (id > maxDetID) {
462 maxDetID = id;
463 }
464 // Create the detector from the given id & shape and with xColumn as the parent
465 auto *detector =
466 new GridDetectorPixel(name_pixel, id, m_shape, xColumn, this, size_t(ix), size_t(iy), size_t(iz));
467
468 const double y = m_ystart + iy * m_ystep;
469 // Translate (relative to parent). This gives the un-parametrized position
470 detector->translate(x, y, z);
471
472 // Add it to the x-column
473 xColumn->add(detector);
474 }
475 }
476}
477
478bool checkValidOrderString(const std::string &order) {
479 static const boost::regex exp("xyz|xzy|yzx|yxz|zyx|zxy");
480
481 return boost::regex_match(order, exp);
482}
483
485 // Some safety checks
487 throw std::invalid_argument("GridDetector::initialize(): order string "
488 "should only comprise exactly 3 letters x, y, "
489 "and z in any order.");
490 if (m_xpixels <= 0)
491 throw std::invalid_argument("GridDetector::initialize(): xpixels should be > 0");
492 if (m_ypixels <= 0)
493 throw std::invalid_argument("GridDetector::initialize(): ypixels should be > 0");
494}
495
496void GridDetector::initializeValues(std::shared_ptr<IObject> shape, int xpixels, double xstart, double xstep,
497 int ypixels, double ystart, double ystep, int zpixels, double zstart, double zstep,
498 int idstart, const std::string &idFillOrder, int idstepbyrow, int idstep) {
499
509 m_xstep = xstep;
510 m_ystep = ystep;
511 m_zstep = zstep;
512 m_shape = std::move(shape);
513
517 m_idfillbyfirst_y = idFillOrder[0] == 'y';
524
526}
527
528//-------------------------------------------------------------------------------------------------
562void GridDetector::initialize(std::shared_ptr<IObject> shape, int xpixels, double xstart, double xstep, int ypixels,
563 double ystart, double ystep, int zpixels, double zstart, double zstep, int idstart,
564 const std::string &idFillOrder, int idstepbyrow, int idstep) {
565
566 if (m_map)
567 throw std::runtime_error("GridDetector::initialize() called for a "
568 "parametrized GridDetector");
569
572
573 std::string name = this->getName();
574 int minDetId = idstart, maxDetId = idstart;
575 // Loop through all the pixels
576 if (m_zpixels > 0) {
577 for (int iz = 0; iz < m_zpixels; ++iz) {
578 // Create an ICompAssembly for each z-layer
579 std::ostringstream oss_layer;
580 oss_layer << name << "(z=" << iz << ")";
581 createLayer(name, new CompAssembly(oss_layer.str(), this), iz, minDetId, maxDetId);
582 }
583 } else
584 createLayer(name, this, 0, minDetId, maxDetId);
585
586 m_minDetId = minDetId;
587 m_maxDetId = maxDetId;
588}
589
590//-------------------------------------------------------------------------------------------------
595 if (m_map)
596 return m_gridBase->m_minDetId;
597 return m_minDetId;
598}
599
600//-------------------------------------------------------------------------------------------------
605 if (m_map)
606 return m_gridBase->m_maxDetId;
607 return m_maxDetId;
608}
609
610//-------------------------------------------------------------------------------------------------
612std::shared_ptr<const IComponent> GridDetector::getComponentByName(const std::string &cname, int nlevels) const {
613 // exact matches
614 if (cname == this->getName())
615 return std::shared_ptr<const IComponent>(this);
616
617 // cache the detector's name as all the other names are longer
618 // The extra ( is because all children of this have that as the next character
619 // and this prevents Bank11 matching Bank 1
620 const std::string MEMBER_NAME = this->getName() + "(";
621
622 // check that the searched for name starts with the detector's
623 // name as they are generated
624 if (cname.substr(0, MEMBER_NAME.length()) != MEMBER_NAME) {
625 return std::shared_ptr<const IComponent>();
626 } else {
627 return CompAssembly::getComponentByName(cname, nlevels);
628 }
629}
630
631//------------------------------------------------------------------------------------------------
642 std::deque<IComponent_const_sptr> & /*searchQueue*/) const {
644 V3D basePoint;
645
647 V3D vertical;
648
650 V3D horizontal;
651
652 basePoint = getAtXYZ(0, 0, 0)->getPos();
653 horizontal = getAtXYZ(xpixels() - 1, 0, 0)->getPos() - basePoint;
654 vertical = getAtXYZ(0, ypixels() - 1, 0)->getPos() - basePoint;
655
656 // The beam direction
657 V3D beam = testRay.direction();
658
659 // From: http://en.wikipedia.org/wiki/Line-plane_intersection (taken on May 4,
660 // 2011),
661 // We build a matrix to solve the linear equation:
662 Matrix<double> mat(3, 3);
663 mat.setColumn(0, beam * -1.0);
664 mat.setColumn(1, horizontal);
665 mat.setColumn(2, vertical);
666 mat.Invert();
667
668 // Multiply by the inverted matrix to find t,u,v
669 V3D tuv = mat * (testRay.startPoint() - basePoint);
670 // std::cout << tuv << "\n";
671
672 // Intersection point
673 V3D intersec = beam;
674 intersec *= tuv[0];
675
676 // t = coordinate along the line
677 // u,v = coordinates along horizontal, vertical
678 // (and correct for it being between 0, xpixels-1). The +0.5 is because the
679 // base point is at the CENTER of pixel 0,0.
680 double u = (double(xpixels() - 1) * tuv[1] + 0.5);
681 double v = (double(ypixels() - 1) * tuv[2] + 0.5);
682
683 // std::cout << u << ", " << v << "\n";
684
685 // In indices
686 auto xIndex = int(u);
687 auto yIndex = int(v);
688
689 // Out of range?
690 if (xIndex < 0)
691 return;
692 if (yIndex < 0)
693 return;
694 if (xIndex >= xpixels())
695 return;
696 if (yIndex >= ypixels())
697 return;
698
699 // TODO: Do I need to put something smart here for the first 3 parameters?
700 auto comp = getAtXYZ(xIndex, yIndex, 0);
701 testRay.addLink(intersec, intersec, 0.0, *(comp->shape()), comp->getComponentID());
702}
703
704//-------------------------------------------------------------------------------------------------
705//-------------------------------------------------------------------------------------------------
706// ------------ IObjComponent methods ----------------
707//-------------------------------------------------------------------------------------------------
708//-------------------------------------------------------------------------------------------------
709
710//-------------------------------------------------------------------------------------------------
712bool GridDetector::isValid(const V3D & /*point*/) const {
713 throw Kernel::Exception::NotImplementedError("GridDetector::isValid() is not implemented.");
714}
715
716//-------------------------------------------------------------------------------------------------
718bool GridDetector::isOnSide(const V3D & /*point*/) const {
719 throw Kernel::Exception::NotImplementedError("GridDetector::isOnSide() is not implemented.");
720}
721
722//-------------------------------------------------------------------------------------------------
724int GridDetector::interceptSurface(Track & /*track*/) const {
725 throw Kernel::Exception::NotImplementedError("GridDetector::interceptSurface() is not implemented.");
726}
727
728//-------------------------------------------------------------------------------------------------
731double GridDetector::solidAngle(const Geometry::SolidAngleParams & /*params*/) const {
732 throw Kernel::Exception::NotImplementedError("GridDetector::solidAngle() is not implemented.");
733}
734
735//-------------------------------------------------------------------------------------------------
737int GridDetector::getPointInObject(V3D & /*point*/) const {
738 throw Kernel::Exception::NotImplementedError("GridDetector::getPointInObject() is not implemented.");
739}
740
741//-------------------------------------------------------------------------------------------------
748 if (m_map) {
749 if (hasComponentInfo()) {
750 assemblyBox = m_map->componentInfo().boundingBox(index(), &assemblyBox);
751 return;
752 }
753 }
754 BoundingBox bb;
755 BoundingBox compBox;
756 getAtXYZ(0, 0, 0)->getBoundingBox(compBox);
757 bb.grow(compBox);
758 getAtXYZ(this->xpixels() - 1, 0, 0)->getBoundingBox(compBox);
759 bb.grow(compBox);
760 getAtXYZ(this->xpixels() - 1, this->ypixels() - 1, 0)->getBoundingBox(compBox);
761 bb.grow(compBox);
762 getAtXYZ(0, this->ypixels() - 1, 0)->getBoundingBox(compBox);
763 bb.grow(compBox);
764 getAtXYZ(0, 0, this->zpixels() - 1)->getBoundingBox(compBox);
765 bb.grow(compBox);
766 getAtXYZ(this->xpixels() - 1, 0, this->zpixels() - 1)->getBoundingBox(compBox);
767 bb.grow(compBox);
768 getAtXYZ(this->xpixels() - 1, this->ypixels() - 1, this->zpixels() - 1)->getBoundingBox(compBox);
769 bb.grow(compBox);
770 getAtXYZ(0, this->ypixels() - 1, this->zpixels() - 1)->getBoundingBox(compBox);
771 bb.grow(compBox);
772
773 assemblyBox = bb;
774}
775
780void GridDetector::draw() const {
781 if (Handle() == nullptr)
782 return;
783 Handle()->render();
784}
785
790
796 if (Handle() == nullptr)
797 return;
798 Handle()->initialize();
799}
800
801//-------------------------------------------------------------------------------------------------
803const std::shared_ptr<const IObject> GridDetector::shape() const {
804 // --- Create a cuboid shape for your pixels ----
805 double szX = m_xpixels;
806 double szY = m_ypixels;
807 double szZ = m_zpixels == 0 ? 0.5 : m_zpixels;
808 std::ostringstream xmlShapeStream;
809 xmlShapeStream << " <cuboid id=\"detector-shape\"> "
810 << "<left-front-bottom-point x=\"" << szX << "\" y=\"" << -szY << "\" z=\"" << -szZ << "\" /> "
811 << "<left-front-top-point x=\"" << szX << "\" y=\"" << -szY << "\" z=\"" << szZ << "\" /> "
812 << "<left-back-bottom-point x=\"" << -szX << "\" y=\"" << -szY << "\" z=\"" << -szZ << "\" /> "
813 << "<right-front-bottom-point x=\"" << szX << "\" y=\"" << szY << "\" z=\"" << -szZ << "\" /> "
814 << "</cuboid>";
815
816 std::string xmlCuboidShape(xmlShapeStream.str());
817 Geometry::ShapeFactory shapeCreator;
818 std::shared_ptr<Geometry::IObject> cuboidShape = shapeCreator.createShape(xmlCuboidShape);
819
820 return cuboidShape;
821}
822
824
825size_t GridDetector::registerContents(ComponentVisitor &componentVisitor) const {
826 return componentVisitor.registerGridBank(*this);
827}
828
829//-------------------------------------------------------------------------------------------------
830//-------------------------------------------------------------------------------------------------
831// ------------ END OF IObjComponent methods ----------------
832//-------------------------------------------------------------------------------------------------
833//-------------------------------------------------------------------------------------------------
834
845std::ostream &operator<<(std::ostream &os, const GridDetector &ass) {
846 ass.printSelf(os);
847 os << "************************\n";
848 os << "Number of children :" << ass.nelements() << '\n';
849 ass.printChildren(os);
850 return os;
851}
852
853} // 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.
detid_t maxDetectorID()
maximum detector id
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.
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.
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?
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.
detid_t minDetectorID()
minimum detector id
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
detid_t getFillFirstY(const GridDetector *me, int x, int y, int z)
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.
detid_t getFillFirstX(const GridDetector *me, int x, int y, int z)
std::tuple< int, int, int > getXYZFillFirstY(const GridDetector *me, int col, int id)
detid_t getFillFirstZ(const GridDetector *me, int x, int y, int z)
std::tuple< int, int, int > getXYZFillFirstZ(const GridDetector *me, int col, int id)
std::tuple< int, int, int > getXYZFillFirstX(const GridDetector *me, int col, int id)
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)