Exemplo n.º 1
0
def read(scan, param, files, chop, remove_near_min, rezero,
         remove_delta=None, improve=False, remove_dups=True):
    # print files
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraphFromTree(
        limit, param, '2*%s' % DELTANLL, 'quantileExpected > -1.5')
    # print 'INPUT'
    # graph.Print()
    graph.SetName(scan)
    graph.Sort()
    if remove_dups:
        plot.RemoveGraphXDuplicates(graph)
    if remove_delta is not None:
        plot.RemoveSmallDelta(graph, remove_delta)
    plot.RemoveGraphYAbove(graph, chop)
    plot.ReZeroTGraph(graph, rezero)
    if remove_near_min is not None:
        plot.RemoveNearMin(graph, remove_near_min)
    if improve:
        global NAMECOUNTER
        spline = ROOT.TSpline3("spline3", graph)
        func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                        graph.GetX()[0], graph.GetX()[graph.GetN() - 1], 1)
        func.SetNpx(NPX)
        NAMECOUNTER += 1
        plot.ImproveMinimum(graph, func, True)
    # graph.Print()
    if FILTER is not None:
        plot.FilterGraph(graph, FILTER)
    if REMOVE_X_RANGES is not None:
        for remove_x in REMOVE_X_RANGES:
            plot.RemoveInXRange(graph, remove_x[0], remove_x[1])
    return graph
Exemplo n.º 2
0
def read(scan,
         param,
         files,
         chop,
         remove_near_min,
         rezero,
         remove_delta=None,
         improve=False):
    # print files
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    # require quantileExpected > -0.5 to avoid the final point which is always committed twice
    # (even if the fit fails)
    graph = plot.TGraphFromTree(limit, param, '2*deltaNLL',
                                'quantileExpected > -0.5')
    graph.SetName(scan)
    graph.Sort()
    plot.RemoveGraphXDuplicates(graph)
    if remove_delta is not None: plot.RemoveSmallDelta(graph, remove_delta)
    plot.RemoveGraphYAbove(graph, chop)
    plot.ReZeroTGraph(graph, rezero)
    if remove_near_min is not None: plot.RemoveNearMin(graph, remove_near_min)
    if improve:
        global NAMECOUNTER
        spline = ROOT.TSpline3("spline3", graph)
        func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                        graph.GetX()[0],
                        graph.GetX()[graph.GetN() - 1], 1)
        NAMECOUNTER += 1
        plot.ImproveMinimum(graph, func, True)
    # graph.Print()
    return graph
Exemplo n.º 3
0
def read(scan, param, files, ycut, rezero=True):
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraphFromTree(limit, param, '2*deltaNLL',
                                'quantileExpected > -1.5')
    graph.SetName(scan)
    graph.Sort()
    plot.RemoveGraphXDuplicates(graph)
    plot.RemoveGraphYAbove(graph, ycut)
    if rezero: plot.ReZeroTGraph(graph, rezero)
    # graph.Print()
    return graph
Exemplo n.º 4
0
    def run_method(self):
        ROOT.gROOT.SetBatch(ROOT.kTRUE)
        outfile = ROOT.TFile('%s.root' % self.args.output, 'RECREATE')
        points = self.args.points
        file = ROOT.TFile(self.args.workspace.split(':')[0])
        wsp = file.Get(self.args.workspace.split(':')[1])
        mc = wsp.genobj('ModelConfig')
        pdf = mc.GetPdf()
        if self.args.data is None:
            data = wsp.data('data_obs')
        else:
            ws_d = self.args.data.split(':')
            print '>> Data: ' + str(ws_d)
            f_d = ROOT.TFile(ws_d[0])
            if len(ws_d) == 2:
                data = f_d.Get(ws_d[1])
            else:
                data = f_d.Get(ws_d[1]).data(ws_d[2])
        ll = ROOT.RooLinkedList()
        nll = pdf.createNLL(data, ll)
        pars = pdf.getParameters(data)
        pars.Print()
        snap = pars.snapshot()
        # nll.setZeroPoint()
        nll.Print()
        if self.args.fitres is not None:
            fitfile = ROOT.TFile(self.args.fitres.split(':')[0])
            rfr = fitfile.Get(self.args.fitres.split(':')[1])
            snap = rfr.floatParsFinal()
        pars.assignValueOnly(snap)

        page = 0
        doPars = []

        for par in self.RooColIter(pars):
            if par.isConstant():
                continue
            if self.args.match is not None:
                if not re.match(self.args.match, par.GetName()):
                    continue
            if self.args.no_match is not None:
                if re.match(self.args.no_match, par.GetName()):
                    continue
            par.Print()
            if not (par.hasMax() and par.hasMin()):
                print 'Parameter does not have an associated range, skipping'
                continue
            doPars.append(par)
        plot.ModTDRStyle(width=700, height=1000)
        for idx, par in enumerate(doPars):
            print '%s : (%i/%i)' % (par.GetName(), idx + 1, len(doPars))
            nlld1 = nll.derivative(par, 1)
            nlld2 = nll.derivative(par, 2)
            xmin = par.getMin()
            xmax = par.getMax()
            gr = ROOT.TGraph(points)
            grd1 = ROOT.TGraph(points)
            grd2 = ROOT.TGraph(points)
            gr.SetName(par.GetName())
            grd1.SetName(par.GetName() + "_d1")
            grd2.SetName(par.GetName() + "_d2")
            w = (xmax - xmin) / float(points)
            for i in xrange(points):
                x = xmin + (float(i) + 0.5) * w
                par.setVal(x)
                gr.SetPoint(i, x, nll.getVal())
                grd1.SetPoint(i, x, nlld1.getVal())
                grd2.SetPoint(i, x, nlld2.getVal())
            plot.ReZeroTGraph(gr, True)
            # plot.RemoveGraphYAbove(gr, 2.)
            # gr.Print()
            outfile.cd()
            gr.Write()
            grd1.Write()
            grd2.Write()
            pars.assignValueOnly(snap)
            canv = ROOT.TCanvas(self.args.output, self.args.output)
            pads = plot.MultiRatioSplit([0.4, 0.3], [0.005, 0.005],
                                        [0.005, 0.005])
            pads[0].cd()
            plot.Set(gr, MarkerSize=0.5)
            gr.Draw('APL')
            axis1 = plot.GetAxisHist(pads[0])
            axis1.GetYaxis().SetTitle('NLL')
            pads[1].cd()
            plot.Set(grd1, MarkerSize=0.5)
            grd1.Draw('APL')
            axis2 = plot.GetAxisHist(pads[1])
            axis2.GetYaxis().SetTitle('NLL\'')
            pads[2].cd()
            plot.Set(grd2, MarkerSize=0.5)
            grd2.Draw('APL')
            axis3 = plot.GetAxisHist(pads[2])
            axis3.GetYaxis().SetTitle('NLL\'\'')
            plot.Set(
                axis3.GetXaxis(),
                Title=par.GetName(),
                TitleSize=axis3.GetXaxis().GetTitleSize() * 0.5,
                TitleOffset=axis3.GetXaxis().GetTitleOffset() * 2,
            )
            extra = ''
            if page == 0:
                extra = '('
            if page == len(doPars) - 1:
                extra = ')'
            print extra
            canv.Print('.pdf%s' % extra)
            page += 1

        outfile.Write()