12from ROOT
import TMVA, TFile, TString
13from array
import array
14from subprocess
import call
15from os.path
import isfile
23if not isfile(
'tmva_class_example.root'):
24 call([
'curl',
'-L',
'-O',
'http://root.cern.ch/files/tmva_class_example.root'])
27signal = data.Get(
'TreeS')
28background = data.Get(
'TreeB')
31for branch
in signal.GetListOfBranches():
32 branchName = branch.GetName()
33 branches[branchName] = array(
'f', [-999])
34 reader.AddVariable(branchName, branches[branchName])
35 signal.SetBranchAddress(branchName, branches[branchName])
36 background.SetBranchAddress(branchName, branches[branchName])
39reader.BookMVA(
'PyKeras',
TString(
'dataset/weights/TMVAClassification_PyKeras.weights.xml'))
42print(
'Some signal example classifications:')
45 print(reader.EvaluateMVA(
'PyKeras'))
48print(
'Some background example classifications:')
50 background.GetEntry(i)
51 print(reader.EvaluateMVA(
'PyKeras'))
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
static void PyInitialize()
Initialize Python interpreter.
The Reader class serves to use the MVAs in a specific analysis context.