ROOT Data Frame Tutorial; Combinations

For this ROOT tutorial on data frames as seen in this link : ROOT: tutorials/dataframe/df103_NanoAODHiggsAnalysis.C File Reference, why do I get an error with this:

ROOT::RDataFrame d(“Delphes;6”, “tag_1_delphes_events.root”);

RVec<float> PT;

RVec<float> Eta;

RVec<float> Phi;

RVec<float> m;

RVec<int> Charge;



RVec<RVec<size_t>> idx(2);

idx[0].reserve(2); idx[1].reserve(2);

auto idx_cmb = Combinations(PT, 2);

for (size_t i = 0; i < idx_cmb[0].size(); i++)

{

  const auto i1 = idx_cmb[0][i];

  const auto i2 = idx_cmb[1][i];

  

  if(Charge[i1] != Charge[i2])

  {
    ROOT::Math::PtEtaPhiMVector m1((PT)[i1], Eta[i1], Phi[i1], m[i1]);

    ROOT::Math::PtEtaPhiMVector m2((PT)[i2], Eta[i2], Phi[i2], m[i2]);

    const auto mass = (m1 + m2).M();

 }

}

The error is

Processing selectMuon.c…
Warning in TROOT::Append: Replacing existing TH1: mass (Potential memory leak).
terminate called after throwing an instance of ‘std::runtime_error’
what(): Cannot make unique combinations of size 2 from vector of size 0.

How can I fix it? Or how can I replace it? What does combinations do exactly?

Thanks

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


For Combinations see https://root.cern.ch/doc/master/namespaceROOT_1_1VecOps.html#a6d1d00c2ccb769cc48c6813dbeb132db

I see that in your code you pass an empty vector PT to the Combinations function. This is the reason of the error. You need at least a vector of size 2

Lorenzo

@moneta Thank you for your reply. It does make sense. Unfortunately, there seems to be a few issues

1. My branch names in my tree is actually Muon.PT, Muon.Phi, Muon.Eta, etc. However, when I replace PT, Phi, Eta with the actual branch names (Muon.PT, Muon.Phi, Muon.Eta) I get an error that states

root [0]
Processing selectMuon.c…
In file included from input_line_8:1:
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:68:21: error: expected ‘;’ at end of declaration
RVec Muon.PT;
^
;
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:69:17: error: redefinition of ‘Muon’
RVec Muon.Eta;
^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:68:17: note: previous definition is here
RVec Muon.PT;
^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:69:21: error: expected ‘;’ at end of declaration
RVec Muon.Eta;
^
;
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:70:17: error: redefinition of ‘Muon’
RVec Muon.Phi;
^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:68:17: note: previous definition is here
RVec Muon.PT;
^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:70:21: error: expected ‘;’ at end of declaration
RVec Muon.Phi;
^
;
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:84:33: error: no member named ‘PT’ in ‘ROOT::VecOps::RVec’
for (size_t i = 0; i < Muon.PT.size(); i++)
~~~~ ^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:97:46: error: no member named ‘PT’ in ‘ROOT::VecOps::RVec’
ROOT::Math::PtEtaPhiMVector m1((Muon.PT)[1], Muon.Eta[1], Muon.Phi[1], 0.1);
~~~~ ^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:97:59: error: no member named ‘Eta’ in ‘ROOT::VecOps::RVec’
ROOT::Math::PtEtaPhiMVector m1((Muon.PT)[1], Muon.Eta[1], Muon.Phi[1], 0.1);
~~~~ ^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:97:72: error: no member named ‘Phi’ in ‘ROOT::VecOps::RVec’
ROOT::Math::PtEtaPhiMVector m1((Muon.PT)[1], Muon.Eta[1], Muon.Phi[1], 0.1);
~~~~ ^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:98:46: error: no member named ‘PT’ in ‘ROOT::VecOps::RVec’
ROOT::Math::PtEtaPhiMVector m2((Muon.PT)[2], Muon.Eta[2], Muon.Phi[2], 0.1);
~~~~ ^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:98:59: error: no member named ‘Eta’ in ‘ROOT::VecOps::RVec’
ROOT::Math::PtEtaPhiMVector m2((Muon.PT)[2], Muon.Eta[2], Muon.Phi[2], 0.1);
~~~~ ^
/mnt/c/1/MG5_aMC_v2_6_6/triplet2s/Events/run_01/selectMuon.c:98:72: error: no member named ‘Phi’ in ‘ROOT::VecOps::RVec’
ROOT::Math::PtEtaPhiMVector m2((Muon.PT)[2], Muon.Eta[2], Muon.Phi[2], 0.1);
~~~~ ^

