User Tools

Site Tools


How to run TMVA

TMVA is a tool to run a multivariate analysis in ROOT. Among many other methods, it includes boosted decision tree (BDT) and neural network (MLP). More information can be found at:

When using the neural netwerk method MLP, you might need ROOT or newer, to have larger buffer for the xml reader, for example:

. /afs/


To run the MVA in python on a signal tree treeS and background tree treeB with a list of variables, varNames, that are available in the tree, you first need:

from ROOT import TFile, TTree, TMVA, TCut
f_out = TFile("MVA.root","RECREATE")
factory = TMVA.Factory( "TMVAClassification", f_out, "" )
for name in varNames:
cut_S = TCut("")
cut_B = TCut("")
factory.PrepareTrainingAndTestTree( cut_S, cut_B, "" )

In the empty quote marks you can add cuts or options. More information on can be found in section 3.1 in the manual and in the Factory Class Reference.

Then you can book multiple methods like the BDT and MLP for different parameters:

factory.BookMethod( TMVA.Types.kBDT, "BDT", "!H:!V" )
factory.BookMethod( TMVA.Types.kBDT, "BDTTuned",
                    "AdaBoostBeta=0.1:SeparationType=GiniIndex:nCuts=80" )
factory.BookMethod( TMVA.Types.kMLP, "MLPTanh",
                    "VarTransform=N:HiddenLayers=N,N:UseRegulator" )

Finally train, test and evaluate all the booked methods:


Applying the output to a tree

The factory will output weights in a XML file you can use to apply to a tree that contains the same variable.

reader = TMVA.Reader()
vars = [ ]
for name in config.varNames:
    for i in range(len(config.varNames)):
    for evt in range(tree.GetEntries()):
        hist.Fill( reader.EvaluateMVA(method) )

Parameters to tune

The parameters and options of the MVA method can be optimized from the default settings for better a performance, check out the option reference page.

In particular, for the BDT, important parameters are the the learning rate, number of boost steps and maximal tree depth:

  • AdaBoostBeta=0.5: learning rate for AdaBoost, smaller (~0.1) is better, but takes longer
  • nTrees=800: number of boost steps, too large mainly costs time and can cause overtraining
  • MaxDepth=3: maximum tree depth, ~2-5 depending on interaction of the variables
  • nCuts=20: grid points in variable range to find the optimal cut in node splitting
  • SeparationType=GiniIndex: separating criterion at each splitting node to select best variable. The Gini index is one often used measure
  • MinNodeSize=5%: minimum percentage of training events required in a leaf node

Important MLP parameters to tune are the number of neurons on each hidden layer, learning rate and the activation function.

  • HiddenLayers=N,N-1: number of nodes in each hidden layer for N variables
    • N = one hidden layer with N nodes
    • N,N = two hidden layers
    • N+2,N = two hidden layers, with N+2 nodes in the first
  • LearningRate=0.02
  • NeuronType=sigmoid: other neuron activation function is tanh

Tutorials and examples

Other information

  title         = {TMVA: Toolkit for Multivariate Data Analysis},
  author        = {Hoecker, Andreas and Speckmayer, Peter and
                   Stelzer, Joerg and Therhaag, Jan and
                   von Toerne, Eckhard and Voss, Helge},
  journal       = {PoS},
  volume        = {ACAT},
  year          = {2007},
  month         = {Mar},
  pages         = {040},
  url           = {},
  reportNumber  = {CERN-OPEN-2007-007},
  eprint        = {physics/0703039},
  archivePrefix = {arXiv},
  primaryClass  = {physics},
  SLACcitation  = {%%CITATION = arXiv:physics/0703039;%%},
mva/mva.txt · Last modified: 2017/03/02 16:34 by iwn