def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToOne=True, saveFormats=[], **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.0f"
    _xlabel = None
    logY    = True
    _opts   = {"ymin": 1e-3, "ymaxfactor": 1.0}
    
    if "dijetm" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jj} (%s)" % (_units)
        _cutBox = {"cutValue": 80.399, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 400.0
    if "trijetm" in histo.lower():
        _rebinX = 1
        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 1000.0 #1500.0
    if "pt" in histo.lower():
        _rebinX = 2
        _format = "%0.0f GeV/c"
    if "eta" in histo.lower():
        _format = "%0.2f"
        _cutBox = {"cutValue": 0., "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmin"] = -3.0
        _opts["xmax"] = +3.0
    if "deltaeta" in histo.lower():
        _format = "%0.2f"
        _opts["xmin"] =  0.0
        _opts["xmax"] = 6.0
    if "bdisc" in histo.lower():
        _format = "%0.2f"
    if "tetrajetm" in histo.lower():
        _rebinX = 10
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjjb} (%s)" % (_units)
        _opts["xmax"] = 3500.0
    if "chisqr" in histo.lower():
        _rebinX = 10
        _units  = ""
        _format = "%0.0f " + _units
        _xlabel = "#chi^{2}"
        #_opts["xmax"] = 3500.0
        
    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise Dataset styling
    p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
    p.histoMgr.setHistoDrawStyle("QCD", "HIST")
    p.histoMgr.setHistoLegendStyle("QCD", "F")

    p.histoMgr.setHistoDrawStyle("TT", "AP")
    p.histoMgr.setHistoLegendStyle("TT", "LP")

    #p.histoMgr.setHistoDrawStyle("TTZToQQ", "AP")
    #p.histoMgr.setHistoLegendStyle("TTZToQQ", "LP")

    # Customise style                                                                                                                                                                                                          
    if 0:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_500", styles.getSignalStyleHToTB())

    plots.drawPlot(p, 
                   histo,  
                   xlabel       = _xlabel,
                   ylabel       = "Arbitrary Units / %s" % (_format),
                   log          = logY,
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.62, "y1": 0.65, "x2": 0.92, "y2": 0.92},
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   cutBox       = _cutBox,
                   )

    # Save plot in all formats    
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, histo.split("/")[0], "", opts.optMode)
    SavePlot(p, saveName, savePath) 
    return
