Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
15TList* TMVA::RegGuiGetKeyList( const TString& pattern )
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,
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
63 //std::cout <<"inc path="<<curIncludePath<<std::endl;
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==""||GetEntries()==1))
85 {
86 TKey *key=(TKey*)file->GetListOfKeys()->At(0);
87 GetName();
88 }else if((dataset==""||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 GetName();
99 bar->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 GetListOfKeys()->Clone();
113
114 // close file
115 file->Close();
116
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 = nullptr;
134 char ch = 'a';
135 while ( (str = (TObjString*)it()) ) {
136 tmp = str->GetString();
137 TString title = TString::Format( "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)";
141 TString::Format( " (%i%c) %s ", ic, ch++, title.Data() ),
142 Data() ),
143 TString::Format( "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 tmp = str->GetString();
153 TString title = TString::Format( "Input variable correlations '%s'-transformed (scatter profiles)",
154 tmp.ReplaceAll("InputVariables_","").Data() );
155 if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
157 TString::Format( "(%i%c) %s", ic, ch++, title.Data() ),
158 Data() ),
159 TString::Format( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui(...))",
160 str->GetString().Data() ),
161 buttonType, str->GetString() );
162 }
163
164 // coefficients
166 TString::Format( "(%i) Input Variable Linear Correlation Coefficients", ++ic ),
167 dataset.Data(), fName ),
168 "Plots signal and background correlation summaries for all input variables (macro correlations.cxx)",
169 buttonType );
170
172 TString::Format( "(%ia) Regression Output Deviation versus Target (test sample)", ++ic ),
173 dataset.Data(), fName ),
174 "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
176
178 TString::Format( "(%ib) Regression Output Deviation versus Target (training sample)", ic ),
179 dataset.Data() , fName ),
180 "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
182
184 TString::Format( "(%ic) Regression Output Deviation versus Input Variables (test sample)", ic ),
185 dataset.Data(), fName ),
186 "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
188
190 TString::Format( " (%id) Regression Output Deviation versus Input Variables (training sample) ", ic ),
191 dataset.Data() , fName ),
192 "Plots the deviation between regression output and target versus target on test data (macro deviations(...,0))",
194
196 TString::Format( "(%i) Summary of Average Regression Deviations ", ++ic ),
197 dataset.Data() , fName ),
198 "Plot Summary of average deviations: MVAvalue - target (macro regression_averagedevs.cxx)",
199 buttonType );
200
202 TString::Format( "(%ia) Network Architecture", ++ic ),
203 dataset.Data(), fName ),
204 "Plots the MLP weights (macro network.cxx)",
205 buttonType, "MLP" );
206
208 TString::Format( "(%ib) Network Convergence Test", ic ),
209 dataset.Data() , fName ),
210 "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.cxx)",
211 buttonType, "MLP" );
212
214 TString::Format( "(%i) Plot Foams", ++ic ),
215 dataset.Data()),
216 "Plot Foams (macro PlotFoams.cxx)",
217 buttonType, "PDEFoam" );
218
220 TString::Format( "(%i) Regression Trees (BDT)", ++ic ),
221 dataset.Data() , fName ),
222 "Plots the Regression Trees trained by BDT algorithms (macro BDT_Reg(itree,...))",
223 buttonType, "BDT" );
224
226 TString::Format( "(%i) Regression Tree Control Plots (BDT)", ++ic ),
227 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( TString::Format( "(%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
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
static TList * TMVARegGui_keyContent
static std::vector< TString > TMVARegGui_inactiveButtons
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
virtual Int_t GetEntries() const
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 SetButtonWidth(UInt_t width)
Sets the width in pixels for control bar button.
void AddButton(TControlBarButton *button)
Add button.
void SetTextColor(const char *colorName)
Sets text color for control bar buttons, e.g.:
TList * GetListOfKeys() const override
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory named "apath".
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:131
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:4131
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:955
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
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:355
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
Collectable string class.
Definition TObjString.h:28
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
void SetScreenFactor(Float_t factor=1)
Definition TStyle.h:321
virtual const char * GetIncludePath()
Get the list of include path.
Definition TSystem.cxx:3986
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:4207
UInt_t GetListOfKeys(TList &keys, TString inherits, TDirectory *dir=nullptr)
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="")