The Gaudi Framework  master (37c0b60a)
RndmGenerators.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 
140  friend class Generator<BreitWignerCutOff>;
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  [[deprecated( "use Numbers( SmartIF<IRndmGenSvc>, IRndmGen::Param ) instead" )]] Numbers(
378  IRndmGenSvc* svc, const IRndmGen::Param& par );
380  [[deprecated( "use Numbers::initialize( SmartIF<IRndmGenSvc>, IRndmGen::Param ) instead" )]] virtual StatusCode
381  initialize( IRndmGenSvc* svc, const IRndmGen::Param& par );
382 #endif
383  virtual StatusCode finalize();
386  operator bool() const { return m_generator; }
388  double operator()() const { return this->shoot(); }
390  double pop() const { return this->shoot(); }
392  double shoot() const { return m_generator ? m_generator->shoot() : -1; }
394  StatusCode shootArray( std::vector<double>& array, long num, long start = 0 ) const {
395  return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
396  }
397  };
398 } // namespace Rndm
399 #endif // GAUDIKERNEL_RNDMGENGENERATORS_H
Rndm::DefinedPdf::interpolation
long interpolation() const
Access interpolation type.
Definition: RndmGenerators.h:315
Rndm::Gauss::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:49
Rndm::BreitWignerCutOff::mean
double mean() const
Access mean value of the distribution.
Definition: RndmGenerators.h:151
Rndm::Flat::m_maximum
double m_maximum
Upper boundary for random numbers.
Definition: RndmGenerators.h:258
Rndm::BreitWignerCutOff::gamma
double gamma() const
Access width of the distribution.
Definition: RndmGenerators.h:153
Rndm::Poisson::mean
double mean() const
Access mean value of the distribution.
Definition: RndmGenerators.h:220
Rndm::Numbers::operator()
double operator()() const
Operator () for the use within STL.
Definition: RndmGenerators.h:388
Rndm::GaussianTail::clone
GaussianTail * clone() const override
Clone parameters.
Definition: RndmGenerators.h:341
Rndm::Chi2::m_nDOF
long m_nDOF
Number of degrees of freedom.
Definition: RndmGenerators.h:79
Rndm::Binomial::nEvent
long nEvent() const
Access number of events.
Definition: RndmGenerators.h:241
gaudirun.s
string s
Definition: gaudirun.py:346
Rndm::GaussianTail::GaussianTail
GaussianTail(double a, double s)
Standard Constructor.
Definition: RndmGenerators.h:333
Rndm::Poisson::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:222
std::vector< double >
Rndm::Gauss::m_sigma
double m_sigma
Sigma of the Gauss distribution.
Definition: RndmGenerators.h:39
Rndm::Exponential::m_mean
double m_mean
Mean value of the exponential distribution.
Definition: RndmGenerators.h:59
Rndm::Binomial::Binomial
Binomial(long n, double p)
Standard Constructor.
Definition: RndmGenerators.h:239
Rndm::DefinedPdf::DefinedPdf
DefinedPdf(const std::vector< double > &pdf, long intpol)
Standard Constructor.
Definition: RndmGenerators.h:310
Rndm::Numbers::m_generator
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Definition: RndmGenerators.h:362
Rndm::Landau::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:131
Rndm::StudentT
Parameters for the StudentT distributed random number generation.
Definition: RndmGenerators.h:164
gaudirun.c
c
Definition: gaudirun.py:525
Rndm::Gauss::m_mean
double m_mean
Mean of the Gauss distribution.
Definition: RndmGenerators.h:37
Rndm::DefinedPdf::m_interpolation
long m_interpolation
Interpolation type.
Definition: RndmGenerators.h:306
Rndm::DefinedPdf::clone
DefinedPdf * clone() const override
Clone parameters.
Definition: RndmGenerators.h:319
Rndm::GaussianTail
Parameters for the Gaussian tail number generation.
Definition: RndmGenerators.h:324
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
Rndm::Bit::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:280
IOTest.start
start
Definition: IOTest.py:110
Rndm::BreitWigner::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:109
Rndm::Gauss::clone
Gauss * clone() const override
Clone parameters.
Definition: RndmGenerators.h:51
Rndm::DefinedPdf::m_pdf
std::vector< double > m_pdf
Vector containing probability distribution function.
Definition: RndmGenerators.h:304
Rndm
Definition: RndmGenerators.h:25
Rndm::StudentT::aValue
double aValue() const
Access A parameter.
Definition: RndmGenerators.h:175
Rndm::Exponential::Exponential
Exponential(double m)
Standard Constructor.
Definition: RndmGenerators.h:63
Rndm::Binomial::m_nEvent
long m_nEvent
Number of events the binomial destribution corresponds to.
Definition: RndmGenerators.h:233
Rndm::Flat::maximum
double maximum() const
Access upper edge.
Definition: RndmGenerators.h:266
compareOutputFiles.par
par
Definition: compareOutputFiles.py:477
Rndm::Binomial::clone
Binomial * clone() const override
Clone parameters.
Definition: RndmGenerators.h:247
Rndm::Flat::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:268
Rndm::BreitWignerCutOff
Parameters for the BreitWigner distributed random number generation with cut off;.
Definition: RndmGenerators.h:139
SmartIF.h
Rndm::GaussianTail::m_sigma
double m_sigma
Sigma of the Gauss ditribution.
Definition: RndmGenerators.h:329
IRndmGen.h
Rndm::Landau::m_sigma
double m_sigma
Definition: RndmGenerators.h:121
Rndm::Landau
Parameters for the Landau distributed random number generation.
Definition: RndmGenerators.h:116
Rndm::GaussianTail::m_cut
double m_cut
Cut on the Gaussian tail distribution.
Definition: RndmGenerators.h:327
Rndm::Landau::Landau
Landau(double m, double s)
Standard Constructor.
Definition: RndmGenerators.h:125
Rndm::Numbers::pop
double pop() const
Pop a new number from the buffer.
Definition: RndmGenerators.h:390
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::DefinedPdf::pdf
std::vector< double > & pdf()
Access pdf.
Definition: RndmGenerators.h:313
Rndm::Gamma::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:201
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
gaudirun.g
dictionary g
Definition: gaudirun.py:582
Rndm::Landau::sigma
double sigma() const
Access width of the distribution.
Definition: RndmGenerators.h:129
Rndm::Poisson::m_mean
double m_mean
Mean value of the Poisson distribution.
Definition: RndmGenerators.h:214
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
Rndm::Gamma::kValue
double kValue() const
Access K parameter.
Definition: RndmGenerators.h:197
Rndm::BreitWigner::mean
double mean() const
Access mean value of the distribution.
Definition: RndmGenerators.h:105
Rndm::BreitWigner
Parameters for the BreitWigner distributed random number generation.
Definition: RndmGenerators.h:94
Rndm::Numbers::shoot
double shoot() const
Pop a new number from the buffer.
Definition: RndmGenerators.h:392
Rndm::StudentT::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:177
Rndm::Gamma::Gamma
Gamma(double k, double l)
Standard Constructor.
Definition: RndmGenerators.h:195
IRndmGen::Param
Definition: IRndmGen.h:49
IRndmGenSvc
Definition: IRndmGenSvc.h:45
Rndm::BreitWignerCutOff::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:157
Rndm::Flat::minimum
double minimum() const
Access lower edge.
Definition: RndmGenerators.h:264
SmartIF< IRndmGen >
Rndm::Gamma
Parameters for the Gamma distributed random number generation.
Definition: RndmGenerators.h:184
Rndm::Chi2::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:87
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Rndm::Exponential::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:67
Rndm::Gauss::mean
double mean() const
Access mean value of the distribution.
Definition: RndmGenerators.h:45
Rndm::Numbers::Numbers
Numbers(const Numbers &)=default
Copy constructor.
Rndm::Gamma::m_kValue
double m_kValue
k Value
Definition: RndmGenerators.h:189
Rndm::Chi2::nDOF
long nDOF() const
Access mean value of the distribution.
Definition: RndmGenerators.h:85
Rndm::Bit::Bit
Bit()
Standard Constructor.
Definition: RndmGenerators.h:278
IRndmGen
Definition: IRndmGen.h:44
Rndm::Binomial::probability
double probability() const
Access number of events.
Definition: RndmGenerators.h:243
Rndm::BreitWignerCutOff::m_mean
double m_mean
Mean, Gamma and cut off parameter of the Breit-Wigner distribution.
Definition: RndmGenerators.h:144
Rndm::Gamma::m_lambda
double m_lambda
Lambda parameter.
Definition: RndmGenerators.h:191
Rndm::BreitWigner::m_mean
double m_mean
Mean and Gamma parameter of the Breit-Wigner distribution.
Definition: RndmGenerators.h:99
Rndm::DefinedPdf::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:317
Rndm::BreitWigner::BreitWigner
BreitWigner(double m, double g)
Standard Constructor.
Definition: RndmGenerators.h:103
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:37
Rndm::Poisson::clone
Poisson * clone() const override
Clone parameters.
Definition: RndmGenerators.h:224
gaudirun.l
dictionary l
Definition: gaudirun.py:583
Rndm::StudentT::StudentT
StudentT(double a)
Standard Constructor.
Definition: RndmGenerators.h:173
Rndm::Landau::mean
double mean() const
Access mean value of the distribution.
Definition: RndmGenerators.h:127
Rndm::Flat::Flat
Flat(double mi, double ma)
Standard Constructor.
Definition: RndmGenerators.h:262
Rndm::Gauss::Gauss
Gauss(double m, double s)
Standard Constructor.
Definition: RndmGenerators.h:43
Rndm::Numbers::shootArray
StatusCode shootArray(std::vector< double > &array, long num, long start=0) const
Pop a new number from the buffer.
Definition: RndmGenerators.h:394
Rndm::Bit::clone
Bit * clone() const override
Clone parameters.
Definition: RndmGenerators.h:282
Rndm::Exponential::mean
double mean() const
Access mean value of the distribution.
Definition: RndmGenerators.h:65
Rndm::Flat::m_minimum
double m_minimum
Lower boundary for random numbers.
Definition: RndmGenerators.h:256
Rndm::Poisson::Poisson
Poisson(double m)
Standard Constructor.
Definition: RndmGenerators.h:218
Rndm::Gauss::sigma
double sigma() const
Access width of the distribution.
Definition: RndmGenerators.h:47
Rndm::Chi2::Chi2
Chi2(long n_dof)
Standard Constructor.
Definition: RndmGenerators.h:83
Rndm::DefinedPdf
Generate a random number Generator following generally distributed random values, given a user-define...
Definition: RndmGenerators.h:301
Rndm::BreitWigner::gamma
double gamma() const
Access width of the distribution.
Definition: RndmGenerators.h:107
Rndm::GaussianTail::sigma
double sigma() const
Access sigma of the distribution.
Definition: RndmGenerators.h:337
Rndm::Gamma::lambda
double lambda() const
Access Lambda parameter.
Definition: RndmGenerators.h:199
Rndm::Exponential
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:56
Rndm::StudentT::m_aValue
double m_aValue
StudentT distribution parameter.
Definition: RndmGenerators.h:169
Rndm::GaussianTail::cut
double cut() const
Access cut value of the distribution.
Definition: RndmGenerators.h:335
Rndm::Chi2
Parameters for the Chi2 distributed random number generation.
Definition: RndmGenerators.h:74
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
InterfaceID
Definition: IInterface.h:39
Rndm::Flat::clone
Flat * clone() const override
Clone parameters.
Definition: RndmGenerators.h:270
Rndm::BreitWignerCutOff::cutOff
double cutOff() const
Access width of the distribution.
Definition: RndmGenerators.h:155
Rndm::GaussianTail::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:339
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Rndm::BreitWignerCutOff::BreitWignerCutOff
BreitWignerCutOff(double m, double g, double c)
Standard Constructor.
Definition: RndmGenerators.h:148
Rndm::Binomial::m_probability
double m_probability
And the probability for having success.
Definition: RndmGenerators.h:235
Rndm::Binomial::typeID
static const InterfaceID & typeID()
Identifier for factory.
Definition: RndmGenerators.h:245
Rndm::Binomial
Parameters for the Binomial distributed random number generation.
Definition: RndmGenerators.h:230
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Rndm::Bit
Parameters for the bit value generation: returns values 0 and 1.
Definition: RndmGenerators.h:275
Rndm::Generator
Definition: RndmGenerators.h:28
Rndm::Numbers::Numbers
Numbers()=default
Standard constructor.