1 |
#include <iostream>
|
2 |
#include <vector>
|
3 |
|
4 |
#include "TROOT.h"
|
5 |
#include "TControlBar.h"
|
6 |
#include "tmvaglob.C"
|
7 |
|
8 |
// some global lists
|
9 |
static TList* TMVAGui_keyContent;
|
10 |
static std::vector<TString> TMVAGui_inactiveButtons;
|
11 |
|
12 |
TList* GetKeyList( const TString& pattern )
|
13 |
{
|
14 |
TList* list = new TList();
|
15 |
|
16 |
TIter next( TMVAGui_keyContent );
|
17 |
TKey* key(0);
|
18 |
while ((key = (TKey*)next())) {
|
19 |
if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
|
20 |
}
|
21 |
return list;
|
22 |
}
|
23 |
|
24 |
// utility function
|
25 |
void ActionButton( TControlBar* cbar,
|
26 |
const TString& title, const TString& macro, const TString& comment,
|
27 |
const TString& buttonType, TString requiredKey = "" )
|
28 |
{
|
29 |
cbar->AddButton( title, macro, comment, buttonType );
|
30 |
|
31 |
// search
|
32 |
if (requiredKey != "") {
|
33 |
Bool_t found = kFALSE;
|
34 |
TIter next( TMVAGui_keyContent );
|
35 |
TKey* key(0);
|
36 |
while ((key = (TKey*)next())) {
|
37 |
if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
|
38 |
}
|
39 |
if (!found) TMVAGui_inactiveButtons.push_back( title );
|
40 |
}
|
41 |
}
|
42 |
|
43 |
// main GUI
|
44 |
void TMVARegGui( const char* fName = "TMVAReg.root" )
|
45 |
{
|
46 |
// Use this script in order to run the various individual macros
|
47 |
// that plot the output of TMVA (e.g. running TMVARegression.C),
|
48 |
// stored in the file "TMVA.Regroot"
|
49 |
|
50 |
TString curMacroPath(gROOT->GetMacroPath());
|
51 |
// uncomment next line for macros submitted to next root version
|
52 |
gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
|
53 |
|
54 |
// for the sourceforge version, including $ROOTSYS/tmva/test in the
|
55 |
// macro path is a mistake, especially if "./" was not part of path
|
56 |
// add ../macros to the path (comment out next line for the ROOT version of TMVA)
|
57 |
// gROOT->SetMacroPath(curMacroPath+":../macros:");
|
58 |
|
59 |
TString curIncludePath=gSystem->GetIncludePath();
|
60 |
//std::cout <<"inc path="<<curIncludePath<<std::endl;
|
61 |
TString newIncludePath=TString("-I../ ")+curIncludePath;
|
62 |
gSystem->SetIncludePath(newIncludePath);
|
63 |
|
64 |
cout << "--- Launch TMVA GUI to view input file: " << fName << endl;
|
65 |
|
66 |
// init
|
67 |
TMVAGui_inactiveButtons.clear();
|
68 |
|
69 |
// check if file exist
|
70 |
TFile* file = TFile::Open( fName );
|
71 |
if (!file) {
|
72 |
cout << "==> Abort TMVAGui, please verify filename" << endl;
|
73 |
return;
|
74 |
}
|
75 |
// find all references
|
76 |
TMVAGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
|
77 |
|
78 |
// close file
|
79 |
file->Close();
|
80 |
|
81 |
TString defaultRequiredClassifier = "";
|
82 |
|
83 |
// gROOT->Reset();
|
84 |
// gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
|
85 |
|
86 |
// create the control bar
|
87 |
TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Regression", 0, 0 );
|
88 |
|
89 |
const TString buttonType( "button" );
|
90 |
|
91 |
// configure buttons
|
92 |
Int_t ic = 1;
|
93 |
|
94 |
// find all input variables types
|
95 |
TList* keylist = GetKeyList( "InputVariables" );
|
96 |
TListIter it( keylist );
|
97 |
TObjString* str = 0;
|
98 |
char ch = 'a';
|
99 |
while (str = (TObjString*)it()) {
|
100 |
TString tmp = str->GetString();
|
101 |
TString title = Form( "Input variables and target(s) '%s'-transformed (training sample)",
|
102 |
tmp.ReplaceAll("InputVariables_","").Data() );
|
103 |
if (tmp.Contains( "Id" )) title = "Input variables and target(s) (training sample)";
|
104 |
ActionButton( cbar,
|
105 |
Form( " (%i%c) %s ", ic, ch++, title.Data() ),
|
106 |
Form( ".x variables.C(\"%s\",\"%s\",\"%s\",kTRUE)", fName, str->GetString().Data(), title.Data() ),
|
107 |
Form( "Plots all '%s'-transformed input variables and target(s) (macro variables.C(...))",
|
108 |
str->GetString().Data() ),
|
109 |
buttonType, str->GetString() );
|
110 |
}
|
111 |
ic++;
|
112 |
|
113 |
// correlation scatter plots
|
114 |
it.Reset(); ch = 'a';
|
115 |
while (str = (TObjString*)it()) {
|
116 |
TString tmp = str->GetString();
|
117 |
TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
|
118 |
tmp.ReplaceAll("InputVariables_","").Data() );
|
119 |
if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
|
120 |
ActionButton( cbar,
|
121 |
Form( "(%i%c) %s", ic, ch++, title.Data() ),
|
122 |
Form( ".x CorrGui.C(\"%s\",\"%s\",\"%s\",kTRUE)", fName, str->GetString().Data(), title.Data() ),
|
123 |
Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui.C(...))",
|
124 |
str->GetString().Data() ),
|
125 |
buttonType, str->GetString() );
|
126 |
}
|
127 |
|
128 |
// coefficients
|
129 |
ActionButton( cbar,
|
130 |
Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic ),
|
131 |
Form( ".x correlations.C(\"%s\",kTRUE)", fName ),
|
132 |
"Plots signal and background correlation summaries for all input variables (macro correlations.C)",
|
133 |
buttonType );
|
134 |
|
135 |
ActionButton( cbar,
|
136 |
Form( "(%ia) Regression Output Deviation versus Target (test sample)", ++ic ),
|
137 |
Form( ".x deviations.C(\"%s\",0,kTRUE)", fName ),
|
138 |
"Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
|
139 |
buttonType, defaultRequiredClassifier );
|
140 |
|
141 |
ActionButton( cbar,
|
142 |
Form( "(%ib) Regression Output Deviation versus Target (training sample)", ic ),
|
143 |
Form( ".x deviations.C(\"%s\",3,kTRUE)", fName ),
|
144 |
"Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
|
145 |
buttonType, defaultRequiredClassifier );
|
146 |
|
147 |
ActionButton( cbar,
|
148 |
Form( "(%ic) Regression Output Deviation versus Input Variables (test sample)", ic ),
|
149 |
Form( ".x deviations.C(\"%s\",0,kFALSE)", fName ),
|
150 |
"Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
|
151 |
buttonType, defaultRequiredClassifier );
|
152 |
|
153 |
ActionButton( cbar,
|
154 |
Form( " (%id) Regression Output Deviation versus Input Variables (training sample) ", ic ),
|
155 |
Form( ".x deviations.C(\"%s\",3,kFALSE)", fName ),
|
156 |
"Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
|
157 |
buttonType, defaultRequiredClassifier );
|
158 |
|
159 |
ActionButton( cbar,
|
160 |
Form( "(%i) Summary of Average Regression Deviations ", ++ic ),
|
161 |
Form( ".x regression_averagedevs.C(\"%s\")", fName ),
|
162 |
"Plot Summary of average deviations: MVAvalue - target (macro regression_averagedevs.C)",
|
163 |
buttonType );
|
164 |
|
165 |
ActionButton( cbar,
|
166 |
Form( "(%ia) Network Architecture", ++ic ),
|
167 |
Form( ".x network.C(\"%s\")", fName ),
|
168 |
"Plots the MLP weights (macro network.C)",
|
169 |
buttonType, "MLP" );
|
170 |
|
171 |
ActionButton( cbar,
|
172 |
Form( "(%ib) Network Convergence Test", ic ),
|
173 |
Form( ".x annconvergencetest.C(\"%s\")", fName ),
|
174 |
"Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)",
|
175 |
buttonType, "MLP" );
|
176 |
|
177 |
ActionButton( cbar,
|
178 |
Form( "(%i) Plot Foams", ++ic ),
|
179 |
Form( ".x PlotFoams.C(\"weights/TMVARegression_PDEFoam.weights_foams.root\")", fName ),
|
180 |
"Plot Foams (macro PlotFoams.C)",
|
181 |
buttonType, "PDEFoam" );
|
182 |
|
183 |
ActionButton( cbar,
|
184 |
Form( "(%i) Regression Trees (BDT)", ++ic ),
|
185 |
Form( ".x BDT_Reg.C+(\"%s\")", fName ),
|
186 |
"Plots the Regression Trees trained by BDT algorithms (macro BDT_Reg.C(itree,...))",
|
187 |
buttonType, "BDT" );
|
188 |
|
189 |
ActionButton( cbar,
|
190 |
Form( "(%i) Regression Tree Control Plots (BDT)", ++ic ),
|
191 |
Form( ".x BDTControlPlots.C(\"%s\")", fName ),
|
192 |
"Plots to monitor boosting and pruning of regression trees (macro BDTControlPlots.C)",
|
193 |
buttonType, "BDT" );
|
194 |
|
195 |
cbar->AddSeparator();
|
196 |
|
197 |
cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
|
198 |
|
199 |
// set the style
|
200 |
cbar->SetTextColor("black");
|
201 |
|
202 |
// there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
|
203 |
// cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
|
204 |
|
205 |
// draw
|
206 |
cbar->Show();
|
207 |
|
208 |
// indicate inactive buttons
|
209 |
for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAGui_inactiveButtons[i], 3 );
|
210 |
if (TMVAGui_inactiveButtons.size() > 0) {
|
211 |
cout << "=== Note: inactive buttons indicate that the corresponding methods were not trained ===" << endl;
|
212 |
}
|
213 |
|
214 |
gROOT->SaveContext();
|
215 |
}
|