Skip to content

Commit

Permalink
Fixed the indentation of the ApplyDeadTimeCorr code.
Browse files Browse the repository at this point in the history
Refs #7229
  • Loading branch information
arturbekasov committed Oct 9, 2013
1 parent ce6ea4e commit 5950a63
Showing 1 changed file with 71 additions and 73 deletions.
144 changes: 71 additions & 73 deletions Code/Mantid/Framework/Algorithms/src/ApplyDeadTimeCorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,104 +46,102 @@ DECLARE_ALGORITHM(ApplyDeadTimeCorr)
*/
void ApplyDeadTimeCorr::init()
{
this->setWikiSummary("Apply deadtime correction to each spectra of a workspace.");
this->setWikiSummary("Apply deadtime correction to each spectra of a workspace.");

declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("InputWorkspace", "",
Direction::Input), "The name of the input workspace containing measured counts");
declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("InputWorkspace", "",
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");
declareProperty(new API::WorkspaceProperty<API::MatrixWorkspace>("OutputWorkspace","",Direction::Output),
"The name of the output workspace containing corrected counts");
declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>("DeadTimeTable", "",
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");
}

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

if (!(deadTimeTable->rowCount() > 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
if (!(deadTimeTable->rowCount() > 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

const API::Run & run = inputWs->run();
if ( run.hasProperty("goodfrm") )
const API::Run & run = inputWs->run();
if ( run.hasProperty("goodfrm") )
{
double 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 = createChildAlgorithm("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)
{
try
{
double 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 = createChildAlgorithm("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);
// Apply Dead Time
for (size_t 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) ) ) );

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

if (timeBinWidth != 0)
{
try
{
// Apply Dead Time
for (size_t 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);
}
catch(std::runtime_error&)
{
throw std::invalid_argument("Invalid argument for algorithm.");
}
}
else
for(size_t j=0; j<inputWs->blocksize(); ++j)
{
g_log.error() << "The time bin width is currently (" << timeBinWidth << "). Can't divide by this amount." << std::endl;
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&)
{
g_log.error() << "To calculate Muon deadtime requires that goodfrm (number of good frames) "
<< "is stored in InputWorkspace Run object\n";
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;

throw std::invalid_argument("Can't divide by 0");
}
}
else
{
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.");
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;

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



} // namespace Mantid
} // namespace Algorithms

0 comments on commit 5950a63

Please sign in to comment.