/** Extract mask information from a workspace containing instrument
  * @return vector of detector IDs of detectors that are masked
  */
std::vector<detid_t> ExtractMaskToTable::extractMaskFromMatrixWorkspace() {
  // Clear input
  std::vector<detid_t> maskeddetids;

  // Get on hold of instrument
  Instrument_const_sptr instrument = m_dataWS->getInstrument();
  if (!instrument)
    throw runtime_error("There is no instrument in input workspace.");

  // Extract
  size_t numdets = instrument->getNumberDetectors();
  vector<detid_t> detids = instrument->getDetectorIDs();

  for (size_t i = 0; i < numdets; ++i) {
    detid_t tmpdetid = detids[i];
    IDetector_const_sptr tmpdetector = instrument->getDetector(tmpdetid);
    bool masked = tmpdetector->isMasked();
    if (masked) {
      maskeddetids.push_back(tmpdetid);
    }
    g_log.debug() << "[DB] Detector No. " << i << ":  ID = " << tmpdetid
                  << ", Masked = " << masked << ".\n";
  }

  g_log.notice() << "Extract mask:  There are " << maskeddetids.size()
                 << " detectors that"
                    " are masked."
                 << ".\n";

  return maskeddetids;
}
Ejemplo n.º 2
0
/**
 * Returns a "dummy" grouping which a single group with all the detectors in it.
 * @param instrument :: Instrument we want a dummy grouping for
 * @return Grouping information
 */
boost::shared_ptr<Grouping> getDummyGrouping(Instrument_const_sptr instrument)
{
  // Group with all the detectors
  std::ostringstream all;
  all << "1-" << instrument->getNumberDetectors();

  auto dummyGrouping = boost::make_shared<Grouping>();
  dummyGrouping->description = "Dummy grouping";
  dummyGrouping->groupNames.push_back("all");
  dummyGrouping->groups.push_back(all.str());
  return dummyGrouping;
}
Ejemplo n.º 3
0
    /** Executes the algorithm. Reading in the file and creating and populating
     *  the output workspace
     * 
     *  @throw std::runtime_error If the instrument cannot be loaded by the LoadInstrument ChildAlgorithm
     *  @throw InstrumentDefinitionError Thrown if issues with the content of XML instrument file not covered by LoadInstrument
     *  @throw std::invalid_argument If the optional properties are set to invalid values
     */
    void LoadEmptyInstrument::exec()
    {
      // Get other properties
      const double detector_value = getProperty("DetectorValue");
      const double monitor_value = getProperty("MonitorValue");

      // load the instrument into this workspace
      MatrixWorkspace_sptr ws = this->runLoadInstrument();
      Instrument_const_sptr instrument = ws->getInstrument();

      // Get number of detectors stored in instrument
      const size_t number_spectra = instrument->getNumberDetectors();

      // Check that we have some spectra for the workspace
      if( number_spectra == 0){
            g_log.error("Instrument has no detectors, unable to create workspace for it");
            throw Kernel::Exception::InstrumentDefinitionError("No detectors found in instrument");
      }
      
      bool MakeEventWorkspace = getProperty("MakeEventWorkspace");
      
      MatrixWorkspace_sptr outWS;

      if (MakeEventWorkspace)
      {
        //Make a brand new EventWorkspace
        EventWorkspace_sptr localWorkspace = boost::dynamic_pointer_cast<EventWorkspace>(
            API::WorkspaceFactory::Instance().create("EventWorkspace", number_spectra, 2, 1));
        //Copy geometry over.
        API::WorkspaceFactory::Instance().initializeFromParent(ws, localWorkspace, true);

        // Cast to matrix WS
        outWS = boost::dynamic_pointer_cast<MatrixWorkspace>(localWorkspace);
      }
      else
      { 
        // Now create the outputworkspace and copy over the instrument object
        DataObjects::Workspace2D_sptr localWorkspace =
          boost::dynamic_pointer_cast<DataObjects::Workspace2D>(WorkspaceFactory::Instance().create(ws,number_spectra,2,1));

        outWS = boost::dynamic_pointer_cast<MatrixWorkspace>(localWorkspace);
      }

      outWS->rebuildSpectraMapping( true /* include monitors */);


      // ---- Set the values ----------
      if (!MakeEventWorkspace)
      {
        MantidVecPtr x,v,v_monitor;
        x.access().resize(2); x.access()[0]=1.0; x.access()[1]=2.0;
        v.access().resize(1); v.access()[0]=detector_value;
        v_monitor.access().resize(1); v_monitor.access()[0]=monitor_value;

        for (size_t i=0; i < outWS->getNumberHistograms(); i++)
        {
          IDetector_const_sptr det = outWS->getDetector(i);
          if ( det->isMonitor() )
            outWS->setData(i, v_monitor, v_monitor);
          else
            outWS->setData(i, v, v);
        }
      }
      // Save in output
      this->setProperty("OutputWorkspace", outWS);

    }