Skip to content
Snippets Groups Projects
Commit f65e3907 authored by Fons Rademakers's avatar Fons Rademakers
Browse files

moved to new math directory.

git-svn-id: http://root.cern.ch/svn/root/trunk@17792 27541ba8-7e3a-0410-8455-c3a389f83636
parent 8fdc57a4
No related branches found
No related tags found
No related merge requests found
// @(#)root/base:$Name: $:$Id: TComplex.h,v 1.6 2005/12/24 17:06:27 rdm Exp $
// Author: Federico Carminati 22/04/2004
/*************************************************************************
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TComplex
#define ROOT_TComplex
//////////////////////////////////////////////////////////////////////////
// //
// TComplex //
// //
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_Riosfwd
#include "Riosfwd.h"
#endif
#ifndef ROOT_TMath
#include "TMath.h"
#endif
class TComplex {
protected:
Double_t fRe; // real part
Double_t fIm; // imaginary part
public:
// ctors and dtors
TComplex(): fRe(0), fIm(0) {}
TComplex(Double_t re, Double_t im=0, Bool_t polar=kFALSE);
virtual ~TComplex() {}
// constants
static TComplex I() {return TComplex(0,1);}
static TComplex One() {return TComplex(1,0);}
// getters and setters
Double_t Re() const {return fRe;}
Double_t Im() const {return fIm;}
Double_t Rho() const {return TMath::Sqrt(fRe*fRe+fIm*fIm);}
Double_t Rho2() const {return fRe*fRe+fIm*fIm;}
Double_t Theta() const {return (fIm||fRe)?TMath::ATan2(fIm,fRe):0;}
TComplex operator()(Double_t x, Double_t y, Bool_t polar=kFALSE)
{ if (polar) { fRe = x*TMath::Cos(y); fIm = x*TMath::Sin(y); }
else { fRe = x; fIm = y; } return *this; }
// Simple operators complex - complex
TComplex operator *(const TComplex & c) const
{return TComplex(fRe*c.fRe-fIm*c.fIm,fRe*c.fIm+fIm*c.fRe);}
TComplex operator +(const TComplex & c) const
{return TComplex(fRe+c.fRe, fIm+c.fIm);}
TComplex operator /(const TComplex & c) const
{return TComplex(fRe*c.fRe+fIm*c.fIm,-fRe*c.fIm+fIm*c.fRe)/c.Rho2();}
TComplex operator -(const TComplex & c) const
{return TComplex(fRe-c.fRe, fIm-c.fIm);}
TComplex operator *=(const TComplex & c)
{return ((*this) = (*this) * c);}
TComplex operator +=(const TComplex & c)
{return ((*this) = (*this) + c);}
TComplex operator /=(const TComplex & c)
{return ((*this) = (*this) / c);}
TComplex operator -=(const TComplex & c)
{return ((*this) = (*this) - c);}
TComplex operator -()
{return TComplex(-fRe,-fIm);}
TComplex operator +()
{return *this;}
// Simple operators complex - double
TComplex operator *(Double_t c) const
{return TComplex(fRe*c,fIm*c);}
TComplex operator +(Double_t c) const
{return TComplex(fRe+c, fIm);}
TComplex operator /(Double_t c) const
{return TComplex(fRe/c,fIm/c);}
TComplex operator -(Double_t c) const
{return TComplex(fRe-c, fIm);}
// Simple operators double - complex
friend TComplex operator *(Double_t d, const TComplex & c)
{return TComplex(d*c.fRe,d*c.fIm);}
friend TComplex operator +(Double_t d, const TComplex & c)
{return TComplex(d+c.fRe, c.fIm);}
friend TComplex operator /(Double_t d, const TComplex & c)
{return TComplex(d*c.fRe,-d*c.fIm)/c.Rho2();}
friend TComplex operator -(Double_t d, const TComplex & c)
{return TComplex(d-c.fRe, -c.fIm);}
// Convertors
operator Double_t () const {return fRe;}
operator Float_t () const {return static_cast<Float_t>(fRe);}
operator Int_t () const {return static_cast<Int_t>(fRe);}
// TMath:: extensions
static TComplex Sqrt(const TComplex &c)
{return TComplex(TMath::Sqrt(c.Rho()),0.5*c.Theta(),kTRUE);}
static TComplex Exp(const TComplex &c)
{return TComplex(TMath::Exp(c.fRe),c.fIm,kTRUE);}
static TComplex Log(const TComplex &c)
{return TComplex(0.5*TMath::Log(c.Rho2()),c.Theta());}
static TComplex Log2(const TComplex &c)
{return Log(c)/TMath::Log(2);}
static TComplex Log10(const TComplex &c)
{return Log(c)/TMath::Log(10);}
static TComplex Sin(const TComplex &c)
{return TComplex(TMath::Sin(c.fRe)*TMath::CosH(c.fIm),
TMath::Cos(c.fRe)*TMath::SinH(c.fIm));}
static TComplex Cos(const TComplex &c)
{return TComplex(TMath::Cos(c.fRe)*TMath::CosH(c.fIm),
-TMath::Sin(c.fRe)*TMath::SinH(c.fIm));}
static TComplex Tan(const TComplex &c)
{TComplex cc=Cos(c); return Sin(c)*Conjugate(cc)/cc.Rho2();}
static TComplex ASin(const TComplex &c)
{return -I()*Log(I()*c+TMath::Sign(1.,c.Im())*Sqrt(1.-c*c));}
static TComplex ACos(const TComplex &c)
{return -I()*Log(c+TMath::Sign(1.,c.Im())*Sqrt(c*c-1.));}
static TComplex ATan(const TComplex &c)
{return -0.5*I()*Log((1.+I()*c)/(1.-I()*c));}
static TComplex SinH(const TComplex &c)
{return TComplex(TMath::SinH(c.fRe)*TMath::Cos(c.fIm),
TMath::CosH(c.fRe)*TMath::Sin(c.fIm));}
static TComplex CosH(const TComplex &c)
{return TComplex(TMath::CosH(c.fRe)*TMath::Cos(c.fIm),
TMath::SinH(c.fRe)*TMath::Sin(c.fIm));}
static TComplex TanH(const TComplex &c)
{TComplex cc=CosH(c); return SinH(c)*Conjugate(cc)/cc.Rho2();}
static TComplex ASinH(const TComplex &c)
{return Log(c+TMath::Sign(1.,c.Im())*Sqrt(c*c+1.));}
static TComplex ACosH(const TComplex &c)
{return Log(c+TMath::Sign(1.,c.Im())*Sqrt(c*c-1.));}
static TComplex ATanH(const TComplex &c)
{return 0.5*Log((1.+c)/(1.-c));}
static Double_t Abs(const TComplex &c)
{return c.Rho();}
static TComplex Power(const TComplex& x, const TComplex& y)
{Double_t lrho=TMath::Log(x.Rho());
Double_t theta=x.Theta();
return TComplex(TMath::Exp(lrho*y.Re()-theta*y.Im()),
lrho*y.Im()+theta*y.Re(),kTRUE);}
static TComplex Power(const TComplex& x, Double_t y)
{return TComplex(TMath::Power(x.Rho(),y),x.Theta()*y,kTRUE);}
static TComplex Power(Double_t x, const TComplex& y)
{Double_t lrho=TMath::Log(TMath::Abs(x));
Double_t theta=(x>0)?0:TMath::Pi();
return TComplex(TMath::Exp(lrho*y.Re()-theta*y.Im()),
lrho*y.Im()+theta*y.Re(),kTRUE);}
static TComplex Power(const TComplex& x, Int_t y)
{return TComplex(TMath::Power(x.Rho(),y),x.Theta()*y,kTRUE);}
static Int_t Finite(const TComplex& c)
{return TMath::Min(TMath::Finite(c.Re()),TMath::Finite(c.Im()));}
static Int_t IsNaN(const TComplex& c)
{return TMath::Max(TMath::IsNaN(c.Re()),TMath::IsNaN(c.Im()));}
static TComplex Min(const TComplex &a, const TComplex &b)
{return a.Rho()<=b.Rho()?a:b;}
static TComplex Max(const TComplex &a, const TComplex &b)
{return a.Rho()>=b.Rho()?a:b;}
static TComplex Normalize(const TComplex &c)
{return TComplex(1.,c.Theta(),kTRUE);}
static TComplex Conjugate(const TComplex &c)
{return TComplex(c.Re(),-c.Im());}
static TComplex Range(const TComplex &lb, const TComplex &ub, const TComplex &c)
{return Max(lb,Min(c,ub));}
// I/O
friend ostream& operator<<(ostream& out, const TComplex& c);
friend istream& operator>>(istream& in, TComplex& c);
ClassDef(TComplex,1) //Complex Class
};
#endif
This diff is collapsed.
// @(#)root/base:$Name: $:$Id: TRandom.h,v 1.8 2006/05/06 08:25:15 brun Exp $
// Author: Rene Brun 15/12/95
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TRandom
#define ROOT_TRandom
//////////////////////////////////////////////////////////////////////////
// //
// TRandom //
// //
// Simple prototype random number generator class (periodicity = 10**9) //
// //
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TNamed
#include "TNamed.h"
#endif
class TRandom : public TNamed {
protected:
UInt_t fSeed; //Random number generator seed
public:
TRandom(UInt_t seed=65539);
virtual ~TRandom();
virtual Int_t Binomial(Int_t ntot, Double_t prob);
virtual Double_t BreitWigner(Double_t mean=0, Double_t gamma=1);
virtual void Circle(Double_t &x, Double_t &y, Double_t r);
virtual Double_t Exp(Double_t tau);
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1);
virtual UInt_t GetSeed() {return fSeed;}
virtual UInt_t Integer(UInt_t imax);
virtual Double_t Landau(Double_t mean=0, Double_t sigma=1);
virtual Int_t Poisson(Double_t mean);
virtual Double_t PoissonD(Double_t mean);
virtual void Rannor(Float_t &a, Float_t &b);
virtual void Rannor(Double_t &a, Double_t &b);
virtual void ReadRandom(const char *filename);
virtual void SetSeed(UInt_t seed=65539);
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);
virtual void Sphere(Double_t &x, Double_t &y, Double_t &z, Double_t r);
virtual Double_t Uniform(Double_t x1=1);
virtual Double_t Uniform(Double_t x1, Double_t x2);
virtual void WriteRandom(const char *filename);
ClassDef(TRandom,1) //Simple Random number generator (periodicity = 10**9)
};
R__EXTERN TRandom *gRandom;
#endif
// @(#)root/base:$Name: $:$Id: TRandom1.h,v 1.1 2006/05/04 13:06:15 brun Exp $
// Author: Rene Brun 04/03/99
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TRandom1
#define ROOT_TRandom1
//////////////////////////////////////////////////////////////////////////
// //
// TRandom1 //
// //
// Ranlux random number generator class (periodicity > 10**14) //
// //
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TRandom
#include "TRandom.h"
#endif
class TRandom1 : public TRandom {
protected:
Int_t fNskip;
Int_t fLuxury;
Int_t fIlag;
Int_t fJlag;
Int_t fCount24;
Float_t fFloatSeedTable[24];
Float_t fCarry;
const Int_t fIntModulus;
static Int_t fgNumEngines;
static Int_t fgMaxIndex;
const UInt_t *fTheSeeds;
const Double_t fMantissaBit24;
const Double_t fMantissaBit12;
public:
TRandom1();
TRandom1(UInt_t seed, Int_t lux = 3 );
TRandom1(Int_t rowIndex, Int_t colIndex, Int_t lux );
virtual ~TRandom1();
virtual Int_t GetLuxury() const {return fLuxury;}
// Gets the current seed.
const UInt_t *GetTheSeeds() const {return fTheSeeds;}
// Gets the current array of seeds.
static void GetTableSeeds(UInt_t* seeds, Int_t index);
// Gets back seed values stored in the table, given the index.
virtual Double_t Rndm(Int_t i=0);
virtual void RndmArray(Int_t size, Float_t *vect);
virtual void RndmArray(Int_t size, Double_t *vect);
virtual void SetSeed2(UInt_t seed, Int_t lux=3);
// Sets the state of the algorithm according to seed.
virtual void SetSeeds(const UInt_t * seeds, Int_t lux=3);
// Sets the state of the algorithm according to the zero terminated
// array of seeds. Only the first seed is used.
virtual void SetSeed(UInt_t seed);
ClassDef(TRandom1,1) //Ranlux Random number generators with periodicity > 10**14
};
R__EXTERN TRandom *gRandom;
#endif
// @(#)root/base:$Name: $:$Id: TRandom2.h,v 1.4 2006/05/17 17:32:40 brun Exp $
// Author: Rene Brun 04/03/99
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TRandom2
#define ROOT_TRandom2
//////////////////////////////////////////////////////////////////////////
// //
// TRandom2 //
// //
// random number generator class (periodicity > 10**26) //
// //
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TRandom
#include "TRandom.h"
#endif
class TRandom2 : public TRandom {
protected:
UInt_t fSeed1; //Random number generator seed 1
UInt_t fSeed2; //Random number generator seed 2
public:
TRandom2(UInt_t seed=1);
virtual ~TRandom2();
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);
virtual void SetSeed(UInt_t seed=0);
ClassDef(TRandom2,1) //Random number generator with periodicity of 10**26
};
R__EXTERN TRandom *gRandom;
#endif
// @(#)root/base:$Name: $:$Id: TRandom3.h,v 1.4 2003/01/26 21:03:16 brun Exp $
// Author: Peter Malzacher 31/08/99
/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TRandom3
#define ROOT_TRandom3
//////////////////////////////////////////////////////////////////////////
// //
// TRandom3 //
// //
// random number generator class: Mersenne Twistor //
// //
//////////////////////////////////////////////////////////////////////////
#ifndef ROOT_TRandom
#include "TRandom.h"
#endif
class TRandom3 : public TRandom {
private:
UInt_t fMt[624];
Int_t fCount624;
public:
TRandom3(UInt_t seed=4357);
virtual ~TRandom3();
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);
virtual void SetSeed(UInt_t seed=0);
ClassDef(TRandom3,2) //Random number generator: Mersenne Twistor
};
R__EXTERN TRandom *gRandom;
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment