예제 #1
0
def main():

    print "Plotting observable"
    c2 = TCanvas("c2")
    c1 = TCanvas("c1", "c1", 800, 800)
    c1.SetBottomMargin(0.16)
    c1.SetLeftMargin(0.16)
    #c1 = utils.mkcanvas()
    #memory = []

    global method

    file = [input]
    c2.cd()
    #(testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods, names) = cut_optimisation.get_bdt_hists(file, None, None, None, None, None, None, 40)
    (testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods,
     names) = cut_optimisation.get_method_hists(file, method, None, None, None,
                                                None, None, None, 40, "",
                                                weight)
    #cut_optimisation.get_mlp_hists(file, testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods, names)
    #def get_bdt_hists(folders, testBGHists=None, trainBGHists=None, testSignalHists=None, trainSignalHists=None, methods=None, names=None, bins=10000,  condition=""):
    #    return get_method_hists(folders, "BDT", testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods, names, bins, condition)

    c1.cd()

    c1.Print(output_file + "[")

    hist = TH1F("hroc", "", 1000, 0, 1)
    hist.SetMinimum(0)
    hist.SetMaximum(1)
    hist.GetXaxis().SetTitle("#font[12]{#epsilon_{S}}")
    hist.GetYaxis().SetTitle(
        "background rejection (1 - #font[12]{#epsilon_{B}})")
    utils.histoStyler(hist)
    hist.GetYaxis().SetTitleOffset(1.20)
    hist.GetXaxis().SetLabelSize(0.055)
    hist.Draw()

    legend = TLegend(0.2, 0.2, 0.7, 0.45)
    legend.SetBorderSize(0)
    legend.SetTextFont(42)
    legend.SetTextSize(0.05)

    for inx in range(len(testBGHists)):

        testBGHist, trainBGHist, testSignalHist, trainSignalHist, method, name = testBGHists[
            inx], trainBGHists[inx], testSignalHists[inx], trainSignalHists[
                inx], methods[inx], names[inx]

        h = TGraph()
        highestZ, highestS, highestB, highestMVA, ST, BT = cut_optimisation.getHighestZ(
            trainSignalHist, trainBGHist, testSignalHist, testBGHist, h)
        h.SetTitle(name)
        h.SetLineColor(kBlack)
        h.SetMarkerSize(0.2)
        #hbdt.SetFillColor(kRed)

        h.Draw("same")
        legend.Draw("same")

    #legend.Draw("SAME")
    utils.stamp_plot()
    #utils.stampFab("35.9")
    c1.Print(output_file)
    c1.Print(output_file + "]")
    exit(0)
