File indexing completed on 2026-04-10 07:50:27
0001
0002 #include "ssys.h"
0003 #include "spath.h"
0004 #include "sdigest.h"
0005 #include "SSim.hh"
0006 #include "NP.hh"
0007
0008 #include "U4Version.h"
0009 #include "U4Material.hh"
0010 #include "U4MaterialPropertiesTable.h"
0011 #include "U4PhysicsVector.h"
0012 #include "G4Material.hh"
0013 #include "Randomize.hh"
0014
0015 #include "OPTICKS_LOG.hh"
0016
0017
0018
0019 void test_MakeMaterialPropertiesTable()
0020 {
0021 G4MaterialPropertiesTable* mpt = U4Material::MakeMaterialPropertiesTable("GScintillatorLib/LS_ori", "FASTCOMPONENT,SLOWCOMPONENT,REEMISSIONPROB", ',' ) ;
0022 std::cout << " mpt " << mpt << std::endl ;
0023 }
0024
0025 void test_MakeScintillator()
0026 {
0027 G4Material* mat = U4Material::MakeScintillator();
0028 G4cout << "mat " << *mat << std::endl ;
0029
0030 G4MaterialPropertiesTable* mpt = mat->GetMaterialPropertiesTable();
0031
0032 assert(mpt);
0033 std::cout << U4MaterialPropertiesTable::Detail(mpt);
0034
0035 }
0036
0037 void test_GetProperty()
0038 {
0039 G4Material* mat = U4Material::MakeScintillator();
0040
0041 std::vector<std::string> names = {"GammaCONSTANT", "AlphaCONSTANT", "NeutronCONSTANT", "OpticalCONSTANT" } ;
0042
0043 for(unsigned i=0 ; i < names.size() ; i++)
0044 {
0045 const char* name = names[i].c_str() ;
0046 G4MaterialPropertyVector* prop = U4Material::GetProperty(mat, name) ;
0047 if(prop == nullptr) continue ;
0048
0049 size_t len = prop->GetVectorLength();
0050
0051 LOG(info) << name << " len: " << len << std::endl << "[" << std::endl << *prop << "]" << std::endl ;
0052 }
0053 }
0054
0055
0056 void test_NumVec()
0057 {
0058 G4MaterialPropertyVector* prop = U4Material::GetProperty(U4Material::MakeScintillator(), "GammaCONSTANT") ;
0059 if(prop == nullptr) return ;
0060
0061 G4int NumTracks = 1000000 ;
0062
0063 G4int nscnt = prop->GetVectorLength();
0064 std::vector<G4int> NumVec(nscnt);
0065 NumVec.clear();
0066 for(G4int i = 0 ; i < NumTracks ; i++){
0067 G4double p = G4UniformRand();
0068 G4double p_count = 0;
0069 for(G4int j = 0 ; j < nscnt; j++)
0070 {
0071 p_count += (*prop)[j] ;
0072 if( p < p_count ){
0073 NumVec[j]++ ;
0074 break;
0075 }
0076 }
0077 }
0078
0079 int tot_NumVec = 0 ;
0080 double tot_prop = 0 ;
0081
0082 std::cout << " split the NumTracks:" << NumTracks << " into nscnt:" << nscnt << " groups, with each group having a single scintillationTime param " << std::endl ;
0083
0084 for(int i=0 ; i < nscnt ; i++)
0085 {
0086 tot_NumVec += NumVec[i] ;
0087 tot_prop += (*prop)[i] ;
0088 std::cout
0089 << " i " << std::setw(5) << i
0090 << " NumVec[i] " << std::setw(7) << NumVec[i]
0091 << " prop[i] " << std::setw(10) << std::fixed << std::setprecision(4) << (*prop)[i]
0092 << " prop.Energy(i) " << std::setw(10) << std::fixed << std::setprecision(4) << prop->Energy(i) << " (scintillationTime) "
0093 << std::endl
0094 ;
0095 }
0096
0097 std::cout
0098 << "tot" << std::setw(5) << ""
0099 << " NumVec[ ] " << std::setw(7) << tot_NumVec
0100 << " prop[ ] " << std::setw(10) << std::fixed << std::setprecision(4) << tot_prop
0101 << std::endl
0102 ;
0103
0104 }
0105
0106
0107
0108 void test_LoadOri_name()
0109 {
0110 G4Material* mat = U4Material::LoadOri("Water");
0111 LOG(info) << " mat " << mat ;
0112 }
0113
0114 void test_ListOri()
0115 {
0116 std::vector<std::string> names ;
0117 U4Material::ListOri(names);
0118 }
0119
0120 void test_LoadOri()
0121 {
0122 U4Material::LoadOri();
0123 std::cout << U4Material::DescMaterialTable() ;
0124 }
0125
0126 void test_LoadOri_remove_material_property()
0127 {
0128 U4Material::LoadOri();
0129 std::cout << U4Material::DescMaterialTable() ;
0130
0131 G4Material* mat = G4Material::GetMaterial("Rock");
0132
0133 LOG(info) << "before removal " << std::endl << U4Material::DescPropertyNames( mat ) ;
0134
0135 U4Material::RemoveProperty( "RINDEX", mat );
0136 U4Material::RemoveProperty( "RINDEX", mat );
0137 U4Material::RemoveProperty( "RINDEX", mat );
0138
0139 LOG(info) << "after removal " << std::endl << U4Material::DescPropertyNames( mat ) ;
0140 }
0141
0142 void test_LoadBnd()
0143 {
0144 U4Material::LoadBnd();
0145
0146
0147
0148
0149
0150 std::cout << U4Material::DescProperty() << std::endl ;
0151 }
0152
0153 void test_BndNames()
0154 {
0155 const char* path = spath::Resolve("$HOME/.opticks/GEOM/$GEOM/CSGFoundry/SSim/bnd_names.txt");
0156 LOG(info) << " path " << path ;
0157 }
0158
0159 void test_MakeStandardArray_prop_override()
0160 {
0161 const char* spec = "Water/RAYLEIGH" ;
0162
0163 std::map<std::string, G4PhysicsVector*> prop_override ;
0164 prop_override[spec] = U4PhysicsVector::CreateConst(101.);
0165
0166 bool do_override = prop_override.count(spec) > 0 ;
0167
0168 G4PhysicsVector* prop = do_override ? prop_override[spec] : nullptr ;
0169 G4double value = prop ? prop->Value(3.*eV) : 0. ;
0170
0171 std::cout
0172 << "spec " << spec
0173 << " do_override " << (do_override ? "Y" : "N" )
0174 << " value " << value
0175 << std::endl
0176 ;
0177
0178 }
0179
0180 void test_MakeStandardArray_override_count()
0181 {
0182 typedef std::map<std::string,int> SI ;
0183 SI oc ;
0184
0185 oc["Water/RAYLEIGH"] += 1 ;
0186 oc["Water/RAYLEIGH"] += 1 ;
0187 oc["vetoWater/RAYLEIGH"] += 1 ;
0188
0189 for(SI::const_iterator it=oc.begin() ; it != oc.end() ; it++)
0190 {
0191 std::cout << it->first << " : " << it->second << std::endl ;
0192 }
0193 }
0194
0195 void test_Get()
0196 {
0197 std::vector<std::string> mats = {{
0198 "Vacuum",
0199 "VACUUM",
0200 "G4_AIR",
0201 "G4_Pb",
0202 "Water",
0203 "Rock",
0204 "G4_Water",
0205 "G4_WATER"
0206 }} ;
0207
0208 for(unsigned i=0 ; i < mats.size() ; i++)
0209 {
0210 const char* mat = mats[i].c_str();
0211 G4Material* material = U4Material::Get(mat);
0212
0213 std::cout
0214 << std::setw(20) << mat
0215 << " : "
0216 << ( material ? "YES" : "NO " )
0217 << "\n"
0218 ;
0219 }
0220 }
0221
0222
0223
0224 int main(int argc, char** argv)
0225 {
0226 OPTICKS_LOG(argc, argv);
0227
0228 const char* TEST = ssys::getenvvar("TEST", "Get") ;
0229 std::cout << U4Version::Desc() << "\n" << "TEST[" << TEST << "]\n" ;
0230
0231
0232 if( strcmp(TEST, "MakeScintillator") == 0 )
0233 {
0234 test_MakeScintillator();
0235 }
0236 else if( strcmp(TEST, "Get") == 0 )
0237 {
0238 test_Get();
0239 }
0240 else if( strcmp(TEST, "ALL") == 0 )
0241 {
0242 test_MakeMaterialPropertiesTable();
0243 test_GetProperty();
0244 test_NumVec();
0245 test_LoadOri_name();
0246 test_ListOri();
0247 test_LoadOri();
0248 test_LoadOri_remove_material_property();
0249 test_LoadBnd();
0250 test_BndNames();
0251 test_MakeStandardArray_prop_override();
0252 test_MakeStandardArray_override_count();
0253 test_MakeScintillator();
0254 }
0255
0256 return 0 ;
0257 }