ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VelocityTable.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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 //
28 //
29 //---------------------------------------------------------------
30 //
31 // G4VelocityTable.cc
32 //
33 // class description:
34 // This class keeps a table of velocity as a function of
35 // the ratio kinetic erngy and mass
36 //
37 //---------------------------------------------------------------
38 // created 17.Aug. 2011 H.Kurashige
39 //
40 
41 #include "G4VelocityTable.hh"
42 #include "G4PhysicalConstants.hh"
43 #include "G4StateManager.hh"
44 #include "G4ApplicationState.hh"
45 #include "G4Log.hh"
46 #include "G4Exp.hh"
47 
48 #include "G4ios.hh"
49 
51 
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 {
61 }
62 
66 {
67  dataVector.clear();
68  binVector.clear();
69 }
70 
71 
75 {
76  //const G4double g4log10 = std::log(10.);
77 
78  dataVector.clear();
79  binVector.clear();
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(G4Exp((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 
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 - 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;
137 
138  } else if( theEnergy <= edgeMin ) {
139  lastBin = 0;
141  lastValue = dataVector[0];
142 
143  } else if( theEnergy >= edgeMax ){
144  lastBin = numberOfNodes-1;
147 
148  } else {
149  lastBin = (size_t)( G4Log(theEnergy)/dBin - baseBin );
150  if(lastBin == numberOfNodes) { --lastBin; } // VI: fix possible precision lost
151  lastEnergy = theEnergy;
153 
154  }
155  return lastValue;
156 }
157 
159 // Static methods
160 
164 {
165  if (!theInstance) {
167  theInstance = inst.Instance();
168  }
169  return theInstance;
170 }
171 
175 {
176  if (theInstance == nullptr) { GetVelocityTable(); }
177 
179  G4ApplicationState currentState = stateManager->GetCurrentState();
180 
181  // check if state is outside event loop
182  if(!(currentState==G4State_Idle||currentState==G4State_PreInit)){
183  G4Exception("G4VelocityTable::SetVelocityTableProperties",
184  "Track101", JustWarning,
185  "Can modify only in PreInit or Idle state : Method ignored.");
186  return;
187  }
188 
189  if (nbin > 100 ) theInstance->NbinT = nbin;
190  if ((t_min < t_max)&&(t_min>0.)) {
191  theInstance->minT = t_min;
192  theInstance->maxT = t_max;
193  }
195 }
196 
200 {
201  return GetVelocityTable()->maxT;
202 }
203 
206 
207 {
208  return GetVelocityTable()->minT;
209 }
210 
213 
214 {
215  return GetVelocityTable()->NbinT;
216 }