Formula Expressions
The ability to calculate inline formulas is another useful feature. The underlying implementation of the formula processor relies on two external libraries. First, formulas are interpreted with the TinyExpr parser. This is a very fast implementation that works for most simple expressions. If parsing fails, the formula is interpreted by the ROOT TFormula class, which is slower but more versatile. To the user, the switching between both parsers is completely transparent and no extra steps have to be taken.
In order to active the formula mode, the relevant expression must be enclosed in curly braces {...}
. Variables may
also be used within a formula, and all variable replacements will be done before the formula parsing (meaning that
the current value of the variable will be used in the formula.) An example of the formula syntax is given in the
following variable definition:
<define name="my_variable" value="4.0"/>
<define name="length" value="{2.3 + 2.0/sqrt([my_variable])}"/>
<print name="length" value="[length]"/>
This example results in the variable length
taking the value of 3.3.
Note that this example uses a standard function sqrt(x)
that is supported by TinyExpr. In general, any formulas
using advanced TMath functions or other complex syntax will use the TFormula parser. Simple TMath functions like
TMath::Sqrt(x)
or TMath::Sin(x)
are mapped to their equivalent standard function (sqrt(x)
, sin(x)
) that is
natively understood by TinyExpr. The standard functions (and mathematical constants) are listed in the table below.
Standard functions and constants 


XML syntax 
C++ function 
ROOT equivalent 
Description 



Compute absolute value. 



Compute arc cosine. 



Compute arc sine. 



Compute arc tangent. 



Compute arc tangent with two parameters. 



Round up value. 



Compute cosine. 



Compute hyperbolic cosine. 



Compute exponential function. 


Compute factorial. 




Round down value. 



Compute natural logarithm. 


Compute common logarithm. 




Compute common logarithm. 


Compute combinations of n over r. 


Compute permuations of n over r. 




Raise to power. 



Compute sine. 



Compute hyperbolic sine. 



Compute square root. 



Compute tangent. 



Compute hyperbolic tangent. 


Fundamental constant. 




Fundamental constant. 