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