CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

RandSkewNormal.cc
Go to the documentation of this file.
1 // $Id: RandSkewNormal.cc,v 1.1 2011/05/27 20:36:57 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 // HEP Random
6 // --- RandSkewNormal ---
7 // class implementation file
8 // -----------------------------------------------------------------------
9 
10 // =======================================================================
11 // M Fischler and L Garren - Created: 26 May 2011
12 // =======================================================================
13 
14 #include "CLHEP/Random/defs.h"
15 #include "CLHEP/Random/RandSkewNormal.h"
16 #include "CLHEP/Random/RandGaussT.h"
17 #include "CLHEP/Random/DoubConv.hh"
18 
19 namespace CLHEP {
20 
21 std::string RandSkewNormal::name() const {return "RandSkewNormal";}
22 HepRandomEngine & RandSkewNormal::engine() {return *localEngine;}
23 
25 
27 {
28  return fire( shapeParameter );
29 }
30 
31 double RandSkewNormal::operator()( double shape )
32 {
33  return fire( shape );
34 }
35 
36 //-------------
37 
39 {
40  // really dumb use of RandSkewNormal
41  double k = 1;
42  return gaussianSkewNormal( anEngine, k );
43 }
44 
45 double RandSkewNormal::shoot(HepRandomEngine* anEngine, double shape)
46 {
47  return gaussianSkewNormal( anEngine, shape );
48 }
49 
51 {
52  // really dumb use of RandSkewNormal
54  double k = 1;
55  return gaussianSkewNormal( anEngine, k );
56 }
57 
58 double RandSkewNormal::shoot(double shape)
59 {
61  return gaussianSkewNormal( anEngine, shape );
62 }
63 
64 void RandSkewNormal::shootArray( const int size, double* vect,
65  double shape )
66 {
67  for( double* v = vect; v != vect+size; ++v )
68  *v = shoot(shape);
69 }
70 
72  double* vect, double shape )
73 {
74  for( double* v = vect; v != vect+size; ++v )
75  *v = shoot(anEngine, shape);
76 }
77 
78 //-------------
79 
82 }
83 
84 double RandSkewNormal::fire(double shape) {
85  return gaussianSkewNormal( getLocalEngine(), shape );
86 }
87 
88 void RandSkewNormal::fireArray( const int size, double* vect)
89 {
90  for( double* v = vect; v != vect+size; ++v )
91  *v = fire( shapeParameter );
92 }
93 
94 void RandSkewNormal::fireArray( const int size, double* vect,
95  double shape )
96 {
97  for( double* v = vect; v != vect+size; ++v )
98  *v = fire( shape );
99 }
100 
101 //-------------
102 
104 {
105  // RandSkewNormal is an implementation of Azzalini's SN generator
106  // http://azzalini.stat.unipd.it/SN/
107  // K. McFarlane, June 2010.
108  // For location parameter m = 0., scale = 1.
109  // To get a distribution with scale parameter b and location m:
110  // r = m + b * RandSkewNormal.fire(k);
111  double u[2] = {0.};
112  RandGaussT::shootArray(e, 2, u, 0, 1);
113  double delta = k/std::sqrt(1. + k*k);
114  double u1 = delta*u[0] + std::sqrt(1 - delta*delta)*u[1];
115  double r = u[0] >= 0 ? u1 : -u1;
116  return r;
117 }
118 
119 //-------------
120 
121 std::ostream & RandSkewNormal::put ( std::ostream & os ) const {
122  int pr=os.precision(20);
123  std::vector<unsigned long> t(2);
124  os << " " << name() << "\n";
125  os << "Uvec" << "\n";
126  t = DoubConv::dto2longs(shapeParameter);
127  os << shapeParameter << " " << t[0] << " " << t[1] << "\n";
128  os.precision(pr);
129  return os;
130 }
131 
132 std::istream & RandSkewNormal::get ( std::istream & is ) {
133  std::string inName;
134  is >> inName;
135  if (inName != name()) {
136  is.clear(std::ios::badbit | is.rdstate());
137  std::cerr << "Mismatch when expecting to read state of a "
138  << name() << " distribution\n"
139  << "Name found was " << inName
140  << "\nistream is left in the badbit state\n";
141  return is;
142  }
143  if (possibleKeywordInput(is, "Uvec", shapeParameter)) {
144  std::vector<unsigned long> t(2);
145  is >> shapeParameter >> t[0] >> t[1]; shapeParameter = DoubConv::longs2double(t);
146  return is;
147  }
148  // is >> shapeParameter encompassed by possibleKeywordInput
149  return is;
150 }
151 
152 
153 } // namespace CLHEP
delta
HepRotation delta() setPhi()
CLHEP::RandSkewNormal::fireArray
void fireArray(const int size, double *vect)
Definition: RandSkewNormal.cc:88
CLHEP::HepRandomEngine
Definition: Matrix/CLHEP/Random/RandomEngine.h:55
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::DoubConv::longs2double
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:106
CLHEP::RandSkewNormal::getShapeParameter
double getShapeParameter()
Definition: Matrix/CLHEP/Random/RandSkewNormal.h:98
CLHEP::RandSkewNormal::shootArray
static void shootArray(const int size, double *vect, double shape=0.)
Definition: RandSkewNormal.cc:64
CLHEP::RandSkewNormal::gaussianSkewNormal
static double gaussianSkewNormal(HepRandomEngine *e, double k)
Definition: RandSkewNormal.cc:103
size
user code seldom needs to call this function directly ZMerrno whether or not they are still recorded ZMerrno size() Return the(integer) number of ZMthrow 'n exceptions currently recorded. 5) ZMerrno.clear() Set an internal counter to zero. This counter is available(see next function) to user code to track ZMthrow 'n exceptions that have occurred during any arbitrary time interval. 6) ZMerrno.countSinceCleared() Return the(integer) number of ZMthrow 'n exceptions that have been recorded via ZMerrno.write()
CLHEP::RandSkewNormal::fire
double fire()
Definition: RandSkewNormal.cc:80
CLHEP
Definition: ClhepVersion.h:13
v
they are gone ZOOM Features Discontinued The following features of the ZOOM package were felt to be extreme overkill These have been after checking that no existing user code was utilizing as in SpaceVector v
Definition: keyMergeIssues.doc:324
CLHEP::RandSkewNormal::operator()
double operator()()
Definition: RandSkewNormal.cc:26
CLHEP::RandSkewNormal::getLocalEngine
HepRandomEngine * getLocalEngine()
CLHEP::RandSkewNormal::~RandSkewNormal
virtual ~RandSkewNormal()
Definition: RandSkewNormal.cc:24
CLHEP::possibleKeywordInput
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: Matrix/CLHEP/Random/RandomEngine.h:168
CLHEP::RandSkewNormal::get
std::istream & get(std::istream &is)
Definition: RandSkewNormal.cc:132
CLHEP::RandSkewNormal::name
std::string name() const
Definition: RandSkewNormal.cc:21
CLHEP::RandGaussT::shootArray
static void shootArray(const int size, double *vect, double mean=0.0, double stdDev=1.0)
Definition: RandGaussT.cc:37
CLHEP::DoubConv::dto2longs
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:90
CLHEP::RandSkewNormal::engine
HepRandomEngine & engine()
Definition: RandSkewNormal.cc:22
CLHEP::HepRandom::getTheEngine
static HepRandomEngine * getTheEngine()
Definition: Random.cc:166
k
long k
Definition: JamesRandomSeeding.txt:29
CLHEP::RandSkewNormal::shoot
static double shoot()
Definition: RandSkewNormal.cc:50
CLHEP::RandSkewNormal::put
std::ostream & put(std::ostream &os) const
Definition: RandSkewNormal.cc:121