Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/8488_horace_ne_manitd'
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiSavici committed Jan 15, 2014
2 parents 0c06ef5 + 185eaef commit 3508842
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 17 deletions.
Expand Up @@ -209,23 +209,26 @@ 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;
/// numbr of primary detectors, contributing into this detector
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);
};


Expand Down
65 changes: 52 additions & 13 deletions Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -428,11 +466,11 @@ size_t FindDetectorsPar::loadParFile(const std::string &fileName){
secondaryFlightpath.resize(m_nDetectors,std::numeric_limits<double>::quiet_NaN());

for(size_t i=0;i<m_nDetectors;i++){
azimuthal[i] =result[shift+2+i*Block_size];
polar[i] =result[shift+1+i*Block_size];
azimuthalWidth[i] =result[shift+3+i*Block_size];
polarWidth[i] =result[shift+4+i*Block_size];
secondaryFlightpath[i] =result[shift+0+i*Block_size];
azimuthal[i] = result[shift+2+i*Block_size];
polar[i] = result[shift+1+i*Block_size];
azimuthalWidth[i] =-result[shift+3+i*Block_size];
polarWidth[i] = result[shift+4+i*Block_size];
secondaryFlightpath[i] = result[shift+0+i*Block_size];
detID[i] = i+1;
}

Expand Down Expand Up @@ -608,6 +646,7 @@ FindDetectorsPar::get_ASCII_header(std::string const &fileName, std::ifstream &d
int space_to_symbol_change=count_changes(&BUF[0],BUF.size());
if(space_to_symbol_change>1){ // 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;
Expand Down
Expand Up @@ -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++){
Expand Down Expand Up @@ -148,10 +148,10 @@ class FindDetectorsParTest : public CxxTest::TestSuite
AnalysisDataService::Instance().retrieveWS<Mantid::DataObjects::TableWorkspace>("DET_PAR2");

TSM_ASSERT_DELTA("polar wrong ", 37.0451, spResult->cell<double>(0,0),1.e-3);
TSM_ASSERT_DELTA("azimut wrong: some average angle -> 0 for many detectors", 8.1818, spResult->cell<double>(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<double>(0,1),1.e-3);
TSM_ASSERT_DELTA("flight path wrong ",7.5248, spResult->cell<double>(0,2),1.e-3);
TSM_ASSERT_DELTA("polar width wrong ",20.0598, spResult->cell<double>(0,3),1.e-3);
TSM_ASSERT_DELTA("azim width wrong ring of ~365deg", 354.6336, spResult->cell<double>(0,4),1.e-3);
TSM_ASSERT_DELTA("azim width wrong ring of ~360deg",364.8752, spResult->cell<double>(0,4),1.e-3);

AnalysisDataService::Instance().remove("DET_PAR2");

Expand Down

0 comments on commit 3508842

Please sign in to comment.