FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_main/random.cpp

00001 /***************************************************************************
00002                           grandom.cpp  -  description
00003                              -------------------
00004     begin                : Sun Nov 26 2000
00005     copyright            : (C) 2000 by Giuseppe m Pierazzini
00006     email                : pierazzini@unipi.it
00007  ***************************************************************************
00008  *                                                                         *
00009  *   NA48  simulation program.                                             *
00010  *                                                                         *
00011  ***************************************************************************/
00012 
00013 // grandom  random generators    GMP 1.10.2000
00014 #include "parm.h"
00015 #include "evento.h"
00016 #include "particella.h"
00017 #include "flyorea.h"
00018 
00019 int Rdm1=314,Rdm2=625,idum1=0,idum2=0,iy_rand=0,iv_rand[32];
00020 //------------------------------------------------------------
00021 //-------------------------R A N D O M -----------------------
00022 #define IM1 2147483563
00023 #define IM2 2147483399
00024 #define AM (1.0/IM1)
00025 #define IMM1 (IM1-1)
00026 #define IA1 40014
00027 #define IA2 40692
00028 #define IQ1 53668
00029 #define IQ2 52774
00030 #define IR1 12211
00031 #define IR2 3791
00032 #define NTAB 32
00033 #define NDIV (1+IMM1/NTAB)
00034 #define EPS 1.2e-7
00035 #define RNMX (1.0-EPS)
00036 
00037 
00039 //-------------------------------------------------------------
00040 //             G a u s s r
00041 //-------------------------------------------------------------
00042 //
00043 double  Pgauss ( double s, double c )
00044 
00045 {
00046         int i = 0;
00047         double a = 0.0;
00048         while ( i++ < 12 )
00049                 a += Pran();
00050         return ( s * ( a - 6. ) + c );
00051 }
00052 //
00053 double Pran()
00054 //
00055 // Long period random number generator. Returns a uniform random
00056 // deviate between 0.0 and 1.0 (both exclusive).
00057 // It should be called with  idum1 negative, or with  (idum1,idum2)
00058 // from a previous call.
00059 // The obtained random number is smaller than   RNMX
00060 // pr->prandom contains the last random value.
00061 {
00062         double prandom;
00063         int j;
00064         int k;
00065         //      int idum1=314,idum2=625;
00066         //      int iy_rand=0;
00067         //      int iv_rand[NTAB];
00068     
00069         //============================================================
00070         if ( Rdm1<1 )
00071         {
00072                 idum1=Rdm1; idum2=Rdm2; Rdm1=100;  //attenzione Rdm1 ridefinito..
00073                 if ( idum1 <= 0 )
00074                 {
00075                         if ( - ( idum1 ) < 1 ) idum1=1; //avoid idum1=0
00076                         else idum1 = - ( idum1 );
00077                         //    idum2=(idum1);  original!!!
00078                         idum2= ( idum2 );
00079                         for ( j=NTAB+7;j>=0;j-- )
00080                         {
00081                                 k= ( idum1 ) /IQ1;
00082                                 idum1=IA1* ( idum1-k*IQ1 )-k*IR1;
00083                                 if ( idum1 < 0 ) idum1 +=IM1;
00084                                 if ( j < NTAB ) iv_rand[j]=idum1;
00085                         }
00086                         iy_rand=iv_rand[0];
00087                 }
00088         }
00089         //===========================================================
00090 
00091         // We start from here, when not initializing ...
00092         k= ( idum1 ) /IQ1;
00093         idum1=IA1* ( idum1-k*IQ1 )-k*IR1;
00094         if ( idum1 < 0 ) idum1 +=IM1;
00095         k= ( idum2 ) /IQ2;
00096         idum2=IA2* ( idum2-k*IQ2 )-k*IR2;
00097         if ( idum2 < 0 ) idum2 +=IM2;
00098         j=iy_rand/NDIV;
00099         iy_rand=iv_rand[j]- ( idum2 );
00100         iv_rand[j]=idum1;
00101         if ( iy_rand < 1 ) iy_rand +=IMM1;
00102         if ( ( prandom=AM*iy_rand ) >RNMX ) prandom=RNMX;
00103         return prandom;
00104 
00105 }
00106 //================================================================
00107 //              S e t _ R a n d o m   X run
00108 //=================================================================
00109 void    Set_Pran()
00110 {
00111         // correlazione con il run
00112         Rdm2=evento_.Gen.Run;
00113         Rdm1=-31415;
00114         Pran();
00115 }
00116 
00117 void Set_PranEv()
00118 {
00119         // per  correlazione.anche con l' evento
00120         Rdm2=evento_.Gen.Run;
00121         Rdm1=-evento_.Gen.Event*512;
00122         Pran();
00123 }
00124 
 All Classes Namespaces Files Functions Variables