Logo ROOT   6.12/07
Reference Guide
List of all members | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
TFormula Class Reference

The Formula class.

This is a new version of the TFormula class based on Cling. This class is not 100% backward compatible with the old TFormula class, which is still available in ROOT as ROOT::v5::TFormula. Some of the TFormula member functions available in version 5, such as Analyze and AnalyzeFunction are not available in the new TFormula. On the other hand formula expressions which were valid in version 5 are still valid in TFormula version 6

This class has been implemented during Google Summer of Code 2013 by Maciej Zimnoch.

Example of valid expressions:

In the last examples above:

TMath functions can be part of the expression, eg:

Formula may contain constants, eg:

and more.

Formulas may also contain other user-defined ROOT functions defined with a TFormula, eg, where f1 is defined on one x-dimension and 2 parameters:

To replace only parameter names, the dimension variable can be dropped. Alternatively, to change only the dimension variable, the parameters can be dropped. Note that if a parameter is dropped or keeps its old name, its old value will be copied to the new function. The syntax used in the examples above also applies to the predefined parametrized functions like gaus and expo.

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("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.

TFormula new("new","x*old")

is equivalent to:

TFormula new("new","x*sin(x*(x&lt;0.5 || x&gt;1))")

The class supports unlimited number of variables and parameters. By default the names which can be used for the variables are x,y,z,t or x[0],x[1],x[2],x[3],....x[N] for N-dimensional formulas.

This class is not anymore the base class for the function classes TF1, but it has now a data member of TF1 which can be accessed via TF1::GetFormula.

Definition at line 83 of file TFormula.h.

Public Types

enum  EStatusBits { kNotGlobal = BIT(10), kNormalized = BIT(14), kLinear = BIT(16), kLambda = BIT(17) }
 
- Public Types inherited from TObject
enum  {
  kIsOnHeap = 0x01000000, kNotDeleted = 0x02000000, kZombie = 0x04000000, kInconsistent = 0x08000000,
  kBitMask = 0x00ffffff
}
 
enum  { kSingleKey = BIT(0), kOverwrite = BIT(1), kWriteDelete = BIT(2) }
 
enum  EDeprecatedStatusBits { kObjInCanvas = BIT(3) }
 
enum  EStatusBits {
  kCanDelete = BIT(0), kMustCleanup = BIT(3), kIsReferenced = BIT(4), kHasUUID = BIT(5),
  kCannotPick = BIT(6), kNoContextMenu = BIT(8), kInvalidObject = BIT(13)
}
 

Public Member Functions

 TFormula ()
 
 TFormula (const char *name, const char *formula="", bool addToGlobList=true, bool vectorize=false)
 
 TFormula (const char *name, const char *formula, int ndim, int npar, bool addToGlobList=true)
 Constructor from a full compile-able C++ expression. More...
 
 TFormula (const TFormula &formula)
 
virtual ~TFormula ()
 
void AddParameter (const TString &name, Double_t value=0)
 
void AddVariable (const TString &name, Double_t value=0)
 Adds variable to known variables, and reprocess formula. More...
 
void AddVariables (const TString *vars, const Int_t size)
 Adds multiple variables. More...
 
virtual void Clear (Option_t *option="")
 Clear the formula setting expression to empty and reset the variables and parameters containers. More...
 
Int_t Compile (const char *expression="")
 Compile the given expression with Cling backward compatibility method to be used in combination with the empty constructor if no expression is given , the current stored formula (retrieved with GetExpFormula()) or the title is used. More...
 
virtual void Copy (TObject &f1) const
 Copy this to obj. More...
 
Double_t Eval (Double_t x) const
 Sets first variable (e.g. x) and evaluate formula. More...
 
Double_t Eval (Double_t x, Double_t y) const
 Sets first 2 variables (e.g. x and y) and evaluate formula. More...
 
Double_t Eval (Double_t x, Double_t y, Double_t z) const
 Sets first 3 variables (e.g. x, y, z) and evaluate formula. More...
 
Double_t Eval (Double_t x, Double_t y, Double_t z, Double_t t) const
 Sets first 4 variables (e.g. x, y, z, t) and evaluate formula. More...
 
Double_t EvalPar (const Double_t *x, const Double_t *params=0) const
 
template<class T >
EvalPar (const T *x, const Double_t *params=0) const
 
TString GetExpFormula (Option_t *option="") const
 Return the expression formula. More...
 
const TObjectGetLinearPart (Int_t i) const
 Return linear part. More...
 
Int_t GetNdim () const
 
Int_t GetNpar () const
 
Int_t GetNumber () const
 
Double_t GetParameter (const char *name) const
 Returns parameter value given by string. More...
 
Double_t GetParameter (Int_t param) const
 Return parameter value given by integer. More...
 
Double_tGetParameters () const
 
void GetParameters (Double_t *params) const
 
const char * GetParName (Int_t ipar) const
 Return parameter name given by integer. More...
 
Int_t GetParNumber (const char *name) const
 Return parameter index given a name (return -1 for not existing parameters) non need to print an error. More...
 
Double_t GetVariable (const char *name) const
 Returns variable value. More...
 
TString GetVarName (Int_t ivar) const
 Returns variable name given its position in the array. More...
 
Int_t GetVarNumber (const char *name) const
 Returns variable number (positon in array) given its name. More...
 
Bool_t IsLinear () const
 
Bool_t IsValid () const
 
Bool_t IsVectorized () const
 
TFormulaoperator= (const TFormula &rhs)
 = operator. More...
 
void Print (Option_t *option="") const
 Print the formula and its attributes. More...
 
void SetName (const char *name)
 Set the name of the formula. More...
 
void SetParameter (const char *name, Double_t value)
 Sets parameter value. More...
 
void SetParameter (Int_t param, Double_t value)
 Set a parameter given a parameter index The parameter index is by default the alphabetic order given to the parameters apart if the users has defined explicitly the parameter names. More...
 
void SetParameters (const Double_t *params)
 Set a vector of parameters value. More...
 
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)
 Set a list of parameters. More...
 
