Opening TClonesArray from Delphes Branches with RDataFrame

Hi all,

I’m trying to open a TTree created by Delphes with RDataFrames, remove events based on some cut and then write the events that pass the cut into a new TTree with the same format as the previous one.

The relevant part of the code is

#include <algorithm>

#include "classes/DelphesClasses.h"
#include <ROOT/RDataFrame.hxx>
#include <ROOT/RSnapshotOptions.hxx>
#include <TFile.h>
  auto low = ROOT::RDataFrame("Delphes", "inputfile.root")
    .Define("TruthLeptonPt", TruthLeptonPt, {"GenElectron", "GenMuon"})
    .Filter("TruthLeptonPt.size() >= 2")
    .Filter("TruthLeptonPt.at(1) >= 100");

  low.Snapshot("Delphes", "outputfile.root", low.GetColumnNames(),
	       // {"Event", "Electron", "Muon", "Jet"}, // try explicitly, first method doesn't seem to work
	       ROOT::RDF::RSnapshotOptions("CREATE", ROOT::kZLIB, 1, 0, 99, false));

wich references a function

std::vector<double> TruthLeptonPt(std::vector<Electron> el, std::vector<Muon> mu)
{
  std::vector<double> ret;
  ret.reserve(el.size() + mu.size());

  for (const auto& e : el) {
    ret.push_back(e.PT);
  }

  for (const auto& m : mu) {
    ret.push_back(m.PT);
  }

  std::sort(ret.begin(), ret.end(),
	    [] (const double& x, const double& y) {
	      return x > y;
	    }
	    );

  return ret;
}

that is supposed to populate the branch I want to apply my cut to. I’m not quite sure whether GenParticle or Electron is the correct type, I’ve tried both with the same result. I’ve seen

When running the above code, I get copious error messages that

Error in <TTreeReaderValueBase::CreateProxy()>: The branch GenElectron contains data of type TClonesArray. It cannot be accessed by a TTreeReaderValue<vector<Electron>>

I’ve tried the obvious thing and replaced GenParticle with TClonesArray, but there the compilation fails, because a TClonesArray doesn’t have the attributes I try to access. I get no errors about the GenMuon branch though.

How does one open and manipulate Delphes output with RDataFrames?

Cheers,

jndrf


ROOT Version: 6.20/02
Platform: x86_64-centos7-gcc9-opt
Compiler: g++ 9.2


Hi @jndrf,
I think the problem is that TTreeReader, which RDataFrame uses to read ROOT files internally, needs to be taught how to deal with TClonesArray properly.

@pcanal or @Axel might be able to confirm/clarify, but I think this is ROOT-7823.

Would you be able to share a file (even with just a few events) that reproduces the issue to facilitate debugging/fixing it please?

Cheers,
Enrico

ROOT-7823 is about the case of unsplit TClonesArray. The error message talks about vector (TTreeReaderValue<vector<Electron>>) so it may be a type inference issue in RDF.

@jndrf , @pcanal is right that one thing that you could try is to use ROOT::RVec<Electron> instead of std::vector<Electron>. That should switch TTreeReaderValue<std::vector<Electron>> to TTreeReaderArray<Electron> (it might or might not help, but it’s worth a try).

Cheers,
Enrico

Good morning @eguiraud @pcanal,

thank you for the quick replies, using ROOT::VecOps::RVec<Electron> instead of std::vector<Electron> solves this problems. I now run into problems when saving the output, but I’ll make a new thread for that.

Cheers,

Jonas

1 Like

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