00001 #include "tmvaglob.C"
00002
00003 enum HistType { MVAType = 0, ProbaType = 1, RarityType = 2 };
00004
00005 #define CheckDerivedPlots 0
00006
00007 TString DerivedPlotName = "Rarity";
00008
00009 void compareClassApp( TString finAn = "TMVA.root", TString finApp = "TMVApp.root",
00010 HistType htype = MVAType, bool useTMVAStyle=kTRUE )
00011 {
00012 cout << "=== Compare histograms of two files ===" << endl;
00013 cout << " File-1: " << finAn << endl;
00014 cout << " File-2: " << finApp << endl;
00015
00016
00017 TMVAGlob::Initialize( useTMVAStyle );
00018
00019
00020 const Bool_t Draw_CFANN_Logy = kFALSE;
00021 const Bool_t Save_Images = kTRUE;
00022
00023 TFile* file = TMVAGlob::OpenFile( finAn );
00024 TFile* fileApp = new TFile( finApp );
00025 file->cd();
00026
00027
00028 const Int_t width = 600;
00029
00030
00031 Int_t countCanvas = 0;
00032 char fname[200];
00033
00034 TList methods;
00035 UInt_t nm = TMVAGlob::GetListOfMethods( methods );
00036 TIter next(&methods);
00037 TKey *key, *hkey;
00038 while ((key = (TKey*)next())) {
00039
00040 TString dirname = ((TDirectory*)key->ReadObj())->GetName();
00041 if (dirname.Contains( "Cuts" )) {
00042 cout << "--- Found directory: " << dirname << " --> ignoring" << endl;
00043 continue;
00044 }
00045 cout << "--- Found directory: " << dirname
00046 << " --> going in" << endl;
00047
00048 TString methodName;
00049 TMVAGlob::GetMethodName(methodName,key);
00050
00051 cout << "--- Method: " << methodName << endl;
00052
00053 TDirectory* mDir = (TDirectory*)key->ReadObj();
00054 TList titles;
00055 UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles);
00056 TIter nextTitle(&titles);
00057 TKey *titkey;
00058 TDirectory *titDir;
00059 while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) {
00060
00061 titDir = (TDirectory *)titkey->ReadObj();
00062 TString methodTitle;
00063 TMVAGlob::GetMethodTitle(methodTitle,titDir);
00064 TString hname = "MVA_" + methodTitle;
00065 if (CheckDerivedPlots) hname += TString("_") + DerivedPlotName;
00066
00067 TH1* sig = dynamic_cast<TH1*>(titDir->Get( hname + "_S" ));
00068 TH1* bgd = dynamic_cast<TH1*>(titDir->Get( hname + "_B" ));
00069
00070 if (sig==0 || bgd==0) continue;
00071
00072
00073 sig->SetTitle( Form("TMVA output for classifier: %s", methodTitle.Data()) );
00074 if (htype == ProbaType)
00075 sig->SetTitle( Form("TMVA probability for classifier: %s", methodTitle.Data()) );
00076 else if (htype == RarityType)
00077 sig->SetTitle( Form("TMVA Rarity for classifier: %s", methodTitle.Data()) );
00078
00079
00080 TString ctitle = ((htype == MVAType) ?
00081 Form("TMVA output %s",methodTitle.Data()) :
00082 (htype == ProbaType) ?
00083 Form("TMVA probability %s",methodTitle.Data()) :
00084 Form("TMVA rarity %s",methodTitle.Data()));
00085
00086 TString cname = ((htype == MVAType) ?
00087 Form("output_%s",methodTitle.Data()) :
00088 (htype == ProbaType) ?
00089 Form("probability_%s",methodTitle.Data()) :
00090 Form("rarity_%s",methodTitle.Data()));
00091
00092 c = new TCanvas( Form("canvas%d", countCanvas+1), ctitle,
00093 countCanvas*50+200, countCanvas*20, width, width*0.78 );
00094
00095
00096 TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
00097
00098
00099 TMVAGlob::NormalizeHists( sig, bgd );
00100
00101
00102 Float_t nrms = 4;
00103 Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(),
00104 bgd->GetMean() - nrms*bgd->GetRMS() ),
00105 sig->GetXaxis()->GetXmin() );
00106 Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(),
00107 bgd->GetMean() + nrms*bgd->GetRMS() ),
00108 sig->GetXaxis()->GetXmax() );
00109 Float_t ymin = 0;
00110 Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*1.2 ;
00111
00112 if (Draw_CFANN_Logy && mvaName[imva] == "CFANN") ymin = 0.01;
00113
00114
00115 Int_t nb = 500;
00116 TH2F* frame = new TH2F( TString("frame") + methodTitle, sig->GetTitle(),
00117 nb, xmin, xmax, nb, ymin, ymax );
00118 frame->GetXaxis()->SetTitle(methodTitle);
00119 if (htype == ProbaType ) frame->GetXaxis()->SetTitle( "Signal probability" );
00120 else if (htype == RarityType) frame->GetXaxis()->SetTitle( "Signal rarity" );
00121 frame->GetYaxis()->SetTitle("Normalized");
00122 TMVAGlob::SetFrameStyle( frame );
00123
00124
00125 frame->Draw();
00126
00127 c->GetPad(0)->SetLeftMargin( 0.105 );
00128 frame->GetYaxis()->SetTitleOffset( 1.2 );
00129
00130 if (Draw_CFANN_Logy && mvaName[imva] == "CFANN") c->SetLogy();
00131
00132
00133 TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12,
00134 c->GetLeftMargin() + 0.3, 1 - c->GetTopMargin() );
00135 legend->SetFillStyle( 1 );
00136 legend->AddEntry(sig,"Signal","F");
00137 legend->AddEntry(bgd,"Background","F");
00138 legend->SetBorderSize(1);
00139 legend->SetMargin( 0.3 );
00140 legend->Draw("same");
00141
00142
00143 sig->Draw("samehist");
00144 bgd->Draw("samehist");
00145
00146
00147 TString hStem(hname);
00148 cout << "--- Searching for histogram: " << hStem.Data() << " in application file" << endl;
00149
00150 TH1* testHist = (TH1*)fileApp->Get( hStem );
00151 if (testHist != 0) {
00152 cout << "--> Found application histogram: " << testHist->GetName() << " --> superimpose it" << endl;
00153
00154 TMVAGlob::NormalizeHists( testHist );
00155 testHist->SetLineWidth( 3 );
00156 testHist->SetLineColor( 1 );
00157 testHist->Draw("samehist");
00158 }
00159
00160
00161 frame->Draw("sameaxis");
00162
00163
00164 Int_t nbin = sig->GetNbinsX();
00165 Double_t dxu = sig->GetBinWidth(0);
00166 Double_t dxo = sig->GetBinWidth(nbin+1);
00167 TString uoflow = Form( "U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%",
00168 sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100,
00169 sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 );
00170 TText* t = new TText( 0.975, 0.115, uoflow );
00171 t->SetNDC();
00172 t->SetTextSize( 0.030 );
00173 t->SetTextAngle( 90 );
00174 t->AppendPad();
00175
00176
00177 c->Update();
00178 TMVAGlob::plot_logo();
00179 if (Save_Images) {
00180 if (htype == MVAType) TMVAGlob::imgconv( c, Form("plots/mva_%s", methodTitle.Data()) );
00181 else if (htype == ProbaType) TMVAGlob::imgconv( c, Form("plots/proba_%s", methodTitle.Data()) );
00182 else TMVAGlob::imgconv( c, Form("plots/rarity_%s", methodTitle.Data()) );
00183 }
00184 countCanvas++;
00185 }
00186 }
00187 }