TFormula
class description - source file - inheritance tree
public:
TFormula TFormula()
TFormula TFormula(const char* name, const char* formula)
TFormula TFormula(const TFormula& formula)
virtual void ~TFormula()
virtual void Analyze(const char* schain, Int_t& err, Int_t offset = 0)
static TClass* Class()
virtual Int_t Compile(const char* expression)
virtual void Copy(TObject& formula)
virtual char* DefinedString(Int_t code)
virtual Double_t DefinedValue(Int_t code)
virtual Int_t DefinedVariable(TString& variable)
virtual Double_t Eval(Double_t x, Double_t y = 0, Double_t z = 0, Double_t t = 0)
virtual Double_t EvalPar(const Double_t* x, const Double_t* params = 0)
virtual Int_t GetNdim() const
virtual Int_t GetNpar() const
virtual Int_t GetNumber() const
Double_t GetParameter(Int_t ipar) const
Double_t GetParameter(const char* name) const
virtual Double_t* GetParameters() const
virtual void GetParameters(Double_t* params)
virtual const char* GetParName(Int_t ipar) const
virtual Int_t GetParNumber(const char* name) const
virtual TClass* IsA() const
virtual void Print(Option_t* option) const
virtual void SetNumber(Int_t number)
virtual void SetParameter(const char* name, Double_t parvalue)
virtual void SetParameter(Int_t ipar, Double_t parvalue)
virtual void SetParameters(const Double_t* params)
virtual void SetParameters(Double_t p0, Double_t p1, Double_t p2 = 0, Double_t p3 = 0, Double_t p4 = 0, Double_t p5 = 0, Double_t p6 = 0, Double_t p7 = 0, Double_t p8 = 0, Double_t p9 = 0, Double_t p10 = 0)
virtual void SetParName(Int_t ipar, const char* name)
virtual void SetParNames(const char* name0 = "p0", const char* name1 = "p1", const char* name2 = "p2", const char* name3 = "p3", const char* name4 = "p4", const char* name5 = "p5", const char* name6 = "p6", const char* name7 = "p7", const char* name8 = "p8", const char* name9 = "p9", const char* name10 = "p10")
virtual void ShowMembers(TMemberInspector& insp, char* parent)
virtual void Streamer(TBuffer& b)
void StreamerNVirtual(TBuffer& b)
virtual void Update()
protected:
Int_t fNdim Dimension of function (1=1-Dim, 2=2-Dim,etc)
Int_t fNpar Number of parameters
Int_t fNoper Number of operators
Int_t fNconst Number of constants
Int_t fNumber formula number identifier
Int_t fNval Number of different variables in expression
Int_t fNstring Number of different constants character strings
TString* fExpr [fNoper] List of expressions
Int_t* fOper [fNoper] List of operators
Double_t* fConst [fNconst] Array of fNconst formula constants
Double_t* fParams [fNpar] Array of fNpar parameters
TString* fNames [fNpar] Array of parameter names
TBits fAlreadyFound ! cache for information
public:
static const enum TObject:: kNotGlobal
See also
-
TF1, TTreeFormula
*-*-*-*-*-*-*-*-*-*-*The F O R M U L A class*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =========================
*-*
*-* This class has been implemented by Nicolas Brun (age 18).
*-* ========================================================
/*
*/
*-*
*-* Example of valid expressions:
*-* - sin(x)/x
*-* - [0]*sin(x) + [1]*exp(-[2]*x)
*-* - x + y**2
*-* - x^2 + y^2
*-* - [0]*pow([1],4)
*-* - 2*pi*sqrt(x/y)
*-* - gaus(0)*expo(3) + ypol3(5)*x
*-*
*-* In the last example above:
*-* gaus(0) is a substitute for [0]*exp(-0.5*((x-[1])/[2])**2)
*-* and (0) means start numbering parameters at 0
*-* expo(3) is a substitute for exp([3]+[4])*x)
*-* pol3(5) is a substitute for par[5]+par[6]*x+par[7]*x**2+par[8]*x**3
*-* (here Pol3 stands for Polynomial of degree 3)
*-*
*-* Comparisons operators are also supported (&&, ||, ==, <=, >=, !)
*-* Examples:
*-* sin(x*(x<0.5 || x>1))
*-* If the result of a comparison is TRUE, the result is 1, otherwise 0.
*-*
*-* Already predefined names can be given. For example, if the formula
*-* TFormula old(sin(x*(x<0.5 || x>1))) one can assign a name to the formula. By default
*-* the name of the object = title = formula itself.
*-* old.SetName("old").
*-* then, old can be reused in a new expression.
*-* TFormula new("x*old") is equivalent to:
*-* TFormula new("x*sin(x*(x<0.5 || x>1))")
*-*
*-* Up to 4 dimensions are supported (indicated by x, y, z, t)
*-* An expression may have 0 parameters or a list of parameters
*-* indicated by the sequence [par_number]
*-*
*-* A graph showing the logic to compile and analyze a formula
*-* is shown in TFormula::Compile and TFormula::Analyze.
*-* Once a formula has been compiled, it can be evaluated for a given
*-* set of parameters. see graph in TFormula::EvalPar.
*-*
*-* This class is the base class for the function classes TF1,TF2 and TF3.
*-* It is also used by the ntuple selection mechanism TNtupleFormula.
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
TFormula(): TNamed()
*-*-*-*-*-*-*-*-*-*-*Formula default constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ============================
TFormula(const char *name,const char *expression) :TNamed(name,expression)
*-*-*-*-*-*-*-*-*-*-*Normal Formula constructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ==========================
TFormula(const TFormula &formula) : TNamed()
~TFormula()
*-*-*-*-*-*-*-*-*-*-*Formula default destructor*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ===========================
void Analyze(const char *schain, Int_t &err, Int_t offset)
*-*-*-*-*-*-*-*-*Analyze a sub-expression in one formula*-*-*-*-*-*-*-*-*-*-*
*-* =======================================
*-*
*-* Expressions in one formula are recursively analyzed.
*-* Result of analysis is stored in the object tables.
*-*
*-* Table of function codes and errors
*-* ==================================
*-*
*-* * functions :
*-*
*-* + 1 pow 20
*-* - 2 sq 21
*-* * 3 sqrt 22
*-* / 4 strstr 23
*-* % 5 min 24
*-* max 25
*-* log 30
*-* cos 10 exp 31
*-* sin 11 log10 32
*-* tan 12
*-* acos 13 abs 41
*-* asin 14 sign 42
*-* atan 15 int 43
*-* atan2 16
*-* fmod 17 rndm 50
*-*
*-* cosh 70 acosh 73
*-* sinh 71 asinh 74
*-* tanh 72 atanh 75
*-*
*-* expo 10xx gaus 20xx
*-* expo(0) 1000 gaus(0) 2000
*-* expo(1) 1001 gaus(1) 2001
*-* xexpo 10xx xgaus 20xx
*-* yexpo 11xx ygaus 21xx
*-* zexpo 12xx zgaus 22xx
*-* xyexpo 15xx xygaus 25xx
*-* yexpo(5) 1105 ygaus(5) 2105
*-* xyexpo(2) 1502 xygaus(2) 2502
*-*
*-* landau 40xx
*-* landau(0) 4000
*-* landau(1) 4001
*-* xlandau 40xx
*-* ylandau 41xx
*-* zlandau 42xx
*-* xylandau 45xx
*-* ylandau(5) 4105
*-* xylandau(2) 4502
*-*
*-* pol0 100xx pol1 101xx
*-* pol0(0) 10000 pol1(0) 10100
*-* pol0(1) 10001 pol1(1) 10101
*-* xpol0 100xx xpol1 101xx
*-* ypol0 200xx ypol1 201xx
*-* zpol0 300xx zpol1 301xx
*-* ypol0(5) 20005 ypol1(5) 20105
*-*
*-* pi 40
*-*
*-* && 60 < 64
*-* || 61 > 65
*-* == 62 <= 66
*-* != 63 => 67
*-* ! 68
*-* ==(string) 76 & 78
*-* !=(string) 77 | 79
*-* <<(shift) 80 >>(shift) 81
*-*
*-* * constants :
*-*
*-* c0 50000 c1 50001 etc..
*-*
*-* * strings :
*-*
*-* s0 80000 s1 80001 etc..
*-*
*-* * variables :
*-*
*-* x 100000 y 100001 z 100002 t 100003
*-*
*-* * parameters :
*-*
*-* [1] 101
*-* [2] 102
*-* etc.
*-*
*-* * errors :
*-*
*-* 1 : Division By Zero
*-* 2 : Invalid Floating Point Operation
*-* 4 : Empty String
*-* 5 : invalid syntax
*-* 6 : Too many operators
*-* 7 : Too many parameters
*-* 10 : z specified but not x and y
*-* 11 : z and y specified but not x
*-* 12 : y specified but not x
*-* 13 : z and x specified but not y
*-* 20 : non integer value for parameter number
*-* 21 : atan2 requires two arguments
*-* 22 : pow requires two arguments
*-* 23 : degree of polynomial not specified
*-* 24 : Degree of polynomial must be positive
*-* 25 : Degree of polynomial must be less than 20
*-* 26 : Unknown name
*-* 27 : Too many constants in expression
*-* 28 : strstr requires two arguments
*-* 40 : '(' is expected
*-* 41 : ')' is expected
*-* 42 : '[' is expected
*-* 43 : ']' is expected
/*
*/
*-*
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Int_t Compile(const char *expression)
*-*-*-*-*-*-*-*-*-*-*Compile expression already stored in fTitle*-*-*-*-*-*
*-* ===========================================
*-*
*-* Loop on all subexpressions of formula stored in fTitle
*-*
/*
*/
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
void Copy(TObject &obj)
*-*-*-*-*-*-*-*-*-*-*Copy this formula*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =================
char* DefinedString(Int_t)
*-*-*-*-*-*Return address of string corresponding to special code*-*-*-*-*-*
*-* ======================================================
*-*
*-* This member function is inactive in the TFormula class.
*-* It may be redefined in derived classes.
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Double_t DefinedValue(Int_t)
*-*-*-*-*-*Return value corresponding to special code*-*-*-*-*-*-*-*-*
*-* ==========================================
*-*
*-* This member function is inactive in the TFormula class.
*-* It may be redefined in derived classes.
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Int_t DefinedVariable(TString &chaine)
*-*-*-*-*-*Check if expression is in the list of defined variables*-*-*-*-*
*-* =======================================================
*-*
*-* This member function can be overloaded in derived classes
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Double_t Eval(Double_t x, Double_t y, Double_t z, Double_t t)
*-*-*-*-*-*-*-*-*-*-*Evaluate this formula*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =====================
*-*
*-* The current value of variables x,y,z,t is passed through x, y, z and t.
*-* The parameters used will be the ones in the array params if params is given
*-* otherwise parameters will be taken from the stored data members fParams
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Double_t EvalPar(const Double_t *x, const Double_t *params)
*-*-*-*-*-*-*-*-*-*-*Evaluate this formula*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =====================
*-*
*-* The current value of variables x,y,z,t is passed through the pointer x.
*-* The parameters used will be the ones in the array params if params is given
*-* otherwise parameters will be taken from the stored data members fParams
/*
*/
*-*
*-*
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Double_t GetParameter(Int_t ipar) const
return value of parameter number ipar
Double_t GetParameter(const char *parName) const
return value of parameter named parName
const char* GetParName(Int_t ipar) const
*-*-*-*-*-*-*-*Return name of one parameter*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ============================
Int_t GetParNumber(const char *parName) const
return parameter number by name
void Print(Option_t *) const
*-*-*-*-*-*-*-*-*-*-*Dump this formula with its attributes*-*-*-*-*-*-*-*-*-*
*-* =====================================
void SetParameter(const char *name, Double_t value)
*-*-*-*-*-*-*-*Initialize parameter number ipar*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ================================
void SetParameter(Int_t ipar, Double_t value)
*-*-*-*-*-*-*-*Initialize parameter number ipar*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ================================
void SetParameters(const Double_t *params)
*-*-*-*-*-*-*-*Initialize array of all parameters*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ==================================
void SetParameters(Double_t p0,Double_t p1,Double_t p2,Double_t p3,Double_t p4
,Double_t p5,Double_t p6,Double_t p7,Double_t p8,Double_t p9,Double_t p10)
*-*-*-*-*-*-*-*Initialize up to 10 parameters*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ==============================
void SetParName(Int_t ipar, const char *name)
Set name of parameter number ipar
void SetParNames(const char*name0,const char*name1,const char*name2,const char*name3,const char*name4,
const char*name5,const char*name6,const char*name7,const char*name8,const char*name9,const char*name10)
*-*-*-*-*-*-*-*-*-*Set up to 10 parameter names*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* ============================
void Streamer(TBuffer &b)
*-*-*-*-*-*-*-*-*Stream a class object*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
*-* =========================================
Inline Functions
Int_t GetNdim() const
Int_t GetNpar() const
Int_t GetNumber() const
Double_t* GetParameters() const
void GetParameters(Double_t* params)
void SetNumber(Int_t number)
void Update()
TClass* Class()
TClass* IsA() const
void ShowMembers(TMemberInspector& insp, char* parent)
void StreamerNVirtual(TBuffer& b)
Author: Nicolas Brun 19/08/95
Last update: root/hist:$Name: $:$Id: TFormula.cxx,v 1.32 2002/08/05 18:13:15 brun Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
ROOT page - Class index - Top of the page
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.