Exemplo n.º 1
0
    def printFractionsPerIEta(self, graph):
        self.output("Fractions of HO time in [-12.5,12.5] ns")
        counterDict = [{
            'total':
            0,
            'inside':
            0,
            'hist':
            TH1D('hist' + str(i - 10), '', 201, -100.5, 100.5)
        } for i in range(0, 21)]
        x = Double(0)
        y = Double(0)
        nTotal = graph.GetN()

        ###
        # Fill histograms for later calculation of mean
        ###
        for i in range(0, nTotal):
            graph.GetPoint(i, x, y)
            indexHelper = int(x + 10)
            counterDict[indexHelper]['total'] += 1
            counterDict[indexHelper]['hist'].Fill(y)

        ###
        # Once all histograms are filled, calculate median
        ###
        for index, item in enumerate(counterDict):
            item['median'] = getMedian(item['hist'])

        ###
        # Fill the number of objects in interval depending on the
        # Histogram median
        ###
        nDone = 0
        if self.DEBUG:
            self.debug('Filling interval counters')
        for i in range(0, nTotal):
            graph.GetPoint(i, x, y)
            indexHelper = int(x + 10)
            median = counterDict[indexHelper]['median']
            if (fabs(median - y) < 12.5):
                counterDict[indexHelper]['inside'] += 1
            nDone += 1
            self.printProgress(nDone, nTotal)

        #Graph for results
        graph = TEfficiency(graph.GetName(), "", 21, -10.5, 10.5)

        ###
        # Plot the results of calculations on CLI
        ###
        for index, item in enumerate(counterDict):
            if (index - 10 == 0):
                continue
            total = item['total']
            inside = item['inside']
            self.output(
                "iEta: %3d\tTotal: %5d\tInside:%5d\tFraction:%6.2f +/- %6.2f" %
                (index - 10, total, inside, calcPercent(
                    inside, total), calcSigma(inside, total) * 100))
            graph.SetTotalEvents(graph.FindFixBin(index - 10), total)
            graph.SetPassedEvents(graph.FindFixBin(index - 10), inside)
        return graph, counterDict
