Beispiel #1
0
void TransformMD::doTransform(
    typename Mantid::DataObjects::MDEventWorkspace<MDE, nd>::sptr ws) {
  std::vector<API::IMDNode *> boxes;
  // Get ALL the boxes, including MDGridBoxes.
  ws->getBox()->getBoxes(boxes, 1000, false);

  // If file backed, sort them first.
  if (ws->isFileBacked())
    API::IMDNode::sortObjByID(boxes);

  PARALLEL_FOR_IF(!ws->isFileBacked())
  for (int i = 0; i < static_cast<int>(boxes.size()); i++) { // NOLINT
    PARALLEL_START_INTERUPT_REGION
    MDBoxBase<MDE, nd> *box = dynamic_cast<MDBoxBase<MDE, nd> *>(boxes[i]);
    if (box) {
      box->transformDimensions(m_scaling, m_offset);
    }
    PARALLEL_END_INTERUPT_REGION
  }
  PARALLEL_CHECK_INTERUPT_REGION
}
Beispiel #2
0
void QueryMDWorkspace::getBoxData(
    typename Mantid::DataObjects::MDEventWorkspace<MDE, nd>::sptr ws) {
    if (this->getPropertyValue("BoxDataTable").empty())
        return;

    ITableWorkspace_sptr output = WorkspaceFactory::Instance().createTable();
    output->addColumn("int", "RecursionDepth");
    output->addColumn("int", "NumBoxes");
    output->addColumn("int", "NumWithEvents");
    output->addColumn("double", "PctWithEvents");
    output->addColumn("int", "TotalEvents");
    output->addColumn("double", "AvgEventsPer");
    output->addColumn("double", "TotalWeight");
    output->addColumn("double", "TotalSignal");
    output->addColumn("double", "TotalErrorSquared");
    for (size_t d = 0; d < nd; d++)
        output->addColumn("double", "Dim" + Strings::toString(d));

    size_t depth = ws->getBoxController()->getMaxDepth() + 1;
    std::vector<int> NumBoxes(depth, 0);
    std::vector<int> NumWithEvents(depth, 0);
    std::vector<int> TotalEvents(depth, 0);
    std::vector<double> TotalWeight(depth, 0);
    std::vector<double> TotalSignal(depth, 0);
    std::vector<double> TotalErrorSquared(depth, 0);
    std::vector<std::vector<double>> Dims(depth, std::vector<double>(nd, 0.0));

    std::vector<API::IMDNode *> boxes;
    ws->getBox()->getBoxes(boxes, depth, true);
    for (size_t i = 0; i < boxes.size(); i++) {
        MDBoxBase<MDE, nd> *box = dynamic_cast<MDBoxBase<MDE, nd> *>(boxes[i]);
        if (!box)
            throw(std::runtime_error("Can not cast IMDNode to any type of boxes"));
        size_t d = box->getDepth();
        NumBoxes[d] += 1;
        if (box->getNPoints() > 0)
            NumWithEvents[d] += 1;
        TotalEvents[d] += static_cast<int>(box->getNPoints());
        TotalWeight[d] += box->getTotalWeight();
        TotalSignal[d] += box->getSignal();
        TotalErrorSquared[d] += box->getErrorSquared();
        for (size_t dim = 0; dim < nd; dim++)
            Dims[d][dim] = double(box->getExtents(dim).getSize());
    }

    int rowCounter = 0;
    for (size_t d = 0; d < depth; d++) {
        int col = 0;
        output->appendRow();
        output->cell<int>(rowCounter, col++) = int(d);
        output->cell<int>(rowCounter, col++) = NumBoxes[d];
        output->cell<int>(rowCounter, col++) = NumWithEvents[d];
        output->cell<double>(rowCounter, col++) =
            100.0 * double(NumWithEvents[d]) / double(NumBoxes[d]);
        output->cell<int>(rowCounter, col++) = TotalEvents[d];
        output->cell<double>(rowCounter, col++) =
            double(TotalEvents[d]) / double(NumBoxes[d]);
        output->cell<double>(rowCounter, col++) = TotalWeight[d];
        output->cell<double>(rowCounter, col++) = TotalSignal[d];
        output->cell<double>(rowCounter, col++) = TotalErrorSquared[d];
        for (size_t dim = 0; dim < nd; dim++)
            output->cell<double>(rowCounter, col++) = Dims[d][dim];
        rowCounter++;
    }

    setProperty("BoxDataTable", output);
}