From dca8370093380ce4143a243333c612605f069af7 Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Sun, 6 Apr 2014 17:21:22 +0000 Subject: [PATCH] - added a few tests to test_surface - fixed some issues in Surface classes --- DDRec/include/DDRec/Surface.h | 16 ++++--- DDRec/src/Surface.cpp | 8 ++-- DDTest/CMakeLists.txt | 13 ++++- DDTest/src/test_surface.cc | 89 ++++++++++++++++++++++++++--------- 4 files changed, 92 insertions(+), 34 deletions(-) diff --git a/DDRec/include/DDRec/Surface.h b/DDRec/include/DDRec/Surface.h index f05ef7948..e29dc4937 100644 --- a/DDRec/include/DDRec/Surface.h +++ b/DDRec/include/DDRec/Surface.h @@ -21,7 +21,7 @@ namespace DD4hep { * @date Apr, 6 2014 * @version $Id:$ */ - struct SurfaceMaterial : public virtual Geometry::Material , IMaterial{ + struct SurfaceMaterial : public virtual Geometry::Material , public IMaterial{ /** Copy c'tor - copies handle */ SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} @@ -90,7 +90,7 @@ namespace DD4hep { * @date Apr, 6 2014 * @version $Id:$ */ - class VolSurface : public Geometry::Handle< SurfaceData > , ISurface { + class VolSurface : public Geometry::Handle< SurfaceData > , public ISurface { protected: @@ -111,7 +111,7 @@ namespace DD4hep { /** properties of the surface encoded in Type. * @see SurfaceType */ - virtual SurfaceType type() const { return object<SurfaceData>()._type ; } + virtual const SurfaceType& type() const { return object<SurfaceData>()._type ; } //==== geometry ==== @@ -199,8 +199,9 @@ namespace DD4hep { VolSurface( vol, type, thickness_inner, thickness_outer, u,v,n,o ) { - type._bits.set( SurfaceType::Cylinder , false ) ; - type._bits.set( SurfaceType::Plane , true ) ; + object<SurfaceData>()._type.setProperty( SurfaceType::Plane , true ) ; + object<SurfaceData>()._type.setProperty( SurfaceType::Cylinder , false ) ; + } /** Distance to surface */ @@ -230,8 +231,9 @@ namespace DD4hep { VolSurface( vol, type, thickness_inner, thickness_outer, u,v,n,o ) { - type._bits.set( SurfaceType::Plane , false ) ; - type._bits.set( SurfaceType::Cylinder , true ) ; + object<SurfaceData>()._type.setProperty( SurfaceType::Plane , false ) ; + object<SurfaceData>()._type.setProperty( SurfaceType::Cylinder , true ) ; + } /** Distance to surface */ diff --git a/DDRec/src/Surface.cpp b/DDRec/src/Surface.cpp index b1e56758e..f222a89b0 100644 --- a/DDRec/src/Surface.cpp +++ b/DDRec/src/Surface.cpp @@ -52,7 +52,7 @@ namespace DD4hep { bool VolPlane::insideBounds(const Vector3D& point, double epsilon) const { -#if 1 +#if 0 double dist = std::abs ( distance( point ) ) ; bool inShape = volume()->GetShape()->Contains( point ) ; @@ -65,7 +65,7 @@ namespace DD4hep { return dist < epsilon && inShape ; #else - return ( std::abs ( distance() ) < epsilon ) && volume()->GetShape()->Contains( point ) ; + return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( point ) ; #endif } @@ -79,7 +79,7 @@ namespace DD4hep { /// Checks if the given point lies within the surface bool VolCylinder::insideBounds(const Vector3D& point, double epsilon) const { -#if 1 +#if 0 double distR = std::abs( distance( point ) ) ; bool inShapeT = volume()->GetShape()->Contains( point ) ; @@ -91,7 +91,7 @@ namespace DD4hep { return distR < epsilon && inShapeT ; #else - return ( std::abs ( distance() ) < epsilon ) && volume()->GetShape()->Contains( point ) ; + return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( point ) ; #endif } diff --git a/DDTest/CMakeLists.txt b/DDTest/CMakeLists.txt index 2bc60f0d4..21e4a03f4 100644 --- a/DDTest/CMakeLists.txt +++ b/DDTest/CMakeLists.txt @@ -4,13 +4,22 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/DDCore/include - ${CMAKE_SOURCE_DIR}/DDG4/include ${CMAKE_SOURCE_DIR}/DDSegmentation/include + ${CMAKE_SOURCE_DIR}/DDSurfaces/include + ${CMAKE_SOURCE_DIR}/DDRec/include ${CMAKE_SOURCE_DIR}/include ${ROOT_INCLUDE_DIR} ) +if(DD4HEP_WITH_GEANT4) + include_directories( ${CMAKE_SOURCE_DIR}/DDG4/include ) +endif() + +if(DD4HEP_WITH_GEANT4) + link_libraries(DD4hepG4 DD4hepCore DD4hepRec DDSegmentation ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) +else() + link_libraries(DD4hepCore DD4hepRec DDSegmentation ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) +endif() -link_libraries(DD4hepG4 DD4hepCore DDSegmentation ${ROOT_LIBRARIES} Reflex ${Geant4_LIBRARIES}) #-------------------------------------------------- #ADD_TEST( t_init source "${CMAKE_CURRENT_WORK_DIR}/thisdd4hep.sh" ) diff --git a/DDTest/src/test_surface.cc b/DDTest/src/test_surface.cc index 78c6e14f1..1085991d7 100644 --- a/DDTest/src/test_surface.cc +++ b/DDTest/src/test_surface.cc @@ -1,11 +1,13 @@ #include "DD4hep/DDTest.h" #include "DD4hep/LCDD.h" -//#include "DD4hep/TGeoUnits.h" -#include "DD4hep/Surface.h" +#include "DD4hep/TGeoUnits.h" #include "DD4hep/Volumes.h" #include "DD4hep/Detector.h" +#include "DDRec/Surface.h" +//#include "DDSurfaces/ISurface.h" + #include <exception> #include <iostream> #include <sstream> @@ -15,6 +17,9 @@ using namespace std ; using namespace DD4hep ; using namespace Geometry; +using namespace DDRec ; +using namespace DDSurfaces ; + //using namespace tgeo ; // this should be the first line in your test @@ -62,7 +67,7 @@ int main(int argc, char** argv ){ lcdd.fromCompact( argv[1] ); - // + // --- test a planar surface double thick = 0.005 ; double width = 1.0 ; double length = 10.0 ; @@ -71,24 +76,54 @@ int main(int argc, char** argv ){ 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. ) ; + Vector3D u( 0. , 1. , 0. ) ; + Vector3D v( 0. , 0. , 1. ) ; + Vector3D n( 1. , 0. , 0. ) ; + Vector3D o( 0. , 0. , 0. ) ; + + + VolPlane surf( vol , SurfaceType( SurfaceType::Sensitive ), thick/2, thick/2 , u,v,n,o ) ; + + // test inside bounds for some points: + + test( surf.insideBounds( Vector3D( 0. , 23. , 42. ) ) , false , " insideBounds Vector3D( 0. , 23. , 42. ) " ) ; + + test( surf.insideBounds( Vector3D( 0, .23 , .42 ) ) , true , " insideBounds Vector3D( 0, .23 , .42 ) " ) ; + + test( surf.insideBounds( Vector3D( 0.00003 , .23 , .42 ) ) , true , " insideBounds Vector3D( 0.00003 , .23 , .42 ) " ) ; + + + // --- test SurfaceMaterial + SurfaceMaterial sm( mat ) ; + + // FIXME: these cause a seg fault .... + + // test( STR( sm.A() ) , STR( 93.4961 ) , " SurfaceMaterial.A() == 93.4961 " ) ; + + // test( STR( sm.Z() ) , STR( 93.4961 ) , " SurfaceMaterial.Z() == 93.4961 " ) ; + + test( STR( sm.radiationLength() / tgeo::mm ) , STR( 93.4961 ) , " SurfaceMaterial.radiationLength() == 93.4961 * mm " ) ; + + test( STR( sm.interactionLength() / tgeo::mm ) , STR( 457.532 ) , " SurfaceMaterial.interactionLength() == 457.532 * mm " ) ; + + + // test surface type: - Surface surf( vol , Surface::Plane, true, thick/2, thick/2 , u,v,n,o ) ; + test( surf.type().isSensitive() , true , " surface is sensitive " ) ; + test( surf.type().isPlane() , true , " surface is Plane " ) ; - test( surf.isInsideBounds( Surface::Vector3D( 0. , 23. , 42. ) ) , false , " isInsideBounds Vector3D( 0. , 23. , 42. ) " ) ; + surf.type().checkParallelToZ( surf ) ; - test( surf.isInsideBounds( Surface::Vector3D( 0, .23 , .42 ) ) , true , " isInsideBounds Vector3D( 0, .23 , .42 ) " ) ; + test( surf.type().isZPlane() , true , " surface is ZPlane " ) ; - test( surf.isInsideBounds( Surface::Vector3D( 0.00003 , .23 , .42 ) ) , true , " isInsideBounds Vector3D( 0.00003 , .23 , .42 ) " ) ; + test( surf.type().isCylinder() , false , " surface is no Cylinder " ) ; // -------------------------------------------------------------------- + // test a cylindrical surface thick = 1.0 ; length = 100.0 ; @@ -98,23 +133,35 @@ int main(int argc, char** argv ){ 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. ) ; + Vector3D o_radius = Vector3D( radius , 0. , 0. ) ; - Surface surfT( vol , Surface::Cylinder , true, thick/2, thick/2 , u,v,n, o_radius ) ; + VolCylinder surfT( vol , SurfaceType( SurfaceType::Sensitive ), thick/2, thick/2 , u,v,n, o_radius ) ; + + test( surfT.insideBounds( Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 49. )) , true + , " insideBounds Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 49. ) " ) ; + + test( surfT.insideBounds( Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 50.01 )) , false + , " insideBounds Vector3D( radius * sin(0.75) , radius * cos( 0.75 ) , 50.01 ) " ) ; + + test( surfT.insideBounds( Vector3D( (radius+0.001) * sin(0.75) , (radius+0.001) * cos( 0.75 ) , 49. )) , false + , " insideBounds Vector3D( (radius+0.001) * sin(0.75) , (radius+0.001) * cos( 0.75 ) , 49. ) " ) ; + + + test( surfT.insideBounds( Vector3D( (radius+0.00005) * sin(0.75) , (radius+0.00005) * cos( 0.75 ) , 49. )) , true + , " insideBounds Vector3D( (radius+0.00005) * sin(0.75) , (radius+0.00005) * cos( 0.75 ) , 49. ) " ) ; + + - 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 surface type: - 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.type().isSensitive() , true , " surface is sensitive " ) ; - 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.type().isPlane() , false , " surface is no Plane " ) ; - 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. ) " ) ; + surfT.type().checkParallelToZ( surfT ) ; + test( surfT.type().isZCylinder() , true , " surface is ZCylinder " ) ; // -------------------------------------------------------------------- -- GitLab