TMVARegGui.C

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 
00004 #include "TROOT.h"
00005 #include "TControlBar.h"
00006 #include "tmvaglob.C"
00007 
00008 // some global lists
00009 static TList*               TMVAGui_keyContent;
00010 static std::vector<TString> TMVAGui_inactiveButtons;
00011 
00012 TList* GetKeyList( const TString& pattern )
00013 {
00014    TList* list = new TList();
00015 
00016    TIter next( TMVAGui_keyContent );
00017    TKey* key(0);
00018    while ((key = (TKey*)next())) {         
00019       if (TString(key->GetName()).Contains( pattern )) { list->Add( new TObjString( key->GetName() ) ); }
00020    }
00021    return list;
00022 }
00023 
00024 // utility function
00025 void ActionButton( TControlBar* cbar, 
00026                    const TString& title, const TString& macro, const TString& comment, 
00027                    const TString& buttonType, TString requiredKey = "" ) 
00028 {
00029    cbar->AddButton( title, macro, comment, buttonType );
00030 
00031    // search    
00032    if (requiredKey != "") {
00033       Bool_t found = kFALSE;
00034       TIter next( TMVAGui_keyContent );
00035       TKey* key(0);
00036       while ((key = (TKey*)next())) {         
00037          if (TString(key->GetName()).Contains( requiredKey )) { found = kTRUE; break; }
00038       }
00039       if (!found) TMVAGui_inactiveButtons.push_back( title );
00040    }
00041 }
00042 
00043 // main GUI
00044 void TMVARegGui( const char* fName = "TMVAReg.root" ) 
00045 {   
00046    // Use this script in order to run the various individual macros
00047    // that plot the output of TMVA (e.g. running TMVARegression.C),
00048    // stored in the file "TMVA.Regroot"
00049 
00050    TString curMacroPath(gROOT->GetMacroPath());
00051    // uncomment next line for macros submitted to next root version
00052    gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
00053 
00054    // for the sourceforge version, including $ROOTSYS/tmva/test in the
00055    // macro path is a mistake, especially if "./" was not part of path
00056    // add ../macros to the path (comment out next line for the ROOT version of TMVA)
00057    // gROOT->SetMacroPath(curMacroPath+":../macros:");
00058 
00059    TString curIncludePath=gSystem->GetIncludePath();
00060    //std::cout <<"inc path="<<curIncludePath<<std::endl;
00061    TString newIncludePath=TString("-I../ ")+curIncludePath;
00062    gSystem->SetIncludePath(newIncludePath);
00063   
00064    cout << "--- Launch TMVA GUI to view input file: " << fName << endl;
00065 
00066    // init
00067    TMVAGui_inactiveButtons.clear();
00068 
00069    // check if file exist
00070    TFile* file = TFile::Open( fName );
00071    if (!file) {
00072       cout << "==> Abort TMVAGui, please verify filename" << endl;
00073       return;
00074    }
00075    // find all references   
00076    TMVAGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
00077 
00078    // close file
00079    file->Close();
00080 
00081    TString defaultRequiredClassifier = "";
00082 
00083    //   gROOT->Reset();
00084    //   gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
00085 
00086    // create the control bar
00087    TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Regression", 0, 0 );
00088 
00089    const TString buttonType( "button" );
00090 
00091    // configure buttons   
00092    Int_t ic = 1;
00093 
00094    // find all input variables types
00095    TList* keylist = GetKeyList( "InputVariables" );
00096    TListIter it( keylist );
00097    TObjString* str = 0;
00098    char ch = 'a';
00099    while (str = (TObjString*)it()) {
00100       TString tmp   = str->GetString();
00101       TString title = Form( "Input variables and target(s) '%s'-transformed (training sample)", 
00102                             tmp.ReplaceAll("InputVariables_","").Data() );
00103       if (tmp.Contains( "Id" )) title = "Input variables and target(s) (training sample)";
00104       ActionButton( cbar, 
00105                     Form( "    (%i%c) %s    ", ic, ch++, title.Data() ),
00106                     Form( ".x variables.C(\"%s\",\"%s\",\"%s\",kTRUE)", fName, str->GetString().Data(), title.Data() ),
00107                     Form( "Plots all '%s'-transformed input variables and target(s) (macro variables.C(...))", 
00108                           str->GetString().Data() ),
00109                     buttonType, str->GetString() );
00110    }      
00111    ic++;
00112 
00113    // correlation scatter plots 
00114    it.Reset(); ch = 'a';
00115    while (str = (TObjString*)it()) {
00116       TString tmp   = str->GetString();
00117       TString title = Form( "Input variable correlations '%s'-transformed (scatter profiles)", 
00118                             tmp.ReplaceAll("InputVariables_","").Data() );
00119       if (tmp.Contains( "Id" )) title = "Input variable correlations (scatter profiles)";
00120       ActionButton( cbar, 
00121                     Form( "(%i%c) %s", ic, ch++, title.Data() ),
00122                     Form( ".x CorrGui.C(\"%s\",\"%s\",\"%s\",kTRUE)", fName, str->GetString().Data(), title.Data() ),
00123                     Form( "Plots all correlation profiles between '%s'-transformed input variables (macro CorrGui.C(...))", 
00124                           str->GetString().Data() ),
00125                     buttonType, str->GetString() );
00126    }      
00127    
00128    // coefficients
00129    ActionButton( cbar,  
00130                  Form( "(%i) Input Variable Linear Correlation Coefficients", ++ic ),
00131                  Form( ".x correlations.C(\"%s\",kTRUE)", fName ),
00132                  "Plots signal and background correlation summaries for all input variables (macro correlations.C)", 
00133                  buttonType );
00134 
00135    ActionButton( cbar,  
00136                  Form( "(%ia) Regression Output Deviation versus Target (test sample)", ++ic ),
00137                  Form( ".x deviations.C(\"%s\",0,kTRUE)", fName ),
00138                  "Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
00139                  buttonType, defaultRequiredClassifier );
00140 
00141    ActionButton( cbar,  
00142                  Form( "(%ib) Regression Output Deviation versus Target (training sample)", ic ),
00143                  Form( ".x deviations.C(\"%s\",3,kTRUE)", fName ),
00144                  "Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
00145                  buttonType, defaultRequiredClassifier );
00146 
00147    ActionButton( cbar,  
00148                  Form( "(%ic) Regression Output Deviation versus Input Variables (test sample)", ic ),
00149                  Form( ".x deviations.C(\"%s\",0,kFALSE)", fName ),
00150                  "Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
00151                  buttonType, defaultRequiredClassifier );
00152 
00153    ActionButton( cbar,  
00154                  Form( "   (%id) Regression Output Deviation versus Input Variables (training sample)   ", ic ),
00155                  Form( ".x deviations.C(\"%s\",3,kFALSE)", fName ),
00156                  "Plots the deviation between regression output and target versus target on test data (macro deviations.C(...,0))",
00157                  buttonType, defaultRequiredClassifier );
00158 
00159    ActionButton( cbar,  
00160                  Form( "(%i) Summary of Average Regression Deviations ", ++ic ),
00161                  Form( ".x regression_averagedevs.C(\"%s\")", fName ),
00162                  "Plot Summary of average deviations: MVAvalue - target (macro regression_averagedevs.C)",
00163                  buttonType );
00164 
00165    ActionButton( cbar,  
00166                  Form( "(%ia) Network Architecture", ++ic ),
00167                  Form( ".x network.C(\"%s\")", fName ), 
00168                  "Plots the MLP weights (macro network.C)",
00169                  buttonType, "MLP" );
00170 
00171    ActionButton( cbar,  
00172                  Form( "(%ib) Network Convergence Test", ic ),
00173                  Form( ".x annconvergencetest.C(\"%s\")", fName ), 
00174                  "Plots error estimator versus training epoch for training and test samples (macro annconvergencetest.C)",
00175                  buttonType, "MLP" );
00176 
00177    ActionButton( cbar,  
00178                  Form( "(%i) Plot Foams", ++ic ),
00179                  Form( ".x PlotFoams.C(\"weights/TMVARegression_PDEFoam.weights_foams.root\")", fName ),
00180                  "Plot Foams (macro PlotFoams.C)",
00181                  buttonType, "PDEFoam" );
00182 
00183    ActionButton( cbar,  
00184                  Form( "(%i) Regression Trees (BDT)", ++ic ),
00185                  Form( ".x BDT_Reg.C+(\"%s\")", fName ),
00186                  "Plots the Regression Trees trained by BDT algorithms (macro BDT_Reg.C(itree,...))",
00187                  buttonType, "BDT" );
00188 
00189    ActionButton( cbar,  
00190                  Form( "(%i) Regression Tree Control Plots (BDT)", ++ic ),
00191                  Form( ".x BDTControlPlots.C(\"%s\")", fName ),
00192                  "Plots to monitor boosting and pruning of regression trees (macro BDTControlPlots.C)",
00193                  buttonType, "BDT" );
00194 
00195    cbar->AddSeparator();
00196 
00197    cbar->AddButton( Form( "(%i) Quit", ++ic ),   ".q", "Quit", buttonType );
00198 
00199    // set the style 
00200    cbar->SetTextColor("black");
00201 
00202    // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
00203    // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
00204    
00205    // draw
00206    cbar->Show();
00207 
00208    // indicate inactive buttons
00209    for (UInt_t i=0; i<TMVAGui_inactiveButtons.size(); i++) cbar->SetButtonState( TMVAGui_inactiveButtons[i], 3 );
00210    if (TMVAGui_inactiveButtons.size() > 0) {
00211       cout << "=== Note: inactive buttons indicate that the corresponding methods were not trained ===" << endl;
00212    }
00213 
00214    gROOT->SaveContext();
00215 }

Generated on Tue Jul 5 15:26:37 2011 for ROOT_528-00b_version by  doxygen 1.5.1