Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4PhysicsOrderedFreeVector.cc
이 파일의 문서화 페이지로 가기
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 
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 
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 binVector
size_t FindValueBinLocation(G4double aValue)
void InsertValues(G4double energy, G4double value)
G4double GetEnergy(G4double aValue)
G4PhysicsVectorType type
double G4double
Definition: G4Types.hh:76
const XML_Char int const XML_Char * value
Definition: expat.h:331
double energy
Definition: plottest35.C:25
G4PVDataVector dataVector
float bin[41]
Definition: plottest35.C:14
G4double LinearInterpolationOfEnergy(G4double aValue, size_t theLocBin)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments