Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
tmva103_Application.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_tmva
3/// \notebook -nodraw
4/// This tutorial illustrates how you can conveniently apply BDTs in C++ using
5/// the fast tree inference engine offered by TMVA. Supported workflows are
6/// event-by-event inference, batch inference and pipelines with RDataFrame.
7///
8/// \macro_code
9/// \macro_output
10///
11/// \date December 2018
12/// \author Stefan Wunsch
13
14using namespace TMVA::Experimental;
15
16void tmva103_Application()
17{
18 // Load BDT model remotely from a webserver
19 RBDT<> bdt("myBDT", "http://root.cern/files/tmva101.root");
20
21 // Apply model on a single input
22 auto y1 = bdt.Compute({1.0, 2.0, 3.0, 4.0});
23
24 std::cout << "Apply model on a single input vector: " << y1[0] << std::endl;
25
26 // Apply model on a batch of inputs
27 float data[8] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0};
28 RTensor<float> x(data, {2, 4});
29 auto y2 = bdt.Compute(x);
30
31 std::cout << "Apply model on an input tensor: " << y2 << std::endl;
32
33 // Apply model as part of an RDataFrame workflow
34 ROOT::RDataFrame df("Events", "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/SMHiggsToZZTo4L.root");
35 auto df2 = df.Filter("nMuon >= 2")
36 .Filter("nElectron >= 2")
37 .Define("Muon_pt_1", "Muon_pt[0]")
38 .Define("Muon_pt_2", "Muon_pt[1]")
39 .Define("Electron_pt_1", "Electron_pt[0]")
40 .Define("Electron_pt_2", "Electron_pt[1]")
41 .Define("y",
42 Compute<4, float>(bdt),
43 {"Muon_pt_1", "Muon_pt_2", "Electron_pt_1", "Electron_pt_2"});
44
45 std::cout << "Mean response on the signal sample: " << *df2.Mean("y") << std::endl;
46}
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char y1
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Fast boosted decision tree inference.
Definition RBDT.hxx:36
RTensor is a container with contiguous memory and shape information.
Definition RTensor.hxx:162
Double_t x[n]
Definition legend1.C:17