Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

util::TRandomNOVA Class Reference

#include <TRandomNOVA.h>

List of all members.

Public Member Functions

 TRandomNOVA (ULong64_t seed0=0, ULong64_t seed1=0, ULong64_t used=0)
 TRandomNOVA (std::vector< ULong64_t > seedvec, ULong64_t used=0)
virtual ~TRandomNOVA ()
virtual void SetSeed (UInt_t seed=0)
virtual void SetSeed (ULong64_t seed0, ULong64_t seed1, ULong64_t used=0)
virtual ULong64_t GetNumUsed () const
virtual ULong64_t GetSeed (UInt_t i) const
virtual const ULong64_t * GetSeedPointer () const
virtual void SetSeed (std::vector< ULong64_t > seedvec, ULong64_t used=0)
virtual std::vector< ULong64_t > GetSeedVector () const
virtual UInt_t GetSeed ()
virtual Double_t Rndm (Int_t i=0)
virtual void RndmArray (Int_t n, Float_t *array)
virtual void RndmArray (Int_t n, Double_t *array)
 ClassDef (TRandomNOVA, 1)

Protected Member Functions

virtual void TRandomNOVA::FillOutState (UShort_t start)

Private Attributes

UInt_t fMt [624]
Int_t fCount624
ULong64_t fUsed
ULong64_t fSeed [2]


Constructor & Destructor Documentation

TRandomNOVA::TRandomNOVA ULong64_t  seed0 = 0,
ULong64_t  seed1 = 0,
ULong64_t  used = 0
 

Definition at line 13 of file TRandomNOVA.cxx.

00014 {
00015   TRandom::SetSeed(1); // arbitrary, but non-zero.  The TRandom seed isn't used.
00016   SetName("RandomNOVA");
00017   SetTitle("NOVA random number generator");
00018   // Ensure reseeding during construction:
00019   fSeed[0] = seed0 + 1;
00020   SetSeed(seed0,seed1,used);
00021 }

TRandomNOVA::TRandomNOVA std::vector< ULong64_t >  seedvec,
ULong64_t  used = 0
 

Definition at line 24 of file TRandomNOVA.cxx.

References fSeed, and SetSeed().

00025 {
00026   TRandom::SetSeed(1); // arbitrary, but non-zero.  The TRandom seed isn't used.
00027   SetName("RandomNOVA");
00028   SetTitle("NOVA random number generator");
00029   // Ensure reseeding during construction:
00030   fSeed[0] = seedvec[0] + 1;
00031   SetSeed(seedvec[0], seedvec[1], used);
00032 }

TRandomNOVA::~TRandomNOVA  )  [virtual]
 

Definition at line 35 of file TRandomNOVA.cxx.

00036 {
00037 }


Member Function Documentation

util::TRandomNOVA::ClassDef TRandomNOVA  ,
 

virtual ULong64_t util::TRandomNOVA::GetNumUsed  )  const [inline, virtual]
 

Definition at line 40 of file TRandomNOVA.h.

00040 { return fUsed; }

UInt_t TRandomNOVA::GetSeed  )  [virtual]
 

Definition at line 218 of file TRandomNOVA.cxx.

00219 {
00220   std::cout << "WARNING: You should not call TRandomNOVA::GetSeed().  The return value is meaningless.  Use TRandomNOVA::GetSeed(UShort_t) or TRandomNOVA::GetSeedPointer() instead." << std::endl;
00221   return 1;
00222 }

virtual ULong64_t util::TRandomNOVA::GetSeed UInt_t  i  )  const [inline, virtual]
 

Definition at line 41 of file TRandomNOVA.h.

00041 { return fSeed[i]; }

virtual const ULong64_t* util::TRandomNOVA::GetSeedPointer  )  const [inline, virtual]
 

Definition at line 42 of file TRandomNOVA.h.

00042 { return fSeed; }

std::vector< ULong64_t > TRandomNOVA::GetSeedVector  )  const [virtual]
 

Definition at line 225 of file TRandomNOVA.cxx.

References fSeed.

00226 {
00227   std::vector<ULong64_t> seedvec;
00228   seedvec.push_back(fSeed[0]);
00229   seedvec.push_back(fSeed[1]);
00230   return seedvec;
00231 }

Double_t TRandomNOVA::Rndm Int_t  i = 0  )  [virtual]
 

Definition at line 40 of file TRandomNOVA.cxx.

References fCount624, fMt, and fUsed.

Referenced by RndmArray(), and SetSeed().

