Logo ROOT  
Reference Guide
TMVA_SOFIE_RDataFrame.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tmva
3/// \notebook -nodraw
4/// This macro provides an example of using a trained model with Keras
5/// and make inference using SOFIE and RDataFrame
6/// This macro uses as input a Keras model generated with the
7/// TMVA_Higgs_Classification.C tutorial
8/// You need to run that macro before to generate the trained Keras model
9/// Then you need to run the macro TMVA_SOFIE_Keras_HiggsModel.C to generate the corresponding
10/// header file using SOFIE.
11///
12/// Execute in this order:
13/// ```
14/// root TMVA_Higgs_Classification.C
15/// root TMVA_SOFIE_Keras_HiggsModel.C
16/// root TMVA_SOFIE_RDataFrame.C
17/// ```
18///
19/// \macro_code
20/// \macro_output
21/// \author Lorenzo Moneta
22
23using namespace TMVA::Experimental;
24
25// need to add the current directory (from where we are running this macro)
26// to the include path for Cling
28R__ADD_INCLUDE_PATH($ROOTSYS/runtutorials)
29#include "Higgs_trained_model.hxx"
30#include "TMVA/SOFIEHelpers.hxx"
31
32using namespace TMVA::Experimental;
33
34void TMVA_SOFIE_RDataFrame(int nthreads = 2){
35
36 std::string inputFileName = "Higgs_data.root";
37 std::string inputFile = "http://root.cern.ch/files/" + inputFileName;
38
39 ROOT::EnableImplicitMT(nthreads);
40
41 ROOT::RDataFrame df1("sig_tree", inputFile);
42 int nslots = df1.GetNSlots();
43 std::cout << "Running using " << nslots << " threads" << std::endl;
44 auto h1 = df1.DefineSlot("DNN_Value", SofieFunctor<7, TMVA_SOFIE_Higgs_trained_model::Session>(nslots),
45 {"m_jj", "m_jjj", "m_lv", "m_jlv", "m_bb", "m_wbb", "m_wwbb"})
46 .Histo1D({"h_sig", "", 100, 0, 1}, "DNN_Value");
47
48 ROOT::RDataFrame df2("bkg_tree", inputFile);
49 nslots = df2.GetNSlots();
50 auto h2 = df2.DefineSlot("DNN_Value", SofieFunctor<7, TMVA_SOFIE_Higgs_trained_model::Session>(nslots),
51 {"m_jj", "m_jjj", "m_lv", "m_jlv", "m_bb", "m_wbb", "m_wwbb"})
52 .Histo1D({"h_bkg", "", 100, 0, 1}, "DNN_Value");
53
55 h2->SetLineColor(kBlue);
56
57 auto c1 = new TCanvas();
59
60 h2->DrawClone();
61 h1->DrawClone("SAME");
62 c1->BuildLegend();
63
64}
#define R__ADD_INCLUDE_PATH(PATH)
Definition: Rtypes.h:490
@ kRed
Definition: Rtypes.h:66
@ kBlue
Definition: Rtypes.h:66
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Definition: RDataFrame.hxx:40
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:23
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
Definition: TObject.cxx:299
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1589
return c1
Definition: legend1.C:41
TH1F * h1
Definition: legend1.C:5
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:527