Beispiel #1
0
/**
 * Cache frequently accessed user input
 */
void LoadDetectorInfo::cacheInputs() {
  m_workspace = getProperty("Workspace");
  m_moveDets = getProperty("RelocateDets");

  // Cache base instrument
  m_baseInstrument = m_workspace->getInstrument()->baseInstrument();
  Geometry::IComponent_const_sptr sample =
      m_workspace->getInstrument()->getSample();
  if (sample)
    m_samplePos = sample->getPos();

  // cache values of instrument level parameters so we only change then if they
  // are different
  const auto &pmap = m_workspace->constInstrumentParameters();
  // delay
  auto param = pmap.get(m_baseInstrument->getComponentID(), DELAY_PARAM);
  if (param)
    m_instDelta = param->value<double>();
  // pressure
  param = pmap.get(m_baseInstrument->getComponentID(), PRESSURE_PARAM);
  if (param)
    m_instPressure = param->value<double>();
  // thickness
  param = pmap.get(m_baseInstrument->getComponentID(), THICKNESS_PARAM);
  if (param)
    m_instThickness = param->value<double>();
}
V3D SaveIsawDetCal::findPixelPos(std::string bankName, int col, int row) {
  boost::shared_ptr<const IComponent> parent =
      inst->getComponentByName(bankName);
  if (parent->type().compare("RectangularDetector") == 0) {
    boost::shared_ptr<const RectangularDetector> RDet =
        boost::dynamic_pointer_cast<const RectangularDetector>(parent);

    boost::shared_ptr<Detector> pixel = RDet->getAtXY(col, row);
    return pixel->getPos();
  } else {
    std::vector<Geometry::IComponent_const_sptr> children;
    boost::shared_ptr<const Geometry::ICompAssembly> asmb =
        boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent);
    asmb->getChildren(children, false);
    if (children[0]->getName().compare("sixteenpack") == 0) {
      asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(
          children[0]);
      children.clear();
      asmb->getChildren(children, false);
    }
    int col0 = col - 1;
    // WISH detectors are in bank in this order in instrument
    if (inst->getName() == "WISH")
      col0 = (col % 2 == 0 ? col / 2 + 75 : (col - 1) / 2);
    boost::shared_ptr<const Geometry::ICompAssembly> asmb2 =
        boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(
            children[col0]);
    std::vector<Geometry::IComponent_const_sptr> grandchildren;
    asmb2->getChildren(grandchildren, false);
    Geometry::IComponent_const_sptr first = grandchildren[row - 1];
    return first->getPos();
  }
}
Beispiel #3
0
/**
 * Get position in space of a componentName
 */
V3D LoadILLSANS::getComponentPosition(const std::string &componentName) {
  Geometry::Instrument_const_sptr instrument =
      m_localWorkspace->getInstrument();
  Geometry::IComponent_const_sptr component =
      instrument->getComponentByName(componentName);
  return component->getPos();
}
Beispiel #4
0
void LoadILLIndirect::moveComponent(const std::string &componentName,
                                    double twoTheta, double offSet) {

  try {

    Geometry::Instrument_const_sptr instrument =
        m_localWorkspace->getInstrument();
    Geometry::IComponent_const_sptr component =
        instrument->getComponentByName(componentName);

    double r, theta, phi, newTheta, newR;
    V3D oldPos = component->getPos();
    oldPos.getSpherical(r, theta, phi);

    newTheta = twoTheta;
    newR = offSet;

    V3D newPos;
    newPos.spherical(newR, newTheta, phi);

    // g_log.debug() << tube->getName() << " : t = " << theta << " ==> t = " <<
    // newTheta << "\n";
    Geometry::ParameterMap &pmap = m_localWorkspace->instrumentParameters();
    Geometry::ComponentHelper::moveComponent(
        *component, pmap, newPos, Geometry::ComponentHelper::Absolute);

  } catch (Mantid::Kernel::Exception::NotFoundError &) {
    throw std::runtime_error("Error when trying to move the " + componentName +
                             " : NotFoundError");
  } catch (std::runtime_error &) {
    throw std::runtime_error("Error when trying to move the " + componentName +
                             " : runtime_error");
  }
}
Beispiel #5
0
 double LoadHelper::getL2(const API::MatrixWorkspace_sptr& workspace, int detId)
 {
   // Get a pointer to the instrument contained in the workspace
   Geometry::Instrument_const_sptr instrument = workspace->getInstrument();
   // Get the distance between the source and the sample (assume in metres)
   Geometry::IComponent_const_sptr sample = instrument->getSample();
   // Get the sample-detector distance for this detector (in metres)
   double l2 = workspace->getDetector(detId)->getPos().distance(sample->getPos());
   return l2;
 }
