Logo ROOT   6.14/05
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 Backgr. Rej. vs Sig. Eff. (1-vs-rest ROC curves)", ++ic);
216  cbar, title, Form("TMVA::efficienciesMulticlass1vsRest(\"%s\", \"%s\")", dataset.Data(), fName),
217  "Plots background rejection vs signal efficiencies (macro efficienciesMulticlass.cxx) [\"ROC\" stands "
218  "for \"Receiver Operation Characteristics\"]",
219  buttonType, defaultRequiredClassifier);
220 
221  // title = Form("(%i) Classifier (1/Backgr. Rejection) vs Sig. Eff. (1-vs-rest ROC curve)", ++ic);
222  // MultiClassActionButton(cbar, title, Form("TMVA::efficienciesMulticlass(\"%s\", \"%s\")", dataset.Data(), fName),
223  // "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands
224  // "
225  // "for \"Receiver Operation Characteristics\"]",
226  // buttonType, defaultRequiredClassifier);
227 
228  title = Form("(%i) Classifier Backgr. Rej. vs Sig. Eff. (1-vs-1 ROC curves)", ++ic);
230  cbar, title, Form("TMVA::efficienciesMulticlass1vs1(\"%s\", \"%s\")", dataset.Data(), fName),
231  "Plots background rejection vs signal efficiencies (macro efficienciesMulticlass.cxx) [\"ROC\" stands "
232  "for \"Receiver Operation Characteristics\"]",
233  buttonType, defaultRequiredClassifier);
234 
235  // title = Form("(%i) Classifier (1/Backgr. Rejection) vs Sig. Eff. (1-vs-1 ROC curve)", ++ic);
236  // MultiClassActionButton(cbar, title, Form("TMVA::efficienciesMulticlass(\"%s\", \"%s\")", dataset.Data(), fName),
237  // "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands
238  // "
239  // "for \"Receiver Operation Characteristics\"]",
240  // buttonType, defaultRequiredClassifier);
241 
242  /*
243  title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
244  MultiClassActionButton( cbar,
245  title,
246  Form( "TMVA::paracoor(\"%s\")", fName ),
247  "Plots parallel coordinates for classifiers and input variables (macro paracoor.cxx, requires ROOT >= 5.17)",
248  buttonType, defaultRequiredClassifier );
249 
250  // parallel coordinates only exist since ROOT 5.17
251  #if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0)
252  TMVAMultiClassGui_inactiveButtons.push_back( title );
253  #endif
254 
255 
256  title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
257  MultiClassActionButton( cbar,
258  title,
259  Form( "TMVA::probas(\"%s\")", fName ),
260  "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.cxx)",
261  buttonType, defaultRequiredClassifier );
262 
263  title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
264  MultiClassActionButton( cbar,
265  title,
266  Form( "TMVA::likelihoodrefs(\"%s\")", fName ),
267  "Plots to verify the likelihood reference distributions (macro likelihoodrefs.cxx)",
268  buttonType, "Likelihood" );
269  */
270 
271  title = Form( "(%ia) Network Architecture (MLP)", ++ic );
272  TString call = Form( "TMVA::network(\"%s\",\"%s\")",dataset.Data() , fName );
273  MultiClassActionButton( cbar,
274  title,
275  call,
276  "Plots the MLP weights (macro network.cxx)",
277  buttonType, "MLP" );
278 
279  title = Form( "(%ib) Network Convergence Test (MLP)", ic );
280  MultiClassActionButton( cbar,
281  title,
282  Form( "TMVA::annconvergencetest(\"%s\",\"%s\")",dataset.Data() , fName ),
283  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
284  buttonType, "MLP" );
285 
286  title = Form( "(%i) Decision Trees (BDT)", ++ic );
287  MultiClassActionButton( cbar,
288  title,
289  Form( "TMVA::BDT(\"%s\",\"%s\")",dataset.Data() , fName ),
290  "Plots the Decision Trees trained by BDT algorithms (macro BDT(itree,...))",
291  buttonType, "BDT" );
292 
293  /*
294  title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
295  MultiClassActionButton( cbar,
296  title,
297  Form( "TMVA::BDTControlPlots(\"%s\")", fName ),
298  "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.cxx)",
299  buttonType, "BDT" );
300 
301  */
302  title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
303  MultiClassActionButton( cbar,
304  title,
305  Form("TMVA::PlotFoams(\"%s/weights/TMVAMulticlass_PDEFoam.weights_foams.root\")",dataset.Data()),
306  "Plot Foams (macro PlotFoams.cxx)",
307  buttonType, "PDEFoam" );
308  /*
309  title = Form( "(%i) General Boost Control Plots", ++ic );
310  MultiClassActionButton( cbar,
311  title,
312  Form( "TMVA::BoostControlPlots(\"%s\")", fName ),
313  "Plots to monitor boosting of general classifiers (macro BoostControlPlots.cxx)",
314  buttonType, "Boost" );
315  */
316  cbar->AddSeparator();
317 
318  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
319 
320  // set the style
321  cbar->SetTextColor("black");
322 
323  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
324  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
325 
326  // draw
327  cbar->Show();
328 
329  // indicate inactive buttons
330  for (UInt_t i=0; i<TMVAMultiClassGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAMultiClassGui_inactiveButtons[i], 3 );
331  if (TMVAMultiClassGui_inactiveButtons.size() > 0) {
332  std::cout << "=== Note: inactive buttons indicate that the corresponding classifiers were not trained ===" << std::endl;
333  }
334 
335  gROOT->SaveContext();
336 }
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:687
R__EXTERN TStyle * gStyle
Definition: TStyle.h:406
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:47
virtual Int_t GetEntries() const
Definition: TCollection.h:177
#define gROOT
Definition: TROOT.h:410
static constexpr double bar
UInt_t GetListOfKeys(TList &keys, TString inherits, TDirectory *dir=0)
Definition: tmvaglob.cxx:375
Basic string class.
Definition: TString.h:131
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:197
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:3976
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:44
const TString & GetString() const
Definition: TObjString.h:47
R__EXTERN TSystem * gSystem
Definition: TSystem.h:540
void SetScreenFactor(Float_t factor=1)
Definition: TStyle.h:297
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:354
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:88
static TList * TMVAMultiClassGui_keyContent
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3872
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
virtual void Add(TObject *obj)
Definition: TList.h:87
Definition: file.py:1
virtual TList * GetListOfKeys() const
void AddSeparator()
Add separator.
void Reset()
Reset list iterator.
Definition: TList.cxx:1157
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:403
const Bool_t kTRUE
Definition: RtypesCore.h:87
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:4074
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:917
const char * Data() const
Definition: TString.h:364