Skip to content

Commit

Permalink
refs #8095 Unit tests fixed
Browse files Browse the repository at this point in the history
and hopefully correct
  • Loading branch information
abuts committed Oct 10, 2013
1 parent b5a40a1 commit 8dab6c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
Expand Up @@ -223,6 +223,9 @@ class AvrgDetector
void addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D &Observer);
void returnAvrgDetPar(DetParameters &det);

void setUseSpherical(bool shouldWe=true)
{m_useSphericalSizes = shouldWe;}

};


Expand Down
34 changes: 19 additions & 15 deletions Code/Mantid/Framework/DataHandling/src/FindDetectorsPar.cpp
Expand Up @@ -176,8 +176,6 @@ FindDetectorsPar::exec()


}
// Constant for converting Radians to Degrees
const double rad2deg = 180.0 / M_PI;

// functions defines the ouptput table with parameters
void FindDetectorsPar::setOutputTable()
Expand Down Expand Up @@ -217,6 +215,9 @@ void FindDetectorsPar::setOutputTable()

}

// Constant for converting Radians to Degrees
const double rad2deg = 180.0 / M_PI;

/// method to cacluate the detectors parameters and add them to the average detector
void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const Kernel::V3D &Observer)
{
Expand All @@ -242,19 +243,22 @@ void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const
Kernel::V3D er(0,1,0),e_th,ez(0,0,1); //ez along beamline, which is always oz; (can be amended)
if(dist2Det)er = toDet/dist2Det; // direction to the detector
Kernel::V3D e_tg = er.cross_prod(ez); // tangential to the ring and anticloakwise;
e_tg.normalize();
// make orthogonal
ez = e_tg.cross_prod(er);

coord[0]=er;
coord[1]=ez;
coord[2]=e_tg ;
coord[0]=er; // new X
coord[1]=ez; // new y
coord[2]=e_tg ; // new z
bbox.setBoxAlignment(ringCentre,coord);

spDet->getBoundingBox(bbox);

// linear extensions of the bounding box orientied tangentially to the equal scattering angle circle
double azimMin = bbox.xMin();
double azimMax = bbox.xMax();
double polarMin = bbox.zMin(); // bounding box has been rotated according to coord above, so z is along e_tg
double polarMax = bbox.zMax();
double azimMin = bbox.zMin();
double azimMax = bbox.zMax();
double polarMin = bbox.yMin(); // bounding box has been rotated according to coord above, so z is along e_tg
double polarMax = bbox.yMax();


if (m_useSphericalSizes)
Expand All @@ -263,12 +267,12 @@ void AvrgDetector::addDetInfo(const Geometry::IDetector_const_sptr &spDet,const

// convert to angular units
double polarHalfSize = rad2deg*atan2(0.5*(polarMax-polarMin), dist2Det);
double azimHalfSize = rad2deg*atan2(0.5*(polarMax-azimMax), dist2Det);
double azimHalfSize = rad2deg*atan2(0.5*(azimMax-azimMin), dist2Det);

double polarMin = Polar -polarHalfSize;
double polarMax = Polar +polarHalfSize;
double azimMin = Azimut -azimHalfSize;
double azimMax = Azimut +azimHalfSize;
polarMin = Polar -polarHalfSize;
polarMax = Polar +polarHalfSize;
azimMin = Azimut -azimHalfSize;
azimMax = Azimut +azimHalfSize;

}
if (m_AzimMin>azimMin)m_AzimMin=azimMin;
Expand Down Expand Up @@ -304,7 +308,7 @@ void FindDetectorsPar::calcDetPar(const Geometry::IDetector_const_sptr &spDet,co
// define summator
AvrgDetector detSum;
// do we want spherical or linear box sizes?
detSum.m_useSphericalSizes = !m_SizesAreLinear;
detSum.setUseSpherical(!m_SizesAreLinear);

if( nDetectors == 1)
{
Expand Down
21 changes: 11 additions & 10 deletions Code/Mantid/Framework/DataHandling/test/FindDetectorsParTest.h
Expand Up @@ -97,8 +97,8 @@ class FindDetectorsParTest : public CxxTest::TestSuite
pattern[2] = "1,2,3,"; // dist
pattern[0] = "2,3,4,"; // azimutal
pattern[1] = "-3,-4,-5,"; //polar
pattern[3] = "75.9638,68.1986,63.4349,"; // atan(4,5,6)/dist; // az_width
pattern[4] = "78.6901,71.5651,66.8014,"; // atan(5,6,7)/dist; // pol_width
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
for(int i=0;i<5;i++){
std::stringstream buf;
for(int j=0;j<3;j++){
Expand Down Expand Up @@ -147,11 +147,11 @@ class FindDetectorsParTest : public CxxTest::TestSuite
Mantid::DataObjects::TableWorkspace_sptr spResult =
AnalysisDataService::Instance().retrieveWS<Mantid::DataObjects::TableWorkspace>("DET_PAR2");

TSM_ASSERT_DELTA("polar wrong ", 37.0858, spResult->cell<double>(0,0),1.e-3);
TSM_ASSERT_DELTA("azimut wrong", 0, spResult->cell<double>(0,1),1.e-3);
TSM_ASSERT_DELTA("flight path wrong ",7.52685, spResult->cell<double>(0,2),1.e-3);
TSM_ASSERT_DELTA("polar width wrong ",23.2429, spResult->cell<double>(0,3),1.e-3); // despite looking strange, this may have cence as detectors overlap; wander what MAPS will be
TSM_ASSERT_DELTA("azim width wrong ", 875.7862, spResult->cell<double>(0,4),1.e-3);
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("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);

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

Expand Down Expand Up @@ -499,8 +499,8 @@ class FindDetectorsParTest : public CxxTest::TestSuite
std::string azim_pattern("0,0,0,");
std::string pol_pattern("170.565,169.565,168.565,");
std::string sfp_pattern("1,1,1,");
std::string polw_pattern("0.804071,0.804258,0.804442,");
std::string azw_pattern("5.72472,5.72472,5.72472,");
std::string polw_pattern("0.792313,0.789995,0.787437,");


std::auto_ptr<std::stringstream> bufs[5];
Expand All @@ -513,8 +513,9 @@ class FindDetectorsParTest : public CxxTest::TestSuite
TSM_ASSERT_EQUALS("azimut wrong",pol_pattern,bufs[0]->str());
TSM_ASSERT_EQUALS("polar wrong ",azim_pattern,bufs[1]->str());
TSM_ASSERT_EQUALS("flight path wrong ",sfp_pattern,bufs[2]->str());
TSM_ASSERT_EQUALS("azim width wrong ",polw_pattern,bufs[3]->str());
TSM_ASSERT_EQUALS("polar width wrong ",azw_pattern,bufs[4]->str());
TSM_ASSERT_EQUALS("polar width wrong ",polw_pattern,bufs[3]->str());
TSM_ASSERT_EQUALS("azimuthal width wrong ",azw_pattern,bufs[4]->str());

}
};
#endif

0 comments on commit 8dab6c2

Please sign in to comment.