RooRandom.cxx

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Project: RooFit                                                           *
00003  * Package: RooFitCore                                                       *
00004  * @(#)root/roofitcore:$Id: RooRandom.cxx 24285 2008-06-16 15:05:15Z wouter $
00005  * Authors:                                                                  *
00006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
00007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
00008  *                                                                           *
00009  * Copyright (c) 2000-2005, Regents of the University of California          *
00010  *                          and Stanford University. All rights reserved.    *
00011  *                                                                           *
00012  * Redistribution and use in source and binary forms,                        *
00013  * with or without modification, are permitted according to the terms        *
00014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
00015  *****************************************************************************/
00016 
00017 //////////////////////////////////////////////////////////////////////////////
00018 //
00019 // BEGIN_HTML
00020 // This class provides a static interface for generating random numbers.
00021 // By default a private copy of TRandom3 is used to generate all random numbers.
00022 // END_HTML
00023 //
00024 
00025 #include "RooFit.h"
00026 
00027 #include "RooRandom.h"
00028 #include "RooRandom.h"
00029 #include "RooQuasiRandomGenerator.h"
00030 
00031 #include "TRandom3.h"
00032 
00033 #include <assert.h>
00034 
00035 ClassImp(RooRandom)
00036   ;
00037 
00038 
00039 
00040 //_____________________________________________________________________________
00041 TRandom *RooRandom::randomGenerator() 
00042 {
00043   // Return a pointer to a singleton random-number generator
00044   // implementation. Creates the object the first time it is called.
00045   
00046   static TRandom *_theGenerator= 0;
00047   if(0 == _theGenerator) _theGenerator= new TRandom3();
00048   return _theGenerator;
00049 }
00050 
00051 
00052 //_____________________________________________________________________________
00053 RooQuasiRandomGenerator *RooRandom::quasiGenerator() 
00054 {
00055   // Return a pointer to a singleton quasi-random generator
00056   // implementation. Creates the object the first time it is called.
00057   
00058   static RooQuasiRandomGenerator *_theGenerator= 0;
00059   if(0 == _theGenerator) _theGenerator= new RooQuasiRandomGenerator();
00060   return _theGenerator;
00061 }
00062 
00063 
00064 //_____________________________________________________________________________
00065 Double_t RooRandom::uniform(TRandom *generator) 
00066 {
00067   // Return a number uniformly distributed from (0,1)
00068 
00069   return generator->Rndm();
00070 }
00071 
00072 
00073 //_____________________________________________________________________________
00074 void RooRandom::uniform(UInt_t dimension, Double_t vector[], TRandom *generator) 
00075 {
00076   // Fill the vector provided with random numbers uniformly distributed from (0,1)
00077   
00078   for(UInt_t index= 0; index < dimension; index++) vector[index]= uniform(generator);
00079 }
00080 
00081 
00082 //_____________________________________________________________________________
00083 UInt_t RooRandom::integer(UInt_t n, TRandom *generator) 
00084 {
00085   // Return an integer uniformly distributed from [0,n-1]
00086 
00087   return generator->Integer(n);
00088 }
00089 
00090 
00091 //_____________________________________________________________________________
00092 Double_t RooRandom::gaussian(TRandom *generator) 
00093 {
00094   // Return a Gaussian random variable with mean 0 and variance 1.
00095 
00096   return generator->Gaus();
00097 }
00098 
00099 
00100 //_____________________________________________________________________________
00101 Bool_t RooRandom::quasi(UInt_t dimension, Double_t vector[], RooQuasiRandomGenerator *generator) 
00102 {
00103   // Return a quasi-random number in the range (0,1) using the
00104   // Niederreiter base 2 generator described in Bratley, Fox, Niederreiter,
00105   // ACM Trans. Model. Comp. Sim. 2, 195 (1992).
00106 
00107   return generator->generate(dimension,vector);
00108 }

Generated on Tue Jul 5 15:07:07 2011 for ROOT_528-00b_version by  doxygen 1.5.1