[quote] and if it was possible to add my own C++ functions. [/quote]Yes
This is one of the fundamental feature of ROOT, via the generation of dictionaries, ROOT can provide access to (almost) all C++ classes and function to an interpreter (CINT, pyroot, TTreeFormula).
The simpliest way of generating a dictionary (see User’s Guide for more complex example) is to use ACLiC. For example with a file myfunc.C simply do:root [] .L myfunc.C+orgROOT->ProcessLine(".L myfunc.C+") or if you function already exist in a shared library and you have an header file (myfunc.h) do:root [] gSystem->Load("mylib.so");
root [] .L myfunc.h+orgROOT->ProcessLine(".L myfunc.h+")
The problem is, even if I make GetHistWeight do nothing (return 1), it is horrendously slow. So I have given up on this idea and instead loop over the events myself - it runs many thousands of times faster. I suppose this is intrinsic ? Is there any good way to do this?
TTreeFormula has not (yet) been upgraded to taken advantage of the better formula compilation implemented for TFormula (and using TFormulaPrimitive).
However TTreeFormula can directly call any static or global function (i.e For example TFastFun::Pow2). i.e. you can do:tree->Draw("TFastFun::Pow2(myvar)");
This is extremely slow. Is there any other way short of calling it myself? I’d really like to use a TTreeFormula, it would be so convenient. In particular I want to compile functions in C++ which are generated at runtime, and then evaluate them as part of a TTreeFormula expression.
As a basic example, something that takes ~5 seconds to do in a TTree::Draw() expression for ~5 million events takes >140 seconds when done in a TTree::Draw(“MyExternalFunction(a,b)”).