23void CompileModelForRDF(
const std::string &headerModelFile,
unsigned int ninputs,
unsigned int nslots = 0)
26 std::string modelName = headerModelFile.substr(0,headerModelFile.find(
".hxx"));
28 std::string(
"#include \"") + headerModelFile + std::string(
"\"\n#include <array>\n#include <vector>");
31 throw std::runtime_error(
"Error compiling : " + cmd);
32 std::cout <<
"compiled : " << cmd << std::endl;
38 cmd =
"std::vector<TMVA_SOFIE_" + modelName +
"::Session> sofie_sessions(" + std::to_string(nslots) +
");";
41 throw std::runtime_error(
"Error compiling : " + cmd);
46 std::string inputValues;
47 for (
unsigned int i = 0; i < ninputs; i++) {
52 params +=
"float x" + std::to_string(i);
53 inputValues +=
"x" + std::to_string(i);
55 cmd =
"double sofie_eval(unsigned int slot, " + params +
57 " std::array<float, " +
58 std::to_string(ninputs) +
"> input{" + inputValues +
60 " return sofie_sessions[slot].infer(input.data())[0];\n"
64 throw std::runtime_error(
"Error compiling : " + cmd);
65 std::cout <<
"compiled : " << cmd << std::endl;
66 std::cout <<
"Model is ready to be evaluated" << std::endl;
70void TMVA_SOFIE_RDataFrame_JIT(std::string modelName =
"HiggsModel"){
75 Info(
"TMVA_SOFIE_RDataFrame",
"You need to run TMVA_SOFIE_PyTorch_HiggsModel.py to generate the SOFIE header "
76 "for the PyTorch trained model");
81 std::string modelWeightFile = modelName + std::string(
".dat");
83 Error(
"TMVA_SOFIE_RDataFrame",
"Generated weight file is missing");
88 CompileModelForRDF(modelHeaderFile,7);
90 std::string inputFileName =
"Higgs_data.root";
91 std::string inputFile = std::string{
gROOT->GetTutorialDir()} +
"/machine_learning/data/" + inputFileName;
96 auto h1 = df1.Define(
"DNN_Value",
"sofie_eval(rdfslot_,m_jj, m_jjj, m_lv, m_jlv, m_bb, m_wbb, m_wwbb)")
97 .Histo1D({
"h_sig",
"", 100, 0, 1},
"DNN_Value");
100 auto h2 = df2.Define(
"DNN_Value",
"sofie_eval(rdfslot_,m_jj, m_jjj, m_lv, m_jlv, m_bb, m_wbb, m_wwbb)")
101 .Histo1D({
"h_bkg",
"", 100, 0, 1},
"DNN_Value");
104 h2->SetLineColor(
kBlue);
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
modelName
Step 2 : Parse model and generate inference code with SOFIE.