void SetParName (Int_t ipar, const char *name)
 
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")
 
void SetVariable (const TString &name, Double_t value)
 Sets variable value. More...
 
void SetVariables (const std::pair< TString, Double_t > *vars, const Int_t size)
 Sets multiple variables. More...
 
void SetVectorized (Bool_t vectorized)
 
- Public Member Functions inherited from TNamed
 TNamed ()
 
 TNamed (const char *name, const char *title)
 
 TNamed (const TString &name, const TString &title)
 
 TNamed (const TNamed &named)
 TNamed copy ctor. More...
 
virtual ~TNamed ()
 TNamed destructor. More...
 
virtual TObjectClone (const char *newname="") const
 Make a clone of an object using the Streamer facility. More...
 
virtual Int_t Compare (const TObject *obj) const
 Compare two TNamed objects. More...
 
virtual void FillBuffer (char *&buffer)
 Encode TNamed into output buffer. More...
 
virtual const char * GetName () const
 Returns name of object. More...
 
virtual const char * GetTitle () const
 Returns title of object. More...
 
virtual ULong_t Hash () const
 Return hash value for this object. More...
 
virtual Bool_t IsSortable () const
 
virtual void ls (Option_t *option="") const
 List TNamed name and title. More...
 
TNamedoperator= (const TNamed &rhs)
 TNamed assignment operator. More...
 
virtual void SetNameTitle (const char *name, const char *title)
 Set all the TNamed parameters (name and title). More...
 
virtual void SetTitle (const char *title="")
 Set the title of the TNamed. More...
 
virtual Int_t Sizeof () const
 Return size of the TNamed part of the TObject. More...
 
- Public Member Functions inherited from TObject
 TObject ()
 TObject constructor. More...
 
 TObject (const TObject &object)
 TObject copy ctor. More...
 
virtual ~TObject ()
 TObject destructor. More...
 
void AbstractMethod (const char *method) const
 Use this method to implement an "abstract" method that you don't want to leave purely abstract. More...
 
virtual void AppendPad (Option_t *option="")
 Append graphics object to current pad. More...
 
virtual void Browse (TBrowser *b)
 Browse object. May be overridden for another default action. More...
 
ULong_t CheckedHash ()
 Checked and record whether for this class has a consistent Hash/RecursiveRemove setup (*) and then return the regular Hash value for this object. More...
 
virtual const char * ClassName () const
 Returns name of class to which the object belongs. More...
 
virtual void Delete (Option_t *option="")
 Delete this object. More...
 
virtual Int_t DistancetoPrimitive (Int_t px, Int_t py)
 Computes distance from point (px,py) to the object. More...
 
virtual void Draw (Option_t *option="")
 Default Draw method for all objects. More...
 
virtual void DrawClass () const
 Draw class inheritance tree of the class to which this object belongs. More...
 
virtual TObjectDrawClone (Option_t *option="") const
 Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad). More...
 
virtual void Dump () const
 Dump contents of object on stdout. More...
 
virtual void Error (const char *method, const char *msgfmt,...) const
 Issue error message. More...
 
virtual void Execute (const char *method, const char *params, Int_t *error=0)
 Execute method on this object with the given parameter string, e.g. More...
 
virtual void Execute (TMethod *method, TObjArray *params, Int_t *error=0)
 Execute method on this object with parameters stored in the TObjArray. More...
 
virtual void ExecuteEvent (Int_t event, Int_t px, Int_t py)
 Execute action corresponding to an event at (px,py). More...
 
virtual void Fatal (const char *method, const char *msgfmt,...) const
 Issue fatal error message. More...
 
virtual TObjectFindObject (const char *name) const
 Must be redefined in derived classes. More...
 
