Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4LEPTSDistribution Class Reference

#include <G4LEPTSDistribution.hh>

Public Member Functions

 G4LEPTSDistribution ()
 
void ReadFile (G4String fileName)
 
G4bool ReadFile (FILE *fp, G4int nData)
 
G4double Sample (G4double, G4double)
 
G4bool IsFileFound () const
 

Detailed Description

Definition at line 36 of file G4LEPTSDistribution.hh.

Constructor & Destructor Documentation

◆ G4LEPTSDistribution()

G4LEPTSDistribution::G4LEPTSDistribution ( )
default

Member Function Documentation

◆ IsFileFound()

G4bool G4LEPTSDistribution::IsFileFound ( ) const
inline

Definition at line 45 of file G4LEPTSDistribution.hh.

45 {
46 return bFileFound;
47 }

◆ ReadFile() [1/2]

G4bool G4LEPTSDistribution::ReadFile ( FILE * fp,
G4int nData )

Definition at line 96 of file G4LEPTSDistribution.cc.

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}
#define NMAX
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85

◆ ReadFile() [2/2]

void G4LEPTSDistribution::ReadFile ( G4String fileName)

Definition at line 33 of file G4LEPTSDistribution.cc.

33 {
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}

◆ Sample()

G4double G4LEPTSDistribution::Sample ( G4double eMin,
G4double eMax )

Definition at line 156 of file G4LEPTSDistribution.cc.

156 {
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}
#define G4UniformRand()
Definition Randomize.hh:52

Referenced by G4LEPTSElossDistr::Sample().


The documentation for this class was generated from the following files: