statDown = ROOT.TEfficiency.ClopperPearson(int(iden), int(inum),
                                                       0.682689492137, False)
            worse_err = (abs(statUp - ieff) /
                         ieff if abs(statUp - ieff) > abs(statDown - ieff) else
                         abs(statDown - ieff) / ieff) if ieff else 0.
            eff_map.SetBinContent(ibinx, ibiny, ieff)
            eff_map.SetBinError(ibinx, ibiny, worse_err * ieff)
            eff_map_statUp.SetBinContent(ibinx, ibiny, statUp)
            eff_map_statDown.SetBinContent(ibinx, ibiny, statDown)
            worse_rel_err.SetBinContent(ibinx, ibiny, worse_err)

    canvas = ROOT.TCanvas("asdf", "asdf", 800, 600)
    ROOT.gStyle.SetPalette(53)
    eff_map.Draw('colz')
    canvas.Print(args.output.replace(".root", ".png"))
    outFile = ROOT.TFile(args.output, 'recreate')  #FIXME move to rootpy io
    outFile.cd()
    eff_map.Write()
    eff_map_statUp.Write()
    eff_map_statDown.Write()
    worse_rel_err.Write()
    base_dir = os.path.dirname(args.num)

    m = ROOT.RooRealVar('m', 'm', 55, 55, 200)
    os_trkMass = ROOT.RooDataHist(
        'higgs_data', 'higgs_data', ROOT.RooArgList(m),
        input_view.Get(os.path.join(base_dir, 'os_trkMass')))
    mean = ROOT.RooRealVar('mean', 'mean', 90, 80, 110)
    sigmaL = ROOT.RooRealVar('sigmaL', 'sigmaL', 30, 0, 100)
    sigmaR = ROOT.RooRealVar('sigmaR', 'sigmaR', 25, 0, 100)
    alphaL = ROOT.RooRealVar('alphaL', 'alphaL', 1, 0, 30)
from FinalStateAnalysis.Utilities.rootbindings import ROOT
import math
import logging
import sys

ROOT.gStyle.SetOptStat(0)
ROOT.gStyle.SetOptTitle(0)
ROOT.gROOT.SetBatch()

file_dataA = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012A.root')
file_dataB = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012B.root')
file_dataC = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012C.root')
file_dataD = ROOT.TFile('results/newNtuple_5Nov/LFVHETauAnalyzerMVA/ZetauEmbedded_Run2012D.root')

dataA=file_dataA.Get('os/gg/ept30/h_collmass_pfmet')
dataB=file_dataB.Get('os/gg/ept30/h_collmass_pfmet')
dataC=file_dataC.Get('os/gg/ept30/h_collmass_pfmet')
dataD=file_dataD.Get('os/gg/ept30/h_collmass_pfmet')

data=dataC.Clone()
data.Add(dataB)
data.Add(dataA)
data.Add(dataD)

c= ROOT.TCanvas("c","c", 800, 1000)
c.Draw()
c.SetGridx(1)
c.SetGridy(1)


njets=[0,1,2,3,4]