32 throw std::invalid_argument(
"MCInteractionVolume() - Sample enviroment has zero components.");
34 }
catch (std::runtime_error &) {
39 bool atLeastOneValidShape =
m_sample->hasValidShape();
40 if (!atLeastOneValidShape &&
m_env) {
43 atLeastOneValidShape =
true;
48 if (!atLeastOneValidShape) {
49 throw std::invalid_argument(
"MCInteractionVolume() - Either the Sample or one of the "
50 "environment parts must have a valid shape.");
66std::shared_ptr<IMCInteractionVolume>
70 std::shared_ptr<MCInteractionVolume>(
new MCInteractionVolume(sample, maxScatterAttempts, pointsIn, gaugeVolume));
73 interactionVol->init();
74 return interactionVol;
91 : m_sample(sample.getShape().clone()), m_env(sample.hasEnvironment() ? &sample.getEnvironment() : nullptr),
92 m_maxScatterAttempts(maxScatterAttempts), m_pointsIn(pointsIn), m_gaugeVolume(
std::move(gaugeVolume)) {}
112 auto sampleBox =
m_sample->getBoundingBox();
117 sampleBox.
grow(envBox);
136 const int sampleIndex = -1;
137 const int firstEnvIndex = sampleIndex + 1;
138 int startIndex = sampleIndex;
141 startIndex = firstEnvIndex;
143 endIndex = sampleIndex;
144 if (startIndex == endIndex) {
147 return rng.
nextInt(startIndex, endIndex);
160std::optional<Kernel::V3D>
162 std::optional<Kernel::V3D> pointGenerated{std::nullopt};
163 std::optional<Kernel::V3D> tmpPoint{std::nullopt};
164 if (componentIndex == -1) {
168 if (
m_sample->isValid(tmpPoint.value())) {
169 pointGenerated = tmpPoint;
178 return pointGenerated;
195 if (pointGenerated) {
196 return {componentIndex, *pointGenerated};
199 throw std::runtime_error(
"MCInteractionVolume::generatePoint() - Unable to "
200 "generate point in object after " +
233 auto beforeScatter = std::make_shared<Track>(scatterPos.
scatterPoint, toStart);
234 int nlinks =
m_sample->interceptSurface(*beforeScatter);
241 return {
false,
nullptr,
nullptr};
247 auto afterScatter = std::make_shared<Track>(scatterPos.
scatterPoint, scatteredDirec);
248 m_sample->interceptSurface(*afterScatter);
253 return {
true, beforeScatter, afterScatter};
This class stores information about the sample used in particular run.
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.
Defines a volume where interactions of Tracks and Objects can take place.
Geometry::IObject_sptr getGaugeVolume() const override
Returns the defined gauge volume if one is present, otherwise returns nullptr.
Geometry::IObject_sptr m_gaugeVolume
const Geometry::BoundingBox getFullBoundingBox() const override
Returns the defined gauge volume if one is present, otherwise returns axis-aligned bounding box for t...
const ScatteringPointVicinity m_pointsIn
const Geometry::SampleEnvironment * m_env
int getComponentIndex(Kernel::PseudoRandomNumberGenerator &rng) const
Randomly select a component across the sample/environment.
std::optional< Kernel::V3D > generatePointInObjectByIndex(int componentIndex, Kernel::PseudoRandomNumberGenerator &rng) const
Generate a point in an object identified by an index.
static std::shared_ptr< IMCInteractionVolume > create(const API::Sample &sample, const size_t maxScatterAttempts=5000, const ScatteringPointVicinity pointsIn=ScatteringPointVicinity::SAMPLEANDENVIRONMENT, Geometry::IObject_sptr gaugeVolume=nullptr)
Factory Method for constructing the volume encompassing the sample + any environment kit.
void init() override
Construct the volume encompassing the sample + any environment kit.
void setGaugeVolume(Geometry::IObject_sptr gaugeVolume) override
Sets the gauge volume on the InteractionVolume.
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
Sets the active region volume on the InteractionVolume.
const std::shared_ptr< Geometry::IObject > m_sample
Geometry::BoundingBox m_activeRegion
const size_t m_maxScatterAttempts
ComponentScatterPoint generatePoint(Kernel::PseudoRandomNumberGenerator &rng) const override
Generate point randomly across one of the components of the environment including the sample itself i...
MCInteractionVolume(const API::Sample &sample, const size_t maxScatterAttempts=5000, const ScatteringPointVicinity pointsIn=ScatteringPointVicinity::SAMPLEANDENVIRONMENT, Geometry::IObject_sptr gaugeVolume=nullptr)
Construct the volume encompassing the sample + any environment kit.
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 std::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
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
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)