Mantid
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::Algorithms::DiscusMultipleScatteringCorrection Class Reference

Calculates a multiple scattering correction Based on Muscat Fortran code provided by Spencer Howells. More...

#include <DiscusMultipleScatteringCorrection.h>

Inheritance diagram for Mantid::Algorithms::DiscusMultipleScatteringCorrection:
Mantid::API::Algorithm Mantid::API::IAlgorithm Mantid::Kernel::IPropertyManager

Public Types

using ComponentWorkspaceMappings = boost::container::small_vector< ComponentWorkspaceMapping, 5 >
 
- Public Types inherited from Mantid::API::Algorithm
using WorkspaceVector = std::vector< std::shared_ptr< Workspace > >
 

Public Member Functions

const std::string alias () const override
 function to return any aliases of the algorithm.
 
const std::string category () const override
 Algorithm's category for identification.
 
bool checkGroups () override
 Check the input workspace properties for groups.
 
const std::string name () const override
 Algorithm's name.
 
const std::vector< std::string > seeAlso () const override
 Function to return all of the seeAlso algorithms related to this algorithm.
 
const std::string summary () const override
 Summary of algorithms purpose.
 
int version () const override
 Algorithm's version.
 
- Public Member Functions inherited from Mantid::API::Algorithm
 Algorithm ()
 Constructor.
 
 Algorithm (const Algorithm &)=delete
 
Algorithmoperator= (const Algorithm &)=delete
 
 ~Algorithm () override
 Virtual destructor.
 
void initialize () override
 Initialization method invoked by the framework.
 
bool execute () override final
 The actions to be performed by the algorithm on a dataset.
 
void addTimer (const std::string &name, const Kernel::time_point_ns &begin, const Kernel::time_point_ns &end)
 
void executeAsChildAlg () override
 Execute as a Child Algorithm.
 
std::map< std::string, std::string > validateInputs () override
 Perform validation of ALL the input properties of the algorithm.
 
ExecutionState executionState () const override
 Gets the current execution state.
 
ResultState resultState () const override
 Gets the current result State.
 
bool isInitialized () const override
 Has the Algorithm already been initialized.
 
bool isExecuted () const override
 Has the Algorithm already been executed successfully.
 
bool isRunning () const override
 True if the algorithm is running.
 
bool isReadyForGarbageCollection () const override
 True if the algorithm is ready for garbage collection.
 
bool isChild () const override
 To query whether algorithm is a child.
 
void setChild (const bool isChild) override
 To set whether algorithm is a child.
 
void enableHistoryRecordingForChild (const bool on) override
 Change the state of the history recording flag.
 
bool isRecordingHistoryForChild ()
 
void setAlwaysStoreInADS (const bool doStore) override
 Do we ALWAYS store in the AnalysisDataService? This is set to true for python algorithms' child algorithms.
 
bool getAlwaysStoreInADS () const override
 Returns true if we always store in the AnalysisDataService.
 
void setRethrows (const bool rethrow) override
 Set whether the algorithm will rethrow exceptions.
 
Poco::ActiveResult< bool > executeAsync () override
 Asynchronous execution.
 
void addObserver (const Poco::AbstractObserver &observer) const override
 Add an observer for a notification.
 
void removeObserver (const Poco::AbstractObserver &observer) const override
 Remove an observer.
 
void cancel () override
 Raises the cancel flag.
 
bool getCancel () const
 Returns the cancellation state.
 
Kernel::LoggergetLogger () const
 Returns a reference to the logger.
 
void setLogging (const bool value) override
 Logging can be disabled by passing a value of false.
 
bool isLogging () const override
 returns the status of logging, True = enabled
 
void setLoggingOffset (const int value) override
 gets the logging priority offset
 
int getLoggingOffset () const override
 returns the logging priority offset
 
void setAlgStartupLogging (const bool enabled) override
 disable Logging of start and end messages
 
bool getAlgStartupLogging () const override
 get the state of Logging of start and end messages
 
void setChildStartProgress (const double startProgress) const override
 setting the child start progress
 
void setChildEndProgress (const double endProgress) const override
 setting the child end progress
 
std::string toString () const override
 Serialize an object to a string.
 
::Json::Value toJson () const override
 Serialize an object to a json object.
 
