Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
27 // $Id: G4VelocityTable.cc 96764 2016-05-04 13:09:31Z 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 
48 #include "G4ios.hh"
49 
50 G4ThreadLocal G4VelocityTable* G4VelocityTable::theInstance = 0;
51 
53 G4VelocityTable::G4VelocityTable()
55  : edgeMin(0.), edgeMax(0.), numberOfNodes(0),
56  dBin(0.), baseBin(0.),
57  lastEnergy(-DBL_MAX), lastValue(0.), lastBin(0),
58  maxT( 1000.0 ), minT( 0.0001 ), NbinT( 500 )
59 {
60  PrepareVelocityTable();
61 }
62 
64 G4VelocityTable::~G4VelocityTable()
66 {
67  dataVector.clear();
68  binVector.clear();
69 }
70 
71 
73 void G4VelocityTable::PrepareVelocityTable()
75 {
76  const G4double g4log10 = std::log(10.);
77 
78  dataVector.clear();
79  binVector.clear();
80  dBin = std::log10(maxT/minT)/NbinT;
81  baseBin = std::log10(minT)/dBin;
82 
83  numberOfNodes = NbinT + 1;
84  dataVector.reserve(numberOfNodes);
85  binVector.reserve(numberOfNodes);
86 
87  binVector.push_back(minT);
88  dataVector.push_back(0.0);
89 
90  for (size_t i=1; i<numberOfNodes-1; i++){
91  binVector.push_back(std::exp(g4log10*(baseBin+i)*dBin));
92  dataVector.push_back(0.0);
93  }
94  binVector.push_back(maxT);
95  dataVector.push_back(0.0);
96 
97  edgeMin = binVector[0];
98  edgeMax = binVector[numberOfNodes-1];
99 
100  for (G4int i=0; i<=NbinT; i++){
101  G4double T = binVector[i];
102  dataVector[i]= c_light*std::sqrt(T*(T+2.))/(T+1.0);
103  }
104 
105  return;
106 }
107 
108 size_t G4VelocityTable::FindBinLocation(G4double theEnergy) const
109 {
110  // For G4PhysicsLogVector, FindBinLocation is implemented using
111  // a simple arithmetic calculation.
112  //
113  // Because this is a virtual function, it is accessed through a
114  // pointer to the G4PhyiscsVector object for most usages. In this
115  // case, 'inline' will not be invoked. However, there is a possibility
116  // that the user access to the G4PhysicsLogVector object directly and
117  // not through pointers or references. In this case, the 'inline' will
118  // be invoked. (See R.B.Murray, "C++ Strategies and Tactics", Chap.6.6)
119 
120  const G4double g4log10 = G4Log(10.);
121  return size_t( G4Log(theEnergy)/dBin/g4log10 - baseBin );
122 }
123 
125 {
126  // Use cache for speed up - check if the value 'theEnergy' is same as the
127  // last call. If it is same, then use the last bin location. Also the
128  // value 'theEnergy' lies between the last energy and low edge of of the
129  // bin of last call, then the last bin location is used.
130 
131  if( theEnergy == lastEnergy ) {
132 
133  } else if( theEnergy < lastEnergy
134  && theEnergy >= binVector[lastBin]) {
135  lastEnergy = theEnergy;
136  lastValue = Interpolation();
137 
138  } else if( theEnergy <= edgeMin ) {
139  lastBin = 0;
140  lastEnergy = edgeMin;
141  lastValue = dataVector[0];
142 
143  } else if( theEnergy >= edgeMax ){
144  lastBin = numberOfNodes-1;
145  lastEnergy = edgeMax;
146  lastValue = dataVector[lastBin];
147 
148  } else {
149  lastBin = FindBinLocation(theEnergy);
150  lastEnergy = theEnergy;
151  lastValue = Interpolation();
152 
153  }
154  return lastValue;
155 }
156 
158 // Static methods
159 
163 {
164  if (!theInstance) { theInstance = new G4VelocityTable(); }
165  return theInstance;
166 }
167 
171 {
172  if (theInstance == 0) { theInstance = new G4VelocityTable(); }
173 
175  G4ApplicationState currentState = stateManager->GetCurrentState();
176 
177  // check if state is outside event loop
178  if(!(currentState==G4State_Idle||currentState==G4State_PreInit)){
179  G4Exception("G4VelocityTable::SetVelocityTableProperties",
180  "Track101", JustWarning,
181  "Can modify only in PreInit or Idle state : Method ignored.");
182  return;
183  }
184 
185  if (nbin > 100 ) theInstance->NbinT = nbin;
186  if ((t_min < t_max)&&(t_min>0.)) {
187  theInstance->minT = t_min;
188  theInstance->maxT = t_max;
189  }
190  theInstance->PrepareVelocityTable();
191 }
192 
196 {
197  return GetVelocityTable()->maxT;
198 }
199 
202 {
204  return GetVelocityTable()->minT;
205 }
206 
209 {
211  return GetVelocityTable()->NbinT;
212 }
static G4VelocityTable * GetVelocityTable()
static G4double GetMinTOfVelocityTable()
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static G4StateManager * GetStateManager()
static G4int GetNbinOfVelocityTable()
G4ApplicationState GetCurrentState() const
static void SetVelocityTableProperties(G4double t_max, G4double t_min, G4int nbin)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double G4Log(G4double x)
Definition: G4Log.hh:230
double G4double
Definition: G4Types.hh:76
static G4double GetMaxTOfVelocityTable()
#define DBL_MAX
Definition: templates.hh:83
G4double Value(G4double theEnergy)
float c_light
Definition: hepunit.py:257
G4ApplicationState