Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMVA_SOFIE_RDataFrame.C File Reference

Detailed Description

View in nbviewer Open in SWAN
This macro provides an example of using a trained model with Keras and make inference using SOFIE and RDataFrame This macro uses as input a Keras model generated with the TMVA_Higgs_Classification.C tutorial You need to run that macro before to generate the trained Keras model Then you need to run the macro TMVA_SOFIE_Keras_HiggsModel.C to generate the corresponding header file using SOFIE.

Execute in this order:

using namespace TMVA::Experimental;
// need to add the current directory (from where we are running this macro)
// to the include path for Cling
R__ADD_INCLUDE_PATH($ROOTSYS/runtutorials)
#include "Higgs_trained_model.hxx"
using namespace TMVA::Experimental;
void TMVA_SOFIE_RDataFrame(int nthreads = 2){
std::string inputFileName = "Higgs_data.root";
std::string inputFile = std::string(gROOT->GetTutorialDir() + "/tmva/data/") + inputFileName;
ROOT::RDataFrame df1("sig_tree", inputFile);
int nslots = df1.GetNSlots();
std::cout << "Running using " << nslots << " threads" << std::endl;
auto h1 = df1.DefineSlot("DNN_Value", SofieFunctor<7, TMVA_SOFIE_Higgs_trained_model::Session>(nslots),
{"m_jj", "m_jjj", "m_lv", "m_jlv", "m_bb", "m_wbb", "m_wwbb"})
.Histo1D({"h_sig", "", 100, 0, 1}, "DNN_Value");
ROOT::RDataFrame df2("bkg_tree", inputFile);
nslots = df2.GetNSlots();
auto h2 = df2.DefineSlot("DNN_Value", SofieFunctor<7, TMVA_SOFIE_Higgs_trained_model::Session>(nslots),
{"m_jj", "m_jjj", "m_lv", "m_jlv", "m_bb", "m_wbb", "m_wwbb"})
.Histo1D({"h_bkg", "", 100, 0, 1}, "DNN_Value");
h1->SetLineColor(kRed);
h2->SetLineColor(kBlue);
auto c1 = new TCanvas();
gStyle->SetOptStat(0);
h2->DrawClone();
h1->DrawClone("SAME");
c1->BuildLegend();
}
#define R__ADD_INCLUDE_PATH(PATH)
Definition Rtypes.h:492
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
#define gROOT
Definition TROOT.h:414
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
The Canvas class.
Definition TCanvas.h:23
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5
RResultPtr<::TH1D > Histo1D(const TH1DModel &model={"", "", 128u, 0., 0.}, std::string_view vName="")
Fill and return a one-dimensional histogram with the values of a column (lazy action).
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition TROOT.cxx:539
auto SofieFunctor(unsigned int nslots=0, const std::string &weightsFile="") -> SofieFunctorHelper< std::make_index_sequence< N >, Session_t, float >
SofieFunctor : used to wrap the infer function of the generated model by SOFIE in a RDF compatible si...
Author
Lorenzo Moneta

Definition in file TMVA_SOFIE_RDataFrame.C.