Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MatUtils Class Reference

#include <G4MatUtils.hh>

Static Public Member Functions

static G4ExtendedPhysicsVectorBuildExtendedVector (const G4String &dirpath, const G4String &filename, const G4int N, const G4int length, const G4double unitE=1.0, const G4double unitS=1.0)

Detailed Description

Definition at line 39 of file G4MatUtils.hh.

Member Function Documentation

◆ BuildExtendedVector()

G4ExtendedPhysicsVector * G4MatUtils::BuildExtendedVector ( const G4String & dirpath,
const G4String & filename,
const G4int N,
const G4int length,
const G4double unitE = 1.0,
const G4double unitS = 1.0 )
static

Definition at line 39 of file G4MatUtils.cc.

45{
46 std::ostringstream ss;
47 ss << dirpath << "/" << filename;
48 std::ifstream infile(ss.str(), std::ios::in);
49
50 if (nxsections < 1 || length <= 0 || nxsections > nmax) {
52 ed << " Wrong data size: nsections=" << nxsections << " length="
53 << length << " nmax=" << nmax;
54 G4Exception("G4MatUtils::BuildExtendedVector(..)","mat004",
55 FatalException, ed, "Check input values");
56 return nullptr;
57 }
58
59 // file is not opened
60 if (!infile.is_open()) {
62 ed << " Fail to open file: <" << ss.str() << ">";
63 G4Exception("G4MatUtils::BuildExtendedVector(..)","mat004",
64 FatalException, ed, "Check file path");
65 return nullptr;
66 }
67 // file is opened
68 auto vtot = new G4PhysicsFreeVector(false);
69 G4ExtendedPhysicsVector* v = new G4ExtendedPhysicsVector(vtot, nxsections);
70 v->SetDataLength(length);
71
72 G4double y[nmax];
73 G4double e, yy, sum;
74 auto nn = (std::size_t)length;
75
76 for (std::size_t i=0; i<nn; ++i) {
77 sum = 0.0;
78 infile >> e;
79 e *= unitE;
80 for (G4int j=0; j<nxsections; ++j) {
81 infile >> yy;
82 yy *= unitS;
83 sum += yy;
84 y[j] = yy;
85 }
86 vtot->PutValues(i, e, sum);
87 v->PutPartialXSData(i, y);
88 }
89 return v;
90}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
void PutPartialXSData(const std::size_t idx, const G4double *y)

The documentation for this class was generated from the following files: