1 |
#include <iostream>
|
2 |
#include <vector>
|
3 |
|
4 |
#include "TList.h"
|
5 |
#include "TROOT.h"
|
6 |
#include "TKey.h"
|
7 |
#include "TString.h"
|
8 |
#include "TControlBar.h"
|
9 |
#include "TObjString.h"
|
10 |
|
11 |
#include "tmvaglob.C"
|
12 |
|
13 |
// some global lists
|
14 |
static TList* TMVAGui_keyContent;
|
15 |
static std::vector<TString> TMVAGui_inactiveButtons;
|
16 |
|
17 |
TList* GetKeyList( const TString& pattern )
|
18 |
{
|
19 |
TList* list = new TList();
|
20 |
|
21 |
TIter next( TMVAGui_keyContent );
|
22 |
TKey* key(0);
|
23 |
while ((key = (TKey*)next())) {
|
24 |
if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
|
25 |
}
|
26 |
return list;
|
27 |
}
|
28 |
|
29 |
// utility function
|
30 |
void ActionButton( TControlBar* cbar,
|
31 |
const TString& title, const TString& macro, const TString& comment,
|
32 |
const TString& buttonType, TString requiredKey = "")
|
33 |
{
|
34 |
cbar->AddButton( title, macro, comment, buttonType );
|
35 |
|
36 |
// search
|
37 |
if (requiredKey != "") {
|
38 |
Bool_t found = kFALSE;
|
39 |
TIter next( TMVAGui_keyContent );
|
40 |
TKey* key(0);
|
41 |
while ((key = (TKey*)next())) {
|
42 |
if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
|
43 |
}
|
44 |
if (!found) TMVAGui_inactiveButtons.push_back( title );
|
45 |
}
|
46 |
}
|
47 |
|
48 |
// main GUI
|
49 |
void TMVAGui( const char* fName = "TMVA.root" )
|
50 |
{
|
51 |
// Use this script in order to run the various individual macros
|
52 |
// that plot the output of TMVA (e.g. running TMVAClassification.C),
|
53 |
// stored in the file "TMVA.root"
|
54 |
|
55 |
TString curMacroPath(gROOT->GetMacroPath());
|
56 |
// uncomment next line for macros submitted to next root version
|
57 |
gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
|
58 |
|
59 |
// for the sourceforge version, including $ROOTSYS/tmva/test in the
|
60 |
// macro path is a mistake, especially if "./" was not part of path
|
61 |
// add ../macros to the path (comment out next line for the ROOT version of TMVA)
|
62 |
// gROOT->SetMacroPath(curMacroPath+":../macros:");
|
63 |
|
64 |
TString curIncludePath=gSystem->GetIncludePath();
|
65 |
TString newIncludePath=TString("-I../ ")+curIncludePath;
|
66 |
gSystem->SetIncludePath(newIncludePath);
|
67 |
|
68 |
cout << "--- Launch TMVA GUI to view input file: " << fName << endl;
|
69 |
|
70 |
// init
|
71 |
TMVAGui_inactiveButtons.clear();
|
72 |
|
73 |
// check if file exist
|
74 |
TFile* file = TFile::Open( fName );
|
75 |
if (!file) {
|
76 |
cout << "==> Abort TMVAGui, please verify filename" << endl;
|
77 |
return;
|
78 |
}
|
79 |
// find all references
|
80 |
TMVAGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
|
81 |
|
82 |
// close file
|
83 |
file->Close();
|
84 |
|
85 |
TString defaultRequiredClassifier = "";
|
86 |
|
87 |
// gROOT->Reset();
|
88 |
// gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
|
89 |
|
90 |
// create the control bar
|
91 |
TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Classification", 0, 0 );
|
92 |
|
93 |
const TString buttonType( "button" );
|
94 |
|
95 |
// configure buttons
|
96 |
Int_t ic = 1;
|
97 |
|
98 |
// find all input variables types
|
99 |
TList* keylist = GetKeyList( "InputVariables" );
|
100 |
TListIter it( keylist );
|
101 |
TObjString* str = 0;
|
102 |
char ch = 'a';
|
103 |
while ((str = (TObjString*)it())) {
|
104 |
TString tmp = str->GetString();
|
105 |
TString title = Form( "Input variables '%s'-transformed (training sample)",
|
106 |
tmp.ReplaceAll("InputVariables_","").Data() );
|
107 |
if (tmp.Contains( "Id" )) title = "Input variables (training sample)";
|
108 |
ActionButton( cbar,
|
109 |
Form( "(%i%c) %s", ic, ch++, title.Data() ),
|
110 |
Form( ".x variables.C(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
|
111 |
Form( "Plots all '%s'-transformed input variables (macro variables.C(...))", str->GetString().Data() ),
|
112 |
buttonType, str->GetString() );
|
113 |
}
|
114 |
ic++;
|
115 |
|
116 |
// correlation scatter plots
|
117 |
it.Reset(); ch = 'a';
|
118 |
while ((str = (TObjString*)it())) {
|
119 |
TString tmp = str->GetString();
|
120 |
TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
|
121 |
tmp.ReplaceAll("InputVariables_","").Data() );
|
122 |
if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
|
123 |
ActionButton( cbar,
|
124 |
Form( "(%i%c) %s", ic, ch++, title.Data() ),
|
125 |
Form( ".x CorrGui.C(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
|
126 |
Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui.C(...))",
|
127 |
str->GetString().Data() ),
|
128 |
buttonType, str->GetString() );
|
129 |
}
|
130 |
|
131 |
TString title;
|
132 |
// coefficients
|
133 |
title =Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic );
|
134 |
ActionButton( cbar,
|
135 |
title,
|
136 |
Form( ".x correlations.C(\"%s\")", fName ),
|
137 |
"Plots signal and background correlation summaries for all input variables (macro correlations.C)",
|
138 |
buttonType );
|
139 |
|
140 |
title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
|
141 |
ActionButton( cbar,
|
142 |
title,
|
143 |
Form( ".x mvas.C(\"%s\",0)", fName ),
|
144 |
"Plots the output of each classifier for the test data (macro mvas.C(...,0))",
|
145 |
buttonType, defaultRequiredClassifier );
|
146 |
|
147 |
title =Form( "(%ib) Classifier Output Distributions (test and training samples superimposed)", ic );
|
148 |
ActionButton( cbar,
|
149 |
title,
|
150 |
Form( ".x mvas.C(\"%s\",3)", fName ),
|
151 |
"Plots the output of each classifier for the test (histograms) and training (dots) data (macro mvas.C(...,3))",
|
152 |
buttonType, defaultRequiredClassifier );
|
153 |
|
154 |
title = Form( "(%ic) Classifier Probability Distributions (test sample)", ic );
|
155 |
ActionButton( cbar,
|
156 |
title,
|
157 |
Form( ".x mvas.C(\"%s\",1)", fName ),
|
158 |
"Plots the probability of each classifier for the test data (macro mvas.C(...,1))",
|
159 |
buttonType, defaultRequiredClassifier );
|
160 |
|
161 |
title =Form( "(%id) Classifier Rarity Distributions (test sample)", ic );
|
162 |
ActionButton( cbar,
|
163 |
title,
|
164 |
Form( ".x mvas.C(\"%s\",2)", fName ),
|
165 |
"Plots the Rarity of each classifier for the test data (macro mvas.C(...,2)) - background distribution should be uniform",
|
166 |
buttonType, defaultRequiredClassifier );
|
167 |
|
168 |
title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
|
169 |
ActionButton( cbar,
|
170 |
title,
|
171 |
Form( ".x mvaeffs.C+(\"%s\")", fName ),
|
172 |
"Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)",
|
173 |
buttonType, defaultRequiredClassifier );
|
174 |
|
175 |
title = Form( "(%ib) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ic );
|
176 |
ActionButton( cbar,
|
177 |
title,
|
178 |
Form( ".x efficiencies.C(\"%s\")", fName ),
|
179 |
"Plots background rejection vs signal efficiencies (macro efficiencies.C) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
|
180 |
buttonType, defaultRequiredClassifier );
|
181 |
|
182 |
title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
|
183 |
ActionButton( cbar,
|
184 |
title,
|
185 |
Form( ".x paracoor.C(\"%s\")", fName ),
|
186 |
"Plots parallel coordinates for classifiers and input variables (macro paracoor.C, requires ROOT >= 5.17)",
|
187 |
buttonType, defaultRequiredClassifier );
|
188 |
|
189 |
// parallel coordinates only exist since ROOT 5.17
|
190 |
#if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0)
|
191 |
TMVAGui_inactiveButtons.push_back( title );
|
192 |
#endif
|
193 |
|
194 |
title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
|
195 |
ActionButton( cbar,
|
196 |
title,
|
197 |
Form( ".x probas.C(\"%s\")", fName ),
|
198 |
"Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.C)",
|
199 |
buttonType, defaultRequiredClassifier );
|
200 |
|
201 |
title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
|
202 |
ActionButton( cbar,
|
203 |
title,
|
204 |
Form( ".x likelihoodrefs.C(\"%s\")", fName ),
|
205 |
"Plots to verify the likelihood reference distributions (macro likelihoodrefs.C)",
|
206 |
buttonType, "Likelihood" );
|
207 |
|
208 |
title = Form( "(%ia) Network Architecture (MLP)", ++ic );
|
209 |
TString call = Form( ".x network.C+g(\"%s\")", fName );
|
210 |
ActionButton( cbar,
|
211 |
title,
|
212 |
call,
|
213 |
"Plots the MLP weights (macro network.C)",
|
214 |
buttonType, "MLP" );
|
215 |
|
216 |
title = Form( "(%ib) Network Convergence Test (MLP)", ic );
|
217 |
ActionButton( cbar,
|
218 |
title,
|
219 |
Form( ".x annconvergencetest.C(\"%s\")", fName ),
|
220 |
"Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)",
|
221 |
buttonType, "MLP" );
|
222 |
|
223 |
title = Form( "(%i) Decision Trees (BDT)", ++ic );
|
224 |
ActionButton( cbar,
|
225 |
title,
|
226 |
Form( ".x BDT.C+(\"%s\")", fName ),
|
227 |
"Plots the Decision Trees trained by BDT algorithms (macro BDT.C(itree,...))",
|
228 |
buttonType, "BDT" );
|
229 |
|
230 |
title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
|
231 |
ActionButton( cbar,
|
232 |
title,
|
233 |
Form( ".x BDTControlPlots.C(\"%s\")", fName ),
|
234 |
"Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.C)",
|
235 |
buttonType, "BDT" );
|
236 |
|
237 |
// ActionButton( cbar,
|
238 |
// Form( "(%i) Monitor Decision Tree Boosting", ++ic ),
|
239 |
// Form( ".x BDTBoostWatch.C+(\"%s\")", fName ),
|
240 |
// "Plots separation obtained by BDT method as function of boosting steps (macro BDTBoostWatch.C(itree,...))",
|
241 |
// buttonType, "BDT" );
|
242 |
|
243 |
// ActionButton( cbar,
|
244 |
// Form( "(%i) Rule Ensemble Importance Plots (RuleFit)", ++ic ),
|
245 |
// Form( ".x rulevis.C(\"%s\",0)", fName ),
|
246 |
// "Plots all input variables with rule ensemble weights, including linear terms (macro rulevis.C)",
|
247 |
// buttonType, "RuleFit" );
|
248 |
|
249 |
title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
|
250 |
ActionButton( cbar,
|
251 |
title,
|
252 |
".x PlotFoams.C",
|
253 |
"Plot Foams (macro PlotFoams.C)",
|
254 |
buttonType, "PDEFoam" );
|
255 |
|
256 |
title = Form( "(%i) General Boost Control Plots", ++ic );
|
257 |
ActionButton( cbar,
|
258 |
title,
|
259 |
Form( ".x BoostControlPlots.C(\"%s\")", fName ),
|
260 |
"Plots to monitor boosting of general classifiers (macro BoostControlPlots.C)",
|
261 |
buttonType, "Boost" );
|
262 |
|
263 |
cbar->AddSeparator();
|
264 |
|
265 |
cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
|
266 |
|
267 |
// set the style
|
268 |
cbar->SetTextColor("black");
|
269 |
|
270 |
// there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
|
271 |
// cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
|
272 |
|
273 |
// draw
|
274 |
cbar->Show();
|
275 |
|
276 |
// indicate inactive buttons
|
277 |
for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState(TMVAGui_inactiveButtons[i], 3 );
|
278 |
if (TMVAGui_inactiveButtons.size() > 0) {
|
279 |
cout << "=== Note: inactive buttons indicate classifiers that were not trained, ===" << endl;
|
280 |
cout << "=== or functionalities that were not invoked during the training ===" << endl;
|
281 |
}
|
282 |
|
283 |
gROOT->SaveContext();
|
284 |
}
|