Ejemplo 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
Ejemplo 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 8
0
###    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:
    limit_sm = plot.MakeTChain(args.sm_exp, 'limit')
    best_sm = ROOT.TGraph(1, array('d', [
        1,
    ]), array('d', [
        1,
limit = plot.MakeTChain(args.files, 'limit')
graph = plot.TGraph2DFromTree(
    #    limit, "muV", "CMS_zz4l_fai1", '2*deltaNLL', 'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 10000000000000000')
    #    limit, "muV", "CMS_zz4l_fai1", '2*deltaNLL', 'quantileExpected > -0.5')
    limit,
    "muV*( (1.-abs(CMS_zz4l_fai1))*%s + abs(CMS_zz4l_fai1)*%s*%s/%s + sign(CMS_zz4l_fai1)*sqrt((1-abs(CMS_zz4l_fai1))*abs(CMS_zz4l_fai1)*%s/%s)*%s )/(%s)"
    % (sigma_SM_HTT, sigma_SM_HZZ, sigma_3_HTT, sigma_3_HZZ, sigma_SM_HTT,
       sigma_3_HTT, sigma_13_intOnly, sigma_SM_HTT),
    "CMS_zz4l_fai1",
    '2*deltaNLL',
    'quantileExpected > -0.5')
best = plot.TGraphFromTree(
    #    limit, "muV", "CMS_zz4l_fai1", 'deltaNLL == 0')
    limit,
    "muV*( (1.-abs(CMS_zz4l_fai1))*%s + abs(CMS_zz4l_fai1)*%s*%s/%s + sign(CMS_zz4l_fai1)*sqrt((1-abs(CMS_zz4l_fai1))*abs(CMS_zz4l_fai1)*%s/%s)*%s )/(%s)"
    % (sigma_SM_HTT, sigma_SM_HZZ, sigma_3_HTT, sigma_3_HZZ, sigma_SM_HTT,
       sigma_3_HTT, sigma_13_intOnly, sigma_SM_HTT),
    "CMS_zz4l_fai1",
    '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, "muV", "CMS_zz4l_fai1", 'deltaNLL == 0')
        limit_bg,
        "muV*( (1.-abs(CMS_zz4l_fai1))*%s + abs(CMS_zz4l_fai1)*%s*%s/%s + sign(CMS_zz4l_fai1)*sqrt((1-abs(CMS_zz4l_fai1))*abs(CMS_zz4l_fai1)*%s/%s)*%s )/(%s)"
        % (sigma_SM_HTT, sigma_SM_HZZ, sigma_3_HTT, sigma_3_HZZ, sigma_SM_HTT,
           sigma_3_HTT, sigma_13_intOnly, sigma_SM_HTT),
        "CMS_zz4l_fai1",
Ejemplo n.º 10
0
             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()

canv.Print('.pdf')
Ejemplo n.º 11
0
plot.ModTDRStyle(width=600, l=0.12)
ROOT.gStyle.SetNdivisions(510, 'XYZ')
plot.SetBirdPalette()
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()

if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

limit = plot.MakeTChain(args.files, 'limit')
graph = plot.TGraph2DFromTree(
    limit, "muV", "CMS_zz4l_fai1", '2*deltaNLL',
    'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
best = plot.TGraphFromTree(limit, "muV", "CMS_zz4l_fai1", '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, "muV", "CMS_zz4l_fai1",
                                  'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)

# If included just plot SM exp at 1,1
if args.sm_exp:
    limit_sm = plot.MakeTChain(args.sm_exp, 'limit')
    best_sm = ROOT.TGraph(1, array('d', [
        1,
    ]), array('d', [
Ejemplo n.º 12
0
ROOT.gStyle.SetNdivisions(510, 'XYZ')
plot.SetBirdPalette()
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()

if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

limit = plot.MakeTChain(args.files, 'limit')

graph = plot.TGraph2DFromTree(
    limit, "r_ggH", "r_bbH", '2*deltaNLL',
    'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
best = plot.TGraphFromTree(limit, "r_ggH", "r_bbH", 'deltaNLL == 0')
plot.RemoveGraphXDuplicates(best)
hists = plot.TH2FromTGraph2D(graph, method='BinCenterAligned')
plot.fastFillTH2(hists, graph, interpolateMissing=False)
if args.bg_exp:
    limit_bg = plot.MakeTChain(args.bg_exp, 'limit')
    best_bg = plot.TGraphFromTree(limit_bg, "r_ggH", "r_bbH", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)
if args.sm_exp:
    limit_sm = plot.MakeTChain(args.sm_exp, 'limit')
    best_sm = plot.TGraphFromTree(limit_sm, "r_ggH", "r_bbH", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_sm)
hists.SetMaximum(6)
hists.SetMinimum(0)
hists.SetContour(255)
# c2=ROOT.TCanvas()
#Create canvas and TH2D for each component
plot.ModTDRStyle(width=600, l=0.12)
ROOT.gStyle.SetNdivisions(510, 'XYZ')
plot.SetBirdPalette()
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()

if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

limit = plot.MakeTChain(args.files, 'limit')
graph = plot.TGraph2DFromTree(
    limit, "kappa_V", "kappa_F", '2*deltaNLL', 'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
best = plot.TGraphFromTree(
    limit, "kappa_V", "kappa_F", '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, "kappa_V", "kappa_F", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)
if args.sm_exp:
    limit_sm = plot.MakeTChain(args.sm_exp, 'limit')
    best_sm = plot.TGraphFromTree(
        limit_sm, "kappa_V", "kappa_F", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_sm)
hists.SetMaximum(6)
hists.SetMinimum(0)
Ejemplo n.º 14
0
plot.ModTDRStyle(width=600, l=0.12)
ROOT.gStyle.SetNdivisions(510, 'XYZ')
plot.SetBirdPalette()
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()

if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

limit = plot.MakeTChain(args.files, 'limit')
graph = plot.TGraph2DFromTree(
    limit, "mu", "fa03", '2*deltaNLL',
    'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
best = plot.TGraphFromTree(limit, "mu", "fa03", '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, "mu", "fa03", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)

# If included just plot SM exp at 1,1
if args.sm_exp:
    limit_sm = plot.MakeTChain(args.sm_exp, 'limit')
    best_sm = ROOT.TGraph(1, array('d', [
        1,
    ]), array('d', [
        1,
Ejemplo n.º 15
0
ROOT.gStyle.SetNdivisions(510, 'XYZ')
plot.SetBirdPalette()
canv = ROOT.TCanvas(args.output, args.output)
pads = plot.OnePad()

if args.debug_output is not None:
    debug = ROOT.TFile(args.debug_output, 'RECREATE')
else:
    debug = None

limit = plot.MakeTChain(args.files, 'limit')
if args.CPodd:
    graph = plot.TGraph2DFromTree(
        limit, "Yt_A", "Yb_A", '2*deltaNLL',
        'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
    best = plot.TGraphFromTree(limit, "Yt_A", "Yb_A", 'deltaNLL == 0')
else:
    graph = plot.TGraph2DFromTree(
        limit, "Yt_H", "Yb_H", '2*deltaNLL',
        'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
    best = plot.TGraphFromTree(limit, "Yt_H", "Yb_H", '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, "alpha", "muF", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)

# If included just plot SM exp at 1,1
if args.sm_exp: