From 108f5cb1e79a14e6cf00348b4a44746165bc1382 Mon Sep 17 00:00:00 2001 From: Ben Couturier Date: Fri, 8 May 2020 22:28:20 +0200 Subject: [PATCH 1/3] Added tool to display volumes and materials between two points --- CMakeLists.txt | 2 ++ Core/src/Checker.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Core/src/Checker.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a7160b187e..c6b39af94d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,9 +100,11 @@ add_detector_plugin(DetectorPlugins Detector/Infrastructure/src/BLS_geo.cpp Detector/Infrastructure/src/DetectorRegion.cpp Detector/Infrastructure/src/MBXW_geo.cpp + Core/src/Checker.cpp ) target_link_libraries(DetectorPlugins GitCondDB::GitCondDB) + #-------------------------------------------------------------------------- # Testing include(CTest) diff --git a/Core/src/Checker.cpp b/Core/src/Checker.cpp new file mode 100644 index 0000000000..0ad99f289a --- /dev/null +++ b/Core/src/Checker.cpp @@ -0,0 +1,72 @@ +/*****************************************************************************\ +* (c) Copyright 2020 CERN for the benefit of the LHCb Collaboration * +* * +* This software is distributed under the terms of the GNU General Public * +* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". * +* * +* In applying this licence, CERN does not waive the privileges and immunities * +* granted to it by virtue of its status as an Intergovernmental Organization * +* or submit itself to any jurisdiction. * +\*****************************************************************************/ + +#include + +#include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/Detector.h" +#include "DD4hep/Printout.h" + +#include "Math/Vector3D.h" + +static long dd4hep_find_intersections( dd4hep::Detector& description, int argc, char** argv ) { + + ROOT::Math::XYZPoint start_point, end_point; + bool help = false; + bool error = false; + for ( int i = 0; i < argc && argv[i]; ++i ) { + if ( 0 == ::strncmp( "-help", argv[i], 4 ) ) { help = true; } + } + + if ( argc == 6 ) { + start_point = ROOT::Math::XYZPoint( atof( argv[0] ), atof( argv[1] ), atof( argv[2] ) ); + end_point = ROOT::Math::XYZPoint( atof( argv[3] ), atof( argv[4] ), atof( argv[5] ) ); + } else { + error = true; + } + + if ( help || error ) { + /// Help printout describing the basic command line interface + std::cout << "Usage: -plugin xstart ystart zstart xend yend zend \n" + " name: factory name find_intersections \n" + " -help Show this help. \n" + "\tArguments given: " + << dd4hep::arguments( argc, argv ) << std::endl; + ::exit( EINVAL ); + } + + auto nav = gGeoManager->GetCurrentNavigator(); + ROOT::Math::XYZVector direction = ( end_point - start_point ).Unit(); + + nav->SetCurrentPoint( start_point.X(), start_point.Y(), start_point.Z() ); + nav->SetCurrentDirection( direction.X(), direction.Y(), direction.Z() ); + bool reached_end = false; + double distancesq = ( end_point - start_point ).mag2(); + + while ( !reached_end ) { + + nav->FindNextBoundaryAndStep( 10 ); + auto c = nav->GetCurrentPoint(); + ROOT::Math::XYZPoint current( c[0], c[1], c[2] ); + + std::ostringstream os; + os << current << " - " << nav->GetCurrentNode()->GetName() << " - " + << nav->GetCurrentNode()->GetVolume()->GetMaterial()->GetName(); + dd4hep::printout( dd4hep::INFO, "test_scan", "%s", os.str().c_str() ); + double prev_distancesq = distancesq; + distancesq = ( end_point - current ).mag2(); + + if ( distancesq > prev_distancesq ) { reached_end = true; } + } + + return 0; +} +DECLARE_APPLY( find_intersections, dd4hep_find_intersections ) \ No newline at end of file -- GitLab From 72f63c1cc1e18ad6944263aee5a1338752758344 Mon Sep 17 00:00:00 2001 From: Ben Couturier Date: Mon, 11 May 2020 12:26:46 +0200 Subject: [PATCH 2/3] Added method to sample material at given points --- Core/src/Checker.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/Core/src/Checker.cpp b/Core/src/Checker.cpp index 0ad99f289a..91776b4ccd 100644 --- a/Core/src/Checker.cpp +++ b/Core/src/Checker.cpp @@ -60,7 +60,7 @@ static long dd4hep_find_intersections( dd4hep::Detector& description, int argc, std::ostringstream os; os << current << " - " << nav->GetCurrentNode()->GetName() << " - " << nav->GetCurrentNode()->GetVolume()->GetMaterial()->GetName(); - dd4hep::printout( dd4hep::INFO, "test_scan", "%s", os.str().c_str() ); + dd4hep::printout( dd4hep::INFO, "find-_intersec", "%s", os.str().c_str() ); double prev_distancesq = distancesq; distancesq = ( end_point - current ).mag2(); @@ -69,4 +69,62 @@ static long dd4hep_find_intersections( dd4hep::Detector& description, int argc, return 0; } -DECLARE_APPLY( find_intersections, dd4hep_find_intersections ) \ No newline at end of file +DECLARE_APPLY( find_intersections, dd4hep_find_intersections ) + +static long dd4hep_scan( dd4hep::Detector& description, int argc, char** argv ) { + /* + Scan the volume defined by two points + */ + + ROOT::Math::XYZPoint start_point, end_point; + double nb_points = 10; + bool help = false; + bool error = false; + for ( int i = 0; i < argc && argv[i]; ++i ) { + if ( 0 == ::strncmp( "-help", argv[i], 4 ) ) { help = true; } + } + + if ( argc == 7 ) { + start_point = ROOT::Math::XYZPoint( atof( argv[0] ), atof( argv[1] ), atof( argv[2] ) ); + end_point = ROOT::Math::XYZPoint( atof( argv[3] ), atof( argv[4] ), atof( argv[5] ) ); + nb_points = atof( argv[6] ); + } else { + error = true; + } + + if ( help || error ) { + /// Help printout describing the basic command line interface + std::cout << "Usage: -plugin xstart ystart zstart xend yend zend \n" + " name: factory name find_intersections \n" + " -help Show this help. \n" + "\tArguments given: " + << dd4hep::arguments( argc, argv ) << std::endl; + ::exit( EINVAL ); + } + + auto nav = gGeoManager->GetCurrentNavigator(); + ROOT::Math::XYZVector direction{end_point - start_point}; + direction /= nb_points; + double x = start_point.x(); + double y = start_point.y(); + double z = start_point.z(); + while ( z <= end_point.z() ) { + while ( y <= end_point.y() ) { + while ( x <= end_point.x() ) { + TGeoNode* node = nav->FindNode( x, y, z ); + std::ostringstream os; + os << "( " << x << ", " << y << ", " << z << ") - " << node->GetName() << " - " + << node->GetVolume()->GetMaterial()->GetName(); + dd4hep::printout( dd4hep::INFO, "scan", "%s", os.str().c_str() ); + x += direction.x(); + } + x = start_point.x(); + y += direction.y(); + } + y = start_point.y(); + z += direction.z(); + } + + return 0; +} +DECLARE_APPLY( scan, dd4hep_scan ) \ No newline at end of file -- GitLab From 129c58cc7e280c5a60b73c2cf951166dfe6cc337 Mon Sep 17 00:00:00 2001 From: Ben Couturier Date: Mon, 11 May 2020 18:12:31 +0200 Subject: [PATCH 3/3] Improved loop --- Core/src/Checker.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Core/src/Checker.cpp b/Core/src/Checker.cpp index 91776b4ccd..8d5a727344 100644 --- a/Core/src/Checker.cpp +++ b/Core/src/Checker.cpp @@ -48,24 +48,21 @@ static long dd4hep_find_intersections( dd4hep::Detector& description, int argc, nav->SetCurrentPoint( start_point.X(), start_point.Y(), start_point.Z() ); nav->SetCurrentDirection( direction.X(), direction.Y(), direction.Z() ); - bool reached_end = false; double distancesq = ( end_point - start_point ).mag2(); - - while ( !reached_end ) { - - nav->FindNextBoundaryAndStep( 10 ); + double prev_distancesq = distancesq; + do { + prev_distancesq = distancesq; + nav->FindNextBoundaryAndStep( std::sqrt(distancesq) ); auto c = nav->GetCurrentPoint(); ROOT::Math::XYZPoint current( c[0], c[1], c[2] ); std::ostringstream os; os << current << " - " << nav->GetCurrentNode()->GetName() << " - " << nav->GetCurrentNode()->GetVolume()->GetMaterial()->GetName(); - dd4hep::printout( dd4hep::INFO, "find-_intersec", "%s", os.str().c_str() ); - double prev_distancesq = distancesq; + dd4hep::printout( dd4hep::INFO, "find_intersec", "%s", os.str().c_str() ); distancesq = ( end_point - current ).mag2(); - - if ( distancesq > prev_distancesq ) { reached_end = true; } - } + + } while ( distancesq > 0.1 ); return 0; } -- GitLab