Geant4.10
 All Data Structures 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: G4PhysicsOrderedFreeVector.cc 74256 2013-10-02 14:24:02Z gcosmo $
28 //
29 ////////////////////////////////////////////////////////////////////////
30 // PhysicsOrderedFreeVector Class Implementation
31 ////////////////////////////////////////////////////////////////////////
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 //
50 ////////////////////////////////////////////////////////////////////////
51 
53 
54 /////////////////////////
55 // Class Implementation
56 /////////////////////////
57 
58  /////////////////
59  // Constructors
60  /////////////////
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 
81  ////////////////
82  // Destructors
83  ////////////////
84 
86 
87  ////////////
88  // Methods
89  ////////////
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 
111  if (aValue <= GetMinValue()) {
112  return GetMinLowEdgeEnergy();
113  } else if (aValue >= GetMaxValue()) {
114  return GetMaxLowEdgeEnergy();
115  } else {
116  size_t closestBin = FindValueBinLocation(aValue);
117  G4double theEnergy = LinearInterpolationOfEnergy(aValue, closestBin);
118 
119  return theEnergy;
120  }
121 }
122 
123 size_t G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
124 {
125  G4int n1 = 0;
126  G4int n2 = numberOfNodes/2;
127  G4int n3 = numberOfNodes - 1;
128  while (n1 != n3 - 1) {
129  if (aValue > dataVector[n2])
130  { n1 = n2; }
131  else
132  { n3 = n2; }
133  n2 = n1 + (n3 - n1 + 1)/2;
134  }
135  return (size_t)n1;
136 }
137 
138 G4double G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
139  size_t theLocBin)
140 {
141  G4double intplFactor = (aValue-dataVector[theLocBin])
142  / (dataVector[theLocBin+1]-dataVector[theLocBin]); // Interpolation factor
143 
144  return binVector[theLocBin] +
145  ( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
146 }
147 
G4PVDataVector dataVector
void InsertValues(G4double energy, G4double value)
int G4int
Definition: G4Types.hh:78
G4PVDataVector binVector
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
G4PhysicsVectorType type
G4double GetEnergy(G4double aValue)
const XML_Char int const XML_Char * value
double G4double
Definition: G4Types.hh:76