Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:29

0001 #pragma once
0002 
0003 #include "G4Material.hh"
0004 
0005 #include "NPFold.h"
0006 #include "sstr.h"
0007 #include "S4MaterialPropertyVector.h"
0008 
0009 struct S4Material
0010 {
0011    static NPFold* MakePropertyFold( const char* mats, const char* props, char delim=',' ); 
0012 }; 
0013 
0014 /**
0015 S4Material::MakePropertyFold
0016 ----------------------------
0017 
0018 This is for example used from LSExpDetectorConstruction_Opticks::SerializePMT with::
0019 
0020     NPFold* pmt_rindex = S4Material::MakePropertyFold("Pyrex,Vacuum","RINDEX") ; 
0021 
0022 **/
0023 
0024 inline NPFold* S4Material::MakePropertyFold( const char* _mats, const char* _props, char delim )
0025 {
0026     std::vector<std::string> mats ; 
0027     sstr::Split(_mats, delim, mats ); 
0028 
0029     std::vector<std::string> props ; 
0030     sstr::Split(_props, delim, props ); 
0031 
0032     int num_mats = mats.size(); 
0033     int num_props = props.size(); 
0034 
0035     NPFold* fold = new NPFold ; 
0036 
0037     for(int i=0 ; i < num_mats ; i++)
0038     {
0039         const char* _mat = mats[i].c_str(); 
0040         G4Material* mat = G4Material::GetMaterial(_mat) ; 
0041         G4MaterialPropertiesTable* mpt = mat ? mat->GetMaterialPropertiesTable() : nullptr ; 
0042         if(mpt == nullptr) continue ; 
0043 
0044         for(int j=0 ; j < num_props ; j++)
0045         {
0046             const char* _prop = props[j].c_str() ; 
0047             G4MaterialPropertyVector* mpv = mpt->GetProperty(_prop) ; 
0048             NP* arr = S4MaterialPropertyVector::ConvertToArray(mpv );          
0049 
0050             std::stringstream ss ; 
0051             ss << _mat << _prop ; 
0052             std::string key = ss.str(); 
0053             fold->add( key.c_str(), arr ); 
0054         }
0055     }
0056     return fold ; 
0057 }
0058