00041 {
00042 
00043   fUsed++; // count the use
00044 
00045   UInt_t y;
00046   
00047   const Int_t  kM = 397;
00048   const Int_t  kN = 624;
00049   const UInt_t kTemperingMaskB =  0x9d2c5680;
00050   const UInt_t kTemperingMaskC =  0xefc60000;
00051   const UInt_t kUpperMask =       0x80000000;
00052   const UInt_t kLowerMask =       0x7fffffff;
00053   const UInt_t kMatrixA =         0x9908b0df;
00054 
00055   if (fCount624 >= kN) {
00056     register Int_t i;
00057 
00058     for (i=0; i < kN-kM; i++) {
00059       y = (fMt[i] & kUpperMask) | (fMt[i+1] & kLowerMask);
00060       fMt[i] = fMt[i+kM] ^ (y >> 1) ^ ((y & 0x1) ? kMatrixA : 0x0);
00061     }
00062 
00063     for (   ; i < kN-1    ; i++) {
00064       y = (fMt[i] & kUpperMask) | (fMt[i+1] & kLowerMask);
00065       fMt[i] = fMt[i+kM-kN] ^ (y >> 1) ^ ((y & 0x1) ? kMatrixA : 0x0);
00066     }
00067 
00068     y = (fMt[kN-1] & kUpperMask) | (fMt[0] & kLowerMask);
00069     fMt[kN-1] = fMt[kM-1] ^ (y >> 1) ^ ((y & 0x1) ? kMatrixA : 0x0);
00070     fCount624 = 0;
00071   }
00072 
00073   y = fMt[fCount624++];
00074   y ^=  (y >> 11);
00075   y ^= ((y << 7 ) & kTemperingMaskB );
00076   y ^= ((y << 15) & kTemperingMaskC );
00077   y ^=  (y >> 18);
00078 
00079   if (y) return ( (Double_t) y * 2.3283064365386963e-10); // * Power(2,-32)
00080   return Rndm();
00081 }

void TRandomNOVA::RndmArray Int_t  n,
Double_t *  array
[virtual]
 

Definition at line 92 of file TRandomNOVA.cxx.

References fCount624, fMt, and fUsed.

00093 {
00094   // Return an array of n random numbers uniformly distributed in ]0,1]
00095 
00096   fUsed += n;
00097 
00098   Int_t k = 0;
00099 
00100   UInt_t y;
00101 
00102   const Int_t  kM = 397;
00103   const Int_t  kN = 624;
00104   const UInt_t kTemperingMaskB =  0x9d2c5680;
00105   const UInt_t kTemperingMaskC =  0xefc60000;
00106   const UInt_t kUpperMask =       0x80000000;
00107   const UInt_t kLowerMask =       0x7fffffff;
00108   const UInt_t kMatrixA =         0x9908b0df;
00109 
00110   while (k < n) {
00111     if (fCount624 >= kN) {
00112       register Int_t i;
00113 
00114       for (i=0; i < kN-kM; i++) {
00115         y = (fMt[i] & kUpperMask) | (fMt[i+1] & kLowerMask);
00116         fMt[i] = fMt[i+kM] ^ (y >> 1) ^ ((y & 0x1) ? kMatrixA : 0x0);
00117       }
00118 
00119       for (   ; i < kN-1    ; i++) {
00120         y = (fMt[i] & kUpperMask) | (fMt[i+1] & kLowerMask);
00121         fMt[i] = fMt[i+kM-kN] ^ (y >> 1) ^ ((y & 0x1) ? kMatrixA : 0x0);
00122       }
00123 
00124       y = (fMt[kN-1] & kUpperMask) | (fMt[0] & kLowerMask);
00125       fMt[kN-1] = fMt[kM-1] ^ (y >> 1) ^ ((y & 0x1) ? kMatrixA : 0x0);
00126       fCount624 = 0;
00127     }
00128 
00129     y = fMt[fCount624++];
00130     y ^=  (y >> 11);
00131     y ^= ((y << 7 ) & kTemperingMaskB );
00132     y ^= ((y << 15) & kTemperingMaskC );
00133     y ^=  (y >> 18);
00134 
00135     if (y) {
00136       array[k] = Double_t( y * 2.3283064365386963e-10); // * Power(2,-32)
00137       k++;
00138     }
00139   }
00140 }

void TRandomNOVA::RndmArray Int_t  n,
Float_t *  array
[virtual]
 

Definition at line 84 of file TRandomNOVA.cxx.

