I'm using pyroot, with root v5.34/01, python v2.7.3 and gcc v4.7.2,
I'm trying to use a custom function for weights in the selection field of TTree.Draw(). My custom function is defined as a C-style root macro:
TH1F *h = 0;
double myfunction(double val = 0)
In the main program (below) I load the macro and use it in TTree.Draw(). This works fine (output reweighted.png looks fine), but (as far as I can judge) at the closing of my main function the program segfaults. My main concern is making this run cleanly, but maybe you can give me other suggestions to improve the method.
a) Why am I getting a segmentation fault and how do I solve it. Output is attached, but I don't understand where the error is coming from.
b) Is it possible to define my custom function in python, e.g. "def myfunction(): ..." syntax, in the main file? If so, how do I load it such that it is known to TTree.Draw().
Main (test) program:
f0 = ROOT.TFile("extra.root","read")
f1 = ROOT.TFile("data.root","read")
h = f0.Get("inputdir/inputhist;1")
ROOT.gROOT.ProcessLineSync('TH1F *h = (TH1F*)gDirectory->Get("h")')
canvas = ROOT.TCanvas("c","c")
t1 = f1.Get("mytree")
if __name__ == "__main__":
out.txt (6.13 KB)