예제 #2
0
def main():

    print "Plotting observable"

    c1 = TCanvas("c1", "c1", 800, 800)
    c1.SetBottomMargin(0.16)
    c1.SetLeftMargin(0.16)
    #c1 = utils.mkcanvas()
    #memory = []
    c1.Print(output_file + "[")

    #legend = TLegend(.55,.75,.89,.89)
    legend = TLegend(.2, .75, .89, .89)
    legend.SetBorderSize(0)
    legend.SetTextFont(42)
    legend.SetTextSize(0.05)

    files = [input]

    print files

    sh = utils.UOFlowTH1F("sh", "", 30, 0, 8)
    bh = utils.UOFlowTH1F("bh", "", 30, 0, 8)
    utils.histoStyler(sh)
    utils.histoStyler(bh)

    for file in files:
        f = TFile(file)
        c = f.Get('tEvent')
        nentries = c.GetEntries()
        print 'Analysing', nentries, "entries"
        for ientry in range(nentries):
            c.GetEntry(ientry)
            if ientry % 1000 == 0:
                print "Processing " + str(ientry) + " weight=" + str(c.Weight)
            if analysis_ntuples.isX1X2X1Process(c):
                genZL, genNonZL = analysis_ntuples.classifyGenZLeptons(c)
                if genZL is None:
                    print "WHAT?!"
                    continue
                nL = c.Electrons.size() + c.Muons.size()
                l1 = None
                l2 = None
                if c.Electrons.size(
                ) == 2 and c.Electrons_charge[0] * c.Electrons_charge[1] < 0:
                    l1 = c.Electrons[0]
                    l2 = c.Electrons[1]
                elif c.Muons.size(
                ) == 2 and c.Muons_charge[0] * c.Muons_charge[1] < 0:
                    l1 = c.Muons[0]
                    l2 = c.Muons[1]
                if l1 is not None:
                    if l1.Pt() < 5 or l2.Pt() < 5:
                        continue
                    #print l1, genZL, c
                    minZ, minCanZ = analysis_ntuples.minDeltaRGenParticles(
                        l1, genZL, c.GenParticles)
                    if minZ > 0.1:
                        #print "NO"
                        continue
                    minZ, minCanZ = analysis_ntuples.minDeltaRGenParticles(
                        l2, genZL, c.GenParticles)
                    if minZ > 0.1:
                        #print "NO"
                        continue
                    sh.Fill((l1 + l2).M(), c.Weight)
                else:
                    ch1 = None
                    if c.Electrons.size() == 1:
                        l1 = c.Electrons[0]
                        ch1 = c.Electrons_charge[0]
                    elif c.Muons.size() == 1:
                        l1 = c.Muons[0]
                        ch1 = c.Muons_charge[0]
                    if not l1:
                        continue
                    if l1.Pt() < 5:
                        continue
                    if not genZL:
                        continue
                    for ti in range(c.tracks.size()):
                        if c.tracks_trkRelIso[ti] > 0.1:
                            continue

                        t = c.tracks[ti]
                        elecMin = analysis_tools.minDeltaR(t, c.Electrons)
                        muonMin = analysis_tools.minDeltaR(t, c.Muons)
                        if (elecMin is not None
                                and elecMin < 0.1) or (muonMin is not None
                                                       and muonMin < 0.1):
                            continue

                        minZ, minCanZ = analysis_ntuples.minDeltaRGenParticles(
                            t, genZL, c.GenParticles)
                        minNZ, minCanNZ = analysis_ntuples.minDeltaRGenParticles(
                            t, genNonZL, c.GenParticles)

                        min = None
                        if minNZ is None or minZ < minNZ:
                            min = minZ
                        else:
                            min = minNZ

                        result = ""

                        if min > 0.1:
                            result = "MM"
                        elif minNZ is None or minZ < minNZ:
                            if c.tracks_charge[ti] * c.GenParticles_PdgId[
                                    minCanZ] < 0:
                                result = "Zl"
                                #print "Found!"
                            else:
                                result = "MM"
                        else:
                            result = "MM"

                        if result == "Zl" and c.tracks_charge[ti] * ch1 < 0:
                            bh.Fill((t + l1).M(), c.Weight)
                            break

    cpBlue = utils.colorPalette[2]
    cpRed = utils.colorPalette[7]

    #trainBGHist.SetTitle(name)
    bh.GetXaxis().SetTitle("M_{ll} [GeV]")
    bh.GetYaxis().SetTitle("Number of events")
    bh.GetYaxis().SetTitleOffset(1.15)
    #bh.GetXaxis().SetLabelSize(0.04)
    #bh.GetYaxis().SetTitle("Arbitrary Units")

    fillC = TColor.GetColor(cpRed["fillColor"])
    lineC = TColor.GetColor(cpRed["lineColor"])
    #trainBGHist.SetFillStyle(cpRed["fillStyle"])
    bh.SetFillColorAlpha(fillC, 0.35)  #.35)
    bh.SetLineColor(lineC)
    bh.SetLineWidth(1)
    bh.SetOption("HIST")
    bh.SetMaximum(900)
    bh.Draw("HIST")

    legend.AddEntry(bh, "One reco one track", 'F')

    fillC = TColor.GetColor(cpBlue["fillColor"])
    lineC = TColor.GetColor(cpBlue["lineColor"])
    #sh.SetFillStyle(cpBlue["fillStyle"])
    sh.SetFillColorAlpha(fillC, 0.35)  #.35)
    sh.SetLineColor(lineC)
    sh.SetLineWidth(1)
    sh.SetOption("HIST")
    sh.Draw("HIST SAME")

    legend.AddEntry(sh, "Two reconstructed", 'F')

    legend.Draw("SAME")
    gPad.SetLogy()
    utils.stamp_plot()
    #utils.stampFab("35.9")
    c1.Print(output_file)
    c1.Print(output_file + "]")
    exit(0)
