Alheana
Alheana

Reputation: 159

ROOT - pyroot: Branch seen as leaf, can't access actual leaves

I am trying to extract information from a root file using pyroot. I tried using the usual GetBranch, GetLeaf, GetValue but it does not work as usual, so I tried alternatives.

I found an equivalent code in c++ which is extracting the values just fine from my ROOT file but when applying the same thing in pyroot, I get an empty object as my "mcinfo" (see below). I also tried displaying the branches and leaves with GetListOfBranches() and GetListOfLeaves(). I get the proper list of branches with the first but when looking at the list of leaves (here MC but it's the same with all branches), I get out of MC.GetListOfLeaves() that the only leaf is MC too... I have several leaves (for instance energy) that I can access just fine with the c++ code and directly with data.Scan("energy") too...

Anyone has an idea of how to fix this? Sorry, I am not that familiar with ROOT yet. I assume it is a rather easy fix, but I don't see what is wrong with this...

C++ code:

TFile *file = new TFile(fname);
TTree *data = (TTree*)file->Get("data");
TBranch * McinfoBranch;
MCInfo* mcinfo = (MCInfo*)file->GetList()->FindObject("MC");
data->SetBranchAddress("MC", &mcinfo, &McinfoBranch);

pyroot version:

infile = ROOT.TFile(fname)
data = infile.Get("data")
mcinfo = infile.GetList().FindObject("MC")

which gives me this when printing mcinfo: <cppyy.gbl.TObject object at 0x(nil)>.

Upvotes: 1

Views: 162

Answers (0)

Related Questions