Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
mlpHiggs.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_mlp
3/// Example of a Multi Layer Perceptron
4/// For a LEP search for invisible Higgs boson, a neural network
5/// was used to separate the signal from the background passing
6/// some selection cuts. Here is a simplified version of this network,
7/// taking into account only WW events.
8///
9/// \macro_image
10/// \macro_output
11/// \macro_code
12///
13/// \author Christophe Delaere
14
15void mlpHiggs(Int_t ntrain=100) {
16 const char *fname = "mlpHiggs.root";
17 TFile *input = 0;
20 } else if (!gSystem->AccessPathName(Form("%s/legacy/mlp/%s", TROOT::GetTutorialDir().Data(), fname))) {
21 input = TFile::Open(Form("%s/legacy/mlp/%s", TROOT::GetTutorialDir().Data(), fname));
22 } else {
23 printf("accessing %s file from http://root.cern/files\n",fname);
24 input = TFile::Open(Form("http://root.cern/files/%s",fname));
25 }
26 if (!input) return;
27
28 TTree *sig_filtered = (TTree *) input->Get("sig_filtered");
29 TTree *bg_filtered = (TTree *) input->Get("bg_filtered");
30 TTree *simu = new TTree("MonteCarlo", "Filtered Monte Carlo Events");
32 Int_t type;
33 sig_filtered->SetBranchAddress("ptsumf", &ptsumf);
34 sig_filtered->SetBranchAddress("qelep", &qelep);
35 sig_filtered->SetBranchAddress("nch", &nch);
36 sig_filtered->SetBranchAddress("msumf", &msumf);
37 sig_filtered->SetBranchAddress("minvis", &minvis);
38 sig_filtered->SetBranchAddress("acopl", &acopl);
39 sig_filtered->SetBranchAddress("acolin", &acolin);
40 bg_filtered->SetBranchAddress("ptsumf", &ptsumf);
41 bg_filtered->SetBranchAddress("qelep", &qelep);
42 bg_filtered->SetBranchAddress("nch", &nch);
43 bg_filtered->SetBranchAddress("msumf", &msumf);
44 bg_filtered->SetBranchAddress("minvis", &minvis);
45 bg_filtered->SetBranchAddress("acopl", &acopl);
46 bg_filtered->SetBranchAddress("acolin", &acolin);
47 simu->Branch("ptsumf", &ptsumf, "ptsumf/F");
48 simu->Branch("qelep", &qelep, "qelep/F");
49 simu->Branch("nch", &nch, "nch/F");
50 simu->Branch("msumf", &msumf, "msumf/F");
51 simu->Branch("minvis", &minvis, "minvis/F");
52 simu->Branch("acopl", &acopl, "acopl/F");
53 simu->Branch("acolin", &acolin, "acolin/F");
54 simu->Branch("type", &type, "type/I");
55 type = 1;
56 Int_t i;
57 for (i = 0; i < sig_filtered->GetEntries(); i++) {
58 sig_filtered->GetEntry(i);
59 simu->Fill();
60 }
61 type = 0;
62 for (i = 0; i < bg_filtered->GetEntries(); i++) {
63 bg_filtered->GetEntry(i);
64 simu->Fill();
65 }
66 // Build and train the NN ptsumf is used as a weight since we are primarily
67 // interested by high pt events.
68 // The datasets used here are the same as the default ones.
70 new TMultiLayerPerceptron("@msumf,@ptsumf,@acolin:5:3:type",
71 "ptsumf",simu,"Entry$%2","(Entry$+1)%2");
72 mlp->Train(ntrain, "text,graph,update=10");
73 mlp->Export("test","python");
74 // Use TMLPAnalyzer to see what it looks for
75 TCanvas* mlpa_canvas = new TCanvas("mlpa_canvas","Network analysis");
76 mlpa_canvas->Divide(2,2);
77 TMLPAnalyzer ana(mlp);
78 // Initialisation
79 ana.GatherInformations();
80 // output to the console
81 ana.CheckNetwork();
82 mlpa_canvas->cd(1);
83 // shows how each variable influences the network
84 ana.DrawDInputs();
85 mlpa_canvas->cd(2);
86 // shows the network structure
87 mlp->Draw();
88 mlpa_canvas->cd(3);
89 // draws the resulting network
90 ana.DrawNetwork(0,"type==1","type==0");
91 mlpa_canvas->cd(4);
92 // Use the NN to plot the results for each sample
93 // This will give approx. the same result as DrawNetwork.
94 // All entries are used, while DrawNetwork focuses on
95 // the test sample. Also the xaxis range is manually set.
96 TH1F *bg = new TH1F("bgh", "NN output", 50, -.5, 1.5);
97 TH1F *sig = new TH1F("sigh", "NN output", 50, -.5, 1.5);
98 bg->SetDirectory(0);
99 sig->SetDirectory(0);
100 Double_t params[3];
101 for (i = 0; i < bg_filtered->GetEntries(); i++) {
102 bg_filtered->GetEntry(i);
103 params[0] = msumf;
104 params[1] = ptsumf;
105 params[2] = acolin;
106 bg->Fill(mlp->Evaluate(0, params));
107 }
108 for (i = 0; i < sig_filtered->GetEntries(); i++) {
109 sig_filtered->GetEntry(i);
110 params[0] = msumf;
111 params[1] = ptsumf;
112 params[2] = acolin;
113 sig->Fill(mlp->Evaluate(0,params));
114 }
115 bg->SetLineColor(kBlue);
116 bg->SetFillStyle(3008); bg->SetFillColor(kBlue);
117 sig->SetLineColor(kRed);
118 sig->SetFillStyle(3003); sig->SetFillColor(kRed);
119 bg->SetStats(0);
120 sig->SetStats(0);
121 bg->Draw();
122 sig->Draw("same");
123 TLegend *legend = new TLegend(.75, .80, .95, .95);
124 legend->AddEntry(bg, "Background (WW)");
125 legend->AddEntry(sig, "Signal (Higgs)");
126 legend->Draw();
127 mlpa_canvas->cd(0);
128 delete input;
129}
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
Definition TAttFill.h:40
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
The Canvas class.
Definition TCanvas.h:23
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:4088
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:645
virtual void SetDirectory(TDirectory *dir)
By default, when a histogram is created, it is added to the list of histogram objects in the current ...
Definition TH1.cxx:8939
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition TH1.cxx:8992
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
This utility class contains a set of tests useful when developing a neural network.
This class describes a neural network.
Double_t Evaluate(Int_t index, Double_t *params) const
Returns the Neural Net for a given set of input parameters #parameters must equal #input neurons.
void Export(Option_t *filename="NNfunction", Option_t *language="C++") const
Exports the NN as a function for any non-ROOT-dependant code Supported languages are: only C++ ,...
void Train(Int_t nEpoch, Option_t *option="text", Double_t minE=0)
Train the network.
void Draw(Option_t *option="") override
Draws the network structure.
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
Definition TROOT.cxx:3119
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition TSystem.cxx:1296
A TTree represents a columnar dataset.
Definition TTree.h:79