16 void TMVA::mvas(TString dataset, TString fin, HistType htype, Bool_t useTMVAStyle )
 
   19    TMVAGlob::Initialize( useTMVAStyle );
 
   22    const Bool_t Save_Images = kTRUE;
 
   25    TFile* file = TMVAGlob::OpenFile( fin );  
 
   28    const Int_t width = 600;   
 
   34    Int_t countCanvas = 0;
 
   37    TIter next(file->GetDirectory(dataset.Data())->GetListOfKeys());
 
   39    while ((key = (TKey*)next())) {
 
   41       if (!TString(key->GetName()).BeginsWith(
"Method_")) 
continue;
 
   42       if (!gROOT->GetClass(key->GetClassName())->InheritsFrom(
"TDirectory")) 
continue;
 
   45       TMVAGlob::GetMethodName(methodName,key);
 
   47       TDirectory* mDir = (TDirectory*)key->ReadObj();
 
   49       TIter keyIt(mDir->GetListOfKeys());
 
   51       while ((titkey = (TKey*)keyIt())) {
 
   53          if (!gROOT->GetClass(titkey->GetClassName())->InheritsFrom(
"TDirectory")) 
continue;
 
   55          TDirectory *titDir = (TDirectory *)titkey->ReadObj();
 
   57          TMVAGlob::GetMethodTitle(methodTitle,titDir);
 
   59          std::cout << 
"--- Found directory for method: " << methodName << 
"::" << methodTitle << std::flush;
 
   60          TString hname = 
"MVA_" + methodTitle;
 
   61          if      (htype == kProbaType  ) hname += 
"_Proba";
 
   62          else if (htype == kRarityType ) hname += 
"_Rarity";
 
   63          TH1* sig = 
dynamic_cast<TH1*
>(titDir->Get( hname + 
"_S" ));
 
   64          TH1* bgd = 
dynamic_cast<TH1*
>(titDir->Get( hname + 
"_B" ));
 
   66          if (sig==0 || bgd==0) {
 
   67             if     (htype == kMVAType)     
 
   68                cout << 
":\t mva distribution not available (this is normal for Cut classifier)" << endl;
 
   69             else if(htype == kProbaType)   
 
   70                cout << 
":\t probability distribution not available" << endl;
 
   71             else if(htype == kRarityType)  
 
   72                cout << 
":\t rarity distribution not available" << endl;
 
   73             else if(htype == kCompareType) 
 
   74                cout << 
":\t overtraining check not available" << endl;
 
   79          cout << 
" containing " << hname << 
"_S/_B" << endl;
 
   81          sig->SetTitle( Form(
"TMVA response for classifier: %s", methodTitle.Data()) );
 
   82          if      (htype == kProbaType) 
 
   83             sig->SetTitle( Form(
"TMVA probability for classifier: %s", methodTitle.Data()) );
 
   84          else if (htype == kRarityType) 
 
   85             sig->SetTitle( Form(
"TMVA Rarity for classifier: %s", methodTitle.Data()) );
 
   86          else if (htype == kCompareType) 
 
   87             sig->SetTitle( Form(
"TMVA overtraining check for classifier: %s", methodTitle.Data()) );
 
   90          TString ctitle = ((htype == kMVAType) ? 
 
   91                            Form(
"TMVA response %s",methodTitle.Data()) : 
 
   92                            (htype == kProbaType) ? 
 
   93                            Form(
"TMVA probability %s",methodTitle.Data()) :
 
   94                            (htype == kCompareType) ? 
 
   95                            Form(
"TMVA comparison %s",methodTitle.Data()) :
 
   96                            Form(
"TMVA Rarity %s",methodTitle.Data()));
 
   98          c = 
new TCanvas( Form(
"canvas%d", countCanvas+1), ctitle, 
 
   99                           countCanvas*50+200, countCanvas*20, width, (Int_t)width*0.78 ); 
 
  102          TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd );
 
  105          TMVAGlob::NormalizeHists( sig, bgd );
 
  109          cout << 
"--- Mean and RMS (S): " << sig->GetMean() << 
", " << sig->GetRMS() << endl;
 
  110          cout << 
"--- Mean and RMS (B): " << bgd->GetMean() << 
", " << bgd->GetRMS() << endl;
 
  111          Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), 
 
  112                                                bgd->GetMean() - nrms*bgd->GetRMS() ),
 
  113                                     sig->GetXaxis()->GetXmin() );
 
  114          Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), 
 
  115                                                bgd->GetMean() + nrms*bgd->GetRMS() ),
 
  116                                     sig->GetXaxis()->GetXmax() );
 
  118          Float_t maxMult = (htype == kCompareType) ? 1.3 : 1.2;
 
  119          Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*maxMult;
 
  123          TString hFrameName(TString(
"frame") + methodTitle);
 
  124          TObject *o = gROOT->FindObject(hFrameName);
 
  126          TH2F* frame = 
new TH2F( hFrameName, sig->GetTitle(), 
 
  127                                  nb, xmin, xmax, nb, ymin, ymax );
 
  128          frame->GetXaxis()->SetTitle( methodTitle + ((htype == kMVAType || htype == kCompareType) ? 
" response" : 
"") );
 
  129          if      (htype == kProbaType  ) frame->GetXaxis()->SetTitle( 
"Signal probability" );
 
  130          else if (htype == kRarityType ) frame->GetXaxis()->SetTitle( 
"Signal rarity" );
 
  131          frame->GetYaxis()->SetTitle(
"(1/N) dN^{ }/^{ }dx");
 
  132          TMVAGlob::SetFrameStyle( frame );
 
  137          c->GetPad(0)->SetLeftMargin( 0.105 );
 
  138          frame->GetYaxis()->SetTitleOffset( 1.2 );
 
  141          TLegend *legend= 
