BDTControlPlots.C

Go to the documentation of this file.
00001 #include <vector>
00002 #include <string>
00003 #include "tmvaglob.C"
00004 
00005 
00006 // input: - Input file (result from TMVA),
00007 //        - use of TMVA plotting TStyle
00008 void BDTControlPlots( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE )
00009 {
00010    // set style and remove existing canvas'
00011    TMVAGlob::Initialize( useTMVAStyle );
00012   
00013    // checks if file with name "fin" is already open, and if not opens one
00014    TFile* file = TMVAGlob::OpenFile( fin );  
00015 
00016    // get all titles of the method BDT
00017    TList titles;
00018    UInt_t ninst = TMVAGlob::GetListOfTitles("Method_BDT",titles);
00019    if (ninst==0) {
00020       cout << "Could not locate directory 'Method_BDT' in file " << fin << endl;
00021       return;
00022    }
00023    // loop over all titles
00024    TIter keyIter(&titles);
00025    TDirectory *bdtdir;
00026    TKey *key;
00027    while ((key = TMVAGlob::NextKey(keyIter,"TDirectory"))) {
00028       bdtdir = (TDirectory *)key->ReadObj();
00029       bdtcontrolplots( bdtdir );
00030    }
00031 }
00032 
00033 void bdtcontrolplots( TDirectory *bdtdir ) {
00034 
00035    const Int_t nPlots = 6;
00036 
00037    Int_t width  = 900;
00038    Int_t height = 600;
00039    char cn[100];
00040    const TString titName = bdtdir->GetName();
00041    sprintf( cn, "cv_%s", titName.Data() );
00042    TCanvas *c = new TCanvas( cn,  Form( "%s Control Plots", titName.Data() ),
00043                              width, height ); 
00044    c->Divide(3,2);
00045 
00046 
00047    const TString titName = bdtdir->GetName();
00048 
00049    TString hname[nPlots]={"BoostWeight","BoostWeightVsTree","ErrFractHist","NodesBeforePruning","NodesAfterPruning",titName+"_FOMvsIterFrame"}
00050 
00051    for (Int_t i=0; i<nPlots; i++){
00052       Int_t color = 4; 
00053       TPad * cPad = (TPad*)c->cd(i+1);
00054       TH1 *h = (TH1*) bdtdir->Get(hname[i]);
00055       if (h){
00056          TString plotname = h->GetName();
00057          h->SetMaximum(h->GetMaximum()*1.3);
00058          h->SetMinimum( 0 );
00059          h->SetMarkerColor(color);
00060          h->SetMarkerSize( 0.7 );
00061          h->SetMarkerStyle( 24 );
00062          h->SetLineWidth(1);
00063          h->SetLineColor(color);
00064          h->Draw();
00065          if(hname[i]==titName+"_FOMvsIterFrame"){ // a plot only available in case of automatic parameter option tuning
00066             TGraph *g = (TGraph*) bdtdir->Get(titName+"_FOMvsIter");
00067             g->Draw();
00068          }
00069          c->Update();
00070       }
00071    }
00072 
00073    // write to file
00074    TString fname = Form( "plots/%s_ControlPlots", titName.Data() );
00075    TMVAGlob::imgconv( c, fname );
00076    
00077 }
00078 
00079 

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