*** Break *** segmentation violation
Generating stack trace…
0x00007fdc29e430e4 in from /home/cucip/builddir/lib/libCling.so
0x00007fdc29e43d08 in from /home/cucip/builddir/lib/libCling.so
0x00007fdc29e47e6a in cling::DeclUnloader::VisitFunctionDecl(clang::FunctionDecl*) + 0x15a from /home/cucip/builddir/lib/libCling.so
0x00007fdc29e16d05 in cling::TransactionUnloader::unloadDeclarations(cling::Transaction*, cling::DeclUnloader&) + 0x175 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29e175a0 in cling::TransactionUnloader::RevertTransaction(cling::Transaction*) + 0x2f0 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29dfd5f5 in cling::Interpreter::unload(cling::Transaction&) + 0x235 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29e796c1 in cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraitscling::Transaction*, llvm::PointerIntPairInfo<cling::Transaction*, 2u, llvm::PointerLikeTypeTraitscling::Transaction* > >&, bool) + 0xf1 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29e79b88 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) + 0x68 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29dfaf23 in cling::Interpreter::DeclareInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions const&, cling::Transaction**) const + 0x53 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29dfd356 in cling::Interpreter::loadHeader(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Transaction**) + 0x186 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29ec5b0c in cling::MetaSema::actOnLCommand(llvm::StringRef, cling::Transaction**) + 0x15c from /home/cucip/builddir/lib/libCling.so
0x00007fdc29ec5cad in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) + 0x4d from /home/cucip/builddir/lib/libCling.so
0x00007fdc29ed6084 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x194 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29ed7476 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0xa6 from /home/cucip/builddir/lib/libCling.so
0x00007fdc29ebf64b in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x10b from /home/cucip/builddir/lib/libCling.so
0x00007fdc29d7b68e in from /home/cucip/builddir/lib/libCling.so
0x00007fdc29d8fe72 in from /home/cucip/builddir/lib/libCling.so
0x00007fdc29d84537 in from /home/cucip/builddir/lib/libCling.so
0x00007fdc2f512908 in TApplication::ExecuteFile(char const*, int*, bool) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1156 from /home/cucip/builddir/lib/libCore.so
0x00007fdc2f5120ac in TApplication::ProcessLine(char const*, bool, int*) at /home/cucip/root-6.18.04/core/base/src/TApplication.cxx:1007 from /home/cucip/builddir/lib/libCore.so
0x00007fdc2f9e18e2 in TRint::ProcessLineNr(char const*, char const*, int*) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:762 from /home/cucip/builddir/lib/libRint.so
0x00007fdc2f9e31d9 in TRint::Run(bool) at /home/cucip/root-6.18.04/core/rint/src/TRint.cxx:421 from /home/cucip/builddir/lib/libRint.so
0x00007fdc30000a0c in from /home/cucip/builddir/bin/root.exe
0x00007fdc2e971b97 in __libc_start_main + 0xe7 from /lib/x86_64-linux-gnu/libc.so.6
0x00007fdc30000a6a in _start + 0x2a from /home/cucip/builddir/bin/root.exe

2. However, if I write in the ROOT terminal

ROOT::RDataFrame df(“Delphes”, “tag_1_delphes_events.root”);
RVec Muon.PT;
auto hist = df.Histo1D(“MuonPT”) ;
hist->Draw();

I end up getting a histogram.

3. In attempt to get rid of some of the errors if I edit my code to just write MuonPT instead of Muon.PT the code runs without error but no plots are produced. In my terminal however, I get the error: Unknown Column MuonPT.

Any other variations would just give me the same warnings or an empty plot. Do you know how I can fix it or what the problem is?

Many thanks!

@swunsch Do you happen to know what the problem might be. I am trying to produce a code similar to your tutorial here ROOT: tutorials/dataframe/df103_NanoAODHiggsAnalysis.C File Reference
But, I keep having the problem of not being able to access my branch data.

I looked at the Define reference guide and also tried:

auto m = df.Define(“muon_mass”, { return ROOT::RVec(49254, 0.1)};);

double muonpt(const RVec &Muon.PT);

auto pt = df.Define(“muon_pt”, muonpt, {“Muon.PT”} );

double muoneta(const RVec &Muon.Eta);

auto eta = df.Define(“muon_eta”, muoneta, {“Muon.Eta”} );

double muonphi(const RVec &Muon.Phi);

auto phi = df.Define(“muon_phi”, muonphi, {“Muon.Phi”} );

double muoncharge(const RVec &Muon.Charge);

auto charge = df.Define(“muon_charge”, muoncharge, {“Muon.Charge”} );

RVec<RVec<size_t>> reco_zz_to_4l(rvec_f pt, rvec_f eta, rvec_f phi, rvec_f m, rvec_i charge);

RVec<RVec<size_t>> idx(2);

idx[0].reserve(2); idx[1].reserve(2);

auto idx_cmb = Combinations(m, 2);

auto best_mass = -1;

size_t best_i1 = 0; size_t best_i2 = 0;

for (size_t i = 0; i < charge.size(); i++)

{

  const auto i1 = idx_cmb[0][i];

  const auto i2 = idx_cmb[1][i];
  if(charge[1] != charge[2])

  {

    ROOT::Math::PtEtaPhiMVector m1((pt)[1], eta[1], phi[1], m);

    ROOT::Math::PtEtaPhiMVector m2((pt)[2], eta[2], phi[2], m);

    const auto this_mass = (m1 + m2).M();

which resulted in some kind of error as well. Is there a way to create the PtEtaPhiMVector from the branches in my Delphes tree?

Typing

ROOT::RDataFrame df(“Delphes”, “tag_1_delphes_events.root”);

auto colNames = df.GetColumnNames();

shows that Muon.PT, Muon.Eta, Muon.Phi, Muon.Charge are my column names but it is not getting recognized however.
Do you know how I can resolve this issue?

Many thanks!

I figured that changing the Branch names to remove the “Dot” helped. Instead of writing Muon.PT (which C++ was not reading as a Branch Name but rather as taking PT from the object Muon) I changed it to Muon_PT.

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