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

#include <G4DistributionGenerator.hh>

Public Member Functions

 G4DistributionGenerator (std::vector< G4double > &x, std::vector< G4double > &values)
 
 G4DistributionGenerator ()
 
 ~G4DistributionGenerator ()
 
G4double Generate (G4double ranflat)
 

Detailed Description

Definition at line 41 of file G4DistributionGenerator.hh.

Constructor & Destructor Documentation

◆ G4DistributionGenerator() [1/2]

G4DistributionGenerator::G4DistributionGenerator ( std::vector< G4double > &  x,
std::vector< G4double > &  values 
)

Definition at line 42 of file G4DistributionGenerator.cc.

45{
46 G4HadronicDeprecate("G4DistributionGenerator");
47 _x = x;
48
49 // Check boundaries: must be size(x) = size(values) + 1
50 if (x.size() != (values.size() + 1))
51 { G4cout << " Inconsistent parameters in G4DistributionGenerator "
52 << G4endl;
53 }
54 assert (x.size() == (values.size() + 1));
55
56 G4double tot = 0.;
57 unsigned int i;
58 for (i=0; i<values.size(); i++) { tot += values[i]; }
59 assert (tot > 0.);
60
61 _cumProb.push_back(0.);
62 // _cumProb.push_back(values[0] / tot);
63 G4double sum = 0.;
64 for (i=0; i<values.size(); i++)
65 {
66 sum += values[i];
67 _cumProb.push_back(sum / tot); }
68
69 // Debugging
70 /*
71 for (i=0; i<values.size(); i++)
72 { G4cout << values[i] << " " ; }
73 G4cout << " Integral = " << tot << G4endl;
74 for (i=0; i<_cumProb.size(); i++)
75 {
76 G4cout << "Variable " << _x[i]
77 << " --- cumProb = " << _cumProb[i] << G4endl;
78 }
79 */
80 // End of debugging
81
82}
#define G4HadronicDeprecate(name)
double G4double
Definition: G4Types.hh:64
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout

◆ G4DistributionGenerator() [2/2]

G4DistributionGenerator::G4DistributionGenerator ( )

◆ ~G4DistributionGenerator()

G4DistributionGenerator::~G4DistributionGenerator ( )

Definition at line 86 of file G4DistributionGenerator.cc.

87{
88}

Member Function Documentation

◆ Generate()

G4double G4DistributionGenerator::Generate ( G4double  ranflat)

Definition at line 91 of file G4DistributionGenerator.cc.

92{
93 G4double xRandom = _x[0];
94
95 G4int bin = _cumProb.size() - 1;
96 unsigned int i;
97 for (i=1; i<_cumProb.size(); i++)
98 {
99 if (ranflat >= _cumProb[i-1] && ranflat < _cumProb[i])
100 {
101 bin = i - 1;
102 }
103 }
104
105 if (bin >= 0 && bin < static_cast<G4int>(_cumProb.size()-1) && bin < static_cast<G4int>(_x.size()-1))
106 {
107 G4double coeff = (ranflat - _cumProb[bin]) * (_x[bin+1] - _x[bin]) /
108 (_cumProb[bin+1] - _cumProb[bin]);
109 xRandom = _x[bin] + coeff;
110
111 // Deugging
112 /*
113 G4cout << "Random = " << ranflat << " Generated " << xRandom << G4endl;
114 */
115 // Endo of Debugging
116
117 }
118 else
119 {
120 // Debugging
121 /*
122 G4cout << "Bin " << bin << " "
123 << _cumProb.size() << " "
124 << _x.size()
125 << G4endl;
126 */
127 // End of debugging
128 }
129
130 return xRandom;
131
132}
int G4int
Definition: G4Types.hh:66

Referenced by G4PiMinusStopMaterial::P4Vector().


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