diff --git a/DDRec/include/DDRec/Surface.h b/DDRec/include/DDRec/Surface.h index ed864021f19d9a5052bd962b266779935fb3ceef..96a76febf5857e6f6a686453b8460726619f4a91 100644 --- a/DDRec/include/DDRec/Surface.h +++ b/DDRec/include/DDRec/Surface.h @@ -158,7 +158,7 @@ namespace DD4hep { // need default implementations for putting it in list.... /** Distance to surface */ - virtual double distance(const Vector3D& point ) const { return 0. ; } + virtual double distance(const Vector3D& point ) const { return 1.e99 ; } /// Checks if the given point lies within the surface virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const { return false ; } @@ -217,6 +217,8 @@ namespace DD4hep { public: VolPlane() : VolSurface() { } + + VolPlane(const VolSurface& vs ) : VolSurface( vs ) { } VolPlane( Geometry::Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, Vector3D u ,Vector3D v ,Vector3D n , Vector3D o = Vector3D(0.,0.,0.) ) : @@ -249,6 +251,8 @@ namespace DD4hep { public: VolCylinder() : VolSurface() { } + + VolCylinder(const VolSurface& vs ) : VolSurface( vs ) { } VolCylinder( Geometry::Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, Vector3D u ,Vector3D v ,Vector3D n , Vector3D o = Vector3D(0.,0.,0.) ) : diff --git a/DDRec/src/Surface.cpp b/DDRec/src/Surface.cpp index 3034ecf4492890228fcd9263c24194b02bb7e4f1..ed8ef0550434a8e7bcbe6182e39db86cb27059cf 100644 --- a/DDRec/src/Surface.cpp +++ b/DDRec/src/Surface.cpp @@ -249,8 +249,8 @@ namespace DD4hep { double pa[3] ; _wtM->MasterToLocal( point , pa ) ; Vector3D localPoint( pa ) ; - - return _volSurf.distance( localPoint ) ; + + return ( _volSurf.type().isPlane() ? VolPlane(_volSurf).distance( localPoint ) : VolCylinder(_volSurf).distance( localPoint ) ) ; } bool Surface::insideBounds(const Vector3D& point, double epsilon) const { @@ -259,7 +259,7 @@ namespace DD4hep { _wtM->MasterToLocal( point , pa ) ; Vector3D localPoint( pa ) ; - return _volSurf.insideBounds( localPoint ) ; + return ( _volSurf.type().isPlane() ? VolPlane(_volSurf).insideBounds( localPoint ) : VolCylinder(_volSurf).insideBounds( localPoint ) ) ; } void Surface::initialize() { diff --git a/DDSurfaces/include/DDSurfaces/ISurface.h b/DDSurfaces/include/DDSurfaces/ISurface.h index d9193014f68b9f9370d3db934f206f11d5b3fa04..7f453a8aa92821ab1906407a835aa190c79cc245 100644 --- a/DDSurfaces/include/DDSurfaces/ISurface.h +++ b/DDSurfaces/include/DDSurfaces/ISurface.h @@ -197,7 +197,7 @@ namespace DDSurfaces { /// dump ISurface operator inline std::ostream& operator<<( std::ostream& os , const ISurface& s ) { - os << " id: " << s.id() << " type : " << s.type() << std::endl + os << " id: " << std::hex << s.id() << std::dec << " type : " << s.type() << std::endl << " u : " << s.u() << " v : " << s.v() << " normal : " << s.normal() << " origin : " << s.origin() << std::endl ; os << " inner material : " << s.innerMaterial() << std::endl << " outerMaterial : " << s.outerMaterial() << std::endl ; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e9c0cc3bfb10c23775dfdd2898b4f508de158a19..fa7ade6328a31d7d65bcde151d01649e8dc8572c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -26,11 +26,11 @@ endif(BUILD_TESTING) # add_subdirectory(ILDExDet) -#add_subdirectory(ILDExSimu) +add_subdirectory(ILDExSimu) -#add_subdirectory(CLICSiD) +add_subdirectory(CLICSiD) -#add_subdirectory(noviceN04) +add_subdirectory(noviceN04) #---- does not build on mac or ubuntu ... #add_subdirectory(Segmentation) diff --git a/examples/ILDExDet/CMakeLists.txt b/examples/ILDExDet/CMakeLists.txt index 4e3aa350778b50d51f2ef75eb082251719a38506..1408ecac7b46bfb4eee250535d7bb7c5e173079a 100644 --- a/examples/ILDExDet/CMakeLists.txt +++ b/examples/ILDExDet/CMakeLists.txt @@ -81,12 +81,6 @@ target_link_libraries(${PackageName} ${DD4hep_LIBRARIES} ) -add_executable( test_surfaces src/test_surfaces.cc) - -target_link_libraries(test_surfaces ${PackageName} ${DD4hep_LIBRARIES} - ${ROOT_LIBRARIES} ${ROOT_COMPONENT_LIBRARIES} - ${GEAR_LIBRARIES} - ) #---Rootmap generation-------------------------------------------------------------- diff --git a/examples/ILDExDet/src/test_surfaces.cc b/examples/ILDExDet/src/test_surfaces.cc deleted file mode 100644 index 4a288891b2dbc2043136dc1ec4bc6cc099b15ea3..0000000000000000000000000000000000000000 --- a/examples/ILDExDet/src/test_surfaces.cc +++ /dev/null @@ -1,57 +0,0 @@ -#include "DD4hep/LCDD.h" - -#include "DDRec/Surface.h" -#include "DDRec/DetectorSurfaces.h" -#include "DDRec/SurfaceManager.h" - -// #include "DD4hep/TGeoUnits.h" -// #include "DD4hep/Detector.h" -// #include "DD4hep/Volumes.h" - - -using namespace std ; -using namespace DD4hep ; -using namespace DD4hep::Geometry; -using namespace DD4hep::DDRec ; -using namespace DDSurfaces ; - -//using namespace tgeo ; - -//============================================================================= - -int main(int argc, char** argv ){ - - if( argc < 2 ) { - std::cout << " usage: test_surfaces compact.xml " << std::endl ; - exit(1) ; - } - - std::string inFile = argv[1] ; - - LCDD& lcdd = LCDD::getInstance(); - - lcdd.fromCompact( inFile ); - - - DetElement world = lcdd.world() ; - - - // create a list of all surfaces in the detector: - SurfaceManager surfMan( world ) ; - - const SurfaceList& sL = surfMan.surfaceList() ; - - - for( SurfaceList::const_iterator it = sL.begin() ; it != sL.end() ; ++it ){ - - Surface& surf = **it ; - - std::cout << " ------------------------- " - << " surface: " << surf << std::endl - << " ------------------------- " << std::endl ; - } - - return 0; -} - -//============================================================================= diff --git a/examples/ILDExSimu/CMakeLists.txt b/examples/ILDExSimu/CMakeLists.txt index 7ab346f3c2345dbe408794894190cf50daeaee43..01d8a604f6b898d65f43517c7ac0d043d186513a 100644 --- a/examples/ILDExSimu/CMakeLists.txt +++ b/examples/ILDExSimu/CMakeLists.txt @@ -80,9 +80,8 @@ if(DD4HEP_USE_PYROOT) list(APPEND sources G__ILDEx.cxx) endif() -#add_library(${PackageName} SHARED ${sources}) +add_library(${PackageName} SHARED ${sources}) -add_executable(ILDExSimu ILDExSimu.cpp ${sources}) #MESSAGE( STATUS "********* DD4hep_LIBRARIES : ${DD4hep_LIBRARIES}") @@ -93,6 +92,23 @@ target_link_libraries(${PackageName} ${DD4hep_LIBRARIES} ${LCIO_LIBRARIES} ) +add_executable(ildex_simu ILDExSimu.cpp ) + +target_link_libraries(ildex_simu ${PackageName} ) +# ${DD4hep_LIBRARIES} +# ${ROOT_LIBRARIES} ${ROOT_COMPONENT_LIBRARIES} +# ${GEAR_LIBRARIES} +# ${LCIO_LIBRARIES} +# ) + +add_executable( test_surfaces src/test_surfaces.cc) + +target_link_libraries(test_surfaces ${PackageName} ) +#${DD4hep_LIBRARIES} +# ${ROOT_LIBRARIES} ${ROOT_COMPONENT_LIBRARIES} +# ${GEAR_LIBRARIES} +# ${LCIO_LIBRARIES} +# ) #---Testing------------------------------------------------------------------------- if(BUILD_TESTING) @@ -123,7 +139,7 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/this${PackageName}.sh #--- install target------------------------------------- -install(TARGETS ${PackageName} +install(TARGETS ${PackageName} ildex_simu test_surfaces RUNTIME DESTINATION bin LIBRARY DESTINATION lib ) @@ -140,8 +156,16 @@ install(TARGETS ${PackageName} SET( test_name "test_sim_ildexdet" ) ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test_${PackageName}.sh" - ILDExSimu file:${CMAKE_CURRENT_SOURCE_DIR}/../ILDExDet/compact/ILDEx.xml file:${CMAKE_CURRENT_SOURCE_DIR}/../ILDExDet/compact/geant4.xml ${CMAKE_CURRENT_SOURCE_DIR}/run1.mac ) + ildex_simu file:${CMAKE_CURRENT_SOURCE_DIR}/../ILDExDet/compact/ILDEx.xml file:${CMAKE_CURRENT_SOURCE_DIR}/../ILDExDet/compact/geant4.xml ${CMAKE_CURRENT_SOURCE_DIR}/run1.mac ) #----- check for typical expected output: SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION " Begin of event: 2" ) SET_TESTS_PROPERTIES( t_${test_name} PROPERTIES PASS_REGULAR_EXPRESSION "-End of Run-" ) + +SET( test_name "test_surfaces" ) +ADD_TEST( t_${test_name} "${CMAKE_INSTALL_PREFIX}/bin/run_test_${PackageName}.sh" + test_surfaces file:${CMAKE_CURRENT_SOURCE_DIR}/../ILDExDet/compact/ILDEx.xml ILDExSimu.slcio) +#----- check for typical expected output: +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/examples/ILDExSimu/src/test_surfaces.cc b/examples/ILDExSimu/src/test_surfaces.cc new file mode 100644 index 0000000000000000000000000000000000000000..a1b09c54066344b15137a936136f7eec0b2751ea --- /dev/null +++ b/examples/ILDExSimu/src/test_surfaces.cc @@ -0,0 +1,145 @@ +#include "DD4hep/LCDD.h" + +#include "DDRec/Surface.h" +#include "DDRec/DetectorSurfaces.h" +#include "DDRec/SurfaceManager.h" +#include "DD4hep/DDTest.h" + +#include "DD4hep/TGeoUnits.h" + +#include "lcio.h" +#include "IO/LCReader.h" +#include "EVENT/LCEvent.h" +#include "EVENT/LCCollection.h" +#include "EVENT/SimTrackerHit.h" +#include "UTIL/ILDConf.h" + +#include <map> +#include <sstream> + +using namespace std ; +using namespace DD4hep ; +using namespace DD4hep::Geometry; +using namespace DD4hep::DDRec ; +using namespace DDSurfaces ; +using namespace lcio; + + +//using namespace tgeo ; +DDTest test = DDTest( "surfaces" ) ; + +//============================================================================= + +int main(int argc, char** argv ){ + + if( argc < 3 ) { + std::cout << " usage: test_surfaces compact.xml lcio_file.slcio" << std::endl ; + exit(1) ; + } + + std::string inFile = argv[1] ; + + LCDD& lcdd = LCDD::getInstance(); + + lcdd.fromCompact( inFile ); + + + DetElement world = lcdd.world() ; + + + // create a list of all surfaces in the detector: + SurfaceManager surfMan( world ) ; + + const SurfaceList& sL = surfMan.surfaceList() ; + + // map of surfaces + std::map< long64, Surface* > surfMap ; + + for( SurfaceList::const_iterator it = sL.begin() ; it != sL.end() ; ++it ){ + + Surface* surf = *it ; + + // std::cout << " ------------------------- " + // << " surface: " << *surf << std::endl + // << " ------------------------- " << std::endl ; + + + surfMap[ surf->id() ] = surf ; + + } + + //--------------------------------------------------------------------- + // open lcio file (created with ILDExSimu) + //--------------------------------------------------------------------- + + std::string lcioFileName = argv[2] ; + + LCReader* rdr = LCFactory::getInstance()->createLCReader() ; + rdr->open( lcioFileName ) ; + + LCEvent* evt = 0 ; + + UTIL::BitField64 idDecoder( ILDCellID0::encoder_string ) ; + + while( ( evt = rdr->readNextEvent() ) != 0 ){ + + LCCollection* col = evt->getCollection("VXDCollection" ) ; + + int nHit = col->getNumberOfElements() ; + + for(int i=0 ; i< nHit ; ++i){ + + SimTrackerHit* sHit = (SimTrackerHit*) col->getElementAt(i) ; + + long64 id = sHit->getCellID0() ; + + idDecoder.setValue( id ) ; + // std::cout << " simhit with cellid : " << idDecoder << std::endl ; + + Surface* surf = surfMap[ id ] ; + + std::stringstream sst ; + sst << " surface found for id : " << std::hex << id << std::dec ; + + + // ===== test that we have a surface with the correct ID for every hit ====================== + + test( surf != 0 , true , sst.str() ) ; + + if( surf != 0 ){ + + Vector3D point( sHit->getPosition()[0]* tgeo::mm , sHit->getPosition()[1]* tgeo::mm , sHit->getPosition()[2]* tgeo::mm ) ; + + double dist = surf->distance( point ) ; + + bool isInside = surf->insideBounds( point ) ; + + + sst.clear() ; + sst << " point " << point << " is on surface " ; + + // ====== test that hit points are inside their surface ================================ + + test( isInside , true , sst.str() ) ; + + // std::cout << " found surface with same id " << *surf << std::endl + // << " point : " << point + // << " is inside : " << isInside + // << " distance from surface : " << dist/tgeo::mm << std::endl + // << std::endl ; + + } else { + + std::cout << "ERROR: no surface found for id: " << idDecoder << std::endl ; + + } + + } + + + } + + return 0; +} + +//=============================================================================