I am trying to use TTreeReader with TChain in a macro as a practice.
I got the following warning when running the macro.
Warning in <TTreeReader::SetEntryBase()>: The current tree in the TChain Nominal has changed (e.g. by TTree::Process) even though TTreeReader::SetEntry() was called, which switched the tree again. Did you mean to call TTreeReader::SetLocalEntry()?
Should I be concerned about this warning?
The portion of my code for using the TChain with the reader.
TChain *tc = new TChain("Nominal");
tc->Add("/afs/cern.ch/work/j/jzeng/public/VBS_test/data/ttbar-*.root");
printf("%d;\n",tc->GetNtrees());
printf("%lld;\n",tc->GetEntries());
TTreeReader myReaderArr(tc);
TTreeReaderValue<float> met(myReaderArr, "met");
TTreeReaderValue<float> weight(myReaderArr, "weight");
while (myReaderArr.Next()) {
if ( *met > met_min ) {
h1 ->Fill(*met,*weight);
}
}
Is there anything I need to add to avoid the warning?
Any feedback is welcome.
Hi,
the warning is due to your GetNtrees and GetEntries calls changing the “current tree” of the TChain, and TTreeReader is trying to tell you that it had to re-switch the tree to the first one in the chain to start the event loop. Can you confirm that removing those two calls the warning is not printed?
If this is the case, one thing you can do to avoid the warning is calling tc->SetEntry(0) before passing it to the TTreeReader. @Axel maybe has a more elegant solution.