How to reset the kEntriesReshuffled bin in pyroot?

Hello,

I processed an ntuple with RDataFrame and now my ntuple has the bin kEntriesReshuffled set. From the documentation of RDataFrame, I understood that I can reset this bin with : ResetBit(EStatusBits::kEntriesReshuffled)
if I know what I’m doing. Well, I sorted my Friend tree such that the entries match so I believe it should be ok.
However, I’m using pyroot, and I don’t manage to reset this bin since the command given in the documentation is for c++. Do you know how to translate that command to python ?

Thanks a lot for your help.

Hi @Emix,
does this do the trick?

tree.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)

Cheers,
Enrico

Hi Enrico,

Thanks for your quick reply ! The code accepts this command but it does not seem to have any effect. I still get the following error message :
Error in : Tree ‘DecayTree’ has the kEntriesReshuffled bit set, and cannot be used as friend nor can be added as a friend unless the main tree has a TTreeIndex on the friend tree ‘sweights’. You can also unset the bit manually if you know what you are doing.

Cheers

Hi,
I cannot reproduce the issue with ROOT v6.22:

import ROOT

ROOT.EnableImplicitMT()
ROOT.RDataFrame(10).Define("x", "42").Snapshot("t", "f.root")

f = ROOT.TFile("f.root")
t = f.Get("t")
print(t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))
t.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
print(t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))

t = ROOT.TTree("t2", "t2")                                                           
t.AddFriend(t)

prints

True
False

i.e. the bit is correctly reset, and AddFriend does not error out.

What am I doing differently?
Cheers,
Enrico

Ok, that’s very interesting. So there are two things and btw I’m also on ROOT v6.22.
First, I was using a TChain to load my ntuple and if I check the value of the bit it’s already “False”. I modified a bit your example to reproduce this. So this might be a bug in TChain.
Second, if I load the ntuple with TFile and TTree and reset the bin correclty, I can add the Friend tree. However, if I load the ntuple with the friendtree in a RDataFrame, as it is suggested in the documentation, I get again the error message :

Error in : Tree ‘t’ has the kEntriesReshuffled bit set, and cannot be used as friend nor can be added as a friend unless the main tree has a TTreeIndex on the friend tree ‘t2’. You can also unset the bit manually if you know what you are doing.

So this might be a bug in RDataFrame. I also modified a bit your example to reproduce this.

import ROOT

ROOT.EnableImplicitMT()
ROOT.RDataFrame(10).Define("x", "42").Snapshot("t", "f.root")

chain = ROOT.TChain("t")
chain.Add("f.root")
print(chain.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))

f = ROOT.TFile("f.root")
t = f.Get("t")
print(t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))
t.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
print(t.TestBit(ROOT.TTree.EStatusBits.kEntriesReshuffled))

ROOT.RDataFrame(10).Define("y", "43").Snapshot("t2", "f2.root")
f2 = ROOT.TFile("f2.root")
t2 = f2.Get("t2")
t2.ResetBit(ROOT.TTree.EStatusBits.kEntriesReshuffled)
t.AddFriend(t2)

rdf = ROOT.RDataFrame(t)
h = rdf.Histo1D("x")
h.Draw()

The TChain output is misleading because it’s telling you what the bit value is for the TChain object itself, not for the underlying TTrees which it will load as it runs over entries.

The last three lines are also tricky. If you add a ROOT.DisableImplicitMT() in front, things are fine.
The reason is similar to what happens with TChain: the tree/friend pair that is actually processed is actually different in each thread and the trees are re-read from file.

A possible solution is to change the value of the bit on disk.

Oh ok, I understand. That is quite tricky indeed. But then your first answer was indeed the solution to my problem. Thanks a lot !

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