本文整理汇总了C++中kernel::Property类的典型用法代码示例。如果您正苦于以下问题:C++ Property类的具体用法?C++ Property怎么用?C++ Property使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Property类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: isMultiperiod
/**
Determine in the WorkspaceGroup is multiperiod.
* @return True if the WorkspaceGroup instance is multiperiod.
*/
bool WorkspaceGroup::isMultiperiod() const {
std::lock_guard<std::recursive_mutex> _lock(m_mutex);
if (m_workspaces.empty()) {
g_log.debug("Not a multiperiod-group with < 1 nested workspace.");
return false;
}
// Loop through all inner workspaces, checking each one in turn.
for (const auto &workspace : m_workspaces) {
if (MatrixWorkspace_sptr ws =
boost::dynamic_pointer_cast<MatrixWorkspace>(workspace)) {
try {
Kernel::Property *nPeriodsProp = ws->run().getLogData("nperiods");
int num = -1;
Kernel::Strings::convert(nPeriodsProp->value(), num);
if (num < 1) {
g_log.debug("Not a multiperiod-group with nperiods log < 1.");
return false;
}
} catch (Kernel::Exception::NotFoundError &) {
g_log.debug("Not a multiperiod-group without nperiods log on all "
"nested workspaces.");
return false;
}
} else {
g_log.debug("Not a multiperiod-group unless all inner workspaces are "
"Matrix Workspaces.");
return false;
}
}
return true;
}
开发者ID:dezed,项目名称:mantid,代码行数:35,代码来源:WorkspaceGroup.cpp
示例2: cacheInputs
/**
* Set up starting values for cached variables
*/
void MDNormDirectSC::cacheInputs() {
m_inputWS = getProperty("InputWorkspace");
bool skipCheck = getProperty("SkipSafetyCheck");
if (!skipCheck && (inputEnergyMode() != "Direct")) {
throw std::invalid_argument("Invalid energy transfer mode. Algorithm only "
"supports direct geometry spectrometers.");
}
// Min/max dimension values
const auto hdim(m_inputWS->getDimension(0)), kdim(m_inputWS->getDimension(1)),
ldim(m_inputWS->getDimension(2)), edim(m_inputWS->getDimension(3));
m_hmin = hdim->getMinimum();
m_kmin = kdim->getMinimum();
m_lmin = ldim->getMinimum();
m_dEmin = edim->getMinimum();
m_hmax = hdim->getMaximum();
m_kmax = kdim->getMaximum();
m_lmax = ldim->getMaximum();
m_dEmax = edim->getMaximum();
const auto &exptInfoZero = *(m_inputWS->getExperimentInfo(0));
auto source = exptInfoZero.getInstrument()->getSource();
auto sample = exptInfoZero.getInstrument()->getSample();
if (source == nullptr || sample == nullptr) {
throw Kernel::Exception::InstrumentDefinitionError(
"Instrument not sufficiently defined: failed to get source and/or "
"sample");
}
m_samplePos = sample->getPos();
m_beamDir = m_samplePos - source->getPos();
m_beamDir.normalize();
double originaldEmin = exptInfoZero.run().getBinBoundaries().front();
double originaldEmax = exptInfoZero.run().getBinBoundaries().back();
if (exptInfoZero.run().hasProperty("Ei")) {
Kernel::Property *eiprop = exptInfoZero.run().getProperty("Ei");
m_Ei = boost::lexical_cast<double>(eiprop->value());
if (m_Ei <= 0) {
throw std::invalid_argument("Ei stored in the workspace is not positive");
}
} else {
throw std::invalid_argument("Could not find Ei value in the workspace.");
}
double eps = 1e-7;
if (m_Ei - originaldEmin < eps) {
originaldEmin = m_Ei - eps;
}
if (m_Ei - originaldEmax < eps) {
originaldEmax = m_Ei - 1e-7;
}
if (originaldEmin == originaldEmax) {
throw std::runtime_error("The limits of the original workspace used in "
"ConvertToMD are incorrect");
}
const double energyToK = 8.0 * M_PI * M_PI * PhysicalConstants::NeutronMass *
PhysicalConstants::meV * 1e-20 /
(PhysicalConstants::h * PhysicalConstants::h);
m_ki = std::sqrt(energyToK * m_Ei);
m_kfmin = std::sqrt(energyToK * (m_Ei - originaldEmin));
m_kfmax = std::sqrt(energyToK * (m_Ei - originaldEmax));
}
开发者ID:mducle,项目名称:mantid,代码行数:63,代码来源:MDNormDirectSC.cpp
示例3: mergeKeepExisting
/**
* Copy logs from the input workspace to the output workspace
* and don't replace any mathcing logs in the output workspace.
*/
void CopyLogs::mergeKeepExisting(
const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
Kernel::Property *prop = *iter;
// add the log only if it doesn't already exist
if (!outputRun.hasProperty(prop->name())) {
outputRun.addLogData(prop->clone());
}
}
}
开发者ID:spaceyatom,项目名称:mantid,代码行数:14,代码来源:CopyLogs.cpp
示例4: getPropertyFromRun
T ConvertEmptyToTof::getPropertyFromRun(API::MatrixWorkspace_const_sptr inputWS,
const std::string &propertyName) {
if (inputWS->run().hasProperty(propertyName)) {
Kernel::Property *prop = inputWS->run().getProperty(propertyName);
return boost::lexical_cast<T>(prop->value());
} else {
std::string mesg =
"No '" + propertyName + "' property found in the input workspace....";
throw std::runtime_error(mesg);
}
}
开发者ID:liyulun,项目名称:mantid,代码行数:11,代码来源:ConvertEmptyToTof.cpp
示例5: mergeReplaceExisting
/**
* Copy logs from the input workspace to the output workspace
* and replace any matching logs with the ones from the input workspace.
*/
void CopyLogs::mergeReplaceExisting(
const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
Kernel::Property *prop = *iter;
// if the log exists, remove and replace it
if (outputRun.hasProperty(prop->name())) {
outputRun.removeLogData(prop->name());
}
outputRun.addLogData(prop->clone());
}
}
开发者ID:spaceyatom,项目名称:mantid,代码行数:15,代码来源:CopyLogs.cpp
示例6: checkValidity
std::string AlgorithmHasProperty::checkValidity(
const boost::shared_ptr<IAlgorithm> &value) const {
std::string message;
if (value->existsProperty(m_propName)) {
Kernel::Property *p = value->getProperty(m_propName);
if (!p->isValid().empty()) {
message = "Algorithm object contains the required property \"" +
m_propName + "\" but it has an invalid value: " + p->value();
}
} else {
message = "Algorithm object does not have the required property \"" +
m_propName + "\"";
}
return message;
}
开发者ID:mducle,项目名称:mantid,代码行数:16,代码来源:AlgorithmHasProperty.cpp
示例7: invalid_argument
TimeAtSampleStrategy *FilterEvents::setupDirectTOFCorrection() const {
// Get incident energy Ei
double ei = 0.;
if (m_eventWS->run().hasProperty("Ei")) {
Kernel::Property *eiprop = m_eventWS->run().getProperty("Ei");
ei = boost::lexical_cast<double>(eiprop->value());
g_log.debug() << "Using stored Ei value " << ei << "\n";
} else {
ei = getProperty("IncidentEnergy");
if (isEmpty(ei))
throw std::invalid_argument(
"No Ei value has been set or stored within the run information.");
g_log.debug() << "Using user-input Ei value " << ei << "\n";
}
return new TimeAtSampleStrategyDirect(m_eventWS, ei);
}
开发者ID:mcvine,项目名称:mantid,代码行数:18,代码来源:FilterEvents.cpp
示例8: searchandreplaceSpecialChars
/** This method creates an XML element named "Run"
* @param sasRun :: string for run element in the xml
*/
void SaveCanSAS1D::createSASRunElement(std::string& sasRun)
{
//initialise the run number to an empty string, this may or may not be changed later
std::string run;
if( m_workspace->run().hasProperty("run_number") )
{
Kernel::Property *logP = m_workspace->run().getLogData("run_number");
run = logP->value();
}
else
{
g_log.debug() << "Didn't find RunNumber log in workspace. Writing <Run></Run> to the CANSAS file\n";
}
searchandreplaceSpecialChars(run);
sasRun="\n\t\t<Run>";
sasRun+=run;
sasRun+="</Run>";
}
开发者ID:AlistairMills,项目名称:mantid,代码行数:23,代码来源:SaveCanSAS1D.cpp
示例9: writeLogValue
/** Write value from a RunInfo property (i.e., log) to a stream
*/
void writeLogValue(std::ostream &os, const Run &runinfo,
const std::string &name,
const std::string &defValue = "UNKNOWN") {
// Return without property exists
if (!runinfo.hasProperty(name)) {
os << defValue;
return;
}
// Get handler of property
Kernel::Property *prop = runinfo.getProperty(name);
// Return without a valid pointer to property
if (prop == NULL) {
os << defValue;
return;
}
// Get value
Kernel::TimeSeriesProperty<double> *log =
dynamic_cast<Kernel::TimeSeriesProperty<double> *>(prop);
if (log) {
// Time series to get mean
os << log->getStatistics().mean;
} else {
// None time series
os << prop->value();
}
// Unit
std::string units = prop->units();
if (!units.empty())
os << " " << units;
return;
}
开发者ID:nimgould,项目名称:mantid,代码行数:38,代码来源:SaveGSS.cpp
示例10: exec
/** Execute the algorithm.
*/
void ConvertToDiffractionMDWorkspace::exec() {
Timer tim, timtotal;
CPUTimer cputim, cputimtotal;
// ---------------------- Extract properties
// --------------------------------------
ClearInputWorkspace = getProperty("ClearInputWorkspace");
Append = getProperty("Append");
std::string OutputDimensions = getPropertyValue("OutputDimensions");
LorentzCorrection = getProperty("LorentzCorrection");
OneEventPerBin = getProperty("OneEventPerBin");
// -------- Input workspace -> convert to Event
// ------------------------------------
m_inWS = getProperty("InputWorkspace");
Workspace2D_sptr m_InWS2D = boost::dynamic_pointer_cast<Workspace2D>(m_inWS);
if (LorentzCorrection) {
API::Run &run = m_inWS->mutableRun();
if (run.hasProperty("LorentzCorrection")) {
Kernel::Property *prop = run.getProperty("LorentzCorrection");
bool lorentzDone = boost::lexical_cast<bool, std::string>(prop->value());
if (lorentzDone) {
LorentzCorrection = false;
g_log.warning() << "Lorentz Correction was already done for this "
"workspace. LorentzCorrection was changed to false."
<< std::endl;
}
}
}
m_inEventWS = boost::dynamic_pointer_cast<EventWorkspace>(m_inWS);
// check the input units
if (m_inWS->getAxis(0)->unit()->unitID() != "TOF")
throw std::invalid_argument(
"Input event workspace's X axis must be in TOF units.");
// Try to get the output workspace
IMDEventWorkspace_sptr i_out = getProperty("OutputWorkspace");
ws = boost::dynamic_pointer_cast<
DataObjects::MDEventWorkspace<DataObjects::MDLeanEvent<3>, 3>>(i_out);
// Initalize the matrix to 3x3 identity
mat = Kernel::Matrix<double>(3, 3, true);
// ----------------- Handle the type of output
// -------------------------------------
std::string dimensionNames[3] = {"Q_lab_x", "Q_lab_y", "Q_lab_z"};
Mantid::Kernel::SpecialCoordinateSystem coordinateSystem =
Mantid::Kernel::QLab;
// Setup the MDFrame
auto frameFactory = makeMDFrameFactoryChain();
Mantid::Geometry::MDFrame_uptr frame;
if (OutputDimensions == "Q (sample frame)") {
// Set the matrix based on goniometer angles
mat = m_inWS->mutableRun().getGoniometerMatrix();
// But we need to invert it, since we want to get the Q in the sample frame.
mat.Invert();
// Names
dimensionNames[0] = "Q_sample_x";
dimensionNames[1] = "Q_sample_y";
dimensionNames[2] = "Q_sample_z";
coordinateSystem = Mantid::Kernel::QSample;
// Frame
MDFrameArgument frameArgQSample(QSample::QSampleName, "");
frame = frameFactory->create(frameArgQSample);
} else if (OutputDimensions == "HKL") {
// Set the matrix based on UB etc.
Kernel::Matrix<double> ub =
m_inWS->mutableSample().getOrientedLattice().getUB();
Kernel::Matrix<double> gon = m_inWS->mutableRun().getGoniometerMatrix();
// As per Busing and Levy 1967, q_lab_frame = 2pi * Goniometer * UB * HKL
// Therefore, HKL = (2*pi * Goniometer * UB)^-1 * q_lab_frame
mat = gon * ub;
mat.Invert();
// Divide by 2 PI to account for our new convention, |Q| = 2pi / wl
// (December 2011, JZ)
mat /= (2 * M_PI);
dimensionNames[0] = "H";
dimensionNames[1] = "K";
dimensionNames[2] = "L";
coordinateSystem = Mantid::Kernel::HKL;
MDFrameArgument frameArgQLab(HKL::HKLName, Units::Symbol::RLU.ascii());
frame = frameFactory->create(frameArgQLab);
} else {
MDFrameArgument frameArgQLab(QLab::QLabName, "");
frame = frameFactory->create(frameArgQLab);
}
// Q in the lab frame is the default, so nothing special to do.
if (ws && Append) {
// Check that existing workspace dimensions make sense with the desired one
// (using the name)
if (ws->getDimension(0)->getName() != dimensionNames[0])
//.........这里部分代码省略.........
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:101,代码来源:ConvertToDiffractionMDWorkspace.cpp
示例11: writeHeaders
/** Write the header information, which is independent of bank, from the given
* workspace
* @param format :: The string containing the header formatting
* @param os :: The stream to use to write the information
* @param primaryflightpath :: Value for the moderator to sample distance
*/
void SaveGSS::writeHeaders(const std::string &format, std::stringstream &os,
double primaryflightpath) const {
const Run &runinfo = inputWS->run();
// Run number
if (format.compare(SLOG) == 0) {
os << "Sample Run: ";
writeLogValue(os, runinfo, "run_number");
os << " Vanadium Run: ";
writeLogValue(os, runinfo, "van_number");
os << " Wavelength: ";
writeLogValue(os, runinfo, "LambdaRequest");
os << "\n";
}
if (this->getProperty("ExtendedHeader")) {
// the instrument parameter file
if (runinfo.hasProperty("iparm_file")) {
Kernel::Property *prop = runinfo.getProperty("iparm_file");
if (prop != NULL && (!prop->value().empty())) {
std::stringstream line;
line << "#Instrument parameter file: " << prop->value();
os << std::setw(80) << std::left << line.str() << "\n";
}
}
// write out the gsas monitor counts
os << "Monitor: ";
if (runinfo.hasProperty("gsas_monitor")) {
writeLogValue(os, runinfo, "gsas_monitor");
} else {
writeLogValue(os, runinfo, "gd_prtn_chrg", "1");
}
os << "\n";
}
if (format.compare(SLOG) == 0) {
os << "# "; // make the next line a comment
}
os << inputWS->getTitle() << "\n";
os << "# " << inputWS->getNumberHistograms() << " Histograms\n";
os << "# File generated by Mantid:\n";
os << "# Instrument: " << inputWS->getInstrument()->getName() << "\n";
os << "# From workspace named : " << inputWS->getName() << "\n";
if (getProperty("MultiplyByBinWidth"))
os << "# with Y multiplied by the bin widths.\n";
os << "# Primary flight path " << primaryflightpath << "m \n";
if (format.compare(SLOG) == 0) {
os << "# Sample Temperature: ";
writeLogValue(os, runinfo, "SampleTemp");
os << " Freq: ";
writeLogValue(os, runinfo, "SpeedRequest1");
os << " Guide: ";
writeLogValue(os, runinfo, "guide");
os << "\n";
// print whether it is normalized by monitor or pcharge
bool norm_by_current = false;
bool norm_by_monitor = false;
const Mantid::API::AlgorithmHistories &algohist =
inputWS->getHistory().getAlgorithmHistories();
for (Mantid::API::AlgorithmHistories::const_iterator it = algohist.begin();
it != algohist.end(); ++it) {
if ((*it)->name().compare("NormaliseByCurrent") == 0)
norm_by_current = true;
if ((*it)->name().compare("NormaliseToMonitor") == 0)
norm_by_monitor = true;
}
os << "#";
if (norm_by_current)
os << " Normalised to pCharge";
if (norm_by_monitor)
os << " Normalised to monitor";
os << "\n";
}
return;
}
开发者ID:nimgould,项目名称:mantid,代码行数:84,代码来源:SaveGSS.cpp
示例12: getInfoList
//.........这里部分代码省略.........
azi = det->getPhi();
}
SVUtils::PushNameValue( "L2", 8, 4, l2, list );
SVUtils::PushNameValue( "TwoTheta", 8, 2, two_theta*180./M_PI, list );
SVUtils::PushNameValue( "Azimuthal", 8, 2, azi*180./M_PI, list );
/* For now, only support diffractometers and monitors. */
/* We need a portable way to determine emode and */
/* and efixed that will work for any matrix workspace! */
int emode = 0;
double efixed = 0.0;
double delta = 0.0;
// First try to get emode & efixed from the user
if ( m_emodeHandler != NULL )
{
efixed = m_emodeHandler->getEFixed();
if ( efixed != 0 )
{
emode = m_emodeHandler->getEMode();
if ( emode == 0 )
{
g_log.information("EMode invalid, spectrometer needed if emode != 0");
g_log.information("Assuming Direct Geometry Spectrometer....");
emode = 1;
}
}
}
// Did NOT get emode & efixed from user, try getting direct geometry information from the run object
if ( efixed == 0 )
{
const API::Run & run = m_matWs->run();
if ( run.hasProperty("Ei") )
{
Kernel::Property* prop = run.getProperty("Ei");
efixed = boost::lexical_cast<double,std::string>(prop->value());
emode = 1; // only correct if direct geometry
}
else if ( run.hasProperty("EnergyRequested") )
{
Kernel::Property* prop = run.getProperty("EnergyRequested");
efixed = boost::lexical_cast<double,std::string>(prop->value());
emode = 1;
}
else if ( run.hasProperty("EnergyEstimate") )
{
Kernel::Property* prop = run.getProperty("EnergyEstimate");
efixed = boost::lexical_cast<double,std::string>(prop->value());
emode = 1;
}
}
// Finally, try getting indirect geometry information from the detector object
if ( efixed == 0 )
{
if ( !(det->isMonitor() && det->hasParameter("Efixed")))
{
try
{
const ParameterMap& pmap = m_matWs->constInstrumentParameters();
Parameter_sptr par = pmap.getRecursive(det.get(),"Efixed");
if (par)
{
efixed = par->value<double>();
emode = 2;
开发者ID:spaceyatom,项目名称:mantid,代码行数:67,代码来源:MatrixWSDataSource.cpp
示例13: execEvent
void ModeratorTzero::execEvent(const std::string &emode) {
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS =
getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS =
boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
const size_t numHists = static_cast<size_t>(inputWS->getNumberHistograms());
Mantid::API::MatrixWorkspace_sptr matrixOutputWS =
getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS) {
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
} else {
// Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
WorkspaceFactory::Instance().create("EventWorkspace", numHists, 2, 1));
// Copy geometry over.
WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
// You need to copy over the data as well.
outputWS->copyDataFrom((*inputWS));
// Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
setProperty("OutputWorkspace", matrixOutputWS);
}
// Get pointers to sample and source
IComponent_const_sptr source = m_instrument->getSource();
IComponent_const_sptr sample = m_instrument->getSample();
double Lss = source->getDistance(*sample); // distance from source to sample
// calculate tof shift once for all neutrons if emode==Direct
double t0_direct(-1);
if (emode == "Direct") {
Kernel::Property *eiprop = inputWS->run().getProperty("Ei");
double Ei = boost::lexical_cast<double>(eiprop->value());
mu::Parser parser;
parser.DefineVar("incidentEnergy", &Ei); // associate E1 to this parser
parser.SetExpr(m_formula);
t0_direct = parser.Eval();
}
// Loop over the spectra
Progress prog(this, 0.0, 1.0, numHists); // report progress of algorithm
PARALLEL_FOR1(outputWS)
for (int i = 0; i < static_cast<int>(numHists); ++i) {
PARALLEL_START_INTERUPT_REGION
size_t wsIndex = static_cast<size_t>(i);
EventList &evlist = outputWS->getEventList(wsIndex);
if (evlist.getNumberEvents() > 0) // don't bother with empty lists
{
IDetector_const_sptr det;
double L1(Lss); // distance from source to sample
double L2(-1); // distance from sample to detector
try {
det = inputWS->getDetector(i);
if (det->isMonitor()) {
// redefine the sample as the monitor
L1 = source->getDistance(*det);
L2 = 0;
} else {
L2 = sample->getDistance(*det);
}
} catch (Exception::NotFoundError &) {
g_log.error() << "Unable to calculate distances to/from detector" << i
<< std::endl;
}
if (L2 >= 0) {
// One parser for each parallel processor needed (except Edirect mode)
double E1;
mu::Parser parser;
parser.DefineVar("incidentEnergy", &E1); // associate E1 to this parser
parser.SetExpr(m_formula);
// fast neutrons are shifted by min_t0_next, irrespective of tof
double v1_max = L1 / m_t1min;
E1 = m_convfactor * v1_max * v1_max;
double min_t0_next = parser.Eval();
if (emode == "Indirect") {
double t2(-1.0); // time from sample to detector. (-1) signals error
if (det->isMonitor()) {
t2 = 0.0;
} else {
static const double convFact =
1.0e-6 * sqrt(2 * PhysicalConstants::meV /
PhysicalConstants::NeutronMass);
std::vector<double> wsProp = det->getNumberParameter("Efixed");
if (!wsProp.empty()) {
double E2 = wsProp.at(0); //[E2]=meV
double v2 = convFact * sqrt(E2); //[v2]=meter/microsec
t2 = L2 / v2;
} else {
// t2 is kept to -1 if no Efixed is found
g_log.debug() << "Efixed not found for detector " << i
<< std::endl;
//.........这里部分代码省略.........
开发者ID:Mantid-Test-Account,项目名称:mantid,代码行数:101,代码来源:ModeratorTzero.cpp
示例14: execEvent
void ModeratorTzero::execEvent(const std::string &emode) {
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS =
getProperty("InputWorkspace");
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS = getProperty("OutputWorkspace");
if (matrixOutputWS != matrixInputWS) {
matrixOutputWS = matrixInputWS->clone();
setProperty("OutputWorkspace", matrixOutputWS);
}
auto outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
// calculate tof shift once for all neutrons if emode==Direct
double t0_direct(-1);
if (emode == "Direct") {
Kernel::Property *eiprop = outputWS->run().getProperty("Ei");
double Ei = boost::lexical_cast<double>(eiprop->value());
mu::Parser parser;
parser.DefineVar("incidentEnergy", &Ei); // associate E1 to this parser
parser.SetExpr(m_formula);
t0_direct = parser.Eval();
}
const auto &spectrumInfo = outputWS->spectrumInfo();
const double Lss = spectrumInfo.l1();
// Loop over the spectra
const size_t numHists = static_cast<size_t>(outputWS->getNumberHistograms());
Progress prog(this, 0.0, 1.0, numHists); // report progress of algorithm
PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS))
for (int i = 0; i < static_cast<int>(numHists); ++i) {
PARALLEL_START_INTERUPT_REGION
size_t wsIndex = static_cast<size_t>(i);
EventList &evlist = outputWS->getSpectrum(wsIndex);
if (evlist.getNumberEvents() > 0) // don't bother with empty lists
{
double L1(Lss); // distance from source to sample
double L2(-1); // distance from sample to detector
if (spectrumInfo.hasDetectors(i)) {
if (spectrumInfo.isMonitor(i)) {
// redefine the sample as the monitor
L1 = Lss + spectrumInfo.l2(i); // L2 in SpectrumInfo defined negative
L2 = 0;
} else {
L2 = spectrumInfo.l2(i);
}
} else {
g_log.error() << "Unable to calculate distances to/from detector" << i
<< '\n';
}
if (L2 >= 0) {
// One parser for each parallel processor needed (except Edirect mode)
double E1;
mu::Parser parser;
parser.DefineVar("incidentEnergy", &E1); // associate E1 to this parser
parser.SetExpr(m_formula);
// fast neutrons are shifted by min_t0_next, irrespective of tof
double v1_max = L1 / m_t1min;
E1 = m_convfactor * v1_max * v1_max;
double min_t0_next = parser.Eval();
if (emode == "Indirect") {
double t2(-1.0); // time from sample to detector. (-1) signals error
if (spectrumInfo.isMonitor(i)) {
t2 = 0.0;
} else {
static const double convFact =
1.0e-6 * sqrt(2 * PhysicalConstants::meV /
PhysicalConstants::NeutronMass);
std::vector<double> wsProp =
spectrumInfo.detector(i).getNumberParameter("Efixed");
if (!wsProp.empty()) {
double E2 = wsProp.at(0); //[E2]=meV
double v2 = convFact * sqrt(E2); //[v2]=meter/microsec
t2 = L2 / v2;
} else {
// t2 is kept to -1 if no Efixed is found
g_log.debug() << "Efixed not found for detector " << i << '\n';
}
}
if (t2 >= 0) // t2 < 0 when no detector info is available
{
// fix the histogram bins
auto &x = evlist.mutableX();
for (double &tof : x) {
if (tof < m_t1min + t2)
tof -= min_t0_next;
else
tof -= CalculateT0indirect(tof, L1, t2, E1, parser);
}
MantidVec tofs = evlist.getTofs();
for (double &tof : tofs) {
if (tof < m_t1min + t2)
tof -= min_t0_next;
//.........这里部分代码省略.........
开发者ID:samueljackson92,项目名称:mantid,代码行数:101,代码来源:ModeratorTzero.cpp
示例15: exec
/**
* Execute the algorithm.
*/
void LoadBBY::exec() {
// Delete the output workspace name if it existed
std::string outName = getPropertyValue("OutputWorkspace");
if (API::AnalysisDataService::Instance().doesExist(outName))
API::AnalysisDataService::Instance().remove(outName);
// Get the name of the data file.
std::string filename = getPropertyValue(FilenameStr);
ANSTO::Tar::File tarFile(filename);
if (!tarFile.good())
throw std::invalid_argument("invalid BBY file");
// region of intreset
std::vector<bool> roi = createRoiVector(getPropertyValue(MaskStr));
double tofMinBoundary = getProperty(FilterByTofMinStr);
double tofMaxBoundary = getProperty(FilterByTofMaxStr);
double timeMinBoundary = getProperty(FilterByTimeStartStr);
double timeMaxBoundary = getProperty(FilterByTimeStopStr);
if (isEmpty(tofMaxBoundary))
tofMaxBoundary = std::numeric_limits<double>::infinity();
if (isEmpty(timeMaxBoundary))
timeMaxBoundary = std::numeric_limits<double>::infinity();
API::Progress prog(this, 0.0, 1.0, Progress_Total);
prog.doReport("creating instrument");
// create workspace
DataObjects::EventWorkspace_sptr eventWS =
boost::make_shared<DataObjects::EventWorkspace>();
eventWS->initialize(HISTO_BINS_Y * HISTO_BINS_X,
2, // number of TOF bin boundaries
1);
// set the units
eventWS->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("TOF");
eventWS->setYUnit("Counts");
// set title
const std::vector<std::string> &subFiles = tarFile.files();
for (const auto &subFile : subFiles)
if (subFile.compare(0, 3, "BBY") == 0) {
std::string title = subFile;
if (title.rfind(".hdf") == title.length() - 4)
title.resize(title.length() - 4);
if (title.rfind(".nx") == title.length() - 3)
title.resize(title.length() - 3);
eventWS->setTitle(title);
break;
}
// create instrument
InstrumentInfo instrumentInfo;
// Geometry::Instrument_sptr instrument =
createInstrument(tarFile, /* ref */ instrumentInfo);
// eventWS->setInstrument(instrument);
// load events
size_t numberHistograms = eventWS->getNumberHistograms();
std::vector<EventVector_pt> eventVectors(numberHistograms, nullptr);
std::vector<size_t> eventCounts(numberHistograms, 0);
// phase correction
Kernel::Property *periodMasterProperty =
getPointerToProperty(PeriodMasterStr);
Kernel::Property *periodSlaveProperty = getPointerToProperty(PeriodSlaveStr);
Kernel::Property *phaseSlaveProperty = getPointerToProperty(PhaseSlaveStr);
double periodMaster;
double periodSlave;
double phaseSlave;
if (periodMasterProperty->isDefault() || periodSlaveProperty->isDefault() ||
phaseSlaveProperty->isDefault()) {
if (!periodMasterProperty->isDefault() ||
!periodSlaveProperty->isDefault() || !phaseSlaveProperty->isDefault()) {
throw std::invalid_argument("Please specify PeriodMaster, PeriodSlave "
"and PhaseSlave or none of them.");
}
// if values have not been specified in loader then use values from hdf file
periodMaster = instrumentInfo.period_master;
periodSlave = instrumentInfo.period_slave;
phaseSlave = instrumentInfo.phase_slave;
} else {
periodMaster = getProperty(PeriodMasterStr);
periodSlave = getProperty(PeriodSlaveStr);
phaseSlave = getProperty(PhaseSlaveStr);
//.........这里部分代码省略.........
开发者ID:dezed,项目名称:mantid,代码行数:101,代码来源:LoadBBY.cpp
示例16: execEvent
void CorrectKiKf::execEvent()
{
g_log.information("Processing event workspace");
const MatrixWorkspace_const_sptr matrixInputWS = this->getProperty("InputWorkspace");
EventWorkspace_const_sptr inputWS= boost::dynamic_pointer_cast<const EventWorkspace>(matrixInputWS);
// generate the output workspace pointer
API::MatrixWorkspace_sptr matrixOutputWS = this->getProperty("OutputWorkspace");
EventWorkspace_sptr outputWS;
if (matrixOutputWS == matrixInputWS)
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(matrixOutputWS);
else
{
//Make a brand new EventWorkspace
outputWS = boost::dynamic_pointer_cast<EventWorkspace>(
API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1));
//Copy geometry over.
API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false);
//You need to copy over the data as well.
outputWS->copyDataFrom( (*inputWS) );
//Cast to the matrixOutputWS and save it
matrixOutputWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS);
this->setProperty("OutputWorkspace", matrixOutputWS);
}
const std::string emodeStr = getProperty("EMode");
double efixedProp = getProperty("EFixed"),efixed;
if( efixedProp == EMPTY_DBL() )
{
if (emodeStr == "Direct")
{
// Check if it has been store on the run object for this workspace
if( this->inputWS->run().hasProperty("Ei"))
{
Kernel::Property* eiprop = this->inputWS->run().getProperty("Ei");
efixedProp = boost::lexical_cast<double>(eiprop->value());
g_log.debug() << "Using stored Ei value " << efixedProp << "\n";
}
else
{
throw std::invalid_argument("No Ei value has been set or stored within the run information.");
}
}
else
{
// If not specified, will try to get Ef from the parameter file for indirect geometry,
// but it will be done for each spectrum separately, in case of different analyzer crystals
}
}
// Get the parameter map
const ParameterMap& pmap = outputWS->constInstrumentParameters();
int64_t numHistograms = static_cast<int64_t>(inputWS->getNumberHistograms());
API::Progress prog = API::Progress(this, 0.0, 1.0, numHistograms);
PARALLEL_FOR1(outputWS)
for (int64_t i=0; i < numHistograms; ++i)
{
PARALLEL_START_INTERUPT_REGION
double Efi = 0;
// Now get the detector object for this histogram to check if monitor
// or to get Ef for indirect geometry
if (emodeStr == "Indirect")
{
if ( efixedProp != EMPTY_DBL()) Efi = efixedProp;
else try
{
IDetector_const_sptr det = inputWS->getDetector(i);
if (!det->isMonitor())
{
try
{
Parameter_sptr par = pmap.getRecursive(det.get(),"Efixed");
if (par)
{
Efi = par->value<double>();
g_log.debug() << "Detector: " << det->getID() << " EFixed: " << Efi << "\n";
}
}
catch (std::runtime_error&) { /* Throws if a DetectorGroup, use single provided value */ }
}
}
catch(std::runtime_error&) { g_log.information() << "Workspace Index " << i << ": cannot find detector" << "\n"; }
}
if (emodeStr == "Indirect") efixed=Efi;
else efixed=efixedProp;
//Do the correction
EventList *evlist=outputWS->getEventListPtr(i);
switch (evlist->getEventType())
{
case TOF:
//Switch to weights if needed.
evlist->switchTo(WEIGHTED);
//.........这里部分代码省略.........
开发者ID:BigShows,项目名称:mantid,代码行数:101,代码来源:CorrectKiKf.cpp
注:本文中的kernel::Property类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论