Reading info from a leaf

Dear experts,

I have created a leaf in a root file to store some normalization weight using a simple python script:

chain = TChain("Delphes")
tree = chain.CloneTree(0)
wght = np.zeros(1, dtype=float)
tree.Branch('wght', wght, 'wght/D')
for ...
     ...
     tree.Fill()

Now I am trying to access this leaf using a C++ macro by typing

Double_t branchWeight = chain.GetLeaf("wght")->GetValue(0);

All I am getting is zeros. How can one access a leaf in this situation?

Thank you,
Amin

apart from this line:

wght = np.zeros(1, dtype=float)

that I’d write more explicitly as:

wght = np.zeros(1, dtype=np.float64)

this looks legit.

(NB: CloneTree(0) only copies active branches, though…)

so, probably the issue is in how you fill that wght variable…

hth,
-s

Thank you Sebastian. This is how I fill wght:

for i in xrange(nEntries):
      chain.GetEntry(i)
      wght[0] = ....some value ....
      tree.Fill()

When I open the root file and click on the leaf I can see the stored values but I cannot extract them using GetLeaf.

Best,
Amin

ok then, I think we’d need a little (as minimal as possible) script that reproduces your issue.

I was using this wrapper code ExRootTreeReader and it seems that it doesn’t work when trying to read objects that are not of array type. I fixed this now and it is working.
Thank you very much.

Best,
Amin

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.