virtual TObjectFindObject (const TObject *obj) const
 Must be redefined in derived classes. More...
 
virtual Option_tGetDrawOption () const
 Get option used by the graphics system to draw this object. More...
 
virtual const char * GetIconName () const
 Returns mime type name of object. More...
 
virtual char * GetObjectInfo (Int_t px, Int_t py) const
 Returns string containing info about the object at position (px,py). More...
 
virtual Option_tGetOption () const
 
virtual UInt_t GetUniqueID () const
 Return the unique object id. More...
 
virtual Bool_t HandleTimer (TTimer *timer)
 Execute action in response of a timer timing out. More...
 
Bool_t HasInconsistentHash () const
 Return true is the type of this object is known to have an inconsistent setup for Hash and RecursiveRemove (i.e. More...
 
virtual void Info (const char *method, const char *msgfmt,...) const
 Issue info message. More...
 
virtual Bool_t InheritsFrom (const char *classname) const
 Returns kTRUE if object inherits from class "classname". More...
 
virtual Bool_t InheritsFrom (const TClass *cl) const
 Returns kTRUE if object inherits from TClass cl. More...
 
virtual void Inspect () const
 Dump contents of this object in a graphics canvas. More...
 
void InvertBit (UInt_t f)
 
virtual Bool_t IsEqual (const TObject *obj) const
 Default equal comparison (objects are equal if they have the same address in memory). More...
 
virtual Bool_t IsFolder () const
 Returns kTRUE in case object contains browsable objects (like containers or lists of other objects). More...
 
R__ALWAYS_INLINE Bool_t IsOnHeap () const
 
R__ALWAYS_INLINE Bool_t IsZombie () const
 
void MayNotUse (const char *method) const
 Use this method to signal that a method (defined in a base class) may not be called in a derived class (in principle against good design since a child class should not provide less functionality than its parent, however, sometimes it is necessary). More...
 
virtual Bool_t Notify ()
 This method must be overridden to handle object notification. More...
 
void Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const
 Use this method to declare a method obsolete. More...
 
void operator delete (void *ptr)
 Operator delete. More...
 
void operator delete[] (void *ptr)
 Operator delete []. More...
 
voidoperator new (size_t sz)
 
voidoperator new (size_t sz, void *vp)
 
voidoperator new[] (size_t sz)
 
voidoperator new[] (size_t sz, void *vp)
 
TObjectoperator= (const TObject &rhs)
 TObject assignment operator. More...
 
virtual void Paint (Option_t *option="")
 This method must be overridden if a class wants to paint itself. More...
 
virtual void Pop ()
 Pop on object drawn in a pad to the top of the display list. More...
 
virtual Int_t Read (const char *name)
 Read contents of object with specified name from the current directory. More...
 
virtual void RecursiveRemove (TObject *obj)
 Recursively remove this object from a list. More...
 
void ResetBit (UInt_t f)
 
virtual void SaveAs (const char *filename="", Option_t *option="") const
 Save this object in the file specified by filename. More...
 
virtual void SavePrimitive (std::ostream &out, Option_t *option="")
 Save a primitive as a C++ statement(s) on output stream "out". More...
 
void SetBit (UInt_t f, Bool_t set)
 Set or unset the user status bits as specified in f. More...
 
void SetBit (UInt_t f)
 
virtual void SetDrawOption (Option_t *option="")
 Set drawing option for object. More...
 
virtual void SetUniqueID (UInt_t uid)
 Set the unique object id. More...
 
virtual void SysError (const char *method, const char *msgfmt,...) const
 Issue system error message. More...
 
R__ALWAYS_INLINE Bool_t TestBit (UInt_t f) const
 
Int_t TestBits (UInt_t f) const
 
virtual void UseCurrentStyle ()
 Set current style settings in this object This function is called when either TCanvas::UseCurrentStyle or TROOT::ForceStyle have been invoked. More...
 
virtual void Warning (const char *method, const char *msgfmt,...) const
 Issue warning message. More...
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0)
 Write this object to the current directory. More...
 
virtual Int_t Write (const char *name=0, Int_t option=0, Int_t bufsize=0) const
 Write this object to the current directory. More...
 

Protected Member Functions

void DoAddParameter (const TString &name, Double_t value, bool processFormula)
 Adds parameter to known parameters. More...
 
Double_t DoEval (const Double_t *x, const Double_t *p=nullptr) const
 Evaluate formula. More...
 
void DoSetParameters (const Double_t *p, Int_t size)
 
void ExtractFunctors (TString &formula)
 Extracts functors from formula, and put them in fFuncs. More...
 
Bool_t PrepareFormula (TString &formula)
 prepare the formula to be executed normally is called with fFormula More...
 
void PreProcessFormula (TString &formula)
 Preprocessing of formula Replace all ** by ^, and removes spaces. More...
 
void ProcessFormula (TString &formula)
 Iterates through functors in fFuncs and performs the appropriate action. More...
 
