ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 )
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  // find all references
83  TMVAMultiClassGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
84 
85  //close file
86  file->Close();
87 
88  TString defaultRequiredClassifier = "";
89 
90  // gROOT->Reset();
91  // gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
92 
93  // create the control bar
94  TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Multiclass Classification", 0, 0 );
95 
96  const TString buttonType( "button" );
97 
98  // configure buttons
99  Int_t ic = 1;
100 
101  // find all input variables types
102  TList* keylist = MultiClassGetKeyList( "InputVariables" );
103  TListIter it( keylist );
104  TObjString* str = 0;
105  char ch = 'a';
106  while ((str = (TObjString*)it())) {
107  TString tmp = str->GetString();
108  TString title = Form( "Input variables '%s'-transformed (training sample)",
109  tmp.ReplaceAll("InputVariables_","").Data() );
110  if (tmp.Contains( "Id" )) title = "Input variables (training sample)";
111  MultiClassActionButton( cbar,
112  Form( "(%i%c) %s", ic, ch++, title.Data() ),
113  Form( "TMVA::variablesMultiClass(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
114  Form( "Plots all '%s'-transformed input variables (macro variablesMultiClass(...))", str->GetString().Data() ),
115  buttonType, str->GetString() );
116  }
117  ic++;
118 
119  // correlation scatter plots
120  it.Reset(); ch = 'a';
121  while ((str = (TObjString*)it())) {
122  TString tmp = str->GetString();
123  TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
124  tmp.ReplaceAll("InputVariables_","").Data() );
125  if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
126  MultiClassActionButton( cbar,
127  Form( "(%i%c) %s", ic, ch++, title.Data() ),
128  Form( "TMVA::CorrGuiMultiClass(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
129  Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGuiMultiClass(...))",
130  str->GetString().Data() ),
131  buttonType, str->GetString() );
132  }
133 
134  TString title;
135  // coefficients
136  title =Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic );
137  MultiClassActionButton( cbar,
138  title,
139  Form( "TMVA::correlationsMultiClass(\"%s\")", fName ),
140  "Plots signal and background correlation summaries for all input variables (macro correlationsMultiClass.cxx)",
141  buttonType );
142 
143  title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
144  MultiClassActionButton( cbar,
145  title,
146  Form( "TMVA::mvasMulticlass(\"%s\",TMVA::kMVAType)", fName ),
147  "Plots the output of each classifier for the test data (macro mvas(...,0))",
148  buttonType, defaultRequiredClassifier );
149 
150  title =Form( "(%ib) Classifier Output Distributions (test and training samples superimposed)", ic );
151  MultiClassActionButton( cbar,
152  title,
153  Form( "TMVA::mvasMulticlass(\"%s\",TMVA::kCompareType)", fName ),
154  "Plots the output of each classifier for the test (histograms) and training (dots) data (macro mvas(...,3))",
155  buttonType, defaultRequiredClassifier );
156  /*
157  title = Form( "(%ic) Classifier Probability Distributions (test sample)", ic );
158  MultiClassActionButton( cbar,
159  Form( "(%ic) Classifier Probability Distributions (test sample)", ic ),
160  Form( "TMVA::mvas(\"%s\",TMVA::kProbaType)", fName ),
161  "Plots the probability of each classifier for the test data (macro mvas(...,1))",
162  buttonType, defaultRequiredClassifier );
163 
164  title =Form( "(%id) Classifier Rarity Distributions (test sample)", ic );
165  MultiClassActionButton( cbar,
166  Form( "(%id) Classifier Rarity Distributions (test sample)", ic ),
167  Form( "TMVA::mvas(\"%s\",TMVA::kRarityType)", fName ),
168  "Plots the Rarity of each classifier for the test data (macro mvas(...,2)) - background distribution should be uniform",
169  buttonType, defaultRequiredClassifier );
170 
171 
172  title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
173  MultiClassActionButton( cbar,
174  title,
175  Form( "TMVA::mvaeffs(\"%s\")", fName ),
176  "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.cxx)",
177  buttonType, defaultRequiredClassifier );
178 
179  title = Form( "(%ib) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ic );
180  MultiClassActionButton( cbar,
181  title,
182  Form( "TMVA::efficiencies(\"%s\")", fName ),
183  "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
184  buttonType, defaultRequiredClassifier );
185 
186 
187  title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
188  MultiClassActionButton( cbar,
189  title,
190  Form( "TMVA::paracoor(\"%s\")", fName ),
191  "Plots parallel coordinates for classifiers and input variables (macro paracoor.cxx, requires ROOT >= 5.17)",
192  buttonType, defaultRequiredClassifier );
193 
194  // parallel coordinates only exist since ROOT 5.17
195  #if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0)
196  TMVAMultiClassGui_inactiveButtons.push_back( title );
197  #endif
198 
199 
200  title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
201  MultiClassActionButton( cbar,
202  title,
203  Form( "TMVA::probas(\"%s\")", fName ),
204  "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.cxx)",
205  buttonType, defaultRequiredClassifier );
206 
207  title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
208  MultiClassActionButton( cbar,
209  title,
210  Form( "TMVA::likelihoodrefs(\"%s\")", fName ),
211  "Plots to verify the likelihood reference distributions (macro likelihoodrefs.cxx)",
212  buttonType, "Likelihood" );
213  */
214 
215  title = Form( "(%ia) Network Architecture (MLP)", ++ic );
216  TString call = Form( "TMVA::network(\"%s\")", fName );
217  MultiClassActionButton( cbar,
218  title,
219  call,
220  "Plots the MLP weights (macro network.cxx)",
221  buttonType, "MLP" );
222 
223  title = Form( "(%ib) Network Convergence Test (MLP)", ic );
224  MultiClassActionButton( cbar,
225  title,
226  Form( "TMVA::annconvergencetest(\"%s\")", fName ),
227  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
228  buttonType, "MLP" );
229 
230  title = Form( "(%i) Decision Trees (BDT)", ++ic );
231  MultiClassActionButton( cbar,
232  title,
233  Form( "TMVA::BDT(\"%s\")", fName ),
234  "Plots the Decision Trees trained by BDT algorithms (macro BDT(itree,...))",
235  buttonType, "BDT" );
236 
237  /*
238  title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
239  MultiClassActionButton( cbar,
240  title,
241  Form( "TMVA::BDTControlPlots(\"%s\")", fName ),
242  "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.cxx)",
243  buttonType, "BDT" );
244 
245  */
246  title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
247  MultiClassActionButton( cbar,
248  title,
249  "TMVA::PlotFoams(\"weights/TMVAMulticlass_PDEFoam.weights_foams.root\")",
250  "Plot Foams (macro PlotFoams.cxx)",
251  buttonType, "PDEFoam" );
252  /*
253  title = Form( "(%i) General Boost Control Plots", ++ic );
254  MultiClassActionButton( cbar,
255  title,
256  Form( "TMVA::BoostControlPlots(\"%s\")", fName ),
257  "Plots to monitor boosting of general classifiers (macro BoostControlPlots.cxx)",
258  buttonType, "Boost" );
259  */
260  cbar->AddSeparator();
261 
262  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
263 
264  // set the style
265  cbar->SetTextColor("black");
266 
267  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
268  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
269 
270  // draw
271  cbar->Show();
272 
273  // indicate inactive buttons
274  for (UInt_t i=0; i<TMVAMultiClassGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAMultiClassGui_inactiveButtons[i], 3 );
275  if (TMVAMultiClassGui_inactiveButtons.size() > 0) {
276  std::cout << "=== Note: inactive buttons indicate that the corresponding classifiers were not trained ===" << std::endl;
277  }
278 
279  gROOT->SaveContext();
280 }
void Show()
Show control bar.
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:37
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Collectable string class.
Definition: TObjString.h:32
void MultiClassActionButton(TControlBar *cbar, const TString &title, const TString &macro, const TString &comment, const TString &buttonType, TString requiredKey="")
static const std::string comment("comment")
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
virtual TList * GetListOfKeys() const
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
#define gROOT
Definition: TROOT.h:344
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Iterator of linked list.
Definition: TList.h:187
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:3851
virtual TObject * Clone(const char *newname="") const
Make a clone of an collection using the Streamer facility.
const char * Data() const
Definition: TString.h:349
static const std::string pattern("pattern")
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
void TMVAMultiClassGui(const char *fName="TMVAMulticlass.root")
A doubly linked list.
Definition: TList.h:47
TString GetString() const
Definition: TObjString.h:50
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
unsigned int UInt_t
Definition: RtypesCore.h:42
char * Form(const char *fmt,...)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
static TList * TMVAMultiClassGui_keyContent
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3728
tuple file
Definition: fildir.py:20
virtual void Add(TObject *obj)
Definition: TList.h:81
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
void AddSeparator()
Add separator.
void Reset()
Reset list iterator.
Definition: TList.cxx:977
void SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button 'label'; possible states are 0-kButtonUp, 1-kButtonDown, 2-kButtonEngaged, 3-kButtonDisabled,.
const Bool_t kTRUE
Definition: Rtypes.h:91
TList * MultiClassGetKeyList(const TString &pattern)
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:3930
virtual void Close(Option_t *option="")
Close a file.
Definition: TFile.cxx:898