Effficiency: TF1 vs directly evaluating a polynomial?

Hi everyone,

Use case:
1.) Reading entries (double) from a TTRee Reader, xi.
2.) Transforming the entries as
-Using TF1

TF1* f = new TF1("pol2");
f->SetParameters(a0, b0, c0);
double yi = f->Eval(xi);

-directly evaluating the polynmial

yi = a0 + b0*xi + c0*xi*xi;

I have a trivial query for a ‘large’ number of operations, is there any significant difference in computational times for the two cases - using TF1 vs direct evaluation?
Further, is any one is aware of more ‘efficient’ ways of doing this, please share them, it will be highly helpful.
Thanks a lot !


The evaluation of the TF1 does not have a significant overhead wrt the evaluation of the parabola directly in C++, provided that you set the value of the parameters and not re-create an instance per entry.

Something which can be more efficient, but perhaps not so useful depending on the context, is to extract the columns from the datasets with RDataFrame and combine them in a vectorised fashion with VecOps (see this tutorial).


1 Like

Thanks for the information.

I’ll try understanding VecOps, thank you for the relevant link.

1 Like

Hi @Danilo ,
I followed the tutorial and think RVecOps() may be a good substitute for the case at hand,
1.)Reading a TTree having different branches (energy, time, hit_info etc) using

TTreeReader ReaderName()

2.) Each TTree entry corresponds to one “event.”

3.) Based on certain conditions(multiplicity, detector id, etc) on the branches, I am trying extracting data(energy) from other branches and transforming the energy using a pol2.

I am thinking of using RVecOps here however I am not sure how to substitute a TTreeReader with RVecOps?
Most probably this is a naive query but I am a complete beginner to RVecOps and vector operations in general, so any assistance will be highly valued. ?

PS: I understand that I am digressing from the original title of the thread and just put this up here for continuity.
Thanks a lot for the help!


I think the best way, if you want to go for the vectorized approach, is to use RDataFrame and not TTreeReader, as mentioned above.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.