00001
00002 #include "TLegend.h"
00003 #include "TText.h"
00004 #include "TH2.h"
00005
00006 #include "tmvaglob.C"
00007
00008
00009
00010
00011
00012 enum HistType { MVAType = 0, ProbaType = 1, RarityType = 2, CompareType = 3 };
00013
00014
00015
00016 void deviations( TString fin = "TMVAReg.root",
00017 HistType htype = MVAType, Bool_t showTarget, Bool_t useTMVAStyle = kTRUE )
00018 {
00019
00020 TMVAGlob::Initialize( useTMVAStyle );
00021 gStyle->SetNumberContours(999);
00022
00023
00024 const Bool_t Save_Images = kTRUE;
00025
00026
00027 TFile* file = TMVAGlob::OpenFile( fin );
00028
00029
00030 Int_t xPad = 1;
00031 Int_t yPad = 1;
00032 Int_t noPad = xPad * yPad ;
00033 const Int_t width = 650;
00034
00035
00036 TCanvas* c[100];
00037
00038
00039 Int_t countCanvas = 0;
00040
00041
00042
00043
00044 TIter next(file->GetListOfKeys());
00045 TKey *key(0);
00046 while ((key = (TKey*)next())) {
00047
00048 if (!TString(key->GetName()).BeginsWith("Method_")) continue;
00049 if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) continue;
00050
00051 TString methodName;
00052 TMVAGlob::GetMethodName(methodName,key);
00053 cout << "--- Plotting deviation for method: " << methodName << endl;
00054
00055 TObjString *mN = new TObjString( methodName );
00056 TDirectory* mDir = (TDirectory*)key->ReadObj();
00057
00058 TList* jobNames = new TList();
00059
00060 TIter keyIt(mDir->GetListOfKeys());
00061 TKey *titkey;
00062 while ((titkey = (TKey*)keyIt())) {
00063
00064 if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom("TDirectory")) continue;
00065
00066 TDirectory *titDir = (TDirectory *)titkey->ReadObj();
00067
00068 TObjString *jN = new TObjString( titDir->GetName() );
00069 if (!jobNames->Contains( jN )) jobNames->Add( jN );
00070 else delete jN;
00071
00072 TString methodTitle;
00073 TMVAGlob::GetMethodTitle(methodTitle,titDir);
00074
00075 TString hname = "MVA_" + methodTitle;
00076 TIter dirKeyIt( titDir->GetListOfKeys() );
00077 TKey* dirKey;
00078
00079 Int_t countPlots = 0;
00080 while ((dirKey = (TKey*)dirKeyIt())){
00081 if (dirKey->ReadObj()->InheritsFrom("TH2F")) {
00082 TString s(dirKey->ReadObj()->GetName());
00083 if (s.Contains("_reg_") &&
00084 ( (showTarget && s.Contains("_tgt")) || (!showTarget && !s.Contains("_tgt")) ) &&
00085 s.Contains( (htype == CompareType ? "train" : "test" ))) {
00086 c[countCanvas] = new TCanvas( Form("canvas%d", countCanvas+1),
00087 Form( "Regression output deviation versus %s for method: %s",
00088 (showTarget ? "target" : "input variables"), methodName.Data() ),
00089 countCanvas*50+100, (countCanvas+1)*20, width, (Int_t)width*0.72 );
00090 c[countCanvas]->SetRightMargin(0.10);
00091 TH1* h = (TH1*)dirKey->ReadObj();
00092 h->SetTitle( Form("Output deviation for method: %s (%s sample)",
00093 hname.Data(), (htype == CompareType ? "training" : "test" )) );
00094
00095 h->Draw("colz");
00096 TLine* l = new TLine( h->GetXaxis()->GetXmin(), 0, h->GetXaxis()->GetXmax(), 0 );
00097 l->SetLineStyle(2);
00098 l->Draw();
00099
00100
00101 cout << "plotting logo" << endl;
00102 TMVAGlob::plot_logo(1.058);
00103 c[countCanvas]->Update();
00104
00105 TString fname = Form( "plots/deviation_%s_%s_%s_c%i",
00106 methodName.Data(),
00107 (showTarget ? "target" : "vars"),
00108 (htype == CompareType ? "training" : "test" ), countPlots );
00109 TMVAGlob::imgconv( c[countCanvas], fname );
00110
00111 countPlots++;
00112 countCanvas++;
00113 }
00114 }
00115 }
00116 }
00117 }
00118 }
00119
00120
00121
00122