User Tools

Site Tools


root:ttreedraw

This is an old revision of the document!


To apply a fuction in TTree::Draw it must be known to CINT. This can be done with ProcessLineSync

This example expects that there is a TTree object named tree containing a TBranch called x.

test.py
import ROOT
ROOT.gROOT.ProcessLineSync(".x test.C+")
print ROOT.test(1) # prints 3.0 (this line works only in pyROOT and CINT, not in compiled code)
tree.Draw("x:test(x)")

It loads the following example function:

test.C
double test(double in = 0)
{
  return in*3;
}

Please note that the function is named “test” as the file name without the “.C” and has default arguments for all variables. If one of those is missing you get an error (even though it may still work).

Data structures (like histogramms) can be stored in a global pointer known to cint. These can be defined and inititalised in another call of ProcessLineSync.

h = ROOT.TH1D("myHist","",0,1,10)
ROOT.gROOT.ProcessLineSync("TH1D * myHist = (TH1D*) gDirectory.Get("myHist")")

To be used in test.C they have to be defined there as well:

test.C
TH1D * myHist = 0;
double test(double in = 0)
{
  if (!myHist)
     return 0;
  return myHist->GetBinContent(myHist->FindBin(in));
}
root/ttreedraw.1342116260.txt.gz · Last modified: 2012/07/12 20:04 by bursche