예제 #3
0
def main():

    print "Plotting observable"

    c1 = TCanvas("c1", "c1", 800, 800)
    c1.SetBottomMargin(0.16)
    c1.SetLeftMargin(0.16)
    #c1 = utils.mkcanvas()
    #memory = []
    c1.Print(output_file + "[")

    legend = TLegend(.55, .75, .89, .89)
    legend.SetBorderSize(0)
    legend.SetTextFont(42)
    legend.SetTextSize(0.05)

    files = glob(signal_dir + "/*")
    signal_files_re = re.compile("(" + SIM_GROUP[input] + ")_sig*")
    bg_files_re = re.compile("(" + SIM_GROUP[input] + ")_bg*")

    signal_files = [f for f in files if signal_files_re.match(f)]
    bg_files = [f for f in files if bg_files_re.match(f)]

    print signal_files
    print bg_files

    sh = utils.UOFlowTH1F("sh", "", 100, 2, 26)
    bh = utils.UOFlowTH1F("bh", "", 100, 2, 26)
    utils.histoStyler(sh)
    utils.histoStyler(bh)

    for (fs, hs) in [(signal_files, sh), (bg_files, bh)]:
        for file in fs:
            print "Processing " + file
            f = TFile(file)
            c = f.Get('tEvent')
            nentries = c.GetEntries()
            print 'Analysing', nentries, "entries"
            for ientry in range(nentries):
                if ientry % 1000 == 0:
                    print "Processing " + str(ientry)
                c.GetEntry(ientry)
                hs.Fill(c.lepton.Pt())

    cpBlue = utils.colorPalette[2]
    cpRed = utils.colorPalette[7]

    #trainBGHist.SetTitle(name)
    bh.GetXaxis().SetTitle("Pt(l)")
    bh.GetYaxis().SetTitle("Number of tracks")
    bh.GetYaxis().SetTitleOffset(1.15)
    #bh.GetXaxis().SetLabelSize(0.04)
    #bh.GetYaxis().SetTitle("Arbitrary Units")

    fillC = TColor.GetColor(cpRed["fillColor"])
    lineC = TColor.GetColor(cpRed["lineColor"])
    #trainBGHist.SetFillStyle(cpRed["fillStyle"])
    bh.SetFillColorAlpha(fillC, 0.35)  #.35)
    bh.SetLineColor(lineC)
    bh.SetLineWidth(1)
    bh.SetMinimum(0.01)
    bh.SetOption("HIST")
    bh.Draw("HIST")

    legend.AddEntry(bh, "Non-Z tracks", 'F')

    fillC = TColor.GetColor(cpBlue["fillColor"])
    lineC = TColor.GetColor(cpBlue["lineColor"])
    #sh.SetFillStyle(cpBlue["fillStyle"])
    sh.SetFillColorAlpha(fillC, 0.35)  #.35)
    sh.SetLineColor(lineC)
    sh.SetLineWidth(1)
    sh.SetOption("HIST")
    sh.Draw("HIST SAME")

    legend.AddEntry(sh, "Z tracks", 'F')

    legend.Draw("SAME")
    gPad.SetLogy()
    utils.stamp_plot()
    #utils.stampFab("35.9")
    c1.Print(output_file)
    c1.Print(output_file + "]")
    exit(0)
