//---------------------------------------------------------------------------------------------- /// LogarithmMD::Run the algorithm with a MDHistoWorkspace void LogarithmMD::execHisto(Mantid::DataObjects::MDHistoWorkspace_sptr out) { bool natural = getProperty("Natural"); double filler = getProperty("Filler"); if (natural) out->log(filler); else out->log10(filler); }
/** Compare the dimensions etc. of two MDWorkspaces */ void CompareMDWorkspaces::compareMDHistoWorkspaces( Mantid::DataObjects::MDHistoWorkspace_sptr ws1, Mantid::DataObjects::MDHistoWorkspace_sptr ws2) { compare(ws1->getNumDims(), ws2->getNumDims(), "Workspaces have a different number of dimensions"); compare(ws1->getNPoints(), ws2->getNPoints(), "Workspaces have a different number of points"); for (size_t i = 0; i < ws1->getNPoints(); i++) { double diff = fabs(ws1->getSignalAt(i) - ws2->getSignalAt(i)); if (diff > m_tolerance) throw CompareFailsException( "MDHistoWorkspaces have a different signal at index " + Strings::toString(i) + " " + versus(ws1->getSignalAt(i), ws2->getSignalAt(i))); double diffErr = fabs(ws1->getErrorAt(i) - ws2->getErrorAt(i)); if (diffErr > m_tolerance) throw CompareFailsException( "MDHistoWorkspaces have a different error at index " + Strings::toString(i) + " " + versus(ws1->getErrorAt(i), ws2->getErrorAt(i))); } }
/** Save a MDHistoWorkspace to a .nxs file * * @param ws :: MDHistoWorkspace to save */ void SaveMD::doSaveHisto(Mantid::DataObjects::MDHistoWorkspace_sptr ws) { std::string filename = getPropertyValue("Filename"); // Erase the file if it exists Poco::File oldFile(filename); if (oldFile.exists()) oldFile.remove(); // Create a new file in HDF5 mode. ::NeXus::File *file; file = new ::NeXus::File(filename, NXACC_CREATE5); // The base entry. Named so as to distinguish from other workspace types. file->makeGroup("MDHistoWorkspace", "NXentry", true); // Write out the coordinate system file->writeData("coordinate_system", static_cast<uint32_t>(ws->getSpecialCoordinateSystem())); // Write out the set display normalization file->writeData("visual_normalization", static_cast<uint32_t>(ws->displayNormalization())); // Save the algorithm history under "process" ws->getHistory().saveNexus(file); // Save all the ExperimentInfos for (uint16_t i = 0; i < ws->getNumExperimentInfo(); i++) { ExperimentInfo_sptr ei = ws->getExperimentInfo(i); std::string groupName = "experiment" + Strings::toString(i); if (ei) { // Can't overwrite entries. Just add the new ones file->makeGroup(groupName, "NXgroup", true); file->putAttr("version", 1); ei->saveExperimentInfoNexus(file); file->closeGroup(); } } // Write out some general information like # of dimensions file->writeData("dimensions", int32_t(ws->getNumDims())); // Save each dimension, as their XML representation for (size_t d = 0; d < ws->getNumDims(); d++) { std::ostringstream mess; mess << "dimension" << d; file->putAttr(mess.str(), ws->getDimension(d)->toXMLString()); } // Write out the affine matrices MDBoxFlatTree::saveAffineTransformMatricies( file, boost::dynamic_pointer_cast<const IMDWorkspace>(ws)); // Check that the typedef has not been changed. The NeXus types would need // changing if it does! assert(sizeof(signal_t) == sizeof(double)); // Number of data points int nPoints = static_cast<int>(ws->getNPoints()); file->makeData("signal", ::NeXus::FLOAT64, nPoints, true); file->putData(ws->getSignalArray()); file->closeData(); file->makeData("errors_squared", ::NeXus::FLOAT64, nPoints, true); file->putData(ws->getErrorSquaredArray()); file->closeData(); file->makeData("num_events", ::NeXus::FLOAT64, nPoints, true); file->putData(ws->getNumEventsArray()); file->closeData(); file->makeData("mask", ::NeXus::INT8, nPoints, true); file->putData(ws->getMaskArray()); file->closeData(); // TODO: Links to original workspace??? file->closeGroup(); file->close(); }
//---------------------------------------------------------------------------------------------- /// Run the algorithm with a MDHisotWorkspace as output, scalar and operand void PlusMD::execHistoScalar( Mantid::DataObjects::MDHistoWorkspace_sptr out, Mantid::DataObjects::WorkspaceSingleValue_const_sptr scalar) { out->add(scalar->dataY(0)[0], scalar->dataE(0)[0]); }
//---------------------------------------------------------------------------------------------- /// Run the algorithm with a MDHisotWorkspace as output and operand void PlusMD::execHistoHisto( Mantid::DataObjects::MDHistoWorkspace_sptr out, Mantid::DataObjects::MDHistoWorkspace_const_sptr operand) { out->add(*operand); }
//---------------------------------------------------------------------------------------------- /// PowerMD::Run the algorithm with a MDHistoWorkspace void PowerMD::execHisto(Mantid::DataObjects::MDHistoWorkspace_sptr out) { double exponent = getProperty("Exponent"); out->power(exponent); }
//---------------------------------------------------------------------------------------------- /// Run the algorithm with a MDHisotWorkspace as output and operand void MinusMD::execHistoHisto(Mantid::DataObjects::MDHistoWorkspace_sptr out, Mantid::DataObjects::MDHistoWorkspace_const_sptr operand) { out->subtract(*operand); }
//---------------------------------------------------------------------------------------------- /// Run the algorithm with a MDHisotWorkspace as output and a scalar on the RHS void EqualToMD::execHistoScalar( Mantid::DataObjects::MDHistoWorkspace_sptr out, Mantid::DataObjects::WorkspaceSingleValue_const_sptr scalar) { double tolerance = getProperty("Tolerance"); out->equalTo(scalar->y(0)[0], tolerance); }