From 7f383a38855b625350b43b87d8d72ad39d983134 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Sat, 5 Apr 2014 19:14:56 +0000 Subject: [PATCH] - test for surface class --- DDTest/CMakeLists.txt | 7 ++ DDTest/src/test_surface.cc | 133 +++++++++++++++++++++++++++++++++++++ DDTest/units.xml | 18 +++-- 3 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 DDTest/src/test_surface.cc diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index b0e08f5c4..2bc60f0d4 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -27,6 +27,13 @@ ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) +SET( test_name "test_surface" ) +ADD_EXECUTABLE( ${test_name} ./src/${test_name}.cc ) +ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test.sh" + ${EXECUTABLE_OUTPUT_PATH}/${test_name} ${CMAKE_CURRENT_SOURCE_DIR}/units.xml ) +SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "TEST_PASSED" ) +SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST_FAILED" ) + #-------------------------------------------------- diff --git a/DDTest/src/test_surface.cc b/DDTest/src/test_surface.cc new file mode 100644 index 000000000..78c6e14f1 --- /dev/null +++ b/DDTest/src/test_surface.cc @@ -0,0 +1,133 @@ +#include "DD4hep/DDTest.h" + +#include "DD4hep/LCDD.h" +//#include "DD4hep/TGeoUnits.h" +#include "DD4hep/Surface.h" +#include "DD4hep/Volumes.h" +#include "DD4hep/Detector.h" + +#include <exception> +#include <iostream> +#include <sstream> +#include <assert.h> +#include <cmath> + +using namespace std ; +using namespace DD4hep ; +using namespace Geometry; +//using namespace tgeo ; + +// this should be the first line in your test +DDTest test = DDTest( "surface" ) ; + +//============================================================================= +/** Helper class for floating point comparisons using string representations */ +class STR { + STR() {} + float _val ; + std::string _str ; +public: + STR ( float val ) : _val( val ){ + std::stringstream s1 ; + s1 << _val ; + _str = s1.str() ; + } + std::string str() const { return _str ; } + + bool operator==( const STR& s2) const { + return this->str() == s2.str() ; + } +}; + +std::ostream& operator<<(std::ostream& os , const STR& s) { + os << s.str() ; + return os ; +} +//============================================================================= + +int main(int argc, char** argv ){ + + test.log( "test units" ); + + if( argc < 2 ) { + std::cout << " usage: test_surface units.xml " << std::endl ; + exit(1) ; + } + + try{ + + // ----- write your tests in here ------------------------------------- + + LCDD& lcdd = LCDD::getInstance(); + + lcdd.fromCompact( argv[1] ); + + // + double thick = 0.005 ; + double width = 1.0 ; + double length = 10.0 ; + + Material mat = lcdd.material( "Silicon" ); + Box box ( thick/2., width/2., length/2. ); + Volume vol ( "test_box", box, mat); + + Surface::Vector3D u( 0. , 1. , 0. ) ; + Surface::Vector3D v( 0. , 0. , 1. ) ; + Surface::Vector3D n( 1. , 0. , 0. ) ; + Surface::Vector3D o( 0. , 0. , 0. ) ; + + + Surface surf( vol , Surface::Plane, true, thick/2, thick/2 , u,v,n,o ) ; + + + test( surf.isInsideBounds( Surface::Vector3D( 0. , 23. , 42. ) ) , false , " isInsideBounds Vector3D( 0. , 23. , 42. ) " ) ; + + test( surf.isInsideBounds( Surface::Vector3D( 0, .23 , .42 ) ) , true , " isInsideBounds Vector3D( 0, .23 , .42 ) " ) ; + + test( surf.isInsideBounds( Surface::Vector3D( 0.00003 , .23 , .42 ) ) , true , " isInsideBounds Vector3D( 0.00003 , .23 , .42 ) " ) ; + + + // -------------------------------------------------------------------- + + + thick = 1.0 ; + length = 100.0 ; + double radius = 42.0 ; + + mat = lcdd.material( "Air" ); + Tube tube ( radius - thick/2., radius + thick/2. , length/2. ); + vol = Volume( "test_tube", tube , mat); + + Surface::Vector3D o_radius = Surface::Vector3D( radius , 0. , 0. ) ; + + Surface surfT( vol , Surface::Cylinder , true, thick/2, thick/2 , u,v,n, o_radius ) ; + + test( surfT.isInsideBounds( Surface::Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 49. )) , true + , " isInsideBounds Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 49. ) " ) ; + + test( surfT.isInsideBounds( Surface::Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 50.01 )) , false + , " isInsideBounds Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 50.01 ) " ) ; + + test( surfT.isInsideBounds( Surface::Vector3D( (radius+0.001) * sin(0.75) , (radius+0.001) * cos( 0.75 ) , 49. )) , false + , " isInsideBounds Vector3D( (radius+0.001) * sin(0.75) , (radius+0.001) * cos( 0.75 ) , 49. ) " ) ; + + + test( surfT.isInsideBounds( Surface::Vector3D( (radius+0.00005) * sin(0.75) , (radius+0.00005) * cos( 0.75 ) , 49. )) , true + , " isInsideBounds Vector3D( (radius+0.00005) * sin(0.75) , (radius+0.00005) * cos( 0.75 ) , 49. ) " ) ; + + + + // -------------------------------------------------------------------- + + + } catch( exception &e ){ + //} catch( ... ){ + + test.log( e.what() ); + test.error( "exception occurred" ); + } + + return 0; +} + +//============================================================================= diff --git a/DDTest/units.xml b/DDTest/units.xml index 9d90bf17a..1d4b1121e 100644 --- a/DDTest/units.xml +++ b/DDTest/units.xml @@ -35,15 +35,21 @@ <!-- need to define vacuum and air --> <materials> <material name="Vacuum"> - <D type="density" unit="g/cm3" value="0.00000001" /> - <fraction n="1" ref="H" /> + <D type="density" unit="g/cm3" value="0.00000001" /> + <fraction n="1" ref="H" /> </material> <material name="Air"> - <D type="density" unit="g/cm3" value="0.0012"/> - <fraction n="0.754" ref="N"/> - <fraction n="0.234" ref="O"/> - <fraction n="0.012" ref="Ar"/> + <D type="density" unit="g/cm3" value="0.0012"/> + <fraction n="0.754" ref="N"/> + <fraction n="0.234" ref="O"/> + <fraction n="0.012" ref="Ar"/> </material> + <material formula="Si" name="Silicon" state="solid" > + <RL type="X0" unit="cm" value="9.36607" /> + <NIL type="lambda" unit="cm" value="45.7531" /> + <D type="density" unit="g/cm3" value="2.33" /> + <composite n="1" ref="Si" /> + </material> </materials> </lccdd> -- GitLab