Exemplo n.º 1
0
/** Create an EventWorkspace containing fake data
 * of single-crystal diffraction.
 * Instrument is MINITOPAZ
 *
 * @return EventWorkspace_sptr
 */
EventWorkspace_sptr
createDiffractionEventWorkspace(int numEvents, int numPixels, int numBins) {
  double binDelta = 10.0;

  auto retVal = boost::make_shared<EventWorkspace>();
  retVal->initialize(numPixels, 1, 1);

  // --------- Load the instrument -----------
  const std::string filename = FileFinder::Instance().getFullPath(
      "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml");
  InstrumentDefinitionParser parser(filename, "MINITOPAZ",
                                    Strings::loadFile(filename));
  auto instrument = parser.parseXML(nullptr);
  retVal->populateInstrumentParameters();
  retVal->setInstrument(instrument);

  DateAndTime run_start("2010-01-01T00:00:00");

  for (int pix = 0; pix < numPixels; pix++) {
    for (int i = 0; i < numEvents; i++) {
      retVal->getSpectrum(pix) += Mantid::DataObjects::TofEvent(
          (i + 0.5) * binDelta, run_start + double(i));
    }
    retVal->getSpectrum(pix).addDetectorID(pix);
  }

  // Create the x-axis for histogramming.
  HistogramData::BinEdges x1(numBins);
  auto &xRef = x1.mutableData();
  for (int i = 0; i < numBins; ++i) {
    xRef[i] = i * binDelta;
  }

  // Set all the histograms at once.
  retVal->setAllX(x1);
  // Default unit: TOF.
  retVal->getAxis(0)->setUnit("TOF");

  // Give it a crystal and goniometer
  WorkspaceCreationHelper::setGoniometer(retVal, 0., 0., 0.);
  WorkspaceCreationHelper::setOrientedLattice(retVal, 1., 1., 1.);

  // Some sanity checks
  if (retVal->getInstrument()->getName() != "MINITOPAZ")
    throw std::runtime_error("MDEventsTestHelper::"
                             "createDiffractionEventWorkspace(): Wrong "
                             "instrument loaded.");
  Mantid::detid2det_map dets;
  retVal->getInstrument()->getDetectors(dets);
  if (dets.size() != 100 * 100)
    throw std::runtime_error("MDEventsTestHelper::"
                             "createDiffractionEventWorkspace(): Wrong "
                             "instrument size.");

  return retVal;
}
Exemplo n.º 2
0
  /** Create an EventWorkspace containing fake data
   * of single-crystal diffraction.
   * Instrument is MINITOPAZ
   *
   * @return EventWorkspace_sptr
   */
  EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents)
  {
    FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST");

    int numPixels = 10000;
    int numBins = 1600;
    double binDelta = 10.0;

    EventWorkspace_sptr retVal(new EventWorkspace);
    retVal->initialize(numPixels,1,1);

    // --------- Load the instrument -----------
    LoadInstrument * loadInst = new LoadInstrument();
    loadInst->initialize();
    loadInst->setPropertyValue("Filename", "IDFs_for_UNIT_TESTING/MINITOPAZ_Definition.xml");
    loadInst->setProperty<Mantid::API::MatrixWorkspace_sptr> ("Workspace", retVal);
    loadInst->execute();
    delete loadInst;
    // Populate the instrument parameters in this workspace - this works around a bug
    retVal->populateInstrumentParameters();

    DateAndTime run_start("2010-01-01T00:00:00");

    for (int pix = 0; pix < numPixels; pix++)
    {
      for (int i=0; i<numEvents; i++)
      {
        retVal->getEventList(pix) += Mantid::DataObjects::TofEvent((i+0.5)*binDelta, run_start+double(i));
      }
      retVal->getEventList(pix).addDetectorID(pix);
    }

    //Create the x-axis for histogramming.
    Mantid::MantidVecPtr x1;
    Mantid::MantidVec& xRef = x1.access();
    xRef.resize(numBins);
    for (int i = 0; i < numBins; ++i)
    {
      xRef[i] = i*binDelta;
    }

    //Set all the histograms at once.
    retVal->setAllX(x1);
    // Default unit: TOF.
    retVal->getAxis(0)->setUnit("TOF");

    // Give it a crystal and goniometer
    WorkspaceCreationHelper::SetGoniometer(retVal, 0., 0., 0.);
    WorkspaceCreationHelper::SetOrientedLattice(retVal, 1., 1., 1.);

    // Some sanity checks
    if (retVal->getInstrument()->getName() != "MINITOPAZ")
      throw std::runtime_error("MDEventsTestHelper::createDiffractionEventWorkspace(): Wrong instrument loaded.");
    Mantid::detid2det_map dets;
    retVal->getInstrument()->getDetectors(dets);
    if ( dets.size() != 100*100)
      throw std::runtime_error("MDEventsTestHelper::createDiffractionEventWorkspace(): Wrong instrument size.");


    return retVal;
  }