void ReplaceParamName (TString &formula, const TString &oldname, const TString &name)
 Replace in Formula expression the parameter name. More...
 
void SetPredefinedParamNames ()
 Set parameter names only in case of pre-defined functions. More...
 
- Protected Member Functions inherited from TObject
virtual void DoError (int level, const char *location, const char *fmt, va_list va) const
 Interface to ErrorHandler (protected). More...
 
void MakeZombie ()
 

Static Protected Member Functions

static Bool_t IsAParameterName (const TString &formula, int ipos)
 
static Bool_t IsBracket (const char c)
 
static Bool_t IsFunctionNameChar (const char c)
 
static Bool_t IsHexadecimal (const TString &formula, int ipos)
 
static Bool_t IsOperator (const char c)
 
static Bool_t IsScientificNotation (const TString &formula, int ipos)
 

Protected Attributes

std::map< TString, Double_tfConsts
 
TString fFormula
 
std::list< TFormulaFunctionfFuncs
 
std::map< TString, TStringfFunctionsShortcuts
 
std::vector< TObject * > fLinearParts
 
Int_t fNdim
 
Int_t fNpar
 
Int_t fNumber
 
std::map< TString, Int_t, TFormulaParamOrderfParams
 list of variable names More...
 
std::map< TString, TFormulaVariablefVars
 
Bool_t fVectorized = false
 
- Protected Attributes inherited from TNamed
TString fName
 
TString fTitle
 

Private Member Functions

void FillDefaults ()
 Fill structures with default variables, constants and function shortcuts. More...
 
void FillParametrizedFunctions (std::map< std::pair< TString, Int_t >, std::pair< TString, TString >> &functions)
 Fill map with parametrized functions. More...
 
void FillVecFunctionsShurtCuts ()
 Fill the shortcuts for vectorized functions We will replace for example sin with vecCore::Mat::Sin. More...
 
void HandleExponentiation (TString &formula)
 Handling exponentiation Can handle multiple carets, eg. More...
 
void HandleFunctionArguments (TString &formula)
 Handling user functions (and parametrized functions) to take variables and optionally parameters as arguments. More...
 
void HandleLinear (TString &formula)
 Handle linear functions defined with the operator ++. More...
 
void HandleParametrizedFunctions (TString &formula)
 Handling parametrized functions Function can be normalized, and have different variable then x. More...
 
void HandleParamRanges (TString &formula)
 Handling parameter ranges, in the form of [1..5]. More...
 
void HandlePolN (TString &formula)
 Handling polN If before 'pol' exist any name, this name will be treated as variable used in polynomial eg. More...
 
Bool_t InitLambdaExpression (const char *formula)
 
void InputFormulaIntoCling ()
 pointer to the lambda function More...
 
Bool_t PrepareEvalMethod ()
 Sets TMethodCall to function inside Cling environment. More...
 
void ReplaceAllNames (TString &formula, std::map< TString, TString > &substitutions)
 

Static Private Member Functions

static Bool_t IsDefaultVariableName (const TString &name)
 

Private Attributes

Bool_t fAllParametersSetted
 transient to force re-initialization More...
 
Bool_t fClingInitialized
 trasient to force initialization More...
 
TString fClingInput
 
TString fClingName
 pointer to methodcall More...
 
std::vector< Double_tfClingParameters
 cached variables More...
 
std::vector< Double_tfClingVariables
 input function passed to Cling More...
 
TInterpreter::CallFuncIFacePtr_t::Generic_t fFuncPtr
 unique name passed to Cling to define the function ( double clingName(double*x, double*p) ) More...
 
voidfLambdaPtr
 function pointer More...
 
TMethodCallfMethod
 
Bool_t fReadyToExecute
 

Additional Inherited Members

- Static Public Member Functions inherited from TObject
static Long_t GetDtorOnly ()
 Return destructor only flag. More...
 
static Bool_t GetObjectStat ()
 Get status of object stat flag. More...
 
static void SetDtorOnly (void *obj)
 Set destructor only flag. More...
 
static void SetObjectStat (Bool_t stat)
 Turn on/off tracking of objects in the TObjectTable. More...
 

#include "inc/TFormula.h"

Inheritance diagram for TFormula:
[legend]

Member Enumeration Documentation

◆ EStatusBits

Enumerator
kNotGlobal 
kNormalized 
kLinear 
kLambda 

Definition at line 153 of file TFormula.h.

Constructor & Destructor Documentation

◆ TFormula() [1/4]

TFormula::TFormula ( )

Definition at line 319 of file TFormula.cxx.

◆ ~TFormula()

TFormula::~TFormula ( )
virtual

Definition at line 346 of file TFormula.cxx.

◆ TFormula() [2/4]

TFormula::TFormula ( const char *  name,
const char *  formula = "",
bool  addToGlobList = true,
bool  vectorize = false 
)

