Geant4  10.00.p02
G4MTRandGeneral.hh
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 //
27 // $Id:$
28 //
29 // Class G4MTRandGeneral
30 //
31 // Modified version with MT extensions
32 // of corresponding CLHEP class RandGeneral
33 
34 // --------------------------------------------------------------------
35 #ifndef G4MTRandGeneral_h
36 #define G4MTRandGeneral_h 1
37 
38 #include <vector>
39 
40 #include "G4MTHepRandom.hh"
41 
43 {
44 
45 public:
46 
47  G4MTRandGeneral ( const G4double* aProbFunc,
48  G4int theProbSize,
49  G4int IntType=0 );
50  G4MTRandGeneral ( CLHEP::HepRandomEngine& anEngine,
51  const G4double* aProbFunc,
52  G4int theProbSize,
53  G4int IntType=0 );
54  G4MTRandGeneral ( CLHEP::HepRandomEngine* anEngine,
55  const G4double* aProbFunc,
56  G4int theProbSize,
57  G4int IntType=0 );
58  // These constructors should be used to instantiate a G4MTRandGeneral
59  // distribution object defining a local engine for it.
60  // The static generator will be skiped by using the non-static methods
61  // defined below. In case no engine is specified in the constructor, the
62  // default engine used by the static generator is applied.
63  // If the engine is passed by pointer the corresponding engine object
64  // will be deleted by the G4MTRandGeneral destructor.
65  // If the engine is passed by reference the corresponding engine object
66  // will not be deleted by the G4MTRandGeneral destructor.
67  // The probability distribution function (Pdf) must be provided by the user
68  // as an array of positive real number. The array size must also be
69  // provided. The Pdf doesn't need to be normalized to 1.
70  // if IntType = 0 ( default value ) a uniform random number is
71  // generated using the engine. The uniform number is then transformed
72  // to the user's distribution using the cumulative probability
73  // distribution constructed from his histogram. The cumulative
74  // distribution is inverted using a binary search for the nearest
75  // bin boundary and a linear interpolation within the
76  // bin. G4MTRandGeneral therefore generates a constant density within
77  // each bin.
78  // if IntType = 1 no interpolation is performed and the result is a
79  // discrete distribution.
80 
81  virtual ~G4MTRandGeneral();
82  // Destructor
83 
84  // Methods to shoot random values using the static generator
85  // N.B.: The methods are NOT static since they use nonstatic members
86  // theIntegralPdf & nBins
87 
88  inline G4double shoot();
89 
90  inline void shootArray ( const G4int size, G4double* vect);
91 
92  // Methods to shoot random values using a given engine
93  // by-passing the static generator.
94 
95  G4double shoot( CLHEP::HepRandomEngine* anEngine );
96 
97  void shootArray ( CLHEP::HepRandomEngine* anEngine, const G4int size,
98  G4double* vect );
99 
100  // Methods using the localEngine to shoot random values, by-passing
101  // the static generator.
102 
103  G4double fire();
104 
105  void fireArray ( const G4int size, G4double* vect);
106 
108 
109 private:
110 
111  CLHEP::HepRandomEngine* localEngine;
113  std::vector<G4double> theIntegralPdf;
117 
118  // Private methods to factor out replicated implementation sections
119  void prepareTable(const G4double* aProbFunc);
120  void useFlatDistribution();
121  G4double mapRandom(G4double rand) const;
122 
123 };
124 
125 #include "G4MTRandGeneral.icc"
126 
127 #endif
void shootArray(const G4int size, G4double *vect)
G4double operator()()
G4double fire()
G4double mapRandom(G4double rand) const
int G4int
Definition: G4Types.hh:78
void fireArray(const G4int size, G4double *vect)
CLHEP::HepRandomEngine * localEngine
bool G4bool
Definition: G4Types.hh:79
std::vector< G4double > theIntegralPdf
G4MTRandGeneral(const G4double *aProbFunc, G4int theProbSize, G4int IntType=0)
void prepareTable(const G4double *aProbFunc)
virtual ~G4MTRandGeneral()
G4double shoot()
void useFlatDistribution()
double G4double
Definition: G4Types.hh:76