FairRoot/PandaRoot
PhotosRandom.cxx
Go to the documentation of this file.
1 #include <iostream>
2 #include "PhotosRandom.h"
3 #include "Photos.h"
4 #include "Log.h"
5 
6 namespace Photospp
7 {
8 
9 bool PhotosRandom::init = false;
10 int PhotosRandom::iseed[2]= { 1802, 9373 };
11 int PhotosRandom::i97 = 96;
12 int PhotosRandom::j97 = 32;
13 double PhotosRandom::uran[97]= { 0.0 };
14 double PhotosRandom::cran = 362436.0 /16777216.0;
15 const double PhotosRandom::cdran = 7654321.0 /16777216.0;
16 const double PhotosRandom::cmran = 16777213.0/16777216.0;
17 
18 /* PHORANC definition.
19  Thanks to this function, this generator can be used by PHOTOS FORTRAN */
20 extern "C" double phoranc_(int *) //phoranc_(int *idum)
21 {
22  return Photos::randomDouble();
23 }
24 
25 void PhotosRandom::setSeed(int s1,int s2)
26 {
27  if(s1<0 || s1>31327) Log::Fatal("PhotosRandom::setSeed(): Seed(1) out of range [0,31327]",8);
28  if(s2<0 || s2>30080) Log::Fatal("PhotosRandom::setSeed(): Seed(2) out of range [0,30080]",9);
29  iseed[0]=s1;
30  iseed[1]=s2;
31 }
32 
33 /*******************************************************************************
34  PHORIN: PHOton radiation in decays RANdom number generator init
35 
36  Purpose: Initialse PHORAN with the user specified seeds in the
37  array iseed. For details see also: F. James CERN DD-
38  Report November 1988.
39 
40  Author(s): B. van Eijk and F. James Created at: 27/09/89
41  Last Update: 22/02/90
42  Rewritten to C++: 18/10/10
43  by T. Przedzinski (tprzedzi@cern.ch)
44 *******************************************************************************/
46 {
47  long IS1,IS2,IS3,IS4,IS5;
48  double S,T;
49 
50 // Calculate Marsaglia and Zaman seeds (by F. James)
51  IS1=(iseed[0]/177)%177+2;
52  IS2= iseed[0]%177+2;
53  IS3=(iseed[1]/169)%178+1;
54  IS4= iseed[1]%169;
55  for(int i=0;i<97;i++)
56  {
57  S=0.0;
58  T=0.5;
59  for(int j=0;j<24;j++)
60  {
61  IS5=( ((IS1*IS2)%179)*IS3 )%179;
62  IS1=IS2;
63  IS2=IS3;
64  IS3=IS5;
65  IS4=(53*IS4+1)%169;
66  if( (IS4*IS5)%64>=32) S=S+T;
67  T=0.5*T;
68  }
69  uran[i]=S;
70  }
71  init=true;
72  Log::Debug(0)<<"PhotosRandom::inititalize(): seed: "<<iseed[0]<<", "<<iseed[1]<<std::endl;
73 }
74 
75 /*******************************************************************************
76  PHORAN: PHOton radiation in decays ret number generator based
77  on Marsaglia Algorithm
78 
79  Purpose: Generate uniformly distributed random numbers between
80  0 and 1. Super long period: 2**144. See also:
81  G. Marsaglia and A. Zaman, FSU-SCR-87-50, for seed mo-
82  difications to this version see: F. James DD-Report,
83  November 1988. The generator has to be initialized by
84  a call to PHORIN ( C++ version: initialize() ).
85 
86  Author(s): B. van Eijk, G. Marsaglia and Created at: 27/09/89
87  A. Zaman Last Update: 27/09/89
88  Rewritten to C++: 18/10/10
89  by T. Przedzinski (tprzedzi@cern.ch)
90 *******************************************************************************/
92 {
93  if(!init) Log::Fatal("PhotosRandom::randomReal(): generator not initialized",1);
94  double ret=0.0;
95  while(true)
96  {
97  ret = uran[i97]-uran[j97];
98  if(ret<0.0) ret+=1.;
99  uran[i97]=ret;
100  i97--;
101  if(i97<0) i97=96;
102  j97--;
103  if(j97<0) j97=96;
104  cran-=cdran;
105  if(cran<0.0) cran+=cmran;
106  ret-=cran;
107  if(ret<0.0) ret+=1.0;
108  if(ret>0.0) break;
109  }
110  return ret;
111 }
112 
113 } // namespace Photospp
114 
static void setSeed(int s1, int s2)
Int_t i
Definition: run_full.C:25
double phoranc_(int *)
static double randomReal()
static const double cmran
Definition: PhotosRandom.h:42
TTree * T
Definition: anaLmdReco.C:32
static ostream & Debug(unsigned short int code=0, bool count=true)
Definition: Log.cxx:30
static double(* randomDouble)()
Definition: Photos.h:190
static int iseed[2]
Definition: PhotosRandom.h:36
static const double cdran
Definition: PhotosRandom.h:41
static void initialize()
static double cran
Definition: PhotosRandom.h:40
static void Fatal(string text, unsigned short int code=0)
static double uran[97]
Definition: PhotosRandom.h:39