Logo ROOT   6.10/09
Reference Guide
TMVARegGui.cxx
Go to the documentation of this file.
1 #include "TMVA/TMVARegGui.h"
2 #include <iostream>
3 #include <vector>
4 
5 #include "TROOT.h"
6 #include "TControlBar.h"
7 
8 
9 // some global lists
11 static std::vector<TString> TMVARegGui_inactiveButtons;
12 
13 
14 TList* TMVA::RegGuiGetKeyList( const TString& pattern )
15 {
16  TList* list = new TList();
17 
18  TIter next( TMVARegGui_keyContent );
19  TKey* key(0);
20  while ((key = (TKey*)next())) {
21  if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
22  }
23  return list;
24 }
25 
26 // utility function
28  const TString& title, const TString& macro, const TString& comment,
29  const TString& buttonType, TString requiredKey)
30 {
31  cbar->AddButton( title, macro, comment, buttonType );
32 
33  // search
34  if (requiredKey != "") {
35  Bool_t found = kFALSE;
36  TIter next( TMVARegGui_keyContent );
37  TKey* key(0);
38  while ((key = (TKey*)next())) {
39  if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
40  }
41  if (!found) TMVARegGui_inactiveButtons.push_back( title );
42  }
43 }
44 
45 // main GUI
46 void TMVA::TMVARegGui( const char* fName ,TString dataset)
47 {
48  // Use this script in order to run the various individual macros
49  // that plot the output of TMVA (e.g. running TMVARegression.cxx),
50  // stored in the file "TMVA.Regroot"
51 
52  TString curMacroPath(gROOT->GetMacroPath());
53  // uncomment next line for macros submitted to next root version
54  gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
55 
56  // for the sourceforge version, including $ROOTSYS/tmva/test in the
57  // macro path is a mistake, especially if "./" was not part of path
58  // add ../macros to the path (comment out next line for the ROOT version of TMVA)
59  // gROOT->SetMacroPath(curMacroPath+":../macros:");
60 
61  TString curIncludePath=gSystem->GetIncludePath();
62  //std::cout <<"inc path="<<curIncludePath<<std::endl;
63  TString newIncludePath=TString("-I../ ")+curIncludePath;
64  gSystem->SetIncludePath(newIncludePath);
65 
66  cout << "--- Launch TMVA GUI to view input file: " << fName << endl;
67 
68  // init
69  TMVARegGui_inactiveButtons.clear();
70 
71  // check if file exist
72  TFile* file = TFile::Open( fName );
73  if (!file) {
74  cout << "==> Abort TMVARegGui, please verify filename" << endl;
75  return;
76  }
77  //
78  if(file->GetListOfKeys()->GetEntries()<=0)
79  {
80  cout << "==> Abort TMVARegGui, please verify if dataset exist" << endl;
81  return;
82  }
83  if( (dataset==""||dataset.IsWhitespace()) && (file->GetListOfKeys()->GetEntries()==1))
84  {
85  TKey *key=(TKey*)file->GetListOfKeys()->At(0);
86  dataset=key->GetName();
87  }else if((dataset==""||dataset.IsWhitespace()) && (file->GetListOfKeys()->GetEntries()>=1))
88  {
89  gROOT->Reset();
90  gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
91 
92  TControlBar *bar=new TControlBar("vertical","Select dataset", 0, 0);
93  bar->SetButtonWidth(300);
94  for(int i=0;i<file->GetListOfKeys()->GetEntries();i++)
95  {
96  TKey *key=(TKey*)file->GetListOfKeys()->At(i);
97  dataset=key->GetName();
98  bar->AddButton(dataset.Data(),Form("TMVA::TMVARegGui(\"%s\",\"%s\")",fName,dataset.Data()),dataset.Data());
99  }
100 
101  bar->AddSeparator();
102  bar->AddButton( "Quit", ".q", "Quit", "button");
103 
104  // set the style
105  bar->SetTextColor("black");
106  bar->Show();
107  gROOT->SaveContext();
108  return ;
109  }
110  // find all references
111  TMVARegGui_keyContent = (TList*)file->GetDirectory(dataset.Data())->GetListOfKeys()->Clone();
112 
113  // close file
114  file->Close();
115 
116  TString defaultRequiredClassifier = "";
117 
118  // gROOT->Reset();
119  // gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
120 
121  // create the control bar
122  TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Regression", 0, 0 );
123 
124  const TString buttonType( "button" );
125 
126  // configure buttons
127  Int_t ic = 1;
128 
129  // find all input variables types
130  TList* keylist = RegGuiGetKeyList( "InputVariables" );
131  TListIter it( keylist );
132  TObjString* str = 0;
133  char ch = 'a';
134  while ( (str = (TObjString*)it()) ) {
135  TString tmp = str->GetString();
136  TString title = Form( "Input variables and target(s) '%s'-transformed (training sample)",
137  tmp.ReplaceAll("InputVariables_","").Data() );
138  if (tmp.Contains( "Id" )) title = "Input variables and target(s) (training sample)";
139  RegGuiActionButton( cbar,
140  Form( " (%i%c) %s ", ic, ch++, title.Data() ),
141  Form( "TMVA::variables(\"%s\",\"%s\",\"%s\",\"%s\",kTRUE)",dataset.Data() , fName, str->GetString().Data(), title.Data() ),
142  Form( "Plots all '%s'-transformed input variables and target(s) (macro variables(...))",
143  str->GetString().Data() ),
144  buttonType, str->GetString() );
145  }
146  ic++;
147 
148  // correlation scatter plots
149  it.Reset(); ch = 'a';
150  while ( (str = (TObjString*)it()) ) {
151  TString tmp = str->GetString();
152  TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
153  tmp.ReplaceAll("InputVariables_","").Data() );
154  if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
155  RegGuiActionButton( cbar,
156  Form( "(%i%c) %s", ic, ch++, title.Data() ),
157  Form( "TMVA::CorrGui(\"%s\",\"%s\",\"%s\",\"%s\",kTRUE)",dataset.Data() , fName, str->GetString().Data(), title.Data() ),
158  Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui(...))",
159  str->GetString().Data() ),
160  buttonType, str->GetString() );
161  }
162 
163  // coefficients
164  RegGuiActionButton( cbar,
165  Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic ),
166  Form( "TMVA::correlations(\"%s\",\"%s\",kTRUE)",dataset.Data(), fName ),
167  "Plots signal and background correlation summaries for all input variables (macro correlations.cxx)",
168  buttonType );
169 
170  RegGuiActionButton( cbar,
171  Form( "(%ia) Regression Output Deviation versus Target (test sample)", ++ic ),
172  Form( "TMVA::deviations(\"%s\",\"%s\",TMVA::kMVAType,kTRUE)",dataset.Data(), fName ),
173  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
174  buttonType, defaultRequiredClassifier );
175 
176  RegGuiActionButton( cbar,
177  Form( "(%ib) Regression Output Deviation versus Target (training sample)", ic ),
178  Form( "TMVA::deviations(\"%s\",\"%s\",TMVA::kCompareType,kTRUE)",dataset.Data() , fName ),
179  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
180  buttonType, defaultRequiredClassifier );
181 
182  RegGuiActionButton( cbar,
183  Form( "(%ic) Regression Output Deviation versus Input Variables (test sample)", ic ),
184  Form( "TMVA::deviations(\"%s\",\"%s\",TMVA::kMVAType,kFALSE)",dataset.Data(), fName ),
185  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
186  buttonType, defaultRequiredClassifier );
187 
188  RegGuiActionButton( cbar,
189  Form( " (%id) Regression Output Deviation versus Input Variables (training sample) ", ic ),
190  Form( "TMVA::deviations(\"%s\",\"%s\",TMVA::kCompareType,kFALSE)",dataset.Data() , fName ),
191  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
192  buttonType, defaultRequiredClassifier );
193 
194  RegGuiActionButton( cbar,
195  Form( "(%i) Summary of Average Regression Deviations ", ++ic ),
196  Form( "TMVA::regression_averagedevs(\"%s\",\"%s\")",dataset.Data() , fName ),
197  "Plot Summary of average deviations: MVAvalue - target (macro regression_averagedevs.cxx)",
198  buttonType );
199 
200  RegGuiActionButton( cbar,
201  Form( "(%ia) Network Architecture", ++ic ),
202  Form( "TMVA::network(\"%s\",\"%s\")",dataset.Data(), fName ),
203  "Plots the MLP weights (macro network.cxx)",
204  buttonType, "MLP" );
205 
206  RegGuiActionButton( cbar,
207  Form( "(%ib) Network Convergence Test", ic ),
208  Form( "TMVA::annconvergencetest(\"%s\",\"%s\")",dataset.Data() , fName ),
209  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
210  buttonType, "MLP" );
211 
212  RegGuiActionButton( cbar,
213  Form( "(%i) Plot Foams", ++ic ),
214  Form("TMVA::PlotFoams(\"%s/weights/TMVARegression_PDEFoam.weights_foams.root\")",dataset.Data()),
215  "Plot Foams (macro PlotFoams.cxx)",
216  buttonType, "PDEFoam" );
217 
218  RegGuiActionButton( cbar,
219  Form( "(%i) Regression Trees (BDT)", ++ic ),
220  Form( "TMVA::BDT_Reg(\"%s\",\"%s\")",dataset.Data() , fName ),
221  "Plots the Regression Trees trained by BDT algorithms (macro BDT_Reg(itree,...))",
222  buttonType, "BDT" );
223 
224  RegGuiActionButton( cbar,
225  Form( "(%i) Regression Tree Control Plots (BDT)", ++ic ),
226  Form( "TMVA::BDTControlPlots(\"%s\",\"%s\")",dataset.Data(), fName ),
227  "Plots to monitor boosting and pruning of regression trees (macro BDTControlPlots.cxx)",
228  buttonType, "BDT" );
229 
230  cbar->AddSeparator();
231 
232  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
233 
234  // set the style
235  cbar->SetTextColor("black");
236 
237  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
238  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
239 
240  // draw
241  cbar->Show();
242 
243  // indicate inactive buttons
244  for (UInt_t i=0; i<TMVARegGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVARegGui_inactiveButtons[i], 3 );
245  if (TMVARegGui_inactiveButtons.size() > 0) {
246  cout << "=== Note: inactive buttons indicate that the corresponding methods were not trained ===" << endl;
247  }
248 
249  gROOT->SaveContext();
250 }
void Show()
Show control bar.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void AddButton(TControlBarButton *button)
Add button.
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
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
static std::vector< TString > TMVARegGui_inactiveButtons
Definition: TMVARegGui.cxx:11
#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
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TList * RegGuiGetKeyList(const TString &pattern)
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
static TList * TMVARegGui_keyContent
Definition: TMVARegGui.cxx:10
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
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 TMVARegGui(const char *fName="TMVAReg.root", TString dataset="")
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
void RegGuiActionButton(TControlBar *cbar, const TString &title, const TString &macro, const TString &comment, const TString &buttonType, TString requiredKey="")
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