예제 #4
0
def main():

    print "Plotting observable"

    c1 = TCanvas("c1", "c1", 800, 800)
    c1.SetBottomMargin(0.16)
    c1.SetLeftMargin(0.18)

    c1.Print(output_file+"[");

    bg_files = glob(bg_dir + "/*")
    sumTypes = {}
    memory = []

    for f in bg_files: 
        filename = os.path.basename(f).split(".")[0]
        types = filename.split("_")
        if types[0] not in sumTypes:
            sumTypes[types[0]] = {}
        sumTypes[types[0]][types[1]] = True
    histograms = {}
    print sumTypes
    for type in sumTypes:
        if utils.existsInCoumpoundType(type):
            continue
        print "Summing type", type
        rootfiles = glob(bg_dir + "/*" + type + "*.root")
        #rootfiles.append(signal_file)
        #rootfiles = [signal_file] + rootfiles
        mll = createPlots(rootfiles, type, memory)
        print type
        histograms[type] = mll
    
    for cType in utils.compoundTypes:
        print "Creating compound type", cType
        rootFiles = []
        for type in utils.compoundTypes[cType]:
            rootFiles.extend(glob(bg_dir + "/*" + type + "*.root"))
        if len(rootFiles):
            mll = createPlots(rootFiles, cType, memory)
            histograms[type] = mll
        else:
            print "**Couldn't find file for " + cType

    sigHist = createPlots([signal_dir], "signal", memory)

    utils.formatHist(sigHist, utils.signalCp[0], 0.8)

    hs = THStack("invMass","")
    memory.append(hs)
    types = [k for k in utils.bgOrder]
    types = sorted(types, key=lambda a: utils.bgOrder[a])
    typesInx = []

    i = 0
    foundBg = False
    for type in types:
        if histograms.get(type) is not None:
            hs.Add(histograms[type])
            typesInx.append(i)
            foundBg = True
        i += 1
    #hs.Add(sigHist)
    #typesInx.append(i)

    sigMax = sigHist.GetMaximum()
    maximum = sigMax
    if foundBg:
        bgMax = hs.GetMaximum()
        maximum = max(bgMax, sigMax)

    #legend = TLegend(.69,.55,.89,.89)
    legend = TLegend(.20,.60,.89,.89)
    legend.SetNColumns(2)
    legend.SetBorderSize(0)
    legend.SetFillStyle(0)
    memory.append(legend)
    if foundBg:
        newBgHist = utils.styledStackFromStack(hs, memory, legend, "", typesInx, True)
        #newBgHist.SetFillColorAlpha(fillC, 0.35)
        newBgHist.SetMaximum(maximum*1000)
        newBgHist.SetMinimum(0.01)
        newBgHist.Draw("hist")
        utils.histoStyler(newBgHist)
        newBgHist.GetXaxis().SetTitle("M_{ll}")
        newBgHist.GetYaxis().SetTitle("Number of events")
        newBgHist.GetYaxis().SetTitleOffset(1.15)
        #newBgHist.GetXaxis().SetLabelSize(0.055)
        c1.Modified()
        #newBgHist.SetTitle(signal_name)

    #sigHist.SetTitle(signal_name)
    legend.AddEntry(sigHist, "signal", 'l')
    if foundBg:
        sigHist.SetMaximum(maximum)
    sigHist.SetMinimum(0.01)
    sigHist.SetLineWidth(2)
    sigHist.GetXaxis().SetTitle("GeV")
    if foundBg:
        sigHist.Draw("HIST SAME")
    else:
        sigHist.Draw("HIST")
    legend.Draw("SAME")
    gPad.SetLogy();
    utils.stamp_plot()
    c1.Update()
    c1.Print(output_file);

    c1.Print(output_file+"]");
