Example #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
Example #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
Example #3
0
def main(args):
    # Get tree with scan values from all input files
    limit = plot.MakeTChain(args.files, 'limit')

    # Write Tree entries in TGraph to get structure for likelihood database
    graph = plot.TGraph2DFromTree(
        limit, args.x_var, args.y_var, 'deltaNLL',
        'quantileExpected > -0.5 && deltaNLL < 1000')
    # 'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')

    # rezero the TGraph to have sensible values in the output file
    min_delta_nll = rezero_tgraph2d(graph)
    df = convert_graph_to_dataframe(graph)
    df.to_csv(args.output,
              sep=" ",
              float_format="%.6f",
              header=False,
              index=False,
              na_rep="NaN",
              columns=[args.x_var, args.y_var, "deltaNLL"])
    best = plot.TGraphFromTree(limit, args.x_var, args.y_var, 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best)
    # Write back a root TTree with the modified contents.
    outfile = ROOT.TFile(args.output.replace(".txt", ".root"), "recreate")
    tree = convert_dataframe_to_tree(df, best, offset=min_delta_nll)
    # Add the best fit values from the limit trees
    outfile.Write()
    return
Example #4
0
def read(scan, param, files, ycut):
    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)
    # graph.Print()
    return graph
Example #5
0
def read(scan, param_x, param_y, file):
    # print files
    goodfiles = [f for f in [file] if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraph2DFromTree(limit, param_x, param_y, '2*deltaNLL', 'quantileExpected > -0.5 && deltaNLL > 0')
    best = plot.TGraphFromTree(limit, param_x, param_y, 'quantileExpected > -0.5 && deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best)
    assert(best.GetN() == 1)
    graph.SetName(scan)
    best.SetName(scan+'_best')
    # graph.Print()
    return (graph, best)
Example #6
0
def read(scan, param, other_param, files, 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, other_param,
                                'quantileExpected > -0.5')
    # print 'INPUT'
    # graph.Print()
    graph.SetName(scan)
    graph.Sort()
    if remove_dups:
        plot.RemoveGraphXDuplicates(graph)
    # graph.Print()
    return graph
Example #7
0
 def ReadScanFromTFiles(self,
                        filenames,
                        param_name,
                        tree_selection='quantileExpected > -1.5'):
     # TODO: should report bad files here
     goodfiles = [f for f in filenames if plotting.TFileIsGood(f)]
     if len(goodfiles) == 0:
         raise RuntimeError('[ReadScanFromTFiles] no valid TFiles')
     limit = plotting.MakeTChain(goodfiles, 'limit')
     graph = plotting.TGraphFromTree(limit, param_name, '2*deltaNLL',
                                     tree_selection)
     # graph.SetName(label)
     graph.Sort()
     if self.verbosity >= 2:
         print '[ReadScanFromTFiles] Produced TGraph:'
         graph.Print()
     return graph
Example #8
0
####limit2 = plot.MakeTChain(['new/higgsCombineCvCf.MultiDimFit.mH125.root',], 'limit')
###limit2 = plot.MakeTChain([args.files[1],], 'limit')
###graph2 = plot.TGraph2DFromTree(
###    limit2, "CV", "CF", '2*deltaNLL', 'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
###best2 = plot.TGraphFromTree(
###    limit2, "CV", "CF", 'deltaNLL == 0')
###plot.RemoveGraphXDuplicates(best2)
####hists2 = plot.TH2FromTGraph2D(graph2, method='BinCenterAligned')
###hists.append( plot.TH2FromTGraph2D(graph2, method='BinCenterAligned') )
####plot.fastFillTH2(hists2, graph,interpolateMissing=True)
###if args.bg_exp:
###    limit_bg = plot.MakeTChain(args.bg_exp, 'limit')
###    best_bg = plot.TGraphFromTree(
###        limit_bg, "CV", "CF", 'deltaNLL == 0')
###    plot.RemoveGraphXDuplicates(best_bg)
limit = plot.MakeTChain(args.files, 'limit')
print limit
graph = plot.TGraph2DFromTree(
    limit, "CV", "CF", '2*deltaNLL',
    'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
best = plot.TGraphFromTree(limit, "CV", "CF", 'deltaNLL == 0')
plot.RemoveGraphXDuplicates(best)
hists = plot.TH2FromTGraph2D(graph, method='BinCenterAligned')
plot.fastFillTH2(hists, graph, interpolateMissing=True)
if args.bg_exp:
    limit_bg = plot.MakeTChain(args.bg_exp, 'limit')
    best_bg = plot.TGraphFromTree(limit_bg, "CV", "CF", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)

# If included just plot SM exp at 1,1
if args.sm_exp:
Example #9
0
             LineColor=ROOT.kBlack,
             LineWidth=2,
             FillStyle=1001)
    gr.Draw(fillstyle)
    gr.Draw("LSAME")

# We just want the top pad to look like a box, so set all the text and tick
# sizes to zero

# Draw the legend in the top TPad
legend = plot.PositionedLegend(0.3, 0.2, 3, 0.015)
legend.AddEntry(contours68['obs'][0], "68% CL", "F")
legend.AddEntry(contours95['obs'][0], "95% CL", "F")
#Add best fit value (From MultiDimFit)
if args.best_fit:
    limit_best = plot.MakeTChain(args.best_fit, 'limit')
    best = plot.TGraphFromTree(limit_best, "r_ggH", "r_bbH", 'deltaNLL == 0')
    best.SetMarkerStyle(34)
    best.SetMarkerSize(3)
    best.Draw("P SAME")
    legend.AddEntry(best, "Best fit", "P")
if args.mass:
    legend.SetHeader("m_{#phi} = " + args.mass + " GeV")
legend.Draw("SAME")

# Draw logos and titles
plot.DrawCMSLogo(pads[0], 'CMS', args.cms_sub, 11, 0.045, 0.035, 1.2, '', 1.0)
plot.DrawTitle(pads[0], args.title_right, 3)
plot.DrawTitle(pads[0], args.title_left, 1)
plot.FixOverlay()