22#include <boost/regex.hpp>
60 static const boost::regex exp(
"grid_?detector", boost::regex::icase);
61 return boost::regex_match(proposedMatch, exp);
84 throw std::runtime_error(
"GridDetector::inBoundsXYZ: invalid X or Y "
85 "width set in the object.");
111 throw std::runtime_error(
"GridDetector::getAtXY: invalid X or Y "
112 "width set in the object.");
114 throw std::runtime_error(
"GridDetector::getAtXYZ: x specified is out of range.");
116 throw std::runtime_error(
"GridDetector::getAtXYZ: y specified is out of range.");
119 throw std::runtime_error(
"GridDetector::getAtXYZ: z specified is out of range.");
123 std::shared_ptr<ICompAssembly> xCol;
126 auto zLayer = std::dynamic_pointer_cast<ICompAssembly>(this->
getChild(z));
128 throw std::runtime_error(
"GridDetector::getAtXYZ: z specified is out of range.");
130 xCol = std::dynamic_pointer_cast<ICompAssembly>(zLayer->getChild(
x));
132 xCol = std::dynamic_pointer_cast<ICompAssembly>(this->
getChild(x));
135 throw std::runtime_error(
"GridDetector::getAtXYZ: x specified is out of range.");
136 return std::dynamic_pointer_cast<Detector>(xCol->getChild(
y));
140int const &orderXYZ(
char const order,
int const &
x,
int const &
y,
int const &
z) {
149 throw std::runtime_error(
"Not a dimensional label: " +
std::to_string(order));
153int const &pixelsXYZ(
char const order, GridDetector
const *
const me) {
156 return me->xpixels();
158 return me->ypixels();
160 return me->zpixels();
162 throw std::runtime_error(std::string(
"Not a dimensional label: ") + order);
180 throw std::out_of_range(
"GridDetector::getDetectorIDAtXYZ: pixel indices are out of range.");
184 int const &first = orderXYZ(order[0],
x,
y,
z);
185 int const &second = orderXYZ(order[1],
x,
y,
z);
186 int const &third = orderXYZ(order[2],
x,
y,
z);
192std::tuple<int, int, int> getXYZFillFirstZ(
const GridDetector *me,
int col,
int id) {
196 return std::tuple<int, int, int>(layer, row, col);
200 return std::tuple<int, int, int>(row, layer, col);
204std::tuple<int, int, int> getXYZFillFirstY(
const GridDetector *me,
int col,
int id) {
205 if (me->idFillOrder()[1] ==
'z') {
206 int row = (
id / me->idstepbyrow()) % me->zpixels();
207 auto layer = (
id / me->idstepbyrow()) / me->zpixels();
208 return std::tuple<int, int, int>(layer, col, row);
210 int row = (
id / me->idstepbyrow()) % me->xpixels();
211 auto layer = (
id / me->idstepbyrow()) / me->xpixels();
212 return std::tuple<int, int, int>(row, col, layer);
216std::tuple<int, int, int> getXYZFillFirstX(
const GridDetector *me,
int col,
int id) {
217 if (me->idFillOrder()[1] ==
'y') {
218 int row = (
id / me->idstepbyrow()) % me->ypixels();
219 auto layer = (
id / me->idstepbyrow()) / me->ypixels();
220 return std::tuple<int, int, int>(col, row, layer);
222 int row = (
id / me->idstepbyrow()) % me->zpixels();
223 auto layer = (
id / me->idstepbyrow()) / me->zpixels();
224 return std::tuple<int, int, int>(col, layer, row);
242 return std::tuple<int, int, int>(-1, -1, -1);
246 return getXYZFillFirstZ(me, col,
id);
248 return getXYZFillFirstY(me, col,
id);
250 return getXYZFillFirstX(me, col,
id);
287 double scaling = 1.0;
299 double scaling = 1.0;
311 double scaling = 1.0;
323 double scaling = 1.0;
335 double scaling = 1.0;
347 double scaling = 1.0;
359 double scaling = 1.0;
371 double scaling = 1.0;
383 double scaling = 1.0;
447 throw std::out_of_range(
"GridDetector::getPosAtXYZ: pixel indices are out of range.");
450 return this->
getPos() + relPos;
485 const std::string name_layer = z_layer_str +
std::to_string(ix) +
")";
493 const std::string name_pixel = x_pixel_str +
std::to_string(iy) + z_pixel_str;
512 detector->translate(
x,
y,
z);
515 xColumn->add(detector);
521bool checkValidOrderString(std::array<char, 3UL>
const &order) {
522 return std::all_of(order.cbegin(), order.cend(), [](
char const &c) { return (c >=
'x') && (c <=
'z'); });
529 throw std::invalid_argument(
530 "GridDetector::initialize(): order string should only comprise exactly 3 letters x, y, and z in any order.");
532 throw std::invalid_argument(
"GridDetector::initialize(): xpixels should be > 0");
534 throw std::invalid_argument(
"GridDetector::initialize(): ypixels should be > 0");
538 int ypixels,
double ystart,
double ystep,
int zpixels,
double zstart,
double zstep,
539 int idstart,
const std::string &idFillOrder,
int idstepbyrow,
int idstep) {
604 double ystart,
double ystep,
int zpixels,
double zstart,
double zstep,
int idstart,
605 const std::string &idFillOrder,
int idstepbyrow,
int idstep) {
608 throw std::runtime_error(
"GridDetector::initialize() called for a parametrized GridDetector");
610 initializeValues(std::move(
shape),
xpixels,
xstart,
xstep,
ypixels,
ystart,
ystep,
zpixels,
zstart,
zstep,
idstart,
619 std::ostringstream oss_layer;
620 oss_layer <<
name <<
"(z=" << iz <<
")";
655 return std::shared_ptr<const IComponent>(
this);
660 const std::string MEMBER_NAME = this->
getName() +
"(";
664 if (cname.substr(0, MEMBER_NAME.length()) != MEMBER_NAME) {
665 return std::shared_ptr<const IComponent>();
682 std::deque<IComponent_const_sptr> & )
const {
709 V3D const intersec = beam * (tuv[0] * -1.0);
715 double u = (double(
xpixels() - 1) * tuv[1] + 0.5);
716 double v = (double(
ypixels() - 1) * tuv[2] + 0.5);
721 auto xIndex = int(u);
722 auto yIndex = int(v);
738 auto comp =
getAtXYZ(xIndex, yIndex, 0);
739 testRay.
addLink(intersec, intersec, 0.0, *pixelShape, comp->getComponentID());
786 if (!pixelShape || !pixelShape->hasValidShape()) {
791 const BoundingBox &shapeBox = pixelShape->getBoundingBox();
814 box.
zMin() *= scalez;
815 box.
zMax() *= scalez;
824 box.
xMin() += pixelPos.
X();
825 box.
xMax() += pixelPos.
X();
826 box.
yMin() += pixelPos.
Y();
827 box.
yMax() += pixelPos.
Y();
828 box.
zMin() += pixelPos.
Z();
829 box.
zMax() += pixelPos.
Z();
899 std::ostringstream xmlShapeStream;
900 xmlShapeStream <<
" <cuboid id=\"detector-shape\"> "
901 <<
"<left-front-bottom-point x=\"" << szX <<
"\" y=\"" << -szY <<
"\" z=\"" << -szZ <<
"\" /> "
902 <<
"<left-front-top-point x=\"" << szX <<
"\" y=\"" << -szY <<
"\" z=\"" << szZ <<
"\" /> "
903 <<
"<left-back-bottom-point x=\"" << -szX <<
"\" y=\"" << -szY <<
"\" z=\"" << -szZ <<
"\" /> "
904 <<
"<right-front-bottom-point x=\"" << szX <<
"\" y=\"" << szY <<
"\" z=\"" << -szZ <<
"\" /> "
907 std::string xmlCuboidShape(xmlShapeStream.str());
909 std::shared_ptr<Geometry::IObject> cuboidShape = shapeCreator.
createShape(xmlCuboidShape);
938 os <<
"************************\n";
939 os <<
"Number of children :" << ass.
nelements() <<
'\n';
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
double xMax() const
Return the maximum value of X.
double zMin() const
Return the minimum value of Z.
bool isNull() const
Is this a default constructed box?
double zMax() const
Return the maximum value of Z.
double yMax() const
Return the maximum value of Y.
double xMin() const
Return the minimum value of X.
double yMin() const
Return the minimum value of Y.
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.
Kernel::V3D getPos() const override
Gets the absolute position of the Parametrized CompAssembly This attempts to read the cached position...
Kernel::Quat getRotation() const override
Gets the absolute position of the Parametrized CompAssembly This attempts to read the cached position...
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.
size_t index() const
Helper for legacy access mode. Returns the index of the component.
bool hasComponentInfo() const
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::array< char, 3UL > const & idFillOrder() const
returns dimensions of filling in order
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.
detid_t const & minDetectorID() const
minimum detector id
int const & ypixels() const
Returns the number of pixels in the Y direction.
Kernel::V3D getPosAtXYZ(int const x, int const y, int const z) const
Returns the position of the center of the pixel at x,y, relative to the center of the GridDetector,...
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.
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.
bool const & idfillbyfirst_y() const
returns if IDs are filled along y direction first
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.
const GridDetector * m_gridBase
Pointer to the base GridDetector, for parametrized instruments.
int const & xpixels() const
Returns the number of pixels in the X direction.
double m_xstart
X position of the 0-th pixel.
const Kernel::Material material() const override
Returns the material of the detector.
int const & idstepbyrow() const
Returns the idstepbyrow.
friend class GridDetectorPixel
void createLayer(const std::string &name, CompAssembly *parent, int iz, int &minDetID, int &maxDetID)
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...
std::array< char, 3UL > m_idFillOrder
The order in which to fill IDs.
double m_zsize
Size in Z of the detector.
int const & zpixels() const
Returns the number of pixels in the Z direction.
double xstart() const
Returns the start position in the X direction.
detid_t const & maxDetectorID() const
maximum detector id
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 m_idstart
IDs start here.
double zstart() const
Returns the start position in the Z direction.
double solidAngle(const Geometry::SolidAngleParams ¶ms) 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 const & idstart() const
Returns the idstart.
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.
void validateInput() const
double zstep() const
Returns the step size in the Z direction.
void getBoundingBoxAtXYZ(int const x, int const y, int const z, BoundingBox &box) const
bool inBoundsXYZ(const int x, const int y, const int z) const
int const & idstep() const
Returns the idstep.
Kernel::V3D getRelativePosAtXYZ(int const x, int const y, int const z) const
Returns the position of the center of the pixel at x,y, relative to the center of the GridDetector,...
detid_t m_maxDetId
maximum detector id
base class for Geometric IComponent
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.
friend class 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.
const Kernel::V3D & startPoint() const
Returns the starting point.
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.
const Kernel::V3D & direction() const
Returns the direction as a unit vector.
Marks code as not implemented yet.
A material is defined as being composed of a given element, defined as a PhysicalConstants::NeutronAt...
T Invert()
LU inversion routine.
void setColumn(const size_t nCol, const std::vector< T > &newCol)
void rotate(V3D &) const
Rotate a vector.
void rotateBB(double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const
Taking two points defining a cuboid bounding box (xmin,ymin,zmin) and.
constexpr double X() const noexcept
Get x.
constexpr double Y() const noexcept
Get y.
constexpr double Z() const noexcept
Get z.
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)