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