Definition at line 366 of file TFormula.cxx.

◆ TFormula() [3/4]

TFormula::TFormula ( const char *  name,
const char *  formula,
int  ndim,
int  npar,
bool  addToGlobList = true 
)

Constructor from a full compile-able C++ expression.

Definition at line 413 of file TFormula.cxx.

◆ TFormula() [4/4]

TFormula::TFormula ( const TFormula formula)

Definition at line 459 of file TFormula.cxx.

Member Function Documentation

◆ AddParameter()

void TFormula::AddParameter ( const TString name,
Double_t  value = 0 
)
inline

Definition at line 167 of file TFormula.h.

◆ AddVariable()

void TFormula::AddVariable ( const TString name,
Double_t  value = 0 
)

Adds variable to known variables, and reprocess formula.

Definition at line 2405 of file TFormula.cxx.

◆ AddVariables()

void TFormula::AddVariables ( const TString vars,
const Int_t  size 
)

Adds multiple variables.

First argument is an array of pairs<TString,Double>, where first argument is name of variable, second argument represents value. size - number of variables passed in first argument

Definition at line 2438 of file TFormula.cxx.

◆ Clear()

void TFormula::Clear ( Option_t option = "")
virtual

Clear the formula setting expression to empty and reset the variables and parameters containers.

Reimplemented from TNamed.

Definition at line 648 of file TFormula.cxx.

◆ Compile()

Int_t TFormula::Compile ( const char *  expression = "")

Compile the given expression with Cling backward compatibility method to be used in combination with the empty constructor if no expression is given , the current stored formula (retrieved with GetExpFormula()) or the title is used.

return 0 if the formula compilation is successful

Definition at line 536 of file TFormula.cxx.

◆ Copy()

void TFormula::Copy ( TObject named) const
virtual

Copy this to obj.

Reimplemented from TNamed.

Definition at line 570 of file TFormula.cxx.

◆ DoAddParameter()

void TFormula::DoAddParameter ( const TString name,
Double_t  value,
bool  processFormula 
)
protected

Adds parameter to known parameters.

User should use SetParameter, because parameters are added during initialization part, and after that adding new will be pointless.

Definition at line 2579 of file TFormula.cxx.

◆ DoEval()

Double_t TFormula::DoEval ( const Double_t x,
const Double_t p = nullptr 
) const
protected

Evaluate formula.

If formula is not ready to execute(missing parameters/variables), print these which are not known. If parameter has default value, and has not been set, appropriate warning is shown.

Definition at line 3087 of file TFormula.cxx.

◆ DoSetParameters()

void TFormula::DoSetParameters ( const Double_t p,
Int_t  size 
)
protected

Definition at line 2785 of file TFormula.cxx.

◆ Eval() [1/4]

Double_t TFormula::Eval ( Double_t  x) const

Sets first variable (e.g. x) and evaluate formula.

Definition at line 3075 of file TFormula.cxx.

◆ Eval() [2/4]

Double_t TFormula::Eval ( Double_t  x,
Double_t  y 
) const

Sets first 2 variables (e.g. x and y) and evaluate formula.

Definition at line 3066 of file TFormula.cxx.

◆ Eval() [3/4]

Double_t TFormula::Eval ( Double_t  x,
Double_t  y,
Double_t  z 
) const

Sets first 3 variables (e.g. x, y, z) and evaluate formula.

Definition at line 3057 of file TFormula.cxx.

◆ Eval() [4/4]

Double_t TFormula::Eval ( Double_t  x,
Double_t  y,
Double_t  z,
Double_t  t 
) const

Sets first 4 variables (e.g. x, y, z, t) and evaluate formula.

Definition at line 3048 of file TFormula.cxx.

◆ EvalPar() [1/2]

Double_t TFormula::EvalPar ( const Double_t x,
const Double_t params = 0 
) const

Definition at line 2966 of file TFormula.cxx.

◆ EvalPar() [2/2]

template<class T >
T TFormula::EvalPar ( const T *  x,
const Double_t params = 0 
) const
inline

Definition at line 181 of file TFormula.h.

◆ ExtractFunctors()

void TFormula::ExtractFunctors ( TString formula)
protected

Extracts functors from formula, and put them in fFuncs.

Simple grammar:

  • <function> := name(arg1,arg2...)
  • <variable> := name
  • <parameter> := [number]
  • <name> := String containing lower and upper letters, numbers, underscores
  • <number> := Integer number Operators are omitted.

Definition at line 1698 of file TFormula.cxx.

◆ FillDefaults()

void TFormula::FillDefaults ( )
private

Fill structures with default variables, constants and function shortcuts.

Definition at line 755 of file TFormula.cxx.

◆ FillParametrizedFunctions()

void TFormula::FillParametrizedFunctions ( std::map< std::pair< TString, Int_t >, std::pair< TString, TString >> &  functions)
private

Fill map with parametrized functions.

