Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PhysicsOrderedFreeVector.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// G4PhysicsOrderedFreeVector class implementation
27//
28// Author: Juliet Armstrong (TRIUMF), 13 August 1996
29// Revisions:
30// - 11.11.2000, H.Kurashige: use STL vector for dataVector and binVector
31// - 19.06.2009, V.Ivanchenko: removed hidden bin
32// --------------------------------------------------------------------
33
35
36// --------------------------------------------------------------------
39{
41}
42
43// --------------------------------------------------------------------
45 G4double* Values,
46 std::size_t VectorLength)
48{
50
51 dataVector.reserve(VectorLength);
52 binVector.reserve(VectorLength);
53
54 for(std::size_t i = 0; i < VectorLength; ++i)
55 {
56 InsertValues(Energies[i], Values[i]);
57 }
58}
59
60// --------------------------------------------------------------------
62 const std::vector<G4double>& Energies, const std::vector<G4double>& Values)
64{
65 if(Energies.size() != Values.size())
66 {
68 ed << "The sizes of the two std::vector arguments must be the same";
69 G4Exception("G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()",
70 "glob04", FatalException, ed);
71 }
72
74
75 dataVector.reserve(Energies.size());
76 binVector.reserve(Energies.size());
77
78 for(std::size_t i = 0; i < Energies.size(); ++i)
79 {
80 InsertValues(Energies[i], Values[i]);
81 }
82}
83
84// --------------------------------------------------------------------
86
87// --------------------------------------------------------------------
89{
90 auto binLoc = std::lower_bound(binVector.cbegin(), binVector.cend(), energy);
91
92 std::size_t binIdx = binLoc - binVector.cbegin(); // Iterator difference!
93
94 auto dataLoc = dataVector.cbegin() + binIdx;
95
96 binVector.insert(binLoc, energy);
97 dataVector.insert(dataLoc, value);
98
100 edgeMin = binVector.front();
101 edgeMax = binVector.back();
102}
103
104// --------------------------------------------------------------------
106{
107 G4double e;
108 if(aValue <= GetMinValue())
109 {
110 e = edgeMin;
111 }
112 else if(aValue >= GetMaxValue())
113 {
114 e = edgeMax;
115 }
116 else
117 {
118 std::size_t closestBin = FindValueBinLocation(aValue);
119 e = LinearInterpolationOfEnergy(aValue, closestBin);
120 }
121 return e;
122}
123
124// --------------------------------------------------------------------
125std::size_t G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
126{
127 std::size_t bin =
128 std::lower_bound(dataVector.cbegin(), dataVector.cend(), aValue) -
129 dataVector.cbegin() - 1;
130 bin = std::min(bin, numberOfNodes - 2);
131 return bin;
132}
133
134// --------------------------------------------------------------------
135G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(
136 G4double aValue, std::size_t bin)
137{
138 G4double res = binVector[bin];
139 G4double del = dataVector[bin + 1] - dataVector[bin];
140 if(del > 0.0)
141 {
142 res += (aValue - dataVector[bin]) * (binVector[bin + 1] - res) / del;
143 }
144 return res;
145}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
@ T_G4PhysicsOrderedFreeVector
double G4double
Definition: G4Types.hh:83
void InsertValues(G4double energy, G4double value)
G4double GetEnergy(G4double aValue)
G4PVDataVector binVector
G4PhysicsVectorType type
std::size_t numberOfNodes
G4PVDataVector dataVector