# Path: mva_tools/build_roc_simple.py
# def build_roc(h_sig, h_bkg, verbose=0):
# 
#     nbins_sig = h_sig.GetXaxis().GetNbins()
#     nbins_bkg = h_bkg.GetXaxis().GetNbins()
#     nbins = nbins_sig if nbins_sig == nbins_bkg else -1
#     #print nbins
#     if nbins < 0.0:
#         sys.exit("Error: nbins_sig != nbins_bkg")
# 
#     min_val = h_sig.GetXaxis().GetXmin()
#     max_val = h_sig.GetXaxis().GetXmax()
# 
#     step = float(max_val - min_val)/(nbins-1)
#     sig_eff = array('f', [])
#     bkg_rej = array('f', [])
# 
#     total_sig = h_sig.Integral()
#     total_bkg = h_bkg.Integral()
#     print total_sig
#     print total_bkg
# 
#     sig_rejected = 0.0
#     bkg_rejected = 0.0
#     for i in xrange_bins(nbins):
#         sig_rejected += h_sig.GetBinContent(i)
#         #print sig_rejected
#         bkg_rejected += h_bkg.GetBinContent(i)
#         #print bkg_rejected
# 
#         seff = float(total_sig-sig_rejected)/total_sig
#         brej = float(bkg_rejected)/total_bkg
#         #print seff, brej
#         sig_eff.append(seff)
#         bkg_rej.append(brej) 
# 
#         if verbose == 1:
#             bdt_score = min_val + i * step
#             print "bdt score =", bdt_score, "sig_eff =", seff 
#         
#         #bin_sig = h_sig.GetBinContent()
#     print "Overflow =", h_sig.GetBinContent(nbins_sig+1)
#     print "Underflow =", h_sig.GetBinContent(0)
# 
#     g = ROOT.TGraph(nbins, sig_eff, bkg_rej)
#     g.GetXaxis().SetRangeUser(0.0,1.0)
#     g.GetYaxis().SetRangeUser(0.0,1.0)
#     #g.Draw("AC")
#     #g.SetLineColor(ROOT.kRed)
#     g.SetTitle("ROC curve")
#     
# 
#     return g
#     
#     #print nbins_bkg


import ROOT
from ROOT import TGraphErrors
from array import array
from mva_tools.build_roc_simple import build_roc 
    hsig_skTMVA_path = "histo_tmva_sig"
    hbkg_skTMVA_path = "histo_tmva_bkg"
    hsig_sklearn_path = "histo_sk_sig"
    hbkg_sklearn_path = "histo_sk_bkg"

    rootfile = ROOT.TFile.Open(path)

    if rootfile.IsZombie():
        print "Root file is corrupt"

    hSig_skTMVA = rootfile.Get(hsig_skTMVA_path)
    hBkg_skTMVA = rootfile.Get(hbkg_skTMVA_path)
    hSig_sklearn = rootfile.Get(hsig_sklearn_path)
    hBkg_sklearn = rootfile.Get(hbkg_sklearn_path)



    # Stack for keeping plots
    plots = []

    # Getting ROC-curve for skTMVA
    g1 = build_roc(hSig_skTMVA, hBkg_skTMVA)
    g1.SetName("g1")
    g1.SetTitle("ROC curve [muons]")
    plots.append(g1)

    g1.SetLineColor(ROOT.kBlue)
    g1.Draw("AL") # draw TGraph with no marker dots

    # Getting ROC-curve for sklearn

# Path: mva_tools/build_roc_simple.py
# def build_roc(h_sig, h_bkg, verbose=0):
# 
#     nbins_sig = h_sig.GetXaxis().GetNbins()
#     nbins_bkg = h_bkg.GetXaxis().GetNbins()
#     nbins = nbins_sig if nbins_sig == nbins_bkg else -1
#     #print nbins
#     if nbins < 0.0:
#         sys.exit("Error: nbins_sig != nbins_bkg")
# 
#     min_val = h_sig.GetXaxis().GetXmin()
#     max_val = h_sig.GetXaxis().GetXmax()
# 
#     step = float(max_val - min_val)/(nbins-1)
#     sig_eff = array('f', [])
#     bkg_rej = array('f', [])
# 
#     total_sig = h_sig.Integral()
#     total_bkg = h_bkg.Integral()
#     print total_sig
#     print total_bkg
# 
#     sig_rejected = 0.0
#     bkg_rejected = 0.0
#     for i in xrange_bins(nbins):
#         sig_rejected += h_sig.GetBinContent(i)
#         #print sig_rejected
#         bkg_rejected += h_bkg.GetBinContent(i)
#         #print bkg_rejected
# 
#         seff = float(total_sig-sig_rejected)/total_sig
#         brej = float(bkg_rejected)/total_bkg
#         #print seff, brej
#         sig_eff.append(seff)
#         bkg_rej.append(brej) 
# 
#         if verbose == 1:
#             bdt_score = min_val + i * step
#             print "bdt score =", bdt_score, "sig_eff =", seff 
#         
#         #bin_sig = h_sig.GetBinContent()
#     print "Overflow =", h_sig.GetBinContent(nbins_sig+1)
#     print "Underflow =", h_sig.GetBinContent(0)
# 
#     g = ROOT.TGraph(nbins, sig_eff, bkg_rej)
#     g.GetXaxis().SetRangeUser(0.0,1.0)
#     g.GetYaxis().SetRangeUser(0.0,1.0)
#     #g.Draw("AC")
#     #g.SetLineColor(ROOT.kRed)
#     g.SetTitle("ROC curve")
#     
# 
#     return g
#     
#     #print nbins_bkg


# Path: test/run1/draw_roc_sklearn_vs_skTMVA_muons.py
import ROOT
from ROOT import TGraphErrors
from array import array
from mva_tools.build_roc_simple import build_roc 

    hsig_skTMVA_path = "histo_tmva_sig"
    hbkg_skTMVA_path = "histo_tmva_bkg"
    hsig_sklearn_path = "histo_sk_sig"
    hbkg_sklearn_path = "histo_sk_bkg"

    rootfile = ROOT.TFile.Open(path)

    if rootfile.IsZombie():
        print "Root file is corrupt"

    hSig_skTMVA = rootfile.Get(hsig_skTMVA_path)
    hBkg_skTMVA = rootfile.Get(hbkg_skTMVA_path)
    hSig_sklearn = rootfile.Get(hsig_sklearn_path)
    hBkg_sklearn = rootfile.Get(hbkg_sklearn_path)



    # Stack for keeping plots
    plots = []

    # Getting ROC-curve for skTMVA
    g1 = build_roc(hSig_skTMVA, hBkg_skTMVA)
    g1.SetName("g1")
    g1.SetTitle("ROC curve [muons]")
    plots.append(g1)

    g1.SetLineColor(ROOT.kBlue)
    g1.Draw("AL") # draw TGraph with no marker dots

    # Getting ROC-curve for sklearn

    g2 = build_roc(hSig_sklearn, hBkg_sklearn)