/**
 * Get value of log from workspace at given index
 * @param logName :: [input] Name of log
 * @param function :: [input] Function to apply to log e.g. min, max, mean...
 * @param index :: [input] Index of workspace in list
 * @returns :: value of log cast to double
 * @throws std::runtime_error if log cannot be found or cast
 * @throws std::invalid_argument if index is not in range
 */
double MDFLogValueFinder::getLogValue(
    const QString &logName, const Mantid::Kernel::Math::StatisticType &function,
    int index) const {
  if (index > m_wsNames.size() - 1 || index < 0) {
    std::ostringstream message;
    message << "Index " << index
            << " out of range: number of workspaces = " << m_wsNames.size();
    throw std::invalid_argument(message.str());
  }

  return getLogValue(logName, function, m_wsNames.at(index));
}
示例#2
0
/**  Performs asymmetry analysis on a loaded workspace
*   @param loadedWs :: [input] Workspace to apply analysis to
*   @param index :: [input] Vector index where results will be stored
*/
void PlotAsymmetryByLogValue::doAnalysis(Workspace_sptr loadedWs,
                                         size_t index) {

  // Check if workspace is a workspace group
  WorkspaceGroup_sptr group =
      boost::dynamic_pointer_cast<WorkspaceGroup>(loadedWs);

  // If it is not, we only have 'red' data
  if (!group) {
    MatrixWorkspace_sptr ws_red =
        boost::dynamic_pointer_cast<MatrixWorkspace>(loadedWs);

    double Y, E;
    calcIntAsymmetry(ws_red, Y, E);
    m_logValue[index] = getLogValue(*ws_red);
    m_redY[index] = Y;
    m_redE[index] = E;

  } else {
    // It is a group

    // Process red data
    MatrixWorkspace_sptr ws_red;
    try {
      ws_red = boost::dynamic_pointer_cast<MatrixWorkspace>(
          group->getItem(m_red - 1));
    } catch (std::out_of_range &) {
      throw std::out_of_range("Red period out of range");
    }
    double YR, ER;
    calcIntAsymmetry(ws_red, YR, ER);
    double logValue = getLogValue(*ws_red);
    m_logValue[index] = logValue;
    m_redY[index] = YR;
    m_redE[index] = ER;

    if (m_green != EMPTY_INT()) {
      // Process green period if supplied by user
      MatrixWorkspace_sptr ws_green;
      try {
        ws_green = boost::dynamic_pointer_cast<MatrixWorkspace>(
            group->getItem(m_green - 1));
      } catch (std::out_of_range &) {
        throw std::out_of_range("Green period out of range");
      }
      double YG, EG;
      calcIntAsymmetry(ws_green, YG, EG);
      // Red data
      m_redY[index] = YR;
      m_redE[index] = ER;
      // Green data
      m_greenY[index] = YG;
      m_greenE[index] = EG;
      // Sum
      m_sumY[index] = YR + YG;
      m_sumE[index] = sqrt(ER * ER + EG * EG);
      // Diff
      calcIntAsymmetry(ws_red, ws_green, YR, ER);
      m_diffY[index] = YR;
      m_diffE[index] = ER;
    }
  } // else loadedGroup
}
/// Execute the algorithm.
void PDDetermineCharacterizations::exec() {
  // setup property manager to return
  const std::string managerName = getPropertyValue("ReductionProperties");
  if (PropertyManagerDataService::Instance().doesExist(managerName)) {
    m_propertyManager =
        PropertyManagerDataService::Instance().retrieve(managerName);
  } else {
    m_propertyManager = boost::make_shared<Kernel::PropertyManager>();
    PropertyManagerDataService::Instance().addOrReplace(managerName,
                                                        m_propertyManager);
  }

  setDefaultsInPropManager();

  m_characterizations = getProperty(CHAR_PROP_NAME);
  if (bool(m_characterizations) && (m_characterizations->rowCount() > 0)) {
    API::MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
    auto run = inputWS->mutableRun();

    double frequency = getLogValue(run, FREQ_PROP_NAME);

    double wavelength = getLogValue(run, WL_PROP_NAME);

    // determine the container name
    std::string container;
    if (run.hasProperty("SampleContainer")) {
      const auto containerProp = run.getLogData("SampleContainer");

      // the property is normally a TimeSeriesProperty
      const auto containerPropSeries =
          dynamic_cast<TimeSeriesProperty<std::string> *>(containerProp);
      if (containerPropSeries) {
        // assume that only the first value matters
        container = containerPropSeries->valuesAsVector().front();
      } else {
        // try as a normal Property
        container = containerProp->value();
      }

      // remove whitespace from the value
      container = Kernel::Strings::replaceAll(container, " ", "");
    }

    getInformationFromTable(frequency, wavelength, container);
  }

  overrideRunNumProperty("BackRun", "container");
  overrideRunNumProperty("NormRun", "vanadium");
  overrideRunNumProperty("NormBackRun", "vanadium_background");
  overrideRunNumProperty("EmptyEnv", "empty_environment");
  overrideRunNumProperty("EmptyInstr", "empty_instrument");

  std::vector<std::string> expectedNames = getColumnNames();
  for (auto &expectedName : expectedNames) {
    if (m_propertyManager->existsProperty(expectedName)) {
      g_log.debug() << expectedName << ":"
                    << m_propertyManager->getPropertyValue(expectedName)
                    << "\n";
    } else {
      g_log.warning() << expectedName << " DOES NOT EXIST\n";
    }
  }
}