Definition at line 2266 of file TFormula.cxx.

◆ FillVecFunctionsShurtCuts()

void TFormula::FillVecFunctionsShurtCuts ( )
private

Fill the shortcuts for vectorized functions We will replace for example sin with vecCore::Mat::Sin.

Definition at line 825 of file TFormula.cxx.

◆ GetExpFormula()

TString TFormula::GetExpFormula ( Option_t option = "") const

Return the expression formula.

  • If option = "P" replace the parameter names with their values
  • If option = "CLING" return the actual expression used to build the function passed to cling
  • If option = "CLINGP" replace in the CLING expression the parameter with their values

Definition at line 3189 of file TFormula.cxx.

◆ GetLinearPart()

const TObject * TFormula::GetLinearPart ( Int_t  i) const

Return linear part.

Definition at line 2389 of file TFormula.cxx.

◆ GetNdim()

Int_t TFormula::GetNdim ( ) const
inline

Definition at line 189 of file TFormula.h.

◆ GetNpar()

Int_t TFormula::GetNpar ( ) const
inline

Definition at line 190 of file TFormula.h.

◆ GetNumber()

Int_t TFormula::GetNumber ( ) const
inline

Definition at line 191 of file TFormula.h.

◆ GetParameter() [1/2]

Double_t TFormula::GetParameter ( const char *  name) const

Returns parameter value given by string.

Definition at line 2669 of file TFormula.cxx.

◆ GetParameter() [2/2]

Double_t TFormula::GetParameter ( Int_t  param) const

Return parameter value given by integer.

Definition at line 2683 of file TFormula.cxx.

◆ GetParameters() [1/2]

Double_t * TFormula::GetParameters ( ) const

Definition at line 2709 of file TFormula.cxx.

◆ GetParameters() [2/2]

void TFormula::GetParameters ( Double_t params) const

Definition at line 2716 of file TFormula.cxx.

◆ GetParName()

const char * TFormula::GetParName ( Int_t  ipar) const

Return parameter name given by integer.

Definition at line 2695 of file TFormula.cxx.

◆ GetParNumber()

Int_t TFormula::GetParNumber ( const char *  name) const

Return parameter index given a name (return -1 for not existing parameters) non need to print an error.

Definition at line 2657 of file TFormula.cxx.

◆ GetVariable()

Double_t TFormula::GetVariable ( const char *  name) const

Returns variable value.

Definition at line 2522 of file TFormula.cxx.

◆ GetVarName()

TString TFormula::GetVarName ( Int_t  ivar) const

Returns variable name given its position in the array.

Definition at line 2548 of file TFormula.cxx.

◆ GetVarNumber()

Int_t TFormula::GetVarNumber ( const char *  name) const

Returns variable number (positon in array) given its name.

Definition at line 2535 of file TFormula.cxx.

◆ HandleExponentiation()

void TFormula::HandleExponentiation ( TString formula)
private

Handling exponentiation Can handle multiple carets, eg.

2^3^4 will be treated like 2^(3^4)

Definition at line 1488 of file TFormula.cxx.

◆ HandleFunctionArguments()

void TFormula::HandleFunctionArguments ( TString formula)
private

Handling user functions (and parametrized functions) to take variables and optionally parameters as arguments.

Definition at line 1204 of file TFormula.cxx.

◆ HandleLinear()

void TFormula::HandleLinear ( TString formula)
private

Handle linear functions defined with the operator ++.

Definition at line 1582 of file TFormula.cxx.

◆ HandleParametrizedFunctions()

void TFormula::HandleParametrizedFunctions ( TString formula)
private

Handling parametrized functions Function can be normalized, and have different variable then x.

Variables should be placed in brackets after function name. No brackets are treated like [x]. Normalized function has char 'n' after name, eg. gausn[var](0) will be replaced with [0]*exp(-0.5*((var-[1])/[2])^2)/(sqrt(2*pi)*[2])

Adding function is easy, just follow these rules, and add to TFormula::FillParametrizedFunctions defined further below:

  • Key for function map is pair of name and dimension of function
  • value of key is a pair function body and normalized function body
  • {Vn} is a place where variable appear, n represents n-th variable from variable list. Count starts from 0.
  • [num] stands for parameter number. If user pass to function argument 5, num will stand for (5 + num) parameter.

Definition at line 958 of file TFormula.cxx.

◆ HandleParamRanges()

void TFormula::HandleParamRanges ( TString formula)
private

Handling parameter ranges, in the form of [1..5].

Definition at line 1173 of file TFormula.cxx.

◆ HandlePolN()

void TFormula::HandlePolN ( TString formula)
private

Handling polN If before 'pol' exist any name, this name will be treated as variable used in polynomial eg.

varpol2(5) will be replaced with: [5] + [6]*var + [7]*var^2 Empty name is treated like variable x.

Definition at line 857 of file TFormula.cxx.

◆ InitLambdaExpression()

