/** Execute the algorithm. */ void ChangeTimeZero::exec() { MatrixWorkspace_sptr in_ws = getProperty("InputWorkspace"); // Create a new target workspace if it does not exist const double progressStartCreateOutputWs = 0.0; const double progressStopCreateOutputWs = 0.3; MatrixWorkspace_sptr out_ws = createOutputWS( in_ws, progressStartCreateOutputWs, progressStopCreateOutputWs); // Get the time shift in seconds auto timeShift = getTimeShift(out_ws); // Set up remaining progress points const double progressStartShiftTimeLogs = progressStopCreateOutputWs; double progressStopShiftTimeLogs = progressStartShiftTimeLogs; if (boost::dynamic_pointer_cast<Mantid::API::IEventWorkspace>(out_ws)) { progressStopShiftTimeLogs = progressStartShiftTimeLogs + 0.1; } else { progressStopShiftTimeLogs = 1.0; } const double progressStartShiftNeutrons = progressStopShiftTimeLogs; const double progressStopShiftNeutrons = 1.0; // Change the time of the logs. // Initialize progress reporting. shiftTimeOfLogs(out_ws, timeShift, progressStartShiftTimeLogs, progressStopShiftTimeLogs); // Change the time stamps on the neutrons shiftTimeOfNeutrons(out_ws, timeShift, progressStartShiftNeutrons, progressStopShiftNeutrons); setProperty("OutputWorkspace", out_ws); }
/** * Executes the algorithm */ void ScaleX::exec() { //Get input workspace and offset const MatrixWorkspace_sptr inputW = getProperty("InputWorkspace"); factor = getProperty("Factor"); API::MatrixWorkspace_sptr outputW = createOutputWS(inputW); //Get number of histograms int histnumber = static_cast<int>(inputW->getNumberHistograms()); m_progress = new API::Progress(this, 0.0, 1.0, histnumber+1); m_progress->report("Scaling X"); wi_min = 0; wi_max = histnumber-1; //check if workspace indexes have been set int tempwi_min = getProperty("IndexMin"); int tempwi_max = getProperty("IndexMax"); if ( tempwi_max != Mantid::EMPTY_INT() ) { if ((wi_min <= tempwi_min) && (tempwi_min <= tempwi_max) && (tempwi_max <= wi_max)) { wi_min = tempwi_min; wi_max = tempwi_max; } else { g_log.error("Invalid Workspace Index min/max properties"); throw std::invalid_argument("Inconsistent properties defined"); } } //Check if its an event workspace EventWorkspace_const_sptr eventWS = boost::dynamic_pointer_cast<const EventWorkspace>(inputW); if (eventWS != NULL) { this->execEvent(); return; } // do the shift in X PARALLEL_FOR2(inputW, outputW) for (int i=0; i < histnumber; ++i) { PARALLEL_START_INTERUPT_REGION //Do the offsetting for (int j=0; j < static_cast<int>(inputW->readX(i).size()); ++j) { //Change bin value by offset if ((i >= wi_min) && (i <= wi_max)) outputW->dataX(i)[j] = inputW->readX(i)[j] * factor; else outputW->dataX(i)[j] = inputW->readX(i)[j]; } //Copy y and e data outputW->dataY(i) = inputW->dataY(i); outputW->dataE(i) = inputW->dataE(i); if( (i >= wi_min) && (i <= wi_max) && factor<0 ) { std::reverse( outputW->dataX(i).begin(), outputW->dataX(i).end() ); std::reverse( outputW->dataY(i).begin(), outputW->dataY(i).end() ); std::reverse( outputW->dataE(i).begin(), outputW->dataE(i).end() ); } m_progress->report("Scaling X"); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION // Copy units if (outputW->getAxis(0)->unit().get()) outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit(); try { if (inputW->getAxis(1)->unit().get()) outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit(); } catch(Exception::IndexError &) { // OK, so this isn't a Workspace2D } // Assign it to the output workspace property setProperty("OutputWorkspace",outputW); }
/** * Executes the algorithm */ void ScaleX::exec() { //Get input workspace and offset const MatrixWorkspace_sptr inputW = getProperty("InputWorkspace"); m_algFactor = getProperty("Factor"); m_parname = getPropertyValue("InstrumentParameter"); m_combine = getProperty("Combine"); if(m_combine && m_parname.empty()) { throw std::invalid_argument("Combine behaviour requested but the InstrumentParameter argument is blank."); } const std::string op = getPropertyValue("Operation"); API::MatrixWorkspace_sptr outputW = createOutputWS(inputW); //Get number of histograms int histnumber = static_cast<int>(inputW->getNumberHistograms()); m_progress = new API::Progress(this, 0.0, 1.0, histnumber+1); m_progress->report("Scaling X"); m_wi_min = 0; m_wi_max = histnumber-1; //check if workspace indexes have been set int tempwi_min = getProperty("IndexMin"); int tempwi_max = getProperty("IndexMax"); if ( tempwi_max != Mantid::EMPTY_INT() ) { if ((m_wi_min <= tempwi_min) && (tempwi_min <= tempwi_max) && (tempwi_max <= m_wi_max)) { m_wi_min = tempwi_min; m_wi_max = tempwi_max; } else { g_log.error("Invalid Workspace Index min/max properties"); throw std::invalid_argument("Inconsistent properties defined"); } } // Setup appropriate binary function const bool multiply = (op=="Multiply"); if(multiply) m_binOp = std::multiplies<double>(); else m_binOp = std::plus<double>(); //Check if its an event workspace EventWorkspace_const_sptr eventWS = boost::dynamic_pointer_cast<const EventWorkspace>(inputW); if (eventWS != NULL) { this->execEvent(); return; } // do the shift in X PARALLEL_FOR2(inputW, outputW) for (int i = 0; i < histnumber; ++i) { PARALLEL_START_INTERUPT_REGION //Copy y and e data auto & outY = outputW->dataY(i); outY = inputW->dataY(i); auto & outE = outputW->dataE(i); outE = inputW->dataE(i); auto & outX = outputW->dataX(i); const auto & inX = inputW->readX(i); //Change bin value by offset if ((i >= m_wi_min) && (i <= m_wi_max)) { double factor = getScaleFactor(inputW, i); // Do the offsetting std::transform(inX.begin(), inX.end(), outX.begin(), std::bind2nd(m_binOp, factor)); // reverse the vector if multiplicative factor was negative if(multiply && factor < 0.0) { std::reverse( outX.begin(), outX.end() ); std::reverse( outY.begin(), outY.end() ); std::reverse( outE.begin(), outE.end() ); } } else { outX = inX; //copy } m_progress->report("Scaling X"); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION // Copy units if (outputW->getAxis(0)->unit().get()) outputW->getAxis(0)->unit() = inputW->getAxis(0)->unit(); try { if (inputW->getAxis(1)->unit().get()) outputW->getAxis(1)->unit() = inputW->getAxis(1)->unit(); } catch(Exception::IndexError &) { // OK, so this isn't a Workspace2D } // Assign it to the output workspace property setProperty("OutputWorkspace",outputW); }