22void CompileModelForRDF(
const std::string & headerModelFile,
unsigned int ninputs,
unsigned int nslots=0) {
24 std::string modelName = headerModelFile.substr(0,headerModelFile.find(
".hxx"));
25 std::string cmd = std::string(
"#include \"") + headerModelFile + std::string(
"\"");
28 throw std::runtime_error(
"Error compiling : " + cmd);
29 std::cout <<
"compiled : " << cmd << std::endl;
31 cmd =
"auto sofie_functor = TMVA::Experimental::SofieFunctor<" + std::to_string(ninputs) +
",TMVA_SOFIE_" +
32 modelName +
"::Session>(" + std::to_string(nslots) +
");";
35 throw std::runtime_error(
"Error compiling : " + cmd);
36 std::cout <<
"compiled : " << cmd << std::endl;
37 std::cout <<
"Model is ready to be evaluated" << std::endl;
41void TMVA_SOFIE_RDataFrame_JIT(std::string modelName =
"HiggsModel"){
44 std::string modelHeaderFile = modelName +
".hxx";
45 if (
gSystem->AccessPathName(modelHeaderFile.c_str())) {
46 Info(
"TMVA_SOFIE_RDataFrame",
"You need to run TMVA_SOFIE_Keras_Higgs_Model.py to generate the SOFIE header for the Keras trained model");
51 std::string modelWeightFile = modelName + std::string(
".dat");
52 if (
gSystem->AccessPathName(modelWeightFile.c_str())) {
53 Error(
"TMVA_SOFIE_RDataFrame",
"Generated weight file is missing");
58 CompileModelForRDF(modelHeaderFile,7);
60 std::string inputFileName =
"Higgs_data.root";
61 std::string inputFile = std::string{
gROOT->GetTutorialDir()} +
"/machine_learning/data/" + inputFileName;
64 auto h1 = df1.Define(
"DNN_Value",
"sofie_functor(rdfslot_,m_jj, m_jjj, m_lv, m_jlv, m_bb, m_wbb, m_wwbb)")
65 .Histo1D({
"h_sig",
"", 100, 0, 1},
"DNN_Value");
68 auto h2 = df2.Define(
"DNN_Value",
"sofie_functor(rdfslot_,m_jj, m_jjj, m_lv, m_jlv, m_bb, m_wbb, m_wwbb)")
69 .Histo1D({
"h_bkg",
"", 100, 0, 1},
"DNN_Value");
72 h2->SetLineColor(
kBlue);
78 h1->DrawClone(
"SAME");
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...