Exemplo n.º 2
0
    def makeCombinedEtaPlot(self, tight=False):
        hist = self.makeL1TimeVsEtaPlot(('tight_' if tight else '') +
                                        'dtOnly_bxidVsEta')[2]
        countsInL1 = []
        for x in np.arange(-.95, 1.05, 0.1):
            totalCounter = 0
            zeroCount = 0
            for y in range(-2, 3):
                totalCounter += hist.GetBinContent(hist.FindBin(x, y))
                if y == 0:
                    zeroCount = hist.GetBinContent(hist.FindBin(x, y))
            countsInL1.append({
                'total': totalCounter,
                'zero': zeroCount,
                'eta': x
            })

        #Graph for results
        graph1 = TEfficiency(hist.GetName(), "", 8, -9.195, -.5)
        graph2 = TEfficiency(hist.GetName(), "", 8, .5, 9.195)

        for item in countsInL1:
            if item['total'] == 0:
                continue
            print item['total'], item['zero'], item['eta']
            if item['eta'] < 0:
                graph1.SetTotalEvents(
                    graph1.FindFixBin(-0.5 + item['eta'] / 0.087),
                    int(item['total']))
                graph1.SetPassedEvents(
                    graph1.FindFixBin(-0.5 + item['eta'] / 0.087),
                    int(item['zero']))
            else:
                graph2.SetTotalEvents(
                    graph2.FindFixBin(0.5 + item['eta'] / 0.087),
                    int(item['total']))
                graph2.SetPassedEvents(
                    graph2.FindFixBin(0.5 + item['eta'] / 0.087),
                    int(item['zero']))

        histHo = None
        if tight:
            histHo = self.plotTightHoTimeVsEta()[3][1]
        else:
            histHo = self.plotHoTimeVsEta()[3][1]

        histHo.SetTitle(('Tight ' if tight else '') + 'Unmatched DT + HO')

        canvas = TCanvas(
            'combinedPlot' + ('Tight ' if tight else '') + hist.GetName(),
            'combinedPlot')
        canvas.cd().SetTopMargin(.15)
        histHo.Draw('ap')
        canvas.Update()
        canvas.cd().SetTicks(0, 0)

        histHo.SetMarkerStyle(2)
        histHo.SetLineColor(colorRwthDarkBlue)
        histHo.SetMarkerColor(colorRwthDarkBlue)
        histHo.GetPaintedGraph().GetXaxis().SetRangeUser(-12, 12)
        histHo.GetPaintedGraph().GetXaxis().SetLabelColor(colorRwthDarkBlue)
        histHo.GetPaintedGraph().GetXaxis().SetTitleColor(colorRwthDarkBlue)
        histHo.GetPaintedGraph().GetXaxis().SetAxisColor(colorRwthDarkBlue)
        yMax = gPad.GetFrame().GetY2()
        yMin = gPad.GetFrame().GetY1()

        #Print average Fraction excluding iEta +/-2
        x = Double(0)
        y = Double(0)
        mean = 0
        var = 0
        for i in range(0, histHo.GetPaintedGraph().GetN()):
            histHo.GetPaintedGraph().GetPoint(i, x, y)
            if abs(x) == 2:
                continue
            mean += y
            var += histHo.GetPaintedGraph().GetErrorY(
                i) * histHo.GetPaintedGraph().GetErrorY(i)

        mean /= histHo.GetPaintedGraph().GetN() - 2
        sigma = sqrt(var / (histHo.GetPaintedGraph().GetN() - 2))

        self.debug(
            "Average fraction excluding iEta +/- 2 %s: %5.2f%% +/- %5.2f%%" %
            ('[Tight]' if tight else '', mean * 100, sigma * 100))

        nTotal = 0
        nPassed = 0
        for item in countsInL1:
            if fabs(item['eta']) == 2 or fabs(item['eta'] == 0):
                continue
            nTotal += item['total']
            nPassed += item['zero']

        #Print again with ClopperPearson uncertainty, the counts are for L1!!!
        mean = nPassed / nTotal * 100
        sigmaPlus = TEfficiency.ClopperPearson(int(nTotal), int(nPassed), .68,
                                               1) * 100 - mean
        sigmaMinus = mean - TEfficiency.ClopperPearson(
            int(nTotal), int(nPassed), .68, 0) * 100
        #self.debug("Average fraction excluding iEta +/- 2 %s with Clop.Pear.: %5.2f%% +%5.2f%% -%5.2f%%"
        #		% ('[Tight]' if tight else '',mean,sigmaPlus,sigmaMinus))

        #Left axis part
        f1 = TF1("f1", "x", -0.87, 0)
        A1 = TGaxis(-10, yMax, -0.5, yMax, "f1", 010, "-")
        A1.SetLineColor(colorRwthRot)
        A1.SetLabelColor(colorRwthRot)
        A1.Draw()

        #Right axis part
        f2 = TF1("f2", "x", 0, 0.87)
        A2 = TGaxis(0.5, yMax, 10, yMax, "f2", 010, "-")
        A2.SetLineColor(colorRwthRot)
        A2.SetLabelColor(colorRwthRot)
        A2.Draw()

        #Box for shading out 0
        box = TBox(-.5, yMin, 0.5, yMax)
        box.SetLineColor(colorRwthDarkGray)
        box.SetFillColor(colorRwthDarkGray)
        box.SetFillStyle(3013)
        box.Draw('same')

        #Left L1 eta
        graph1.SetMarkerColor(colorRwthRot)
        graph1.SetLineColor(colorRwthRot)
        graph1.SetMarkerStyle(20)
        graph1.Draw('same,p')

        #Right L1Eta
        graph2.SetMarkerColor(colorRwthRot)
        graph2.SetLineColor(colorRwthRot)
        graph2.SetMarkerStyle(20)
        graph2.Draw('same,p')

        #Label for extra axis
        axisLabel = TPaveText(0.83, 0.85, 0.89, 0.9, "NDC")
        axisLabel.AddText('#eta_{L1}')
        axisLabel.SetBorderSize(0)
        axisLabel.SetFillStyle(0)
        axisLabel.SetTextColor(colorRwthRot)
        axisLabel.SetTextSize(0.05)
        axisLabel.Draw()

        #Legend
        legend = getLegend(x1=0.1, y1=0.1, x2=0.4, y2=.35)
        legend.AddEntry(histHo, 'HO #in #pm12.5 ns', 'pe')
        legend.AddEntry(graph1, ('Tight ' if tight else '') + 'L1 BXID = 0',
                        'pe')
        legend.Draw()

        canvas.Update()
        self.storeCanvas(canvas,
                         "combinedFractionL1AndHo" +
                         ('Tight' if tight else ''),
                         drawMark=False)

        return histHo, graph1, canvas, A1, f1, A2, f2, box, graph2, axisLabel, legend