TTree::Draw(myfunction.C+ >> histogram)?

Hi,

I’m trying to use TTree::Draw on a simple user function, and then dump this in a predefined histogram. Here’s my simple test case:

mass2.C

double mass2() {
   return my_mass_branch*my_mass_branch;
}

test.py

import ROOT
tc = ROOT.TChain('chain')
tc.Add('my_ttree_file.root')
tc.Draw('mass2.C+')

So for me, this works just fine. But what if I want to store the result in a histogram, like

import ROOT
tc = ROOT.TChain('chain')
tc.Add('my_ttree_file.root')
h = ROOT.TH1F('my_hist', 'mass2', 100, 0, 400)
tc.Draw('mass2.C+ >> my_hist')

This doesn’t work, but I guess you get what I am trying to do. When I try this, I get:

Error in <TTreeFormula::Compile>:  Invalid Syntax "+"

Is there any special syntax to handle this case, or should I proceed in a completely different way?

Hi, I do not the Python environment. Anyway, I guess you should use Project instead of Draw. For example, you should write