Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 // 19 Jun. 2009-06-19 by V.Ivanchenko
45 // > removed hidden bin
46 //
47 // mail: gum@triumf.ca
48 //
50 
52 
54 // Class Implementation
56 
58  // Constructors
60 
62  G4double *Values,
63  size_t VectorLength)
64  : G4PhysicsVector()
65 {
67 
68  for (size_t i = 0 ; i < VectorLength ; i++)
69  {
70  InsertValues(Energies[i], Values[i]);
71  }
72 }
73 
75  : G4PhysicsVector()
76 {
78 }
79 
81  // Destructors
83 
85 
87  // Methods
89 
91 {
92  std::vector<G4double>::iterator binLoc =
93  std::lower_bound(binVector.begin(), binVector.end(), energy);
94 
95  size_t binIdx = binLoc - binVector.begin(); // Iterator difference!
96 
97  std::vector<G4double>::iterator dataLoc = dataVector.begin() + binIdx;
98 
99  binVector.insert(binLoc, energy);
100  dataVector.insert(dataLoc, value);
101 
102  numberOfNodes++;
103  edgeMin = binVector.front();
104  edgeMax = binVector.back();
105 }
106 
108 {
109  return binVector[binNumber];
110 }
111 
113 {
114 
115  if (aValue <= GetMinValue()) {
116  return GetMinLowEdgeEnergy();
117  } else if (aValue >= GetMaxValue()) {
118  return GetMaxLowEdgeEnergy();
119  } else {
120  size_t closestBin = FindValueBinLocation(aValue);
121  G4double theEnergy = LinearInterpolationOfEnergy(aValue, closestBin);
122 
123  return theEnergy;
124  }
125 }
126 
127 size_t G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
128 {
129  G4int n1 = 0;
130  G4int n2 = numberOfNodes/2;
131  G4int n3 = numberOfNodes - 1;
132  while (n1 != n3 - 1) {
133  if (aValue > dataVector[n2])
134  { n1 = n2; }
135  else
136  { n3 = n2; }
137  n2 = n1 + (n3 - n1 + 1)/2;
138  }
139  return (size_t)n1;
140 }
141 
142 G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
143  size_t theLocBin)
144 {
145  G4double intplFactor = (aValue-dataVector[theLocBin])
146  / (dataVector[theLocBin+1]-dataVector[theLocBin]); // Interpolation factor
147 
148  return binVector[theLocBin] +
149  ( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
150 }
151 
152 
153 size_t G4PhysicsOrderedFreeVector::FindBinLocation(G4double theEnergy) const
154 {
155  G4int n1 = 0;
156  G4int n2 = numberOfNodes/2;
157  G4int n3 = numberOfNodes - 1;
158  while (n1 != n3 - 1)
159  {
160  if (theEnergy > binVector[n2])
161  { n1 = n2; }
162  else
163  { n3 = n2; }
164  n2 = n1 + (n3 - n1 + 1)/2;
165  }
166  return (size_t)n1;
167 }