References Rndm().

00085 {
00086   // Return an array of n random numbers uniformly distributed in ]0,1]
00087   
00088   for(Int_t i=0; i<n; i++) array[i]=(Float_t)Rndm();
00089 }

void TRandomNOVA::SetSeed std::vector< ULong64_t >  seedvec,
ULong64_t  used = 0
[virtual]
 

Definition at line 234 of file TRandomNOVA.cxx.

References SetSeed().

00235 {
00236   if (seedvec.size()!=2) {
00237     std::cout << "In TRandomNOVA::SetSeed(): input vector does not have exactly two entries.  Not setting the seed." << std::endl;
00238   }
00239   SetSeed(seedvec[0], seedvec[1], used);
00240 }

void TRandomNOVA::SetSeed ULong64_t  seed0,
ULong64_t  seed1,
ULong64_t  used = 0
[virtual]
 

Definition at line 162 of file TRandomNOVA.cxx.

References fMt, fSeed, fUsed, Rndm(), and SetSeed().

00163 {
00164   if (seed0!=fSeed[0]||seed1!=fSeed[1]||used<fUsed) {
00165     // start fresh
00166     fUsed=0;
00167 
00168     if (seed0==0&&seed1==0) {
00169       // Note: A TRandom3 seeded with zero results in a state
00170       // not represented by the value of GetSeed().  And, seeding
00171       // by the clock means you can't just run a bunch of jobs
00172       // using all 128 bits of a TUUID, we essentially guarantee
00173       // that every SetSeed(0) will produce a unique (but still
00174       // reproducible) seed.
00175 
00176       // get 128 bits of uniqueness
00177       TUUID uid;
00178       uid.GetUUID((UChar_t*)fSeed);
00179     }
00180     else {
00181       fSeed[0] = seed0;
00182       fSeed[1] = seed1;
00183     }
00184 
00185     if (seed0&&seed1==0) {
00186       // use the inherited seeding scheme (only 32 bits)
00187       SetSeed((UInt_t)seed0);
00188     }
00189     else {
00190       // seed in the same way as TRandom3.cxx
00191       UChar_t *uuid = (UChar_t*)fSeed;
00192       for (Int_t i=0;i<8;i++) {
00193         fMt[i] = uuid[2*i]*256 + uuid[2*i+1];
00194         if (i > 1) fMt[i] += fMt[0];
00195       }
00196       FillOutState(8);
00197     }
00198   }
00199   // spill some, if requested
00200   for (UInt_t i=fUsed;i<used;i++) {
00201     Rndm();
00202   }
00203 
00204 }

void TRandomNOVA::SetSeed UInt_t  seed = 0  )  [virtual]
 

Definition at line 143 of file TRandomNOVA.cxx.

References fMt, fSeed, and fUsed.

Referenced by util::RandomHandler::GetGenerator(), SetSeed(), and TRandomNOVA().

00144 {
00145   if (seed==0) {
00146     SetSeed(0,0,0);
00147   }
00148   else {
00149     // if the user wishes to use a specific 32-bit seed, we
00150     // can't just throw zeros into the state array.  To use
00151     // the original TRandom3 algorithm for this case, we call
00152     // the routine FillOutState();
00153     fUsed = 0;
00154     fSeed[0] = seed;
00155     fSeed[1] = 0;
00156     fMt[0] = seed;
00157     FillOutState(1);
00158   }
00159 }

virtual void util::TRandomNOVA::TRandomNOVA::FillOutState UShort_t  start  )  [protected, virtual]
 


Member Data Documentation

Int_t util::TRandomNOVA::fCount624 [private]
 

Definition at line 26 of file TRandomNOVA.h.

Referenced by Rndm(), and RndmArray().

UInt_t util::TRandomNOVA::fMt[624] [private]
 

Definition at line 25 of file TRandomNOVA.h.

Referenced by Rndm(), RndmArray(), and SetSeed().

ULong64_t util::TRandomNOVA::fSeed[2] [private]
 

Definition at line 29 of file TRandomNOVA.h.

Referenced by GetSeedVector(), SetSeed(), and TRandomNOVA().

ULong64_t util::TRandomNOVA::fUsed [private]
 

Definition at line 28 of file TRandomNOVA.h.

Referenced by Rndm(), RndmArray(), and SetSeed().


The documentation for this class was generated from the following files:
Generated on Sun Mar 15 04:45:27 2009 for NOvA Offline by  doxygen 1.3.9.1