Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 98864 2016-08-15 11:53:26Z 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  : G4PhysicsVector()
56 {
58 }
59 
61  G4double *Values,
62  size_t VectorLength)
63  : G4PhysicsVector()
64 {
66 
67  dataVector.reserve(VectorLength);
68  binVector.reserve(VectorLength);
69 
70  for (size_t i = 0 ; i < VectorLength ; ++i)
71  {
72  InsertValues(Energies[i], Values[i]);
73  }
74 }
75 
77 {}
78 
80 {
81  std::vector<G4double>::iterator binLoc =
82  std::lower_bound(binVector.begin(), binVector.end(), energy);
83 
84  size_t binIdx = binLoc - binVector.begin(); // Iterator difference!
85 
86  std::vector<G4double>::iterator dataLoc = dataVector.begin() + binIdx;
87 
88  binVector.insert(binLoc, energy);
89  dataVector.insert(dataLoc, value);
90 
91  ++numberOfNodes;
92  edgeMin = binVector.front();
93  edgeMax = binVector.back();
94 }
95 
97 {
98  G4double e;
99  if (aValue <= GetMinValue()) {
100  e = edgeMin;
101  } else if (aValue >= GetMaxValue()) {
102  e = edgeMax;
103  } else {
104  size_t closestBin = FindValueBinLocation(aValue);
105  e = LinearInterpolationOfEnergy(aValue, closestBin);
106  }
107  return e;
108 }
109 
110 size_t G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
111 {
112  size_t bin = std::lower_bound(dataVector.begin(), dataVector.end(), aValue)
113  - dataVector.begin() - 1;
114  bin = std::min(bin, numberOfNodes-2);
115  return bin;
116 }
117 
118 G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
119  size_t bin)
120 {
121  G4double res = binVector[bin];
122  G4double del = dataVector[bin+1] - dataVector[bin];
123  if(del > 0.0) {
124  res += (aValue - dataVector[bin])*(binVector[bin+1] - res)/del;
125  }
126  return res;
127 }
G4PVDataVector dataVector
void InsertValues(G4double energy, G4double value)
G4PVDataVector binVector
const XML_Char int const XML_Char * value
Definition: expat.h:331
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
double G4double
Definition: G4Types.hh:76