Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:38

0001 // $Id: RandGamma.h,v 1.5 2010/06/16 17:24:53 garren Exp $
0002 // -*- C++ -*-
0003 //
0004 // -----------------------------------------------------------------------
0005 //                             HEP Random
0006 //                          --- RandGamma ---
0007 //                          class header file
0008 // -----------------------------------------------------------------------
0009 
0010 // Class defining methods for shooting gamma distributed random values,
0011 // given a k (default=1) and specifying also a lambda (default=1).
0012 // Default values are used for operator()().
0013 
0014 // Valid input values are k > 0 and lambda > 0.  When invalid values are
0015 // presented, the code silently returns -1.0.
0016 
0017 // =======================================================================
0018 // John Marraffino - Created: 12th May 1998  Based on the C-Rand package
0019 //                   by Ernst Stadlober and Franz Niederl of the Technical
0020 //                   University of Graz, Austria.
0021 // Gabriele Cosmo  - Removed useless methods and data: 5th Jan 1999
0022 // M Fischler      - put and get to/from streams 12/10/04
0023 // =======================================================================
0024 
0025 #ifndef RandGamma_h
0026 #define RandGamma_h 1
0027 
0028 #include "CLHEP/Random/defs.h"
0029 #include "CLHEP/Random/Random.h"
0030 #include "CLHEP/Utility/memory.h"
0031 
0032 namespace CLHEP {
0033 
0034 /**
0035  * @author
0036  * @ingroup random
0037  */
0038 class RandGamma : public HepRandom {
0039 
0040 public:
0041 
0042   inline RandGamma ( HepRandomEngine& anEngine, double k=1.0,
0043                                                 double lambda=1.0 );
0044   inline RandGamma ( HepRandomEngine* anEngine, double k=1.0, 
0045                                                 double lambda=1.0 );
0046   // These constructors should be used to instantiate a RandGamma
0047   // distribution object defining a local engine for it.
0048   // The static generator will be skipped using the non-static methods
0049   // defined below.
0050   // If the engine is passed by pointer the corresponding engine object
0051   // will be deleted by the RandGamma destructor.
0052   // If the engine is passed by reference the corresponding engine object
0053   // will not be deleted by the RandGamma destructor.
0054 
0055   virtual ~RandGamma();
0056   // Destructor
0057 
0058   // Static methods to shoot random values using the static generator
0059 
0060   static inline double shoot();
0061 
0062   static double shoot( double k, double lambda );
0063 
0064   static void shootArray ( const int size, double* vect,
0065                             double k=1.0, double lambda=1.0 );
0066 
0067   //  Static methods to shoot random values using a given engine
0068   //  by-passing the static generator.
0069 
0070   static inline double shoot( HepRandomEngine* anEngine );
0071 
0072   static double shoot( HepRandomEngine* anEngine, 
0073                                   double k, double lambda );
0074 
0075   static void shootArray ( HepRandomEngine* anEngine, const int size,
0076                             double* vect, double k=1.0,
0077                             double lambda=1.0 );
0078 
0079   //  Methods using the localEngine to shoot random values, by-passing
0080   //  the static generator.
0081 
0082   inline double fire();
0083 
0084   double fire( double k, double lambda );
0085   
0086   void fireArray ( const int size, double* vect);
0087   void fireArray ( const int size, double* vect,
0088                    double k, double lambda );
0089   inline double operator()();
0090   inline double operator()( double k, double lambda );
0091 
0092   // Save and restore to/from streams
0093   
0094   std::ostream & put ( std::ostream & os ) const;
0095   std::istream & get ( std::istream & is );
0096 
0097   std::string name() const;
0098   HepRandomEngine & engine();
0099 
0100   static std::string distributionName() {return "RandGamma";}  
0101   // Provides the name of this distribution class
0102   
0103 
0104 private:
0105 
0106   static double genGamma( HepRandomEngine *anEngine, double k,
0107                                                         double lambda );
0108 
0109   std::shared_ptr<HepRandomEngine> localEngine;
0110   double defaultK;
0111   double defaultLambda;
0112 
0113 };
0114 
0115 }  // namespace CLHEP
0116 
0117 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
0118 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
0119 using namespace CLHEP;
0120 #endif
0121 
0122 #include "CLHEP/Random/RandGamma.icc"
0123 
0124 #endif