TMVAMultiClassGui.C

Go to the documentation of this file.
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 // some global lists
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 // utility function
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    // search    
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 // main GUI
00049 void TMVAMultiClassGui( const char* fName = "TMVAMulticlass.root" ) 
00050 {   
00051    // Use this script in order to run the various individual macros
00052    // that plot the output of TMVA (e.g. running TMVAClassification.C),
00053    // stored in the file "TMVA.root"
00054 
00055    TString curMacroPath(gROOT->GetMacroPath());
00056    // uncomment next line for macros submitted to next root version
00057    gROOT->SetMacroPath(curMacroPath+":./:$ROOTSYS/tmva/test/:");
00058    
00059    // for the sourceforge version, including $ROOTSYS/tmva/test in the
00060    // macro path is a mistake, especially if "./" was not part of path
00061    // add ../macros to the path (comment out next line for the ROOT version of TMVA)
00062    // gROOT->SetMacroPath(curMacroPath+":../macros:");
00063 
00064    TString curIncludePath=gSystem->GetIncludePath();
00065    //std::cout <<"inc path="<<curIncludePath<<std::endl;
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    // init
00073    TMVAGui_inactiveButtons.clear();
00074 
00075    // check if file exist
00076    TFile* file = TFile::Open( fName );
00077    if (!file) {
00078       cout << "==> Abort TMVAGui, please verify filename" << endl;
00079       return;
00080    }
00081    // find all references   
00082    TMVAGui_keyContent = (TList*)file->GetListOfKeys()->Clone();
00083 
00084    //close file
00085    file->Close();
00086 
00087    TString defaultRequiredClassifier = "";
00088 
00089    //   gROOT->Reset();
00090    //   gStyle->SetScreenFactor(2); // if you have a large screen, select 1,2 or 1.4
00091 
00092    // create the control bar
00093    TControlBar* cbar = new TControlBar( "vertical", "TMVA Plotting Macros for Multiclass Classification", 0, 0 );
00094 
00095    const TString buttonType( "button" );
00096 
00097    // configure buttons   
00098    Int_t ic = 1;
00099 
00100    // find all input variables types
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    // correlation scatter plots 
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    // coefficients
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      title = Form( "(%ic) Classifier Probability Distributions (test sample)", ic );
00157      ActionButton( cbar,  
00158      Form( "(%ic) Classifier Probability Distributions (test sample)", ic ),
00159      Form( ".x mvas.C(\"%s\",1)", fName ),
00160      "Plots the probability of each classifier for the test data (macro mvas.C(...,1))",
00161      buttonType, defaultRequiredClassifier );
00162      
00163      title =Form( "(%id) Classifier Rarity Distributions (test sample)", ic );
00164      ActionButton( cbar,  
00165      Form( "(%id) Classifier Rarity Distributions (test sample)", ic ),
00166      Form( ".x mvas.C(\"%s\",2)", fName ),
00167      "Plots the Rarity of each classifier for the test data (macro mvas.C(...,2)) - background distribution should be uniform",
00168      buttonType, defaultRequiredClassifier );
00169    
00170    
00171    title =Form( "(%ia) Classifier Cut Efficiencies", ++ic );
00172    ActionButton( cbar,  
00173                  title,
00174                  Form( ".x mvaeffs.C+(\"%s\")", fName ),
00175                  "Plots signal and background efficiencies versus cut on classifier output (macro mvaeffs.C)",
00176                  buttonType, defaultRequiredClassifier );
00177 
00178    title = Form( "(%ib) Classifier Background Rejection vs Signal Efficiency (ROC curve)", ic );
00179    ActionButton( cbar,  
00180                  title,
00181                  Form( ".x efficiencies.C(\"%s\")", fName ),
00182                  "Plots background rejection vs signal efficiencies (macro efficiencies.C) [\"ROC\" stands for \"Receiver Operation Characteristics\"]",
00183                  buttonType, defaultRequiredClassifier );
00184                  
00185    
00186    title = Form( "(%i) Parallel Coordinates (requires ROOT-version >= 5.17)", ++ic );
00187    ActionButton( cbar,  
00188                  title,
00189                  Form( ".x paracoor.C(\"%s\")", fName ),
00190                  "Plots parallel coordinates for classifiers and input variables (macro paracoor.C, requires ROOT >= 5.17)",
00191                  buttonType, defaultRequiredClassifier );
00192 
00193    // parallel coordinates only exist since ROOT 5.17
00194    #if ROOT_VERSION_CODE < ROOT_VERSION(5,17,0)
00195    TMVAGui_inactiveButtons.push_back( title );
00196    #endif
00197    
00198    
00199    title =Form( "(%i) PDFs of Classifiers (requires \"CreateMVAPdfs\" option set)", ++ic );
00200    ActionButton( cbar,  
00201                  title,
00202                  Form( ".x probas.C(\"%s\")", fName ),
00203                  "Plots the PDFs of the classifier output distributions for signal and background - if requested (macro probas.C)",
00204                  buttonType, defaultRequiredClassifier );
00205 
00206    title = Form( "(%i) Likelihood Reference Distributiuons", ++ic);
00207    ActionButton( cbar,  
00208                  title,
00209                  Form( ".x likelihoodrefs.C(\"%s\")", fName ), 
00210                  "Plots to verify the likelihood reference distributions (macro likelihoodrefs.C)",
00211                  buttonType, "Likelihood" );
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      title = Form( "(%i) Decision Tree Control Plots (BDT)", ++ic );
00238    ActionButton( cbar,  
00239                  title,
00240                  Form( ".x BDTControlPlots.C(\"%s\")", fName ),
00241                  "Plots to monitor boosting and pruning of decision trees (macro BDTControlPlots.C)",
00242                  buttonType, "BDT" );
00243 
00244    
00245    title = Form( "(%i) Plot Foams (PDEFoam)", ++ic );
00246    ActionButton( cbar,  
00247                  title,
00248                  Form( ".x PlotFoams.C", fName ),
00249                  "Plot Foams (macro PlotFoams.C)",
00250                  buttonType, "PDEFoam" );
00251 
00252    title = Form( "(%i) General Boost Control Plots", ++ic );
00253    ActionButton( cbar,  
00254                  title,
00255                  Form( ".x BoostControlPlots.C(\"%s\")", fName ),
00256                  "Plots to monitor boosting of general classifiers (macro BoostControlPlots.C)",
00257                  buttonType, "Boost" );
00258    */
00259    cbar->AddSeparator();
00260 
00261    cbar->AddButton( Form( "(%i) Quit", ++ic ),   ".q", "Quit", buttonType );
00262 
00263    // set the style 
00264    cbar->SetTextColor("black");
00265 
00266    // there seems to be a bug in ROOT: font jumps back to default after pressing on >2 different buttons
00267    // cbar->SetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
00268    
00269    // draw
00270    cbar->Show();
00271 
00272    // indicate inactive buttons
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 }

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