]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PYTHIA6/AliPythiaRndm.cxx
Correct handling of seeds for MC on the fly trains
[u/mrichter/AliRoot.git] / PYTHIA6 / AliPythiaRndm.cxx
index c0368062bf7cbd302c91ee0f6e5fdd4f1a57ca49..0dcb21c52d8f84efe1007b55b4c27632191603e9 100644 (file)
@@ -30,6 +30,7 @@
 //
 //-----------------------------------------------------------------------------
 
+#include <TMath.h>
 #include <TRandom.h>
 
 #include "AliPythiaRndm.h"
@@ -53,24 +54,41 @@ TRandom * AliPythiaRndm::GetPythiaRandom() {
   //
   // Retrieves the pointer to the random numbers generator
   //
+  if (!fgPythiaRandom) fgPythiaRandom=gRandom;
   return fgPythiaRandom;
 }
 
 //_______________________________________________________________________
-#define pyr    pyr_
-#define pyrset pyrset_
-#define pyrget pyrget_
+#define pyr        pyr_
+#define pygauss    pygauss_
+#define pyrset     pyrset_
+#define pyrget     pyrget_
 
 extern "C" {
-  Double_t pyr(Int_t*) 
-  {
-    // Wrapper to FINCTION PYR from PYTHIA
-    // Uses static method to retrieve the pointer to the (C++) generator
-    Double_t r;
-    do r=AliPythiaRndm::GetPythiaRandom()->Rndm();
-    while(0 >= r || r >= 1);
-    return r;
-  }
-  void pyrset(Int_t*,Int_t*) {}
-  void pyrget(Int_t*,Int_t*) {}
+    Double_t pyr(Int_t*) 
+    {
+       // Wrapper to FUNCTION PYR from PYTHIA
+       // Uses static method to retrieve the pointer to the (C++) generator
+       Double_t r;
+       do r=AliPythiaRndm::GetPythiaRandom()->Rndm();
+       while(0 >= r || r >= 1);
+       return r;
+    }
+    
+    Double_t pygauss(Double_t x0, Double_t sig)
+    {
+       Double_t s = 2.;
+       Double_t v1 = 0.;
+       Double_t v2 = 0.;
+       
+       while (s > 1.) {
+           v1 = 2. * pyr(0) - 1.;
+           v2 = 2. * pyr(0) - 1.;
+           s = v1 * v1 + v2 * v2;
+       }
+       return v1 * TMath::Sqrt(-2. * TMath::Log(s) / s) * sig + x0;
+    }
+
+    void pyrset(Int_t*,Int_t*) {}
+    void pyrget(Int_t*,Int_t*) {}
 }