Geant4  10.02
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 //
27 // $Id: G4PhysicsOrderedFreeVector.cc 93409 2015-10-21 13:26:27Z gcosmo $
28 //
30 // PhysicsOrderedFreeVector Class Implementation
32 //
33 // File: G4PhysicsOrderedFreeVector.cc
34 // Version: 2.0
35 // Created: 1996-08-13
36 // Author: Juliet Armstrong
37 // Updated: 1997-03-25 by Peter Gumplinger
38 // > cosmetics (only)
39 // 1998-11-11 by Peter Gumplinger
40 // > initialize all data members of the base class in
41 // derived class constructors
42 // 2000-11-11 by H.Kurashige
43 // > use STL vector for dataVector and binVector
44 // 2009-06-19 by V.Ivanchenko
45 // > removed hidden bin
46 // 2013-10-02 by V.Ivanchenko removed FindBinLocation
47 //
48 // mail: gum@triumf.ca
49 //
51 
53 
55 // Class Implementation
57 
59  // Constructors
61 
63  G4double *Values,
64  size_t VectorLength)
65  : G4PhysicsVector()
66 {
68 
69  for (size_t i = 0 ; i < VectorLength ; ++i)
70  {
71  InsertValues(Energies[i], Values[i]);
72  }
73 }
74 
76  : G4PhysicsVector()
77 {
79 }
80 
82  // Destructors
84 
86 
88  // Methods
90 
92 {
93  std::vector<G4double>::iterator binLoc =
94  std::lower_bound(binVector.begin(), binVector.end(), energy);
95 
96  size_t binIdx = binLoc - binVector.begin(); // Iterator difference!
97 
98  std::vector<G4double>::iterator dataLoc = dataVector.begin() + binIdx;
99 
100  binVector.insert(binLoc, energy);
101  dataVector.insert(dataLoc, value);
102 
103  ++numberOfNodes;
104  edgeMin = binVector.front();
105  edgeMax = binVector.back();
106 }
107 
109 {
110  G4double e;
111  if (aValue <= GetMinValue()) {
112  e = edgeMin;
113  } else if (aValue >= GetMaxValue()) {
114  e = edgeMax;
115  } else {
116  size_t closestBin = FindValueBinLocation(aValue);
117  e = LinearInterpolationOfEnergy(aValue, closestBin);
118  }
119  return e;
120 }
121 
123 {
124  size_t bin = std::lower_bound(dataVector.begin(), dataVector.end(), aValue)
125  - dataVector.begin() - 1;
126  bin = std::min(bin, numberOfNodes-2);
127  return bin;
128 }
129 
131  size_t bin)
132 {
133  G4double res = binVector[bin];
134  G4double del = dataVector[bin+1] - dataVector[bin];
135  if(del > 0.0) {
136  res += (aValue - dataVector[bin])*(binVector[bin+1] - res)/del;
137  }
138  return res;
139 }
140 
142 {
143  for (size_t i = 0; i < numberOfNodes; i++)
144  {
145  G4cout << binVector[i] << "\t" << dataVector[i] << G4endl;
146  }
147 }
G4PVDataVector dataVector
G4double LinearInterpolationOfEnergy(G4double aValue, size_t theLocBin)
void InsertValues(G4double energy, G4double value)
G4PVDataVector binVector
G4GLOB_DLL std::ostream G4cout
G4PhysicsVectorType type
G4double GetEnergy(G4double aValue)
G4double energy(const ThreeVector &p, const G4double m)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
size_t FindValueBinLocation(G4double aValue)