Using C functions with histogram arguments in Tree.Draw()

Hello PyROOT experts,
I am trying to apply a functional weight in a Tree.Draw() command. Ideally, it would take as input two branches in the tree as well as a 2D “lookup” histogram found in a different root file which stores the weights. The function would return the bin content of the bin in the 2D histogram corresponding to where the first two inputs land. However, I can’t figure out how to get Tree.Draw() to recognize the name of the lookup histogram. My first instinct is to try something like this:

import ROOT as R

R.gROOT.ProcessLine('.L CFunc.C+')

tree_file = R.TFile('TTbar_FullHad.root','READ')
tree = tree_file.Get('ljmet')

lookup_file = R.TFile('lookup_hist_el.root','READ')
lookup_hist = lookup_file.Get('PFjet0_pt_nB1p_el__DATA')
lookup_hist.SetName('lookup')
lookup_hist.SetTitle('lookup')

hist = R.TH1D('PlotHist','PlotHist',50,0,500)

print tree.Draw('isTTBB_ChargedHiggsCalc >> PlotHist', '','GOFF')
print tree.Draw('isTTBB_ChargedHiggsCalc >> PlotHist', 'CFunc(lookup)','GOFF')

Where CFunc.C contains something like:

#include "TH2D.h"

double CFunc(TH2D hist){
    return 1.0;
}

…It doesn’t matter what is in the function, I always get back the error:

805
Error in <TTreeFormula::Compile>:  Bad numerical expression : "CFunc(lookup)"
-1

(I can provide these files if need be)

I interpret this as the Tree.Draw() command not being aware of the defined lookup histogram (if I take the histogram out of the function it works fine). So, I guess my question is: Is this even possible? and if so, how do I get the weight string to recognize the histogram as one of the arguments?

Thanks,
Alex

Alex,

sorry I don’t have time to look into this in detail at this point, but this:double CFunc(TH2D hist)struck me as definitely wrong. Any expected callback interface would take a “TH2D*” or “TH2D&” (the former being the most likely).

Cheers,
Wim