예제 #5
0
    #isoBarrelHist.GetYaxis().SetTitle("#varepsilon")

    barrelHist.Draw("p")
    dataBarrelHist.Draw("p same")
    if not id_only:
        isoBarrelHist.Draw("p")
        isoDataBarrelHist.Draw("p same")
        if plot_stability:
            isoBarrelHistFactor.Draw("p same")
            isoDataBarrelHistFactor.Draw("p same")
            barrelHist.Draw("p same")
            dataBarrelHist.Draw("p same")

    isoLegend.Draw("SAME")
    #utils.stamp_plot("22.9")
    utils.stamp_plot("", utils.StampStr.PRE, utils.StampCoor.ABOVE_PLOT, False)
    if id_only:
        if region == 0:
            c1.SaveAs("barrelDeltaRidOnlyNoTagCut.pdf")
        else:
            c1.SaveAs("endcapsDeltaRidOnlyNoTagCut.pdf")
    else:
        if region == 0:
            c1.SaveAs("barrelDeltaRisoNoTagCut.pdf")
        else:
            c1.SaveAs("endcapsDeltaRisoNoTagCut.pdf")

    #Scale Factors

    isoLegend = TLegend(.70, .75, .89, .88)
    isoLegend.SetNColumns(1)
예제 #6
0
#setMarkers(dataBarrelHist, kFullCircle)

dataBarrelHist.SetMarkerStyle(kFullCircle)
dataBarrelHist.SetLineColor(kBlack)

legend.AddEntry(barrelHist, "MC", 'p')
legend.AddEntry(dataBarrelHist, "Data", 'p')
#legend.AddEntry(barrelHistHistCount, "Signal Count Efficiency", 'p')
barrelHist.GetXaxis().SetTitle("pT")

barrelHist.Draw("p")
dataBarrelHist.Draw("p same")
#barrelHistHistCount.Draw("p same")

legend.Draw("SAME")
utils.stamp_plot("22.9")
c1.SaveAs("barrelHist.pdf")

### SCALE FACTORS #####

c1 = TCanvas("c1", "c1", 800, 800)

legend = TLegend(.60, .40, .89, .60)
legend.SetNColumns(1)
legend.SetBorderSize(1)
legend.SetFillStyle(0)

dataBarrelHist.Divide(barrelHist)
dataBarrelHist.GetXaxis().SetTitle("pT")
dataBarrelHist.Draw("p")
utils.stamp_plot("22.9")
    #isoBarrelHist.GetYaxis().SetTitle("#varepsilon")

    barrelHist.Draw("p")
    dataBarrelHist.Draw("p same")
    if not id_only:
        isoBarrelHist.Draw("p")
        isoDataBarrelHist.Draw("p same")
        if plot_stability:
            isoBarrelHistFactor.Draw("p same")
            isoDataBarrelHistFactor.Draw("p same")
            barrelHist.Draw("p same")
            dataBarrelHist.Draw("p same")

    isoLegend.Draw("SAME")
    #utils.stamp_plot("22.9")
    utils.stamp_plot("36.0", utils.StampStr.PRE, utils.StampCoor.ABOVE_PLOT)
    if id_only:
        if region == 0:
            c1.SaveAs("barrelDeltaRSingleElectron.pdf")
        else:
            c1.SaveAs("endcapsDeltaRSingleElectron.pdf")
    else:
        if region == 0:
            c1.SaveAs("barrelDeltaRSingleElectron.pdf")
        else:
            c1.SaveAs("endcapsDeltaRSingleElectron.pdf")

    #Scale Factors

    isoLegend = TLegend(.70, .75, .89, .88)
    isoLegend.SetNColumns(1)