Beispiel #2
0
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr,
                         histo,
                         normalizeToOne=True,
                         saveFormats=[],
                         **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr,
                         histo,
                         normalizeToLumi=intLumi,
                         saveFormats=[],
                         **kwargs)

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.0f"
    _xlabel = None
    logY = False
    _opts = {"ymin": 1e-3, "ymaxfactor": 1.0}

    if "ChiSqr" in histo:
        _rebinX = 1
        logY = True
        _units = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {
            "cutValue": 10.0,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 100
    elif "trijetmass" in histo.lower():
        _rebinX = 4
        logY = False
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {
            "cutValue": 173.21,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 805  #1005
    elif "ht" in histo.lower():
        _rebinX = 2
        logY = False
        _units = "GeV"
        _format = "%0.0f " + _units
        _xlabel = "H_{T} (%s)" % _units
        _cutBox = {
            "cutValue": 500,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        #_opts["xmin"] = 500
        _opts["xmax"] = 2000
    elif "tetrajetmass" in histo.lower():
        _rebinX = 5  #5 #10 #4
        logY = False
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _cutBox = {
            "cutValue": 500.0,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 1500  #3500.0
        #_rebinX = 10
        #_opts["xmax"] = 3500
    elif "tetrajetbjetpt" in histo.lower():
        _rebinX = 2
        logY = False
        _units = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 600
    elif "foxwolframmoment" in histo.lower():
        _format = "%0.1f"
        _cutBox = {
            "cutValue": 0.5,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
    else:
        pass

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(
        lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasets():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle())
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasets():
        p.histoMgr.setHistoDrawStyle("TT", "AP")
        p.histoMgr.setHistoLegendStyle("TT", "LP")

    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" % m,
                            styles.getSignalStyleHToTB_M(m))

    plots.drawPlot(
        p,
        histo,
        xlabel=_xlabel,
        ylabel="Arbitrary Units / %s" % (_format),
        log=logY,
        rebinX=_rebinX,
        cmsExtraText="Preliminary",
        createLegend={
            "x1": 0.58,
            "y1": 0.65,
            "x2": 0.92,
            "y2": 0.92
        },
        opts=_opts,
        opts2={
            "ymin": 0.6,
            "ymax": 1.4
        },
        cutBox=_cutBox,
    )

    # Save plot in all formats
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, "HplusMasses",
                            histo.split("/")[0], opts.optMode)
    SavePlot(p, saveName, savePath)
    return
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToOne=True, saveFormats=[], **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
#    p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.0f"
    _xlabel = None

    _opts   = {"ymin": 1e-3, "ymaxfactor": 1.0}

    if "ChiSqr" in histo:
        _rebinX = 1
#        logY    = True
        _units  = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {"cutValue": 10.0, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 100

    elif "trijetmass" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 #1005

    elif "ht" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV"
        _format = "%0.0f " + _units
        _xlabel = "H_{T} (%s)" % _units
        _cutBox = {"cutValue": 500, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 2000

    elif "tetrajetmass" in histo.lower():
        _rebinX = 5 #5 #10 #4
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 1500 #3500.0

    elif "dijetmass" in histo.lower():
        _rebinX = 1 #5 #10 #4
#        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{W} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800 #3500.0
        _cutBox = {"cutValue": 80.4, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 300

    elif "tetrajetbjetpt" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800
    elif "ldgtrijetpt" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "trijetbdt_mass" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 
#    elif "topcandmass" in histo.lower():
#        _rebinX = 2
#        _units  = "GeV/c^{2}"
#        _format = "%0.0f " + _units
#        _xlabel = "m_{jjb} (%s)" % _units
#        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
#        _opts["xmax"] = 505 

    elif "matched_mass" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 

    elif "bdtvalue" in histo.lower():
        _format = "%0.1f"

    elif "foxwolframmoment" in histo.lower():
        _format = "%0.1f"
        _cutBox = {"cutValue": 0.5, "fillColor": 16, "box": False, "line": True, "greaterThan": True}

    elif "absdeltamvamax_mctruth_sameobjfakes" in histo.lower():
        _format = "%0.1f"
        _xlabel = "|#Delta BDTG| response"

    elif "deltamvamin_mctruth_sameobjfakespassbdt" in histo.lower():
        _opts["xmax"] = 1
        _opts["xmin"] = -1
    elif "bdtmultiplicity" in histo.lower():
        _opts["xmax"] = 15


    else:
        pass


    if opts.normaliseToOne:
        logY    = False
        Ylabel  = "Arbitrary Units / %s" % (_format)
    else:
        logY    = True
        Ylabel  = "Events / %s" % (_format)

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasets():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasets():
        p.histoMgr.setHistoDrawStyle("TT", "AP")
        p.histoMgr.setHistoLegendStyle("TT", "LP")

    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, styles.getSignalStyleHToTB_M(m))
        

    plots.drawPlot(p, 
                   histo,  
                   xlabel       = _xlabel,
                   ylabel       = Ylabel,#"Arbitrary Units / %s" % (_format), #"Events / %s" % (_format), #"Arbitrary Units / %s" % (_format),
                   log          = logY,
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.58, "y1": 0.65, "x2": 0.92, "y2": 0.92},
#                   createLegend = {"x1": 0.73, "y1": 0.85, "x2": 0.97, "y2": 0.77},
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   cutBox       = _cutBox,
                   )

    # Save plot in all formats    
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, "HplusMasses", histo.split("/")[0], opts.optMode)

    if opts.normaliseToOne:
        save_path = savePath + opts.MVAcut
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"
    else:
        save_path = savePath + opts.MVAcut + "/normToLumi/"
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"

#    SavePlot(p, saveName, savePath) 
    SavePlot(p, saveName, save_path) 

    return
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToOne=True, saveFormats=[], **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
#    p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.1f"
    _xlabel = None

    _opts   = {"ymin": 1e-3, "ymaxfactor": 1.0}


    if "ChiSqr" in histo:
        _rebinX = 1
        #logY    = True
        _units  = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {"cutValue": 10.0, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 100

    elif "trijetjets_deltarmin" in histo.lower():
        _xlabel = "#Delta R_{min}"
        _rebinX = 2
        _opts["xmax"] = 3
        _units = ""
        _format = "%0.1f "
        _cutBox = {"cutValue": 0.8, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        
        
    elif "trijetjets_deltarmax" in histo.lower():
        _xlabel = "#Delta R_{max}"
        _rebinX = 2
        _opts["xmax"] = 3.5
        _units = ""
        _format = "%0.1f "
        _cutBox = {"cutValue": 0.8, "fillColor": 16, "box": False, "line": True, "greaterThan": True}

    elif "trijetdijetdr" in histo.lower():
        _rebinX = 1
        units = ""
        _format = "%0.1f "
        _opts["xmax"] = 3.5
        _cutBox = {"cutValue": 0.8, "fillColor": 16, "box": False, "line": True, "greaterThan": True}

    elif "trijetdijetpt" in histo.lower():
        _rebinX = 2
        _units = "GeV/c"
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "trijetdijetmass" in histo.lower():
        _rebinX = 1
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _opts["xmax"] = 200
        _xlabel = "m_{w} (%s)" % _units
        _cutBox = {"cutValue": 80.39, "fillColor": 16, "box": False, "line": True, "greaterThan": True}


    if "cevts_ldgtrijetmatchedtofatjet_fatjetpt" in histo.lower():
        _rebin = 1
        _opts["xmax"] = 3

    elif "pt" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _opts["xmax"] = 800



    elif "trijetmass" in histo.lower():
        _rebinX = 1
#        logY    = False
        _units  = "GeV/c^{2}"
#        _format = "%0.0f " + _units
        _format = "%0.0f" + (_units)
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 305 #1005
        _opts["xmin"] = 55 #1005


    elif "topcandmass" in histo.lower():
        _rebinX = 1
#        logY    = False
        _units  = "GeV/c^{2}"
#        _format = "%0.0f " + _units
        _format = "%0.0f" + (_units)
        _xlabel = "m_{jjb}^{BDTG} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 #1005
        _opts["xmin"] = 0 #1005


#    elif "ht" in histo.lower():
#        _rebinX = 2
##        logY    = False
#        _units  = "GeV"
#        _format = "%0.0f " + _units
#        _xlabel = "H_{T} (%s)" % _units
#        _cutBox = {"cutValue": 500, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
#        _opts["xmax"] = 2000

    elif "tetrajetptd" in histo.lower():
        _rebinX = 2 #5 #10 #4
        _units  = "GeV/c^{2}"
#        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 2000 #3500.0
        _cutBox = {"cutValue": 400, "fillColor": 16, "box": False, "line": True, "greaterThan": True}

    elif "tetrajetmass" in histo.lower() or "tetrajetmass_" in histo.lower():
        #ROOT.gStyle.SetNdivisions(10, "X")
#        h = dataset.getDatasetRootHisto(histo).getHistogram()
#        h.SetTickLength(100, "X")
        _rebinX = 5 #5 #10 #4
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 1500 #3500.0
        _cutBox = {"cutValue": 500, "fillColor": 16, "box": False, "line": False, "greaterThan": True}

    elif "dijetmass" in histo.lower():
        _rebinX = 1 #5 #10 #4
#        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{W} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800 #3500.0
        _cutBox = {"cutValue": 80.4, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 205

    elif "trijetmultiplicitypassbdt" in histo.lower():
        _rebinX = 1
        _opts["xmax"] = 5
        _format = "%0.0f "

    elif "bdtg" or "bdtvalue" in histo.lower():
        _rebinX = 1 
        _format = "%0.2f "

    elif "trijetbdt_mass" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _opts["xmax"] = 800


#    if "eta" or "phi" or "delta" in histo.lower():
        #_rebinX = 1 #5 #10 #4
#        _units  = ""
#        _format = "%0.1f " 

#    if "eta" in histo.lower():
#        _xlabel = "#eta"
#    if "phi" in histo.lower():
#        _xlabel = "#phi"
#    if "pt" in histo.lower():
#        _opts["xmax"] = 800
    elif "boosted" in histo.lower():
        _xlabel = "Trijet Counter"
    elif "matched_dijetpt" in histo.lower():
        _units = "(GeV/c)"
        _xlabel = "p_{T}" +_units

    elif "deltar_bdttrijets_tetrajetbjet" in  histo.lower():
        _xlabel = "#Delta R(Trijet,b_{free})"



    elif "tetrajetbjetbdisc" in histo.lower():
        _rebinX = 2
        _opts["xmax"] = 1.05

#    if "matched_dijetmass" in histo.lower():
#        _rebinX = 2
#    if "higgstop_dijetmass" in histo.lower():
#        _rebinX = 2
        
    elif "trijet_deltaeta_trijet_tetrajetbjet" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta #eta (Trijet, b_{free})"

    elif "trijet_deltaphi_trijet_tetrajetbjet" in histo.lower():
        _xlabel = "#Delta #phi (Trijet, b_{free})"
    elif "cevts_closejettotetrajetbjet_isbtagged" in histo.lower():
        _units = ""
        _format = "%0.0f " + _units
#    if "higgstop_" in histo.lower():
#        _rebinX = 2
    if "eventtrijetpt2t" in histo.lower():
        _rebinX = 2

    if "ldgfatjetpt" in histo.lower():
        _opts["xmax"] = 1000

    if "deltar_w" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta R"
        _format = "%0.1f "
        _opts["xmax"] = 5
        logY = True

    if "ldgtrijet_deltar" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta R"
        _format = "%0.1f "
        _opts["xmax"] = 5
        logY = True

    if "higgstop_deltar" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta R"
        _format = "%0.1f "
        _opts["xmax"] = 5
        logY = True


    if "allfatjet" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _opts["xmax"] = 800


    else:
        pass


    if opts.normaliseToOne:
        logY    = True
        Ylabel  = "Arbitrary Units / %s" % (_format)
    else:
        logY    = True
        Ylabel  = "Events / %s" % (_format)

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2


    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasets():        
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasets():
        p.histoMgr.setHistoDrawStyle("TT", "HIST")
        p.histoMgr.setHistoLegendStyle("TT", "LP")

#    if "M_200" in datasetsMgr.getAllDatasets() or "M_300" in datasetsMgr.getAllDatasets():        
#        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
#        p.histoMgr.setHistoDrawStyle("QCD", "P")
#        p.histoMgr.setHistoLegendStyle("QCD", "F")

#    elif d.getName() == "TT" or d.getName() == "QCD" or d.getName() == "Data":
#            otherHisto = histograms.Histo(histo, legName, "LP", "P")
#            otherHistos.append(otherHisto)


    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, styles.getSignalStyleHToTB_M(m))
#soti
#        p.histoMgr.setHistoDrawStyle("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, "LP")
#        p.histoMgr.setHistoLegendStyle("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, "P")
        

    plots.drawPlot(p, 
                   histo,  
                   xlabel       = _xlabel,
                   ylabel       = Ylabel,#"Arbitrary Units / %s" % (_format), #"Events / %s" % (_format), #"Arbitrary Units / %s" % (_format),
#                   ylabel       = "Arbitrary Units / %s" % (_format), #"Events / %s" % (_format), #"Arbitrary Units / %s" % (_format),
                   log          = logY,
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", #_rebinX
                   #createLegend = {"x1": 0.48, "y1": 0.45, "x2": 0.92, "y2": 0.92}, #All datasets
#                   createLegend = {"x1": 0.58, "y1": 0.7, "x2": 0.92, "y2": 0.92},
                   createLegend = {"x1": 0.58, "y1": 0.65, "x2": 0.92, "y2": 0.87},
                   #createLegend = {"x1": 0.73, "y1": 0.85, "x2": 0.97, "y2": 0.77},   #One dataset
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   cutBox       = _cutBox,
                   )

    # Save plot in all formats    
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, "HplusMasses", histo.split("/")[0], opts.optMode)

    if opts.normaliseToOne:
        save_path = savePath + opts.MVAcut
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"
    else:
        save_path = savePath + opts.MVAcut + "/normToLumi/TT/"
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"

#    SavePlot(p, saveName, savePath) 
    SavePlot(p, saveName, save_path) 

    return
Beispiel #5
0
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr,
                         histo,
                         normalizeToOne=True,
                         saveFormats=[],
                         **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr,
                         histo,
                         normalizeToLumi=intLumi,
                         saveFormats=[],
                         **kwargs)
#    p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
# Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.1f"
    _xlabel = None

    _opts = {"ymin": 1e-3, "ymaxfactor": 1.0}

    if "ChiSqr" in histo:
        _rebinX = 1
        #logY    = True
        _units = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {
            "cutValue": 10.0,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 100

    elif "trijetjets_deltarmin" in histo.lower():
        _xlabel = "#Delta R_{min}"
        _rebinX = 2
        _opts["xmax"] = 3
        _units = ""
        _format = "%0.1f "
        _cutBox = {
            "cutValue": 0.8,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }

    elif "trijetjets_deltarmax" in histo.lower():
        _xlabel = "#Delta R_{max}"
        _rebinX = 2
        _opts["xmax"] = 3.5
        _units = ""
        _format = "%0.1f "
        _cutBox = {
            "cutValue": 0.8,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }

    elif "trijetdijetdr" in histo.lower():
        _rebinX = 1
        units = ""
        _format = "%0.1f "
        _opts["xmax"] = 3.5
        _cutBox = {
            "cutValue": 0.8,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }

    elif "trijetdijetpt" in histo.lower():
        _rebinX = 2
        _units = "GeV/c"
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "trijetdijetmass" in histo.lower():
        _rebinX = 1
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _opts["xmax"] = 200
        _xlabel = "m_{w} (%s)" % _units
        _cutBox = {
            "cutValue": 80.39,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }

    if "cevts_ldgtrijetmatchedtofatjet_fatjetpt" in histo.lower():
        _rebin = 1
        _opts["xmax"] = 3

    elif "pt" in histo.lower():
        _rebinX = 2
        _units = "GeV/c"
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "trijetmass" in histo.lower():
        _rebinX = 1
        #        logY    = False
        _units = "GeV/c^{2}"
        #        _format = "%0.0f " + _units
        _format = "%0.0f" + (_units)
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {
            "cutValue": 173.21,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 305  #1005
        _opts["xmin"] = 55  #1005

    elif "topcandmass" in histo.lower():
        _rebinX = 1
        #        logY    = False
        _units = "GeV/c^{2}"
        #        _format = "%0.0f " + _units
        _format = "%0.0f" + (_units)
        _xlabel = "m_{jjb}^{BDTG} (%s)" % _units
        _cutBox = {
            "cutValue": 173.21,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 505  #1005
        _opts["xmin"] = 0  #1005

#    elif "ht" in histo.lower():
#        _rebinX = 2
##        logY    = False
#        _units  = "GeV"
#        _format = "%0.0f " + _units
#        _xlabel = "H_{T} (%s)" % _units
#        _cutBox = {"cutValue": 500, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
#        _opts["xmax"] = 2000

    elif "tetrajetptd" in histo.lower():
        _rebinX = 2  #5 #10 #4
        _units = "GeV/c^{2}"
        #        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 2000  #3500.0
        _cutBox = {
            "cutValue": 400,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }

    elif "tetrajetmass" in histo.lower() or "tetrajetmass_" in histo.lower():
        #ROOT.gStyle.SetNdivisions(10, "X")
        #        h = dataset.getDatasetRootHisto(histo).getHistogram()
        #        h.SetTickLength(100, "X")
        _rebinX = 5  #5 #10 #4
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 1500  #3500.0
        _cutBox = {
            "cutValue": 500,
            "fillColor": 16,
            "box": False,
            "line": False,
            "greaterThan": True
        }

    elif "dijetmass" in histo.lower():
        _rebinX = 1  #5 #10 #4
        #        logY    = False
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{W} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800  #3500.0
        _cutBox = {
            "cutValue": 80.4,
            "fillColor": 16,
            "box": False,
            "line": True,
            "greaterThan": True
        }
        _opts["xmax"] = 205

    elif "trijetmultiplicitypassbdt" in histo.lower():
        _rebinX = 1
        _opts["xmax"] = 5
        _format = "%0.0f "

    elif "bdtg" or "bdtvalue" in histo.lower():
        _rebinX = 1
        _format = "%0.2f "

    elif "trijetbdt_mass" in histo.lower():
        _rebinX = 2
        _units = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _opts["xmax"] = 800

#    if "eta" or "phi" or "delta" in histo.lower():
#_rebinX = 1 #5 #10 #4
#        _units  = ""
#        _format = "%0.1f "

#    if "eta" in histo.lower():
#        _xlabel = "#eta"
#    if "phi" in histo.lower():
#        _xlabel = "#phi"
#    if "pt" in histo.lower():
#        _opts["xmax"] = 800
    elif "boosted" in histo.lower():
        _xlabel = "Trijet Counter"
    elif "matched_dijetpt" in histo.lower():
        _units = "(GeV/c)"
        _xlabel = "p_{T}" + _units

    elif "deltar_bdttrijets_tetrajetbjet" in histo.lower():
        _xlabel = "#Delta R(Trijet,b_{free})"

    elif "tetrajetbjetbdisc" in histo.lower():
        _rebinX = 2
        _opts["xmax"] = 1.05

#    if "matched_dijetmass" in histo.lower():
#        _rebinX = 2
#    if "higgstop_dijetmass" in histo.lower():
#        _rebinX = 2

    elif "trijet_deltaeta_trijet_tetrajetbjet" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta #eta (Trijet, b_{free})"

    elif "trijet_deltaphi_trijet_tetrajetbjet" in histo.lower():
        _xlabel = "#Delta #phi (Trijet, b_{free})"
    elif "cevts_closejettotetrajetbjet_isbtagged" in histo.lower():
        _units = ""
        _format = "%0.0f " + _units
#    if "higgstop_" in histo.lower():
#        _rebinX = 2
    if "eventtrijetpt2t" in histo.lower():
        _rebinX = 2

    if "ldgfatjetpt" in histo.lower():
        _opts["xmax"] = 1000

    if "deltar_w" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta R"
        _format = "%0.1f "
        _opts["xmax"] = 5
        logY = True

    if "ldgtrijet_deltar" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta R"
        _format = "%0.1f "
        _opts["xmax"] = 5
        logY = True

    if "higgstop_deltar" in histo.lower():
        _rebinX = 2
        _xlabel = "#Delta R"
        _format = "%0.1f "
        _opts["xmax"] = 5
        logY = True

    if "allfatjet" in histo.lower():
        _rebinX = 2
        _units = "GeV/c"
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    else:
        pass

    if opts.normaliseToOne:
        logY = True
        Ylabel = "Arbitrary Units / %s" % (_format)
    else:
        logY = True
        Ylabel = "Events / %s" % (_format)

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(
        lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasets():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle())
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasets():
        p.histoMgr.setHistoDrawStyle("TT", "HIST")
        p.histoMgr.setHistoLegendStyle("TT", "LP")

#    if "M_200" in datasetsMgr.getAllDatasets() or "M_300" in datasetsMgr.getAllDatasets():
#        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
#        p.histoMgr.setHistoDrawStyle("QCD", "P")
#        p.histoMgr.setHistoLegendStyle("QCD", "F")

#    elif d.getName() == "TT" or d.getName() == "QCD" or d.getName() == "Data":
#            otherHisto = histograms.Histo(histo, legName, "LP", "P")
#            otherHistos.append(otherHisto)

# Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" % m,
                            styles.getSignalStyleHToTB_M(m))
#soti
#        p.histoMgr.setHistoDrawStyle("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, "LP")
#        p.histoMgr.setHistoLegendStyle("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, "P")

    plots.drawPlot(
        p,
        histo,
        xlabel=_xlabel,
        ylabel=
        Ylabel,  #"Arbitrary Units / %s" % (_format), #"Events / %s" % (_format), #"Arbitrary Units / %s" % (_format),
        #                   ylabel       = "Arbitrary Units / %s" % (_format), #"Events / %s" % (_format), #"Arbitrary Units / %s" % (_format),
        log=logY,
        rebinX=_rebinX,
        cmsExtraText="Preliminary",  #_rebinX
        #createLegend = {"x1": 0.48, "y1": 0.45, "x2": 0.92, "y2": 0.92}, #All datasets
        #                   createLegend = {"x1": 0.58, "y1": 0.7, "x2": 0.92, "y2": 0.92},
        createLegend={
            "x1": 0.58,
            "y1": 0.65,
            "x2": 0.92,
            "y2": 0.87
        },
        #createLegend = {"x1": 0.73, "y1": 0.85, "x2": 0.97, "y2": 0.77},   #One dataset
        opts=_opts,
        opts2={
            "ymin": 0.6,
            "ymax": 1.4
        },
        cutBox=_cutBox,
    )

    # Save plot in all formats
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, "HplusMasses",
                            histo.split("/")[0], opts.optMode)

    if opts.normaliseToOne:
        save_path = savePath + opts.MVAcut
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"
    else:
        save_path = savePath + opts.MVAcut + "/normToLumi/TT/"
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"


#    SavePlot(p, saveName, savePath)
    SavePlot(p, saveName, save_path)

    return
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToOne=True, saveFormats=[], **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.0f"
    _xlabel = None
    logY    = False
    _opts   = {"ymin": 1e-3, "ymaxfactor": 1.0}


    if "ChiSqr" in histo:
        _rebinX = 1
        logY    = True
        _units  = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {"cutValue": 10.0, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 100
    elif "trijetmass" in histo.lower():
        _rebinX = 4
        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 805 #1005
    elif "ht" in histo.lower():
        _rebinX = 2
        logY    = False
        _units  = "GeV"
        _format = "%0.0f " + _units
        _xlabel = "H_{T} (%s)" % _units
        _cutBox = {"cutValue": 500, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        #_opts["xmin"] = 500
        _opts["xmax"] = 2000
    elif "tetrajetmass" in histo.lower():
        _rebinX = 5 #5 #10 #4
        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _cutBox = {"cutValue": 500.0, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 1500 #3500.0
        #_rebinX = 10
        #_opts["xmax"] = 3500
    elif "tetrajetbjetpt" in histo.lower():
        _rebinX = 2
        logY    = False
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 600
    elif "foxwolframmoment" in histo.lower():
        _format = "%0.1f"
        _cutBox = {"cutValue": 0.5, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
    else:
        pass

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
    else:
        _opts["ymin"] = 1e0

    # Customise styling
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    
    if "QCD" in datasetsMgr.getAllDatasets():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasets():
        p.histoMgr.setHistoDrawStyle("TT", "AP")
        p.histoMgr.setHistoLegendStyle("TT", "LP")

    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, styles.getSignalStyleHToTB_M(m))

    plots.drawPlot(p, 
                   histo,  
                   xlabel       = _xlabel,
                   ylabel       = "Arbitrary Units / %s" % (_format),
                   log          = logY,
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.58, "y1": 0.65, "x2": 0.92, "y2": 0.92},
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   cutBox       = _cutBox,
                   )

    # Save plot in all formats    
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, "HplusMasses", histo.split("/")[0], opts.optMode)
    SavePlot(p, saveName, savePath) 
    return
Beispiel #7
0
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToOne=True, saveFormats=[], **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)

    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.0f"
    _xlabel = None

    _opts   = {"ymin": 1e-3, "ymaxfactor": 1.0}


    if "pt" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": False, "greaterThan": True}
        _opts["xmax"] = 805 #1005

    if "bdisc" in histo.lower():
        _rebinX = 2
        _units  = ""
        _format = "%0.2f " + _units
        _xlabel = "b-discriminator" #(%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": False, "greaterThan": True}
        _opts["xmax"] = 1.2

    if "ht" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "H_{T} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": False, "greaterThan": True}
        _opts["xmax"] = 1505 #1005

    if "met" in histo.lower():
        _rebinX = 1
        _units  = "GeV"
        _format = "%0.0f " + _units
        _xlabel = "E_{T,missing} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": False, "greaterThan": True}
        _opts["xmax"] = 205 #1005

    if "mult" in histo.lower():
        _units  = ""
        _format = "%0.0f " + _units
        _xlabel = "jet multiplicity"
        _opts["xmax"] = 10

    if "mass" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 350 #1005

    elif "tetrajetmass" in histo.lower():
        _rebinX = 5 #5 #10 #4
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 1500 #3500.0

    elif "dijetmass" in histo.lower():
        _rebinX = 1 #5 #10 #4
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{W} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800 #3500.0
        _cutBox = {"cutValue": 80.4, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 300

    elif "tetrajetbjetpt" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "ldgtrijetpt" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "tau" in histo.lower():
        _format = "%0.2f "

    elif "deltar" in histo.lower():
        _format = "%0.2f "

    elif "bdtvalue" in histo.lower():
        _format = "%0.1f"

    else:
        pass


    if opts.normaliseToOne:
        logY    = False
        Ylabel  = "Arbitrary Units / %s" % (_format)
    else:
        logY    = True
        Ylabel  = "Events / %s" % (_format)

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasetNames():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasetNames():
        TTStyle           = styles.StyleCompound([styles.StyleFill(fillColor=ROOT.kMagenta-2), styles.StyleLine(lineColor=ROOT.kMagenta-2, lineStyle=ROOT.kSolid, lineWidth=3),
                                                  styles.StyleMarker(markerSize=1.2, markerColor=ROOT.kMagenta-2, markerSizes=None, markerStyle=ROOT.kFullTriangleUp)])
        p.histoMgr.forHisto("TT", TTStyle)
        p.histoMgr.setHistoDrawStyle("TT", "HIST") #AP
        p.histoMgr.setHistoLegendStyle("TT", "F")  #LP
        
        
    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, styles.getSignalStyleHToTB_M(m))
        

    plots.drawPlot(p, 
                   histo,  
                   xlabel       = _xlabel,
                   ylabel       = Ylabel,
                   log          = logY,
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.68, "y1": 0.82, "x2": 1.0, "y2": 0.92},
                   #createLegend = {"x1": 0.73, "y1": 0.85, "x2": 0.97, "y2": 0.77},
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   cutBox       = _cutBox,
                   )

    # Save plot in all formats    
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, histo.split("/")[0], opts.optMode)

    '''
    if opts.normaliseToOne:
        save_path = savePath + opts.MVAcut
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"
    else:
        save_path = savePath + opts.MVAcut + "/normToLumi/"
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"
     '''
    
    SavePlot(p, saveName, savePath) 

    return
