Skip to content

Commit

Permalink
Refs #9378. Modified event time correction for splitting.
Browse files Browse the repository at this point in the history
The correction formula for splitting is generalized to
T_pulse + toffactor * TOF + tofshift

The printdetail option is removed because the code is well tested.
  • Loading branch information
wdzhou committed May 30, 2014
1 parent 3f2c8ac commit a06ec5b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
Expand Up @@ -282,12 +282,13 @@ class DLLExport EventList : public Mantid::API::IEventList

void splitByTime(Kernel::TimeSplitterType & splitter, std::vector< EventList * > outputs) const;

void splitByFullTime(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs, double tofcorrection, bool docorrection) const;
void splitByFullTime(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs, bool docorrection,
double toffactor, double tofshift) const;

/// Split ...
std::string splitByFullTimeMatrixSplitter(const std::vector<int64_t>& vectimes, const std::vector<int>& vecgroups,
std::map<int, EventList*> vec_outputEventList,
double tofcorrection, bool docorrection, bool printdetail=false) const;
bool docorrection, double toffactor, double tofshift) const;

/// Split events by pulse time
void splitByPulseTime(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs) const;
Expand Down Expand Up @@ -387,15 +388,15 @@ class DLLExport EventList : public Mantid::API::IEventList
void splitByTimeHelper(Kernel::TimeSplitterType & splitter, std::vector< EventList * > outputs, typename std::vector<T> & events) const;
template< class T >
void splitByFullTimeHelper(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs, typename std::vector<T> & events,
double tofcorrection, bool docorrection) const;
bool docorrection, double toffactor, double tofshift) const;
/// Split events by pulse time
template< class T >
void splitByPulseTimeHelper(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs,
typename std::vector<T> & events) const;
template< class T >
std::string splitByFullTimeVectorSplitterHelper(const std::vector<int64_t>& vectimes, const std::vector<int>& vecgroups,
std::map<int, EventList * > outputs, typename std::vector<T> & events,
double tofcorrection, bool docorrection, bool printdetail=false) const;
std::map<int, EventList * > outputs, typename std::vector<T> & events,
bool docorrection,double toffactor, double tofshift) const;
template< class T>
static void multiplyHelper(std::vector<T> & events, const double value, const double error = 0.0);
template<class T>
Expand Down
54 changes: 25 additions & 29 deletions Code/Mantid/Framework/DataObjects/src/EventList.cpp
Expand Up @@ -3757,15 +3757,15 @@ namespace DataObjects
* @param outputs :: a vector of where the split events will end up. The # of entries in there should
* be big enough to accommodate the indices.
* @param events :: either this->events or this->weightedEvents.
* @param tofcorrection :: a correction for each TOF to multiply with.
* @param docorrection :: flag to determine whether or not to apply correction
* @param toffactor :: factor to correct TOF in formula toffactor*tof+tofshift
* @param tofshift :: amount to shift (in SECOND) to correct TOF in formula: toffactor*tof+tofshift
*/
template< class T >
void EventList::splitByFullTimeHelper(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs,
typename std::vector<T> & events, double tofcorrection, bool docorrection) const
typename std::vector<T> & events, bool docorrection, double toffactor, double tofshift) const
{
// 1. Prepare to Iterate through the splitter at the same time

Kernel::TimeSplitterType::iterator itspl = splitter.begin();
Kernel::TimeSplitterType::iterator itspl_end = splitter.end();
int64_t start, stop;
Expand All @@ -3789,7 +3789,7 @@ namespace DataObjects
{
int64_t fulltime;
if (docorrection)
fulltime = itev->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(itev->m_tof*1000*tofcorrection);
fulltime = itev->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(toffactor*itev->m_tof*1000+tofshift*1.0E9);
else
fulltime = itev->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(itev->m_tof*1000);
if (fulltime < start)
Expand All @@ -3810,7 +3810,7 @@ namespace DataObjects
{
int64_t fulltime;
if (docorrection)
fulltime = itev->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(itev->m_tof*1000*tofcorrection);
fulltime = itev->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(toffactor*itev->m_tof*1000+tofshift*1.0E9);
else
fulltime = itev->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(itev->m_tof*1000);
if (fulltime < stop)
Expand Down Expand Up @@ -3851,7 +3851,8 @@ namespace DataObjects
* @param tofcorrection: a correction for each TOF to multiply with.
* @param docorrection :: a boolean to indiciate whether it is need to do correction
*/
void EventList::splitByFullTime(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs, double tofcorrection, bool docorrection) const
void EventList::splitByFullTime(Kernel::TimeSplitterType & splitter, std::map<int, EventList * > outputs,
bool docorrection, double toffactor, double tofshift) const
{
if (eventType == WEIGHTED_NOTIME)
throw std::runtime_error("EventList::splitByTime() called on an EventList that no longer has time information.");
Expand Down Expand Up @@ -3884,10 +3885,10 @@ namespace DataObjects
switch (eventType)
{
case TOF:
splitByFullTimeHelper(splitter, outputs, this->events, tofcorrection, docorrection);
splitByFullTimeHelper(splitter, outputs, this->events, docorrection, toffactor, tofshift);
break;
case WEIGHTED:
splitByFullTimeHelper(splitter, outputs, this->weightedEvents, tofcorrection, docorrection);
splitByFullTimeHelper(splitter, outputs, this->weightedEvents, docorrection, toffactor, tofshift);
break;
case WEIGHTED_NOTIME:
break;
Expand All @@ -3906,29 +3907,30 @@ namespace DataObjects
* @param outputs :: a vector of where the split events will end up. The # of entries in there should
* be big enough to accommodate the indices.
* @param events :: either this->events or this->weightedEvents.
* @param tofcorrection :: a correction for each TOF to multiply with.
* @param docorrection :: flag to determine whether or not to apply correction
* @param printdetail :: flag to print out how the events are splitted.
* @param toffactor :: factor multiplied to TOF for correcting event time from detector to sample
* @param tofshift :: shift in SECOND to TOF for correcting event time from detector to sample
*/
template< class T >
std::string EventList::splitByFullTimeVectorSplitterHelper(const std::vector<int64_t>& vectimes,
const std::vector<int>& vecgroups,
std::map<int, EventList * > outputs,
typename std::vector<T> & events, double tofcorrection,
bool docorrection, bool printdetail) const
typename std::vector<T> & vecEvents, bool docorrection,
double toffactor, double tofshift) const
{
// Define variables for events
// size_t numevents = events.size();
typename std::vector<T>::iterator eviter;
std::stringstream msgss;

// Loop through events
for (eviter = events.begin(); eviter != events.end(); ++eviter)
for (eviter = vecEvents.begin(); eviter != vecEvents.end(); ++eviter)
{
// Obtain time of event
int64_t evabstimens;
if (docorrection)
evabstimens = eviter->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(eviter->m_tof*1000*tofcorrection);
evabstimens = eviter->m_pulsetime.totalNanoseconds() +
static_cast<int64_t>(toffactor * eviter->m_tof * 1000 + tofshift * 1.0E9);
else
evabstimens = eviter->m_pulsetime.totalNanoseconds() + static_cast<int64_t>(eviter->m_tof*1000);

Expand All @@ -3945,18 +3947,6 @@ namespace DataObjects
group = vecgroups[index-1];
}

if (printdetail)
{
if (group >= 0)
msgss << "[Event-12A-" << group << "] AbsTime = " << evabstimens << ", Pulse = " << eviter->m_pulsetime
<< ", TOF = " << eviter->m_tof
<< ", AbsLower = " << vectimes[index-1] << ", AbsUpper = " << vectimes[index] << "\n";
else
msgss << "[Event-12B] AbsTime = " << evabstimens << ", Pulse = " << eviter->m_pulsetime
<< ", TOF = " << eviter->m_tof
<< ", AbsLower = " << vectimes[index-1] << ", AbsUpper = " << vectimes[index] << "\n";
}

// Copy event to the proper group
EventList* myOutput = outputs[group];
if (!myOutput)
Expand All @@ -3978,10 +3968,16 @@ namespace DataObjects

//----------------------------------------------------------------------------------------------
/**
* @param vectimes :: vector of splitting times
* @param vecgroups :: vector of index group for splitters
* @param vec_outputEvetnList :: vector of groups of splitted events
* @param docorrection :: flag to do TOF correction from detector to sample
* @param toffactor :: factor multiplied to TOF for correction
* @param tofshift :: shift to TOF in unit of SECOND for correction
*/
std::string EventList::splitByFullTimeMatrixSplitter(const std::vector<int64_t>& vectimes, const std::vector<int>& vecgroups,
std::map<int, EventList*> vec_outputEventList,
double tofcorrection, bool docorrection, bool printdetail) const
bool docorrection, double toffactor, double tofshift) const
{
// Check validity
if (eventType == WEIGHTED_NOTIME)
Expand Down Expand Up @@ -4020,11 +4016,11 @@ namespace DataObjects
{
case TOF:
debugmessage = splitByFullTimeVectorSplitterHelper(vectimes, vecgroups, vec_outputEventList, this->events,
tofcorrection, docorrection, printdetail);
docorrection, toffactor, tofshift);
break;
case WEIGHTED:
debugmessage = splitByFullTimeVectorSplitterHelper(vectimes, vecgroups, vec_outputEventList, this->weightedEvents,
tofcorrection, docorrection);
docorrection, toffactor, tofshift);
break;
case WEIGHTED_NOTIME:
debugmessage = "TOF type is weighted no time. Impossible to split. ";
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataObjects/test/EventListTest.h
Expand Up @@ -1479,7 +1479,7 @@ class EventListTest : public CxxTest::TestSuite
}

// Do the splitting
el.splitByFullTime(split, outputs, 1.0, false);
el.splitByFullTime(split, outputs, false, 1.0, 0.0);

//No events in the first ouput 0-99
TS_ASSERT_EQUALS( outputs[0]->getNumberEvents(), 0);
Expand Down Expand Up @@ -1553,7 +1553,7 @@ class EventListTest : public CxxTest::TestSuite
}

// Do the splitting
el.splitByFullTimeMatrixSplitter(vec_splitTimes, vec_splitGroup, outputs, 1.0, false);
el.splitByFullTimeMatrixSplitter(vec_splitTimes, vec_splitGroup, outputs, false, 1.0, 0.0);


//No events in the first ouput 0-99
Expand Down

0 comments on commit a06ec5b

Please sign in to comment.