diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h index 1cd90cb81549..057e9564ff78 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h +++ b/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/FindDetectorsPar.h @@ -209,6 +209,7 @@ class AvrgDetector double m_AzimutSum; double m_PolarSum; double m_FlightPathSum; + double m_AzimBase,m_PolarBase; // if azimuthal and polar sizes expressed in angular or linear units bool m_useSphericalSizes; double m_AzimMin,m_PolarMin,m_AzimMax,m_PolarMax; @@ -216,16 +217,18 @@ class AvrgDetector size_t m_nComponents; public: AvrgDetector():m_AzimutSum(0),m_PolarSum(0),m_FlightPathSum(0), + m_AzimBase(0),m_PolarBase(0), m_useSphericalSizes(false), m_AzimMin(FLT_MAX),m_PolarMin(FLT_MAX),m_AzimMax(-FLT_MAX),m_PolarMax(-FLT_MAX), m_nComponents(0) - {} + { } void addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D &Observer); void returnAvrgDetPar(DetParameters &det); void setUseSpherical(bool shouldWe=true) {m_useSphericalSizes = shouldWe;} + static double nearAngle(const double &baseAngle,const double &anAngle); }; diff --git a/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp b/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp index f3df83090b7a..3d5f175ec676 100644 --- a/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp +++ b/Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp @@ -230,6 +230,28 @@ void FindDetectorsPar::setOutputTable() // Constant for converting Radians to Degrees const double rad2deg = 180.0 / M_PI; +/** method calculates an angle closest to the initial one taken on a ring + * e.g. given inital angle 179 deg and another one -179 closest one to 179 is 181 + @param baseAngle -- the angle to be close to + @param anAngle -- the angle which ring image may be requested + + @returns -- the angle closest to the initial on a ring. +*/ +double AvrgDetector::nearAngle(const double &baseAngle,const double &anAngle) +{ + double dist = baseAngle-anAngle; + if (dist>180.) + { + return (anAngle+360.); + } + else if(dist<-180.) + { + return (anAngle - 360.); + } + else + return anAngle; +} + /** method to cacluate the detectors parameters and add them to the detectors averages *@param spDet -- shared pointer to the Mantid Detector *@param Observer -- sample position or the centre of the polar system of coordinates to calculate detector's parameters. @@ -240,12 +262,28 @@ void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D detPos = spDet->getPos(); Kernel::V3D toDet = (detPos - Observer); - double dist2Det,Polar,Azimut; + double dist2Det,Polar,Azimut,ringPolar,ringAzim; // identify the detector' position in the beam coordinate system: toDet.getSpherical(dist2Det,Polar,Azimut); - m_FlightPathSum +=dist2Det; - m_PolarSum +=Polar; - m_AzimutSum +=Azimut; + if(m_nComponents <=1) + { + m_FlightPathSum =dist2Det; + m_PolarSum =Polar; + m_AzimutSum =Azimut; + + m_AzimBase = Polar; + m_PolarBase = Azimut; + ringPolar = Polar; + ringAzim = Azimut; + } + else + { + ringPolar = nearAngle(m_AzimBase,Polar) ; + ringAzim = nearAngle(m_PolarBase,Azimut); + m_FlightPathSum +=dist2Det; + m_PolarSum +=ringPolar; + m_AzimutSum +=ringAzim; + } // centre of the azimuthal ring (the ring detectors form around the beam) @@ -284,10 +322,10 @@ void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const double polarHalfSize = rad2deg*atan2(0.5*(polarMax-polarMin), dist2Det); double azimHalfSize = rad2deg*atan2(0.5*(azimMax-azimMin), dist2Det); - polarMin = Polar -polarHalfSize; - polarMax = Polar +polarHalfSize; - azimMin = Azimut -azimHalfSize; - azimMax = Azimut +azimHalfSize; + polarMin = ringPolar -polarHalfSize; + polarMax = ringPolar +polarHalfSize; + azimMin = ringAzim -azimHalfSize; + azimMax = ringAzim +azimHalfSize; } if (m_AzimMin>azimMin)m_AzimMin=azimMin; @@ -428,11 +466,11 @@ size_t FindDetectorsPar::loadParFile(const std::string &fileName){ secondaryFlightpath.resize(m_nDetectors,std::numeric_limits::quiet_NaN()); for(size_t i=0;i1){ // more then one group of symbols in the string, spe file int nData_records(0),nData_blocks(0); + // cppcheck-suppress invalidscanf int nDatas = sscanf(&BUF[0]," %d %d ",&nData_records,&nData_blocks); file_descriptor.nData_records = (size_t)nData_records; file_descriptor.nData_blocks = (size_t)nData_blocks; diff --git a/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h b/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h index d6192a75332f..37ef9c9d51a3 100644 --- a/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h +++ b/Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h @@ -98,7 +98,7 @@ class FindDetectorsParTest : public CxxTest::TestSuite pattern[0] = "2,3,4,"; // azimutal pattern[1] = "-3,-4,-5,"; //polar pattern[3] = "78.6901,71.5651,66.8014,"; // atan(5,6,7)/dist; // pol_width - pattern[4] = "75.9638,68.1986,63.4349,"; // atan(4,5,6)/dist; // az_width + pattern[4] = "-75.9638,-68.1986,-63.4349,"; // atan(4,5,6)/dist; // az_width for(int i=0;i<5;i++){ std::stringstream buf; for(int j=0;j<3;j++){ @@ -148,10 +148,10 @@ class FindDetectorsParTest : public CxxTest::TestSuite AnalysisDataService::Instance().retrieveWS("DET_PAR2"); TSM_ASSERT_DELTA("polar wrong ", 37.0451, spResult->cell(0,0),1.e-3); - TSM_ASSERT_DELTA("azimut wrong: some average angle -> 0 for many detectors", 8.1818, spResult->cell(0,1),1.e-3); + TSM_ASSERT_DELTA("azimut wrong: some average angle -> around initial detector's angle for many detectors", -114.5454, spResult->cell(0,1),1.e-3); TSM_ASSERT_DELTA("flight path wrong ",7.5248, spResult->cell(0,2),1.e-3); TSM_ASSERT_DELTA("polar width wrong ",20.0598, spResult->cell(0,3),1.e-3); - TSM_ASSERT_DELTA("azim width wrong ring of ~365deg", 354.6336, spResult->cell(0,4),1.e-3); + TSM_ASSERT_DELTA("azim width wrong ring of ~360deg",364.8752, spResult->cell(0,4),1.e-3); AnalysisDataService::Instance().remove("DET_PAR2");