TTree::Draw and functions

I have found that in the interactive mode of root I can perform the following:

.L somefunction.cc
somefunction(5,4)
1
MyTree.Draw(“somefunction(x,y)”)

i.e somefunction() returns the difference of its two arguments and I have a TTree called MyTree which contains two branches called ‘x’ and ‘y’. By executing the TTree::Draw() command as I did above, a histogram will be produced of the difference (or whatever I write somefunction() to do) of x and y for each entry. What are the limitations of this feature? I tried doing something similar where I pass a pointer to an array of floats to somefunction() but I receive a segmentation fault. A clear indication of what is and is not possible would be greatly appreciated. Thanks in advance.

Max Atkin

Hi,

The functions used by TTree::Draw have to take simple numerical arguments and return simple numerical arguments. I.e. only int, floats, double, etc. and no array or objects.

To use function works on arrays, you should use the new TTree Proxy mechanism released in ROOT 4.00/08 where you can run a function in context where the branchname can be used as variables.

Cheers,
Philippe.

Hi,

But is it possible to use to MakeProxy mechanism in the selection variable of TTree::Draw() (as it was in PAW)? For example,
MyTree.Draw(“somefunc.C++”,“func1.C++<a && func2.C++>b”), where a and b are numbers.

If not is there any ROOT analog of such a mechanism in PAW which allows to use automatic histogram creating (like Draw(), in contrast with MakeClass) with user defined function of Ntuple variables (such as arrays) in varexp and selection?

Hi,

You can use:MyTree.Draw("somefunc.C+","somesel.C+");(+ vs ++ to avoid unnecessary recompilation).

Currently you can not pass argument to the generated code from inside the Draw command itself. However an alternative is to use something like:[code]// file somefunc.C
double a;
double b;
double func1() {

}
double func2() {

}
void somefunc() {
if (func1()<a && func2()>b) {
double value = …;
htemp->Fill(value);
}
}[/code]
and use with:MyTree->MakeProxy("sel","somefunc.C","","nohist"); gROOT->ProcessLine(".L sel.h+"); sel *mysel = new sel(); sel->a = val1; sel->b = val2; MyTree->Process(mysel);

Cheers,
Philippe.

Thank you very much.

Alexander.

Hi, I have a somewhat similar question. I’m working with a tree whose branches are collection.

I’m trying to do something like:
tree->Draw(“Cone4H1TowerJets.pt()”, “f(Cone4H1TowerJets)>0”);

I get different root reactions, depending on the way f is defined:

  1. double f(const JetCollection *jets)
    Error in TTreeFormula::Compile: Bad numerical expression :
    “f(Cone4H1TowerJets)”

if I use @Cone4H1TowerJets in the selection argument of Draw:
Error in TTreeFormula::Compile: Bad numerical expression :
“f(@Cone4H1TowerJets)”

same thing without the const.

  1. double f(JetCollection jets)
    no errors, but inside f, jets.size() is always 0
    same thing with const.
    same thing with @

  2. double f( JetCollection &jets)
    segmentation fault
    same thing with const
    same thing with @

I was also trying to use MakeProxy, but I get punched in the face:

root [1] tree->MakeProxy(“proxytest01”, “somefunc.C”, “”, “nohist”);
Fatal in ROOT::TBranchProxyClassDescriptor:: strcmp(fInfo->GetName(), type)==0 violated at line 117 of `treeplayer/src/TBranchProxyClassDescriptor.cxx’
aborting
… … …

root version is 5.18/00a btw.
Thanks,
Raz

Hi,

TTree::Draw can not pass object to a function, it can only pass numerical values. [I.e. all three of your example should have failed with a nice warnign message :frowning:]

root [1] tree->MakeProxy("proxytest01", "somefunc.C", "", "nohist"); Fatal in <ROOT::TBranchProxyClassDescriptor::>: strcmp(fInfo->GetName(), type)==0 violated at line 117 of `treeplayer/src/TBranchProxyClassDescriptor.cxx' Humm … this seems to indicate an issue with the ROOT type system, it is missing some information about your classes! Could you send me your ROOT file so that I can try to reproduce this problem?

Thanks,
Philippe.

Thanks Philippe.

I attached my

test.py - in which are the dpd’s I’m trying to use. On of the files there is from castor so I guess you can use it.

load.cxx - the file I use to load the tree

somefunc.C - the file I tried to use with MakeProxy

(everything is in /afs/cern.ch/user/r/raza/scratch0/athena/14.1.0.3)

Thanks again,
Raz
somefunc.C (51 Bytes)
load.cxx (598 Bytes)
test.py (2.43 KB)