File indexing completed on 2026-04-10 07:50:27
0001
0002 #include "OPTICKS_LOG.hh"
0003 #include "spath.h"
0004 #include "U4GDML.h"
0005
0006 #include "G4Material.hh"
0007
0008 struct Traverse
0009 {
0010 const G4VPhysicalVolume* const world ;
0011 int count ;
0012 Traverse(const G4VPhysicalVolume* const world) ;
0013 void traverse_r(const G4VPhysicalVolume* const pv, int depth ) ;
0014 void visit( const G4VPhysicalVolume* const pv, int depth );
0015 };
0016
0017 inline Traverse::Traverse(const G4VPhysicalVolume* const world_)
0018 :
0019 world(world_),
0020 count(0)
0021 {
0022 traverse_r(world, 0) ;
0023 }
0024
0025 inline void Traverse::traverse_r(const G4VPhysicalVolume* const pv, int depth )
0026 {
0027 visit( pv, depth );
0028 count += 1 ;
0029 const G4LogicalVolume* lv = pv->GetLogicalVolume() ;
0030 for (size_t i=0 ; i < size_t(lv->GetNoDaughters()) ;i++ ) traverse_r( lv->GetDaughter(i), depth+1 );
0031 }
0032
0033 inline void Traverse::visit( const G4VPhysicalVolume* const pv, int depth )
0034 {
0035 const G4LogicalVolume* lv = pv->GetLogicalVolume() ;
0036 G4Material* mt = lv->GetMaterial() ;
0037 if( count % 10000 == 0 ) std::cout
0038 << "Traverse::visit"
0039 << " count " << count
0040 << " depth " << depth
0041 << " mt " << mt->GetName()
0042 << std::endl
0043 ;
0044 }
0045
0046
0047
0048 int main(int argc, char** argv)
0049 {
0050 OPTICKS_LOG(argc, argv);
0051
0052 const char* path = spath::Resolve("$CFBaseFromGEOM/origin.gdml") ;
0053
0054 LOG(info)
0055 << " argv[0] "
0056 << argv[0]
0057 << " path "
0058 << path ;
0059
0060 new U4SensitiveDetector("PMTSDMgr") ;
0061
0062 const G4VPhysicalVolume* world = U4GDML::Read(path) ;
0063
0064 LOG_IF(fatal, world == nullptr)
0065 << " argv[0] " << argv[0] << "\n"
0066 << " path " << ( path ? path : "-" ) << "\n"
0067 << " world " << ( world ? "YES" : "NO " ) << "\n"
0068 ;
0069
0070 if(world == nullptr) return 0;
0071
0072 Traverse trv(world);
0073
0074 return 0 ;
0075 }