Beispiel #6
0
 V3D LoadHelper::getComponentPosition(API::MatrixWorkspace_sptr ws, const std::string &componentName)
 {
   try
   {
     Geometry::Instrument_const_sptr instrument = ws->getInstrument();
     Geometry::IComponent_const_sptr component = instrument->getComponentByName(componentName);
     V3D pos = component->getPos();
     return pos;
   } catch (Mantid::Kernel::Exception::NotFoundError&)
   {
     throw std::runtime_error("Error when trying to move the " + componentName + " : NotFoundError");
   }
 }
/** Get detectors' counts
 * @brief GetSpiceDataRawCountsFromMD::getDetCounts
 * @param mdws
 * @param runnumber :: run number of the detectors having for exporting; -1 for
 * all run numbers
 * @param detid :: detector ID for the detectors for exporting; -1 for all
 * detectors
 * @param vecX :: x-values as 2theta position of detectors to be exported;
 * @param vecY :: raw detector's counts
 * @param formX :: flag to set up vecX
 */
void GetSpiceDataRawCountsFromMD::getDetCounts(
    API::IMDEventWorkspace_const_sptr mdws, const int &runnumber,
    const int &detid, std::vector<double> &vecX, std::vector<double> &vecY,
    bool formX) {
  // Get sample and source position
  if (mdws->getNumExperimentInfo() == 0)
    throw std::runtime_error(
        "There is no ExperimentInfo object that has been set to "
        "input MDEventWorkspace!");

  V3D samplepos;
  V3D sourcepos;

  if (formX) {
    ExperimentInfo_const_sptr expinfo = mdws->getExperimentInfo(0);
    Geometry::IComponent_const_sptr sample =
        expinfo->getInstrument()->getSample();
    samplepos = sample->getPos();
    g_log.debug() << "Sample position is " << samplepos.X() << ", "
                  << samplepos.Y() << ", " << samplepos.Z() << "\n";

    Geometry::IComponent_const_sptr source =
        expinfo->getInstrument()->getSource();
    sourcepos = source->getPos();
    g_log.debug() << "Source position is " << sourcepos.X() << ","
                  << sourcepos.Y() << ", " << sourcepos.Z() << "\n";
    vecX.clear();
  }
  vecY.clear();

  // Go through all events to find out their positions
  IMDIterator *mditer = mdws->createIterator();

  bool scancell = true;
  size_t nextindex = 1;
  while (scancell) {
    // get the number of events of this cell
    size_t numev2 = mditer->getNumEvents();
    g_log.debug() << "MDWorkspace " << mdws->name() << " Cell " << nextindex - 1
                  << ": Number of events = " << numev2
                  << " Does NEXT cell exist = " << mditer->next() << "\n";

    // loop over all the events in current cell
    for (size_t iev = 0; iev < numev2; ++iev) {
      // filter out the events with uninterrested run numbers and detid
      // runnumber/detid < 0 indicates that all run number or all detectors will
      // be taken
      int thisrunnumber = mditer->getInnerRunIndex(iev);
      if (runnumber >= 0 && thisrunnumber != runnumber)
        continue;

      int thisdetid = mditer->getInnerDetectorID(iev);
      if (detid >= 0 && thisdetid != detid)
        continue;

      // get detector position for 2theta
      if (formX) {
        double tempx = mditer->getInnerPosition(iev, 0);
        double tempy = mditer->getInnerPosition(iev, 1);
        double tempz = mditer->getInnerPosition(iev, 2);
        Kernel::V3D detpos(tempx, tempy, tempz);
        Kernel::V3D v_det_sample = detpos - samplepos;
        Kernel::V3D v_sample_src = samplepos - sourcepos;
        double twotheta = v_det_sample.angle(v_sample_src) / M_PI * 180.;
        vecX.push_back(twotheta);
      }

      // add new value to vecPair
      double signal = mditer->getInnerSignal(iev);
      vecY.push_back(signal);
    } // ENDFOR (iev)

    // Advance to next cell
    if (mditer->next()) {
      // advance to next cell
      mditer->jumpTo(nextindex);
      ++nextindex;
    } else {
      // break the loop
      scancell = false;
    }
  } // ENDOF(while)

  delete (mditer);

  return;
}