Exemplo n.º 1
0
void UnitsConversionHelper::initialize(
    const std::string &unitsFrom, const std::string &unitsTo,
    const DataObjects::TableWorkspace_const_sptr &DetWS, int Emode,
    bool forceViaTOF) {
  m_Emode = Emode;

  if (!DetWS)
    throw std::runtime_error("UnitsConversionHelper::initialize called with "
                             "empty preprocessed detectors table");

  // Check how the source units relate to the units requested and create source
  // units
  m_UnitCnvrsn = analyzeUnitsConversion(unitsFrom, unitsTo, forceViaTOF);

  // create target units class
  m_TargetUnit = Kernel::UnitFactory::Instance().create(unitsTo);
  if (!m_TargetUnit)
    throw(std::runtime_error(
        " Cannot retrieve target unit from the units factory"));

  // get access to all values used by unit conversion.
  m_pTwoThetas = &(DetWS->getColVector<double>("TwoTheta"));
  m_pL2s = &(DetWS->getColVector<double>("L2"));

  m_L1 = DetWS->getLogs()->getPropertyValueAsType<double>("L1");

  // get efix
  m_Efix = DetWS->getLogs()->getPropertyValueAsType<double>("Ei");
  m_pEfixedArray = NULL;
  if (m_Emode == (int)Kernel::DeltaEMode::Indirect)
    m_pEfixedArray = DetWS->getColDataArray<float>("eFixed");

  // set up conversion to working state -- in some tests it can be used straight
  // from the beginning.
  m_TwoTheta = (*m_pTwoThetas)[0];
  m_L2 = (*m_pL2s)[0];
  double Efix = m_Efix;
  if (m_pEfixedArray)
    Efix = (double)(*(m_pEfixedArray + 0));

  m_TargetUnit->initialize(m_L1, m_L2, m_TwoTheta, m_Emode, Efix, 0.);
  if (m_SourceWSUnit) {
    m_SourceWSUnit->initialize(m_L1, m_L2, m_TwoTheta, m_Emode, Efix, 0.);
  }
}