Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 07:50:31

0001 #pragma once
0002 /**
0003 U4PhysicsTable.h 
0004 ==================
0005 
0006 Canonical usage is at U4Tree instanciation 
0007 within U4Tree::initRayleigh 
0008 
0009 HMM: trying a different approach from former impl
0010 for handling the Geant4 Water RAYLEIGH from RINDEX 
0011 special casing. Former approach was material centric::
0012 
0013    X4MaterialWater.hh
0014    X4MaterialWater.cc
0015    X4OpRayleigh.hh
0016    X4OpRayleigh.cc
0017 
0018 Instead of focussing on Water material and rayleigh process
0019 just grab the entire physics table from a templated process.
0020 So can peruse the physics table and use it as appropriate. 
0021 
0022 "g4-cls G4PhysicsTable" ISA : std::vector<G4PhysicsVector*>
0023 
0024 
0025 When called without a process argument U4PhysicsTable
0026 attempts access the process from process manager. 
0027 This approach requires this to be run after physics setup.::
0028 
0029     NP* tab = U4PhysicsTable<G4OpRayleigh>::Convert();  
0030 
0031 Directly passing a process instance gives more 
0032 flexibility, allowing running from U4Tree::initRayleigh::
0033 
0034     NP* tab = U4PhysicsTable<G4OpRayleigh>::Convert(new G4OpRayleigh); 
0035 
0036 
0037 **/
0038 
0039 #include <string>
0040 #include <sstream>
0041 #include <iostream>
0042 
0043 #include "U4Process.h"
0044 #include "U4PhysicsVector.h"
0045 #include "U4MaterialTable.h"
0046 
0047 template<typename T>
0048 struct U4PhysicsTable
0049 {
0050     T*              proc ; 
0051     G4PhysicsTable* table ; 
0052     NP*             tab ; 
0053     std::vector<std::string> names ; 
0054 
0055     static NP* Convert(T* proc_=nullptr); 
0056     U4PhysicsTable(T* proc_=nullptr); 
0057 
0058     int              find_index(const char* name) ; // with T=G4OpRayleigh this is matname
0059     G4PhysicsVector* find(const char* name) ; 
0060 
0061     std::string desc() const ; 
0062 };
0063 
0064 template<typename T>
0065 inline NP* U4PhysicsTable<T>::Convert(T* proc)
0066 {
0067     U4PhysicsTable<T> table(proc) ; 
0068     if(table.tab == nullptr) std::cerr << table.desc() ; 
0069     return table.tab ; 
0070 }
0071 
0072 template<typename T>
0073 inline U4PhysicsTable<T>::U4PhysicsTable(T* proc_)
0074     :
0075     proc(proc_ ? proc_ : U4Process::Get<T>()),
0076     table(proc ? proc->GetPhysicsTable() : nullptr),
0077     tab(table ? U4PhysicsVector::CreateCombinedArray(table) : nullptr)
0078 {
0079     U4MaterialTable::GetMaterialNames(names); 
0080     if(tab) tab->set_names(names) ; 
0081 }
0082 
0083 
0084 template<typename T>
0085 inline int U4PhysicsTable<T>::find_index(const char* name)
0086 {
0087     size_t idx = std::distance( names.begin(), std::find( names.begin(), names.end(), name ) ) ; 
0088     return idx < names.size() ? int(idx) : -1 ; 
0089 }
0090 
0091 template<typename T>
0092 inline G4PhysicsVector* U4PhysicsTable<T>::find(const char* name)
0093 {
0094     int idx = find_index(name); 
0095     if( idx < 0 ) return nullptr ; 
0096 
0097     int entries = table ? int(table->entries()) : 0 ; 
0098     assert( idx < entries ); 
0099 
0100     return (*table)(idx) ; 
0101 }
0102 
0103 
0104 template<typename T>
0105 inline std::string U4PhysicsTable<T>::desc() const 
0106 {
0107     std::stringstream ss ; 
0108     ss << "U4PhysicsTable::desc"
0109         << " proc " << ( proc ? "YES" : "NO " ) << std::endl 
0110         << " procName " << ( proc ? proc->GetProcessName() : "-" ) << std::endl 
0111         << " table " << ( table ? "YES" : "NO " ) << std::endl 
0112         << " tab " << ( tab ? tab->sstr() : "-" ) << std::endl 
0113         ;
0114     std::string str = ss.str(); 
0115     return str ; 
0116 }
0117