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

Last change on this file since 835 was 833, checked in by garnier, 16 years ago

import all except CVS

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.10 2006/06/29 19:04:20 gunter Exp $
28// GEANT4 tag $Name:  $
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// mail:        gum@triumf.ca
46//
47//
48////////////////////////////////////////////////////////////////////////
49
50#include "G4PhysicsOrderedFreeVector.hh"
51
52/////////////////////////
53// Class Implementation
54/////////////////////////
55
56        /////////////////
57        // Constructors
58        /////////////////
59
60G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector(G4double *Energies,
61                                                       G4double *Values,
62                                                       size_t VectorLength)
63{
64        type = T_G4PhysicsOrderedFreeVector;
65
66        lastBin = INT_MAX;
67
68        lastEnergy = -DBL_MAX;
69        lastValue = DBL_MAX;
70
71        numberOfBin = 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.front();
79        edgeMax = binVector.back();
80}
81
82G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector()
83{
84        type = T_G4PhysicsOrderedFreeVector;
85
86        lastBin = INT_MAX;
87        lastEnergy = -DBL_MAX;
88        lastValue = DBL_MAX;
89
90        edgeMin = 0.0;
91        edgeMax = 0.0;
92        numberOfBin = 0;
93}
94
95        ////////////////
96        // Destructors
97        ////////////////
98
99G4PhysicsOrderedFreeVector::~G4PhysicsOrderedFreeVector() {}
100
101        ////////////
102        // Methods
103        ////////////
104 
105void 
106G4PhysicsOrderedFreeVector::InsertValues(G4double energy, G4double value)
107{
108        binVector.push_back(energy);
109        dataVector.push_back(value);
110        numberOfBin++;
111        edgeMin = binVector.front();
112        edgeMax = binVector.back();
113
114}
115
116G4double
117G4PhysicsOrderedFreeVector::GetLowEdgeEnergy(size_t binNumber) const
118{
119        return binVector[binNumber];
120} 
121
122G4double
123G4PhysicsOrderedFreeVector::GetEnergy(G4double aValue)
124{
125
126        if (aValue <= GetMinValue()) {
127                return GetMinLowEdgeEnergy();
128        } else if (aValue >= GetMaxValue()) {
129                return GetMaxLowEdgeEnergy();
130        } else { 
131        size_t closestBin = FindValueBinLocation(aValue);
132        G4double theEnergy = LinearInterpolationOfEnergy(aValue, closestBin);
133
134        return theEnergy;
135        }
136}
137
138size_t
139G4PhysicsOrderedFreeVector::FindValueBinLocation(G4double aValue)
140{
141   G4int n1 = 0;
142   G4int n2 = numberOfBin/2;
143   G4int n3 = numberOfBin - 1;
144   while (n1 != n3 - 1) {
145      if (aValue > dataVector[n2])
146         { n1 = n2; }
147      else
148         { n3 = n2; }
149      n2 = n1 + (n3 - n1 + 1)/2;
150   }
151   return (size_t)n1;
152}
153
154G4double
155G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy(G4double aValue,
156                                                        size_t theLocBin)
157{
158  G4double intplFactor = (aValue-dataVector[theLocBin])
159     / (dataVector[theLocBin+1]-dataVector[theLocBin]); // Interpolation factor
160
161  return binVector[theLocBin] +
162         ( binVector[theLocBin+1]-binVector[theLocBin] ) * intplFactor;
163}
Note: See TracBrowser for help on using the repository browser.