Skip to content

Commit

Permalink
Refs #5021 performance improvements in ConvertToDiffractionMDWorkspace
Browse files Browse the repository at this point in the history
also fix for TestViewer
  • Loading branch information
Janik Zikovsky committed Mar 28, 2012
1 parent f3c045c commit 459e9f1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
7 changes: 5 additions & 2 deletions Code/Mantid/Framework/DataObjects/src/EventList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ namespace DataObjects
this->copyInfoFrom( *inSpec );
// We need weights but have no way to set the time. So use weighted, no time
this->switchTo(WEIGHTED_NOTIME);
if (GenerateZeros)
this->weightedEventsNoTime.reserve(Y.size());

for (size_t i=0; i<X.size()-1; i++)
{
Expand Down Expand Up @@ -205,7 +207,8 @@ namespace DataObjects
{
double tof = X[i] + tofStep * (0.5 + double(j));
// Create and add the event
this->addEventQuickly( WeightedEventNoTime(tof, weight, errorSquared) );
// TODO: try emplace_back() here.
weightedEventsNoTime.push_back( WeightedEventNoTime(tof, weight, errorSquared) );
}
}
else
Expand All @@ -217,7 +220,7 @@ namespace DataObjects
double errorSquared = E[i];
errorSquared *= errorSquared;
// Create and add the event
this->addEventQuickly( WeightedEventNoTime(tof, weight, errorSquared) );
weightedEventsNoTime.push_back( WeightedEventNoTime(tof, weight, errorSquared) );
}
} // error is nont NAN or infinite
} // weight is non-zero, not NAN, and non-infinite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ namespace MDEvents
/// Matrix. Multiply this by the lab frame Qx, Qy, Qz to get the desired Q or HKL.
Kernel::Matrix<double> mat;

/// Minimum extents of the workspace. Cached for speed
coord_t * m_extentsMin;
/// Maximum extents of the workspace. Cached for speed
coord_t * m_extentsMax;


};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,12 @@ namespace MDEvents
void ConvertToDiffractionMDWorkspace::convertEventList(int workspaceIndex, EventList & el)
{
size_t numEvents = el.getNumberEvents();
IMDBox<MDLeanEvent<3>,3> * box = ws->getBox();

// Get the position of the detector there.
const std::set<detid_t>& detectors = el.getDetectorIDs();
if (detectors.size() > 0)
{
// The 3D MDEvents that will be added into the MDEventWorkspce
std::vector<MDE> out_events;
out_events.reserve( el.getNumberEvents() );

// Get the detector (might be a detectorGroup for multiple detectors)
// or might return an exception if the detector is not in the instrument definition
IDetector_const_sptr det;
Expand Down Expand Up @@ -290,18 +287,23 @@ namespace MDEvents
// Q vector = K_final - K_initial = wavenumber * (output_direction - input_direction)
coord_t center[3] = {Q_dir_x * wavenumber, Q_dir_y * wavenumber, Q_dir_z * wavenumber};

// Check that the event is within bounds
if (center[0] < m_extentsMin[0] || center[0] >= m_extentsMax[0]) continue;
if (center[1] < m_extentsMin[1] || center[1] >= m_extentsMax[1]) continue;
if (center[2] < m_extentsMin[2] || center[2] >= m_extentsMax[2]) continue;

if (LorentzCorrection)
{
//double lambda = 1.0/wavenumber;
// (sin(theta))^2 / wavelength^4
float correct = float( sin_theta_squared * wavenumber*wavenumber*wavenumber*wavenumber );
// Push the MDLeanEvent but correct the weight.
out_events.push_back( MDE(float(it->weight()*correct), float(it->errorSquared()*correct*correct), center) );
box->addEvent( MDE(float(it->weight()*correct), float(it->errorSquared()*correct*correct), center) );
}
else
{
// Push the MDLeanEvent with the same weight
out_events.push_back( MDE(float(it->weight()), float(it->errorSquared()), center) );
box->addEvent( MDE(float(it->weight()), float(it->errorSquared()), center) );
}
}

Expand All @@ -315,9 +317,6 @@ namespace MDEvents
// For Linux with tcmalloc, make sure memory goes back, if you've cleared 200 Megs
MemoryManager::Instance().releaseFreeMemoryIfAccumulated(memoryCleared, (size_t)2e8);
}

// Add them to the MDEW
ws->addEvents(out_events);
}
prog->reportIncrement(numEvents, "Adding Events");
}
Expand Down Expand Up @@ -463,6 +462,15 @@ namespace MDEvents
if (!bc)
throw std::runtime_error("Output MDEventWorkspace does not have a BoxController!");

// Cache the extents for speed.
m_extentsMin = new coord_t[3];
m_extentsMax = new coord_t[3];
for (size_t d=0; d<3; d++)
{
m_extentsMin[d] = ws->getDimension(d)->getMinimum();
m_extentsMax[d] = ws->getDimension(d)->getMaximum();
}

// Copy ExperimentInfo (instrument, run, sample) to the output WS
ExperimentInfo_sptr ei(m_inWS->cloneExperimentInfo());
uint16_t runIndex = ws->addExperimentInfo(ei);
Expand Down Expand Up @@ -583,6 +591,10 @@ namespace MDEvents

// Save the output
setProperty("OutputWorkspace", boost::dynamic_pointer_cast<IMDEventWorkspace>(ws));

// Clean up
delete [] m_extentsMin;
delete [] m_extentsMax;
}


Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/src/IMDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace MDEvents
bool badEvent = false;
for (size_t d=0; d<nd; d++)
{
double x = it->getCenter(d);
coord_t x = it->getCenter(d);
if ((x < this->extents[d].min) || (x >= this->extents[d].max))
{
badEvent = true;
Expand Down
2 changes: 1 addition & 1 deletion Code/Tools/TestViewer/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def start():
if len(sys.argv) > 1: bin_folder = sys.argv[1]

source_folder = ""
if len(sys.argv) > 2: source_folder = sys.argv[1]
if len(sys.argv) > 2: source_folder = sys.argv[2]

if bin_folder == "--help":
print """TestViewer.py [BINFOLDER] [SOURCEFOLDER]
Expand Down

0 comments on commit 459e9f1

Please sign in to comment.