Skip to content

Commit

Permalink
Add notification of function eval to MD convolution. Refs #5397
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Aug 3, 2012
1 parent c95595b commit a8b1dc2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,33 @@ namespace Mantid
virtual ~MDResolutionConvolution() {}

/**
* Returns the value of the cross-section convoluted with the resolution for an event
* @param box :: An interator pointing at the current box under examination
* @param innerRunIndex :: The index into the run for this workspace
* @param eventIndex :: An index of the current pixel in the box
*/
virtual double signal(const API::IMDIterator & box, const uint16_t innerRunIndex,
const size_t eventIndex) const = 0;

/**
* Called before any fit/simulation is started to allow caching of
* Called once before any fit/simulation is started to allow caching of
* frequently used parameters
* @param workspace :: The MD that will be used for the fit
*/
virtual void preprocess(const API::IMDEventWorkspace_const_sptr & workspace) { UNUSED_ARG(workspace); }
/**
* Called before any fit/simulation is started to tell the function how many threads will be used.
* Called once before any fit/simulation is started to tell the function how many threads will be used.
* Default does nothing.
*/
virtual void useNumberOfThreads(const int) {}
/**
* Called immediately before the evaluation of the main function starts
*/
virtual void functionEvalStarting() const {}
/**
* Called immediately after the evaluation of the main function finishes
*/
virtual void functionEvalFinished() const {}
/**
* Returns the value of the cross-section convoluted with the resolution for an event
* @param box :: An interator pointing at the current box under examination
* @param innerRunIndex :: The index into the run for this workspace
* @param eventIndex :: An index of the current pixel in the box
*/
virtual double signal(const API::IMDIterator & box, const uint16_t innerRunIndex,
const size_t eventIndex) const = 0;


/// Declares the parameters. Overridden here to ensure that concrete models override it
void declareAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ namespace Mantid

/// Informs the function how many threads will be processing it
void useNumberOfThreads(const int nthreads);
/// Cache detector observations
/// Cache detector observations once when the workspac is set
void preprocess(const API::IMDEventWorkspace_const_sptr & workspace);
/// Resets the random number generator ready for the next call
void functionEvalFinished() const;

/// Declare function attributes
void declareAttributes();
/// Declare fitting parameters
Expand Down Expand Up @@ -118,7 +121,7 @@ namespace Mantid
void function(const Mantid::API::FunctionDomain&, Mantid::API::FunctionValues&) const {}

/// A random number generator
Kernel::NDRandomNumberGenerator *m_randGen;
mutable Kernel::NDRandomNumberGenerator *m_randGen;
/// The value to mark an attribute as active
int m_activeAttrValue;
/// Check for convergence after loop min number of steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ namespace Mantid
delete iterator;
}

/**
* Resets the random number generator ready for the next call.
* This ensures that each evaluation of the function during fitting gets the
* same set of random numbers
*/
void TobyFitResolutionModel::functionEvalFinished() const
{
m_randGen->restart();
}

/**
* Declare function attributes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,11 @@ namespace Mantid

void ResolutionConvolvedCrossSection::function(const API::FunctionDomain& domain, API::FunctionValues& values) const
{
const API::FunctionDomainMD* dmd = dynamic_cast<const API::FunctionDomainMD*>(&domain);
if (!dmd)
{
throw std::invalid_argument("Unexpected domain in IFunctionMD");
}
dmd->reset();
size_t i = 0;
for(const API::IMDIterator* r = dmd->getNextIterator(); r != NULL; r = dmd->getNextIterator())
{
values.setCalculated(i,functionMD(*r));
i++;
};
m_convolution->functionEvalStarting();
IFunctionMD::function(domain, values);
m_convolution->functionEvalFinished();
}


/**
* Returns the value of the function for the given MD box. For each MDPoint
* within the box the convolution of the current model with the resolution
Expand Down

0 comments on commit a8b1dc2

Please sign in to comment.