예제 #8
0
def main():

    print "Plotting observable"
    c2 = TCanvas("c2")
    c1 = TCanvas("c1", "c1", 800, 800)
    c1.SetBottomMargin(0.16)
    c1.SetLeftMargin(0.18)
    #c1 = utils.mkcanvas()
    #memory = []
    
    global method
    global normalise
    
    file = [input]
    c2.cd()
    #(testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods, names) = cut_optimisation.get_bdt_hists(file, None, None, None, None, None, None, 40)
    (testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods, names) = cut_optimisation.get_method_hists(file, method, None, None, None, None, None, None, 40, "", weight)
    #cut_optimisation.get_mlp_hists(file, testBGHists, trainBGHists, testSignalHists, trainSignalHists, methods, names)
    c1.cd()
    
    c1.Print(output_file+"[");
    
    c1.SetLogy()
    
    legend = TLegend(0.65, 0.70, 0.87, 0.875)
    legend.SetBorderSize(0)
    legend.SetTextFont(42)
    legend.SetTextSize(0.05)
    
    for inx in range(len(testBGHists)):
    
        testBGHist, trainBGHist, testSignalHist, trainSignalHist, method, name = testBGHists[inx], trainBGHists[inx], testSignalHists[inx], trainSignalHists[inx], methods[inx], names[inx]
        
        ST = trainSignalHist.Integral() + testSignalHist.Integral()
        BT = trainBGHist.Integral() + testBGHist.Integral()

        if normalise:
            trainSignalHist.Scale(1./ST)
            testSignalHist.Scale(1./ST)
            testBGHist.Scale(1./BT)
            trainBGHist.Scale(1./BT)
            
        maxY = max(trainSignalHist.GetMaximum(), testSignalHist.GetMaximum(), testBGHist.GetMaximum(), trainBGHist.GetMaximum())
        
        cpBlue = utils.colorPalette[2]
        cpRed = utils.colorPalette[7]
        utils.histoStyler(trainBGHist)
        trainBGHist.SetTitle("")
        trainBGHist.GetXaxis().SetTitle("BDT Output")
        trainBGHist.GetYaxis().SetTitle("Number of events")
        trainBGHist.GetYaxis().SetTitleOffset(1.4)
        trainBGHist.GetXaxis().SetLabelSize(0.055)
        #trainBGHist.SetMaximum(maxY + 0.02)

        fillC = TColor.GetColor(cpRed["fillColor"])
        lineC = TColor.GetColor(cpRed["lineColor"])
        trainBGHist.SetFillStyle(cpRed["fillStyle"])
        trainBGHist.SetFillColorAlpha(fillC, 0.35)
        trainBGHist.SetLineColor(lineC)
        trainBGHist.SetLineWidth(1)
        trainBGHist.SetOption("HIST")
        
        trainBGHist.Draw("HIST")

        legend.AddEntry(trainBGHist, "B (train)", 'F')

        fillC = TColor.GetColor(cpBlue["fillColor"])
        lineC = TColor.GetColor(cpBlue["lineColor"])
        trainSignalHist.SetFillStyle(cpBlue["fillStyle"])
        trainSignalHist.SetFillColorAlpha(fillC, 0.35)
        trainSignalHist.SetLineColor(lineC)
        trainSignalHist.SetLineWidth(1)
        trainSignalHist.SetOption("HIST")
        trainSignalHist.Draw("HIST SAME")
        
        legend.AddEntry(trainSignalHist, "S (train)", 'F')
        
        testBGHist.SetMarkerColor(kRed)
        testBGHist.SetMarkerSize(0.5)
        testBGHist.SetMarkerStyle(20)
        testBGHist.SetOption("p E1")
        testBGHist.SetLineColor(kRed)
        testBGHist.Draw("SAME p E1")
        
        legend.AddEntry(testBGHist, "B (test)", "p e2")
        
        testSignalHist.SetMarkerColor(kBlue)
        testSignalHist.SetMarkerSize(0.5)
        testSignalHist.SetMarkerStyle(20)
        testSignalHist.SetOption("p E1")
        testSignalHist.SetLineColor(kBlue)
        testSignalHist.Draw("SAME p E1")
        
        legend.AddEntry(testSignalHist, "S (test)", "p e2")
    
        legend.Draw("SAME")

    utils.stamp_plot()
    #gPad.SetLogy();
    #utils.stampFab("35.9")
    c1.Print(output_file);
    c1.Print(output_file+"]");
    exit(0)