Skip to content

Commit

Permalink
refs #3868. reduce variable scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcampbell committed Dec 30, 2011
1 parent aed2db1 commit 16863c6
Showing 1 changed file with 72 additions and 72 deletions.
144 changes: 72 additions & 72 deletions Code/Mantid/Framework/Algorithms/src/ApplyDeadTimeCorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,111 +27,111 @@ namespace Mantid
namespace Algorithms
{

// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ApplyDeadTimeCorr)
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ApplyDeadTimeCorr)

//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
*/
void ApplyDeadTimeCorr::init()
{
void ApplyDeadTimeCorr::init()
{
declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("InputWorkspace", "",
Direction::Input), "The name of the input workspace containing measured counts");
Direction::Input), "The name of the input workspace containing measured counts");

declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>("DeadTimeTable", "",
Direction::Input), "Name of the Dead Time Table");
Direction::Input), "Name of the Dead Time Table");

declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("OutputWorkspace","",Direction::Output),
"The name of the output workspace containing corrected counts");
}
"The name of the output workspace containing corrected counts");
}

//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
//----------------------------------------------------------------------------------------------
/** Execute the algorithm.
*/
void ApplyDeadTimeCorr::exec()
{
void ApplyDeadTimeCorr::exec()
{
// Get pointers to the workspace and dead time table
API::MatrixWorkspace_sptr inputWs = getProperty("InputWorkspace");
API::ITableWorkspace_sptr deadTimeTable = getProperty("DeadTimeTable");

if (!(deadTimeTable->rowCount() > static_cast<int>(inputWs->getNumberHistograms() ) ) )
{
// Get number of good frames from Run object. This also serves as
// a test to see if valid input workspace has been provided

double numGoodFrames = 1.0;
const API::Run & run = inputWs->run();
if ( run.hasProperty("goodfrm") )
{
numGoodFrames = boost::lexical_cast<double>(run.getProperty("goodfrm")->value());

// Duplicate the input workspace. Only need to change Y values based on dead time corrections
IAlgorithm_sptr duplicate = createSubAlgorithm("CloneWorkspace");
duplicate->initialize();
duplicate->setProperty<Workspace_sptr>("InputWorkspace", boost::dynamic_pointer_cast<Workspace>(inputWs));
duplicate->execute();
Workspace_sptr temp = duplicate->getProperty("OutputWorkspace");
MatrixWorkspace_sptr outputWs = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);

// Presumed to be the same for all data
double timeBinWidth(inputWs->dataX(0)[1] - inputWs->dataX(0)[0]);

if (timeBinWidth != 0)
// Get number of good frames from Run object. This also serves as
// a test to see if valid input workspace has been provided

const API::Run & run = inputWs->run();
if ( run.hasProperty("goodfrm") )
{
try
{
// Apply Dead Time
for (int i=0; i<deadTimeTable->rowCount(); ++i)
{
API::TableRow deadTimeRow = deadTimeTable->getRow(i);
size_t index = static_cast<size_t>(inputWs->getIndexFromSpectrumNumber(static_cast<int>(deadTimeRow.Int(0) ) ) );
double numGoodFrames = 1.0;
numGoodFrames = boost::lexical_cast<double>(run.getProperty("goodfrm")->value());

// Duplicate the input workspace. Only need to change Y values based on dead time corrections
IAlgorithm_sptr duplicate = createSubAlgorithm("CloneWorkspace");
duplicate->initialize();
duplicate->setProperty<Workspace_sptr>("InputWorkspace", boost::dynamic_pointer_cast<Workspace>(inputWs));
duplicate->execute();
Workspace_sptr temp = duplicate->getProperty("OutputWorkspace");
MatrixWorkspace_sptr outputWs = boost::dynamic_pointer_cast<MatrixWorkspace>(temp);

// Presumed to be the same for all data
double timeBinWidth(inputWs->dataX(0)[1] - inputWs->dataX(0)[0]);

for(size_t j=0; j<inputWs->blocksize(); ++j)
{
double temp(1 - inputWs->dataY(index)[j] * (deadTimeRow.Double(1)/ (timeBinWidth * numGoodFrames) ) );
if (temp != 0)
if (timeBinWidth != 0)
{
try
{
outputWs->dataY(index)[j] = inputWs->dataY(index)[j] / temp;
// Apply Dead Time
for (int i=0; i<deadTimeTable->rowCount(); ++i)
{
API::TableRow deadTimeRow = deadTimeTable->getRow(i);
size_t index = static_cast<size_t>(inputWs->getIndexFromSpectrumNumber(static_cast<int>(deadTimeRow.Int(0) ) ) );

for(size_t j=0; j<inputWs->blocksize(); ++j)
{
double temp(1 - inputWs->dataY(index)[j] * (deadTimeRow.Double(1)/ (timeBinWidth * numGoodFrames) ) );
if (temp != 0)
{
outputWs->dataY(index)[j] = inputWs->dataY(index)[j] / temp;
}
else
{
g_log.error() << "1 - MeasuredCount * (Deadtime/TimeBin width is currently (" << temp << "). Can't divide by this amount." << std::endl;

throw std::invalid_argument("Can't divide by 0");
}
}
}

setProperty("OutputWorkspace", outputWs);
}
else
catch(std::runtime_error& ex)
{
g_log.error() << "1 - MeasuredCount * (Deadtime/TimeBin width is currently (" << temp << "). Can't divide by this amount." << std::endl;

throw std::invalid_argument("Can't divide by 0");
throw std::invalid_argument("Invalid argument for algorithm.");
}
}
}
else
{
g_log.error() << "The time bin width is currently (" << timeBinWidth << "). Can't divide by this amount." << std::endl;

setProperty("OutputWorkspace", outputWs);
}
catch(std::runtime_error& ex)
{
throw std::invalid_argument("Invalid argument for algorithm.");
}
throw std::invalid_argument("Can't divide by 0");
}
}
else
{
g_log.error() << "The time bin width is currently (" << timeBinWidth << "). Can't divide by this amount." << std::endl;

throw std::invalid_argument("Can't divide by 0");
g_log.error() << "To calculate Muon deadtime requires that goodfrm (number of good frames) "
<< "is stored in InputWorkspace Run object\n";
}
}
else
{
g_log.error() << "To calculate Muon deadtime requires that goodfrm (number of good frames) "
<< "is stored in InputWorkspace Run object\n";
}
}
else
{
g_log.error() << "Row count(" << deadTimeTable->rowCount() << ") of Dead time table is bigger than the Number of Histograms("
<< inputWs->getNumberHistograms() << ")." << std::endl;
g_log.error() << "Row count(" << deadTimeTable->rowCount() << ") of Dead time table is bigger than the Number of Histograms("
<< inputWs->getNumberHistograms() << ")." << std::endl;

throw std::invalid_argument("Row count was bigger than the Number of Histograms.");
throw std::invalid_argument("Row count was bigger than the Number of Histograms.");
}
}
}



} // namespace Mantid
} // namespace Algorithms
} // namespace Algorithms

0 comments on commit 16863c6

Please sign in to comment.