ROOT  6.06/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 
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 )
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  // find all references
78  TMVARegGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
79 
80  // close file
81  file->Close();
82 
83  TString defaultRequiredClassifier = "";
84 
85  // gROOT->Reset();
86  // gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
87 
88  // create the control bar
89  TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Regression", 0, 0 );
90 
91  const TString buttonType( "button" );
92 
93  // configure buttons
94  Int_t ic = 1;
95 
96  // find all input variables types
97  TList* keylist = RegGuiGetKeyList( "InputVariables" );
98  TListIter it( keylist );
99  TObjString* str = 0;
100  char ch = 'a';
101  while ( (str = (TObjString*)it()) ) {
102  TString tmp = str->GetString();
103  TString title = Form( "Input variables and target(s) '%s'-transformed (training sample)",
104  tmp.ReplaceAll("InputVariables_","").Data() );
105  if (tmp.Contains( "Id" )) title = "Input variables and target(s) (training sample)";
106  RegGuiActionButton( cbar,
107  Form( " (%i%c) %s ", ic, ch++, title.Data() ),
108  Form( "TMVA::variables(\"%s\",\"%s\",\"%s\",kTRUE)", fName, str->GetString().Data(), title.Data() ),
109  Form( "Plots all '%s'-transformed input variables and target(s) (macro variables(...))",
110  str->GetString().Data() ),
111  buttonType, str->GetString() );
112  }
113  ic++;
114 
115  // correlation scatter plots
116  it.Reset(); ch = 'a';
117  while ( (str = (TObjString*)it()) ) {
118  TString tmp = str->GetString();
119  TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
120  tmp.ReplaceAll("InputVariables_","").Data() );
121  if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
122  RegGuiActionButton( cbar,
123  Form( "(%i%c) %s", ic, ch++, title.Data() ),
124  Form( "TMVA::CorrGui(\"%s\",\"%s\",\"%s\",kTRUE)", fName, str->GetString().Data(), title.Data() ),
125  Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui(...))",
126  str->GetString().Data() ),
127  buttonType, str->GetString() );
128  }
129 
130  // coefficients
131  RegGuiActionButton( cbar,
132  Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic ),
133  Form( "TMVA::correlations(\"%s\",kTRUE)", fName ),
134  "Plots signal and background correlation summaries for all input variables (macro correlations.cxx)",
135  buttonType );
136 
137  RegGuiActionButton( cbar,
138  Form( "(%ia) Regression Output Deviation versus Target (test sample)", ++ic ),
139  Form( "TMVA::deviations(\"%s\",TMVA::kMVAType,kTRUE)", fName ),
140  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
141  buttonType, defaultRequiredClassifier );
142 
143  RegGuiActionButton( cbar,
144  Form( "(%ib) Regression Output Deviation versus Target (training sample)", ic ),
145  Form( "TMVA::deviations(\"%s\",TMVA::kCompareType,kTRUE)", fName ),
146  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
147  buttonType, defaultRequiredClassifier );
148 
149  RegGuiActionButton( cbar,
150  Form( "(%ic) Regression Output Deviation versus Input Variables (test sample)", ic ),
151  Form( "TMVA::deviations(\"%s\",TMVA::kMVAType,kFALSE)", fName ),
152  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
153  buttonType, defaultRequiredClassifier );
154 
155  RegGuiActionButton( cbar,
156  Form( " (%id) Regression Output Deviation versus Input Variables (training sample) ", ic ),
157  Form( "TMVA::deviations(\"%s\",TMVA::kCompareType,kFALSE)", fName ),
158  "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
159  buttonType, defaultRequiredClassifier );
160 
161  RegGuiActionButton( cbar,
162  Form( "(%i) Summary of Average Regression Deviations ", ++ic ),
163  Form( "TMVA::regression_averagedevs(\"%s\")", fName ),
164  "Plot Summary of average deviations: MVAvalue - target (macro regression_averagedevs.cxx)",
165  buttonType );
166 
167  RegGuiActionButton( cbar,
168  Form( "(%ia) Network Architecture", ++ic ),
169  Form( "TMVA::network(\"%s\")", fName ),
170  "Plots the MLP weights (macro network.cxx)",
171  buttonType, "MLP" );
172 
173  RegGuiActionButton( cbar,
174  Form( "(%ib) Network Convergence Test", ic ),
175  Form( "TMVA::annconvergencetest(\"%s\")", fName ),
176  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
177  buttonType, "MLP" );
178 
179  RegGuiActionButton( cbar,
180  Form( "(%i) Plot Foams", ++ic ),
181  "TMVA::PlotFoams(\"weights/TMVARegression_PDEFoam.weights_foams.root\")",
182  "Plot Foams (macro PlotFoams.cxx)",
183  buttonType, "PDEFoam" );
184 
185  RegGuiActionButton( cbar,
186  Form( "(%i) Regression Trees (BDT)", ++ic ),
187  Form( "TMVA::BDT_Reg(\"%s\")", fName ),
188  "Plots the Regression Trees trained by BDT algorithms (macro BDT_Reg(itree,...))",
189  buttonType, "BDT" );
190 
191  RegGuiActionButton( cbar,
192  Form( "(%i) Regression Tree Control Plots (BDT)", ++ic ),
193  Form( "TMVA::BDTControlPlots(\"%s\")", fName ),
194  "Plots to monitor boosting and pruning of regression trees (macro BDTControlPlots.cxx)",
195  buttonType, "BDT" );
196 
197  cbar->AddSeparator();
198 
199  cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
200 
201  // set the style
202  cbar->SetTextColor("black");
203 
204  // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
205  // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
206 
207  // draw
208  cbar->Show();
209 
210  // indicate inactive buttons
211  for (UInt_t i=0; i<TMVARegGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVARegGui_inactiveButtons[i], 3 );
212  if (TMVARegGui_inactiveButtons.size() > 0) {
213  cout << "=== Note: inactive buttons indicate that the corresponding methods were not trained ===" << endl;
214  }
215 
216  gROOT->SaveContext();
217 }
void Show()
Show control bar.
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: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
static std::vector< TString > TMVARegGui_inactiveButtons
Definition: TMVARegGui.cxx:11
TList * RegGuiGetKeyList(const TString &pattern)
Definition: TMVARegGui.cxx:14
#define gROOT
Definition: TROOT.h:340
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 TList * TMVARegGui_keyContent
Definition: TMVARegGui.cxx:10
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
TString GetString() const
Definition: TObjString.h:50
R__EXTERN TSystem * gSystem
Definition: TSystem.h:549
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:3805
void TMVARegGui(const char *fName="TMVAReg.root")
Definition: TMVARegGui.cxx:46
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:976
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
void RegGuiActionButton(TControlBar *cbar, const TString &title, const TString &macro, const TString &comment, const TString &buttonType, TString requiredKey="")
Definition: TMVARegGui.cxx:27
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:898