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.);
  }
}
void UnitsConversionHelper::initialize(const MDWSDescription &TWSD, const std::string &units_to)
{   
  // obtain input workspace units
    API::MatrixWorkspace_const_sptr inWS2D = TWSD.getInWS();
    if(!inWS2D.get()){
        throw(std::logic_error("UnitsConversionHelper::initialize Should not be able to call this function when workpsace is undefined"));
    }
    API::NumericAxis *pAxis = dynamic_cast<API::NumericAxis *>(inWS2D->getAxis(0));
    if(!pAxis){
        std::string ERR = "can not retrieve numeric X axis from the input workspace: "+inWS2D->name();
        throw(std::invalid_argument(ERR));
   }
   pSourceWSUnit =   inWS2D->getAxis(0)->unit();
   if(!pSourceWSUnit){
        throw(std::logic_error(" can not retrieve source workspace units from the source workspace's numeric axis"));
   }
   // Check how input workspace units relate to the units requested
   UnitCnvrsn = analyzeUnitsConversion(pSourceWSUnit->unitID(),units_to);


   // get units class, requested by ChildAlgorithm
   pTargetUnit = Kernel::UnitFactory::Instance().create(units_to);
   if(!pTargetUnit){
         throw(std::logic_error(" can not retrieve target unit from the units factory"));
   }

   // get detectors positions and other data needed for units conversion:
    pTwoTheta =  &(TWSD.getDetectors()->getTwoTheta());      
    pL2       =  &(TWSD.getDetectors()->getL2());

    L1        =  TWSD.getDetectors()->getL1();
   // get efix
    efix      =  TWSD.getEi();
    emode     =  (int)TWSD.getEMode();

}