The Gaudi Framework  v29r0 (ff2e7097)
RndmGenerators.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_RNDMGENGENERATORS_H
2 #define GAUDIKERNEL_RNDMGENGENERATORS_H
3 
4 // STL include files
5 #include <vector>
6 
7 // Framework include files
8 #include "GaudiKernel/IRndmGen.h"
9 #include "GaudiKernel/SmartIF.h"
10 
11 // Forward declarations
12 class IRndmGen;
13 class IRndmGenSvc;
14 
15 namespace Rndm
16 {
17 
18  template <class TYPE>
19  class Generator;
20 
24  {
25  protected:
27  friend class Generator<Gauss>;
29  double m_mean;
31  double m_sigma;
32 
33  public:
35  Gauss( double m, double s ) : IRndmGen::Param( IID_IRndmGauss ), m_mean( m ), m_sigma( s ) {}
37  ~Gauss() override = default;
39  double mean() const { return m_mean; }
41  double sigma() const { return m_sigma; }
43  static const InterfaceID& typeID() { return IID_IRndmGauss; }
45  Gauss* clone() const override { return new Gauss( m_mean, m_sigma ); }
46  };
47 
51  {
52  protected:
54  double m_mean;
55 
56  public:
58  Exponential( double m ) : IRndmGen::Param( IID_IRndmExponential ), m_mean( m ) {}
60  ~Exponential() override = default;
62  double mean() const { return m_mean; }
64  static const InterfaceID& typeID() { return IID_IRndmExponential; }
66  Exponential* clone() const override { return new Exponential( m_mean ); }
67  };
68 
72  {
73  friend class Generator<Chi2>;
74 
75  protected:
77  long m_nDOF;
78 
79  public:
81  Chi2( long n_dof ) : IRndmGen::Param( IID_IRndmChi2 ), m_nDOF( n_dof ) {}
83  ~Chi2() override = default;
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  {
96  friend class Generator<BreitWigner>;
97 
98  protected:
100  double m_mean, m_gamma;
101 
102  public:
104  BreitWigner( double m, double g ) : IRndmGen::Param( IID_IRndmBreitWigner ), m_mean( m ), m_gamma( g ) {}
106  ~BreitWigner() override = default;
108  double mean() const { return m_mean; }
110  double gamma() const { return m_gamma; }
112  static const InterfaceID& typeID() { return IID_IRndmBreitWigner; }
114  BreitWigner* clone() const override { return new BreitWigner( m_mean, m_gamma ); }
115  };
116 
120  {
121  friend class Generator<Landau>;
122 
123  protected:
125  double m_mean, m_sigma;
126 
127  public:
129  Landau( double m, double s ) : IRndmGen::Param( IID_IRndmLandau ), m_mean( m ), m_sigma( s ) {}
131  ~Landau() override = default;
133  double mean() const { return m_mean; }
135  double sigma() const { return m_sigma; }
137  static const InterfaceID& typeID() { return IID_IRndmLandau; }
139  Landau* clone() const override { return new Landau( m_mean, m_sigma ); }
140  };
141 
146  {
148 
149  protected:
151  double m_mean, m_gamma, m_cut;
152 
153  public:
155  BreitWignerCutOff( double m, double g, double c )
156  : IRndmGen::Param( IID_IRndmBreitWignerCutOff ), m_mean( m ), m_gamma( g ), m_cut( c )
157  {
158  }
160  ~BreitWignerCutOff() override = default;
162  double mean() const { return m_mean; }
164  double gamma() const { return m_gamma; }
166  double cutOff() const { return m_cut; }
168  static const InterfaceID& typeID() { return IID_IRndmBreitWignerCutOff; }
170  BreitWignerCutOff* clone() const override { return new BreitWignerCutOff( m_mean, m_gamma, m_cut ); }
171  };
172 
176  {
177  friend class Generator<StudentT>;
178 
179  protected:
181  double m_aValue;
182 
183  public:
185  StudentT( double a ) : IRndmGen::Param( IID_IRndmStudentT ), m_aValue( a ) {}
187  ~StudentT() override = default;
189  double aValue() const { return m_aValue; }
191  static const InterfaceID& typeID() { return IID_IRndmStudentT; }
193  StudentT* clone() const override { return new StudentT( m_aValue ); }
194  };
195 
199  {
200  friend class Generator<Gamma>;
201 
202  protected:
204  double m_kValue;
206  double m_lambda;
207 
208  public:
210  Gamma( double k, double l ) : IRndmGen::Param( IID_IRndmGamma ), m_kValue( k ), m_lambda( l ) {}
212  ~Gamma() override = default;
214  double kValue() const { return m_kValue; }
216  double lambda() const { return m_lambda; }
218  static const InterfaceID& typeID() { return IID_IRndmGamma; }
220  Gamma* clone() const override { return new Gamma( m_kValue, m_lambda ); }
221  };
222 
227  {
228  friend class Generator<Poisson>;
229 
230  protected:
232  double m_mean;
233 
234  public:
236  Poisson( double m ) : IRndmGen::Param( IID_IRndmPoisson ), m_mean( m ) {}
238  ~Poisson() override = default;
240  double mean() const { return m_mean; }
242  static const InterfaceID& typeID() { return IID_IRndmPoisson; }
244  Poisson* clone() const override { return new Poisson( m_mean ); }
245  };
246 
251  {
252  protected:
254  long m_nEvent;
257 
258  public:
260  Binomial( long n, double p ) : IRndmGen::Param( IID_IRndmBinomial ), m_nEvent( n ), m_probability( p ) {}
262  ~Binomial() override = default;
264  long nEvent() const { return m_nEvent; }
266  double probability() const { return m_probability; }
268  static const InterfaceID& typeID() { return IID_IRndmBinomial; }
270  Binomial* clone() const override { return new Binomial( m_nEvent, m_probability ); }
271  };
272 
277  {
278  protected:
280  double m_minimum;
282  double m_maximum;
283 
284  public:
286  Flat( double mi, double ma ) : IRndmGen::Param( IID_IRndmFlat ), m_minimum( mi ), m_maximum( ma ) {}
288  ~Flat() override = default;
290  double minimum() const { return m_minimum; }
292  double maximum() const { return m_maximum; }
294  static const InterfaceID& typeID() { return IID_IRndmFlat; }
296  Flat* clone() const override { return new Flat( m_minimum, m_maximum ); }
297  };
298 
302  {
303  public:
305  Bit() : IRndmGen::Param( IID_IRndmBit ) {}
307  ~Bit() override = default;
309  static const InterfaceID& typeID() { return IID_IRndmBit; }
311  Bit* clone() const override { return new Bit(); }
312  };
313 
331  {
332  protected:
337 
338  public:
340  DefinedPdf( const std::vector<double>& pdf, long intpol )
341  : IRndmGen::Param( IID_IRndmDefinedPdf ), m_pdf( pdf ), m_interpolation( intpol )
342  {
343  }
345  ~DefinedPdf() override = default;
347  std::vector<double>& pdf() { return m_pdf; }
349  long interpolation() const { return m_interpolation; }
351  static const InterfaceID& typeID() { return IID_IRndmDefinedPdf; }
353  DefinedPdf* clone() const override { return new DefinedPdf( m_pdf, m_interpolation ); }
354  };
355 
359  {
360  protected:
362  double m_cut;
364  double m_sigma;
365 
366  public:
368  GaussianTail( double a, double s ) : IRndmGen::Param( IID_IRndmGaussianTail ), m_cut( a ), m_sigma( s ) {}
370  ~GaussianTail() override = default;
372  double cut() const { return m_cut; }
374  double sigma() const { return m_sigma; }
376  static const InterfaceID& typeID() { return IID_IRndmGaussianTail; }
378  GaussianTail* clone() const override { return new GaussianTail( m_cut, m_sigma ); }
379  };
380 
397  {
398  protected:
401 
402  public:
404  Numbers() = default;
406  Numbers( const Numbers& ) = default;
408  Numbers( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
410  virtual ~Numbers();
412  virtual StatusCode initialize( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
413 #if !defined( GAUDI_V22_API ) || defined( G22_NEW_SVCLOCATOR )
414  Numbers( IRndmGenSvc* svc, const IRndmGen::Param& par );
417  virtual StatusCode initialize( IRndmGenSvc* svc, const IRndmGen::Param& par );
418 #endif
419  virtual StatusCode finalize();
422  operator bool() const { return m_generator; }
424  double operator()() { return this->shoot(); }
426  double pop() { return this->shoot(); }
428  double shoot() { return m_generator ? m_generator->shoot() : -1; }
431  {
432  return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
433  }
434  };
435 }
436 #endif // GAUDIKERNEL_RNDMGENGENERATORS_H
Binomial * clone() const override
Clone parameters.
Gamma * clone() const override
Clone parameters.
StudentT * clone() const override
Clone parameters.
virtual double shoot() const =0
Single shot returning single random number according to specified distribution.
long nDOF() const
Access mean value of the distribution.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the bit value generation: returns values 0 and 1.
double m_mean
Mean, Gamma and cut off parameter of the Breit-Wigner distribution.
static const InterfaceID & typeID()
Identifier for factory.
GaussianTail(double a, double s)
Standard Constructor.
double m_kValue
k Value
double m_minimum
Lower boundary for random numbers.
static const InterfaceID & typeID()
Identifier for factory.
double mean() const
Access mean value of the distribution.
Parameters for the Poisson distributed random number generation with a given mean.
Exponential * clone() const override
Clone parameters.
double mean() const
Access mean value of the distribution.
Definition of a interface for a generic random number generators.
Definition: IRndmGen.h:34
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.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the Gauss random number generation.
Gauss(double m, double s)
Standard Constructor.
Bit * clone() const override
Clone parameters.
Flat(double mi, double ma)
Standard Constructor.
double mean() const
Access mean value of the distribution.
double shoot()
Pop a new number from the buffer.
double lambda() const
Access Lambda parameter.
long m_nEvent
Number of events the binomial destribution corresponds to.
double m_mean
Mean value of the exponential distribution.
BreitWigner(double m, double g)
Standard Constructor.
long nEvent() const
Access number of events.
long interpolation() const
Access interpolation type.
Landau(double m, double s)
Standard Constructor.
Flat * clone() const override
Clone parameters.
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:29
Bit()
Standard Constructor.
double probability() const
Access number of events.
Poisson * 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:35
double m_cut
Cut on the Gaussian tail distribution.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
constexpr double m
Definition: SystemOfUnits.h:94
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.
StudentT(double a)
Standard Constructor.
double cutOff() const
Access width of the distribution.
start
Definition: IOTest.py:99
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.
double maximum() const
Access upper edge.
Parameters for the StudentT distributed random number generation.
double m_lambda
Lambda parameter.
static const InterfaceID & typeID()
Identifier for factory.
dictionary l
Definition: gaudirun.py:440
Parameters for the Binomial distributed random number generation.
StatusCode shootArray(std::vector< double > &array, long num, long start=0)
Pop a new number from the buffer.
double kValue() const
Access K parameter.
double sigma() const
Access width of the distribution.
Parameters for the Landau distributed random number generation.
BreitWigner * clone() const override
Clone parameters.
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.
double m_sigma
Sigma of the Gauss distribution.
Landau * clone() const override
Clone parameters.
static const InterfaceID & typeID()
Identifier for factory.
Parameters for the BreitWigner distributed random number generation with cut off;.
double sigma() const
Access width of the distribution.
double mean() const
Access mean value of the distribution.
Parameters for the Gamma distributed random number generation.
dictionary g
Definition: gaudirun.py:439
string s
Definition: gaudirun.py:253
BreitWignerCutOff(double m, double g, double c)
Standard Constructor.
static const InterfaceID & typeID()
Identifier for factory.
Gamma(double k, double l)
Standard Constructor.
BreitWignerCutOff * clone() const override
Clone parameters.
double gamma() const
Access width of the distribution.
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.
Binomial(long n, double p)
Standard Constructor.
double m_aValue
StudentT distribution parameter.
Gauss * clone() const override
Clone parameters.
Chi2(long n_dof)
Standard Constructor.
double aValue() const
Access A parameter.
double cut() const
Access cut value of the distribution.
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:110
Chi2 * clone() const override
Clone parameters.
double minimum() const
Access lower edge.
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 gamma() const
Access width of the distribution.
double m_mean
Mean and Gamma parameter of the Breit-Wigner distribution.
GaussianTail * clone() const override
Clone parameters.
double sigma() const
Access sigma of the distribution.
Exponential(double m)
Standard Constructor.
std::vector< double > & pdf()
Access pdf.
static const InterfaceID & typeID()
Identifier for factory.