コード例 #1
0
ファイル: NormaliseToMonitor.cpp プロジェクト: mganeva/mantid
/** Calculates the overall normalization factor.
 *  This multiplies result by (bin width * sum of monitor counts) / total
 * frame
 * width.
 *  @param X The BinEdges of the workspace
 *  @param Y The Counts of the workspace
 *  @param E The CountStandardDeviations of the workspace
 */
void NormaliseToMonitor::normalisationFactor(const BinEdges &X, Counts &Y,
                                             CountStandardDeviations &E) {
  const double monitorSum = std::accumulate(Y.begin(), Y.end(), 0.0);
  const double range = X.back() - X.front();
  auto specLength = Y.size();

  auto &yNew = Y.mutableRawData();
  auto &eNew = E.mutableRawData();

  for (size_t j = 0; j < specLength; ++j) {
    const double factor = range / ((X[j + 1] - X[j]) * monitorSum);
    yNew[j] *= factor;
    eNew[j] *= factor;
  }
}
コード例 #2
0
ファイル: Points.cpp プロジェクト: DanNixon/mantid
/// Constructs Points from BinEdges, where each point is a bin center.
Points::Points(const BinEdges &edges) {
  if (!edges)
    return;
  if (edges.size() == 1)
    throw std::logic_error("Points: Cannot construct from BinEdges of size 1");
  if (edges.empty()) {
    m_data = Kernel::make_cow<HistogramX>(0);
    return;
  }

  std::vector<double> data(edges.size() - 1);
  for (size_t i = 0; i < data.size(); ++i) {
    data[i] = (0.5 * (edges[i] + edges[i + 1]));
  }
  m_data = Kernel::make_cow<HistogramX>(std::move(data));
}
コード例 #3
0
/// Move-constructs FrequencyStandardDeviations from CountStandardDeviations and
/// bin width based on BinEdges.
FrequencyStandardDeviations::FrequencyStandardDeviations(
    CountStandardDeviations &&counts, const BinEdges &edges) {
  if (!counts)
    return;
  if (!edges)
    throw std::logic_error("FrequencyStandardDeviations: Cannot construct from "
                           "CountStandardDeviations -- BinEdges are NULL.");
  if ((counts.size() + 1) != edges.size())
    if (!counts.empty() || !edges.empty())
      throw std::logic_error("FrequencyStandardDeviations: Cannot construct "
                             "from CountStandardDeviations -- BinEdges size "
                             "does not match.");
  // Cannot move counts private data since it is of different type.
  m_data = counts.cowData();
  counts = Kernel::cow_ptr<HistogramE>(nullptr);
  auto &data = m_data.access();
  for (size_t i = 0; i < data.size(); ++i) {
    data[i] /= edges[i + 1] - edges[i];
  }
}
コード例 #4
0
ファイル: MaskBins.cpp プロジェクト: mantidproject/mantid
/** Finds the indices of the bins at the limits of the range given.
 *  @param X ::        The X vector to search
 *  @param startBin :: Returns the bin index including the starting value
 *  @param endBin ::   Returns the bin index after the end value
 */
void MaskBins::findIndices(const BinEdges &X,
                           MantidVec::difference_type &startBin,
                           MantidVec::difference_type &endBin) {
  startBin = std::distance(X.begin(),
                           std::upper_bound(X.cbegin(), X.cend(), m_startX));
  if (startBin != 0)
    --startBin;
  auto last = std::lower_bound(X.cbegin(), X.cend(), m_endX);
  if (last == X.cend())
    --last;
  endBin = std::distance(X.cbegin(), last);
}