Bool_t TFormula::InitLambdaExpression ( const char *  formula)
private

Definition at line 491 of file TFormula.cxx.

◆ InputFormulaIntoCling()

void TFormula::InputFormulaIntoCling ( )
private

pointer to the lambda function

Inputs formula, transfered to C++ code into Cling.

Definition at line 738 of file TFormula.cxx.

◆ IsAParameterName()

Bool_t TFormula::IsAParameterName ( const TString formula,
int  ipos 
)
staticprotected

Definition at line 232 of file TFormula.cxx.

◆ IsBracket()

Bool_t TFormula::IsBracket ( const char  c)
staticprotected

Definition at line 173 of file TFormula.cxx.

◆ IsDefaultVariableName()

Bool_t TFormula::IsDefaultVariableName ( const TString name)
staticprivate

Definition at line 191 of file TFormula.cxx.

◆ IsFunctionNameChar()

Bool_t TFormula::IsFunctionNameChar ( const char  c)
staticprotected

Definition at line 185 of file TFormula.cxx.

◆ IsHexadecimal()

Bool_t TFormula::IsHexadecimal ( const TString formula,
int  ipos 
)
staticprotected

Definition at line 209 of file TFormula.cxx.

◆ IsLinear()

Bool_t TFormula::IsLinear ( ) const
inline

Definition at line 203 of file TFormula.h.

◆ IsOperator()

Bool_t TFormula::IsOperator ( const char  c)
staticprotected

Definition at line 161 of file TFormula.cxx.

◆ IsScientificNotation()

Bool_t TFormula::IsScientificNotation ( const TString formula,
int  ipos 
)
staticprotected

Definition at line 197 of file TFormula.cxx.

◆ IsValid()

Bool_t TFormula::IsValid ( ) const
inline

Definition at line 201 of file TFormula.h.

◆ IsVectorized()

Bool_t TFormula::IsVectorized ( ) const
inline

Definition at line 202 of file TFormula.h.

◆ operator=()

TFormula & TFormula::operator= ( const TFormula rhs)

= operator.

Definition at line 481 of file TFormula.cxx.

◆ PrepareEvalMethod()

bool TFormula::PrepareEvalMethod ( )
private

Sets TMethodCall to function inside Cling environment.

TFormula uses it to execute function. After call, TFormula should be ready to evaluate formula.

Definition at line 685 of file TFormula.cxx.

◆ PrepareFormula()

Bool_t TFormula::PrepareFormula ( TString formula)
protected

prepare the formula to be executed normally is called with fFormula

Definition at line 1659 of file TFormula.cxx.

◆ PreProcessFormula()

void TFormula::PreProcessFormula ( TString formula)
protected

Preprocessing of formula Replace all ** by ^, and removes spaces.

Handle also parametrized functions like polN,gaus,expo,landau and exponentiation. Similar functionality should be added here.

Definition at line 1637 of file TFormula.cxx.

◆ Print()

void TFormula::Print ( Option_t option = "") const
virtual

Print the formula and its attributes.

Reimplemented from TNamed.

Definition at line 3262 of file TFormula.cxx.

◆ ProcessFormula()

void TFormula::ProcessFormula ( TString formula)
protected

Iterates through functors in fFuncs and performs the appropriate action.

If functor has 0 arguments (has only name) can be:

  • variable
    • will be replaced with x[num], where x is an array containing value of this variable under num.
  • pre-defined formula
    • will be replaced with formulas body
  • constant
    • will be replaced with constant value
  • parameter
    • will be replaced with p[num], where p is an array containing value of this parameter under num. If has arguments it can be :
  • function shortcut, eg. sin
    • will be replaced with fullname of function, eg. sin -> TMath::Sin
  • function from cling environment, eg. TMath::BreitWigner(x,y,z)
    • first check if function exists, and has same number of arguments, then accept it and set as found. If all functors after iteration are matched with corresponding action, it inputs C++ code of formula into cling, and sets flag that formula is ready to evaluate.

Definition at line 1940 of file TFormula.cxx.

◆ ReplaceAllNames()

void TFormula::ReplaceAllNames ( TString formula,
std::map< TString, TString > &  substitutions 
)
private

Definition at line 286 of file TFormula.cxx.

◆ ReplaceParamName()

void TFormula::ReplaceParamName ( TString formula,
const TString oldname,
const TString name 
)
protected

Replace in Formula expression the parameter name.

Definition at line 2906 of file TFormula.cxx.

◆ SetName()

void TFormula::SetName ( const char *  name)
virtual

Set the name of the formula.

We need to allow the list of function to properly handle the hashes.

Reimplemented from TNamed.

Definition at line 2476 of file TFormula.cxx.

◆ SetParameter() [1/2]

void TFormula::SetParameter ( const char *  name,
Double_t  value 
)

Sets parameter value.

Definition at line 2729 of file TFormula.cxx.

