Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VelocityTable.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: G4VelocityTable.cc 107603 2017-11-27 07:21:59Z gcosmo $
28 //
29 //
30 //---------------------------------------------------------------
31 //
32 // G4VelocityTable.cc
33 //
34 // class description:
35 // This class keeps a table of velocity as a function of
36 // the ratio kinetic erngy and mass
37 //
38 //---------------------------------------------------------------
39 // created 17.Aug. 2011 H.Kurashige
40 //
41 
42 #include "G4VelocityTable.hh"
43 #include "G4PhysicalConstants.hh"
44 #include "G4StateManager.hh"
45 #include "G4ApplicationState.hh"
46 #include "G4Log.hh"
47 #include "G4Exp.hh"
48 
49 #include "G4ios.hh"
50 
52 
56  : edgeMin(0.), edgeMax(0.), numberOfNodes(0),
57  dBin(0.), baseBin(0.),
58  lastEnergy(-DBL_MAX), lastValue(0.), lastBin(0),
59  maxT( 1000.0 ), minT( 0.0001 ), NbinT( 500 )
60 {
62 }
63 
67 {
68  dataVector.clear();
69  binVector.clear();
70 }
71 
72 
76 {
77  //const G4double g4log10 = std::log(10.);
78 
79  dataVector.clear();
80  binVector.clear();
83 
84  numberOfNodes = NbinT + 1;
85  dataVector.reserve(numberOfNodes);
86  binVector.reserve(numberOfNodes);
87 
88  binVector.push_back(minT);
89  dataVector.push_back(0.0);
90 
91  for (size_t i=1; i<numberOfNodes-1; i++){
92  binVector.push_back(G4Exp((baseBin+i)*dBin));
93  dataVector.push_back(0.0);
94  }
95  binVector.push_back(maxT);
96  dataVector.push_back(0.0);
97 
98  edgeMin = binVector[0];
99  edgeMax = binVector[numberOfNodes-1];
100 
101  for (G4int i=0; i<=NbinT; i++){
102  G4double T = binVector[i];
103  dataVector[i]= c_light*std::sqrt(T*(T+2.))/(T+1.0);
104  }
105 
106  return;
107 }
108 
110 {
111  // For G4PhysicsLogVector, FindBinLocation is implemented using
112  // a simple arithmetic calculation.
113  //
114  // Because this is a virtual function, it is accessed through a
115  // pointer to the G4PhyiscsVector object for most usages. In this
116  // case, 'inline' will not be invoked. However, there is a possibility
117  // that the user access to the G4PhysicsLogVector object directly and
118  // not through pointers or references. In this case, the 'inline' will
119  // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
120 
121  //const G4double g4log10 = G4Log(10.);
122  return size_t( G4Log(theEnergy)/dBin - baseBin );
123 }
124 
126 {
127  // Use cache for speed up - check if the value 'theEnergy' is same as the
128  // last call. If it is same, then use the last bin location. Also the
129  // value 'theEnergy' lies between the last energy and low edge of of the
130  // bin of last call, then the last bin location is used.
131 
132  if( theEnergy == lastEnergy ) {
133 
134  } else if( theEnergy < lastEnergy
135  && theEnergy >= binVector[lastBin]) {
136  lastEnergy = theEnergy;
138 
139  } else if( theEnergy <= edgeMin ) {
140  lastBin = 0;
142  lastValue = dataVector[0];
143 
144  } else if( theEnergy >= edgeMax ){
145  lastBin = numberOfNodes-1;
148 
149  } else {
150  lastBin = (size_t)( G4Log(theEnergy)/dBin - baseBin );
151  if(lastBin == numberOfNodes) { --lastBin; } // VI: fix possible precision lost
152  lastEnergy = theEnergy;
154 
155  }
156  return lastValue;
157 }
158 
160 // Static methods
161 
165 {
166  if (!theInstance) {
168  theInstance = inst.Instance();
169  }
170  return theInstance;
171 }
172 
176 {
177  if (theInstance == nullptr) { GetVelocityTable(); }
178 
180  G4ApplicationState currentState = stateManager->GetCurrentState();
181 
182  // check if state is outside event loop
183  if(!(currentState==G4State_Idle||currentState==G4State_PreInit)){
184  G4Exception("G4VelocityTable::SetVelocityTableProperties",
185  "Track101", JustWarning,
186  "Can modify only in PreInit or Idle state : Method ignored.");
187  return;
188  }
189 
190  if (nbin > 100 ) theInstance->NbinT = nbin;
191  if ((t_min < t_max)&&(t_min>0.)) {
192  theInstance->minT = t_min;
193  theInstance->maxT = t_max;
194  }
196 }
197 
201 {
202  return GetVelocityTable()->maxT;
203 }
204 
207 {
209  return GetVelocityTable()->minT;
210 }
211 
214 {
216  return GetVelocityTable()->NbinT;
217 }
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
G4VTDataVector binVector
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:183
static G4ThreadLocal G4VelocityTable * theInstance
G4double Value(G4double theEnergy)
static G4VelocityTable * GetVelocityTable()
G4double Interpolation() const
size_t FindBinLocation(G4double theEnergy) const
static G4double GetMinTOfVelocityTable()
static G4double GetMaxTOfVelocityTable()
void PrepareVelocityTable()
#define G4ThreadLocal
Definition: tls.hh:69
G4double G4Log(G4double x)
Definition: G4Log.hh:230
double G4double
Definition: G4Types.hh:76
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
static constexpr double c_light
G4ApplicationState GetCurrentState() const
G4ApplicationState
G4VTDataVector dataVector
static G4int GetNbinOfVelocityTable()
#define DBL_MAX
Definition: templates.hh:83
static G4StateManager * GetStateManager()