The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
RndmGenerators.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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#pragma once
12
14#include <GaudiKernel/SmartIF.h>
15#include <vector>
16
17class IRndmGen;
18class IRndmGenSvc;
19
20namespace Rndm {
21
22 template <class TYPE>
23 class Generator;
24
28 protected:
30 friend class Generator<Gauss>;
32 double m_mean;
34 double m_sigma;
35
36 public:
38 Gauss( double m, double s ) : IRndmGen::Param( IID_IRndmGauss ), m_mean( m ), m_sigma( s ) {}
40 double mean() const { return m_mean; }
42 double sigma() const { return m_sigma; }
44 static const InterfaceID& typeID() { return IID_IRndmGauss; }
46 Gauss* clone() const override { return new Gauss( m_mean, m_sigma ); }
47 };
48
52 protected:
54 double m_mean;
55
56 public:
58 Exponential( double m ) : IRndmGen::Param( IID_IRndmExponential ), m_mean( m ) {}
60 double mean() const { return m_mean; }
62 static const InterfaceID& typeID() { return IID_IRndmExponential; }
64 Exponential* clone() const override { return new Exponential( m_mean ); }
65 };
66
70 friend class Generator<Chi2>;
71
72 protected:
74 long m_nDOF;
75
76 public:
78 Chi2( long n_dof ) : IRndmGen::Param( IID_IRndmChi2 ), m_nDOF( n_dof ) {}
80 long nDOF() const { return m_nDOF; }
82 static const InterfaceID& typeID() { return IID_IRndmChi2; }
84 Chi2* clone() const override { return new Chi2( m_nDOF ); }
85 };
86
90 friend class Generator<BreitWigner>;
91
92 protected:
94 double m_mean, m_gamma;
95
96 public:
98 BreitWigner( double m, double g ) : IRndmGen::Param( IID_IRndmBreitWigner ), m_mean( m ), m_gamma( g ) {}
100 double mean() const { return m_mean; }
102 double gamma() const { return m_gamma; }
104 static const InterfaceID& typeID() { return IID_IRndmBreitWigner; }
106 BreitWigner* clone() const override { return new BreitWigner( m_mean, m_gamma ); }
107 };
108
112 friend class Generator<Landau>;
113
114 protected:
117
118 public:
120 Landau( double m, double s ) : IRndmGen::Param( IID_IRndmLandau ), m_mean( m ), m_sigma( s ) {}
122 double mean() const { return m_mean; }
124 double sigma() const { return m_sigma; }
126 static const InterfaceID& typeID() { return IID_IRndmLandau; }
128 Landau* clone() const override { return new Landau( m_mean, m_sigma ); }
129 };
130
135 friend class Generator<BreitWignerCutOff>;
136
137 protected:
140
141 public:
143 BreitWignerCutOff( double m, double g, double c )
144 : IRndmGen::Param( IID_IRndmBreitWignerCutOff ), m_mean( m ), m_gamma( g ), m_cut( c ) {}
145
146 double mean() const { return m_mean; }
148 double gamma() const { return m_gamma; }
150 double cutOff() const { return m_cut; }
152 static const InterfaceID& typeID() { return IID_IRndmBreitWignerCutOff; }
154 BreitWignerCutOff* clone() const override { return new BreitWignerCutOff( m_mean, m_gamma, m_cut ); }
155 };
156
160 friend class Generator<StudentT>;
161
162 protected:
164 double m_aValue;
165
166 public:
168 StudentT( double a ) : IRndmGen::Param( IID_IRndmStudentT ), m_aValue( a ) {}
170 double aValue() const { return m_aValue; }
172 static const InterfaceID& typeID() { return IID_IRndmStudentT; }
174 StudentT* clone() const override { return new StudentT( m_aValue ); }
175 };
176
180 friend class Generator<Gamma>;
181
182 protected:
184 double m_kValue;
186 double m_lambda;
187
188 public:
190 Gamma( double k, double l ) : IRndmGen::Param( IID_IRndmGamma ), m_kValue( k ), m_lambda( l ) {}
192 double kValue() const { return m_kValue; }
194 double lambda() const { return m_lambda; }
196 static const InterfaceID& typeID() { return IID_IRndmGamma; }
198 Gamma* clone() const override { return new Gamma( m_kValue, m_lambda ); }
199 };
200
205 friend class Generator<Poisson>;
206
207 protected:
209 double m_mean;
210
211 public:
213 Poisson( double m ) : IRndmGen::Param( IID_IRndmPoisson ), m_mean( m ) {}
215 double mean() const { return m_mean; }
217 static const InterfaceID& typeID() { return IID_IRndmPoisson; }
219 Poisson* clone() const override { return new Poisson( m_mean ); }
220 };
221
226 protected:
231
232 public:
234 Binomial( long n, double p ) : IRndmGen::Param( IID_IRndmBinomial ), m_nEvent( n ), m_probability( p ) {}
236 long nEvent() const { return m_nEvent; }
238 double probability() const { return m_probability; }
240 static const InterfaceID& typeID() { return IID_IRndmBinomial; }
242 Binomial* clone() const override { return new Binomial( m_nEvent, m_probability ); }
243 };
244
249 protected:
251 double m_minimum;
253 double m_maximum;
254
255 public:
257 Flat( double mi, double ma ) : IRndmGen::Param( IID_IRndmFlat ), m_minimum( mi ), m_maximum( ma ) {}
259 double minimum() const { return m_minimum; }
261 double maximum() const { return m_maximum; }
263 static const InterfaceID& typeID() { return IID_IRndmFlat; }
265 Flat* clone() const override { return new Flat( m_minimum, m_maximum ); }
266 };
267
271 public:
273 Bit() : IRndmGen::Param( IID_IRndmBit ) {}
275 static const InterfaceID& typeID() { return IID_IRndmBit; }
277 Bit* clone() const override { return new Bit(); }
278 };
279
297 protected:
299 std::vector<double> m_pdf;
302
303 public:
305 DefinedPdf( const std::vector<double>& pdf, long intpol )
306 : IRndmGen::Param( IID_IRndmDefinedPdf ), m_pdf( pdf ), m_interpolation( intpol ) {}
307
308 std::vector<double>& pdf() { return m_pdf; }
310 long interpolation() const { return m_interpolation; }
312 static const InterfaceID& typeID() { return IID_IRndmDefinedPdf; }
314 DefinedPdf* clone() const override { return new DefinedPdf( m_pdf, m_interpolation ); }
315 };
316
320 protected:
322 double m_cut;
324 double m_sigma;
325
326 public:
328 GaussianTail( double a, double s ) : IRndmGen::Param( IID_IRndmGaussianTail ), m_cut( a ), m_sigma( s ) {}
330 double cut() const { return m_cut; }
332 double sigma() const { return m_sigma; }
334 static const InterfaceID& typeID() { return IID_IRndmGaussianTail; }
336 GaussianTail* clone() const override { return new GaussianTail( m_cut, m_sigma ); }
337 };
338
355 protected:
358
359 public:
361 Numbers() = default;
363 Numbers( const Numbers& ) = default;
365 Numbers( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
367 virtual ~Numbers();
369 virtual StatusCode initialize( const SmartIF<IRndmGenSvc>& svc, const IRndmGen::Param& par );
371 virtual StatusCode finalize();
373 operator bool() const { return m_generator; }
375 double operator()() const { return this->shoot(); }
377 double pop() const { return this->shoot(); }
379 double shoot() const { return m_generator ? m_generator->shoot() : -1; }
381 StatusCode shootArray( std::vector<double>& array, long num, long start = 0 ) const {
382 return m_generator ? m_generator->shootArray( array, num, start ) : StatusCode::FAILURE;
383 }
384 };
385} // namespace Rndm
#define GAUDI_API
Definition Kernel.h:49
Param(const InterfaceID &type=IID_IRndmFlat)
Standard constructor.
Definition IRndmGen.h:52
Definition of a interface for a generic random number generators.
Definition IRndmGen.h:40
Random Generator service interface definition Definition of a interface for a service to access rando...
Definition IRndmGenSvc.h:40
Interface ID class.
Definition IInterface.h:38
long m_nEvent
Number of events the binomial destribution corresponds to.
double m_probability
And the probability for having success.
long nEvent() const
Access number of events.
double probability() const
Access number of events.
static const InterfaceID & typeID()
Identifier for factory.
Binomial * clone() const override
Clone parameters.
Binomial(long n, double p)
Standard Constructor.
Bit()
Standard Constructor.
Bit * clone() const override
Clone parameters.
static const InterfaceID & typeID()
Identifier for factory.
double m_mean
Mean, Gamma and cut off parameter of the Breit-Wigner distribution.
double cutOff() const
Access width of the distribution.
double mean() const
Access mean value of the distribution.
static const InterfaceID & typeID()
Identifier for factory.
double gamma() const
Access width of the distribution.
BreitWignerCutOff * clone() const override
Clone parameters.
BreitWignerCutOff(double m, double g, double c)
Standard Constructor.
double mean() const
Access mean value of the distribution.
BreitWigner(double m, double g)
Standard Constructor.
BreitWigner * clone() const override
Clone parameters.
double gamma() const
Access width of the distribution.
double m_mean
Mean and Gamma parameter of the Breit-Wigner distribution.
static const InterfaceID & typeID()
Identifier for factory.
static const InterfaceID & typeID()
Identifier for factory.
long m_nDOF
Number of degrees of freedom.
long nDOF() const
Access mean value of the distribution.
Chi2 * clone() const override
Clone parameters.
Chi2(long n_dof)
Standard Constructor.
DefinedPdf * clone() const override
Clone parameters.
std::vector< double > & pdf()
Access pdf.
long m_interpolation
Interpolation type.
DefinedPdf(const std::vector< double > &pdf, long intpol)
Standard Constructor.
std::vector< double > m_pdf
Vector containing probability distribution function.
long interpolation() const
Access interpolation type.
static const InterfaceID & typeID()
Identifier for factory.
double m_mean
Mean value of the exponential distribution.
Exponential(double m)
Standard Constructor.
static const InterfaceID & typeID()
Identifier for factory.
double mean() const
Access mean value of the distribution.
Exponential * clone() const override
Clone parameters.
Flat(double mi, double ma)
Standard Constructor.
double maximum() const
Access upper edge.
double m_maximum
Upper boundary for random numbers.
double minimum() const
Access lower edge.
double m_minimum
Lower boundary for random numbers.
Flat * clone() const override
Clone parameters.
static const InterfaceID & typeID()
Identifier for factory.
double kValue() const
Access K parameter.
double m_lambda
Lambda parameter.
static const InterfaceID & typeID()
Identifier for factory.
double m_kValue
k Value
double lambda() const
Access Lambda parameter.
Gamma(double k, double l)
Standard Constructor.
Gamma * clone() const override
Clone parameters.
double m_sigma
Sigma of the Gauss distribution.
double mean() const
Access mean value of the distribution.
double sigma() const
Access width of the distribution.
Gauss(double m, double s)
Standard Constructor.
Gauss * clone() const override
Clone parameters.
double m_mean
Mean of the Gauss distribution.
static const InterfaceID & typeID()
Identifier for factory.
double sigma() const
Access sigma of the distribution.
GaussianTail(double a, double s)
Standard Constructor.
double m_cut
Cut on the Gaussian tail distribution.
double cut() const
Access cut value of the distribution.
GaussianTail * clone() const override
Clone parameters.
static const InterfaceID & typeID()
Identifier for factory.
double m_sigma
Sigma of the Gauss ditribution.
static const InterfaceID & typeID()
Identifier for factory.
Landau * clone() const override
Clone parameters.
Landau(double m, double s)
Standard Constructor.
double mean() const
Access mean value of the distribution.
double sigma() const
Access width of the distribution.
double m_mean
Mean and Gamma parameter of the Breit-Wigner distribution.
double pop() const
Pop a new number from the buffer.
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
double shoot() const
Pop a new number from the buffer.
StatusCode shootArray(std::vector< double > &array, long num, long start=0) const
Pop a new number from the buffer.
virtual StatusCode finalize()
Finalization.
Numbers()=default
Standard constructor.
SmartIF< IRndmGen > m_generator
Pointer to random number generator.
Numbers(const Numbers &)=default
Copy constructor.
double operator()() const
Operator () for the use within STL.
double mean() const
Access mean value of the distribution.
Poisson * clone() const override
Clone parameters.
double m_mean
Mean value of the Poisson distribution.
static const InterfaceID & typeID()
Identifier for factory.
Poisson(double m)
Standard Constructor.
double aValue() const
Access A parameter.
static const InterfaceID & typeID()
Identifier for factory.
double m_aValue
StudentT distribution parameter.
StudentT * clone() const override
Clone parameters.
StudentT(double a)
Standard Constructor.
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
constexpr static const auto FAILURE
Definition StatusCode.h:100