Geant4-11
G4VelocityTable.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// G4VelocityTable class implementation
27//
28// Author: Hisaya Kurashige, 17 August 2011
29// --------------------------------------------------------------------
30
31#include "G4VelocityTable.hh"
33#include "G4StateManager.hh"
34#include "G4ApplicationState.hh"
35#include "G4Log.hh"
36#include "G4Exp.hh"
37
38#include "G4ios.hh"
39
41
42// --------------------------------------------------------------------
44{
46}
47
48// --------------------------------------------------------------------
50{
51 dataVector.clear();
52 binVector.clear();
53}
54
55// --------------------------------------------------------------------
57{
58 // const G4double g4log10 = std::log(10.);
59
60 dataVector.clear();
61 binVector.clear();
62 dBin = G4Log(maxT / minT) / NbinT;
64
65 numberOfNodes = NbinT + 1;
67 binVector.reserve(numberOfNodes);
68
69 binVector.push_back(minT);
70 dataVector.push_back(0.0);
71
72 for(std::size_t i = 1; i < numberOfNodes - 1; ++i)
73 {
74 binVector.push_back(G4Exp((baseBin + i) * dBin));
75 dataVector.push_back(0.0);
76 }
77 binVector.push_back(maxT);
78 dataVector.push_back(0.0);
79
80 edgeMin = binVector[0];
82
83 for(G4int i = 0; i <= NbinT; ++i)
84 {
85 G4double T = binVector[i];
86 dataVector[i] = c_light * std::sqrt(T * (T + 2.)) / (T + 1.0);
87 }
88
89 return;
90}
91
92// --------------------------------------------------------------------
93std::size_t G4VelocityTable::FindBinLocation(G4double theEnergy) const
94{
95 // For G4PhysicsLogVector, FindBinLocation is implemented using
96 // a simple arithmetic calculation.
97 //
98 // Because this is a virtual function, it is accessed through a
99 // pointer to the G4PhysicsVector object for most usages. In this
100 // case, 'inline' will not be invoked. However, there is a possibility
101 // that the user access to the G4PhysicsLogVector object directly and
102 // not through pointers or references. In this case, the 'inline' will
103 // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
104
105 // const G4double g4log10 = G4Log(10.);
106 return std::size_t(G4Log(theEnergy) / dBin - baseBin);
107}
108
109// --------------------------------------------------------------------
111{
112 // Use cache for speed up - check if the value 'theEnergy' is same as the
113 // last call. If it is same, then use the last bin location. Also the
114 // value 'theEnergy' lies between the last energy and low edge of of the
115 // bin of last call, then the last bin location is used
116
117 if(theEnergy == lastEnergy)
118 {
119 }
120 else if(theEnergy < lastEnergy && theEnergy >= binVector[lastBin])
121 {
122 lastEnergy = theEnergy;
124 }
125 else if(theEnergy <= edgeMin)
126 {
127 lastBin = 0;
130 }
131 else if(theEnergy >= edgeMax)
132 {
136 }
137 else
138 {
139 lastBin = (std::size_t)(G4Log(theEnergy) / dBin - baseBin);
141 {
142 --lastBin;
143 } // VI: fix possible precision lost
144 lastEnergy = theEnergy;
146 }
147 return lastValue;
148}
149
150// --------------------------------------------------------------------
152{
153 if(theInstance == nullptr)
154 {
156 theInstance = inst.Instance();
157 }
158 return theInstance;
159}
160
161// --------------------------------------------------------------------
164{
165 if(theInstance == nullptr)
166 {
168 }
169
171 G4ApplicationState currentState = stateManager->GetCurrentState();
172
173 // check if state is outside event loop
174 if(!(currentState == G4State_Idle || currentState == G4State_PreInit))
175 {
176 G4Exception("G4VelocityTable::SetVelocityTableProperties()", "Track101",
178 "Can modify only in PreInit or Idle state : Method ignored.");
179 return;
180 }
181
182 if(nbin > 100)
183 theInstance->NbinT = nbin;
184 if((t_min < t_max) && (t_min > 0.))
185 {
186 theInstance->minT = t_min;
187 theInstance->maxT = t_max;
188 }
190}
191
192// --------------------------------------------------------------------
194{
195 return GetVelocityTable()->maxT;
196}
197
198// --------------------------------------------------------------------
200{
201 return GetVelocityTable()->minT;
202}
203
204// --------------------------------------------------------------------
206{
207 return GetVelocityTable()->NbinT;
208}
G4ApplicationState
@ G4State_Idle
@ G4State_PreInit
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition: G4Exp.hh:179
G4double G4Log(G4double x)
Definition: G4Log.hh:226
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
static G4VelocityTable * GetVelocityTable()
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
std::size_t numberOfNodes
static G4ThreadLocal G4VelocityTable * theInstance
std::size_t lastBin
G4VTDataVector dataVector
G4double Value(G4double theEnergy)
static G4double GetMaxTOfVelocityTable()
G4VTDataVector binVector
static G4double GetMinTOfVelocityTable()
G4double Interpolation() const
void PrepareVelocityTable()
std::size_t FindBinLocation(G4double theEnergy) const
static G4int GetNbinOfVelocityTable()
float c_light
Definition: hepunit.py:256
#define G4ThreadLocal
Definition: tls.hh:77