diff --git a/Framework/Algorithms/src/GetAllEi.cpp b/Framework/Algorithms/src/GetAllEi.cpp index 8febbe220215c9a8423b419126f08c761eaf3abf..814986e46c5131c70bca69923e27918cbcc02317 100644 --- a/Framework/Algorithms/src/GetAllEi.cpp +++ b/Framework/Algorithms/src/GetAllEi.cpp @@ -460,9 +460,9 @@ bool GetAllEi::peakGuess(const API::MatrixWorkspace_sptr &inputWS, size_t index, if (std::fabs(double(ind_max - ind_min)) < 5) return false; - //double xMin = X[ind_min]; - //double xMax = X[ind_max]; - //size_t ind_Ofmax(ind_min); + // double xMin = X[ind_min]; + // double xMax = X[ind_max]; + // size_t ind_Ofmax(ind_min); for (size_t i = ind_min; i < ind_max; i++) { double dX = X[i + 1] - X[i]; @@ -473,7 +473,7 @@ bool GetAllEi::peakGuess(const API::MatrixWorkspace_sptr &inputWS, size_t index, sMax = signal; dXmax = dX; xOfMax = X[i]; - //ind_Ofmax=i; + // ind_Ofmax=i; } Intensity += S[i]; } @@ -653,7 +653,7 @@ bool signChanged(double val, int &prevSign) { /**Bare-bone function to calculate numerical derivative, and estimate number of * zeros this derivative has. The function is assumed to be defined on the * the left of a bin range so the derivative is calculated in the same point. -* No checks are performed for simplicity so data have to be correct +* No checks are performed for simplicity so data have to be correct * form at input. *@param bins -- vector of bin boundaries. *@param signal -- vector of signal size of bins.size()-1 @@ -685,15 +685,14 @@ size_t GetAllEi::calcDerivativeAndCountZeros(const std::vector<double> &bins, for (size_t i = 1; i < nPoints - 1; i++) { bin1 = (bins[i + 2] - bins[i + 1]); f1 = signal[i + 1] / bin1; - deriv[i] =(f1 - f0) / (bins[i + 2] - bins[i]); + deriv[i] = (f1 - f0) / (bins[i + 2] - bins[i]); f0 = funVal.back(); funVal.pop_back(); funVal.push_front(f1); - if (signChanged(deriv[i], prevSign)) { nZeros++; - zeros.push_back(0.5*(bins[i-1]+bins[i])); + zeros.push_back(0.5 * (bins[i - 1] + bins[i])); } } deriv[nPoints - 1] = 2 * (f1 - f0) / (bin1 + bin0); @@ -996,40 +995,40 @@ GetAllEi::getAvrgLogValue(const API::MatrixWorkspace_sptr &inputWS, } namespace { // former lambda function for findChopSpeedAndDelay - /**Select time interval on the basis of previous time interval - * selection and check if current value gets in the selection - * - * @param t_beg -- initial time for current time interval - * @param t_end -- final time for current time interval - * @param inSelection -- the boolean indicating if previous interval - * was selected on input and current selected on - * output - * @param startTime -- total selection time start moment - * @param endTime -- total selection time final moments - * - *@return true if selection interval is completed - * (current interval is not selected) and false otherwise - */ - bool SelectInterval(const Kernel::DateAndTime &t_beg, - const Kernel::DateAndTime &t_end, - double value, bool &inSelection, - Kernel::DateAndTime &startTime, Kernel::DateAndTime &endTime){ - - if (value > 0) { - if (!inSelection) { - startTime = t_beg; - } - inSelection = true; - } else { - if (inSelection) { - inSelection = false; - if (endTime > startTime) - return true; - } - } - endTime = t_end; - return false; - }; +/**Select time interval on the basis of previous time interval +* selection and check if current value gets in the selection +* +* @param t_beg -- initial time for current time interval +* @param t_end -- final time for current time interval +* @param inSelection -- the boolean indicating if previous interval +* was selected on input and current selected on +* output +* @param startTime -- total selection time start moment +* @param endTime -- total selection time final moments +* +*@return true if selection interval is completed +* (current interval is not selected) and false otherwise +*/ +bool SelectInterval(const Kernel::DateAndTime &t_beg, + const Kernel::DateAndTime &t_end, double value, + bool &inSelection, Kernel::DateAndTime &startTime, + Kernel::DateAndTime &endTime) { + + if (value > 0) { + if (!inSelection) { + startTime = t_beg; + } + inSelection = true; + } else { + if (inSelection) { + inSelection = false; + if (endTime > startTime) + return true; + } + } + endTime = t_end; + return false; +}; } /**Analyze chopper logs and identify chopper speed and delay @param inputWS -- sp to workspace with attached logs. @@ -1065,8 +1064,8 @@ void GetAllEi::findChopSpeedAndDelay(const API::MatrixWorkspace_sptr &inputWS, // initialize selection log if (dateAndTimes.size() <= 1) { - SelectInterval(it->first, it->first, itder->second, - inSelection,startTime,endTime); + SelectInterval(it->first, it->first, itder->second, inSelection, + startTime, endTime); if (inSelection) { startTime = inputWS->run().startTime(); endTime = inputWS->run().endTime(); @@ -1076,16 +1075,16 @@ void GetAllEi::findChopSpeedAndDelay(const API::MatrixWorkspace_sptr &inputWS, throw std::runtime_error("filtered all data points. Nothing to do"); } } else { - SelectInterval(it->first, next->first, itder->second, - inSelection,startTime,endTime); + SelectInterval(it->first, next->first, itder->second, inSelection, + startTime, endTime); } // if its filtered using log, both iterator walk through the same values // if use derivative, derivative's values are used for filtering // and derivative assumed in a center of an interval for (; next != dateAndTimes.end(); ++next, ++itder) { - if (SelectInterval(it->first, next->first, itder->second, - inSelection,startTime,endTime)) { + if (SelectInterval(it->first, next->first, itder->second, inSelection, + startTime, endTime)) { Kernel::SplittingInterval interval(startTime, endTime, 0); splitter.push_back(interval); } @@ -1113,7 +1112,9 @@ void GetAllEi::findChopSpeedAndDelay(const API::MatrixWorkspace_sptr &inputWS, "during the algorithm execution"); std::string units = pProperty->units(); // its chopper phase provided - if (units == "deg" || units.c_str()[0] == -80) { //<- userd in ISIS ASCII representation of o(deg) + if (units == "deg" || + units.c_str()[0] == + -80) { //<- userd in ISIS ASCII representation of o(deg) chop_delay *= 1.e+6 / (360. * chop_speed); // convert in uSec } chop_delay += m_phase / chop_speed; diff --git a/Framework/Algorithms/test/GetAllEiTest.h b/Framework/Algorithms/test/GetAllEiTest.h index ad83816931dc3fb198e6b5dd2aa0a3ebe8d0350f..bc185dab7173a5b129edf8ce8ab9743df75c990b 100644 --- a/Framework/Algorithms/test/GetAllEiTest.h +++ b/Framework/Algorithms/test/GetAllEiTest.h @@ -470,23 +470,27 @@ public: TS_ASSERT_THROWS_NOTHING(m_getAllEi.execute()); API::MatrixWorkspace_sptr out_ws; - TS_ASSERT_THROWS_NOTHING(out_ws = API::AnalysisDataService::Instance().retrieveWS<API::MatrixWorkspace>("allEiWs")); + TS_ASSERT_THROWS_NOTHING( + out_ws = API::AnalysisDataService::Instance() + .retrieveWS<API::MatrixWorkspace>("allEiWs")); - TSM_ASSERT("Should be able to retrieve workspace",out_ws); + TSM_ASSERT("Should be able to retrieve workspace", out_ws); auto wso = dynamic_cast<DataObjects::Workspace2D *>(out_ws.get()); TS_ASSERT(wso); - if(!wso) return; + if (!wso) + return; auto &x = wso->dataX(0); - TSM_ASSERT_EQUALS("Second peak should be filtered by monitor ranges",x.size(),1); - TS_ASSERT_DELTA(x[0],134.316,1.e-3) + TSM_ASSERT_EQUALS("Second peak should be filtered by monitor ranges", + x.size(), 1); + TS_ASSERT_DELTA(x[0], 134.316, 1.e-3) } private: GetAllEiTester m_getAllEi; DataObjects::Workspace2D_sptr createTestingWS(bool noLogs = false) { - double delay(2000), chopSpeed(100),inital_chop_phase(-3000); + double delay(2000), chopSpeed(100), inital_chop_phase(-3000); auto ws = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument( 2, 1000, true); auto pInstrument = ws->getInstrument(); @@ -498,8 +502,8 @@ private: "The initial rotation phase of the disk used to calculate the time" " for neutrons arriving at the chopper according to the formula time = " "delay + initial_phase/Speed"); - paramMap.add<double>("double", chopper.get(), "initial_phase", inital_chop_phase, - &description); + paramMap.add<double>("double", chopper.get(), "initial_phase", + inital_chop_phase, &description); paramMap.add<std::string>("string", chopper.get(), "ChopperDelayLog", "fermi_delay"); paramMap.add<std::string>("string", chopper.get(), "ChopperSpeedLog", @@ -512,46 +516,46 @@ private: auto moderator = pInstrument->getSource(); auto detector1 = ws->getDetector(0); auto detector2 = ws->getDetector(1); - double l_chop = chopper->getDistance(*moderator); - double l_mon1 = detector1->getDistance(*moderator); - double l_mon2 = detector2->getDistance(*moderator); + double l_chop = chopper->getDistance(*moderator); + double l_mon1 = detector1->getDistance(*moderator); + double l_mon2 = detector2->getDistance(*moderator); //,l_mon1(20-9),l_mon2(20-2); - double t_chop(delay+inital_chop_phase/chopSpeed); + double t_chop(delay + inital_chop_phase / chopSpeed); double Period = - (0.5 * 1.e+6) / chopSpeed; // 0.5 because some choppers open twice. + (0.5 * 1.e+6) / chopSpeed; // 0.5 because some choppers open twice. auto &x = ws->dataX(0); - for(size_t i=0;i<x.size();i++){ - x[i]=5+double(i)*10; + for (size_t i = 0; i < x.size(); i++) { + x[i] = 5 + double(i) * 10; } // signal at first monitor - double t1=t_chop*l_mon1/l_chop; - double t2=(t_chop+Period)*l_mon1/l_chop; + double t1 = t_chop * l_mon1 / l_chop; + double t2 = (t_chop + Period) * l_mon1 / l_chop; { auto &y = ws->dataY(0); for (size_t i = 0; i < y.size(); i++) { - double t=0.5*(x[i]+x[i+1]); - double tm1=t-t1; - double tm2=t-t2; - y[i] = (10000*std::exp(-tm1*tm1/1000.)+20000*std::exp(-tm2*tm2/1000.)); - //std::cout<<"t="<<t<<" signal="<<y[i]<<" ind="<<i<<std::endl; + double t = 0.5 * (x[i] + x[i + 1]); + double tm1 = t - t1; + double tm2 = t - t2; + y[i] = (10000 * std::exp(-tm1 * tm1 / 1000.) + + 20000 * std::exp(-tm2 * tm2 / 1000.)); + // std::cout<<"t="<<t<<" signal="<<y[i]<<" ind="<<i<<std::endl; } } // signal at second monitor - t1=t_chop*l_mon2/l_chop; - t2=(t_chop+Period)*l_mon2/l_chop; + t1 = t_chop * l_mon2 / l_chop; + t2 = (t_chop + Period) * l_mon2 / l_chop; { auto &y = ws->dataY(1); for (size_t i = 0; i < y.size(); i++) { - double t=0.5*(x[i]+x[i+1]); - double tm1=t-t1; - double tm2=t-t2; - y[i] = (100*std::exp(-tm1*tm1/1000.)+200*std::exp(-tm2*tm2/1000.)); - //std::cout<<"t="<<t<<" signal="<<y[i]<<" ind="<<i<<std::endl; + double t = 0.5 * (x[i] + x[i + 1]); + double tm1 = t - t1; + double tm2 = t - t2; + y[i] = (100 * std::exp(-tm1 * tm1 / 1000.) + + 200 * std::exp(-tm2 * tm2 / 1000.)); + // std::cout<<"t="<<t<<" signal="<<y[i]<<" ind="<<i<<std::endl; } } - - if (noLogs) return ws; diff --git a/Framework/Kernel/src/VectorHelper.cpp b/Framework/Kernel/src/VectorHelper.cpp index f78d40d449cc3c80b345ce6bf5d10f913d45df8e..02ed7bcd6f0f7f54b1aea402b9bf5fb09fe978d5 100644 --- a/Framework/Kernel/src/VectorHelper.cpp +++ b/Framework/Kernel/src/VectorHelper.cpp @@ -534,8 +534,9 @@ void linearlyInterpolateY(const std::vector<double> &x, std::vector<double> &y, } } namespace { -/** internal function converted from Lambda to identify interval around specified -* point and run average around this point +/** internal function converted from Lambda to identify interval around +*specified +* point and run average around this point *@param index -- index to average around *@param startIndex -- index in the array of data (input to start average * from) should be: index>=startIndex>=0 @@ -558,7 +559,7 @@ double runAverage(size_t index, size_t startIndex, size_t endIndex, // between start and end bin and shift of // the interpolating function into the center // of each bin - //bin0 = binBndrs->operator[](index + 1) - binBndrs->operator[](index); + // bin0 = binBndrs->operator[](index + 1) - binBndrs->operator[](index); double binC = 0.5 * (binBndrs->operator[](index + 1) + binBndrs->operator[](index)); start = binC - halfWidth; @@ -589,10 +590,10 @@ double runAverage(size_t index, size_t startIndex, size_t endIndex, if (iEnd > endIndex) iEnd = endIndex; } - if(iStart>iEnd){ // start and end get into the same bin - weight1 =0; - weight0 = (end-start) / - (binBndrs->operator[](iStart) - binBndrs->operator[](iStart-1)); + if (iStart > iEnd) { // start and end get into the same bin + weight1 = 0; + weight0 = (end - start) / + (binBndrs->operator[](iStart)-binBndrs->operator[](iStart - 1)); } double avrg = 0; @@ -607,7 +608,7 @@ double runAverage(size_t index, size_t startIndex, size_t endIndex, if (iEnd != endIndex) avrg += input[iEnd] * weight1; - return avrg/(end - start); + return avrg / (end - start); } else { return avrg / double(ic); } @@ -638,7 +639,7 @@ double runAverage(size_t index, size_t startIndex, size_t endIndex, * bin boundaries for output array. */ void smoothInRange(const std::vector<double> &input, - std::vector<double> &output,const double avrgInterval, + std::vector<double> &output, const double avrgInterval, std::vector<double> const *const binBndrs, size_t startIndex, size_t endIndex, std::vector<double> *const outBins) { @@ -676,13 +677,14 @@ void smoothInRange(const std::vector<double> &input, outBins->resize(length + 1); // Run averaging - double binSize = 1; + double binSize = 1; for (size_t i = startIndex; i < endIndex; i++) { if (binBndrs) { - binSize = binBndrs->operator[](i+1) - binBndrs->operator[](i); + binSize = binBndrs->operator[](i + 1) - binBndrs->operator[](i); } output[i - startIndex] = - runAverage(i, startIndex, endIndex, halfWidth, input, binBndrs) * binSize; + runAverage(i, startIndex, endIndex, halfWidth, input, binBndrs) * + binSize; if (outBins) { outBins->operator[](i - startIndex) = binBndrs->operator[](i); } diff --git a/Framework/Kernel/test/VectorHelperTest.h b/Framework/Kernel/test/VectorHelperTest.h index 22ab58331de5d35186691b0f742d6feacddfcbf0..36ac636a8f3644be183ca269644490a15f7f741e 100644 --- a/Framework/Kernel/test/VectorHelperTest.h +++ b/Framework/Kernel/test/VectorHelperTest.h @@ -340,8 +340,8 @@ public: iRight = inputData[indOfMax + 1] / (inputBoundaries[indOfMax + 2] - inputBoundaries[indOfMax + 1]); - TS_ASSERT(iLeft<fMax); - TS_ASSERT(iRight<fMax); + TS_ASSERT(iLeft < fMax); + TS_ASSERT(iRight < fMax); output.swap(inputData); VectorHelper::smoothInRange(inputData, output, 10, &inputBoundaries); @@ -367,7 +367,7 @@ public: (inputBoundaries[indOfMax + 2] - inputBoundaries[indOfMax + 1]); // TS_ASSERT(iLeft<fMax); - TS_ASSERT(iRight<fMax); + TS_ASSERT(iRight < fMax); output.swap(inputData); VectorHelper::smoothInRange(inputData, output, 10, &inputBoundaries);