00001 #include <iostream>
00002 #include <vector>
00003
00004 #include "TList.h"
00005 #include "TROOT.h"
00006 #include "TKey.h"
00007 #include "TString.h"
00008 #include "TControlBar.h"
00009 #include "TObjString.h"
00010
00011 #include "tmvaglob.C"
00012
00013
00014 static TList* TMVAGui_keyContent;
00015 static std::vector<TString> TMVAGui_inactiveButtons;
00016
00017 TList* GetKeyList( const TString& pattern )
00018 {
00019 TList* list = new TList();
00020
00021 TIter next( TMVAGui_keyContent );
00022 TKey* key(0);
00023 while ((key = (TKey*)next())) {
00024 if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
00025 }
00026 return list;
00027 }
00028
00029
00030 void ActionButton( TControlBar* cbar,
00031 const TString& title, const TString& macro, const TString& comment,
00032 const TString& buttonType, TString requiredKey = "" )
00033 {
00034 cbar->AddButton( title, macro, comment, buttonType );
00035
00036
00037 if (requiredKey != "") {
00038 Bool_t found = kFALSE;
00039 TIter next( TMVAGui_keyContent );
00040 TKey* key(0);
00041 while ((key = (TKey*)next())) {
00042 if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
00043 }
00044 if (!found) TMVAGui_inactiveButtons.push_back( title );
00045 }
00046 }
00047
00048
00049 void TMVAMultiClassGui( const char* fName = "TMVAMulticlass.root" )
00050 {
00051
00052
00053
00054
00055 TString curMacroPath(gROOT->GetMacroPath());
00056
00057 gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
00058
00059
00060
00061
00062
00063
00064 TString curIncludePath=gSystem->GetIncludePath();
00065
00066 TString newIncludePath=TString("-I../ ")+curIncludePath;
00067 gSystem->SetIncludePath(newIncludePath);
00068 std::cout <<"new include path="<<gSystem->GetIncludePath()<<std::endl;
00069
00070 cout << "--- Launch TMVA GUI to view input file: " << fName << endl;
00071
00072
00073 TMVAGui_inactiveButtons.clear();
00074
00075
00076 TFile* file = TFile::Open( fName );
00077 if (!file) {
00078 cout << "==> Abort TMVAGui, please verify filename" << endl;
00079 return;
00080 }
00081
00082 TMVAGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
00083
00084
00085 file->Close();
00086
00087 TString defaultRequiredClassifier = "";
00088
00089
00090
00091
00092
00093 TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Multiclass Classification", 0, 0 );
00094
00095 const TString buttonType( "button" );
00096
00097
00098 Int_t ic = 1;
00099
00100
00101 TList* keylist = GetKeyList( "InputVariables" );
00102 TListIter it( keylist );
00103 TObjString* str = 0;
00104 char ch = 'a';
00105 while ((str = (TObjString*)it())) {
00106 TString tmp = str->GetString();
00107 TString title = Form( "Input variables '%s'-transformed (training sample)",
00108 tmp.ReplaceAll("InputVariables_","").Data() );
00109 if (tmp.Contains( "Id" )) title = "Input variables (training sample)";
00110 ActionButton( cbar,
00111 Form( "(%i%c) %s", ic, ch++, title.Data() ),
00112 Form( ".x variablesMultiClass.C(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
00113 Form( "Plots all '%s'-transformed input variables (macro variablesMultiClass.C(...))", str->GetString().Data() ),
00114 buttonType, str->GetString() );
00115 }
00116 ic++;
00117
00118
00119 it.Reset(); ch = 'a';
00120 while ((str = (TObjString*)it())) {
00121 TString tmp = str->GetString();
00122 TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)",
00123 tmp.ReplaceAll("InputVariables_","").Data() );
00124 if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
00125 ActionButton( cbar,
00126 Form( "(%i%c) %s", ic, ch++, title.Data() ),
00127 Form( ".x CorrGuiMultiClass.C(\"%s\",\"%s\",\"%s\")", fName, str->GetString().Data(), title.Data() ),
00128 Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGuiMultiClass.C(...))",
00129 str->GetString().Data() ),
00130 buttonType, str->GetString() );
00131 }
00132
00133 TString title;
00134
00135 title =Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic );
00136 ActionButton( cbar,
00137 title,
00138 Form( ".x correlationsMultiClass.C(\"%s\")", fName ),
00139 "Plots signal and background correlation summaries for all input variables (macro correlationsMultiClass.C)",
00140 buttonType );
00141
00142 title =Form( "(%ia) Classifier Output Distributions (test sample)", ++ic );
00143 ActionButton( cbar,
00144 title,
00145 Form( ".x mvasMulticlass.C(\"%s\",0)", fName ),
00146 "Plots the output of each classifier for the test data (macro mvas.C(...,0))",
00147 buttonType, defaultRequiredClassifier );
00148
00149 title =Form( "(%ib) Classifier Output Distributions (test and training samples superimposed)", ic );
00150 ActionButton( cbar,
00151 title,
00152 Form( ".x mvasMulticlass.C(\"%s\",1)", fName ),
00153 "Plots the output of each classifier for the test (histograms) and training (dots) data (macro mvas.C(...,3))",
00154 buttonType, defaultRequiredClassifier );
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 title = Form( "(%ia) Network Architecture (MLP)", ++ic );
00215 TString call = Form( ".x network.C+g(\"%s\")", fName );
00216 ActionButton( cbar,
00217 title,
00218 call,
00219 "Plots the MLP weights (macro network.C)",
00220 buttonType, "MLP" );
00221
00222 title = Form( "(%ib) Network Convergence Test (MLP)", ic );
00223 ActionButton( cbar,
00224 title,
00225 Form( ".x annconvergencetest.C(\"%s\")", fName ),
00226 "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)",
00227 buttonType, "MLP" );
00228
00229 title = Form( "(%i) Decision Trees (BDT)", ++ic );
00230 ActionButton( cbar,
00231 title,
00232 Form( ".x BDT.C+(\"%s\")", fName ),
00233 "Plots the Decision Trees trained by BDT algorithms (macro BDT.C(itree,...))",
00234 buttonType, "BDT" );
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 cbar->AddSeparator();
00260
00261 cbar->AddButton( Form( "(%i) Quit", ++ic ), ".q", "Quit", buttonType );
00262
00263
00264 cbar->SetTextColor("black");
00265
00266
00267
00268
00269
00270 cbar->Show();
00271
00272
00273 for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAGui_inactiveButtons[i], 3 );
00274 if (TMVAGui_inactiveButtons.size() > 0) {
00275 cout << "=== Note: inactive buttons indicate that the corresponding classifiers were not trained ===" << endl;
00276 }
00277
00278 gROOT->SaveContext();
00279 }