Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMVAGui.cxx
Go to the documentation of this file.
1#include "TMVA/TMVAGui.h"
2#include "TMVA/Types.h"
3#include <iostream>
4#include <vector>
5
6#include "TList.h"
7#include "TROOT.h"
8#include "TKey.h"
9#include "TString.h"
10#include "TControlBar.h"
11#include "TObjString.h"
12
13
14// some global lists
16static std::vector<TString> TMVAGui_inactiveButtons;
17
18TList* TMVA::GetKeyList( const TString& pattern )
19{
20 TList* list = new TList();
21
23 TKey* key(0);
24 while ((key = (TKey*)next())) {
25 if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
26 }
27 return list;
28}
29
30// utility function
32 const TString& title, const TString& macro, const TString& comment,
33 const TString& buttonType, TString requiredKey )
34{
35 cbar->AddButton( title, macro, comment, buttonType );
36
37 // search
38 if (requiredKey != "") {
39 Bool_t found = kFALSE;
41 TKey* key(0);
42 while ((key = (TKey*)next())) {
43 if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
44 }
45 if (!found) TMVAGui_inactiveButtons.push_back( title );
46 }
47}
48
49// main GUI
50void TMVA::TMVAGui( const char* fName , TString dataset)
51{
52 // Use this script in order to run the various individual macros
53 // that plot the output of TMVA (e.g. running TMVAClassification.C),
54 // stored in the file "TMVA.root"
55
56 TString curMacroPath(gROOT->GetMacroPath());
57 // uncomment next line for macros submitted to next root version
58 gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
59
60 // for the sourceforge version, including $ROOTSYS/tmva/test in the
61 // macro path is a mistake, especially if "./" was not part of path
62 // add ../macros to the path (comment out next line for the ROOT version of TMVA)
63 // gROOT->SetMacroPath(curMacroPath+":../macros:");
64
65 TString curIncludePath=gSystem->GetIncludePath();
66 TString newIncludePath=TString("-I../ ")+curIncludePath;
67 gSystem->SetIncludePath(newIncludePath);
68
69 cout << "--- Launch TMVA GUI to view input file: " << fName << endl;
70
71 // init
73
74 // check if file exist
75 TFile* file = TFile::Open( fName );
76 if (!file) {
77 cout << "==> Abort TMVAGui, please verify filename" << endl;
78 return;
79 }
80
81 if(file->GetListOfKeys()->GetEntries()<=0)
82 {
83 cout << "==> Abort TMVAGui, please verify if dataset exist" << endl;
84 return;
85 }
86 if( (dataset==""||dataset.IsWhitespace()) && (file->GetListOfKeys()->GetEntries()==1))
87 {
88 TKey *key=(TKey*)file->GetListOfKeys()->At(0);
89 dataset=key->GetName();
90 }else if((dataset==""||dataset.IsWhitespace()) && (file->GetListOfKeys()->GetEntries()>=1))
91 {
92 gROOT->Reset();
93 gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
94
95 TControlBar *bar=new TControlBar("vertical","Select dataset", 0, 0);
96 bar->SetButtonWidth(300);
97 for(int i=0;i<file->GetListOfKeys()->GetEntries();i++)
98 {
99 TKey *key=(TKey*)file->GetListOfKeys()->At(i);
100 dataset=key->GetName();
101 bar->AddButton(dataset.Data(),Form("TMVA::TMVAGui(\"%s\",\"%s\")",fName,dataset.Data()),dataset.Data());
102 }
103
104 bar->AddSeparator();
105 bar->AddButton( "Quit", ".q", "Quit", "button");
106
107 // set the style
108 bar->SetTextColor("black");
109 bar->Show();
110 gROOT->SaveContext();
111 return ;
112 }
113
114 // find all references
115 TMVAGui_keyContent = (TList*)file->GetDirectory(dataset.Data())->GetListOfKeys()->Clone();
116
117 // close file
118 file->Close();
119
120 TString defaultRequiredClassifier = "";
121
122 // gROOT->Reset();
123 // gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
124
125 // create the control bar
126 TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Classification", 0, 0 );
127
128 const TString buttonType( "button" );
129
130 // configure buttons
131 Int_t ic = 1;
132
133 // find all input variables types
134 TList* keylist = GetKeyList( "InputVariables" );
135 TListIter it( keylist );
136 TObjString* str = 0;
137 char ch = 'a';
138 while ((str = (TObjString*)it())) {
139 TString tmp = str->GetString();
140 TString title = Form( "Input variables '%s'-transformed (training sample)",
141 tmp.ReplaceAll("InputVariables_","").Data() );
142 if (tmp.Contains( "Id" )) title = "Input variables (training sample)";
143 ActionButton( cbar,
144 Form( "(%i%c) %s", ic, ch++, title.Data() ),
145 Form( "TMVA::variables(\"%s\",\"%s\",\"%s\",\"%s\")",dataset.Data(), fName, str->GetString().Data(), title.Data() ),
146 Form( "Plots all '%s'-transformed input variables (macro variables(...))", str->GetString().Data() ),
147 buttonType, str->GetString() );
148 }
149 ic++;
150
151 // correlation scatter plots
152 it.Reset(); ch = 'a';
153 while ((str = (TObjString*)it())) {
154 TString tmp = str->GetString();
155 TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
156 tmp.ReplaceAll("InputVariables_","").Data() );
157 if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
158 ActionButton( cbar,
159 Form( "(%i%c) %s", ic, ch++, title.Data() ),
160 Form( "TMVA::CorrGui(\"%s\",\"%s\",\"%s\",\"%s\")",dataset.Data(), fName, str->GetString().Data(), title.Data() ),
161 Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui(...))",
162 str->GetString().Data() ),
163 buttonType, str->GetString() );
164 }
165
166 TString title;
167 // coefficients
168 title =Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic );
169 ActionButton( cbar,
170 title,
171 Form( "TMVA::correlations(\"%s\",\"%s\")",dataset.Data(), fName ),
172 "Plots signal and background correlation summaries for all input variables (macro correlations.C)",
173 buttonType );
174
175 title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
176 ActionButton( cbar,
177 title,
178 Form( "TMVA::mvas(\"%s\",\"%s\", TMVA::kMVAType)",dataset.Data(), fName ),
179 "Plots the output of each classifier for the test data (macro mvas(...,0))",
180 buttonType, defaultRequiredClassifier );
181
182 title =Form( "(%ib) Classifier Output Distributions (test and training samples superimposed)", ic );
183 ActionButton( cbar,
184 title,
185 Form( "TMVA::mvas(\"%s\",\"%s\", TMVA::kCompareType )",dataset.Data(), fName),
186 "Plots the output of each classifier for the test (histograms) and training (dots) data (macro mvas(...,3))",
187 buttonType, defaultRequiredClassifier );
188
189 title = Form( "(%ic) Classifier Probability Distributions (test sample)", ic );
190 ActionButton( cbar,
191 title,
192 Form( "TMVA::mvas(\"%s\",\"%s\", TMVA::kProbaType)",dataset.Data(), fName ),
193 "Plots the probability of each classifier for the test data (macro mvas(...,1))",
194 buttonType, defaultRequiredClassifier );
195
196 title =Form( "(%id) Classifier Rarity Distributions (test sample)", ic );
197 ActionButton( cbar,
198 title,
199 Form( "TMVA::mvas(\"%s\",\"%s\", TMVA::kRarityType)",dataset.Data(), fName ),
200 "Plots the Rarity of each classifier for the test data (macro mvas(...,2)) - background distribution should be uniform",
201 buttonType, defaultRequiredClassifier );
202
203 title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
204 ActionButton( cbar,
205 title,
206 Form( "TMVA::mvaeffs(\"%s\",\"%s\")",dataset.Data(), fName ),
207 "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.cxx)",
208 buttonType, defaultRequiredClassifier );
209
210 title = Form( "(%ib) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ic );
211 ActionButton( cbar,
212 title,
213 Form( "TMVA::efficiencies(\"%s\",\"%s\")",dataset.Data(), fName ),
214 "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
215 buttonType, defaultRequiredClassifier );
216
217 title = Form( "(%ib) Classifier 1/(Backgr. Efficiency) vs Signal Efficiency (ROC curve)", ic );
218 ActionButton( cbar,
219 title,
220 Form( "TMVA::efficiencies(\"%s\",\"%s\",%d)",dataset.Data(), fName, 3 ),
221 "Plots 1/(background eff.) vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
222 buttonType, defaultRequiredClassifier );
223
224 title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
225 ActionButton( cbar,
226 title,
227 Form( "TMVA::paracoor(\"%s\",\"%s\")",dataset.Data(), fName ),
228 "Plots parallel coordinates for classifiers and input variables (macro paracoor.cxx, requires ROOT >= 5.17)",
229 buttonType, defaultRequiredClassifier );
230
231 title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
232 ActionButton( cbar,
233 title,
234 Form( "TMVA::probas(\"%s\",\"%s\")",dataset.Data(), fName ),
235 "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.cxx)",
236 buttonType, defaultRequiredClassifier );
237
238 title = Form( "(%i) Training History", ++ic );
239 ActionButton( cbar,
240 title,
241 Form( "TMVA::training_history(\"%s\",\"%s\")",dataset.Data(), fName ),
242 "Plot training history of classifiers with multiple passed (eg Neural Networks) ",
243 buttonType, defaultRequiredClassifier );
244
245 title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
246 ActionButton( cbar,
247 title,
248 Form( "TMVA::likelihoodrefs(\"%s\",\"%s\")",dataset.Data(), fName ),
249 "Plots to verify the likelihood reference distributions (macro likelihoodrefs.cxx)",
250 buttonType, "Likelihood" );
251
252 title = Form( "(%ia) Network Architecture (MLP)", ++ic );
253 TString call = Form( "TMVA::network(\"%s\",\"%s\")", dataset.Data(),fName );
254 ActionButton( cbar,
255 title,
256 call,
257 "Plots the MLP weights (macro network.cxx)",
258 buttonType, "MLP" );
259
260 title = Form( "(%ib) Network Convergence Test (MLP)", ic );
261 ActionButton( cbar,
262 title,
263 Form( "TMVA::annconvergencetest(\"%s\",\"%s\")",dataset.Data(), fName ),
264 "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)",
265 buttonType, "MLP" );
266
267 title = Form( "(%i) Decision Trees (BDT)", ++ic );
268 ActionButton( cbar,
269 title,
270 Form( "TMVA::BDT(\"%s\",\"%s\")",dataset.Data() , fName ),
271 "Plots the Decision Trees trained by BDT algorithms (macro BDT(itree,...))",
272 buttonType, "BDT" );
273
274 title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
275 ActionButton( cbar,
276 title,
277 Form( "TMVA::BDTControlPlots(\"%s\",\"%s\")",dataset.Data() , fName ),
278 "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.cxx)",
279 buttonType, "BDT" );
280 // ActionButton( cbar,
281 // Form( "(%i) Rule Ensemble Importance Plots (RuleFit)", ++ic ),
282 // Form( "TMVA::rulevis(\"%s\",0)", fName ),
283 // "Plots all input variables with rule ensemble weights, including linear terms (macro rulevis.cxx)",
284 // buttonType, "RuleFit" );
285
286 title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
287 ActionButton( cbar,
288 title,
289 Form("TMVA::PlotFoams(\"%s/weights/TMVAClassification_PDEFoam.weights_foams.root\")",dataset.Data()),
290 "Plot Foams (macro PlotFoams.cxx)",
291 buttonType, "PDEFoam" );
292
293 title = Form( "(%i) General Boost Control Plots", ++ic );
294 ActionButton( cbar,
295 title,
296 Form( "TMVA::BoostControlPlots(\"%s\",\"%s\")",dataset.Data() , fName ),
297 "Plots to monitor boosting of general classifiers (macro BoostControlPlots)",
298 buttonType, "Boost" );
299
300 cbar->AddSeparator();
301
302 cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
303
304 // set the style
305 cbar->SetTextColor("black");
306
307 // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
308 // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
309
310 // draw
311 cbar->Show();
312
313 // indicate inactive buttons
314 for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState(TMVAGui_inactiveButtons[i], 3 );
315 if (TMVAGui_inactiveButtons.size() > 0) {
316 cout << "=== Note: inactive buttons indicate classifiers that were not trained, ===" << endl;
317 cout << "=== or functionalities that were not invoked during the training ===" << endl;
318 }
319
320 gROOT->SaveContext();
321}
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
const Bool_t kFALSE
Definition RtypesCore.h:101
bool Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:100
static TList * TMVAGui_keyContent
Definition TMVAGui.cxx:15
static std::vector< TString > TMVAGui_inactiveButtons
Definition TMVAGui.cxx:16
#define gROOT
Definition TROOT.h:404
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
Definition TStyle.h:413
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition TControlBar.h:26
void Show()
Show control bar.
void AddSeparator()
Add separator.
void SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button 'label'; possible states are 0-kButtonUp, 1-kButtonDown,...
void SetButtonWidth(UInt_t width)
Sets the width in pixels for control bar button.
void AddButton(TControlBarButton *button)
Add button.
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.:
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition TFile.h:54
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:4025
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
Iterator of linked list.
Definition TList.h:191
A doubly linked list.
Definition TList.h:38
virtual void Add(TObject *obj)
Definition TList.h:81
virtual const char * GetName() const
Returns name of object.
Definition TNamed.h:47
Collectable string class.
Definition TObjString.h:28
const TString & GetString() const
Definition TObjString.h:46
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition TString.h:692
Bool_t IsWhitespace() const
Definition TString.h:408
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:624
void SetScreenFactor(Float_t factor=1)
Definition TStyle.h:303
virtual const char * GetIncludePath()
Get the list of include path.
Definition TSystem.cxx:3971
virtual void SetIncludePath(const char *includePath)
IncludePath should contain the list of compiler flags to indicate where to find user defined header f...
Definition TSystem.cxx:4188
UInt_t GetListOfKeys(TList &keys, TString inherits, TDirectory *dir=0)
Definition tmvaglob.cxx:382
void ActionButton(TControlBar *cbar, const TString &title, const TString &macro, const TString &comment, const TString &buttonType, TString requiredKey="")
TList * GetKeyList(const TString &pattern)
void TMVAGui(const char *fName="TMVA.root", TString dataset="")
Definition file.py:1