From $ROOTSYS/tutorials/mlp/mlpHiggs.C

void mlpHiggs(Int_t ntrain=100) {
// Example of a Multi Layer Perceptron
// For a LEP search for invisible Higgs boson, a neural network 
// was used to separate the signal from the background passing 
// some selection cuts. Here is a simplified version of this network, 
// taking into account only WW events.
//Author: Christophe Delaere
   
   if (!gROOT->GetClass("TMultiLayerPerceptron")) {
      gSystem->Load("libMLP");
   }

   // Prepare inputs
   // The 2 trees are merged into one, and a "type" branch, 
   // equal to 1 for the signal and 0 for the background is added.
   const char *fname = "mlpHiggs.root";
   TFile *input = 0;
   if (!gSystem->AccessPathName(fname)) {
      input = TFile::Open(fname);
   } else {
      printf("accessing %s file from http://root.cern.ch/files\n",fname);
      input = TFile::Open(Form("http://root.cern.ch/files/%s",fname));
   }
   if (!input) return;

   TTree *signal = (TTree *) input->Get("sig_filtered");
   TTree *background = (TTree *) input->Get("bg_filtered");
   TTree *simu = new TTree("MonteCarlo", "Filtered Monte Carlo Events");
   Float_t ptsumf, qelep, nch, msumf, minvis, acopl, acolin;
   Int_t type;
   signal->SetBranchAddress("ptsumf", &ptsumf);
   signal->SetBranchAddress("qelep",  &qelep);
   signal->SetBranchAddress("nch",    &nch);
   signal->SetBranchAddress("msumf",  &msumf);
   signal->SetBranchAddress("minvis", &minvis);
   signal->SetBranchAddress("acopl",  &acopl);
   signal->SetBranchAddress("acolin", &acolin);
   background->SetBranchAddress("ptsumf", &ptsumf);
   background->SetBranchAddress("qelep",  &qelep);
   background->SetBranchAddress("nch",    &nch);
   background->SetBranchAddress("msumf",  &msumf);
   background->SetBranchAddress("minvis", &minvis);
   background->SetBranchAddress("acopl",  &acopl);
   background->SetBranchAddress("acolin", &acolin);
   simu->Branch("ptsumf", &ptsumf, "ptsumf/F");
   simu->Branch("qelep",  &qelep,  "qelep/F");
   simu->Branch("nch",    &nch,    "nch/F");
   simu->Branch("msumf",  &msumf,  "msumf/F");
   simu->Branch("minvis", &minvis, "minvis/F");
   simu->Branch("acopl",  &acopl,  "acopl/F");
   simu->Branch("acolin", &acolin, "acolin/F");
   simu->Branch("type",   &type,   "type/I");
   type = 1;
   Int_t i;
   for (i = 0; i < signal->GetEntries(); i++) {
      signal->GetEntry(i);
      simu->Fill();
   }
   type = 0;
   for (i = 0; i < background->GetEntries(); i++) {
      background->GetEntry(i);
      simu->Fill();
   }
   // Build and train the NN ptsumf is used as a weight since we are primarly 
   // interested  by high pt events.
   // The datasets used here are the same as the default ones.
   TMultiLayerPerceptron *mlp = 
      new TMultiLayerPerceptron("@msumf,@ptsumf,@acolin:5:3:type",
                                "ptsumf",simu,"Entry$%2","(Entry$+1)%2");
   mlp->Train(ntrain, "text,graph,update=10");
   mlp->Export("test","python");
   // Use TMLPAnalyzer to see what it looks for
   TCanvas* mlpa_canvas = new TCanvas("mlpa_canvas","Network analysis");
   mlpa_canvas->Divide(2,2);
   TMLPAnalyzer ana(mlp);
   // Initialisation
   ana.GatherInformations();
   // output to the console
   ana.CheckNetwork();
   mlpa_canvas->cd(1);
   // shows how each variable influences the network
   ana.DrawDInputs();
   mlpa_canvas->cd(2);
   // shows the network structure
   mlp->Draw();
   mlpa_canvas->cd(3);
   // draws the resulting network
   ana.DrawNetwork(0,"type==1","type==0");
   mlpa_canvas->cd(4);
   // Use the NN to plot the results for each sample
   // This will give approx. the same result as DrawNetwork.
   // All entries are used, while DrawNetwork focuses on 
   // the test sample. Also the xaxis range is manually set.
   TH1F *bg = new TH1F("bgh", "NN output", 50, -.5, 1.5);
   TH1F *sig = new TH1F("sigh", "NN output", 50, -.5, 1.5);
   bg->SetDirectory(0);
   sig->SetDirectory(0);
   Double_t params[4];
   for (i = 0; i < background->GetEntries(); i++) {
      background->GetEntry(i);
      params[0] = msumf;
      params[1] = ptsumf;
      params[2] = acolin;
      params[3] = acopl;
      bg->Fill(mlp->Evaluate(0, params));
   }
   for (i = 0; i < signal->GetEntries(); i++) {
      signal->GetEntry(i);
      params[0] = msumf;
      params[1] = ptsumf;
      params[2] = acolin;
      params[3] = acopl;
      sig->Fill(mlp->Evaluate(0,params));
   }
   bg->SetLineColor(kBlue);
   bg->SetFillStyle(3008);   bg->SetFillColor(kBlue);
   sig->SetLineColor(kRed);
   sig->SetFillStyle(3003); sig->SetFillColor(kRed);
   bg->SetStats(0);
   sig->SetStats(0);
   bg->Draw();
   sig->Draw("same");
   TLegend *legend = new TLegend(.75, .80, .95, .95);
   legend->AddEntry(bg, "Background (WW)");
   legend->AddEntry(sig, "Signal (Higgs)");
   legend->Draw();
   mlpa_canvas->cd(0);
   delete input;
}
 mlpHiggs.C:1
 mlpHiggs.C:2
 mlpHiggs.C:3
 mlpHiggs.C:4
 mlpHiggs.C:5
 mlpHiggs.C:6
 mlpHiggs.C:7
 mlpHiggs.C:8
 mlpHiggs.C:9
 mlpHiggs.C:10
 mlpHiggs.C:11
 mlpHiggs.C:12
 mlpHiggs.C:13
 mlpHiggs.C:14
 mlpHiggs.C:15
 mlpHiggs.C:16
 mlpHiggs.C:17
 mlpHiggs.C:18
 mlpHiggs.C:19
 mlpHiggs.C:20
 mlpHiggs.C:21
 mlpHiggs.C:22
 mlpHiggs.C:23
 mlpHiggs.C:24
 mlpHiggs.C:25
 mlpHiggs.C:26
 mlpHiggs.C:27
 mlpHiggs.C:28
 mlpHiggs.C:29
 mlpHiggs.C:30
 mlpHiggs.C:31
 mlpHiggs.C:32
 mlpHiggs.C:33
 mlpHiggs.C:34
 mlpHiggs.C:35
 mlpHiggs.C:36
 mlpHiggs.C:37
 mlpHiggs.C:38
 mlpHiggs.C:39
 mlpHiggs.C:40
 mlpHiggs.C:41
 mlpHiggs.C:42
 mlpHiggs.C:43
 mlpHiggs.C:44
 mlpHiggs.C:45
 mlpHiggs.C:46
 mlpHiggs.C:47
 mlpHiggs.C:48
 mlpHiggs.C:49
 mlpHiggs.C:50
 mlpHiggs.C:51
 mlpHiggs.C:52
 mlpHiggs.C:53
 mlpHiggs.C:54
 mlpHiggs.C:55
 mlpHiggs.C:56
 mlpHiggs.C:57
 mlpHiggs.C:58
 mlpHiggs.C:59
 mlpHiggs.C:60
 mlpHiggs.C:61
 mlpHiggs.C:62
 mlpHiggs.C:63
 mlpHiggs.C:64
 mlpHiggs.C:65
 mlpHiggs.C:66
 mlpHiggs.C:67
 mlpHiggs.C:68
 mlpHiggs.C:69
 mlpHiggs.C:70
 mlpHiggs.C:71
 mlpHiggs.C:72
 mlpHiggs.C:73
 mlpHiggs.C:74
 mlpHiggs.C:75
 mlpHiggs.C:76
 mlpHiggs.C:77
 mlpHiggs.C:78
 mlpHiggs.C:79
 mlpHiggs.C:80
 mlpHiggs.C:81
 mlpHiggs.C:82
 mlpHiggs.C:83
 mlpHiggs.C:84
 mlpHiggs.C:85
 mlpHiggs.C:86
 mlpHiggs.C:87
 mlpHiggs.C:88
 mlpHiggs.C:89
 mlpHiggs.C:90
 mlpHiggs.C:91
 mlpHiggs.C:92
 mlpHiggs.C:93
 mlpHiggs.C:94
 mlpHiggs.C:95
 mlpHiggs.C:96
 mlpHiggs.C:97
 mlpHiggs.C:98
 mlpHiggs.C:99
 mlpHiggs.C:100
 mlpHiggs.C:101
 mlpHiggs.C:102
 mlpHiggs.C:103
 mlpHiggs.C:104
 mlpHiggs.C:105
 mlpHiggs.C:106
 mlpHiggs.C:107
 mlpHiggs.C:108
 mlpHiggs.C:109
 mlpHiggs.C:110
 mlpHiggs.C:111
 mlpHiggs.C:112
 mlpHiggs.C:113
 mlpHiggs.C:114
 mlpHiggs.C:115
 mlpHiggs.C:116
 mlpHiggs.C:117
 mlpHiggs.C:118
 mlpHiggs.C:119
 mlpHiggs.C:120
 mlpHiggs.C:121
 mlpHiggs.C:122
 mlpHiggs.C:123
 mlpHiggs.C:124
 mlpHiggs.C:125
 mlpHiggs.C:126
 mlpHiggs.C:127
 mlpHiggs.C:128
 mlpHiggs.C:129
 mlpHiggs.C:130