예제 #1
0
/** Execute the algorithm.
 */
void ConvertDiffCal::exec() {
  OffsetsWorkspace_const_sptr offsetsWS = getProperty("OffsetsWorkspace");

  // initial setup of new style config
  ITableWorkspace_sptr configWksp = boost::make_shared<TableWorkspace>();
  configWksp->addColumn("int", "detid");
  configWksp->addColumn("double", "difc");
  configWksp->addColumn("double", "difa");
  configWksp->addColumn("double", "tzero");

  // create values in the table
  const size_t numberOfSpectra = offsetsWS->getNumberHistograms();
  Progress progress(this, 0.0, 1.0, numberOfSpectra);

  for (size_t i = 0; i < numberOfSpectra; ++i) {
    API::TableRow newrow = configWksp->appendRow();
    newrow << static_cast<int>(getDetID(offsetsWS, i));
    newrow << calculateDIFC(offsetsWS, i);
    newrow << 0.; // difa
    newrow << 0.; // tzero

    progress.report();
  }

  // sort the results
  IAlgorithm_sptr sortTable = createChildAlgorithm("SortTableWorkspace");
  sortTable->setProperty("InputWorkspace", configWksp);
  sortTable->setProperty("OutputWorkspace", configWksp);
  sortTable->setPropertyValue("Columns", "detid");
  sortTable->executeAsChildAlg();

  // copy over the results
  configWksp = sortTable->getProperty("OutputWorkspace");
  setProperty("OutputWorkspace", configWksp);
}
예제 #2
0
/**
 * @param offsetsWS
 * @param index
 * @return The offset adjusted value of DIFC
 */
double calculateDIFC(OffsetsWorkspace_const_sptr offsetsWS, const size_t index) {
    Instrument_const_sptr instrument = offsetsWS->getInstrument();

    const detid_t detid = getDetID(offsetsWS, index);
    const double offset = getOffset(offsetsWS, detid);

    double l1;
    Kernel::V3D beamline, samplePos;
    double beamline_norm;
    instrument->getInstrumentParameters(l1, beamline, beamline_norm, samplePos);

    Geometry::IDetector_const_sptr detector = instrument->getDetector(detid);

    // the factor returned is what is needed to convert TOF->d-spacing
    // the table is supposed to be filled with DIFC which goes the other way
    const double factor = Instrument::calcConversion(l1, beamline, beamline_norm,
                                      samplePos, detector, offset);
    return 1./factor;
}