Home | News | Documentation | Download

RDataFrame & TMVA

Dear root experts,

Do you know any example where weights from TMVA are used in RDataFrame?

I think @moneta can help you.

Thank you for your help @couet !

Hi Nathanael,

Could you give more details about what you want to do? Do you want to process the prediction of a method from TMVA in dataframe, like the BDT score or something similar?

Best
Stefan

Hi Stefan,

Yes, for example I would like to know how to apply a cut on the BDT variable in RDataFrame.

Hi!

Alrighty, you have actually three options:

  1. You loop once over the tree, calculate all predictions and create a friend tree. Then, you attach the friend tree as a new column (branch) the the original tree and you have the BDT score in dataframe. You can find in the RDataFrame docs a section about how to use friend trees.

  2. You can calculate the BDT score “on the fly” in the dataframe loop. But take care, TMVA is not thread safe! That means you cannot use ROOT::EnableImplicitMT() easily. This looks roughly like this (no code guarantee):

TMVA::Reader reader (...);
auto predict = [&](float var1, float var2) { return reader.EvaluateMVA({var1, var2}, "method name"); };
ROOT::RDataFrame df(...);
auto df2 = df.Define("score", predict, {"var1", "var2"});
  1. You can use the experimental (!) feature on master, which does actually the same than option 2, but nicely wrapped. This is thread safe, but uses many locks, which basically serializes the event loop again. You can find a tutorial here.

I would recommend you to go for option 1, since this allows you to use the full potential of RDataFrame later on.

Best
Stefan

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