RDataFrame handling branches with different leaf names, seg. violation (6.16.00)

Hi,

I have a TTree with a branch name which is different from the variable name:

*Br   22 :Tag       : fTag/I

When I read in the file and create an RDataFrame, listing the column names,

 ROOT::RDataFrame df(TreeName.c_str(), (MyPath + FilePattern).c_str());
 std::vector<std::string> colNames = df.GetColumnNames();
  for(int i = 0; i < colNames.size(); i++){
    std::cout << colNames[i] << std::endl;
  }

I can see it showing up as Tag.fTag, but when trying to use it in a Filter:

  auto myLYHisto = df.Filter("Tag.fTag > 1").Histo1D(...);

I get a segmentation violation:

Tag.fTag
bdtDiscr
Total number of events: 1598010
Error in <TTreeCache::AddBranch>: unknown branch -> Tag.fTag
Error in <TBranchProxy::Read>: Unable to initialize Tag.fTag


 *** Break *** segmentation violation
Error in <TTreeCache::AddBranch>: unknown branch -> Tag.fTag
Error in <TBranchProxy::Read>: Unable to initialize Tag.fTag
...

Any ideas?

Thanks,
Balint


_ROOT Version: 6.16.00
_Platform: Mac OS 10.14.3
Compiler: Not Provided


Hi,
looks like a bug on our part.
Does either Tag or fTag work?

And: could you share even just one event of that TTree so we can add it as a test?

Cheers,
Enrico

Hi,
thanks a lot for taking a look. Please find a few events attached.
For fTag I get this error:

input_line_73:1:46: error: use of undeclared identifier 'fTag'
namespace __tdf_0{ auto tdf_f = []() {return fTag > 1
                                             ^
Error in <TRint::HandleTermInput()>: std::runtime_error caught: Cannot interpret the following expression:
fTag > 1

Make sure it is valid C++.

while for Tag I get the same.

Cheers,
Balint
test.root (13.8 KB)

Hi Balint,

thanks for reporting and for the reproducer. We have opened a JIRA item dedicated to this issue: https://sft.its.cern.ch/jira/browse/ROOT-10046

Cheers,
Danilo

Hi,
thank you for the file. I can reproduce the problem, and this is now jira ticket 10046. You can follow the development there.

As a partial workaround, at least if you don’t enable multi-threading with EnableImplicitMT(), you can read that branch if you construct the RDataFrame by passing the TTree object directly:

TFile f("test.root");
TTree *tree = nullptr;
f.GetObject("miniTree", tree);
RDataFrame df(*miniTree);
auto myLYHisto = df.Filter("Tag.fTag > 1").Histo1D(...);

Please ping us on the jira ticket page if you don’t see any progress on the bug in the next 2/3 weeks and it’s a blocker for you.
Cheers,
Enrico

Another quick update.
The branch can be read with TTreeReader, narrowing down the issue…

   TFile f("file.root");
   TTreeReader r("miniTree", &f);
   TTreeReaderValue<int> rv(r, "Tag.fTag");

   while (r.Next()) {
      cout << *rv << endl;
   }

Cheers,
D

Hi Enrico and Danilo,

thanks a lot for creating a jira ticket and taking a look at the issue.
In the meantime I have used the temporary workaround suggested by Enrico, and the following works:


  TFile f("test.root");
  TTree *tree = nullptr;
  f.GetObject("miniTree", tree);

  ROOT::RDataFrame df(*tree, {"Tag.fTag"});
  std::vector<std::string> colNames = df.GetColumnNames();
  for(int i = 0; i < colNames.size(); i++){
    std::cout << colNames[i] << std::endl;
  }
  
  // Cut
  auto cutb1 = [](int tag) { return tag == 1; };
  
  // Get number of events:
  auto c_totevents = df.Count();
  std::cout << "Total number of events: " << *c_totevents << std::endl;
  
  //---------------------------------------------------
  auto c1 = new TCanvas("c1", "c1", 100, 100, 800, 600);
  auto myCut = df.Filter(cutb1, "Tag.fTag");
  auto myCutCount = df.Filter(cutb1, "Tag.fTag").Count();
  auto myVec = myCut.Take<int>();
  std::cout << "N of entries: " << *myCutCount << std::endl;
  std::cout << "Selected entries" << std::endl;
  for (auto my_entry : *myVec)
    std::cout << my_entry << " ";
  std::cout << std::endl; 

But if in addition, I want to make a Hist1D out of another variable, using the cut
on this Tag.fTag, then it crashes again, or creates empty histo…

auto myLYHisto = df.Filter("Tag.fTag == 1").Histo1D("LYTotal");
myLYHisto->DrawClone();

Unless I am doing something wrong…

Thanks,
Balint

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