33 : m_sample(sample.getShape().clone()), m_env(nullptr), m_activeRegion(getFullBoundingBox()),
34 m_maxScatterAttempts(maxScatterAttempts), m_pointsIn(pointsIn) {
39 throw std::invalid_argument(
"MCInteractionVolume() - Sample enviroment has zero components.");
41 }
catch (std::runtime_error &) {
45 bool atLeastOneValidShape =
m_sample->hasValidShape();
46 if (!atLeastOneValidShape &&
m_env) {
49 atLeastOneValidShape =
true;
54 if (!atLeastOneValidShape) {
55 throw std::invalid_argument(
"MCInteractionVolume() - Either the Sample or one of the "
56 "environment parts must have a valid shape.");
66 auto sampleBox =
m_sample->getBoundingBox();
69 sampleBox.
grow(envBox);
84 const int sampleIndex = -1;
85 const int firstEnvIndex = sampleIndex + 1;
86 int startIndex = sampleIndex;
89 startIndex = firstEnvIndex;
91 endIndex = sampleIndex;
92 if (startIndex == endIndex) {
95 return rng.
nextInt(startIndex, endIndex);
108boost::optional<Kernel::V3D>
110 boost::optional<Kernel::V3D> pointGenerated{boost::none};
111 if (componentIndex == -1) {
116 return pointGenerated;
133 if (pointGenerated) {
134 return {componentIndex, *pointGenerated};
137 throw std::runtime_error(
"MCInteractionVolume::generatePoint() - Unable to "
138 "generate point in object after " +
171 auto beforeScatter = std::make_shared<Track>(scatterPos.
scatterPoint, toStart);
172 int nlinks =
m_sample->interceptSurface(*beforeScatter);
179 return {
false,
nullptr,
nullptr};
185 auto afterScatter = std::make_shared<Track>(scatterPos.
scatterPoint, scatteredDirec);
186 m_sample->interceptSurface(*afterScatter);
191 return {
true, beforeScatter, afterScatter};
This class stores information about the sample used in particular run.
const Geometry::SampleEnvironment & getEnvironment() const
Get a reference to the sample's environment.
Stores statistics relating to the tracks generated in MCInteractionVolume for a specific detector.
void UpdateScatterPointCounts(int componentIndex, bool pointUsed)
Update the scatter point counts.
void UpdateScatterAngleStats(const Kernel::V3D &toStart, const Kernel::V3D &scatteredDirec)
Update the scattering angle statistics.
MCInteractionVolume(const API::Sample &sample, const size_t maxScatterAttempts=5000, const ScatteringPointVicinity pointsIn=ScatteringPointVicinity::SAMPLEANDENVIRONMENT)
Construct the volume encompassing the sample + any environment kit.
const Geometry::BoundingBox getFullBoundingBox() const override
Returns the axis-aligned bounding box for the volume including env if m_pointsIn !...
const ScatteringPointVicinity m_pointsIn
const Geometry::SampleEnvironment * m_env
int getComponentIndex(Kernel::PseudoRandomNumberGenerator &rng) const
Randomly select a component across the sample/environment.
boost::optional< Kernel::V3D > generatePointInObjectByIndex(int componentIndex, Kernel::PseudoRandomNumberGenerator &rng) const
Generate a point in an object identified by an index.
virtual TrackPair calculateBeforeAfterTrack(Kernel::PseudoRandomNumberGenerator &rng, const Kernel::V3D &startPos, const Kernel::V3D &endPos, MCInteractionStatistics &stats) const override
Calculate a before scatter and after scatter track based on a scatter point in the volume given a sta...
void setActiveRegion(const Geometry::BoundingBox ®ion) override
const std::shared_ptr< Geometry::IObject > m_sample
ComponentScatterPoint generatePoint(Kernel::PseudoRandomNumberGenerator &rng) const
Generate point randomly across one of the components of the environment including the sample itself i...
Geometry::BoundingBox m_activeRegion
const size_t m_maxScatterAttempts
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.
virtual boost::optional< Kernel::V3D > generatePointInObject(Kernel::PseudoRandomNumberGenerator &rng, const size_t) const =0
virtual bool hasValidShape() const =0
const IObject & getComponent(const size_t index) const
Returns the requested IObject.
Geometry::BoundingBox boundingBox() const
int interceptSurfaces(Track &track) const
Update the given track with intersections within the environment.
Defines a 1D pseudo-random number generator, i.e.
virtual int nextInt(int start, int end)=0
Return the next integer in the sequence.
std::tuple< bool, std::shared_ptr< Geometry::Track >, std::shared_ptr< Geometry::Track > > TrackPair
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Helper class which provides the Collimation Length for SANS instruments.
std::string to_string(const wide_integer< Bits, Signed > &n)