◆ SetParameter() [2/2]

void TFormula::SetParameter ( Int_t  param,
Double_t  value 
)

Set a parameter given a parameter index The parameter index is by default the alphabetic order given to the parameters apart if the users has defined explicitly the parameter names.

Definition at line 2837 of file TFormula.cxx.

◆ SetParameters() [1/2]

void TFormula::SetParameters ( const Double_t params)

Set a vector of parameters value.

Order in the vector is by default the alphabetic order given to the parameters apart if the users has defined explicitly the parameter names

Definition at line 2806 of file TFormula.cxx.

◆ SetParameters() [2/2]

void TFormula::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 
)

Set a list of parameters.

The order is by default the alphabetic order given to the parameters apart if the users has defined explicitly the parameter names

Definition at line 2816 of file TFormula.cxx.

◆ SetParName()

void TFormula::SetParName ( Int_t  ipar,
const char *  name 
)

Definition at line 2876 of file TFormula.cxx.

◆ SetParNames()

void TFormula::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" 
)

Definition at line 2847 of file TFormula.cxx.

◆ SetPredefinedParamNames()

void TFormula::SetPredefinedParamNames ( )
protected

Set parameter names only in case of pre-defined functions.

Definition at line 2317 of file TFormula.cxx.

◆ SetVariable()

void TFormula::SetVariable ( const TString name,
Double_t  value 
)

Sets variable value.

Definition at line 2564 of file TFormula.cxx.

◆ SetVariables()

void TFormula::SetVariables ( const std::pair< TString, Double_t > *  vars,
const Int_t  size 
)

Sets multiple variables.

First argument is an array of pairs<TString,Double>, where first argument is name of variable, second argument represents value. size - number of variables passed in first argument

Definition at line 2505 of file TFormula.cxx.

◆ SetVectorized()

void TFormula::SetVectorized ( Bool_t  vectorized)

Definition at line 2932 of file TFormula.cxx.

Member Data Documentation

◆ fAllParametersSetted

Bool_t TFormula::fAllParametersSetted
private

transient to force re-initialization

Definition at line 94 of file TFormula.h.

◆ fClingInitialized

Bool_t TFormula::fClingInitialized
private

trasient to force initialization

Definition at line 93 of file TFormula.h.

◆ fClingInput

TString TFormula::fClingInput
private

Definition at line 89 of file TFormula.h.

◆ fClingName

TString TFormula::fClingName
private

pointer to methodcall

Definition at line 96 of file TFormula.h.

◆ fClingParameters

std::vector<Double_t> TFormula::fClingParameters
private

cached variables

Definition at line 91 of file TFormula.h.

◆ fClingVariables

std::vector<Double_t> TFormula::fClingVariables
private

input function passed to Cling

Definition at line 90 of file TFormula.h.

◆ fConsts

std::map<TString,Double_t> TFormula::fConsts
protected

Definition at line 121 of file TFormula.h.

◆ fFormula

TString TFormula::fFormula
protected

Definition at line 123 of file TFormula.h.

◆ fFuncPtr

TInterpreter::CallFuncIFacePtr_t::Generic_t TFormula::fFuncPtr
private

unique name passed to Cling to define the function ( double clingName(double*x, double*p) )

Definition at line 98 of file TFormula.h.

◆ fFuncs

std::list<TFormulaFunction> TFormula::fFuncs
protected

Definition at line 118 of file TFormula.h.

◆ fFunctionsShortcuts

std::map<TString,TString> TFormula::fFunctionsShortcuts
protected

Definition at line 122 of file TFormula.h.

◆ fLambdaPtr

void* TFormula::fLambdaPtr
private

function pointer

Definition at line 99 of file TFormula.h.

◆ fLinearParts

std::vector<TObject*> TFormula::fLinearParts
protected

Definition at line 127 of file TFormula.h.

◆ fMethod

TMethodCall* TFormula::fMethod
private

Definition at line 95 of file TFormula.h.

◆ fNdim

Int_t TFormula::fNdim
protected

Definition at line 124 of file TFormula.h.

◆ fNpar

Int_t TFormula::fNpar
protected

Definition at line 125 of file TFormula.h.

◆ fNumber

Int_t TFormula::fNumber
protected

Definition at line 126 of file TFormula.h.

◆ fParams

std::map<TString,Int_t,TFormulaParamOrder> TFormula::fParams
protected

list of variable names

Definition at line 120 of file TFormula.h.

◆ fReadyToExecute

Bool_t TFormula::fReadyToExecute
private

Definition at line 92 of file TFormula.h.

◆ fVars

std::map<TString,TFormulaVariable> TFormula::fVars
protected

Definition at line 119 of file TFormula.h.

◆ fVectorized

Bool_t TFormula::fVectorized = false
protected

Definition at line 128 of file TFormula.h.

Libraries for TFormula:
[legend]

The documentation for this class was generated from the following files: