-
Notifications
You must be signed in to change notification settings - Fork 1
Home
This page contains step-by-step instructions for the tutorial on artificial neural networks in TMVA. In order to follow it, you need an access to a computer with a recent version of ROOT installed (and the TMVA package as a part of it). Start by checking out the tutorial's repository as explained in the README.
The TMVA package includes a number of MVA methods, with neural networks among others, incorporated into a common framework. The manual can be found here; keep it opened during the session.
The tutorial addresses the task of binary classification, by an example of discrimination between tH, H->bb and semileptonic ttbar events. A number of observables have been chosen to distinguish between the two. ROOT tuples with the observables are available in the data/ directory of the repository. For each process several tuples are provided, varying in the number of events.
The tutorial is focused on the usage of TMVA rather than illustrating various aspects of neural networks as a machine learning technique.
In this part of the tutorial you will learn how to train neural networks, check for overfitting, and evaluate their performance. Navigate into the directory tutorial/ and open script train.C. It is mostly empty, and you will fill it step-by-step. If needed, you can consult an exemplary completed version in train_Example.C. The script can be executed with the command
root -q -b train.C
A central class in TMVA is Factory, and most of interactions with the package is done via an instance of this class. It manages trees with input variables, keeps track of “booked” MVA methods, and trains them. Thus, creating a factory is the first thing you do. Copy the following code into your train.C file:
TString jobName("TutorialTrain");
TFile infoFile(TString("info") + jobName + ".root", "recreate");
TMVA::Factory factory(jobName, &infoFile, "Color=True");The code fragment also opens a ROOT file for writing and gives it to the factory. The file will contain various control and performance histograms. The last argument is a set of parameters for the factory. The parameters control verbosity and visual appearance, a complete list can be found on p. 15 of the manual.
There are many ways to provide training and testing sets to a factory, ranging from a single ROOT tree that contains everything (signal and background, training and testing sets) to simple ASCII files. Details are described in section 3.1.1 of the manual. Here we stick to the more robust option, providing four independent trees:
factory.AddSignalTree(sgnTrainTree, 1., TMVA::Types::kTraining);
factory.AddBackgroundTree(bkgTrainTree, 1., TMVA::Types::kTraining);
factory.AddSignalTree(sgnTestTree, 1., TMVA::Types::kTesting);
factory.AddBackgroundTree(bkgTestTree, 1., TMVA::Types::kTesting);The second argument is an event weight, which is applied to all events in the tree. We do not use it and specify per-event weight instead:
factory.SetWeightExpression("Weight");“Weight” is the name of branches in the source trees. The expression provided here is parsed with TTreeFormula and thus can include mathematical operations.
Input variables are specified with the following syntax:
factory.AddVariable("abs(tHq_Eta_Recoil)");The expression given is parsed with TTreeFormula and can include mathematical operations as in the example above. One can define short labels and human readable titles for variables to obtain a better decoration in control plots; details are in section 3.1.3.
Copy the line above to your train.C and add all the remaining observables stored in the trees. Here is the complete list: glb_Charge_Lep, glb_Sphericity, tHq_Eta_Recoil, tHq_NumBTag_Higgs, tHq_Pt_Higgs, tHq_Pt_Recoil, tt_DeltaR_Light, tt_Mass_TopHad, tt_NumPassBTag_Light. Note that the two transverse momenta and the mass have long tails, and because of this it is better to use their logarithms instead.
Copy the following line into your train.C:
factory.PrepareTrainingAndTestTree("", "NormMode=EqualNumEvents");It makes the factory read the training and testing sets (or split the only given set in two), evaluate expressions in input variables, and store results internally. The first argument defines a preselection cut (we do not apply any). The second argument is the list of parameters. If the data were not split into training and testing sets, the splitting is performed now, and the parameters specify how it is done; details are in section 3.1.4. Since we provided separate trees for the two sets, there is no need for the splitting.
The only parameter set in the example demands that signal and background events in the training set are independently reweighted such that the total signal normalisation equals the one of the background. Such symmetrisation usually improves performance of the classification.