1 // $Id: RandSkewNormal.h,v 1.1 2011/05/27 20:36:28 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 //                             HEP Random
6 //                          --- RandSkewNormal ---
7 //                          class header file
8 // -----------------------------------------------------------------------
9 
10 // RandSkewNormal ---
11 //    returns a skew-normal distribution with shape parameter k
12 //    To get a distribution with scale parameter b and location m:
13 //    r = m + b * RandSkewNormal.fire(k);
14 // http://azzalini.stat.unipd.it/SN/
15 // algorithm from K. McFarlane, June 2010.
16 
17 // =======================================================================
18 // M Fischler and L Garren - Created: 26 May 2011
19 // =======================================================================
20 
21 #ifndef RandSkewNormal_h
22 #define RandSkewNormal_h 1
23 
24 #include "CLHEP/Random/defs.h"
25 #include "CLHEP/Random/Random.h"
26 #include "CLHEP/Utility/memory.h"
27 
28 namespace CLHEP {
29 
30 /**
31  * @author <mf@fnal.gov>
32  * @ingroup random
33  */
34 class RandSkewNormal : public HepRandom {
35 
36 public:
37 
38   inline RandSkewNormal ( HepRandomEngine& anEngine, double shape=0. );
39   inline RandSkewNormal ( HepRandomEngine* anEngine, double shape=0. );
40   // These constructors should be used to instantiate a RandSkewNormal
41   // distribution object defining a local engine for it.
42   // The static generator will be skipped using the non-static methods
43   // defined below.
44   // If the engine is passed by pointer the corresponding engine object
45   // will be deleted by the RandSkewNormal destructor.
46   // If the engine is passed by reference the corresponding engine object
47   // will not be deleted by the RandSkewNormal destructor.
48 
49   virtual ~RandSkewNormal();
50   // Destructor
51 
52   // Static methods to shoot random values using the static generator
53 
54   static  double shoot();
55 
56   static  double shoot( double shape );
57 
58   static  void shootArray ( const int size, double* vect,
59                             double shape=0. );
60 
61   //  Static methods to shoot random values using a given engine
62   //  by-passing the static generator.
63 
64   static  double shoot( HepRandomEngine* anEngine );
65 
66   static  double shoot( HepRandomEngine* anEngine, double shape );
67 
68   static  void shootArray ( HepRandomEngine* anEngine, const int size,
69                             double* vect, double shape=0. );
70 
71   //  Methods using the localEngine to shoot random values, by-passing
72   //  the static generator.
73 
74   double fire();
75 
76   double fire( double shape );
77 
78   void fireArray ( const int size, double* vect );
79   void fireArray ( const int size, double* vect, double shape );
80 
81   double operator()();
82   double operator()( double shape );
83 
84   // Save and restore to/from streams
85 
86   std::ostream & put ( std::ostream & os ) const;
87   std::istream & get ( std::istream & is );
88 
89   std::string name() const;
90   HepRandomEngine & engine();
91 
distributionName()92   static std::string distributionName() {return "RandSkewNormal";}
93   // Provides the name of this distribution class
94 
95 protected:
96 
97   static double gaussianSkewNormal ( HepRandomEngine *e, double k);
getShapeParameter()98   double getShapeParameter() { return shapeParameter; }
99 
100   inline HepRandomEngine* getLocalEngine();
101 
102 private:
103 
104   shared_ptr<HepRandomEngine> localEngine;
105   double shapeParameter;
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/RandSkewNormal.icc"
117 
118 #endif
119