23 void TMVA::probas(TString dataset, TString fin , Bool_t useTMVAStyle )
26 TMVAGlob::Initialize( useTMVAStyle );
29 const Bool_t Draw_CFANN_Logy = kFALSE;
30 const Bool_t Save_Images = kTRUE;
33 TFile* file = TMVAGlob::OpenFile( fin );
35 const Int_t width = 600;
41 Int_t countCanvas = 0;
45 TString suffixSig =
"_tr_S";
46 TString suffixBgd =
"_tr_B";
50 UInt_t nmethods = TMVAGlob::GetListOfMethods( methods,file->GetDirectory(dataset.Data()) );
52 cout <<
"--- Probas.C: no methods found!" << endl;
62 while ( (key = (TKey*)next()) ) {
63 TDirectory * mDir = (TDirectory*)key->ReadObj();
65 UInt_t ni = TMVAGlob::GetListOfTitles( mDir, titles );
67 TMVAGlob::GetMethodName(methodName,key);
69 cout <<
"+++ No titles found for classifier: " << methodName << endl;
72 TIter nextTitle(&titles);
77 while ( (instkey = (TKey *)nextTitle()) ) {
78 instDir = (TDirectory *)instkey->ReadObj();
79 TString instName = instkey->GetName();
81 UInt_t nhists = TMVAGlob::GetListOfKeys( h1hists,
"TH1", instDir );
82 if (nhists==0) cout <<
"*** No histograms found!" << endl;
83 TIter nextInDir(&h1hists);
85 TMVAGlob::GetMethodTitle(methodTitle,instDir);
86 Bool_t found = kFALSE;
87 while ( (hkey = (TKey*)nextInDir()) ) {
88 TH1 *th1 = (TH1*)hkey->ReadObj();
89 TString hname= th1->GetName();
90 if (hname.Contains( suffixSig ) && !hname.Contains(
"Cut") &&
91 !hname.Contains(
"original") && !hname.Contains(
"smoothed")) {
93 TString hnameS = hname;
94 TString hnameB = hname; hnameB.ReplaceAll(
"_S",
"_B");
96 sig = (TH1*)instDir->Get( hnameS );
97 bgd = (TH1*)instDir->Get( hnameB );
99 if (sig == 0 || bgd == 0) {
100 cout <<
"*** probas.C: big troubles in probas.... histogram: " << hname <<
" not found" << endl;
107 for (
int i=0; i<= 5; i++) {
108 TString hspline = hnameS + Form(
"_smoothed_hist_from_spline%i",i);
109 sigF = (TH1*)instDir->Get( hspline );
112 bkgF = (TH1*)instDir->Get( hspline.ReplaceAll(
"_tr_S",
"_tr_B") );
117 TString hspline = hnameS + TString(
"_smoothed_hist_from_KDE");
118 sigF = (TH1*)instDir->Get( hspline );
121 bkgF = (TH1*)instDir->Get( hspline.ReplaceAll(
"_tr_S",
"_tr_B") );
125 if ((sigF == NULL || bkgF == NULL) &&!hname.Contains(
"hist") ) {
126 cout <<
"*** probas.C: big troubles - did not find probability histograms" << endl;
133 if (NULL != sigF && NULL != bkgF && NULL!=sig && NULL!=bgd) {
137 sig->SetTitle( TString(
"TMVA output for classifier: ") + methodTitle );
140 cout <<
"--- Book canvas no: " << countCanvas << endl;
142 sprintf( cn,
"canvas%d", countCanvas+1 );
143 c =
new TCanvas( cn, Form(
"TMVA Output Fit Variables %s",methodTitle.Data()),
144 countCanvas*50+200, countCanvas*20, width, width*0.78 );
147 TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
148 TMVAGlob::SetSignalAndBackgroundStyle( sigF, bkgF );
152 Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(),
153 bgd->GetMean() - nrms*bgd->GetRMS() ),
154 sig->GetXaxis()->GetXmin() );
155 Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(),
156 bgd->GetMean() + nrms*bgd->GetRMS() ),
157 sig->GetXaxis()->GetXmax() );
159 Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*1.5;
161 if (Draw_CFANN_Logy && methodName ==
"CFANN") ymin = 0.01;
165 TH2F* frame =
new TH2F( TString(
"frame") + sig->GetName() +
"_proba", sig->GetTitle(),
166 nb, xmin, xmax, nb, ymin, ymax );
167 frame->GetXaxis()->SetTitle(methodTitle);
168 frame->GetYaxis()->SetTitle(
"Normalized");
169 TMVAGlob::SetFrameStyle( frame );
174 if (Draw_CFANN_Logy && methodName ==
"CFANN") c->SetLogy();
177 sig->SetMarkerColor( TMVAGlob::getSignalLine() );
178 sig->SetMarkerSize( 0.7 );
179 sig->SetMarkerStyle( 20 );
180 sig->SetLineWidth(1);
182 bgd->SetMarkerColor( TMVAGlob::getBackgroundLine() );
183 bgd->SetMarkerSize( 0.7 );
184 bgd->SetMarkerStyle( 24 );
185 bgd->SetLineWidth(1);
190 sigF->SetFillStyle( 0 );
191 bkgF->SetFillStyle( 0 );
192 sigF->Draw(
"samehist");
193 bkgF->Draw(
"samehist");
196 frame->Draw(
"sameaxis");
199 TLegend *legend=
new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.2,
200 c->GetLeftMargin() + 0.4, 1 - c->GetTopMargin() );
201 legend->AddEntry(sig,
"Signal data",
"P");
202 legend->AddEntry(sigF,
"Signal PDF",
"L");
203 legend->AddEntry(bgd,
"Background data",
"P");
204 legend->AddEntry(bkgF,
"Background PDF",
"L");
205 legend->Draw(
"same");
206 legend->SetBorderSize(1);
207 legend->SetMargin( 0.3 );
211 TMVAGlob::plot_logo();
212 sprintf( fname,
"%s/plots/mva_pdf_%s_c%i",dataset.Data(), methodTitle.Data(), countCanvas+1 );
213 if (Save_Images) TMVAGlob::imgconv( c, fname );
221 cout <<
"--- No PDFs found for method " << methodTitle <<
". Did you request \"CreateMVAPdfs\" in the option string?" << endl;