ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
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
50
G4ThreadLocal
G4VelocityTable
*
G4VelocityTable::theInstance
=
nullptr
;
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
=
G4Log
(
maxT
/
minT
)/
NbinT
;
81
baseBin
=
G4Log
(
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(
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
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
-
baseBin
);
122
}
123
124
G4double
G4VelocityTable::Value
(
G4double
theEnergy)
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 = (size_t)(
G4Log
(theEnergy)/
dBin
-
baseBin
);
150
if
(lastBin ==
numberOfNodes
) { --
lastBin
; }
// VI: fix possible precision lost
151
lastEnergy
= theEnergy;
152
lastValue
=
Interpolation
();
153
154
}
155
return
lastValue
;
156
}
157
159
// Static methods
160
162
G4VelocityTable
*
G4VelocityTable::GetVelocityTable
()
164
{
165
if
(!
theInstance
) {
166
static
G4ThreadLocalSingleton<G4VelocityTable>
inst;
167
theInstance
= inst.
Instance
();
168
}
169
return
theInstance
;
170
}
171
173
void
G4VelocityTable::SetVelocityTableProperties
(
G4double
t_max,
G4double
t_min,
G4int
nbin)
175
{
176
if
(
theInstance
==
nullptr
) {
GetVelocityTable
(); }
177
178
G4StateManager
* stateManager =
G4StateManager::GetStateManager
();
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
}
194
theInstance
->
PrepareVelocityTable
();
195
}
196
198
G4double
G4VelocityTable::GetMaxTOfVelocityTable
()
200
{
201
return
GetVelocityTable
()->
maxT
;
202
}
203
205
G4double
G4VelocityTable::GetMinTOfVelocityTable
()
206
207
{
208
return
GetVelocityTable
()->
minT
;
209
}
210
212
G4int
G4VelocityTable::GetNbinOfVelocityTable
()
213
214
{
215
return
GetVelocityTable
()->
NbinT
;
216
}
geant4
tree
geant4-10.6-release
source
track
src
G4VelocityTable.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:53
using
1.8.2 with
ECCE GitHub integration