12 from ROOT
import TMVA, TFile, TString
13 from array
import array
14 from subprocess
import call
15 from os.path
import isfile
19 TMVA.PyMethodBase.PyInitialize()
20 reader = TMVA.Reader(
"Color:!Silent")
23 if not isfile(
'tmva_class_example.root'):
24 call([
'curl',
'-O',
'http://root.cern.ch/files/tmva_class_example.root'])
26 data = TFile.Open(
'tmva_class_example.root')
27 signal = data.Get(
'TreeS')
28 background = data.Get(
'TreeB')
31 for 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])
39 reader.BookMVA(
'PyKeras', TString(
'dataset/weights/TMVAClassification_PyKeras.weights.xml'))
42 print(
'Some signal example classifications:')
45 print(reader.EvaluateMVA(
'PyKeras'))
48 print(
'Some background example classifications:')
50 background.GetEntry(i)
51 print(reader.EvaluateMVA(
'PyKeras'))