virtual std::shared_ptr< AlgorithmcreateChildAlgorithm (const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
 Create a Child Algorithm.
 
void setupAsChildAlgorithm (const Algorithm_sptr &algorithm, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true)
 Setup algorithm as child algorithm.
 
void trackAlgorithmHistory (std::shared_ptr< AlgorithmHistory > parentHist)
 set whether we wish to track the child algorithm's history and pass it the parent object to fill.
 
void findWorkspaces (WorkspaceVector &workspaces, unsigned int direction, bool checkADS=false) const
 Populate lists of the workspace properties for a given direction (InOut workspaces are included in both input/output)
 
virtual bool processGroups ()
 Process WorkspaceGroup inputs.
 
void copyNonWorkspaceProperties (IAlgorithm *alg, int periodNum)
 Copy all the non-workspace properties from this to alg.
 
void declareProperty (std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
 Add a property to the list of managed properties.
 
void declareOrReplaceProperty (std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
 Add or replace property in the list of managed properties.
 
void resetProperties () override
 Reset property values back to initial values (blank or default values)
 
void setProperties (const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
 Set the ordered list of properties by one string of values, separated by semicolons.
 
void setProperties (const ::Json::Value &jsonValue, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
 Sets all the declared properties from a json object.
 
void setPropertiesWithString (const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >()) override
 Sets all the declared properties from a string.
 
void setPropertyValue (const std::string &name, const std::string &value) override
 Set the value of a property by string N.B.
 
void setPropertyValueFromJson (const std::string &name, const Json::Value &value) override
 Set the value of a property by Json::Value object.
 
void setPropertyOrdinal (const int &index, const std::string &value) override
 Set the value of a property by an index N.B.
 
virtual void copyPropertiesFrom (const Algorithm &alg)
 Make m_properties point to the same PropertyManager as alg.m_properties.
 
bool existsProperty (const std::string &name) const override
 Checks whether the named property is already in the list of managed property.
 
bool validateProperties () const override
 Validates all the properties in the collection.
 
size_t propertyCount () const override
 Count the number of properties under management.
 
std::string getPropertyValue (const std::string &name) const override
 Get the value of a property as a string.
 
const std::vector< Kernel::Property * > & getProperties () const override
 Get the list of managed properties.
 
std::vector< std::string > getDeclaredPropertyNames () const noexcept override
 Return the list of declared property names.
 
TypedValue getProperty (const std::string &name) const override
 Get the value of a property.
 
std::string asString (bool withDefaultValues=false) const override
 Return the property manager serialized as a string.
 
::Json::Value asJson (bool withDefaultValues=false) const override
 Return the property manager serialized as a json object.
 
bool isDefault (const std::string &name) const
 
void removeProperty (const std::string &name, const bool delproperty=true) override
 Removes the property from management.
 
std::unique_ptr< Kernel::PropertytakeProperty (const size_t index) override
 Removes the property from management and returns a pointer to it.
 
void clear () override
 Clears all properties under management.
 
void afterPropertySet (const std::string &) override
 Override this method to perform a custom action right after a property was set.
 
Kernel::PropertygetPointerToProperty (const std::string &name) const override
 Get a property by name.
 
Kernel::PropertygetPointerToPropertyOrdinal (const int &index) const override
 Get a property by an index.
 
virtual void declareProperty (std::unique_ptr< Property > p, const std::string &doc="")=0
 Function to declare properties (i.e. store them)
 
template<typename T >
void declareProperty (const std::string &name, T value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc="", const unsigned int direction=Direction::Input)
 Add a property of the template type to the list of managed properties.
 
template<typename T >
void declareProperty (const std::string &name, T value, const std::string &doc, const unsigned int direction=Direction::Input)
 Add a property to the list of managed properties with no validator.
 
template<typename T >
void declareProperty (const std::string &name, T value, const unsigned int direction)
 Add a property of the template type to the list of managed properties.
 
void declareProperty (const std::string &name, const char *value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc=std::string(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string).
 
void declareProperty (const std::string &name, const char *value, const std::string &doc, IValidator_sptr validator=std::make_shared< NullValidator >(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string).
 
void declareProperty (const std::string &name, const char *value, const unsigned int direction)
 Add a property of string type to the list of managed properties.
 
const std::string category () const override
 function to return a category of the algorithm.
 
const std::vector< std::string > categories () const override
 Function to return all of the categories that contain this algorithm.
 
const std::string categorySeparator () const override
 Function to return the separator token for the category string.
 
const std::vector< std::string > seeAlso () const override
 Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm.A default implementation is provided.
 
const std::string alias () const override
 function to return any aliases to the algorithm; A default implementation is provided
 
const std::string aliasDeprecated () const override
 Expiration date (in ISO8601 format) for the algorithm aliases; default implementation for no expiration date.
 
const std::string helpURL () const override
 function to return URL for algorithm documentation; A default implementation is provided.
 
template<typename T , typename = typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
std::tuple< std::shared_ptr< T >, Indexing::SpectrumIndexSet > getWorkspaceAndIndices (const std::string &name) const
 Mechanism for retriving the index property.
 
template<typename T1 , typename T2 , typename = typename std::enable_if<std::is_convertible<T1 *, MatrixWorkspace *>::value>::type, typename = typename std::enable_if<std::is_convertible<T2 *, std::string *>::value || std::is_convertible<T2 *, std::vector<int64_t> *>::value>::type>
void setWorkspaceInputProperties (const std::string &name, const std::shared_ptr< T1 > &wksp, IndexType type, const T2 &list)
 Mechanism for setting the index property with a workspace shared pointer.
 
template<typename T1 , typename T2 , typename = typename std::enable_if<std::is_convertible<T1 *, MatrixWorkspace *>::value>::type, typename = typename std::enable_if<std::is_convertible<T2 *, std::string *>::value || std::is_convertible<T2 *, std::vector<int64_t> *>::value>::type>
void setWorkspaceInputProperties (const std::string &name, const std::string &wsName, IndexType type, const T2 &list)
 Mechanism for setting the index property with a workspace shared pointer.
 
const std::string workspaceMethodName () const override
 
const std::vector< std::string > workspaceMethodOn () const override
 
const std::string workspaceMethodInputProperty () const override
 
AlgorithmID getAlgorithmID () const override
 Algorithm ID.
 
Algorithms As Methods
- Public Member Functions inherited from Mantid::Kernel::IPropertyManager
void declareProperty (const std::string &name, const char *value, const std::string &doc, IValidator_sptr validator=std::make_shared< NullValidator >(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string).
 
void declareProperty (const std::string &name, const char *value, const unsigned int direction)
 Add a property of string type to the list of managed properties.
 
void declareProperty (const std::string &name, const char *value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc=std::string(), const unsigned int direction=Direction::Input)
 Specialised version of declareProperty template method to prevent the creation of a PropertyWithValue of type const char* if an argument in quotes is passed (it will be converted to a string).
 
template<typename T >
void declareProperty (const std::string &name, T value, const std::string &doc, const unsigned int direction=Direction::Input)
 Add a property to the list of managed properties with no validator.
 
template<typename T >
void declareProperty (const std::string &name, T value, const unsigned int direction)
 Add a property of the template type to the list of managed properties.
 
template<typename T >
void declareProperty (const std::string &name, T value, IValidator_sptr validator=std::make_shared< NullValidator >(), const std::string &doc="", const unsigned int direction=Direction::Input)
 Add a property of the template type to the list of managed properties.
 
virtual void filterByProperty (Mantid::Kernel::LogFilter *, const std::vector< std::string > &)
 
std::vector< Property * > getPropertiesInGroup (const std::string &group) const
 Get the list of managed properties in a given group.
 
IPropertyManagersetProperty (const std::string &name, const char *value)
 Specialised version of setProperty template method to handle const char *.
 
IPropertyManagersetProperty (const std::string &name, const std::string &value)
 Specialised version of setProperty template method to handle std::string.
 
template<typename T >
IPropertyManagersetProperty (const std::string &name, const T &value)
 Templated method to set the value of a PropertyWithValue.
 
template<typename T >
IPropertyManagersetProperty (const std::string &name, std::unique_ptr< T > value)
 Templated method to set the value of a PropertyWithValue from a std::unique_ptr.
 
void setPropertyGroup (const std::string &name, const std::string &group)
 Set the group for a given property.
 
void setPropertySettings (const std::string &name, std::unique_ptr< IPropertySettings > settings)
 
void updatePropertyValues (const IPropertyManager &other)
 Update values of the existing properties.
 
virtual ~IPropertyManager ()=default
 

Protected Member Functions

const std::shared_ptr< Geometry::CSGObjectcreateCollimatorHexahedronShape (const Kernel::V3D &samplePos, const Mantid::Geometry::DetectorInfo &detectorInfo, const size_t &histogramIndex)
 
virtual std::unique_ptr< InterpolationOptioncreateInterpolateOption ()
 Factory method to return an instance of the required InterpolationOption class.
 
virtual std::shared_ptr< SparseWorkspacecreateSparseWorkspace (const API::MatrixWorkspace &modelWS, const size_t nXPoints, const size_t rows, const size_t columns)
 Factory method to return an instance of the required SparseInstrument class.
 
void getXMinMax (const Mantid::API::MatrixWorkspace &ws, double &xmin, double &xmax) const
 This is a variation on the function MatrixWorkspace::getXMinMax with some additional logic eg if x values are all NaN values it raises an error.
 
void integrateCumulative (const DiscusData1D &h, const double xmin, const double xmax, std::vector< double > &resultX, std::vector< double > &resultY, const bool returnCumulative)
 Integrate a distribution between the supplied xmin and xmax values using trapezoid rule without any extrapolation on either end of the distribution Return the integral for each x value between xmin and xmax.
 
API::MatrixWorkspace_sptr integrateWS (const API::MatrixWorkspace_sptr &ws)
 Create new workspace with y equal to integral across the bins.
 
double Interpolate2D (const ComponentWorkspaceMapping &SQWSMapping, double q, double w)
 Interpolate value on S(Q,w) surface given a Q and w.
 
double interpolateFlat (const DiscusData1D &histToInterpolate, double x)
 Interpolate function using flat interpolation from previous point.
 
double interpolateGaussian (const DiscusData1D &histToInterpolate, double x)
 Interpolate a value from a spectrum containing Gaussian peaks.
 
double interpolateSquareRoot (const DiscusData1D &histToInterpolate, double x)
 Interpolate function of the form y = a * sqrt(x - b) ie inverse of a quadratic Used to lookup value in the cumulative probability distribution of Q S(Q) which for flat S(Q) will be a quadratic.
 
void prepareSampleBeamGeometry (const API::MatrixWorkspace_sptr &inputWS)
 
std::tuple< double, int > sampleQW (const std::shared_ptr< DiscusData2D > &CumulativeProb, double x)
 Use importance sampling to choose a Q and w value for the scatter.
 
void updateTrackDirection (Geometry::Track &track, const double cosT, const double phi)
 Update the track's direction following a scatter event given theta and phi angles.
 
- Protected Member Functions inherited from Mantid::API::Algorithm
virtual const std::string workspaceMethodOnTypes () const
 Returns a semi-colon separated list of workspace types to attach this algorithm.
 
void cacheWorkspaceProperties ()
 Go through the properties and cache the input/output workspace properties for later use.
 
void cacheInputWorkspaceHistories ()
 Cache the histories of any input workspaces so they can be copied over after algorithm completion.
 
void setExecutionState (const ExecutionState state)
 Sets the current execution state.
 
void setResultState (const ResultState state)
 Sets the result execution state.
 
void store ()
 Stores any output workspaces into the AnalysisDataService.
 
void progress (double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
 Sends ProgressNotification.
 
void interruption_point ()
 This is called during long-running operations, and check if the algorithm has requested that it be cancelled.
 
Poco::NotificationCenter & notificationCenter () const
 Return a reference to the algorithm's notification dispatcher.
 
void handleChildProgressNotification (const Poco::AutoPtr< ProgressNotification > &pNf)
 Observation slot for child algorithm progress notification messages, these are scaled and then signalled for this algorithm.
 
const Poco::AbstractObserver & progressObserver () const
 Return a reference to the algorithm's object that is reporting progress.
 
bool isWorkspaceProperty (const Kernel::Property *const prop) const
 checks the property is a workspace property
 
bool trackingHistory ()
 get whether we are tracking the history for this algorithm,
 
virtual void fillHistory ()
 Copy workspace history from input workspaces to output workspaces and record the history for ths algorithm.
 
void fillHistory (const std::vector< Workspace_sptr > &outputWorkspaces)
 Copy workspace history from input workspaces to provided vector of output workspaces.
 
virtual void setOtherProperties (IAlgorithm *alg, const std::string &propertyName, const std::string &propertyValue, int periodNum)
 Virtual method to set the non workspace properties for this algorithm.
 
template<typename T , const int AllowedIndexTypes = static_cast<int>(IndexType::WorkspaceIndex), typename... WSPropArgs, typename = typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
void declareWorkspaceInputProperties (const std::string &propertyName, const std::string &doc, WSPropArgs &&...wsPropArgs)
 Declare a property which defines the workspace and allowed index types, as well as a property for capturing the indices all at once.
 
- Protected Member Functions inherited from Mantid::Kernel::IPropertyManager
template<typename T >
getValue (const std::string &name) const
 Templated method to get the value of a property.
 
template<>
MANTID_KERNEL_DLL PropertyManager_sptr getValue (const std::string &name) const
 
template<>
MANTID_KERNEL_DLL PropertyManager_const_sptr getValue (const std::string &name) const
 

Private Member Functions

void addWorkspaceToDiscus2DData (const Geometry::IObject_const_sptr &shape, const std::string_view &matName, API::MatrixWorkspace_sptr ws)
 Function to convert between a Matrix workspace and the internal simplified 2D data structure.
 
void calculateQSQIntegralAsFunctionOfK (ComponentWorkspaceMappings &matWSs, const std::vector< double > &specialKs)
 This is a generalised version of the normalisation done in the original Discus algorithm The original algorithm only considered two scatters so there was only ever one scatter with a free direction after scatter that got a contribution from the q_dir function.
 
void convertToLogWorkspace (const std::shared_ptr< DiscusData2D > &SOfQ)
 
void convertWsBothAxesToPoints (API::MatrixWorkspace_sptr &ws)
 Convert x axis of a workspace to points if it's bin edges.
 
void correctForWorkspaceNameClash (std::string &wsName)
 Adjust workspace name in case of clash in the ADS.
 
void createInvPOfQWorkspaces (ComponentWorkspaceMappings &matWSs, size_t nhists)
 
API::MatrixWorkspace_sptr createOutputWorkspace (const API::MatrixWorkspace &inputWS) const
 
void exec () override
 Execution code.
 
const ComponentWorkspaceMappingfindMatchingComponent (const ComponentWorkspaceMappings &componentWorkspaces, const Geometry::IObject *shapeObjectWithScatter)
 Lookup a sample or sample environment component in the supplied list.
 
Geometry::Track generateInitialTrack (Kernel::PseudoRandomNumberGenerator &rng)
 Generate an initial track starting at the source and entering the sample/sample environment at a random point on its front surface.
 
std::vector< std::tuple< double, int, double > > generateInputKOutputWList (const double efixed, const std::vector< double > &xPoints)
 Generate a list of the k and w points where calculation results are required.
 
double getDoubleParamFromIDF (std::string paramName)
 
double getKf (const double deltaE, const double kinc)
 
std::tuple< double, double > getKinematicRange (double kf, double ki)
 Get the range of q values accessible for a particular kinc and kf.
 
double getQSQIntegral (const DiscusData1D &QSQScaleFactor, double k)
 This is a generalised version of the normalisation done in the original Discus algorithm The original algorithm only considered two scatters so there was only ever one scatter with a free direction after scatter that got a contribution from the q_dir function.
 
Kernel::V3D getV3DParamFromIDF (std::string paramName)
 
void inc_xyz (Geometry::Track &track, double vl)
 Update the x, y, z position of the neutron (or dV volume element to integrate over).
 
void init () override
 Initialize the algorithm.
 
std::tuple< std::vector< double >, std::vector< double >, std::vector< double > > integrateQSQ (const std::shared_ptr< DiscusData2D > &QSQ, double kinc, const bool returnCumulative)
 Integrate QSQ over Q and w over the kinematic range accessible for a given kinc.
 
void interpolateFromSparse (API::MatrixWorkspace &targetWS, const SparseWorkspace &sparseWS, const Mantid::Algorithms::InterpolationOption &interpOpt)
 
void loadCollimatorInfo ()
 
std::tuple< double, double > new_vector (const Kernel::Material &material, double k, bool specialSingleScatterCalc)
 Calculate a total cross section using a k-specific scattering cross section Note - a separate tabulated scattering cross section is used elsewhere in the calculation.
 
void prepareCumulativeProbForQ (double kinc, const ComponentWorkspaceMappings &PInvOfQs)
 Calculate a cumulative probability distribution for use in importance sampling.
 
void prepareQSQ (double kinc)
 Prepare a profile of Q*S(Q) that will later be used to calculate a cumulative probability distribution for use in importance sampling.
 
void prepareStructureFactors ()
 
bool q_dir (Geometry::Track &track, const Geometry::IObject *shapePtr, const ComponentWorkspaceMappings &invPOfQs, double &k, const double scatteringXSection, Kernel::PseudoRandomNumberGenerator &rng, double &weight)
 Update track direction and weight as a result of a scatter.
 
const std::shared_ptr< Geometry::CSGObjectreadFromCollimatorCorridorCache (const std::size_t &histogramIndex)
 
std::tuple< double, double, int, double > sampleQWUniform (const std::vector< double > &wValues, Kernel::PseudoRandomNumberGenerator &rng, const double kinc)
 Sample the q and w value for a scattering event without importance sampling.
 
std::tuple< bool, std::vector< double > > scatter (const int nScatters, Kernel::PseudoRandomNumberGenerator &rng, const ComponentWorkspaceMappings &componentWorkspaces, const double kinc, const std::vector< double > &wValues, bool specialSingleScatterCalc, const Mantid::Geometry::DetectorInfo &detectorInfo, const size_t &histogramIndex)
 Simulates a single neutron path through the sample to a specific detector position containing the specified number of scattering events.
 
void setWorkspaceName (const API::MatrixWorkspace_sptr &ws, std::string wsName)
 Set the name on a workspace, adjusting for potential clashes in the ADS.
 
std::tuple< std::vector< double >, std::vector< double > > simulatePaths (const int nEvents, const int nScatters, Kernel::PseudoRandomNumberGenerator &rng, const ComponentWorkspaceMappings &componentWorkspaces, const double kinc, const std::vector< double > &wValues, bool specialSingleScatterCalc, const Mantid::Geometry::DetectorInfo &detectorInfo, const size_t &histogramIndex)
 Simulates a set of neutron paths through the sample to a specific detector position with each path containing the specified number of scattering events.
 
Geometry::Track start_point (Kernel::PseudoRandomNumberGenerator &rng)
 Repeatedly attempt to generate an initial track starting at the source and entering the sample at a random point on its front surface.
 
const Geometry::IObjectupdateWeightAndPosition (Geometry::Track &track, double &weight, const double k, Kernel::PseudoRandomNumberGenerator &rng, bool specialSingleScatterCalc, const ComponentWorkspaceMappings &componentWorkspaces)
 update track start point and weight.
 
std::map< std::string, std::string > validateInputs () override
 Validate the input properties.
 
void writeToCollimatorCorridorCache (const std::size_t &histogramIndex, const std::shared_ptr< Geometry::CSGObject > &collimatorCorridorCsgObj)
 

Private Attributes

Geometry::BoundingBox m_activeRegion
 
std::map< int, int > m_attemptsToGenerateInitialTrack
 
std::unique_ptr< IBeamProfilem_beamProfile
 
long long m_callsToInterceptSurface {0}
 
std::map< std::size_t, std::shared_ptr< Geometry::CSGObject > > m_collimatorCorridorCache
 
std::unique_ptr< CollimatorInfom_collimatorInfo
 
Kernel::DeltaEMode::Type m_EMode {Kernel::DeltaEMode::Undefined}
 
const Geometry::SampleEnvironmentm_env {nullptr}
 
long long m_IkCalculations {0}
 
bool m_importanceSampling {}
 
Mantid::Geometry::Instrument_const_sptr m_instrument
 
int m_maxScatterPtAttempts {}
 
std::shared_mutex m_mutexCorridorCache
 
bool m_NormalizeSQ {}
 
std::shared_ptr< const Geometry::ReferenceFramem_refframe
 
Geometry::IObject_const_sptr m_sampleShape
 
std::shared_ptr< const DiscusData1Dm_sigmaSS
 
bool m_simulateEnergiesIndependently {}
 
Kernel::V3D m_sourcePos
 
ComponentWorkspaceMappings m_SQWSs
 

Additional Inherited Members

- Static Public Member Functions inherited from Mantid::API::Algorithm
static IAlgorithm_sptr fromString (const std::string &input)
 De-serialize an object from a string.
 
static IAlgorithm_sptr fromJson (const Json::Value &input)
 De-serialize an object from a Json.
 
static IAlgorithm_sptr fromHistory (const AlgorithmHistory &history)
 Construct an object from a history entry.
 
- Public Attributes inherited from Mantid::API::Algorithm
bool calledByAlias = false
 Flag to indicate if the algorithm is called by its alias.
 
- Static Protected Member Functions inherited from Mantid::API::Algorithm
template<typename NumT >
static bool isEmpty (const NumT toCheck)
 checks that the value was not set by users, uses the value in empty double/int.
 
- Protected Attributes inherited from Mantid::API::Algorithm
std::atomic< bool > m_cancel
 Set to true to stop execution.
 
std::atomic< bool > m_parallelException
 Set if an exception is thrown, and not caught, within a parallel region.
 
std::vector< IWorkspaceProperty * > m_inputWorkspaceProps
 All the WorkspaceProperties that are Input or InOut. Set in execute()
 
std::shared_ptr< AlgorithmHistorym_history
 Pointer to the history for the algorithm being executed.
 
Kernel::Logger m_log
 Logger for this algorithm.
 
Kernel::Loggerg_log
 
std::shared_ptr< AlgorithmHistorym_parentHistory
 Pointer to the parent history object (if set)
 
std::vector< WorkspaceVectorm_unrolledInputWorkspaces
 One vector of workspaces for each input workspace property.
 
size_t m_groupSize
 Size of the group(s) being processed.
 
bool m_usingBaseProcessGroups = false
 distinguish between base processGroups() and overriden/algorithm specific versions
 
- Static Protected Attributes inherited from Mantid::API::Algorithm
static size_t g_execCount = 0
 Counter to keep track of algorithm execution order.
 

Detailed Description

Calculates a multiple scattering correction Based on Muscat Fortran code provided by Spencer Howells.

Author
Danny Hindson
Date
2020-11-10

Definition at line 88 of file DiscusMultipleScatteringCorrection.h.

Member Typedef Documentation

◆ ComponentWorkspaceMappings

Definition at line 91 of file DiscusMultipleScatteringCorrection.h.

Member Function Documentation

◆ addWorkspaceToDiscus2DData()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::addWorkspaceToDiscus2DData ( const Geometry::IObject_const_sptr shape,
const std::string_view &  matName,
API::MatrixWorkspace_sptr  SQWS 
)
private

Function to convert between a Matrix workspace and the internal simplified 2D data structure.

This decouples the internal calculation logic from the Mantid workspaces

Definition at line 425 of file DiscusMultipleScatteringCorrection.cpp.

References convertToLogWorkspace(), convertWsBothAxesToPoints(), Mantid::API::Algorithm::createChildAlgorithm(), Mantid::Algorithms::ComponentWorkspaceMapping::logSQ, and m_SQWSs.

Referenced by prepareStructureFactors().

◆ alias()

const std::string Mantid::Algorithms::DiscusMultipleScatteringCorrection::alias ( ) const
inlineoverridevirtual

function to return any aliases of the algorithm.

Implements Mantid::API::IAlgorithm.

Definition at line 105 of file DiscusMultipleScatteringCorrection.h.

◆ calculateQSQIntegralAsFunctionOfK()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::calculateQSQIntegralAsFunctionOfK ( ComponentWorkspaceMappings matWSs,
const std::vector< double > &  specialKs 
)
private

This is a generalised version of the normalisation done in the original Discus algorithm The original algorithm only considered two scatters so there was only ever one scatter with a free direction after scatter that got a contribution from the q_dir function.

This meant that the k value going into the scatter was always fixed and equal to the overall kinc The approach here will cope with multiple scatters by calculating a sumQSS at multiple kinc values. These will be interpolated as required later on

Parameters
matWSsList of workspaces related to the structure factor for each sample/env component
specialKsA list of special k values that the QSQ integral will be calculated for to reduce amount of interpolation required later on

Definition at line 994 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::DeltaEMode::Elastic, integrateCumulative(), integrateQSQ(), and m_EMode.

Referenced by exec().

◆ category()

const std::string Mantid::Algorithms::DiscusMultipleScatteringCorrection::category ( ) const
inlineoverridevirtual

Algorithm's category for identification.

Implements Mantid::API::IAlgorithm.

Definition at line 100 of file DiscusMultipleScatteringCorrection.h.

◆ checkGroups()

bool Mantid::Algorithms::DiscusMultipleScatteringCorrection::checkGroups ( )
inlineoverridevirtual

Check the input workspace properties for groups.

If there are more than one input workspace properties, then:

  • All inputs should be groups of the same size
    • In this case, algorithms are processed in order
  • OR, only one input should be a group, the others being size of 1

If the property itself is a WorkspaceProperty<WorkspaceGroup> then this returns false

Returns true if processGroups() should be called. It also sets up some other members.

Override if it is needed to customize the group checking.

Exceptions
std::invalid_argumentif the groups sizes are incompatible.
std::invalid_argumentif a member is not found

This method (or an override) must NOT THROW any exception if there are no input workspace groups

Reimplemented from Mantid::API::Algorithm.

Definition at line 106 of file DiscusMultipleScatteringCorrection.h.

◆ convertToLogWorkspace()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::convertToLogWorkspace ( const std::shared_ptr< DiscusData2D > &  SOfQ)
private

Definition at line 967 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Geometry::d.

Referenced by addWorkspaceToDiscus2DData().

◆ convertWsBothAxesToPoints()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::convertWsBothAxesToPoints ( API::MatrixWorkspace_sptr ws)
private

Convert x axis of a workspace to points if it's bin edges.

If the spectrum axis is a numeric axis and also bin edges convert that to points as well

Parameters
wsThe workspace that will potentially be converted

Definition at line 462 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::VectorHelper::convertToBinCentre(), Mantid::API::Algorithm::createChildAlgorithm(), Mantid::API::NumericAxis::getValues(), Mantid::Kernel::SingletonHolder< T >::Instance(), and m_importanceSampling.

Referenced by addWorkspaceToDiscus2DData().

◆ correctForWorkspaceNameClash()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::correctForWorkspaceNameClash ( std::string &  wsName)
private

Adjust workspace name in case of clash in the ADS.

Was mainly of value when member workspaces didn't have the group name as a prefix but have left this in place in case there is a clash for any reason

Parameters
wsNameThe name to set on the workspace

Definition at line 2128 of file DiscusMultipleScatteringCorrection.cpp.

References std::to_string().

Referenced by setWorkspaceName().

◆ createCollimatorHexahedronShape()

const std::shared_ptr< Geometry::CSGObject > Mantid::Algorithms::DiscusMultipleScatteringCorrection::createCollimatorHexahedronShape ( const Kernel::V3D samplePos,
const Mantid::Geometry::DetectorInfo detectorInfo,
const size_t &  histogramIndex 
)
protected

◆ createInterpolateOption()

std::unique_ptr< InterpolationOption > Mantid::Algorithms::DiscusMultipleScatteringCorrection::createInterpolateOption ( )
protectedvirtual

Factory method to return an instance of the required InterpolationOption class.

Returns
a pointer to an InterpolationOption object

Definition at line 2092 of file DiscusMultipleScatteringCorrection.cpp.

◆ createInvPOfQWorkspaces()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::createInvPOfQWorkspaces ( ComponentWorkspaceMappings matWSs,
size_t  nhists 
)
private

Definition at line 2063 of file DiscusMultipleScatteringCorrection.cpp.

References value.

Referenced by exec().

◆ createOutputWorkspace()

MatrixWorkspace_sptr Mantid::Algorithms::DiscusMultipleScatteringCorrection::createOutputWorkspace ( const API::MatrixWorkspace inputWS) const
private

Definition at line 2077 of file DiscusMultipleScatteringCorrection.cpp.

Referenced by exec().

◆ createSparseWorkspace()

std::shared_ptr< SparseWorkspace > Mantid::Algorithms::DiscusMultipleScatteringCorrection::createSparseWorkspace ( const API::MatrixWorkspace modelWS,
const size_t  nXPoints,
const size_t  rows,
const size_t  columns 
)
protectedvirtual

Factory method to return an instance of the required SparseInstrument class.

Parameters
modelWSThe full workspace that the sparse one will be based on
nXPointsThe number of x points (k or w) to include in the histograms in the sparse workspace
rowsThe number of rows of detectors to create
columnsThe number of columns of detectors to create
Returns
a pointer to an SparseInstrument object

Definition at line 2057 of file DiscusMultipleScatteringCorrection.cpp.

Referenced by exec().

◆ exec()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::exec ( )
overrideprivatevirtual

Execution code.

Implements Mantid::API::Algorithm.

Definition at line 497 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Algorithms::InterpolationOption::applyInplace(), Mantid::Kernel::DeltaEMode::asString(), calculateQSQIntegralAsFunctionOfK(), Mantid::API::Algorithm::createChildAlgorithm(), createInvPOfQWorkspaces(), createOutputWorkspace(), createSparseWorkspace(), Mantid::API::ExperimentInfo::detectorInfo(), Mantid::Kernel::DeltaEMode::Direct, Mantid::Kernel::efixed, Mantid::Kernel::DeltaEMode::Elastic, Mantid::API::Algorithm::g_log, generateInputKOutputWList(), Mantid::API::Algorithm::getAlwaysStoreInADS(), Mantid::API::MatrixWorkspace::getNumberHistograms(), Mantid::API::Algorithm::getProperty(), Mantid::API::Algorithm::getPropertyValue(), Mantid::API::MatrixWorkspace::getSpectrum(), Mantid::API::ISpectrum::getSpectrumNo(), getXMinMax(), Mantid::Kernel::Logger::information(), integrateWS(), interpolateFromSparse(), Mantid::Kernel::Logger::is(), Mantid::API::Algorithm::isEmpty(), loadCollimatorInfo(), m_attemptsToGenerateInitialTrack, m_callsToInterceptSurface, m_EMode, m_IkCalculations, m_importanceSampling, m_maxScatterPtAttempts, m_NormalizeSQ, m_sigmaSS, m_simulateEnergiesIndependently, m_SQWSs, PARALLEL_CHECK_INTERRUPT_REGION, PARALLEL_END_INTERRUPT_REGION, PARALLEL_FOR_IF, PARALLEL_START_INTERRUPT_REGION, Mantid::API::MatrixWorkspace::points(), prepareCumulativeProbForQ(), prepareQSQ(), prepareSampleBeamGeometry(), prepareStructureFactors(), Mantid::Kernel::ProgressBase::report(), Mantid::Algorithms::InterpolationOption::set(), Mantid::Kernel::ProgressBase::setNotifyStep(), Mantid::Kernel::IPropertyManager::setProperty(), setWorkspaceName(), simulatePaths(), Mantid::API::ExperimentInfo::spectrumInfo(), Mantid::Kernel::threadSafe(), std::to_string(), and Mantid::Kernel::Logger::warning().

◆ findMatchingComponent()

const ComponentWorkspaceMapping * Mantid::Algorithms::DiscusMultipleScatteringCorrection::findMatchingComponent ( const ComponentWorkspaceMappings componentWorkspaces,
const Geometry::IObject shapeObjectWithScatter 
)
private

Lookup a sample or sample environment component in the supplied list.

Parameters
componentWorkspacesThe list of components, each with some associated workspaces
shapeObjectWithScatterA pointer to the component shape that is to be looked up
Returns
an iterator to the found sample or sample environment component

Definition at line 2164 of file DiscusMultipleScatteringCorrection.cpp.

Referenced by q_dir(), and updateWeightAndPosition().

◆ generateInitialTrack()

Geometry::Track Mantid::Algorithms::DiscusMultipleScatteringCorrection::generateInitialTrack ( Kernel::PseudoRandomNumberGenerator rng)
private

Generate an initial track starting at the source and entering the sample/sample environment at a random point on its front surface.

Parameters
rngRandom number generator
Returns
a track

Definition at line 2012 of file DiscusMultipleScatteringCorrection.cpp.

References m_activeRegion, m_beamProfile, m_refframe, and m_sourcePos.

Referenced by start_point().

◆ generateInputKOutputWList()

std::vector< std::tuple< double, int, double > > Mantid::Algorithms::DiscusMultipleScatteringCorrection::generateInputKOutputWList ( const double  efixed,
const std::vector< double > &  xPoints 
)
private

Generate a list of the k and w points where calculation results are required.

The w points are expressed as bin indices and values. The special bin index value -1 means calculate results for all w bins in the innermost calculation loop using a single set of simulated tracks

Parameters
efixedThe fixed energy (or zero if an elastic calculation)
xPointsThe x points either in momentum (elastic) or energy transfer (inelastic)

Definition at line 795 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Geometry::d, Mantid::Kernel::DeltaEMode::Direct, Mantid::Kernel::efixed, Mantid::Kernel::DeltaEMode::Elastic, index, Mantid::Kernel::DeltaEMode::Indirect, m_EMode, and m_simulateEnergiesIndependently.

Referenced by exec().

◆ getDoubleParamFromIDF()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::getDoubleParamFromIDF ( std::string  paramName)
private

Definition at line 1689 of file DiscusMultipleScatteringCorrection.cpp.

References m_instrument.

Referenced by loadCollimatorInfo().

◆ getKf()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::getKf ( const double  deltaE,
const double  kinc 
)
private

Definition at line 1720 of file DiscusMultipleScatteringCorrection.cpp.

Referenced by integrateQSQ(), and q_dir().

◆ getKinematicRange()

std::tuple< double, double > Mantid::Algorithms::DiscusMultipleScatteringCorrection::getKinematicRange ( double  kf,
double  ki 
)
private

Get the range of q values accessible for a particular kinc and kf.

Since the kinc value is known during the simulation this is similar to direct geometry kinematics w | — |_/________Q | \ \ | \ \

Parameters
kfThe wavevector after the scatter event
kiThe wavevector before the scatter event
Returns
a tuple containing qmin and the qrange

Definition at line 1746 of file DiscusMultipleScatteringCorrection.cpp.

Referenced by integrateQSQ().

◆ getQSQIntegral()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::getQSQIntegral ( const DiscusData1D QSQScaleFactor,
double  k 
)
private

This is a generalised version of the normalisation done in the original Discus algorithm The original algorithm only considered two scatters so there was only ever one scatter with a free direction after scatter that got a contribution from the q_dir function.

This meant that the k value going into the scatter was always fixed and equal to the overall kinc The approach here will cope with multiple scatters by calculating a sumQSS at each required kinc values and cache the results

Definition at line 1802 of file DiscusMultipleScatteringCorrection.cpp.

References interpolateFlat().

Referenced by q_dir().

◆ getV3DParamFromIDF()

Kernel::V3D Mantid::Algorithms::DiscusMultipleScatteringCorrection::getV3DParamFromIDF ( std::string  paramName)
private

Definition at line 1701 of file DiscusMultipleScatteringCorrection.cpp.

References m_instrument.

Referenced by loadCollimatorInfo().

◆ getXMinMax()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::getXMinMax ( const Mantid::API::MatrixWorkspace ws,
double &  xmin,
double &  xmax 
) const
protected

This is a variation on the function MatrixWorkspace::getXMinMax with some additional logic eg if x values are all NaN values it raises an error.

Parameters
wsWorkspace to scan for min and max x values
xminIn/out parameter for min x value found
xmaxIn/out parameter for max x value found

Definition at line 355 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::API::MatrixWorkspace::getNumberHistograms(), Mantid::API::MatrixWorkspace::points(), and Mantid::API::ExperimentInfo::spectrumInfo().

Referenced by exec().

◆ inc_xyz()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::inc_xyz ( Geometry::Track track,
double  vl 
)
private

Update the x, y, z position of the neutron (or dV volume element to integrate over).

Save new start point in to the track object supplied along

Parameters
trackA track defining the current trajectory
vlA distance to move along the current trajectory

Definition at line 2036 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Geometry::Track::clearIntersectionResults(), Mantid::Geometry::Track::direction(), Mantid::Geometry::Track::front(), position, Mantid::Geometry::Track::reset(), Mantid::Geometry::x, Mantid::Geometry::y, and Mantid::Geometry::z.

Referenced by updateWeightAndPosition().

◆ init()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::init ( )
overrideprivatevirtual

◆ integrateCumulative()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::integrateCumulative ( const DiscusData1D h,
const double  xmin,
const double  xmax,
std::vector< double > &  resultX,
std::vector< double > &  resultY,
const bool  returnCumulative 
)
protected

Integrate a distribution between the supplied xmin and xmax values using trapezoid rule without any extrapolation on either end of the distribution Return the integral for each x value between xmin and xmax.

This is the main reason the Integration algorithm isn't used. The Integration algorithm also has some unexpected behaviour for points datasets Return two vectors rather than a histogram for performance reasons and to make transposing it easier

Parameters
hHistogram object containing the distribution to integrate
xminThe lower integration limit
xmaxThe upper integration limit
resultXThe x values at which the integral has been calculated
resultYthe values of the integral at various x values up to xmax
returnCumulativeFlag to indicate whether the function should return the cumulative integral at each x value in the histogram or whether to just return the total integral (quicker)

Definition at line 1068 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::PhysicalConstants::h, std::to_string(), and Mantid::Geometry::x.

Referenced by calculateQSQIntegralAsFunctionOfK(), and integrateQSQ().

◆ integrateQSQ()

std::tuple< std::vector< double >, std::vector< double >, std::vector< double > > Mantid::Algorithms::DiscusMultipleScatteringCorrection::integrateQSQ ( const std::shared_ptr< DiscusData2D > &  QSQ,
double  kinc,
const bool  returnCumulative 
)
private

Integrate QSQ over Q and w over the kinematic range accessible for a given kinc.

Parameters
kincThe incident wavenumber
QSQA workspace containing Q.S(Q,w) with each spectra S(Q) at a particular w
returnCumulativeA flag indicating whether the function should return the cumulative integral at each q value or just the total (quicker)
Returns
a tuple containing a cumulative integral as a function of a pseudo variable based on the q values for each w concatenated into a single 1D sequence, the q values corresponding to each value of the pseudo variable, the w values corresponding to each value of the pseudo variable

Definition at line 884 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::VectorHelper::convertToBinBoundary(), Mantid::Geometry::d, getKf(), getKinematicRange(), integrateCumulative(), and m_IkCalculations.

Referenced by calculateQSQIntegralAsFunctionOfK(), and prepareCumulativeProbForQ().

◆ integrateWS()

API::MatrixWorkspace_sptr Mantid::Algorithms::DiscusMultipleScatteringCorrection::integrateWS ( const API::MatrixWorkspace_sptr ws)
protected

Create new workspace with y equal to integral across the bins.

Parameters
wsThe workspace whose spectra need integrating
Returns
A workspace containing the integrals

Definition at line 1160 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::API::Algorithm::createChildAlgorithm().

Referenced by exec().

◆ Interpolate2D()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::Interpolate2D ( const ComponentWorkspaceMapping SQWSMapping,
double  q,
double  w 
)
protected

Interpolate value on S(Q,w) surface given a Q and w.

For now there is no interpolation between w values so the nearest one is taken. Also S(Q,w) is assumed to be zero for w beyond the w limits of the supplied surface. S(Q,w) is assumed to equal the extreme value for q beyond the q limits

Parameters
SQWSMappingA set of workspaces related to the structure factor to interpolate
qThe momentum transfer (q) value to interpolate at
wThe energy transfer (w) value to interpolate at
Returns
The interpolated S(Q,w) value

Definition at line 1315 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::VectorHelper::indexOfValueFromCentersNoThrow(), interpolateFlat(), interpolateGaussian(), Mantid::Algorithms::ComponentWorkspaceMapping::logSQ, m_importanceSampling, and Mantid::Algorithms::ComponentWorkspaceMapping::SQ.

◆ interpolateFlat()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::interpolateFlat ( const DiscusData1D histToInterpolate,
double  x 
)
protected

Interpolate function using flat interpolation from previous point.

Parameters
histToInterpolateThe histogram containing the data to interpolate
xThe x value to interpolate at
Returns
The interpolated value

Definition at line 1248 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Algorithms::DiscusData1D::X, Mantid::Geometry::x, and Mantid::Algorithms::DiscusData1D::Y.

Referenced by getQSQIntegral(), Interpolate2D(), new_vector(), and sampleQW().

◆ interpolateFromSparse()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::interpolateFromSparse ( API::MatrixWorkspace targetWS,
const SparseWorkspace sparseWS,
const Mantid::Algorithms::InterpolationOption interpOpt 
)
private

◆ interpolateGaussian()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::interpolateGaussian ( const DiscusData1D histToInterpolate,
double  x 
)
protected

Interpolate a value from a spectrum containing Gaussian peaks.

The log of the spectrum has previously been taken so this method does a quadratic interpolation and returns e^y

Parameters
histToInterpolateThe histogram containing the data to interpolate
xThe x value to interpolate at
Returns
The exponential of the interpolated value

Definition at line 1271 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Algorithms::DiscusData1D::X, Mantid::Geometry::x, Mantid::Algorithms::DiscusData1D::Y, and Mantid::Geometry::y.

Referenced by Interpolate2D(), and q_dir().

◆ interpolateSquareRoot()

double Mantid::Algorithms::DiscusMultipleScatteringCorrection::interpolateSquareRoot ( const DiscusData1D histToInterpolate,
double  x 
)
protected

Interpolate function of the form y = a * sqrt(x - b) ie inverse of a quadratic Used to lookup value in the cumulative probability distribution of Q S(Q) which for flat S(Q) will be a quadratic.

Definition at line 1220 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Algorithms::DiscusData1D::X, Mantid::Geometry::x, and Mantid::Algorithms::DiscusData1D::Y.

Referenced by sampleQW().

◆ loadCollimatorInfo()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::loadCollimatorInfo ( )
private

◆ name()

const std::string Mantid::Algorithms::DiscusMultipleScatteringCorrection::name ( ) const
inlineoverridevirtual

Algorithm's name.

Implements Mantid::API::Algorithm.

Definition at line 93 of file DiscusMultipleScatteringCorrection.h.

◆ new_vector()

std::tuple< double, double > Mantid::Algorithms::DiscusMultipleScatteringCorrection::new_vector ( const Kernel::Material material,
double  k,
bool  specialSingleScatterCalc 
)
private

Calculate a total cross section using a k-specific scattering cross section Note - a separate tabulated scattering cross section is used elsewhere in the calculation.

Parameters
materialThe sample material
kThe wavenumber where the cross sections are required
specialSingleScatterCalcBoolean indicating whether special single scatter calculation should be performed
Returns
A tuple containing the total cross section and the scattering cross section

Definition at line 1183 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::Material::absorbXSection(), interpolateFlat(), m_sigmaSS, and Mantid::Kernel::Material::totalScatterXSection().

Referenced by updateWeightAndPosition().

◆ prepareCumulativeProbForQ()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::prepareCumulativeProbForQ ( double  kinc,
const ComponentWorkspaceMappings materialWorkspaces 
)
private

Calculate a cumulative probability distribution for use in importance sampling.

The distribution is the inverse function P^-1(t4) where P(Q) = I(Q)/I(2k) and I(x) = integral of Q.S(Q)dQ between 0 and x

Parameters
kincThe incident wavenumber
materialWorkspacesList of workspaces for each material. Of particular interest here is the inverted cumulative probability distribution which is updated by this method

Definition at line 941 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Geometry::d, and integrateQSQ().

Referenced by exec().

◆ prepareQSQ()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::prepareQSQ ( double  qmax)
private

Prepare a profile of Q*S(Q) that will later be used to calculate a cumulative probability distribution for use in importance sampling.

Parameters
qmaxThe maxmimum q value required based on the data in the InputWorkspace

Definition at line 832 of file DiscusMultipleScatteringCorrection.cpp.

References m_SQWSs.

Referenced by exec().

◆ prepareSampleBeamGeometry()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::prepareSampleBeamGeometry ( const API::MatrixWorkspace_sptr inputWS)
protected

◆ prepareStructureFactors()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::prepareStructureFactors ( )
private

◆ q_dir()

bool Mantid::Algorithms::DiscusMultipleScatteringCorrection::q_dir ( Geometry::Track track,
const Geometry::IObject shapePtr,
const ComponentWorkspaceMappings componentWorkspaces,
double &  k,
const double  scatteringXSection,
Kernel::PseudoRandomNumberGenerator rng,
double &  weight 
)
private

Update track direction and weight as a result of a scatter.

Parameters
trackThe track whose direction will be updated
shapePtrA pointer to the shape in which the scatter is happening
componentWorkspaceslist of workspaces related to the structure factor for each sample/env component
kThe wavevector. Updated from the pre-scatter to post-scatter wavevector during the function
scatteringXSectionThe scattering cross section of the material where the scatter happens
rngRandom number generator
weightThe current weight for this track. Updated to include this scatter during the function

Definition at line 1818 of file DiscusMultipleScatteringCorrection.cpp.

References findMatchingComponent(), getKf(), getQSQIntegral(), interpolateGaussian(), m_importanceSampling, Mantid::Kernel::PseudoRandomNumberGenerator::nextValue(), sampleQW(), sampleQWUniform(), and updateTrackDirection().

◆ readFromCollimatorCorridorCache()

const std::shared_ptr< Geometry::CSGObject > Mantid::Algorithms::DiscusMultipleScatteringCorrection::readFromCollimatorCorridorCache ( const std::size_t &  histogramIndex)
private

◆ sampleQW()

std::tuple< double, int > Mantid::Algorithms::DiscusMultipleScatteringCorrection::sampleQW ( const std::shared_ptr< DiscusData2D > &  CumulativeProb,
double  x 
)
protected

Use importance sampling to choose a Q and w value for the scatter.

Parameters
CumulativeProbThe inverse of the cumulative probability distribution. Both spectra have x set to 0-1. The first spectrum has y set to Q values and the second spectrum as y set to w index values
xA randomly chosen value between 0 and 1
Returns
A tuple containing the sampled Q value and the index of the sampled w value in the S(Q,w) distribution

Definition at line 1210 of file DiscusMultipleScatteringCorrection.cpp.

References interpolateFlat(), interpolateSquareRoot(), and Mantid::Geometry::x.

Referenced by q_dir().

◆ sampleQWUniform()

std::tuple< double, double, int, double > Mantid::Algorithms::DiscusMultipleScatteringCorrection::sampleQWUniform ( const std::vector< double > &  wValues,
Kernel::PseudoRandomNumberGenerator rng,
const double  kinc 
)
private

Sample the q and w value for a scattering event without importance sampling.

Parameters
wValuesThe energy transfer values from the S(Q,w) workspace
rngRandom number generator
kincThe wavevector before the scatter event
Returns
a tuple containing the sampled q, qrange, w and wrange values

Definition at line 1759 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::VectorHelper::convertToBinBoundary(), Mantid::Kernel::VectorHelper::indexOfValueFromCentersNoThrow(), and Mantid::Kernel::PseudoRandomNumberGenerator::nextValue().

Referenced by q_dir().

◆ scatter()

std::tuple< bool, std::vector< double > > Mantid::Algorithms::DiscusMultipleScatteringCorrection::scatter ( const int  nScatters,
Kernel::PseudoRandomNumberGenerator rng,
const ComponentWorkspaceMappings componentWorkspaces,
const double  kinc,
const std::vector< double > &  wValues,
bool  specialSingleScatterCalc,
const Mantid::Geometry::DetectorInfo detectorInfo,
const size_t &  histogramIndex 
)
private

Simulates a single neutron path through the sample to a specific detector position containing the specified number of scattering events.

Each path represents a group of neutrons and the proportion of neutrons making it to the destination without being scattered or absorbed is calculated as a weight using the cross section information from the sample material

Parameters
nScattersThe number of scattering events to simulate along each path
rngRandom number generator
componentWorkspaceslist of workspaces related to the structure factor for each sample/env component
kincThe incident wavevector
wValuesA vector of overall energy transfers
specialSingleScatterCalcBoolean indicating whether special single
detectorInfoObeject to get detector information
histogramIndexIndex of the current histogram being processed
Returns
A tuple containing a success/fail boolean and the calculated weights across the n-1 multiple scatters

Definition at line 1421 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Kernel::V3D::norm(), and Mantid::Kernel::V3D::normalize().

◆ seeAlso()

const std::vector< std::string > Mantid::Algorithms::DiscusMultipleScatteringCorrection::seeAlso ( ) const
inlineoverridevirtual

Function to return all of the seeAlso algorithms related to this algorithm.

Implements Mantid::API::IAlgorithm.

Definition at line 96 of file DiscusMultipleScatteringCorrection.h.

◆ setWorkspaceName()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::setWorkspaceName ( const API::MatrixWorkspace_sptr ws,
std::string  wsName 
)
private

Set the name on a workspace, adjusting for potential clashes in the ADS.

Used to set the names on the output workspace group members. N

Parameters
wsThe ws to set the name on
wsNameThe name to set on the workspace

Definition at line 2152 of file DiscusMultipleScatteringCorrection.cpp.

References correctForWorkspaceNameClash().

Referenced by exec().

◆ simulatePaths()

std::tuple< std::vector< double >, std::vector< double > > Mantid::Algorithms::DiscusMultipleScatteringCorrection::simulatePaths ( const int  nPaths,
const int  nScatters,
Kernel::PseudoRandomNumberGenerator rng,
const ComponentWorkspaceMappings componentWorkspaces,
const double  kinc,
const std::vector< double > &  wValues,
bool  specialSingleScatterCalc,
const Mantid::Geometry::DetectorInfo detectorInfo,
const size_t &  histogramIndex 
)
private

Simulates a set of neutron paths through the sample to a specific detector position with each path containing the specified number of scattering events.

Each path represents a group of neutrons and the proportion of neutrons making it to the destination without being scattered or absorbed is calculated as a weight using the cross section information from the sample material. The average weight across all the simulated paths is returned

Parameters
nPathsThe number of paths to simulate
nScattersThe number of scattering events to simulate along each path
rngRandom number generator
componentWorkspaceslist of workspaces related to the structure factor for each sample/env component
kincThe incident wavevector
wValuesA vector of overall energy transfers
specialSingleScatterCalcBoolean indicating whether special single
detectorInfoObeject to get detector information
histogramIndexIndex for the current histogram being processed
Returns
An average weight across all of the paths

Definition at line 1362 of file DiscusMultipleScatteringCorrection.cpp.

References count, and Mantid::Geometry::d.

Referenced by exec().

◆ start_point()

Geometry::Track Mantid::Algorithms::DiscusMultipleScatteringCorrection::start_point ( Kernel::PseudoRandomNumberGenerator rng)
private

Repeatedly attempt to generate an initial track starting at the source and entering the sample at a random point on its front surface.

After each attempt check the track has at least one intercept with sample shape (sometimes for tracks very close to the surface this can sometimes be zero due to numerical precision)

Parameters
rngRandom number generator
Returns
a track intercepting the sample

Definition at line 1915 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::API::Algorithm::g_log, generateInitialTrack(), Mantid::Geometry::SampleEnvironment::interceptSurfaces(), Mantid::Kernel::Logger::is(), m_attemptsToGenerateInitialTrack, m_callsToInterceptSurface, m_env, m_maxScatterPtAttempts, m_sampleShape, Mantid::Geometry::SampleEnvironment::nelements(), and std::to_string().

◆ summary()

const std::string Mantid::Algorithms::DiscusMultipleScatteringCorrection::summary ( ) const
inlineoverridevirtual

Summary of algorithms purpose.

Implements Mantid::API::Algorithm.

Definition at line 102 of file DiscusMultipleScatteringCorrection.h.

◆ updateTrackDirection()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::updateTrackDirection ( Geometry::Track track,
const double  cosT,
const double  phi 
)
protected

Update the track's direction following a scatter event given theta and phi angles.

Parameters
trackThe track whose direction will be updated
cosTCos two theta. two theta is scattering angle
phiPhi (radians) of after track. Measured in plane perpendicular to initial trajectory

Definition at line 1865 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Geometry::Track::direction(), Mantid::Geometry::Track::reset(), and Mantid::Geometry::Track::startPoint().

Referenced by q_dir().

◆ updateWeightAndPosition()

const Geometry::IObject * Mantid::Algorithms::DiscusMultipleScatteringCorrection::updateWeightAndPosition ( Geometry::Track track,
double &  weight,
const double  k,
Kernel::PseudoRandomNumberGenerator rng,
bool  specialSingleScatterCalc,
const ComponentWorkspaceMappings componentWorkspaces 
)
private

update track start point and weight.

The weight is based on a change of variables from length to t1 as described in Mancinelli paper

Parameters
trackA track defining the current trajectory
weightThe weight for the current path that is about to be updated
kThe wavevector of the track
rngRandom number generator
specialSingleScatterCalcBoolean indicating whether special single scatter calculation should be performed
componentWorkspaceslist of workspaces related to the structure factor for each sample/env component
Returns
the shape object for the component where the scatter occurred

Definition at line 1949 of file DiscusMultipleScatteringCorrection.cpp.

References Mantid::Geometry::Track::cbegin(), Mantid::Geometry::Track::cend(), Mantid::Geometry::Track::count(), findMatchingComponent(), Mantid::API::Algorithm::g_log, inc_xyz(), Mantid::Kernel::Logger::is(), new_vector(), and Mantid::Kernel::PseudoRandomNumberGenerator::nextValue().

◆ validateInputs()

std::map< std::string, std::string > Mantid::Algorithms::DiscusMultipleScatteringCorrection::validateInputs ( void  )
overrideprivatevirtual

◆ version()

int Mantid::Algorithms::DiscusMultipleScatteringCorrection::version ( ) const
inlineoverridevirtual

Algorithm's version.

Implements Mantid::API::Algorithm.

Definition at line 95 of file DiscusMultipleScatteringCorrection.h.

◆ writeToCollimatorCorridorCache()

void Mantid::Algorithms::DiscusMultipleScatteringCorrection::writeToCollimatorCorridorCache ( const std::size_t &  histogramIndex,
const std::shared_ptr< Geometry::CSGObject > &  collimatorCorridorCsgObj 
)
private

Member Data Documentation

◆ m_activeRegion

Geometry::BoundingBox Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_activeRegion
private

◆ m_attemptsToGenerateInitialTrack

std::map<int, int> Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_attemptsToGenerateInitialTrack
private

Definition at line 187 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec(), and start_point().

◆ m_beamProfile

std::unique_ptr<IBeamProfile> Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_beamProfile
private

◆ m_callsToInterceptSurface

long long Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_callsToInterceptSurface {0}
private

Definition at line 185 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec(), and start_point().

◆ m_collimatorCorridorCache

std::map<std::size_t, std::shared_ptr<Geometry::CSGObject> > Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_collimatorCorridorCache
private

◆ m_collimatorInfo

std::unique_ptr<CollimatorInfo> Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_collimatorInfo
private

◆ m_EMode

Kernel::DeltaEMode::Type Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_EMode {Kernel::DeltaEMode::Undefined}
private

◆ m_env

const Geometry::SampleEnvironment* Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_env {nullptr}
private

◆ m_IkCalculations

long long Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_IkCalculations {0}
private

Definition at line 186 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec(), and integrateQSQ().

◆ m_importanceSampling

bool Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_importanceSampling {}
private

◆ m_instrument

Mantid::Geometry::Instrument_const_sptr Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_instrument
private

◆ m_maxScatterPtAttempts

int Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_maxScatterPtAttempts {}
private

Definition at line 188 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec(), and start_point().

◆ m_mutexCorridorCache

std::shared_mutex Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_mutexCorridorCache
mutableprivate

◆ m_NormalizeSQ

bool Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_NormalizeSQ {}
private

Definition at line 199 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec().

◆ m_refframe

std::shared_ptr<const Geometry::ReferenceFrame> Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_refframe
private

◆ m_sampleShape

Geometry::IObject_const_sptr Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_sampleShape
private

◆ m_sigmaSS

std::shared_ptr<const DiscusData1D> Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_sigmaSS
private

Definition at line 189 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec(), and new_vector().

◆ m_simulateEnergiesIndependently

bool Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_simulateEnergiesIndependently {}
private

Definition at line 195 of file DiscusMultipleScatteringCorrection.h.

Referenced by exec(), and generateInputKOutputWList().

◆ m_sourcePos

Kernel::V3D Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_sourcePos
private

◆ m_SQWSs

ComponentWorkspaceMappings Mantid::Algorithms::DiscusMultipleScatteringCorrection::m_SQWSs
private

The documentation for this class was generated from the following files: