diff --git a/CMakeLists.txt b/CMakeLists.txt index a7160b187eb68b426f4b1d6a65fc1a6114523e39..c6b39af94d96f3b45c0e8d24b188c95f4bfca429 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 0000000000000000000000000000000000000000..8d5a727344e772d29e7b5f48042f9101cca23a4e --- /dev/null +++ b/Core/src/Checker.cpp @@ -0,0 +1,127 @@ +/*****************************************************************************\ +* (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() ); + double distancesq = ( end_point - start_point ).mag2(); + 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() ); + distancesq = ( end_point - current ).mag2(); + + } while ( distancesq > 0.1 ); + + return 0; +} +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