// input: - Input file (result from TMVA), // - use of TMVA plotting TStyle void network( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); Network_GFile = file; TKey* mkey = TMVAGlob::FindMethod("MLP"); if (mkey==0) { cout << "Could not locate directory MLP in file " << fin << endl; return; } TDirectory *dir = (TDirectory *)mkey->ReadObj(); dir->cd(); TList titles; UInt_t ni = TMVAGlob::GetListOfTitles( dir, titles ); if (ni==0) { cout << "No titles found for Method_MLP" << endl; return; } TIter nextTitle(&titles); TKey *titkey; TDirectory *titDir; while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) { titDir = (TDirectory *)titkey->ReadObj(); cout << "Drawing title: " << titDir->GetName() << endl; draw_network(titDir); } }
void TitleWIdget::wheelEvent(QWheelEvent *ev) { if(ev->delta() > 0) { prevTitle(); emit prevTitleSignal(); } else { nextTitle(); emit nextTitleSignal(); } }
void plot_efficiencies( TFile* file, Int_t type = 2, TDirectory* BinDir) { // input: - Input file (result from TMVA), // - type = 1 --> plot efficiency(B) versus eff(S) // = 2 --> plot rejection (B) versus efficiency (S) Bool_t __PLOT_LOGO__ = kTRUE; Bool_t __SAVE_IMAGE__ = kTRUE; // the coordinates Float_t x1 = 0; Float_t x2 = 1; Float_t y1 = 0; Float_t y2 = 0.8; // reverse order if "rejection" if (type == 2) { Float_t z = y1; y1 = 1 - y2; y2 = 1 - z; // cout << "--- type==2: plot background rejection versus signal efficiency" << endl; } else { // cout << "--- type==1: plot background efficiency versus signal efficiency" << endl; } // create canvas TCanvas* c = new TCanvas( "c", "the canvas", 200, 0, 650, 500 ); // global style settings c->SetGrid(); c->SetTicks(); // legend Float_t x0L = 0.107, y0H = 0.899; Float_t dxL = 0.457-x0L, dyH = 0.22; if (type == 2) { x0L = 0.15; y0H = 1 - y0H + dyH + 0.07; } TLegend *legend = new TLegend( x0L, y0H-dyH, x0L+dxL, y0H ); legend->SetTextSize( 0.05 ); legend->SetHeader( "MVA Method:" ); legend->SetMargin( 0.4 ); TString xtit = "Signal efficiency"; TString ytit = "Background efficiency"; if (type == 2) ytit = "Background rejection"; TString ftit = ytit + " versus " + xtit; if (TString(BinDir->GetName()).Contains("multicut")){ ftit += " Bin: "; ftit += (BinDir->GetTitle()); } // draw empty frame if(gROOT->FindObject("frame")!=0) gROOT->FindObject("frame")->Delete(); TH2F* frame = new TH2F( "frame", ftit, 500, x1, x2, 500, y1, y2 ); frame->GetXaxis()->SetTitle( xtit ); frame->GetYaxis()->SetTitle( ytit ); TMVAGlob::SetFrameStyle( frame, 1.0 ); frame->Draw(); Int_t color = 1; Int_t nmva = 0; TKey *key, *hkey; TString hNameRef = "effBvsS"; if (type == 2) hNameRef = "rejBvsS"; TList hists; TList methods; UInt_t nm = TMVAGlob::GetListOfMethods( methods ); // TIter next(file->GetListOfKeys()); TIter next(&methods); // loop over all methods while (key = (TKey*)next()) { TDirectory * mDir = (TDirectory*)key->ReadObj(); TList titles; UInt_t ninst = TMVAGlob::GetListOfTitles(mDir,titles); TIter nextTitle(&titles); TKey *titkey; TDirectory *titDir; while ((titkey = TMVAGlob::NextKey(nextTitle,"TDirectory"))) { titDir = (TDirectory *)titkey->ReadObj(); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,titDir); TIter nextKey( titDir->GetListOfKeys() ); while ((hkey = TMVAGlob::NextKey(nextKey,"TH1"))) { TH1 *h = (TH1*)hkey->ReadObj(); TString hname = h->GetName(); if (hname.Contains( hNameRef ) && hname.BeginsWith( "MVA_" )) { h->SetLineWidth(3); h->SetLineColor(color); color++; if (color == 5 || color == 10 || color == 11) color++; h->Draw("csame"); hists.Add(h); nmva++; } } } } while (hists.GetSize()) { TListIter hIt(&hists); TH1* hist(0); Double_t largestInt=-1; TH1* histWithLargestInt(0); while ((hist = (TH1*)hIt())!=0) { Double_t integral = hist->Integral(1,hist->FindBin(0.9999)); if (integral>largestInt) { largestInt = integral; histWithLargestInt = hist; } } if (histWithLargestInt == 0) { cout << "ERROR - unknown hist \"histWithLargestInt\" --> serious problem in ROOT file" << endl; break; } legend->AddEntry(histWithLargestInt,TString(histWithLargestInt->GetTitle()).ReplaceAll("MVA_",""),"l"); hists.Remove(histWithLargestInt); } // rescale legend box size // current box size has been tuned for 3 MVAs + 1 title if (type == 1) { dyH *= (1.0 + Float_t(nmva - 3.0)/4.0); legend->SetY1( y0H - dyH ); } else { dyH *= (Float_t(nmva - 3.0)/4.0); legend->SetY2( y0H + dyH); } // redraw axes frame->Draw("sameaxis"); legend->Draw("same"); // ============================================================ if (__PLOT_LOGO__) TMVAGlob::plot_logo(); // ============================================================ c->Update(); TString fname = "plots/" + hNameRef; if (TString(BinDir->GetName()).Contains("multicut")){ TString fprepend(BinDir->GetName()); fprepend.ReplaceAll("multicutMVA_",""); fname = "plots/" + fprepend + "_" + hNameRef; } if (__SAVE_IMAGE__) TMVAGlob::imgconv( c, fname ); return; }
// input: - Input file (result from TMVA) // - use of TMVA plotting TStyle void probas( TString fin = "TMVA.root", Bool_t useTMVAStyle = kTRUE ) { // set style and remove existing canvas' TMVAGlob::Initialize( useTMVAStyle ); // switches const Bool_t Draw_CFANN_Logy = kFALSE; const Bool_t Save_Images = kTRUE; // checks if file with name "fin" is already open, and if not opens one TFile* file = TMVAGlob::OpenFile( fin ); // define Canvas layout here! Int_t xPad = 1; // no of plots in x Int_t yPad = 1; // no of plots in y Int_t noPad = xPad * yPad ; const Int_t width = 600; // size of canvas // this defines how many canvases we need TCanvas *c = 0; // counter variables Int_t countCanvas = 0; // list of existing MVAs const Int_t nveto = 1; TString suffixSig = "_tr_S"; TString suffixBgd = "_tr_B"; // search for the right histograms in full list of keys TList methods; UInt_t nmethods = TMVAGlob::GetListOfMethods( methods ); if (nmethods==0) { cout << "--- Probas.C: no methods found!" << endl; return; } TIter next(&methods); TKey *key, *hkey; char fname[200]; TH1* sig(0); TH1* bgd(0); while ((key = (TKey*)next())) { TDirectory * mDir = (TDirectory*)key->ReadObj(); TList titles; UInt_t ni = TMVAGlob::GetListOfTitles( mDir, titles ); TString methodName; TMVAGlob::GetMethodName(methodName,key); if (ni==0) { cout << "+++ No titles found for classifier: " << methodName << endl; return; } TIter nextTitle(&titles); TKey *instkey; TDirectory *instDir; while ((instkey = (TKey *)nextTitle())) { instDir = (TDirectory *)instkey->ReadObj(); TString instName = instkey->GetName(); TList h1hists; UInt_t nhists = TMVAGlob::GetListOfKeys( h1hists, "TH1", instDir ); if (nhists==0) cout << "*** No histograms found!" << endl; TIter nextInDir(&h1hists); TString methodTitle; TMVAGlob::GetMethodTitle(methodTitle,instDir); while (hkey = (TKey*)nextInDir()) { TH1 *th1 = (TH1*)hkey->ReadObj(); TString hname= th1->GetName(); if (hname.Contains( suffixSig ) && !hname.Contains( "Cut") && !hname.Contains("original") && !hname.Contains("smoothed")) { // retrieve corresponding signal and background histograms TString hnameS = hname; TString hnameB = hname; hnameB.ReplaceAll("_S","_B"); sig = (TH1*)instDir->Get( hnameS ); bgd = (TH1*)instDir->Get( hnameB ); if (sig == 0 || bgd == 0) { cout << "*** probas.C: big troubles in probas.... histogram: " << hname << " not found" << endl; return; } TH1* sigF(0); TH1* bkgF(0); for (int i=0; i<= 5; i++) { TString hspline = hnameS + Form("_smoothed_hist_from_spline%i",i); sigF = (TH1*)instDir->Get( hspline ); if (sigF) { bkgF = (TH1*)instDir->Get( hspline.ReplaceAll("_tr_S","_tr_B") ); break; } } if ((sigF == NULL || bkgF == NULL) &&!hname.Contains("hist") ) { cout << "*** probas.C: big troubles - did not found histogram " << hspline.Data() << " " << sigF << " " << bkgF << endl; return; } else { // remove the signal suffix // check that exist if (NULL != sigF && NULL != bkgF && NULL!=sig && NULL!=bgd) { TString hname = sig->GetName(); // chop off useless stuff sig->SetTitle( TString("TMVA output for classifier: ") + methodTitle ); // create new canvas cout << "--- Book canvas no: " << countCanvas << endl; char cn[20]; sprintf( cn, "canvas%d", countCanvas+1 ); c = new TCanvas( cn, Form("TMVA Output Fit Variables %s",methodTitle.Data()), countCanvas*50+200, countCanvas*20, width, width*0.78 ); // set the histogram style TMVAGlob::SetSignalAndBackgroundStyle( sig, bgd ); TMVAGlob::SetSignalAndBackgroundStyle( sigF, bkgF ); // frame limits (choose judicuous x range) Float_t nrms = 4; Float_t xmin = TMath::Max( TMath::Min(sig->GetMean() - nrms*sig->GetRMS(), bgd->GetMean() - nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmin() ); Float_t xmax = TMath::Min( TMath::Max(sig->GetMean() + nrms*sig->GetRMS(), bgd->GetMean() + nrms*bgd->GetRMS() ), sig->GetXaxis()->GetXmax() ); Float_t ymin = 0; Float_t ymax = TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*1.5; if (Draw_CFANN_Logy && mvaName[imva] == "CFANN") ymin = 0.01; // build a frame Int_t nb = 500; TH2F* frame = new TH2F( TString("frame") + sig->GetName() + "_proba", sig->GetTitle(), nb, xmin, xmax, nb, ymin, ymax ); frame->GetXaxis()->SetTitle(methodTitle); frame->GetYaxis()->SetTitle("Normalized"); TMVAGlob::SetFrameStyle( frame ); // eventually: draw the frame frame->Draw(); if (Draw_CFANN_Logy && mvaName[imva] == "CFANN") c->SetLogy(); // overlay signal and background histograms sig->SetMarkerColor( TMVAGlob::c_SignalLine ); sig->SetMarkerSize( 0.7 ); sig->SetMarkerStyle( 20 ); sig->SetLineWidth(1); bgd->SetMarkerColor( TMVAGlob::c_BackgroundLine ); bgd->SetMarkerSize( 0.7 ); bgd->SetMarkerStyle( 24 ); bgd->SetLineWidth(1); sig->Draw("samee"); bgd->Draw("samee"); sigF->SetFillStyle( 0 ); bkgF->SetFillStyle( 0 ); sigF->Draw("samehist"); bkgF->Draw("samehist"); // redraw axes frame->Draw("sameaxis"); // Draw legend TLegend *legend= new TLegend( c->GetLeftMargin(), 1 - c->GetTopMargin() - 0.2, c->GetLeftMargin() + 0.4, 1 - c->GetTopMargin() ); legend->AddEntry(sig,"Signal data","P"); legend->AddEntry(sigF,"Signal PDF","L"); legend->AddEntry(bgd,"Background data","P"); legend->AddEntry(bkgF,"Background PDF","L"); legend->Draw("same"); legend->SetBorderSize(1); legend->SetMargin( 0.3 ); // save canvas to file c->Update(); TMVAGlob::plot_logo(); sprintf( fname, "plots/mva_pdf_%s_c%i", methodTitle.Data(), countCanvas+1 ); if (Save_Images) TMVAGlob::imgconv( c, fname ); countCanvas++; } } } } } } }