Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #pragma once
0002 /**
0003 SPropMockup.h : formerly SProp.hh
0004 ===================================
0005 
0006 ::
0007 
0008     epsilon:opticks blyth$ opticks-f SPropMockup.h 
0009     ./sysrap/CMakeLists.txt:    SPropMockup.h
0010     ./sysrap/SPropMockup.h:SPropMockup.h : formerly SProp.hh
0011     ./ggeo/GGeo.cc:#include "SPropMockup.h"  
0012     ./qudarap/tests/QPropTest.cc:#include "SPropMockup.h"
0013     epsilon:opticks blyth$ 
0014 
0015 **/
0016 
0017 #include <vector>
0018 struct NP ; 
0019 
0020 struct SPropMockup
0021 {
0022     static constexpr const char* DEMO_BASE = "$HOME/.opticks/GEOM/$GEOM" ;
0023     static constexpr const char* DEMO_RELP = "CSGFoundry/SSim/stree/material/LS/RINDEX.npy" ; 
0024 
0025     static const NP* CombinationDemo(); 
0026     static const NP* Combination(const char* base, const char* relp ); 
0027     static const NP* Combination(const NP* a_ ); 
0028 
0029     // TODO: below functionality belongs in NP.hh not here 
0030     static const NP* NarrowCombine(const std::vector<const NP*>& aa ); 
0031     static const NP* Combine(const std::vector<const NP*>& aa ); 
0032 }; 
0033 
0034 
0035 #include <vector>
0036 #include "NP.hh"
0037 #include "spath.h"
0038 
0039 
0040 inline const NP* SPropMockup::CombinationDemo() // static
0041 {
0042     const NP* propcom = Combination( DEMO_BASE, DEMO_RELP);
0043     return propcom ;  
0044 }
0045 
0046 /**
0047 SPropMockup::Combination
0048 ------------------------
0049 
0050 Mockup a real set of multiple properties, by loading 
0051 a single property, copying it, and applying scalings. 
0052 
0053 The source property is assumed to be provided in double precision 
0054 (ie direct from Geant4 originals) with energies in MeV which are scaled to eV.
0055 Also the properties are narrowed to float when the template type is float.
0056 
0057 **/
0058 
0059 
0060 inline const NP* SPropMockup::Combination(const char* base, const char* relp )  // static 
0061 {
0062     const char* path = spath::Resolve(base, relp); 
0063     std::cout
0064         << "SPropMockup::Combination"
0065         << " base " << base  
0066         << " relp " << relp  
0067         << " spath::Resolve to path " << path  
0068         << std::endl 
0069         ;
0070 
0071     if( path == nullptr ) return nullptr ;  // malformed path ?
0072 
0073     bool exists = NP::Exists(path) ; 
0074     std::cout
0075         << "SPropMockup::Combination"
0076         << " path " << ( path ? path : "-" )
0077         << " exists " << ( exists ? "YES" : "NO " )
0078         << std::endl 
0079         ;
0080 
0081 
0082     NP* a = exists ? NP::Load(path) : nullptr ; 
0083     if( a == nullptr ) return nullptr ;  // non-existing path 
0084 
0085     bool is_double = strcmp( a->dtype, "<f8") == 0; 
0086     if(!is_double) std::cerr 
0087        << "SPropMockup::Combination"
0088        << " EXPECTING double precision input array " 
0089        << std::endl 
0090        ; 
0091     assert(is_double); 
0092 
0093     return Combination(a) ; 
0094 }
0095 
0096 
0097 inline const NP* SPropMockup::Combination(const NP* a_ )
0098 {
0099     NP* a = a_->copy(); 
0100     NP* b = a_->copy(); 
0101     NP* c = a_->copy(); 
0102 
0103     a->pscale<double>(1e6, 0u);   // energy scale from MeV to eV,   1.55 to 15.5 eV
0104     b->pscale<double>(1e6, 0u); 
0105     c->pscale<double>(1e6, 0u); 
0106 
0107     b->pscale<double>(1.05, 1u); 
0108     c->pscale<double>(0.95, 1u); 
0109 
0110     std::vector<const NP*> aa = {a, b, c } ; 
0111     const NP* com = NarrowCombine(aa); 
0112 
0113     std::cout
0114         << "SPropMockup::Combination"
0115         << " com " << ( com ? com->desc() : "-" )
0116         << std::endl 
0117         ;
0118 
0119     return com ; 
0120 }
0121 
0122 
0123 /**
0124 SPropMockup::NarrowCombine
0125 ------------------------------
0126 
0127 Only implemented for float template specialization.
0128 
0129 Combination using NP::Combine which pads shorter properties
0130 allowing all to be combined into a single array, with final 
0131 extra column used to record the payload column count.
0132 
0133 
0134 HMM: maybe simpler to just MakeNarrow on the combined array ?
0135 
0136 **/
0137 
0138 
0139 inline const NP* SPropMockup::NarrowCombine(const std::vector<const NP*>& aa )   // static
0140 {
0141     std::cout << "SPropMockup::NarrowCombine : narrowing double to float " << std::endl ; 
0142     std::vector<const NP*> nn ; 
0143     for(unsigned i=0 ; i < aa.size() ; i++)
0144     {
0145         const NP* a = aa[i] ; 
0146         const NP* n = NP::MakeNarrow( a );
0147         nn.push_back(n); 
0148     }
0149     NP* com = NP::Combine(nn) ; 
0150     return com ;  
0151 }
0152 
0153 inline const NP* SPropMockup::Combine(const std::vector<const NP*>& aa )   // static
0154 {
0155     std::cout << "SPropMockup::Combine :  not-narrowing retaining double " << std::endl  ; 
0156     NP* com = NP::Combine(aa) ;
0157     return com ;  
0158 }
0159 
0160