Пример #1
0
bool Zerberus::loadSoundFonts(const QStringList& sl)
      {
      foreach (const QString& s, sl) {
            if (!loadInstrument(s))
                  return false;
            }
      return true;
      }
Пример #2
0
/**
 * Initialize the buffer event workspace.
 * @param setup :: Information on the data to be sent.
 */
void ISISLiveEventDataListener::initEventBuffer(
    const TCPStreamEventDataSetup &setup) {
  // Create an event workspace for the output
  auto workspace = API::WorkspaceFactory::Instance().create(
      "EventWorkspace", m_numberOfSpectra, 2, 1);

  m_eventBuffer.resize(m_numberOfPeriods);

  // save this workspace as the event buffer
  m_eventBuffer[0] =
      boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(workspace);
  if (!m_eventBuffer[0]) {
    throw std::runtime_error("Failed to create an event workspace");
  }
  // Set the units
  m_eventBuffer[0]->getAxis(0)->unit() =
      Kernel::UnitFactory::Instance().create("TOF");
  m_eventBuffer[0]->setYUnit("Counts");

  // Set the spectra-detector maping
  loadSpectraMap();

  // Load the instrument
  std::string instrName(setup.head_setup.inst_name);
  loadInstrument(instrName);

  // Set the run number
  m_runNumber = setup.head_setup.run_number;
  std::string run_num = boost::lexical_cast<std::string>(m_runNumber);
  m_eventBuffer[0]->mutableRun().addLogData(
      new Mantid::Kernel::PropertyWithValue<std::string>(RUN_NUMBER_PROPERTY,
                                                         run_num));

  // Add the proton charge property
  m_eventBuffer[0]->mutableRun().addLogData(
      new Mantid::Kernel::TimeSeriesProperty<double>(PROTON_CHARGE_PROPERTY));

  if (m_numberOfPeriods > 1) {
    for (size_t i = 1; i < static_cast<size_t>(m_numberOfPeriods); ++i) {
      // create an event workspace for each period
      m_eventBuffer[i] =
          boost::dynamic_pointer_cast<DataObjects::EventWorkspace>(
              API::WorkspaceFactory::Instance().create(
                  "EventWorkspace", m_eventBuffer[0]->getNumberHistograms(), 2,
                  1));

      // Copy geometry over.
      API::WorkspaceFactory::Instance().initializeFromParent(
          m_eventBuffer[0], m_eventBuffer[i], false);
    }
  }
}
Пример #3
0
bool Zerberus::addSoundFont(const QString& s)
      {
      return loadInstrument(s);
      }
/** Execute the algorithm.
 */
