22#include <boost/regex.hpp>
60 static const boost::regex exp(
"grid_?detector", boost::regex::icase);
61 return boost::regex_match(proposedMatch, exp);
96 throw std::runtime_error(
"GridDetector::getAtXY: invalid X or Y "
97 "width set in the object.");
99 throw std::runtime_error(
"GridDetector::getAtXYZ: x specified is out of range.");
101 throw std::runtime_error(
"GridDetector::getAtXYZ: y specified is out of range.");
104 throw std::runtime_error(
"GridDetector::getAtXYZ: z specified is out of range.");
108 std::shared_ptr<ICompAssembly> xCol;
111 auto zLayer = std::dynamic_pointer_cast<ICompAssembly>(this->
getChild(z));
113 throw std::runtime_error(
"GridDetector::getAtXYZ: z specified is out of range.");
115 xCol = std::dynamic_pointer_cast<ICompAssembly>(zLayer->getChild(
x));
117 xCol = std::dynamic_pointer_cast<ICompAssembly>(this->
getChild(x));
120 throw std::runtime_error(
"GridDetector::getAtXYZ: x specified is out of range.");
121 return std::dynamic_pointer_cast<Detector>(xCol->getChild(
y));
173 return std::tuple<int, int, int>(layer, row, col);
177 return std::tuple<int, int, int>(row, layer, col);
185 return std::tuple<int, int, int>(layer, col, row);
189 return std::tuple<int, int, int>(row, col, layer);
197 return std::tuple<int, int, int>(col, row, layer);
201 return std::tuple<int, int, int>(col, layer, row);
218 return std::tuple<int, int, int>(-1, -1, -1);
263 double scaling = 1.0;
275 double scaling = 1.0;
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;
441 std::ostringstream oss_col;
443 oss_col << name <<
"(z=" << iz <<
","
444 <<
"x=" << ix <<
")";
446 oss_col << name <<
"(x=" << ix <<
")";
448 auto *xColumn =
new CompAssembly(oss_col.str(), parent);
452 std::ostringstream oss;
454 oss << name <<
"(" << ix <<
"," << iy <<
"," << iz <<
")";
456 oss << name <<
"(" << ix <<
"," << iy <<
")";
480 detector->translate(pos);
483 xColumn->add(detector);
489 static const boost::regex exp(
"xyz|xzy|yzx|yxz|zyx|zxy");
491 return boost::regex_match(order, exp);
497 throw std::invalid_argument(
"GridDetector::initialize(): order string "
498 "should only comprise exactly 3 letters x, y, "
499 "and z in any order.");
501 throw std::invalid_argument(
"GridDetector::initialize(): xpixels should be > 0");
503 throw std::invalid_argument(
"GridDetector::initialize(): ypixels should be > 0");
507 int ypixels,
double ystart,
double ystep,
int zpixels,
double zstart,
double zstep,
508 int idstart,
const std::string &idFillOrder,
int idstepbyrow,
int idstep) {
573 double ystart,
double ystep,
int zpixels,
double zstart,
double zstep,
int idstart,
574 const std::string &idFillOrder,
int idstepbyrow,
int idstep) {
577 throw std::runtime_error(
"GridDetector::initialize() called for a "
578 "parametrized GridDetector");
580 initializeValues(std::move(
shape),
xpixels,
xstart,
xstep,
ypixels,
ystart,
ystep,
zpixels,
zstart,
zstep,
idstart,
583 std::string name = this->
getName();
589 std::ostringstream oss_layer;
590 oss_layer << name <<
"(z=" << iz <<
")";
625 return std::shared_ptr<const IComponent>(
this);
630 const std::string MEMBER_NAME = this->
getName() +
"(";
634 if (cname.substr(0, MEMBER_NAME.length()) != MEMBER_NAME) {
635 return std::shared_ptr<const IComponent>();
652 std::deque<IComponent_const_sptr> & )
const {
662 basePoint =
getAtXYZ(0, 0, 0)->getPos();
690 double u = (double(
xpixels() - 1) * tuv[1] + 0.5);
691 double v = (double(
ypixels() - 1) * tuv[2] + 0.5);
696 auto xIndex = int(u);
697 auto yIndex = int(v);
710 auto comp =
getAtXYZ(xIndex, yIndex, 0);
711 testRay.
addLink(intersec, intersec, 0.0, *(comp->shape()), comp->getComponentID());
766 getAtXYZ(0, 0, 0)->getBoundingBox(compBox);
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 <<
"\" /> "
826 std::string xmlCuboidShape(xmlShapeStream.str());
828 std::shared_ptr<Geometry::IObject> cuboidShape = shapeCreator.
createShape(xmlCuboidShape);
857 os <<
"************************\n";
858 os <<
"Number of children :" << ass.
nelements() <<
'\n';
A simple structure that defines an axis-aligned cuboid shaped bounding box for a geometrical object.
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.
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.
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 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
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.
friend class GridDetectorPixel
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.
int m_idstart
IDs start here.
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.
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.
void validateInput() const
double zstep() const
Returns the step size in the Z direction.
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)
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