Geant4
11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LEPTSDistribution.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
#include "
G4LEPTSDistribution.hh
"
27
28
29
G4LEPTSDistribution::G4LEPTSDistribution
()
30
=
default
;
31
32
33
void
G4LEPTSDistribution::ReadFile
(
G4String
fileName) {
34
35
G4int
eB, out, out2;
36
float
float_data1,float_data2;
37
G4double
sum, esum;
38
FILE * fp;
39
40
for
(eB=0;eB<10000;eB++){
41
E[eB]=0.0;
42
f[eB]=0.0;
43
F[eB]=0.0;
44
eF[eB]=0.0;
45
}
46
47
if
((fp=fopen(fileName.c_str(),
"r"
))==
nullptr
){
48
//G4cout << "Error reading " << fileName << G4endl;
49
NoBins = 0;
50
bFileFound =
false
;
51
return
;
52
}
53
54
bFileFound =
true
;
55
// G4cout << "Read Distro (" << fileName << ") " << G4endl;
56
out=1;
57
eB=1;
58
while
(out==1){
59
out = fscanf(fp,
"%f \n"
,&float_data1);
60
out2 = fscanf(fp,
"%f \n"
,&float_data2);
61
if
(out==1 && out2==1){
62
E[eB]=(
G4double
)float_data1;
63
f[eB]=(
G4double
)float_data2;
64
eB++;
65
}
66
}
67
68
fclose(fp);
69
70
NoBins=eB-1;
//=1272+1 or 9607+1;
71
72
if
( NoBins >=
NMAX
)
73
printf(
"ERROR !!!! Eloss NoBins= %d \n"
, NoBins);
74
75
sum=0.0;
76
esum=0.0;
77
for
(eB=0;eB<=NoBins;eB++) {
78
if
( f[eB] > 0) {
79
sum+=f[eB];
80
esum+=E[eB]*f[eB];
81
}
82
F[eB]=sum;
83
eF[eB]=esum;
84
}
85
86
// if( verboseLevel >= 1 ) G4cout << "Norm: " << F[NoBins] << " NoBins: "<< NoBins << G4endl;
87
88
for
(eB=0;eB<=NoBins;eB++) {
89
eF[eB] = eF[eB]/F[eB];
90
F[eB] = F[eB]/F[NoBins];
91
}
92
//for (eB=0;eB<=NoBins;eB++)
93
//G4cout << "eff " << E[eB] << " " << f[eB] << " " << F[eB] << "\n";
94
}
95
96
G4bool
G4LEPTSDistribution::ReadFile
( FILE* fp,
G4int
nData )
97
{
98
99
G4int
eB, out, out2;
100
float
float_data1,float_data2;
101
G4double
sum, esum;
102
103
for
(eB=0;eB<10000;eB++){
104
E[eB]=0.0;
105
f[eB]=0.0;
106
F[eB]=0.0;
107
eF[eB]=0.0;
108
}
109
110
bFileFound =
true
;
111
out=1;
112
eB=1;
113
114
for
(
G4int
id
= 0;
id
< nData;
id
++ ){
115
out = fscanf(fp,
"%f \n"
,&float_data1);
116
out2 = fscanf(fp,
"%f \n"
,&float_data2);
117
if
(out==1 && out2==1){
118
E[eB]=(
G4double
)float_data1;
119
f[eB]=(
G4double
)float_data2;
120
eB++;
121
}
else
{
122
return
true
;
123
}
124
}
125
126
NoBins=eB-1;
//=1272+1 or 9607+1;
127
128
if
( NoBins >=
NMAX
)
129
printf(
"ERROR !!!! Eloss NoBins= %d \n"
, NoBins);
130
131
sum=0.0;
132
esum=0.0;
133
for
(eB=0;eB<=NoBins;eB++) {
134
if
( f[eB] > 0) {
135
sum+=f[eB];
136
esum+=E[eB]*f[eB];
137
}
138
F[eB]=sum;
139
eF[eB]=esum;
140
}
141
142
//if( verboseLevel >= 1 ) G4cout << "Norm: " << F[NoBins] << " NoBins: "<< NoBins << G4endl;
143
144
for
(eB=0;eB<=NoBins;eB++) {
145
eF[eB] = eF[eB]/F[eB];
146
F[eB] = F[eB]/F[NoBins];
147
}
148
//for (eB=0;eB<=NoBins;eB++)
149
//G4cout << "eff " << E[eB] << " " << f[eB] << " " << F[eB] << "\n";
150
151
return
false
;
152
}
153
154
155
156
G4double
G4LEPTSDistribution::Sample
(
G4double
eMin,
G4double
eMax) {
157
// Sample Energy from Cumulative distr. G4interval [eMin, eMax]
158
159
if
( eMin > eMax)
return
0.0;
160
161
G4int
i,j,k=0, iMin, iMax;
162
163
i=0; j=NoBins;
164
while
((j-i)>1) {
165
k=(i+j)/2;
166
if
( E[k] < eMax ) i=k;
167
else
j=k;
168
}
169
iMax = i;
170
171
i=0; j=NoBins;
172
while
((j-i)>1) {
173
k=(i+j)/2;
174
if
( E[k] < eMin ) i=k;
175
else
j=k;
176
}
177
iMin = i;
178
179
G4double
rnd = F[iMin] + (F[iMax] - F[iMin]) *
G4UniformRand
();
180
181
i=0; j=NoBins;
182
while
((j-i)>1) {
183
k=(i+j)/2;
184
if
( F[k]<rnd) i=k;
185
else
j=k;
186
}
187
188
G4double
Sampled = E[k];
189
190
if
( Sampled < eMin) Sampled = eMin;
191
else
if
( Sampled > eMax) Sampled = eMax;
192
193
return
Sampled;
194
}
G4LEPTSDistribution.hh
NMAX
#define NMAX
Definition
G4LEPTSDistribution.hh:51
G4double
double G4double
Definition
G4Types.hh:83
G4bool
bool G4bool
Definition
G4Types.hh:86
G4int
int G4int
Definition
G4Types.hh:85
G4UniformRand
#define G4UniformRand()
Definition
Randomize.hh:52
G4LEPTSDistribution::Sample
G4double Sample(G4double, G4double)
Definition
G4LEPTSDistribution.cc:156
G4LEPTSDistribution::ReadFile
void ReadFile(G4String fileName)
Definition
G4LEPTSDistribution.cc:33
G4LEPTSDistribution::G4LEPTSDistribution
G4LEPTSDistribution()
G4String
Definition
G4String.hh:62
geant4-v11.2.2
source
processes
electromagnetic
dna
models
src
G4LEPTSDistribution.cc
Generated by
1.12.0