The Gaudi Framework  v33r0 (d5ea422b)
RndmGenerators.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_RNDMGENGENERATORS_H
12 #define GAUDIKERNEL_RNDMGENGENERATORS_H
13 
14 // STL include files
15 #include <vector>
16 
17 // Framework include files
18 #include "GaudiKernel/IRndmGen.h"
19 #include "GaudiKernel/SmartIF.h"
20 
21 // Forward declarations
22 class IRndmGen;
23 class IRndmGenSvc;
24 
25 namespace Rndm {
26 
27  template <class TYPE>
28  class Generator;
29 
32  class GAUDI_API Gauss : public IRndmGen::Param {
33  protected:
35  friend class Generator<Gauss>;
37  double m_mean;
39  double m_sigma;
40 
41  public:
43  Gauss( double m, double s ) : IRndmGen::Param( IID_IRndmGauss ), m_mean( m ), m_sigma( s ) {}
45  double mean() const { return m_mean; }
47  double sigma() const { return m_sigma; }
49  static const InterfaceID& typeID() { return IID_IRndmGauss; }
51  Gauss* clone() const override { return new Gauss( m_mean, m_sigma ); }
52  };
53 
57  protected:
59  double m_mean;
60 
61  public:
63  Exponential( double m ) : IRndmGen::Param( IID_IRndmExponential ), m_mean( m ) {}
65  double mean() const { return m_mean; }
67  static const InterfaceID& typeID() { return IID_IRndmExponential; }
69  Exponential* clone() const override { return new Exponential( m_mean ); }
70  };
71 
74  class GAUDI_API Chi2 : public IRndmGen::Param {
75  friend class Generator<Chi2>;
76 
77  protected:
79  long m_nDOF;
80 
81  public:
83  Chi2( long n_dof ) : IRndmGen::Param( IID_IRndmChi2 ), m_nDOF( n_dof ) {}
85  long nDOF() const { return m_nDOF; }
87  static const InterfaceID& typeID() { return IID_IRndmChi2; }
89  Chi2* clone() const override { return new Chi2( m_nDOF ); }
90  };
91 
95  friend class Generator<BreitWigner>;
96 
97  protected:
99  double m_mean, m_gamma;
100 
101  public:
103  BreitWigner( double m, double g ) : IRndmGen::Param( IID_IRndmBreitWigner ), m_mean( m ), m_gamma( g ) {}
105  double mean() const { return m_mean; }
107  double gamma() const { return m_gamma; }
109  static const InterfaceID& typeID() { return IID_IRndmBreitWigner; }
111  BreitWigner* clone() const override { return new BreitWigner( m_mean, m_gamma ); }
112  };
113 
117  friend class Generator<Landau>;
118 
119  protected:
121  double m_mean, m_sigma;
122 
123  public:
125  Landau( double m, double s ) : IRndmGen::Param( IID_IRndmLandau ), m_mean( m ), m_sigma( s ) {}
127  double mean() const { return m_mean; }
129  double sigma() const { return m_sigma; }
131  static const InterfaceID& typeID() { return IID_IRndmLandau; }
133  Landau* clone() const override { return new Landau( m_mean, m_sigma ); }
134  };
135 
141 
142  protected:
144  double m_mean, m_gamma, m_cut;
145 
146  public:
148  BreitWignerCutOff( double m, double g, double c )
149  : IRndmGen::Param( IID_IRndmBreitWignerCutOff ), m_mean( m ), m_gamma( g ), m_cut( c ) {}
151  double mean() const { return m_mean; }
153  double gamma() const { return m_gamma; }
155  double cutOff() const { return m_cut; }
157  static const InterfaceID& typeID() { return IID_IRndmBreitWignerCutOff; }
159  BreitWignerCutOff* clone() const override { return new BreitWignerCutOff( m_mean, m_gamma, m_cut ); }
160  };
161 
165  friend class Generator<StudentT>;
166 
167  protected:
169  double m_aValue;
170 
171  public:
173  StudentT( double a ) : IRndmGen::Param( IID_IRndmStudentT ), m_aValue( a ) {}
175  double aValue() const { return m_aValue; }
177  static const InterfaceID& typeID() { return IID_IRndmStudentT; }
179  StudentT* clone() const override { return new StudentT( m_aValue ); }
180  };
181 
184  class GAUDI_API Gamma : public IRndmGen::Param {
185  friend class Generator<Gamma>;
186 
187  protected:
189  double m_kValue;
191  double m_lambda;
192 
193  public:
195  Gamma( double k, double l ) : IRndmGen::Param( IID_IRndmGamma ), m_kValue( k ), m_lambda( l ) {}
197  double kValue() const { return m_kValue; }
199  double lambda() const { return m_lambda; }
201  static const InterfaceID& typeID() { return IID_IRndmGamma; }
203  Gamma* clone() const override { return new Gamma( m_kValue, m_lambda ); }
204  };
205 
210  friend class Generator<Poisson>;
211 
212  protected:
214  double m_mean;
215 
216  public:
218  Poisson( double m ) : IRndmGen::Param( IID_IRndmPoisson ), m_mean( m ) {}
220  double mean() const { return m_mean; }
222  static const InterfaceID& typeID() { return IID_IRndmPoisson; }
224  Poisson* clone() const override { return new Poisson( m_mean ); }
225  };
226 
231  protected:
233  long m_nEvent;
236 
237  public:
239  Binomial( long n, double p ) : IRndmGen::Param( IID_IRndmBinomial ), m_nEvent( n ), m_probability( p ) {}
241  long nEvent() const { return m_nEvent; }
243  double probability() const { return m_probability; }
245  static const InterfaceID& typeID() { return IID_IRndmBinomial; }
247  Binomial* clone() const override { return new Binomial( m_nEvent, m_probability ); }
248  };
249 
253  class GAUDI_API Flat : public IRndmGen::Param {
254  protected:
256  double m_minimum;
258  double m_maximum;
259 
260  public:
262  Flat( double mi, double ma ) : IRndmGen::Param( IID_IRndmFlat ), m_minimum( mi ), m_maximum( ma ) {}
264  double minimum() const { return m_minimum; }
266  double maximum() const { return m_maximum; }
268  static const InterfaceID& typeID() { return IID_IRndmFlat; }
270  Flat* clone() const override { return new Flat( m_minimum, m_maximum ); }
271  };
272 
275  class GAUDI_API Bit : public IRndmGen::Param {
276  public:
278  Bit() : IRndmGen::Param( IID_IRndmBit ) {}
280  static const InterfaceID& typeID() { return IID_IRndmBit; }
282  Bit* clone() const override { return new Bit(); }
283  };
284 
302  protected:
307 
308  public:
310  DefinedPdf( const std::vector<double>& pdf, long intpol )
311  : IRndmGen::Param( IID_IRndmDefinedPdf ), m_pdf( pdf ), m_interpolation( intpol ) {}
313  std::vector<double>& pdf() { return m_pdf; }
315  long interpolation() const { return m_interpolation; }
317  static const InterfaceID& typeID() { return IID_IRndmDefinedPdf; }
319  DefinedPdf* clone() const override { return new DefinedPdf( m_pdf, m_interpolation ); }
320  };
321 
325  protected:
327  double m_cut;
329  double m_sigma;
330 
331  public:
333  GaussianTail( double a, double s ) : IRndmGen::Param( IID_IRndmGaussianTail ), m_cut( a ), m_sigma( s ) {}
335  double cut() const { return m_cut; }
337  double sigma() const { return m_sigma; }
339  static const InterfaceID& typeID() { return IID_IRndmGaussianTail; }
341  GaussianTail* clone() const override { return new GaussianTail( m_cut, m_sigma ); }
342  };
343 
360  protected:
363 
364  public:
366  Numbers() = default;
368  Numbers( const Numbers& ) = default;
370  Numbers( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
372  virtual ~Numbers();
374  virtual StatusCode initialize( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
375 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
376  Numbers( IRndmGenSvc* svc, const IRndmGen::Param& par );
379  virtual StatusCode initialize( IRndmGenSvc* svc, const IRndmGen::Param& par );
380 #endif
381  virtual StatusCode finalize();
384  operator bool() const { return m_generator; }
386  double operator()() { return this->shoot(); }
388  double pop() { return this->shoot(); }
390  double shoot() { return m_generator ? m_generator->shoot() : -1; }
393  return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
394  }
395  };
396 } // namespace Rndm
397 #endif // GAUDIKERNEL_RNDMGENGENERATORS_H
double cut() const
Access cut value of the distribution.
double lambda() const
Access Lambda parameter.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the bit value generation: returns values 0 and 1.
double mean() const
Access mean value of the distribution.
double m_mean
Mean, Gamma and cut off parameter of the Breit-Wigner distribution.
Exponential * clone() const override
Clone parameters.
static const InterfaceID & typeID()
Identifier for factory.
GaussianTail(double a, double s)
Standard Constructor.
double m_kValue
k Value
double kValue() const
Access K parameter.
double m_minimum
Lower boundary for random numbers.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the Poisson distributed random number generation with a given mean.
Definition of a interface for a generic random number generators.
Definition: IRndmGen.h:44
double mean() const
Access mean value of the distribution.
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
double m_probability
And the probability for having success.
static const InterfaceID & typeID()
Identifier for factory.
double operator()()
Operator () for the use within STL.
double m_sigma
Sigma of the Gauss ditribution.
BreitWigner * clone() const override
Clone parameters.
static const InterfaceID & typeID()
Identifier for factory.
GaussianTail * clone() const override
Clone parameters.
Parameters for the Gauss random number generation.
Gauss(double m, double s)
Standard Constructor.
double cutOff() const
Access width of the distribution.
Landau * clone() const override
Clone parameters.
Flat(double mi, double ma)
Standard Constructor.
def start
Definition: IOTest.py:108
double shoot()
Pop a new number from the buffer.
long m_nEvent
Number of events the binomial destribution corresponds to.
double m_mean
Mean value of the exponential distribution.
double mean() const
Access mean value of the distribution.
BreitWigner(double m, double g)
Standard Constructor.
double probability() const
Access number of events.
Landau(double m, double s)
Standard Constructor.
long nDOF() const
Access mean value of the distribution.
double m_mean
Mean value of the Poisson distribution.
Random number accessor This small class encapsulates the use of the random number generator.
Interface ID class.
Definition: IInterface.h:39
double gamma() const
Access width of the distribution.
Bit()
Standard Constructor.
Chi2 * clone() const override
Clone parameters.
DefinedPdf(const std::vector< double > &pdf, long intpol)
Standard Constructor.
Random Generator service interface definition Definition of a interface for a service to access rando...
Definition: IRndmGenSvc.h:45
double m_cut
Cut on the Gaussian tail distribution.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
double mean() const
Access mean value of the distribution.
constexpr double m
double minimum() const
Access lower edge.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the flat random number generation within boundaries [minimum, maximum].
double m_maximum
Upper boundary for random numbers.
std::vector< double > m_pdf
Vector containing probability distribution function.
static const InterfaceID & typeID()
Identifier for factory.
long interpolation() const
Access interpolation type.
StudentT(double a)
Standard Constructor.
StudentT * clone() const override
Clone parameters.
double gamma() const
Access width of the distribution.
static const InterfaceID & typeID()
Identifier for factory.
double m_mean
Mean of the Gauss distribution.
long m_interpolation
Interpolation type.
static const InterfaceID & typeID()
Identifier for factory.
Gauss * clone() const override
Clone parameters.
Parameters for the StudentT distributed random number generation.
double m_lambda
Lambda parameter.
static const InterfaceID & typeID()
Identifier for factory.
Flat * clone() const override
Clone parameters.
dictionary l
Definition: gaudirun.py:543
Parameters for the Binomial distributed random number generation.
double aValue() const
Access A parameter.
StatusCode shootArray(std::vector< double > &array, long num, long start=0)
Pop a new number from the buffer.
virtual double shoot() const =0
Single shot returning single random number according to specified distribution.
Parameters for the Landau distributed random number generation.
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Parameters for the Chi2 distributed random number generation.
double pop()
Pop a new number from the buffer.
Binomial * clone() const override
Clone parameters.
double m_sigma
Sigma of the Gauss distribution.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the BreitWigner distributed random number generation with cut off;.
double maximum() const
Access upper edge.
virtual StatusCode shootArray(std::vector< double > &array, long howmany, long start=0) const =0
Multiple shots returning vector with random number according to specified distribution.
double sigma() const
Access width of the distribution.
Parameters for the Gamma distributed random number generation.
double sigma() const
Access width of the distribution.
BreitWignerCutOff * clone() const override
Clone parameters.
long nEvent() const
Access number of events.
Poisson * clone() const override
Clone parameters.
dictionary g
Definition: gaudirun.py:542
string s
Definition: gaudirun.py:328
BreitWignerCutOff(double m, double g, double c)
Standard Constructor.
constexpr static const auto FAILURE
Definition: StatusCode.h:97
static const InterfaceID & typeID()
Identifier for factory.
Gamma * clone() const override
Clone parameters.
Gamma(double k, double l)
Standard Constructor.
Binomial(long n, double p)
Standard Constructor.
double m_aValue
StudentT distribution parameter.
double sigma() const
Access sigma of the distribution.
Chi2(long n_dof)
Standard Constructor.
double mean() const
Access mean value of the distribution.
Parameters for the Gaussian tail number generation.
Generate a random number Generator following generally distributed random values, given a user-define...
Parameters for the Gauss random number generation.
#define GAUDI_API
Definition: Kernel.h:81
Bit * clone() const override
Clone parameters.
DefinedPdf * clone() const override
Clone parameters.
long m_nDOF
Number of degrees of freedom.
double mean() const
Access mean value of the distribution.
Parameters for the BreitWigner distributed random number generation.
Poisson(double m)
Standard Constructor.
static const InterfaceID & typeID()
Identifier for factory.
double m_mean
Mean and Gamma parameter of the Breit-Wigner distribution.
Exponential(double m)
Standard Constructor.
std::vector< double > & pdf()
Access pdf.
static const InterfaceID & typeID()
Identifier for factory.