new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.12, 
 
  142                                        c->GetLeftMargin() + (htype == kCompareType ? 0.40 : 0.3), 1 - c->GetTopMargin() );
 
  143          legend->SetFillStyle( 1 );
 
  144          legend->AddEntry(sig,TString(
"Signal")     + ((htype == kCompareType) ? 
" (test sample)" : 
""), 
"F");
 
  145          legend->AddEntry(bgd,TString(
"Background") + ((htype == kCompareType) ? 
" (test sample)" : 
""), 
"F");
 
  146          legend->SetBorderSize(1);
 
  147          legend->SetMargin( (htype == kCompareType ? 0.2 : 0.3) );
 
  148          legend->Draw(
"same");
 
  151          sig->Draw(
"samehist");
 
  152          bgd->Draw(
"samehist");
 
  154          if (htype == kCompareType) {
 
  159             TString ovname = hname += 
"_Train";
 
  160             sigOv = 
dynamic_cast<TH1*
>(titDir->Get( ovname + 
"_S" ));
 
  161             bgdOv = 
dynamic_cast<TH1*
>(titDir->Get( ovname + 
"_B" ));
 
  163             if (sigOv == 0 || bgdOv == 0) {
 
  164                cout << 
"+++ Problem in \"mvas.C\": overtraining check histograms do not exist" << endl;
 
  167                cout << 
"--- Found comparison histograms for overtraining check" << endl;
 
  169                TLegend *legend2= 
new TLegend( 1 - c->GetRightMargin() - 0.42, 1 - c->GetTopMargin() - 0.12,
 
  170                                               1 - c->GetRightMargin(), 1 - c->GetTopMargin() );
 
  171                legend2->SetFillStyle( 1 );
 
  172                legend2->SetBorderSize(1);
 
  173                legend2->AddEntry(sigOv,
"Signal (training sample)",
"P");
 
  174                legend2->AddEntry(bgdOv,
"Background (training sample)",
"P");
 
  175                legend2->SetMargin( 0.1 );
 
  176                legend2->Draw(
"same");
 
  179             TMVAGlob::NormalizeHists( sigOv, bgdOv );
 
  181             Int_t col = sig->GetLineColor();
 
  182             sigOv->SetMarkerColor( col );
 
  183             sigOv->SetMarkerSize( 0.7 );
 
  184             sigOv->SetMarkerStyle( 20 );
 
  185             sigOv->SetLineWidth( 1 );
 
  186             sigOv->SetLineColor( col );
 
  187             sigOv->Draw(
"e1same");
 
  189             col = bgd->GetLineColor();
 
  190             bgdOv->SetMarkerColor( col );
 
  191             bgdOv->SetMarkerSize( 0.7 );
 
  192             bgdOv->SetMarkerStyle( 20 );
 
  193             bgdOv->SetLineWidth( 1 );
 
  194             bgdOv->SetLineColor( col );
 
  195             bgdOv->Draw(
"e1same");
 
  197             ymax = TMath::Max( ymax, 
float(TMath::Max( sigOv->GetMaximum(), bgdOv->GetMaximum() )*maxMult ));
 
  198             frame->GetYaxis()->SetLimits( 0, ymax );
 
  201             sig->SetLineWidth( 1 );
 
  202             bgd->SetLineWidth( 1 );
 
  205             cout << 
"--- Perform Kolmogorov-Smirnov tests" << endl;
 
  206             Double_t kolS = sig->KolmogorovTest( sigOv, 
"X" );
 
  207             Double_t kolB = bgd->KolmogorovTest( bgdOv, 
"X" );
 
  208             cout << 
"--- Goodness of signal (background) consistency: " << kolS << 
" (" << kolB << 
")" << endl;
 
  210             TString probatext = Form( 
"Kolmogorov-Smirnov test: signal (background) probability = %5.3g (%5.3g)", kolS, kolB );
 
  211             TText* tt = 
new TText( 0.12, 0.74, probatext );
 
  212             tt->SetNDC(); tt->SetTextSize( 0.032 ); tt->AppendPad(); 
 
  216          frame->Draw(
"sameaxis");
 
  219          Int_t    nbin = sig->GetNbinsX();
 
  220          Double_t dxu  = sig->GetBinWidth(0);
 
  221          Double_t dxo  = sig->GetBinWidth(nbin+1);
 
  222          TString uoflow = Form( 
"U/O-flow (S,B): (%.1f, %.1f)%% / (%.1f, %.1f)%%", 
 
  223                                 sig->GetBinContent(0)*dxu*100, bgd->GetBinContent(0)*dxu*100,
 
  224                                 sig->GetBinContent(nbin+1)*dxo*100, bgd->GetBinContent(nbin+1)*dxo*100 );
 
  225          TText* t = 
new TText( 0.975, 0.115, uoflow );
 
  227          t->SetTextSize( 0.030 );
 
  228          t->SetTextAngle( 90 );
 
  236          TMVAGlob::plot_logo(1.058);
 
  238             if      (htype == kMVAType)     TMVAGlob::imgconv( c, Form(
"%s/plots/mva_%s",dataset.Data(),     methodTitle.Data()) );
 
  239             else if (htype == kProbaType)   TMVAGlob::imgconv( c, Form(
"%s/plots/proba_%s",dataset.Data(),   methodTitle.Data()) ); 
 
  240             else if (htype == kCompareType) TMVAGlob::imgconv( c, Form(
"%s/plots/overtrain_%s",dataset.Data(), methodTitle.Data()) ); 
 
  241             else                           TMVAGlob::imgconv( c, Form(
"%s/plots/rarity_%s",dataset.Data(), methodTitle.Data()) );