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