File indexing completed on 2026-04-10 07:50:31
0001 #pragma once
0002
0003 #include "G4PhysicsOrderedFreeVector.hh"
0004 #include "G4PhysicsVector.hh"
0005 #include "G4PhysicsTable.hh"
0006 #include "G4SystemOfUnits.hh"
0007
0008 #include "NP.hh"
0009
0010 struct U4PhysicsVector
0011 {
0012 static G4PhysicsOrderedFreeVector* CreateConst(double value);
0013
0014 static NP* ConvertToArray(const G4PhysicsVector* prop) ;
0015 static NP* CreateCombinedArray( const G4PhysicsTable* table );
0016 };
0017
0018
0019 G4PhysicsOrderedFreeVector* U4PhysicsVector::CreateConst(double value)
0020 {
0021 G4double Energies[2] = { 1.55*eV , 15.5*eV } ;
0022 G4double Values[2] = { value, value } ;
0023 return new G4PhysicsOrderedFreeVector(Energies, Values, 2 ) ;
0024 }
0025
0026
0027
0028
0029
0030
0031
0032 inline NP* U4PhysicsVector::ConvertToArray(const G4PhysicsVector* prop)
0033 {
0034 size_t num_val = prop ? prop->GetVectorLength() : 0 ;
0035 NP* a = NP::Make<double>( num_val, 2 );
0036 double* a_v = a->values<double>();
0037 for(size_t i=0 ; i < num_val ; i++)
0038 {
0039 G4double energy = prop->Energy(i);
0040 G4double value = (*prop)[i] ;
0041 a_v[2*i+0] = energy ;
0042 a_v[2*i+1] = value ;
0043 }
0044 return a ;
0045 }
0046
0047 inline NP* U4PhysicsVector::CreateCombinedArray( const G4PhysicsTable* table )
0048 {
0049 if(table == nullptr) return nullptr ;
0050 size_t entries = table->entries() ;
0051 if(entries == 0) return nullptr ;
0052
0053 const G4PhysicsTable& tab = *table ;
0054
0055 std::vector<const NP*> aa ;
0056 for(size_t i=0 ; i < entries ; i++)
0057 {
0058 G4PhysicsVector* vec = tab(i) ;
0059 const NP* a = ConvertToArray(vec) ;
0060 aa.push_back(a);
0061 }
0062 return NP::Combine(aa);
0063 }
0064
0065
0066
0067
0068