1 // $Id: RandChiSquare.h,v 1.5 2010/06/16 17:24:53 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 //                             HEP Random
6 //                         --- RandChiSquare ---
7 //                          class header file
8 // -----------------------------------------------------------------------
9 
10 // Class defining methods for shooting Chi^2 distributed random values,
11 // given a number of degrees of freedom a (default=1.0).
12 // Default values are used for operator()().
13 
14 // Valid values of a satisfy a > 1. When invalid values are presented,
15 // the code silently returns -1.0.
16 
17 // =======================================================================
18 // John Marraffino - Created: 12th May 1998  Based on the C-Rand package
19 //                   by Ernst Stadlober and Franz Niederl of the Technical
20 //                   University of Graz, Austria.
21 // Gabriele Cosmo  - Removed useless methods and data: 5th Jan 1999
22 // M Fischler      - put and get to/from streams 12/10/04
23 // =======================================================================
24 
25 #ifndef RandChiSquare_h
26 #define RandChiSquare_h 1
27 
28 #include "CLHEP/Random/defs.h"
29 #include "CLHEP/Random/Random.h"
30 #include "CLHEP/Utility/memory.h"
31 
32 namespace CLHEP {
33 
34 /**
35  * @author
36  * @ingroup random
37  */
38 class RandChiSquare : public HepRandom {
39 
40 public:
41 
42   inline RandChiSquare ( HepRandomEngine& anEngine, double a=1 );
43   inline RandChiSquare ( HepRandomEngine* anEngine, double a=1 );
44   // These constructors should be used to instantiate a RandChiSquare
45   // distribution object defining a local engine for it.
46   // The static generator will be skipped using the non-static methods
47   // defined below.
48   // If the engine is passed by pointer the corresponding engine object
49   // will be deleted by the RandChiSquare destructor.
50   // If the engine is passed by reference the corresponding engine object
51   // will not be deleted by the RandChiSquare destructor.
52 
53   virtual ~RandChiSquare();
54   // Destructor
55 
56   // Static methods to shoot random values using the static generator
57 
58   static inline double shoot();
59 
60   static double shoot( double a );
61 
62   static void shootArray ( const int size, double* vect,
63                             double a=1.0 );
64 
65   //  Static methods to shoot random values using a given engine
66   //  by-passing the static generator.
67 
68   static inline double shoot( HepRandomEngine* anEngine );
69 
70   static double shoot( HepRandomEngine* anEngine,
71                                   double a );
72 
73   static void shootArray ( HepRandomEngine* anEngine, const int size,
74                             double* vect, double a=1.0 );
75 
76   //  Methods using the localEngine to shoot random values, by-passing
77   //  the static generator.
78 
79   inline double fire();
80 
81   double fire( double a );
82 
83   void fireArray ( const int size, double* vect);
84   void fireArray ( const int size, double* vect,
85                    double a );
86   inline double operator()();
87   inline double operator()( double a );
88 
89   // Save and restore to/from streams
90 
91   std::ostream & put ( std::ostream & os ) const;
92   std::istream & get ( std::istream & is );
93 
94   std::string name() const;
95   HepRandomEngine & engine();
96 
distributionName()97   static std::string distributionName() {return "RandChiSquare";}
98   // Provides the name of this distribution class
99 
100 private:
101 
102   static double genChiSquare( HepRandomEngine *anEngine, double a );
103 
104   std::shared_ptr<HepRandomEngine> localEngine;
105   double defaultA;
106 
107 };
108 
109 }  // namespace CLHEP
110 
111 #ifdef ENABLE_BACKWARDS_COMPATIBILITY
112 //  backwards compatibility will be enabled ONLY in CLHEP 1.9
113 using namespace CLHEP;
114 #endif
115 
116 #include "CLHEP/Random/RandChiSquare.icc"
117 
118 #endif
119