Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MatUtils.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25
26#include "G4MatUtils.hh"
28#include <fstream>
29#include <sstream>
30
31namespace
32{
33 constexpr G4int nmax = 40;
34}
35
36//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37
40 const G4String& filename,
41 const G4int nxsections,
42 const G4int length,
43 const G4double unitE,
44 const G4double unitS)
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}
91
92//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@ 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)
static G4ExtendedPhysicsVector * BuildExtendedVector(const G4String &dirpath, const G4String &filename, const G4int N, const G4int length, const G4double unitE=1.0, const G4double unitS=1.0)
Definition G4MatUtils.cc:39