ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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
18 static std::vector<TString> TMVAGui_inactiveButtons;
19 
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
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 )
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  // find all references
83  TMVAGui_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 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 = GetKeyList( "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  ActionButton( cbar,
112  Form( "(%i%c) %s", ic, ch++, title.Data() ),
113  Form( "TMVA::variables(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
114  Form( "Plots all '%s'-transformed input variables (macro variables(...))", 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  ActionButton( cbar,
127  Form( "(%i%c) %s", ic, ch++, title.Data() ),
128  Form( "TMVA::CorrGui(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
129  Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui(...))",
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  ActionButton( cbar,
138  title,
139  Form( "TMVA::correlations(\"%s\")", fName ),
140  "Plots signal and background correlation summaries for all input variables (macro correlations.C)",
141  buttonType );
142 
143  title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
144  ActionButton( cbar,
145  title,
146  Form( "TMVA::mvas(\"%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  ActionButton( cbar,
152  title,
153  Form( "TMVA::mvas(\"%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  ActionButton( cbar,
159  title,
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  ActionButton( cbar,
166  title,
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  title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
172  ActionButton( cbar,
173  title,
174  Form( "TMVA::mvaeffs(\"%s\")", fName ),
175  "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.cxx)",
176  buttonType, defaultRequiredClassifier );
177 
178  title = Form( "(%ib) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ic );
179  ActionButton( cbar,
180  title,
181  Form( "TMVA::efficiencies(\"%s\")", fName ),
182  "Plots background rejection vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
183  buttonType, defaultRequiredClassifier );
184 
185  title = Form( "(%ib) Classifier 1/(Backgr. Efficiency) vs Signal Efficiency (ROC curve)", ic );
186  ActionButton( cbar,
187  title,
188  Form( "TMVA::efficiencies(\"%s\",%d)", fName, 3 ),
189  "Plots 1/(background eff.) vs signal efficiencies (macro efficiencies.cxx) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
190  buttonType, defaultRequiredClassifier );
191 
192  title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
193  ActionButton( cbar,
194  title,
195  Form( "TMVA::paracoor(\"%s\")", fName ),
196  "Plots parallel coordinates for classifiers and input variables (macro paracoor.cxx, requires ROOT >= 5.17)",
197  buttonType, defaultRequiredClassifier );
198 
199  // parallel coordinates only exist since ROOT 5.17
200  #if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0)
201  TMVAGui_inactiveButtons.push_back( title );
202  #endif
203 
204  title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
205  ActionButton( cbar,
206  title,
207  Form( "TMVA::probas(\"%s\")", fName ),
208  "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.cxx)",
209  buttonType, defaultRequiredClassifier );
210 
211  title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
212  ActionButton( cbar,
213  title,
214  Form( "TMVA::likelihoodrefs(\"%s\")", fName ),
215  "Plots to verify the likelihood reference distributions (macro likelihoodrefs.cxx)",
216  buttonType, "Likelihood" );
217 
218  title = Form( "(%ia) Network Architecture (MLP)", ++ic );
219  TString call = Form( "TMVA::network(\"%s\")", fName );
220  ActionButton( cbar,
221  title,
222  call,
223  "Plots the MLP weights (macro network.cxx)",
224  buttonType, "MLP" );
225 
226  title = Form( "(%ib) Network Convergence Test (MLP)", ic );
227  ActionButton( cbar,
228  title,
229  Form( "TMVA::annconvergencetest(\"%s\")", fName ),
230  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)",
231  buttonType, "MLP" );
232 
233  title = Form( "(%i) Decision Trees (BDT)", ++ic );
234  ActionButton( cbar,
235  title,
236  Form( "TMVA::BDT(\"%s\")", fName ),
237  "Plots the Decision Trees trained by BDT algorithms (macro BDT(itree,...))",
238  buttonType, "BDT" );
239 
240  title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
241  ActionButton( cbar,
242  title,
243  Form( "TMVA::BDTControlPlots(\"%s\")", fName ),
244  "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.cxx)",
245  buttonType, "BDT" );
246  // ActionButton( cbar,
247  // Form( "(%i) Rule Ensemble Importance Plots (RuleFit)", ++ic ),
248  // Form( "TMVA::rulevis(\"%s\",0)", fName ),
249  // "Plots all input variables with rule ensemble weights, including linear terms (macro rulevis.cxx)",
250  // buttonType, "RuleFit" );
251 
252  title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
253  ActionButton( cbar,
254  title,
255  Form("TMVA::PlotFoams(\"weights/TMVAClassification_PDEFoam.weights_foams.root\")"),
256  "Plot Foams (macro PlotFoams.cxx)",
257  buttonType, "PDEFoam" );
258 
259  title = Form( "(%i) General Boost Control Plots", ++ic );
260  ActionButton( cbar,
261  title,
262  Form( "TMVA::BoostControlPlots(\"%s\")", fName ),
263  "Plots to monitor boosting of general classifiers (macro BoostControlPlots)",
264  buttonType, "Boost" );
265 
266  cbar->AddSeparator();
267 
268  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
269 
270  // set the style
271  cbar->SetTextColor("black");
272 
273  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
274  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
275 
276  // draw
277  cbar->Show();
278 
279  // indicate inactive buttons
280  for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState(TMVAGui_inactiveButtons[i], 3 );
281  if (TMVAGui_inactiveButtons.size() > 0) {
282  cout << "=== Note: inactive buttons indicate classifiers that were not trained, ===" << endl;
283  cout << "=== or functionalities that were not invoked during the training ===" << endl;
284  }
285 
286  gROOT->SaveContext();
287 }
void Show()
Show control bar.
void AddButton(TControlBarButton *button)
Add button.
TList * GetKeyList(const TString &pattern)
Definition: TMVAGui.cxx:20
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
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
void TMVAGui(const char *fName="TMVA.root")
Definition: TMVAGui.cxx:52
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
A doubly linked list.
Definition: TList.h:47
void ActionButton(TControlBar *cbar, const TString &title, const TString &macro, const TString &comment, const TString &buttonType, TString requiredKey="")
Definition: TMVAGui.cxx:33
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
virtual const char * GetIncludePath()
Get the list of include path.
Definition: TSystem.cxx:3728
tuple file
Definition: fildir.py:20
static std::vector< TString > TMVAGui_inactiveButtons
Definition: TMVAGui.cxx:18
virtual void Add(TObject *obj)
Definition: TList.h:81
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
static TList * TMVAGui_keyContent
Definition: TMVAGui.cxx:17
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
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