Performance of TTree::Draw with a function

Hi,
recently I noticed some nasty performance troubles in the TTree::Draw() method. If you draw the result of a user-defined function with

mytree->Draw("myFunc(treevar)")

the Draw method is about 100 times slower than usually, even if the function myFunc is complied with aclic.
The attached code illustrates the problem:

  • 200000 calls of the function addone(i) takes almost no time.
  • to Draw a variable of a tree with 200000 entries takes 0.12 seconds on my PC
  • to draw tree->Draw(“addone(counter)”) takes more than 10 seconds.

I am using ROOT 5/22.
Is there a way to speed up Drawing the result of a user defined function or am I doing something wrong?

Cheers, J.
testit.C (919 Bytes)

I’m just a user, so hopefully somebody real will respond, but…

When you use a function, it doesn’t know which branches it needs so it loads the whole object. If you just draw one (or N) member data, it only loads those pieces. So, as far as I know, we’re stuck…

Cheers,
Charles

p.s. It would be kind of cool if we could tell root/rootcint/reflex this member function only uses these data…

Hi,

Inmytree->Draw("myFunc(treevar)") we use CINT to execute the function. Relatively speaking this is a slow operation and explain the factor 100. To regain the performance, we recommand that the syntaxmytree->Draw("myscript.C+");[code]with myscript.h being [code]#include "myFunc.h" and myscript.C being double myscript() { return myFunc(treevar); }. (See TTree::Draw documentation for more details).

Cheers,
Philippe.

Hi,

Please note that revision 29623 reduce dramatically the cost TTreeDraw of calling function via CINT.

Cheers,
Philippe

This is good to hear, because

cannot be the complete answer to this performance hit, as you can see, if you run my testcase in the interpreted mode. Calling 200000 the testcase function in CINT mode takes not more than 0.3 seconds on my PC, while calling the function in question via TTree::Draw takes 10 second for 200000 calls.

Because of this I am more than glad to see performance improvements in the TTree::Draw implementation. Using TTree::Draw with a script file to speed up the Draw method helps to regain the performance, but requires to handle three source code files instead of only one. This is no issue, if you are working on a ROOT project with several source files, but for small “quick-and-dirty”-scripts this is quite annoying.

Cheers, J.

Hi,

With the change I made, the performance of the calling the function via TTree::Draw is on par with calling it directly from the interpreter :slight_smile::slight_smile:

Cheers,
Philippe.