New TFormula class

Download Report

Transcript New TFormula class

Google Summer of Code 2013 project.
By Maciej Zimnoch (Mentor Lorenzo Moneta)
* Handle complex formulas without restrictions
on function dimension
* Keep old functionality and provide easy way to
add next ones
* Use Cling
* Keep code clean and flexible, easy to maintain
* Provide test suits
*
* Unlimited number of formula dimensions
* Parameters
* Constants
* Parametrized functions
* Linear functions
* Exponentiation
* Polynomial generator
* Fast evaluation
*
New parameters can have string names or be
like old ones just numbers.
Variables are not limited to 4 : x, y, z and t.
User can specify unlimited number of variables
and parameters, use hard-coded constants (such
as pi, e, ln10), functions shortcuts( f.e sin, cos,
floor), TMath functions and pre-defined
formulas.
*
Old TFormula could handle 3 parametrized
functions : gaus, expo and landau. Adding new
was very hard.
New TFormula handle them all, and provide an
easy way to add new ones.
Just follow few simple steps, and add ONE line
into code to have it done.
*
User can easly generate N-degree polynomial
inside formula.He’s not limited to hard-coded
variables.
my_varpol3(0) will generate polynomial of
degree three of variable my_var.
*
New TFormula is using TMethodCall to evaluate
formula.
After user define all variables, and set all
parameters that occurs in formula, class will
generate C++ code of function, which will be
used to evaluate it. After that code is passed to
Cling, and then TMethodCall is initialized and
used.
*
root[]: TFormula *sind = new TFormula(„sindeg”,”sin(var*TMath::DegToRad())”);
root[]: TFormula *example = new TFormula(„ex” „x*sindeg – (vargausn(0)^2)/[p]”);
root[]: Double_t params[] = { 1,2,3};
root[]: example->SetParameters(params,3);
root[]: example->SetParameter(„p”,2); //parameters can have string names
root[]: example->AddVariable(„var”,4); // var = 4
root[]: example->Eval(5,6) // x = 5, y = 6
(Double_t) -8.374594e-01
Extended example formula:
sin(var*TMath::DegToRad())–(([0]*exp(-0.5*((var-[1])/[2])^2)/(sqrt(2*pi)*[2])))^2)/[p]
*
Test suit contains unit tests and stress test.
Benchmark result for 1000-dimension formula, with 5000 parameters:
* Initialization part:
* Real Time =
3.61 seconds Cpu Time = 3.60 seconds
* Defining variables :
* Real Time = 17.62 seconds Cpu Time =
* Why so slow? Next slide
17.62 seconds
* Setting parameters :
* Real Time =
0.01 seconds Cpu Time = 0.01 seconds
* 10000 Evaluations :
* Real Time = 5.15 seconds Cpu Time =
* Why so slow? (TMethodCall)
*
5.14 seconds
After user add variable, function inside TFormula is
searching for every occurance of variable name inside
formula to replace it with reference to it’s value.
Formula in this test has over 55 000 length, that’s
why it take so much time.
Optimalization is in progress.
*
More natural example : 100 variables, 500 parameters:
* Initialization
* : Real Time =
0.04 seconds Cpu Time = 0.05 seconds
* Defining variables
* : Real Time =
0.20 seconds Cpu Time = 0.18 seconds
* Setting parameters
* : Real Time =
0.00 seconds Cpu Time = 0.01 seconds
* 10000 Evaluations
* : Real Time =
*
3.21 seconds Cpu Time = 3.21 seconds
* Initialization speed with complex formula
* Old TFormula:
* Real Time = 19.60 seconds Cpu Time = 19.60 seconds
* New TFormula:
* Real Time = 0.07 seconds Cpu Time = 0.08 seconds
*
* Full compatibility with old TFormula.
* Version implemented in C++98 and C++11
standard. Now it uses the newer one.
* Integrate it with ROOT by replacing old code
with new one.
* Optimalizations.
*
Mail/skype:[email protected]
*