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
G4PhysicsOrderedFreeVector.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file G4PhysicsOrderedFreeVector.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
//
29
// PhysicsOrderedFreeVector Class Implementation
31
//
32
// File: G4PhysicsOrderedFreeVector.cc
33
// Version: 2.0
34
// Created: 1996-08-13
35
// Author: Juliet Armstrong
36
// Updated: 1997-03-25 by Peter Gumplinger
37
// > cosmetics (only)
38
// 1998-11-11 by Peter Gumplinger
39
// > initialize all data members of the base class in
40
// derived class constructors
41
// 2000-11-11 by H.Kurashige
42
// > use STL vector for dataVector and binVector
43
// 2009-06-19 by V.Ivanchenko
44
// > removed hidden bin
45
// 2013-10-02 by V.Ivanchenko removed FindBinLocation
46
//
47
// mail: gum@triumf.ca
48
//
50
51
#include "
G4PhysicsOrderedFreeVector.hh
"
52
53
G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector
()
54
:
G4PhysicsVector
()
55
{
56
type
=
T_G4PhysicsOrderedFreeVector
;
57
}
58
59
G4PhysicsOrderedFreeVector::G4PhysicsOrderedFreeVector
(
G4double
*Energies,
60
G4double
*Values,
61
size_t
VectorLength)
62
:
G4PhysicsVector
()
63
{
64
type
=
T_G4PhysicsOrderedFreeVector
;
65
66
dataVector
.reserve(VectorLength);
67
binVector
.reserve(VectorLength);
68
69
for
(
size_t
i = 0 ; i < VectorLength ; ++i)
70
{
71
InsertValues
(Energies[i], Values[i]);
72
}
73
}
74
75
G4PhysicsOrderedFreeVector::~G4PhysicsOrderedFreeVector
()
76
{}
77
78
void
G4PhysicsOrderedFreeVector::InsertValues
(
G4double
energy
,
G4double
value
)
79
{
80
std::vector<G4double>::iterator binLoc =
81
std::lower_bound(
binVector
.begin(),
binVector
.end(),
energy
);
82
83
size_t
binIdx = binLoc -
binVector
.begin();
// Iterator difference!
84
85
std::vector<G4double>::iterator dataLoc =
dataVector
.begin() + binIdx;
86
87
binVector
.insert(binLoc, energy);
88
dataVector
.insert(dataLoc, value);
89
90
++
numberOfNodes
;
91
edgeMin
=
binVector
.front();
92
edgeMax
=
binVector
.back();
93
}
94
95
G4double
G4PhysicsOrderedFreeVector::GetEnergy
(
G4double
aValue)
96
{
97
G4double
e
;
98
if
(aValue <=
GetMinValue
()) {
99
e =
edgeMin
;
100
}
else
if
(aValue >=
GetMaxValue
()) {
101
e =
edgeMax
;
102
}
else
{
103
size_t
closestBin =
FindValueBinLocation
(aValue);
104
e =
LinearInterpolationOfEnergy
(aValue, closestBin);
105
}
106
return
e
;
107
}
108
109
size_t
G4PhysicsOrderedFreeVector::FindValueBinLocation
(
G4double
aValue)
110
{
111
size_t
bin
= std::lower_bound(
dataVector
.begin(),
dataVector
.end(), aValue)
112
-
dataVector
.begin() - 1;
113
bin =
std::min
(bin,
numberOfNodes
-2);
114
return
bin
;
115
}
116
117
G4double
G4PhysicsOrderedFreeVector::LinearInterpolationOfEnergy
(
G4double
aValue,
118
size_t
bin
)
119
{
120
G4double
res =
binVector
[
bin
];
121
G4double
del =
dataVector
[bin+1] -
dataVector
[
bin
];
122
if
(del > 0.0) {
123
res += (aValue - dataVector[
bin
])*(
binVector
[bin+1] - res)/del;
124
}
125
return
res;
126
}
geant4
tree
geant4-10.6-release
source
global
management
src
G4PhysicsOrderedFreeVector.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:21
using
1.8.2 with
ECCE GitHub integration