Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PhysicsFreeVector.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// G4PhysicsFreeVector class implementation
27//
28// Authors:
29// - 02 Dec. 1995, G.Cosmo: Structure created based on object model
30// - 06 Jun. 1996, K.Amako: Implemented the 1st version
31// Revisions:
32// - 11 Nov. 2000, H.Kurashige: Use STL vector for dataVector and binVector
33// - 25 Aug. 2021, V.Ivanchenko updated for Geant4 11.0
34// --------------------------------------------------------------------
35
37
38// --------------------------------------------------------------------
40 : G4PhysicsVector(spline)
41{}
42
43// --------------------------------------------------------------------
45 : G4PhysicsFreeVector((std::size_t)length, false)
46{}
47
48// --------------------------------------------------------------------
50 : G4PhysicsVector(spline)
51{
52 numberOfNodes = length;
53
54 if(0 < length) {
55 binVector.resize(numberOfNodes, 0.0);
56 dataVector.resize(numberOfNodes, 0.0);
57 }
58 Initialise();
59}
60
61// --------------------------------------------------------------------
63 G4double, G4bool spline)
64 : G4PhysicsFreeVector(length, spline)
65{}
66
67// --------------------------------------------------------------------
68G4PhysicsFreeVector::G4PhysicsFreeVector(const std::vector<G4double>& energies,
69 const std::vector<G4double>& values,
70 G4bool spline)
71 : G4PhysicsVector(spline)
72{
73 numberOfNodes = energies.size();
74
75 if(numberOfNodes != values.size())
76 {
78 ed << "The size of energy vector " << numberOfNodes << " != " << values.size();
79 G4Exception("G4PhysicsFreeVector constructor: ","glob04", FatalException, ed);
80 }
81
82 binVector = energies;
83 dataVector = values;
84 Initialise();
85}
86
87// --------------------------------------------------------------------
89 const G4double* values,
90 std::size_t length,
91 G4bool spline)
92 : G4PhysicsVector(spline)
93{
94 numberOfNodes = length;
95
96 if(0 < numberOfNodes)
97 {
100
101 for(std::size_t i = 0; i < numberOfNodes; ++i)
102 {
103 binVector[i] = energies[i];
104 dataVector[i] = values[i];
105 }
106 }
107 Initialise();
108}
109
110// --------------------------------------------------------------------
111void G4PhysicsFreeVector::PutValues(const std::size_t index,
112 const G4double e,
113 const G4double value)
114{
115 if(index >= numberOfNodes)
116 {
117 PrintPutValueError(index, value, "G4PhysicsFreeVector::PutValues ");
118 return;
119 }
120 binVector[index] = e;
121 dataVector[index] = value;
122 if(index == 0)
123 {
124 edgeMin = e;
125 }
126 else if(numberOfNodes == index + 1)
127 {
128 edgeMax = e;
129 }
130}
131
132// --------------------------------------------------------------------
134 const G4double value)
135{
136 auto binLoc = std::lower_bound(binVector.cbegin(), binVector.cend(), energy);
137 auto dataLoc = dataVector.cbegin();
138 dataLoc += binLoc - binVector.cbegin();
139
140 binVector.insert(binLoc, energy);
141 dataVector.insert(dataLoc, value);
142
144 Initialise();
145}
146
147// --------------------------------------------------------------------
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void InsertValues(const G4double energy, const G4double value)
void PutValues(const std::size_t index, const G4double energy, const G4double value)
G4PhysicsFreeVector(G4bool spline=false)
void PrintPutValueError(std::size_t index, G4double value, const G4String &text)
std::size_t numberOfNodes
std::vector< G4double > dataVector
std::vector< G4double > binVector
virtual void Initialise()