]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PYTHIA6/AliPythiaRndm.cxx
Re-fixing coverity 18130
[u/mrichter/AliRoot.git] / PYTHIA6 / AliPythiaRndm.cxx
index c10eb9e510114b19c26b0390987e38e7dcc36f9d..0dcb21c52d8f84efe1007b55b4c27632191603e9 100644 (file)
 
 //-----------------------------------------------------------------------------
 //   Class: AliPythiaRndm
-//   Random Number Interface to Fortran (FINCTION PYR from PYTHIA)
-//   Very similar to AliHijingRndm
-//   Author:
+//   Responsibilities: Interface to Root random number generator 
+//                     from Fortran (re-implements FINCTION PYR from PYTHIA)
+//                     Very similar to AliHijingRndm
+//   Collaborators: AliPythia and AliGenPythia classes
+//   Example:
+//
+//   root> AliPythia::Instance();
+//   root> AliPythiaRndm::SetPythiaRandom(new TRandom3()); 
+//   root> AliPythiaRndm::GetPythiaRandom()->SetSeed(0);
+//   root> cout<<"Seed "<< AliPythiaRndm::GetPythiaRandom()->GetSeed() <<endl;
+//
 //-----------------------------------------------------------------------------
 
-#include <TError.h>
+#include <TMath.h>
+#include <TRandom.h>
 
 #include "AliPythiaRndm.h"
 
@@ -30,39 +39,6 @@ TRandom * AliPythiaRndm::fgPythiaRandom=0;
 
 ClassImp(AliPythiaRndm)
 
-//_______________________________________________________________________
-AliPythiaRndm::AliPythiaRndm()
-{
-  // 
-  // Default ctor
-  //
-}
-
-//_______________________________________________________________________
-AliPythiaRndm::AliPythiaRndm(const AliPythiaRndm& rn)
-{
-  //
-  // Copy constructor
-  //
-  rn.Copy(*this);
-}
-
-//_______________________________________________________________________
-AliPythiaRndm::~AliPythiaRndm() {
-  //
-  // Destructor
-  //
-  fgPythiaRandom=0;
-}
-
-//_______________________________________________________________________
-void AliPythiaRndm::Copy(AliPythiaRndm&) const
-{
-  //
-  // No copy is allowed for the object
-  //
-  ::Fatal("Copy","Not implemented\n");
-}
 
 //_______________________________________________________________________
 void AliPythiaRndm::SetPythiaRandom(TRandom *ran) {
@@ -78,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*) {}
 }