Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/Math/QuasiRandom.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/mathmore:$Id$
0002 // Author: L. Moneta, A. Zsenei   08/2005
0003 
0004  /**********************************************************************
0005   *                                                                    *
0006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
0007   *                                                                    *
0008   * This library is free software; you can redistribute it and/or      *
0009   * modify it under the terms of the GNU General Public License        *
0010   * as published by the Free Software Foundation; either version 2     *
0011   * of the License, or (at your option) any later version.             *
0012   *                                                                    *
0013   * This library is distributed in the hope that it will be useful,    *
0014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
0015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
0016   * General Public License for more details.                           *
0017   *                                                                    *
0018   * You should have received a copy of the GNU General Public License  *
0019   * along with this library (see file COPYING); if not, write          *
0020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
0021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
0022   *                                                                    *
0023   **********************************************************************/
0024 
0025 // Header file for class GSLRandom
0026 //
0027 // Created by: moneta  at Sun Nov 21 16:26:03 2004
0028 //
0029 // Last update: Sun Nov 21 16:26:03 2004
0030 //
0031 #ifndef ROOT_Math_QuasiRandom
0032 #define ROOT_Math_QuasiRandom
0033 
0034 #include <string>
0035 
0036 /**
0037    @defgroup QuasiRandom QuasiRandom number generators and distributions
0038    Classes for generating QuasiRandom numbers and based on GSL.
0039    \note MathMore needs to be enabled for these integrator to be available.
0040    @ingroup Random
0041 */
0042 
0043 namespace ROOT {
0044 namespace Math {
0045 
0046 
0047 //_____________________________________________________________________________________
0048 /**
0049    User class for MathMore random numbers template on the Engine type.
0050    The API of this class followed that of the class ROOT::Math::Random
0051    It must be implemented using as Engine one of the derived classes of
0052    ROOT::Math::GSLQuasiRandomEngine, like ROOT::Math::GSLQrngSobol
0053 
0054    @ingroup QuasiRandom
0055 
0056 */
0057 template < class Engine>
0058 class QuasiRandom {
0059 
0060 public:
0061 
0062 
0063    /**
0064       Create a QuasiRandom generator. Use default engine constructor.
0065       Engine will  be initialized via Initialize() function in order to
0066       allocate resources
0067    */
0068    QuasiRandom(unsigned int dimension = 1) {
0069       fEngine.Initialize(dimension);
0070    }
0071 
0072 
0073    /**
0074       Create a QuasiRandom generator based on a provided generic engine.
0075       Engine will  be initialized via Initialize() function in order to
0076       allocate resources
0077    */
0078    explicit QuasiRandom(const Engine & e, unsigned int dimension = 1) : fEngine(e) {
0079       fEngine.Initialize(dimension);
0080    }
0081 
0082    /**
0083       Destructor: call Terminate() function of engine to free any
0084       allocated resource
0085    */
0086    ~QuasiRandom() {
0087       fEngine.Terminate();
0088    }
0089 
0090    /**
0091       Generate next quasi random numbers points
0092    */
0093    bool Next(double * x) {
0094       return fEngine(x);
0095    }
0096 
0097    /**
0098       Generate next quasi random numbers point (1 - dimension)
0099    */
0100    double Next() {
0101       return fEngine();
0102    }
0103 
0104    /**
0105        Generate quasi random numbers between ]0,1[
0106        0 and 1 are excluded
0107        Function to be compatible with  ROOT TRandom compatibility
0108    */
0109    double Rndm() {
0110       return fEngine();
0111    }
0112 
0113    /**
0114       skip the next n number and jumb directly to the current state + n
0115    */
0116    bool Skip(unsigned int n) {
0117       return fEngine.Skip(n);
0118    }
0119    /**
0120        Generate an array of random numbers between ]0,1[
0121        Function to preserve ROOT Trandom compatibility
0122        The array will be filled as   x1,y1,z1,....x2,y2,z2,...
0123    */
0124    bool RndmArray(int n, double * array) {
0125       return fEngine.GenerateArray(array, array+n*NDim());
0126    }
0127 
0128    /**
0129       Return the type (name) of the used generator
0130    */
0131    std::string Type() const {
0132       return fEngine.Name();
0133    }
0134 
0135    /**
0136       Return the size of the generator state
0137    */
0138    unsigned int EngineSize() const {
0139       return fEngine.Size();
0140    }
0141 
0142    /**
0143       Return the dimension of the generator
0144    */
0145    unsigned int NDim() const {
0146       return fEngine.NDim();
0147    }
0148 
0149    /**
0150       Return the name of the generator
0151    */
0152    std::string Name() const {
0153       return fEngine.Name();
0154    }
0155 
0156 private:
0157 
0158    Engine fEngine;
0159 
0160 };
0161 
0162 
0163 
0164 } // namespace Math
0165 } // namespace ROOT
0166 
0167 #include "Math/GSLQuasiRandom.h"
0168 
0169 
0170 
0171 
0172 namespace ROOT {
0173 namespace Math {
0174 
0175 
0176 typedef QuasiRandom<ROOT::Math::GSLQRngSobol> QuasiRandomSobol;
0177 typedef QuasiRandom<ROOT::Math::GSLQRngNiederreiter2> QuasiRandomNiederreiter;
0178 
0179 } // namespace Math
0180 } // namespace ROOT
0181 
0182 
0183 #endif /* ROOT_Math_QuasiRandom */
0184 
0185 
0186