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10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/include/CLHEP/Random/RandGeneral.h (Version 11.3.0) and /externals/clhep/include/CLHEP/Random/RandGeneral.h (Version 10.1.p3)


                                                   >>   1 // $Id:$
  1 // -*- C++ -*-                                      2 // -*- C++ -*-
  2 //                                                  3 //
  3 // -------------------------------------------      4 // -----------------------------------------------------------------------
  4 //                             HEP Random           5 //                             HEP Random
  5 //                          --- RandGeneral --      6 //                          --- RandGeneral ---
  6 //                          class header file       7 //                          class header file
  7 // -------------------------------------------      8 // -----------------------------------------------------------------------
  8                                                     9 
  9 // Class defining methods for shooting general     10 // Class defining methods for shooting generally distributed random values,
 10 // given a user-defined probability distributi     11 // given a user-defined probability distribution function.
 11                                                    12 
 12 // ===========================================     13 // =======================================================================
 13 // S.Magni & G.Pieri  - Created: 29 April 1998     14 // S.Magni & G.Pieri  - Created: 29 April 1998 
 14 // G.Cosmo            - Added constructor usin     15 // G.Cosmo            - Added constructor using default engine from the
 15 //                      static generator: 20 A     16 //                      static generator: 20 Aug 1998
 16 // S.Magni & G.Pieri  - Added linear interpola     17 // S.Magni & G.Pieri  - Added linear interpolation: 24 March 1999
 17 // M. Fischler        - Added private methods      18 // M. Fischler        - Added private methods that simplify the implementaion
 18 //      prepareTables(), useFlatDistribution()     19 //      prepareTables(), useFlatDistribution(), mapRandom()
 19 //          - Added private variable oneOverNb     20 //          - Added private variable oneOverNbins.
 20 //              - Made the warning about shoot     21 //              - Made the warning about shoot() not being static a tad
 21 //      more prominent.       14 May 1999          22 //      more prominent.       14 May 1999 
 22 // M Fischler         - put and get to/from st     23 // M Fischler         - put and get to/from streams 12/15/04
 23 // ===========================================     24 // =======================================================================
 24                                                    25 
 25 #ifndef RandGeneral_h                              26 #ifndef RandGeneral_h
 26 #define RandGeneral_h 1                            27 #define RandGeneral_h 1
 27                                                    28 
 28 #include "CLHEP/Random/Random.h"                   29 #include "CLHEP/Random/Random.h"
 29 #include "CLHEP/Utility/memory.h"                  30 #include "CLHEP/Utility/memory.h"
 30 #include <vector>                                  31 #include <vector>
 31                                                    32 
 32 namespace CLHEP {                                  33 namespace CLHEP {
 33                                                    34 
 34 /**                                                35 /**
 35  * @author                                         36  * @author
 36  * @ingroup random                                 37  * @ingroup random
 37  */                                                38  */
 38 class RandGeneral : public HepRandom {             39 class RandGeneral : public HepRandom {
 39                                                    40 
 40 public:                                            41 public:
 41                                                    42 
 42   RandGeneral ( const double* aProbFunc,           43   RandGeneral ( const double* aProbFunc, 
 43     int theProbSize,                               44     int theProbSize, 
 44     int IntType=0 );                               45     int IntType=0 );
 45   RandGeneral ( HepRandomEngine& anEngine,         46   RandGeneral ( HepRandomEngine& anEngine,
 46                 const double* aProbFunc,           47                 const double* aProbFunc, 
 47     int theProbSize,                               48     int theProbSize, 
 48     int IntType=0 );                               49     int IntType=0 );
 49   RandGeneral ( HepRandomEngine* anEngine,         50   RandGeneral ( HepRandomEngine* anEngine, 
 50                 const double* aProbFunc,           51                 const double* aProbFunc, 
 51     int theProbSize,                               52     int theProbSize, 
 52     int IntType=0 );                               53     int IntType=0 );
 53   // These constructors should be used to inst     54   // These constructors should be used to instantiate a RandGeneral
 54   // distribution object defining a local engi     55   // distribution object defining a local engine for it.
 55   // The static generator will be skipped by u     56   // The static generator will be skipped by using the non-static methods
 56   // defined below. In case no engine is speci     57   // defined below. In case no engine is specified in the constructor, the
 57   // default engine used by the static generat     58   // default engine used by the static generator is applied.
 58   // If the engine is passed by pointer the co     59   // If the engine is passed by pointer the corresponding engine object
 59   // will be deleted by the RandGeneral destru     60   // will be deleted by the RandGeneral destructor.
 60   // If the engine is passed by reference the      61   // If the engine is passed by reference the corresponding engine object
 61   // will not be deleted by the RandGeneral de     62   // will not be deleted by the RandGeneral destructor.
 62   // The probability distribution function (Pd     63   // The probability distribution function (Pdf) must be provided by the user
 63   // as an array of positive real number. The      64   // as an array of positive real number. The array size must also be
 64   // provided. The Pdf doesn't need to be norm     65   // provided. The Pdf doesn't need to be normalized to 1. 
 65   // if IntType = 0 ( default value ) a unifor     66   // if IntType = 0 ( default value ) a uniform random number is
 66   // generated using the engine. The uniform n     67   // generated using the engine. The uniform number is then transformed
 67   // to the user's distribution using the cumu     68   // to the user's distribution using the cumulative probability
 68   // distribution constructed from his histogr     69   // distribution constructed from his histogram. The cumulative
 69   // distribution is inverted using a binary s     70   // distribution is inverted using a binary search for the nearest
 70   // bin boundary and a linear interpolation w     71   // bin boundary and a linear interpolation within the
 71   // bin. RandGeneral therefore generates a co     72   // bin. RandGeneral therefore generates a constant density within
 72   // each bin.                                     73   // each bin.
 73   // if IntType = 1 no interpolation is perfor     74   // if IntType = 1 no interpolation is performed and the result is a
 74   // discrete distribution.                        75   // discrete distribution.
 75                                                    76 
 76   virtual ~RandGeneral();                          77   virtual ~RandGeneral();
 77   // Destructor                                    78   // Destructor
 78                                                    79 
 79   // Methods to shoot random values using the      80   // Methods to shoot random values using the static generator
 80   // N.B.: The methods are NOT static since th     81   // N.B.: The methods are NOT static since they use nonstatic members
 81   // theIntegralPdf & nBins                        82   // theIntegralPdf & nBins
 82                                                    83 
 83   /////////////////////                            84   /////////////////////
 84   //       //                                      85   //       //
 85   // BIG RED WARNING //                            86   // BIG RED WARNING //
 86   //       //                                      87   //       //
 87   /////////////////////                            88   /////////////////////
 88   //                                               89   //
 89   // The above N.B. is telling users that the      90   // The above N.B. is telling users that the shoot() methods in this
 90   // class are NOT STATIC.  You cannot do          91   // class are NOT STATIC.  You cannot do 
 91   //  double x = RandGeneral::shoot();             92   //  double x = RandGeneral::shoot();
 92   // It would not make sense to provide a stat     93   // It would not make sense to provide a static shoot -- what would 
 93   // the default probability function look lik     94   // the default probability function look like?
 94                                                    95 
 95   inline double shoot();                           96   inline double shoot();
 96                                                    97 
 97   inline void shootArray ( const int size, dou     98   inline void shootArray ( const int size, double* vect);
 98                                                    99 
 99   //  Methods to shoot random values using a g    100   //  Methods to shoot random values using a given engine
100   //  by-passing the static generator.            101   //  by-passing the static generator.
101                                                   102 
102   double shoot( HepRandomEngine* anEngine );      103   double shoot( HepRandomEngine* anEngine );
103                                                   104 
104   void shootArray ( HepRandomEngine* anEngine,    105   void shootArray ( HepRandomEngine* anEngine, const int size,
105                     double* vect );               106                     double* vect );
106                                                   107           
107   //  Methods using the localEngine to shoot r    108   //  Methods using the localEngine to shoot random values, by-passing
108   //  the static generator.                       109   //  the static generator.
109                                                   110 
110   double fire();                                  111   double fire();
111                                                   112 
112   void fireArray ( const int size, double* vec    113   void fireArray ( const int size, double* vect);
113                                                   114 
114   double operator()();                            115   double operator()();
115                                                   116 
116   // Save and restore to/from streams             117   // Save and restore to/from streams
117                                                   118   
118   std::ostream & put ( std::ostream & os ) con    119   std::ostream & put ( std::ostream & os ) const;
119   std::istream & get ( std::istream & is );       120   std::istream & get ( std::istream & is );
120                                                   121 
121   std::string name() const;                       122   std::string name() const;
122   HepRandomEngine & engine();                     123   HepRandomEngine & engine();
123                                                   124 
124   static std::string distributionName() {retur    125   static std::string distributionName() {return "RandGeneral";}  
125   // Provides the name of this distribution cl    126   // Provides the name of this distribution class
126                                                   127   
127                                                   128 
128 private:                                          129 private:
129                                                   130 
130   std::shared_ptr<HepRandomEngine> localEngine << 131   shared_ptr<HepRandomEngine> localEngine;
131   std::vector<double> theIntegralPdf;             132   std::vector<double> theIntegralPdf;
132   int nBins;                                      133   int nBins;
133   double oneOverNbins;                            134   double oneOverNbins;
134   int InterpolationType;                          135   int InterpolationType;
135                                                   136 
136   // Private methods to factor out replicated     137   // Private methods to factor out replicated implementation sections
137   void prepareTable(const double* aProbFunc);     138   void prepareTable(const double* aProbFunc);
138   void useFlatDistribution();                     139   void useFlatDistribution();
139   double mapRandom(double rand) const;            140   double mapRandom(double rand) const;
140                                                   141 
141 };                                                142 };
142                                                   143 
143 }  // namespace CLHEP                             144 }  // namespace CLHEP
144                                                   145 
145 #include "CLHEP/Random/RandGeneral.icc"           146 #include "CLHEP/Random/RandGeneral.icc"
146                                                   147 
147 #endif                                            148 #endif
148                                                   149