CLHEP/Random/RandBinomial.h

00001 // $Id: RandBinomial.h,v 1.9 2002/04/12 15:02:44 evc Exp $
00002 // -*- C++ -*-
00003 //
00004 // -----------------------------------------------------------------------
00005 //                             HEP Random
00006 //                         --- RandBinomial ---
00007 //                          class header file
00008 // -----------------------------------------------------------------------
00009 
00010 // Class defining methods for shooting binomial distributed random values,
00011 // given a sample size n (default=1) and a probability p (default=0.5).
00012 // Default values are used for operator()().
00013 //
00014 // Valid input values satisfy the relation n*min(p,1-p) > 0. When invalid
00015 // values are presented, the code silently returns -1.0.
00016 
00017 // =======================================================================
00018 // John Marraffino - Created: 12th May 1998  Based on the C-Rand package
00019 //                   by Ernst Stadlober and Franz Niederl of the Technical
00020 //                   University of Graz, Austria.
00021 // Gabriele Cosmo  - Removed useless methods and data: 5th Jan 1999
00022 // =======================================================================
00023 
00024 #ifndef RandBinomial_h
00025 #define RandBinomial_h 1
00026 
00027 #include "CLHEP/Random/Random.h"
00028 
00033 class RandBinomial : public HepRandom {
00034 
00035 public:
00036 
00037   inline RandBinomial ( HepRandomEngine& anEngine, long n=1,
00038                                                      double p=0.5 );
00039   inline RandBinomial ( HepRandomEngine* anEngine, long n=1,
00040                                                      double p=0.5 );
00041   // These constructors should be used to instantiate a RandBinomial
00042   // distribution object defining a local engine for it.
00043   // The static generator will be skipped using the non-static methods
00044   // defined below.
00045   // If the engine is passed by pointer the corresponding engine object
00046   // will be deleted by the RandBinomial destructor.
00047   // If the engine is passed by reference the corresponding engine object
00048   // will not be deleted by the RandBinomial destructor.
00049 
00050   virtual ~RandBinomial();
00051   // Destructor
00052 
00053   // Static methods to shoot random values using the static generator
00054 
00055   static inline double shoot();
00056 
00057   static double shoot( long n, double p );
00058 
00059   static void shootArray ( const int size, double* vect,
00060                             long n=1, double p=0.5 );
00061 
00062   //  Static methods to shoot random values using a given engine
00063   //  by-passing the static generator.
00064 
00065   static inline double shoot( HepRandomEngine* anEngine );
00066 
00067   static double shoot( HepRandomEngine* anEngine, 
00068                                   long n, double p );
00069 
00070   static void shootArray ( HepRandomEngine* anEngine, const int size,
00071                             double* vect, long n=1,
00072                             double p=0.5 );
00073 
00074   //  Methods using the localEngine to shoot random values, by-passing
00075   //  the static generator.
00076 
00077   inline double fire();
00078 
00079   double fire( long n, double p );
00080   
00081   void fireArray ( const int size, double* vect);
00082   void fireArray ( const int size, double* vect,
00083                    long n, double p );
00084   inline double operator()();
00085   inline double operator()( long n, double p );
00086 
00087 private:
00088 
00089   // Private copy constructor. Defining it here disallows use.
00090   RandBinomial(const RandBinomial& d);
00091 
00092   static double genBinomial( HepRandomEngine *anEngine, long n, double p );
00093 
00094   HepRandomEngine* localEngine;
00095   bool deleteEngine;
00096   const long defaultN;
00097   const double defaultP;
00098  
00099 };
00100 
00101 #include "CLHEP/Random/RandBinomial.icc"
00102 
00103 #endif

Class Library for High Energy Physics (version 1.8)