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