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,
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(),TString::Format("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 = nullptr;
134 char ch = 'a';
135 while ( (str = (TObjString*)it()) ) {
136 TString 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)";
140 RegGuiActionButton( cbar,
141 TString::Format( " (%i%c) %s ", ic, ch++, title.Data() ),
142 TString::Format( "TMVA::variables(\"%s\",\"%s\",\"%s\",\"%s\",kTRUE)",dataset.Data() , fName, str->GetString().Data(), title.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 TString 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)";
156 RegGuiActionButton( cbar,
157 TString::Format( "(%i%c) %s", ic, ch++, title.Data() ),
158 TString::Format( "TMVA::CorrGui(\"%s\",\"%s\",\"%s\",\"%s\",kTRUE)",dataset.Data() , fName, str->GetString().Data(), title.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
165 RegGuiActionButton( cbar,
166 TString::Format( "(%i) Input Variable Linear Correlation Coefficients", ++ic ),
167 TString::Format( "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 TString::Format( "(%ia) Regression Output Deviation versus Target (test sample)", ++ic ),
173 TString::Format( "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 TString::Format( "(%ib) Regression Output Deviation versus Target (training sample)", ic ),
179 TString::Format( "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 TString::Format( "(%ic) Regression Output Deviation versus Input Variables (test sample)", ic ),
185 TString::Format( "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 TString::Format( " (%id) Regression Output Deviation versus Input Variables (training sample) ", ic ),
191 TString::Format( "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 TString::Format( "(%i) Summary of Average Regression Deviations ", ++ic ),
197 TString::Format( "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 TString::Format( "(%ia) Network Architecture", ++ic ),
203 TString::Format( "TMVA::network(\"%s\",\"%s\")",dataset.Data(), fName ),
204 "Plots the MLP weights (macro network.cxx)",
205 buttonType, "MLP" );
206
207 RegGuiActionButton( cbar,
208 TString::Format( "(%ib) Network Convergence Test", ic ),
209 TString::Format( "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 TString::Format( "(%i) Plot Foams", ++ic ),
215 TString::Format("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 TString::Format( "(%i) Regression Trees (BDT)", ++ic ),
221 TString::Format( "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 TString::Format( "(%i) Regression Tree Control Plots (BDT)", ++ic ),
227 TString::Format( "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( 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:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
static TList * TMVARegGui_keyContent
static std::vector< TString > TMVARegGui_inactiveButtons
#define gROOT
Definition TROOT.h:406
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
R__EXTERN TSystem * gSystem
Definition TSystem.h:555
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 SetButtonState(const char *label, Int_t state=0)
Sets a state for control bar button 'label'; possible states are 0-kButtonUp, 1-kButtonDown,...
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 composed of a header, followed by consecutive data records (TKey instances) with a wel...
Definition TFile.h:53
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:4067
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:928
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
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:47
Collectable string class.
Definition TObjString.h:28
const TString & GetString() const
Definition TObjString.h:46
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:315
virtual const char * GetIncludePath()
Get the list of include path.
Definition TSystem.cxx:3973
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:4194
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="")