void VesuvioL1ThetaResolution::exec() {
  // Load the instrument workspace
  loadInstrument();

  const std::string l1DistributionWsName = getPropertyValue("L1Distribution");
  const std::string thetaDistributionWsName =
      getPropertyValue("ThetaDistribution");
  const size_t numHist = m_instWorkspace->getNumberHistograms();
  const int numEvents = getProperty("NumEvents");

  // Create output workspace of resolution
  m_outputWorkspace =
      WorkspaceFactory::Instance().create("Workspace2D", 4, numHist, numHist);

  // Set vertical axis to statistic labels
  auto specAxis = new TextAxis(4);
  specAxis->setLabel(0, "l1_Mean");
  specAxis->setLabel(1, "l1_StdDev");
  specAxis->setLabel(2, "theta_Mean");
  specAxis->setLabel(3, "theta_StdDev");
  m_outputWorkspace->replaceAxis(1, specAxis);

  // Set X axis to spectrum numbers
  m_outputWorkspace->getAxis(0)->setUnit("Label");
  auto xAxis = boost::dynamic_pointer_cast<Units::Label>(
      m_outputWorkspace->getAxis(0)->unit());
  if (xAxis)
    xAxis->setLabel("Spectrum Number");

  // Create output workspaces for distributions if required
  if (!l1DistributionWsName.empty()) {
    m_l1DistributionWs = WorkspaceFactory::Instance().create(
        m_instWorkspace, numHist, numEvents, numEvents);

    // Set Y axis
    m_l1DistributionWs->setYUnitLabel("Events");

    // Set X axis
    auto distributionXAxis = m_l1DistributionWs->getAxis(0);
    distributionXAxis->setUnit("Label");
    auto labelUnit =
        boost::dynamic_pointer_cast<Units::Label>(distributionXAxis->unit());
    if (labelUnit)
      labelUnit->setLabel("l1");
  }

  if (!thetaDistributionWsName.empty()) {
    m_thetaDistributionWs = WorkspaceFactory::Instance().create(
        m_instWorkspace, numHist, numEvents, numEvents);

    // Set Y axis
    m_thetaDistributionWs->setYUnitLabel("Events");

    // Set X axis
    auto distributionXAxis = m_thetaDistributionWs->getAxis(0);
    distributionXAxis->setUnit("Label");
    auto labelUnit =
        boost::dynamic_pointer_cast<Units::Label>(distributionXAxis->unit());
    if (labelUnit)
      labelUnit->setLabel("theta");
  }

  // Set up progress reporting
  Progress prog(this, 0.0, 1.0, numHist);
  const int seed(getProperty("Seed"));
  std::mt19937 randEngine(static_cast<std::mt19937::result_type>(seed));
  std::uniform_real_distribution<> flatDistrib(0.0, 1.0);
  std::function<double()> flatVariateGen(
      [&randEngine, &flatDistrib]() { return flatDistrib(randEngine); });

  const auto &spectrumInfo = m_instWorkspace->spectrumInfo();
  // Loop for all detectors
  for (size_t i = 0; i < numHist; i++) {
    std::vector<double> l1;
    std::vector<double> theta;
    const auto &det = spectrumInfo.detector(i);

    // Report progress
    std::stringstream report;
    report << "Detector " << det.getID();
    prog.report(report.str());
    g_log.information() << "Detector ID " << det.getID() << '\n';

    // Do simulation
    calculateDetector(det, flatVariateGen, l1, theta);

    // Calculate statistics for L1 and theta
    Statistics l1Stats = getStatistics(l1);
    Statistics thetaStats = getStatistics(theta);

    g_log.information() << "l0: mean=" << l1Stats.mean
                        << ", std.dev.=" << l1Stats.standard_deviation
                        << "\ntheta: mean=" << thetaStats.mean
                        << ", std.dev.=" << thetaStats.standard_deviation
                        << '\n';

    // Set values in output workspace
    const int specNo = m_instWorkspace->getSpectrum(i).getSpectrumNo();
    m_outputWorkspace->mutableX(0)[i] = specNo;
    m_outputWorkspace->mutableX(1)[i] = specNo;
    m_outputWorkspace->mutableX(2)[i] = specNo;
    m_outputWorkspace->mutableX(3)[i] = specNo;
    m_outputWorkspace->mutableY(0)[i] = l1Stats.mean;
    m_outputWorkspace->mutableY(1)[i] = l1Stats.standard_deviation;
    m_outputWorkspace->mutableY(2)[i] = thetaStats.mean;
    m_outputWorkspace->mutableY(3)[i] = thetaStats.standard_deviation;

    // Process data for L1 distribution
    if (m_l1DistributionWs) {
      auto &x = m_l1DistributionWs->mutableX(i);

      std::sort(l1.begin(), l1.end());
      std::copy(l1.begin(), l1.end(), x.begin());

      m_l1DistributionWs->mutableY(i) = 1.0;

      auto &spec = m_l1DistributionWs->getSpectrum(i);
      spec.setSpectrumNo(specNo);
      spec.addDetectorID(det.getID());
    }

    // Process data for theta distribution
    if (m_thetaDistributionWs) {
      auto &x = m_thetaDistributionWs->mutableX(i);

      std::sort(theta.begin(), theta.end());
      std::copy(theta.begin(), theta.end(), x.begin());

      m_thetaDistributionWs->mutableY(i) = 1.0;

      auto &spec = m_thetaDistributionWs->getSpectrum(i);
      spec.setSpectrumNo(specNo);
      spec.addDetectorID(det.getID());
    }
  }

  // Process the L1 distribution workspace
  if (m_l1DistributionWs) {
    const double binWidth = getProperty("L1BinWidth");
    setProperty("L1Distribution",
                processDistribution(m_l1DistributionWs, binWidth));
  }

  // Process the theta distribution workspace
  if (m_thetaDistributionWs) {
    const double binWidth = getProperty("ThetaBinWidth");
    setProperty("ThetaDistribution",
                processDistribution(m_thetaDistributionWs, binWidth));
  }

  setProperty("OutputWorkspace", m_outputWorkspace);
}