#include <math.h>
#include "TFormulaPrimitive.h"
#include "TMath.h"
#ifdef WIN32
#pragma optimize("",off)
#endif
void TMath_GenerInterface();
ClassImp(TFormulaPrimitive)
TObjArray * TFormulaPrimitive::fgListOfFunction = 0;
TFormulaPrimitive::TFormulaPrimitive() : TNamed()
{
fType=0;
fNArguments=0;
fNParameters=0;
fIsStatic=kTRUE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
GenFunc0 fpointer) : TNamed(name,formula)
{
fType= 0;
fFunc0 = fpointer;
fNArguments=0;
fNParameters=0;
fIsStatic=kTRUE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
GenFunc10 fpointer) : TNamed(name,formula)
{
fType= 10;
fFunc10 = fpointer;
fNArguments=1;
fNParameters=0;
fIsStatic=kTRUE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
GenFunc110 fpointer) : TNamed(name,formula)
{
fType= 110;
fFunc110 = fpointer;
fNArguments=2;
fNParameters=0;
fIsStatic=kTRUE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
GenFunc1110 fpointer) : TNamed(name,formula)
{
fType= 1110;
fFunc1110 = fpointer;
fNArguments=3;
fNParameters=0;
fIsStatic=kTRUE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
GenFuncG fpointer,Int_t npar) : TNamed(name,formula)
{
fType= -1;
fFuncG = fpointer;
fNArguments=2;
fNParameters=npar;
fIsStatic=kTRUE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
TFuncG fpointer) : TNamed(name,formula)
{
fType= 0;
fTFuncG=fpointer;
fNArguments=0;
fNParameters=0;
fIsStatic =kFALSE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
TFunc0 fpointer) : TNamed(name,formula)
{
fType = 0;
fTFunc0= fpointer;
fNArguments=0;
fNParameters=0;
fIsStatic =kFALSE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
TFunc10 fpointer) : TNamed(name,formula)
{
fType=-10;
fTFunc10=fpointer;
fNArguments=1;
fNParameters=0;
fIsStatic =kFALSE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
TFunc110 fpointer) : TNamed(name,formula)
{
fType=-110;
fTFunc110=fpointer;
fNArguments=2;
fNParameters=0;
fIsStatic =kFALSE;
}
TFormulaPrimitive::TFormulaPrimitive(const char *name,const char *formula,
TFunc1110 fpointer) :TNamed(name,formula)
{
fType=-1110;
fTFunc1110=fpointer;
fNArguments=3;
fNParameters=0;
fIsStatic =kFALSE;
}
TFormulaPrimitive* TFormulaPrimitive::FindFormula(const char* name)
{
if (!fgListOfFunction) {
BuildBasicFormulas();
}
return (TFormulaPrimitive*)fgListOfFunction->FindObject(name);
}
Int_t TFormulaPrimitive::AddFormula(TFormulaPrimitive * formula)
{
if (fgListOfFunction == 0) BuildBasicFormulas();
if (FindFormula(formula->GetName())){
delete formula;
return 0;
}
fgListOfFunction->AddLast(formula);
return 1;
}
Double_t TFormulaPrimitive::Eval(Double_t* x)
{
if (fIsStatic ==kFALSE) return 0;
if (fType==0) return fFunc0();
if (fType==10) {
return fFunc10(x[0]);
}
if (fType==110) {
return fFunc110(x[0],x[1]);
}
if (fType==1110) {
return fFunc1110(x[0],x[1],x[2]);
}
return 0;
}
Double_t TFormulaPrimitive::Eval(TObject *o, Double_t *x)
{
if (fIsStatic ==kTRUE) return 0;
if (fType== 0) return (*o.*fTFunc0)();
if (fType==-10) return (*o.*fTFunc10)(*x);
if (fType==-110) return (*o.*fTFunc110)(x[0],x[1]);
if (fType==-1110) return (*o.*fTFunc1110)(x[0],x[1],x[2]);
return 0;
}
Double_t TFormulaPrimitive::Eval(Double_t *x, Double_t *param)
{
return fFuncG(x,param);
}
#define RTFastFun__POLY(var) \
{ \
Double_t res= param[var-1]+param[var]*x[0]; \
for (Int_t j=var-1 ;j>0;j--) res = param[j-1]+x[0]*res; \
return res; \
}
namespace TFastFun {
Double_t Pow2(Double_t x){return x*x;}
Double_t Pow3(Double_t x){return x*x*x;}
Double_t Pow4(Double_t x){return x*x*x*x;}
Double_t Pow5(Double_t x){return x*x*x*x*x;}
inline Double_t FPoln(Double_t *x, Double_t *param, Int_t npar);
Double_t FPol0(Double_t * , Double_t *param){ return param[0];}
Double_t FPol1(Double_t *x, Double_t *param){ return param[0]+param[1]*x[0];}
Double_t FPol2(Double_t *x, Double_t *param){ return param[0]+x[0]*(param[1]+param[2]*x[0]);}
Double_t FPol3(Double_t *x, Double_t *param){ return param[0]+x[0]*(param[1]+x[0]*(param[2]+param[3]*x[0]));}
Double_t FPol4(Double_t *x, Double_t *param){ RTFastFun__POLY(4)}
Double_t FPol5(Double_t *x, Double_t *param){ RTFastFun__POLY(5)}
Double_t FPol6(Double_t *x, Double_t *param){ RTFastFun__POLY(6)}
Double_t FPol7(Double_t *x, Double_t *param){ RTFastFun__POLY(7)}
Double_t FPol8(Double_t *x, Double_t *param){ RTFastFun__POLY(8)}
Double_t FPol9(Double_t *x, Double_t *param){ RTFastFun__POLY(9)}
Double_t FPol10(Double_t *x, Double_t *param){ RTFastFun__POLY(10)}
Double_t PlusXY(Double_t x,Double_t y){return x+y;}
Double_t MinusXY(Double_t x,Double_t y){return x-y;}
Double_t MultXY(Double_t x,Double_t y){return x*y;}
Double_t DivXY(Double_t x, Double_t y){return TMath::Abs(y)>0 ? x/y:0;}
Double_t XpYpZ(Double_t x, Double_t y, Double_t z){ return x+y+z;}
Double_t XxYxZ(Double_t x, Double_t y, Double_t z){ return x*y*z;}
Double_t XxYpZ(Double_t x, Double_t y, Double_t z){ return x*(y+z);}
Double_t XpYxZ(Double_t x, Double_t y, Double_t z){ return x+(y*z);}
Double_t Gaus(Double_t x, Double_t mean, Double_t sigma);
Double_t Gausn(Double_t x, Double_t mean, Double_t sigma);
Double_t Landau(Double_t x, Double_t mean, Double_t sigma){return TMath::Landau(x,mean,sigma,kFALSE);}
Double_t Landaun(Double_t x, Double_t mean, Double_t sigma){return TMath::Landau(x,mean,sigma,kTRUE);}
Double_t Sqrt(Double_t x) {return x>0?sqrt(x):0;}
Double_t Sign(Double_t x){return (x<0)? -1:1;}
Double_t Nint(Double_t x){return TMath::Nint(x);}
Double_t Abs(Double_t x){return TMath::Abs(x);}
Double_t XandY(Double_t x, Double_t y){ return (x*y>0.1);}
Double_t XorY(Double_t x, Double_t y) { return (x+y>0.1);}
Double_t XgY(Double_t x, Double_t y) {return (x>y);}
Double_t XgeY(Double_t x, Double_t y) {return (x>=y);}
Double_t XlY(Double_t x, Double_t y) {return (x<y);}
Double_t XleY(Double_t x, Double_t y) {return (x<=y);}
Double_t XeY(Double_t x,Double_t y) {return (x==y);}
Double_t XneY(Double_t x,Double_t y) {return (x!=y);}
Double_t XNot(Double_t x){ return (x<0.1);}
};
Double_t TFastFun::FPoln(Double_t *x, Double_t *param, Int_t npar)
{
Double_t res = 0; Double_t temp=1;
for (Int_t j=npar ;j>=0;j--) {
res += temp*param[j];
temp *= *x;
}
return res;
}
Double_t TFastFun::Gaus(Double_t x, Double_t mean, Double_t sigma)
{
if (sigma == 0) return 1.e30;
Double_t arg = (x-mean)/sigma;
return TMath::Exp(-0.5*arg*arg);
}
Double_t TFastFun::Gausn(Double_t x, Double_t mean, Double_t sigma)
{
if (sigma == 0) return 0;
Double_t arg = (x-mean)/sigma;
return TMath::Exp(-0.5*arg*arg)/(2.50662827463100024*sigma);
}
Int_t TFormulaPrimitive::BuildBasicFormulas()
{
if (fgListOfFunction==0) fgListOfFunction = new TObjArray(1000);
AddFormula(new TFormulaPrimitive("XandY","XandY",TFastFun::XandY));
AddFormula(new TFormulaPrimitive("XorY","XorY",TFastFun::XorY));
AddFormula(new TFormulaPrimitive("XNot","XNot",TFastFun::XNot));
AddFormula(new TFormulaPrimitive("XlY","XlY",TFastFun::XlY));
AddFormula(new TFormulaPrimitive("XleY","XleY",TFastFun::XleY));
AddFormula(new TFormulaPrimitive("XgY","XgY",TFastFun::XgY));
AddFormula(new TFormulaPrimitive("XgeY","XgeY",TFastFun::XgeY));
AddFormula(new TFormulaPrimitive("XeY","XeY",TFastFun::XeY));
AddFormula(new TFormulaPrimitive("XneY","XneY",TFastFun::XneY));
AddFormula(new TFormulaPrimitive("PlusXY","PlusXY",TFastFun::PlusXY));
AddFormula(new TFormulaPrimitive("MinusXY","MinusXY",TFastFun::MinusXY));
AddFormula(new TFormulaPrimitive("MultXY","MultXY",TFastFun::MultXY));
AddFormula(new TFormulaPrimitive("DivXY","DivXY",TFastFun::DivXY));
AddFormula(new TFormulaPrimitive("XpYpZ","XpYpZ",TFastFun::XpYpZ));
AddFormula(new TFormulaPrimitive("XxYxZ","XxYxZ",TFastFun::XxYxZ));
AddFormula(new TFormulaPrimitive("XxYpZ","XxYpZ",TFastFun::XxYpZ));
AddFormula(new TFormulaPrimitive("XpYxZ","XpYxZ",TFastFun::XpYxZ));
AddFormula(new TFormulaPrimitive("Gaus","Gaus",TFastFun::Gaus));
AddFormula(new TFormulaPrimitive("Gausn","Gausn",TFastFun::Gausn));
AddFormula(new TFormulaPrimitive("Landau","Landau",TFastFun::Landau));
AddFormula(new TFormulaPrimitive("Landaun","Landaun",TFastFun::Landaun));
AddFormula(new TFormulaPrimitive("Pol0","Pol0",(GenFuncG)TFastFun::FPol0,1));
AddFormula(new TFormulaPrimitive("Pol1","Pol1",(GenFuncG)TFastFun::FPol1,2));
AddFormula(new TFormulaPrimitive("Pol2","Pol2",(GenFuncG)TFastFun::FPol2,3));
AddFormula(new TFormulaPrimitive("Pol3","Pol3",(GenFuncG)TFastFun::FPol3,4));
AddFormula(new TFormulaPrimitive("Pol4","Pol4",(GenFuncG)TFastFun::FPol4,5));
AddFormula(new TFormulaPrimitive("Pol5","Pol5",(GenFuncG)TFastFun::FPol5,6));
AddFormula(new TFormulaPrimitive("Pol6","Pol6",(GenFuncG)TFastFun::FPol6,7));
AddFormula(new TFormulaPrimitive("Pol7","Pol7",(GenFuncG)TFastFun::FPol7,8));
AddFormula(new TFormulaPrimitive("Pol8","Pol8",(GenFuncG)TFastFun::FPol8,9));
AddFormula(new TFormulaPrimitive("Pol9","Pol9",(GenFuncG)TFastFun::FPol9,10));
AddFormula(new TFormulaPrimitive("Pol10","Pol10",(GenFuncG)TFastFun::FPol10,11));
AddFormula(new TFormulaPrimitive("Pow2","Pow2",TFastFun::Pow2));
AddFormula(new TFormulaPrimitive("Pow3","Pow3",TFastFun::Pow3));
AddFormula(new TFormulaPrimitive("Pow4","Pow4",TFastFun::Pow4));
AddFormula(new TFormulaPrimitive("Pow5","Pow5",TFastFun::Pow5));
AddFormula(new TFormulaPrimitive("TMath::Cos","TMath::Cos",cos));
AddFormula(new TFormulaPrimitive("cos","cos",cos));
AddFormula(new TFormulaPrimitive("TMath::Sin","TMath::Sin",sin));
AddFormula(new TFormulaPrimitive("sin","sin",sin));
AddFormula(new TFormulaPrimitive("TMath::Tan","TMath::Tan",tan));
AddFormula(new TFormulaPrimitive("tan","tan",tan));
AddFormula(new TFormulaPrimitive("TMath::ACos","TMath::ACos",acos));
AddFormula(new TFormulaPrimitive("acos","acos",acos));
AddFormula(new TFormulaPrimitive("TMath::ASin","TMath::ASin",asin));
AddFormula(new TFormulaPrimitive("asin","asin",asin));
AddFormula(new TFormulaPrimitive("TMath::ATan","TMath::ATan",atan));
AddFormula(new TFormulaPrimitive("atan","atan",atan));
AddFormula(new TFormulaPrimitive("TMath::ATan2","TMath::ATan2",atan2));
AddFormula(new TFormulaPrimitive("atan2","atan2",atan2));
AddFormula(new TFormulaPrimitive("pow","pow",TMath::Power));
AddFormula(new TFormulaPrimitive("sq","sq",TFastFun::Pow2));
AddFormula(new TFormulaPrimitive("sqrt","sqrt",TFastFun::Sqrt));
AddFormula(new TFormulaPrimitive("min","min",(GenFunc110)TMath::Min));
AddFormula(new TFormulaPrimitive("max","max",(GenFunc110)TMath::Max));
AddFormula(new TFormulaPrimitive("log","log",TMath::Log));
AddFormula(new TFormulaPrimitive("exp","exp",TMath::Exp));
AddFormula(new TFormulaPrimitive("log10","log10",TMath::Log10));
AddFormula(new TFormulaPrimitive("TMath::CosH","TMath::Cosh",cosh));
AddFormula(new TFormulaPrimitive("cosh","cosh",cosh));
AddFormula(new TFormulaPrimitive("TMath::SinH","TMath::SinH",sinh));
AddFormula(new TFormulaPrimitive("sinh","sinh",sinh));
AddFormula(new TFormulaPrimitive("TMath::TanH","TMath::Tanh",tanh));
AddFormula(new TFormulaPrimitive("tanh","tanh",tanh));
AddFormula(new TFormulaPrimitive("TMath::ACosH","TMath::ACosh",TMath::ACosH));
AddFormula(new TFormulaPrimitive("acosh","acosH",TMath::ACosH));
AddFormula(new TFormulaPrimitive("TMath::ASinH","TMath::ASinh",TMath::ASinH));
AddFormula(new TFormulaPrimitive("acosh","acosH",TMath::ASinH));
AddFormula(new TFormulaPrimitive("TMath::ATanH","TMath::ATanh",TMath::ATanH));
AddFormula(new TFormulaPrimitive("atanh","atanh",TMath::ATanH));
AddFormula(new TFormulaPrimitive("TMath::Abs","TMath::Abs",TMath::Abs));
AddFormula(new TFormulaPrimitive("TMath::BreitWigner","TMath::BreitWigner",TMath::BreitWigner));
TMath_GenerInterface();
return 1;
}
Last change: Wed Jun 25 08:39:16 2008
Last generated: 2008-06-25 08:39
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.