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 // Loop and create all detectors in this layer.
439 for (int ix = 0; ix < m_xpixels; ++ix) {
440 // Create an ICompAssembly for each x-column
441 std::ostringstream oss_col;
442 if (m_zpixels > 0)
443 oss_col << name << "(z=" << iz << ","
444 << "x=" << ix << ")";
445 else
446 oss_col << name << "(x=" << ix << ")";
447
448 auto *xColumn = new CompAssembly(oss_col.str(), parent);
449
450 for (int iy = 0; iy < m_ypixels; ++iy) {
451 // Make the name
452 std::ostringstream oss;
453 if (m_zpixels > 0)
454 oss << name << "(" << ix << "," << iy << "," << iz << ")";
455 else
456 oss << name << "(" << ix << "," << iy << ")";
457
458 // Calculate its id and set it.
459 auto id = this->getDetectorIDAtXYZ(ix, iy, iz);
460
461 // minimum grid detector id
462 if (id < minDetID) {
463 minDetID = id;
464 }
465 // maximum grid detector id
466 if (id > maxDetID) {
467 maxDetID = id;
468 }
469 // Create the detector from the given id & shape and with xColumn as the
470 // parent.
471 auto *detector = new GridDetectorPixel(oss.str(), id, m_shape, xColumn, this, size_t(ix), size_t(iy), size_t(iz));
472
473 // Calculate the x,y,z position
474 double x = m_xstart + ix * m_xstep;
475 double y = m_ystart + iy * m_ystep;
476 double z = m_zstart + iz * m_zstep;
477 V3D pos(x, y, z);
478 // Translate (relative to parent). This gives the un-parametrized
479 // position.
480 detector->translate(pos);
481
482 // Add it to the x-column
483 xColumn->add(detector);
484 }
485 }
486}
487
488bool checkValidOrderString(const std::string &order) {
489 static const boost::regex exp("xyz|xzy|yzx|yxz|zyx|zxy");
490
491 return boost::regex_match(order, exp);
492}
493
495 // Some safety checks
497 throw std::invalid_argument("GridDetector::initialize(): order string "
498 "should only comprise exactly 3 letters x, y, "
499 "and z in any order.");
500 if (m_xpixels <= 0)
501 throw std::invalid_argument("GridDetector::initialize(): xpixels should be > 0");
502 if (m_ypixels <= 0)
503 throw std::invalid_argument("GridDetector::initialize(): ypixels should be > 0");
504}
505
506void GridDetector::initializeValues(std::shared_ptr<IObject> shape, int xpixels, double xstart, double xstep,
507 int ypixels, double ystart, double ystep, int zpixels, double zstart, double zstep,
508 int idstart, const std::string &idFillOrder, int idstepbyrow, int idstep) {
509
519 m_xstep = xstep;
520 m_ystep = ystep;
521 m_zstep = zstep;
522 m_shape = std::move(shape);
523
527 m_idfillbyfirst_y = idFillOrder[0] == 'y';
534
536}
537
538//-------------------------------------------------------------------------------------------------
572void GridDetector::initialize(std::shared_ptr<IObject> shape, int xpixels, double xstart, double xstep, int ypixels,
573 double ystart, double ystep, int zpixels, double zstart, double zstep, int idstart,
574 const std::string &idFillOrder, int idstepbyrow, int idstep) {
575
576 if (m_map)
577 throw std::runtime_error("GridDetector::initialize() called for a "
578 "parametrized GridDetector");
579
582
583 std::string name = this->getName();
584 int minDetId = idstart, maxDetId = idstart;
585 // Loop through all the pixels
586 if (m_zpixels > 0) {
587 for (int iz = 0; iz < m_zpixels; ++iz) {
588 // Create an ICompAssembly for each z-layer
589 std::ostringstream oss_layer;
590 oss_layer << name << "(z=" << iz << ")";
591 createLayer(name, new CompAssembly(oss_layer.str(), this), iz, minDetId, maxDetId);
592 }
593 } else
594 createLayer(name, this, 0, minDetId, maxDetId);
595
596 m_minDetId = minDetId;
597 m_maxDetId = maxDetId;
598}
599
600//-------------------------------------------------------------------------------------------------
605 if (m_map)
606 return m_gridBase->m_minDetId;
607 return m_minDetId;
608}
609
610//-------------------------------------------------------------------------------------------------
615 if (m_map)
616 return m_gridBase->m_maxDetId;
617 return m_maxDetId;
618}
619
620//-------------------------------------------------------------------------------------------------
622std::shared_ptr<const IComponent> GridDetector::getComponentByName(const std::string &cname, int nlevels) const {
623 // exact matches
624 if (cname == this->getName())
625 return std::shared_ptr<const IComponent>(this);
626
627 // cache the detector's name as all the other names are longer
628 // The extra ( is because all children of this have that as the next character
629 // and this prevents Bank11 matching Bank 1
630 const std::string MEMBER_NAME = this->getName() + "(";
631
632 // check that the searched for name starts with the detector's
633 // name as they are generated
634 if (cname.substr(0, MEMBER_NAME.length()) != MEMBER_NAME) {
635 return std::shared_ptr<const IComponent>();
636 } else {
637 return CompAssembly::getComponentByName(cname, nlevels);
638 }
639}
640
641//------------------------------------------------------------------------------------------------
652 std::deque<IComponent_const_sptr> & /*searchQueue*/) const {
654 V3D basePoint;
655
657 V3D vertical;
658
660 V3D horizontal;
661
662 basePoint = getAtXYZ(0, 0, 0)->getPos();
663 horizontal = getAtXYZ(xpixels() - 1, 0, 0)->getPos() - basePoint;
664 vertical = getAtXYZ(0, ypixels() - 1, 0)->getPos() - basePoint;
665
666 // The beam direction
667 V3D beam = testRay.direction();
668
669 // From: http://en.wikipedia.org/wiki/Line-plane_intersection (taken on May 4,
670 // 2011),
671 // We build a matrix to solve the linear equation:
672 Matrix<double> mat(3, 3);
673 mat.setColumn(0, beam * -1.0);
674 mat.setColumn(1, horizontal);
675 mat.setColumn(2, vertical);
676 mat.Invert();
677
678 // Multiply by the inverted matrix to find t,u,v
679 V3D tuv = mat * (testRay.startPoint() - basePoint);
680 // std::cout << tuv << "\n";
681
682 // Intersection point
683 V3D intersec = beam;
684 intersec *= tuv[0];
685
686 // t = coordinate along the line
687 // u,v = coordinates along horizontal, vertical
688 // (and correct for it being between 0, xpixels-1). The +0.5 is because the
689 // base point is at the CENTER of pixel 0,0.
690 double u = (double(xpixels() - 1) * tuv[1] + 0.5);
691 double v = (double(ypixels() - 1) * tuv[2] + 0.5);
692
693 // std::cout << u << ", " << v << "\n";
694
695 // In indices
696 auto xIndex = int(u);
697 auto yIndex = int(v);
698
699 // Out of range?
700 if (xIndex < 0)
701 return;
702 if (yIndex < 0)
703 return;
704 if (xIndex >= xpixels())
705 return;
706 if (yIndex >= ypixels())
707 return;
708
709 // TODO: Do I need to put something smart here for the first 3 parameters?
710 auto comp = getAtXYZ(xIndex, yIndex, 0);
711 testRay.addLink(intersec, intersec, 0.0, *(comp->shape()), comp->getComponentID());
712}
713
714//-------------------------------------------------------------------------------------------------
715//-------------------------------------------------------------------------------------------------
716// ------------ IObjComponent methods ----------------
717//-------------------------------------------------------------------------------------------------
718//-------------------------------------------------------------------------------------------------
719
720//-------------------------------------------------------------------------------------------------
722bool GridDetector::isValid(const V3D & /*point*/) const {
723 throw Kernel::Exception::NotImplementedError("GridDetector::isValid() is not implemented.");
724}
725
726//-------------------------------------------------------------------------------------------------
728bool GridDetector::isOnSide(const V3D & /*point*/) const {
729 throw Kernel::Exception::NotImplementedError("GridDetector::isOnSide() is not implemented.");
730}
731
732//-------------------------------------------------------------------------------------------------
734int GridDetector::interceptSurface(Track & /*track*/) const {
735 throw Kernel::Exception::NotImplementedError("GridDetector::interceptSurface() is not implemented.");
736}
737
738//-------------------------------------------------------------------------------------------------
741double GridDetector::solidAngle(const V3D & /*observer*/) const {
742 throw Kernel::Exception::NotImplementedError("GridDetector::solidAngle() is not implemented.");
743}
744
745//-------------------------------------------------------------------------------------------------
747int GridDetector::getPointInObject(V3D & /*point*/) const {
748 throw Kernel::Exception::NotImplementedError("GridDetector::getPointInObject() is not implemented.");
749}
750
751//-------------------------------------------------------------------------------------------------
758 if (m_map) {
759 if (hasComponentInfo()) {
760 assemblyBox = m_map->componentInfo().boundingBox(index(), &assemblyBox);
761 return;
762 }
763 }
764 BoundingBox bb;
765 BoundingBox compBox;
766 getAtXYZ(0, 0, 0)->getBoundingBox(compBox);
767 bb.grow(compBox);
768 getAtXYZ(this->xpixels() - 1, 0, 0)->getBoundingBox(compBox);
769 bb.grow(compBox);
770 getAtXYZ(this->xpixels() - 1, this->ypixels() - 1, 0)->getBoundingBox(compBox);
771 bb.grow(compBox);
772 getAtXYZ(0, this->ypixels() - 1, 0)->getBoundingBox(compBox);
773 bb.grow(compBox);
774 getAtXYZ(0, 0, this->zpixels() - 1)->getBoundingBox(compBox);
775 bb.grow(compBox);
776 getAtXYZ(this->xpixels() - 1, 0, this->zpixels() - 1)->getBoundingBox(compBox);
777 bb.grow(compBox);
778 getAtXYZ(this->xpixels() - 1, this->ypixels() - 1, this->zpixels() - 1)->getBoundingBox(compBox);
779 bb.grow(compBox);
780 getAtXYZ(0, this->ypixels() - 1, this->zpixels() - 1)->getBoundingBox(compBox);
781 bb.grow(compBox);
782
783 assemblyBox = bb;
784}
785
790void GridDetector::draw() const {
791 if (Handle() == nullptr)
792 return;
793 Handle()->render();
794}
795
800
806 if (Handle() == nullptr)
807 return;
808 Handle()->initialize();
809}
810
811//-------------------------------------------------------------------------------------------------
813const std::shared_ptr<const IObject> GridDetector::shape() const {
814 // --- Create a cuboid shape for your pixels ----
815 double szX = m_xpixels;
816 double szY = m_ypixels;
817 double szZ = m_zpixels == 0 ? 0.5 : m_zpixels;
818 std::ostringstream xmlShapeStream;
819 xmlShapeStream << " <cuboid id=\"detector-shape\"> "
820 << "<left-front-bottom-point x=\"" << szX << "\" y=\"" << -szY << "\" z=\"" << -szZ << "\" /> "
821 << "<left-front-top-point x=\"" << szX << "\" y=\"" << -szY << "\" z=\"" << szZ << "\" /> "
822 << "<left-back-bottom-point x=\"" << -szX << "\" y=\"" << -szY << "\" z=\"" << -szZ << "\" /> "
823 << "<right-front-bottom-point x=\"" << szX << "\" y=\"" << szY << "\" z=\"" << -szZ << "\" /> "
824 << "</cuboid>";
825
826 std::string xmlCuboidShape(xmlShapeStream.str());
827 Geometry::ShapeFactory shapeCreator;
828 std::shared_ptr<Geometry::IObject> cuboidShape = shapeCreator.createShape(xmlCuboidShape);
829
830 return cuboidShape;
831}
832
834
835size_t GridDetector::registerContents(ComponentVisitor &componentVisitor) const {
836 return componentVisitor.registerGridBank(*this);
837}
838
839//-------------------------------------------------------------------------------------------------
840//-------------------------------------------------------------------------------------------------
841// ------------ END OF IObjComponent methods ----------------
842//-------------------------------------------------------------------------------------------------
843//-------------------------------------------------------------------------------------------------
844
855std::ostream &operator<<(std::ostream &os, const GridDetector &ass) {
856 ass.printSelf(os);
857 os << "************************\n";
858 os << "Number of children :" << ass.nelements() << '\n';
859 ass.printChildren(os);
860 return os;
861}
862
863} // namespace Mantid::Geometry
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
Definition: BoundingBox.h:34
void grow(const BoundingBox &other)
Grow the bounding box so that it also encompasses the given box.
Class for Assembly of geometric components.
Definition: CompAssembly.h:31
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:307
size_t index() const
Helper for legacy access mode. Returns the index of the component.
Definition: Component.cpp:297
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.
Definition: GridDetector.h:34
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.
Definition: GridDetector.h:176
bool m_idfillbyfirst_y
IDs are filled in Y fastest.
Definition: GridDetector.h:195
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.
Definition: GridDetector.h:158
double m_ysize
Size in Y of the detector.
Definition: GridDetector.h:167
std::shared_ptr< IObject > m_shape
Pointer to the shape of the pixels in this detector array.
Definition: GridDetector.h:186
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.
Definition: GridDetector.h:160
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.
Definition: GridDetector.h:174
int m_idstep
Step size in ID in each col.
Definition: GridDetector.h:201
double m_zstep
Step size in the Z direction of the detector.
Definition: GridDetector.h:183
double solidAngle(const Kernel::V3D &observer) const override
Finds the approximate solid angle covered by the component when viewed from the point given.
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
Definition: GridDetector.h:188
double m_ystep
Step size in the Y direction of detector.
Definition: GridDetector.h:181
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.
Definition: GridDetector.h:165
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.
Definition: GridDetector.h:197
const GridDetector * m_gridBase
Pointer to the base GridDetector, for parametrized instruments.
Definition: GridDetector.h:153
double m_xstart
X position of the 0-th pixel.
Definition: GridDetector.h:172
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.
Definition: GridDetector.h:169
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.
int m_idstart
IDs start here.
Definition: GridDetector.h:193
double zstart() const
Returns the start position in the Z direction.
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.
Definition: GridDetector.h:179
void drawObject() const override
Draws the Object.
int m_idstepbyrow
Step size in ID in each row.
Definition: GridDetector.h:199
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.
Definition: GridDetector.h:162
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
Definition: GridDetector.h:190
base class for Geometric IComponent
Definition: IComponent.h:51
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...
Definition: IObjComponent.h:37
void setGeometryHandler(GeometryHandler *h)
Reset the current geometry handler.
GeometryHandler * Handle() const
Gets the GeometryHandler.
Definition: IObjComponent.h:92
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.
Definition: ShapeFactory.h:89
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.
Definition: PointGroup.cpp:312
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.
Definition: SpectrumInfo.h:21
adjust instrument component position and orientation
: detector size scale at y-direction