File indexing completed on 2026-04-10 07:50:29
0001
0002 #include <sstream>
0003 #include "OPTICKS_LOG.hh"
0004 #include "U4VolumeMaker.hh"
0005 #include "ssys.h"
0006
0007 #include "G4Material.hh"
0008 #include "G4VSolid.hh"
0009 #include "G4LogicalVolume.hh"
0010 #include "G4VPhysicalVolume.hh"
0011 #include "U4Volume.h"
0012
0013
0014
0015 struct U4VolumeMakerTest
0016 {
0017 static std::string Desc(const G4VPhysicalVolume* pv, const char* symbol );
0018 static std::string Desc(const G4VSolid* so, const char* symbol);
0019 std::string desc() const ;
0020
0021 const char* sub ;
0022 const G4VPhysicalVolume* pv ;
0023 const G4VPhysicalVolume* spv ;
0024 const G4LogicalVolume* slv ;
0025
0026 const G4VPhysicalVolume* spv1 ;
0027 const G4VPhysicalVolume* spv2 ;
0028
0029 const G4LogicalVolume* slv1 ;
0030 const G4LogicalVolume* slv2 ;
0031
0032 const G4VSolid* sso1 ;
0033 const G4VSolid* sso2 ;
0034
0035 U4VolumeMakerTest();
0036
0037 int sub_check();
0038 int OldHamaBodyPhys();
0039 };
0040
0041
0042
0043 std::string U4VolumeMakerTest::Desc(const G4VPhysicalVolume* pv, const char* symbol)
0044 {
0045 const G4LogicalVolume* lv = pv ? pv->GetLogicalVolume() : nullptr ;
0046 const G4Material* mt = lv ? lv->GetMaterial() : nullptr ;
0047 const G4VSolid* so = lv ? lv->GetSolid() : nullptr ;
0048 std::stringstream ss ;
0049 ss
0050 << symbol
0051 << " pv " << ( pv ? pv->GetName() : "-" )
0052 << " lv " << ( lv ? lv->GetName() : "-" )
0053 << " mt " << ( mt ? mt->GetName() : "-" )
0054 << " so " << ( so ? so->GetName() : "-" )
0055 << "\n"
0056 ;
0057 std::string str = ss.str();
0058 return str ;
0059 }
0060
0061 std::string U4VolumeMakerTest::Desc(const G4VSolid* so, const char* symbol )
0062 {
0063 G4GeometryType et = so ? so->GetEntityType() : "" ;
0064 std::stringstream ss ;
0065 ss
0066 << symbol
0067 << " so " << ( so ? so->GetName() : "-" )
0068 << " et " << et
0069 << "\n"
0070 ;
0071
0072 std::string str = ss.str();
0073 return str ;
0074 }
0075
0076
0077
0078 std::string U4VolumeMakerTest::desc() const
0079 {
0080 std::stringstream ss ;
0081 ss << U4VolumeMaker::Desc()
0082 << " sub " << ( sub ? sub : "-" )
0083 << Desc(pv, "pv")
0084 << Desc(spv, "spv")
0085 << Desc(spv1, "spv1")
0086 << Desc(spv2, "spv2")
0087 << Desc(sso1, "sso1")
0088 << Desc(sso2, "sso2")
0089 ;
0090
0091 std::string str = ss.str() ;
0092 return str ;
0093 }
0094
0095
0096 inline U4VolumeMakerTest::U4VolumeMakerTest()
0097 :
0098 sub(ssys::getenvvar("SUB", "hama_body_phys")),
0099 pv(U4VolumeMaker::PV()),
0100 spv(pv ? U4Volume::FindPV(pv, sub ) : nullptr),
0101 slv(spv ? spv->GetLogicalVolume() : nullptr),
0102 spv1(slv ? slv->GetDaughter(0) : nullptr ),
0103 spv2(slv ? slv->GetDaughter(1) : nullptr ),
0104 slv1(spv1 ? spv1->GetLogicalVolume() : nullptr ),
0105 slv2(spv2 ? spv2->GetLogicalVolume() : nullptr ),
0106 sso1(slv1 ? slv1->GetSolid() : nullptr ),
0107 sso2(slv2 ? slv2->GetSolid() : nullptr )
0108 {
0109 std::cout << desc();
0110 }
0111
0112 inline int U4VolumeMakerTest::sub_check()
0113 {
0114 int rc = 0 ;
0115 if(sub && strcmp(sub, "hama_body_phys") == 0) rc += OldHamaBodyPhys();
0116 return rc ;
0117 }
0118
0119 inline int U4VolumeMakerTest::OldHamaBodyPhys()
0120 {
0121 if(spv == nullptr) return 0 ;
0122 LOG(info) << " spv :: " << Desc(spv, "spv") ;
0123 LOG(info) << " spv1 :: " << Desc(spv1, "spv1") ;
0124 LOG(info) << " spv2 :: " << Desc(spv2, "spv2") ;
0125
0126 if( spv1 == nullptr || spv2 == nullptr ) return 0 ;
0127
0128 assert( sso1 );
0129
0130 G4ThreeVector pos(103,0,-50) ;
0131 G4ThreeVector dir(0,0,1) ;
0132
0133 G4double dist1 = sso1->DistanceToOut(pos, dir);
0134 G4double dist2 = sso2->DistanceToIn(pos, dir);
0135
0136 std::cout << " dist1 = sso1->DistanceToOut(pos, dir) : " << dist1 << std::endl ;
0137 std::cout << " dist2 = sso2->DistanceToIn( pos, dir) : " << dist2 << std::endl ;
0138
0139 std::cout << Desc(sso1, "sso1") ;
0140 std::cout << Desc(sso2, "sso2") ;
0141
0142 return 0 ;
0143 }
0144
0145
0146
0147 int main(int argc, char** argv)
0148 {
0149 OPTICKS_LOG(argc, argv);
0150 U4VolumeMakerTest test ;
0151 return test.sub_check() ;
0152 }