source: trunk/source/global/management/src/G4PhysicsOrderedFreeVector.cc@ 1276

Last change on this file since 1276 was 1228, checked in by garnier, 16 years ago

update geant4.9.3 tag

File size: 5.3 KB
Line 
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,v 1.13 2009/06/25 10:05:26 vnivanch Exp $
28// GEANT4 tag $Name: geant4-09-03 $
29//
30////////////////////////////////////////////////////////////////////////
31// PhysicsOrderedFreeVector Class Implementation
32////////////////////////////////////////////////////////////////////////
33//
34// File: G4PhysicsOrderedFreeVector.cc
35// Version: 2.0
36// Created: 1996-08-13
37// Author: Juliet Armstrong
38// Updated: 1997-03-25 by Peter Gumplinger
39// > cosmetics (only)
40// 1998-11-11 by Peter Gumplinger
41// > initialize all data members of the base class in
42// derived class constructors
43// 2000-11-11 by H.Kurashige
44// > use STL vector for dataVector and binVector
45// 19 Jun. 2009-06-19 by V.Ivanchenko
46// > removed hidden bin
47//
48// mail: gum@triumf.ca
49//
50////////////////////////////////////////////////////////////////////////
51
52#include "G4PhysicsOrderedFreeVector.hh"
53
54/////////////////////////
55// Class Implementation
56/////////////////////////
57
58 /////////////////
59 // Constructors
60 /////////////////
61
62G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector(G4double *Energies,
63 G4double *Values,
64 size_t VectorLength)
65 : G4PhysicsVector()
66{
67 type = T_G4PhysicsOrderedFreeVector;
68
69 dataVector.reserve(VectorLength);
70 binVector.reserve(VectorLength);
71 numberOfNodes = VectorLength;
72
73 for (size_t i = 0 ; i < VectorLength ; i++)
74 {
75 binVector.push_back(Energies[i]);
76 dataVector.push_back(Values[i]);
77 }
78 edgeMin = binVector[0];
79 edgeMax = binVector[numberOfNodes-1];
80}
81
82G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()
83 : G4PhysicsVector()
84{
85 type = T_G4PhysicsOrderedFreeVector;
86}
87
88 ////////////////
89 // Destructors
90 ////////////////
91
92G4PhysicsOrderedFreeVector::~G4PhysicsOrderedFreeVector() {}
93
94 ////////////
95 // Methods
96 ////////////
97
98void
99G4PhysicsOrderedFreeVector::InsertValues(G4double energy, G4double value)
100{
101 binVector.push_back(energy);
102 dataVector.push_back(value);
103 numberOfNodes++;
104 edgeMin = binVector.front();
105 edgeMax = binVector.back();
106
107}
108
109G4double
110G4PhysicsOrderedFreeVector::GetLowEdgeEnergy(size_t binNumber) const
111{
112 return binVector[binNumber];
113}
114
115G4double
116G4PhysicsOrderedFreeVector::GetEnergy(G4double aValue)
117{
118
119 if (aValue <= GetMinValue()) {
120 return GetMinLowEdgeEnergy();
121 } else if (aValue >= GetMaxValue()) {
122 return GetMaxLowEdgeEnergy();
123 } else {
124 size_t closestBin = FindValueBinLocation(aValue);
125 G4double theEnergy = LinearInterpolationOfEnergy(aValue, closestBin);
126
127 return theEnergy;
128 }
129}
130
131size_t
132G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
133{
134 G4int n1 = 0;
135 G4int n2 = numberOfNodes/2;
136 G4int n3 = numberOfNodes - 1;
137 while (n1 != n3 - 1) {
138 if (aValue > dataVector[n2])
139 { n1 = n2; }
140 else
141 { n3 = n2; }
142 n2 = n1 + (n3 - n1 + 1)/2;
143 }
144 return (size_t)n1;
145}
146
147G4double
148G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
149 size_t theLocBin)
150{
151 G4double intplFactor = (aValue-dataVector[theLocBin])
152 / (dataVector[theLocBin+1]-dataVector[theLocBin]); // Interpolation factor
153
154 return binVector[theLocBin] +
155 ( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
156}
Note: See TracBrowser for help on using the repository browser.