Logo ROOT   6.10/09
Reference Guide
TMVAMultiClassGui.cxx
Go to the documentation of this file.
2 #include <iostream>
3 #include <vector>
4 
5 #include "TList.h"
6 #include "TROOT.h"
7 #include "TKey.h"
8 #include "TString.h"
9 #include "TControlBar.h"
10 #include "TObjString.h"
11 
12 
13 
14 // some global lists
16 static std::vector<TString> TMVAMultiClassGui_inactiveButtons;
17 
18 TList* TMVA::MultiClassGetKeyList( const TString& pattern )
19 {
20  TList* list = new TList();
21 
22  TIter next( TMVAMultiClassGui_keyContent );
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;
40  TIter next( TMVAMultiClassGui_keyContent );
41  TKey* key(0);
42  while ((key = (TKey*)next())) {
43  if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
44  }
45  if (!found) TMVAMultiClassGui_inactiveButtons.push_back( title );
46  }
47 }
48 
49 // main GUI
50 void TMVA::TMVAMultiClassGui(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.cxx),
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  //std::cout <<"inc path="<<curIncludePath<<std::endl;
67  TString newIncludePath=TString("-I../ ")+curIncludePath;
68  gSystem->SetIncludePath(newIncludePath);
69  std::cout <<"new include path="<<gSystem->GetIncludePath()<<std::endl;
70 
71  std::cout << "--- Launch TMVA GUI to view input file: " << fName << std::endl;
72 
73  // init
74  TMVAMultiClassGui_inactiveButtons.clear();
75 
76  // check if file exist
77  TFile* file = TFile::Open( fName );
78  if (!file) {
79  std::cout << "==> Abort TMVAMultiClassGui, please verify filename" << std::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::TMVAMultiClassGui(\"%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  TMVAMultiClassGui_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 Multiclass 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 = MultiClassGetKeyList( "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  MultiClassActionButton( cbar,
146  Form( "(%i%c) %s", ic, ch++, title.Data() ),
147  Form( "TMVA::variablesMultiClass(\"%s\",\"%s\",\"%s\",\"%s\")",dataset.Data(), fName, str->GetString().Data(), title.Data() ),
148  Form( "Plots all '%s'-transformed input variables (macro variablesMultiClass(...))", 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  MultiClassActionButton( cbar,
161  Form( "(%i%c) %s", ic, ch++, title.Data() ),
162  Form( "TMVA::CorrGuiMultiClass(\"%s\",\"%s\",\"%s\",\"%s\")",dataset.Data() , fName, str->GetString().Data(), title.Data() ),
163  Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGuiMultiClass(...))",
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  MultiClassActionButton( cbar,
172  title,
173  Form( "TMVA::correlationsMultiClass(\"%s\",\"%s\")",dataset.Data(), fName ),
174  "Plots signal and background correlation summaries for all input variables (macro correlationsMultiClass.cxx)",
175  buttonType );
176 
177  title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
178  MultiClassActionButton( cbar,
179  title,
180  Form( "TMVA::mvasMulticlass(\"%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  MultiClassActionButton( cbar,
186  title,
187  Form( "TMVA::mvasMulticlass(\"%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  MultiClassActionButton( cbar,
193  Form( "(%ic) Classifier Probability Distributions (test sample)", ic ),
194  Form( "TMVA::mvas(\"%s\",TMVA::kProbaType)", 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  MultiClassActionButton( cbar,
200  Form( "(%id) Classifier Rarity Distributions (test sample)", ic ),
201  Form( "TMVA::mvas(\"%s\",TMVA::kRarityType)", fName ),
202  "Plots the Rarity of each classifier for the test data (macro mvas(...,2)) - background distribution should be
203  uniform", buttonType, defaultRequiredClassifier );
204 
205 
206  title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
207  MultiClassActionButton( cbar,
208  title,
209  Form( "TMVA::mvaeffs(\"%s\")", fName ),
210  "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.cxx)",
211  buttonType, defaultRequiredClassifier );
212  */
213 
214  title = Form("(%i) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ++ic);
215  MultiClassActionButton(cbar, title, Form("TMVA::efficienciesMulticlass(\"%s\", \"%s\")", dataset.Data(), fName),
216  "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands "
217  "for \"Receiver Operation Characteristics\"]",
218  buttonType, defaultRequiredClassifier);
219 
220  /*
221  title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
222  MultiClassActionButton( cbar,
223  title,
224  Form( "TMVA::paracoor(\"%s\")", fName ),
225  "Plots parallel coordinates for classifiers and input variables (macro paracoor.cxx, requires ROOT >= 5.17)",
226  buttonType, defaultRequiredClassifier );
227 
228  // parallel coordinates only exist since ROOT 5.17
229  #if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0)
230  TMVAMultiClassGui_inactiveButtons.push_back( title );
231  #endif
232 
233 
234  title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
235  MultiClassActionButton( cbar,
236  title,
237  Form( "TMVA::probas(\"%s\")", fName ),
238  "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.cxx)",
239  buttonType, defaultRequiredClassifier );
240 
241  title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
242  MultiClassActionButton( cbar,
243  title,
244  Form( "TMVA::likelihoodrefs(\"%s\")", fName ),
245  "Plots to verify the likelihood reference distributions (macro likelihoodrefs.cxx)",
246  buttonType, "Likelihood" );
247  */
248 
249  title = Form( "(%ia) Network Architecture (MLP)", ++ic );
250  TString call = Form( "TMVA::network(\"%s\",\"%s\")",dataset.Data() , fName );
251  MultiClassActionButton( cbar,
252  title,
253  call,
254  "Plots the MLP weights (macro network.cxx)",
255  buttonType, "MLP" );
256 
257  title = Form( "(%ib) Network Convergence Test (MLP)", ic );
258  MultiClassActionButton( cbar,
259  title,
260  Form( "TMVA::annconvergencetest(\"%s\",\"%s\")",dataset.Data() , fName ),
261  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
262  buttonType, "MLP" );
263 
264  title = Form( "(%i) Decision Trees (BDT)", ++ic );
265  MultiClassActionButton( cbar,
266  title,
267  Form( "TMVA::BDT(\"%s\",\"%s\")",dataset.Data() , fName ),
268  "Plots the Decision Trees trained by BDT algorithms (macro BDT(itree,...))",
269  buttonType, "BDT" );
270 
271  /*
272  title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
273  MultiClassActionButton( cbar,
274  title,
275  Form( "TMVA::BDTControlPlots(\"%s\")", fName ),
276  "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.cxx)",
277  buttonType, "BDT" );
278 
279  */
280  title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
281  MultiClassActionButton( cbar,
282  title,
283  Form("TMVA::PlotFoams(\"%s/weights/TMVAMulticlass_PDEFoam.weights_foams.root\")",dataset.Data()),
284  "Plot Foams (macro PlotFoams.cxx)",
285  buttonType, "PDEFoam" );
286  /*
287  title = Form( "(%i) General Boost Control Plots", ++ic );
288  MultiClassActionButton( cbar,
289  title,
290  Form( "TMVA::BoostControlPlots(\"%s\")", fName ),
291  "Plots to monitor boosting of general classifiers (macro BoostControlPlots.cxx)",
292  buttonType, "Boost" );
293  */
294  cbar->AddSeparator();
295 
296  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
297 
298  // set the style
299  cbar->SetTextColor("black");
300 
301  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
302  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
303 
304  // draw
305  cbar->Show();
306 
307  // indicate inactive buttons
308  for (UInt_t i=0; i<TMVAMultiClassGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAMultiClassGui_inactiveButtons[i], 3 );
309  if (TMVAMultiClassGui_inactiveButtons.size() > 0) {
310  std::cout << "=== Note: inactive buttons indicate that the corresponding classifiers were not trained ===" << std::endl;
311  }
312 
313  gROOT->SaveContext();
314 }
void Show()
Show control bar.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void AddButton(TControlBarButton *button)
Add button.
static std::vector< TString > TMVAMultiClassGui_inactiveButtons
A Control Bar is a fully user configurable tool which provides fast access to frequently used operati...
Definition: TControlBar.h:22
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
Collectable string class.
Definition: TObjString.h:28
void MultiClassActionButton(TControlBar *cbar, const TString &title, const TString &macro, const TString &comment, const TString &buttonType, TString requiredKey="")
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:640
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:46
virtual Int_t GetEntries() const
Definition: TCollection.h:86
#define gROOT
Definition: TROOT.h:375
UInt_t GetListOfKeys(TList &keys, TString inherits, TDirectory *dir=0)
Definition: tmvaglob.cxx:375
Basic string class.
Definition: TString.h:129
TList * MultiClassGetKeyList(const TString &pattern)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Iterator of linked list.
Definition: TList.h:183
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3909
void TMVAMultiClassGui(const char *fName="TMVAMulticlass.root", TString dataset="")
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
void SetButtonWidth(UInt_t width)
Sets the width in pixels for control bar button.
A doubly linked list.
Definition: TList.h:43
const TString & GetString() const
Definition: TObjString.h:47
R__EXTERN TSystem * gSystem
Definition: TSystem.h:539
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:294
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:315
virtual TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory named "apath".
const Bool_t kFALSE
Definition: RtypesCore.h:92
static TList * TMVAMultiClassGui_keyContent
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3805
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:572
virtual void Add(TObject *obj)
Definition: TList.h:77
Definition: file.py:1
virtual TList * GetListOfKeys() const
void AddSeparator()
Add separator.
void Reset()
Reset list iterator.
Definition: TList.cxx:981
void SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button &#39;label&#39;; possible states are 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,.
Bool_t IsWhitespace() const
Definition: TString.h:386
const Bool_t kTRUE
Definition: RtypesCore.h:91
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:4007
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:904
const char * Data() const
Definition: TString.h:347