def PlotMC(datasetsMgr, histo, intLumi):

    kwargs = {}
    if opts.normaliseToOne:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToOne=True, saveFormats=[], **kwargs)
    else:
        p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
#    p = plots.MCPlot(datasetsMgr, histo, normalizeToLumi=intLumi, saveFormats=[], **kwargs)
    # Draw the histograms
    _cutBox = None
    _rebinX = 1
    _format = "%0.0f"
    _xlabel = None

    _opts   = {"ymin": 1e-3, "ymaxfactor": 1.0}

    if "ChiSqr" in histo:
        _rebinX = 1
#        logY    = True
        _units  = ""
        _format = "%0.1f " + _units
        _xlabel = "#chi^{2}"
        _cutBox = {"cutValue": 10.0, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 100

    elif "trijetmass" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 #1005

    elif "ht" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV"
        _format = "%0.0f " + _units
        _xlabel = "H_{T} (%s)" % _units
        _cutBox = {"cutValue": 500, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 2000

    elif "tetrajetmass" in histo.lower():
        _rebinX = 5 #5 #10 #4
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjbb} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 1500 #3500.0

    elif "dijetmass" in histo.lower():
        _rebinX = 1 #5 #10 #4
#        logY    = False
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{W} (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800 #3500.0
        _cutBox = {"cutValue": 80.4, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 300

    elif "tetrajetbjetpt" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800
    elif "ldgtrijetpt" in histo.lower():
        _rebinX = 2
#        logY    = False
        _units  = "GeV/c"
        _format = "%0.0f " + _units
        _xlabel = "p_{T}  (%s)" % (_units)
        _format = "%0.0f " + _units
        _opts["xmax"] = 800

    elif "trijetbdt_mass" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 
#    elif "topcandmass" in histo.lower():
#        _rebinX = 2
#        _units  = "GeV/c^{2}"
#        _format = "%0.0f " + _units
#        _xlabel = "m_{jjb} (%s)" % _units
#        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
#        _opts["xmax"] = 505 

    elif "matched_mass" in histo.lower():
        _rebinX = 2
        _units  = "GeV/c^{2}"
        _format = "%0.0f " + _units
        _xlabel = "m_{jjb} (%s)" % _units
        _cutBox = {"cutValue": 173.21, "fillColor": 16, "box": False, "line": True, "greaterThan": True}
        _opts["xmax"] = 505 

    elif "bdtvalue" in histo.lower():
        _format = "%0.1f"

    elif "foxwolframmoment" in histo.lower():
        _format = "%0.1f"
        _cutBox = {"cutValue": 0.5, "fillColor": 16, "box": False, "line": True, "greaterThan": True}

    elif "absdeltamvamax_mctruth_sameobjfakes" in histo.lower():
        _format = "%0.1f"
        _xlabel = "|#Delta BDTG| response"

    elif "deltamvamin_mctruth_sameobjfakespassbdt" in histo.lower():
        _opts["xmax"] = 1
        _opts["xmin"] = -1
    elif "bdtmultiplicity" in histo.lower():
        _opts["xmax"] = 15


    else:
        pass


    if opts.normaliseToOne:
        logY    = False
        Ylabel  = "Arbitrary Units / %s" % (_format)
    else:
        logY    = True
        Ylabel  = "Events / %s" % (_format)

    if logY:
        yMaxFactor = 2.0
    else:
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasets():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    if "TT" in datasetsMgr.getAllDatasets():
        p.histoMgr.setHistoDrawStyle("TT", "AP")
        p.histoMgr.setHistoLegendStyle("TT", "LP")

    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM:
        p.histoMgr.forHisto("ChargedHiggs_HplusTB_HplusToTB_M_%s" %m, styles.getSignalStyleHToTB_M(m))
        

    plots.drawPlot(p, 
                   histo,  
                   xlabel       = _xlabel,
                   ylabel       = Ylabel,#"Arbitrary Units / %s" % (_format), #"Events / %s" % (_format), #"Arbitrary Units / %s" % (_format),
                   log          = logY,
                   rebinX       = _rebinX, cmsExtraText = "Preliminary", 
                   createLegend = {"x1": 0.58, "y1": 0.65, "x2": 0.92, "y2": 0.92},
#                   createLegend = {"x1": 0.73, "y1": 0.85, "x2": 0.97, "y2": 0.77},
                   opts         = _opts,
                   opts2        = {"ymin": 0.6, "ymax": 1.4},
                   cutBox       = _cutBox,
                   )

    # Save plot in all formats    
    saveName = histo.split("/")[-1]
    savePath = os.path.join(opts.saveDir, "HplusMasses", histo.split("/")[0], opts.optMode)

    if opts.normaliseToOne:
        save_path = savePath + opts.MVAcut
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"
    else:
        save_path = savePath + opts.MVAcut + "/normToLumi/"
        if opts.noQCD:
            save_path = savePath + opts.MVAcut + "/noQCD/"

#    SavePlot(p, saveName, savePath) 
    SavePlot(p, saveName, save_path) 

    return
        yMaxFactor = 1.2

    _opts["ymaxfactor"] = yMaxFactor
    if opts.normaliseToOne:
        _opts["ymin"] = 1e-3
        #_opts   = {"ymin": 1e-3, "ymaxfactor": yMaxFactor, "xmax": None}
    else:
        _opts["ymin"] = 1e0
        #_opts["ymaxfactor"] = yMaxFactor
        #_opts   = {"ymin": 1e0, "ymaxfactor": yMaxFactor, "xmax": None}

    # Customise styling
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineStyle(ROOT.kSolid))

    if "QCD" in datasetsMgr.getAllDatasets():
        p.histoMgr.forHisto("QCD", styles.getQCDFillStyle() )
        p.histoMgr.setHistoDrawStyle("QCD", "HIST")
        p.histoMgr.setHistoLegendStyle("QCD", "F")

    for d in datasetsMgr.getAllDatasets():
        if "TT" in d.getName():
            p.histoMgr.forHisto("TT", styles.getTTFillStyle() )
            #p.histoMgr.setHistoDrawStyle("TT", "AP")
            p.histoMgr.setHistoLegendStyle("TT", "F")
            

    # Customise style
    signalM = []
    for m in signalMass:
        signalM.append(m.rsplit("M_")[-1])
    for m in signalM: