Example #1
0
 def make_plot(self):
     '''
     Creates a canvas and draws the histogram on it.
     '''
     canvases.next(self.GetName())
     self.DrawCopy()
     canvases.update()
Example #2
0
 def make_plot(self):
     '''
     Creates a canvas and draws the histogram on it.
     '''
     canvases.next(self.GetName())
     self.DrawCopy()
     canvases.update()
Example #3
0
def outro():
    'Closing stuff'
    canvases.update()
    canvases.make_plots(['png', 'eps'])

    for c in canvases.canvases:
        if c:
            w.Import(c, 'c_' + c.GetName())
    w.writeToFile(outputfile)
Example #4
0
def main():
    sw = ROOT.TStopwatch()
    sw.Start()

    init()
    get_data()

    canvases.update()
    sw.Stop()
    print 'CPU time:', sw.CpuTime(), 's, real time:', sw.RealTime(), 's'
Example #5
0
def main():
    sw = ROOT.TStopwatch()
    sw.Start()

    init()
    get_data()

    canvases.update()
    sw.Stop()
    print 'CPU time:', sw.CpuTime(), 's, real time:', sw.RealTime(), 's'
Example #6
0
def main():
    define_cuts()
    define_workspace_and_variables()
    #get_data()
    get_saved_data()
    build_model()
    beautify_response_title_and_unit()
    make_scale_dependence_plot()
    make_resolution_scan_plot()
    #plot_multiple_models()
    #plot_shape_and_fit()
    canvases.update()
Example #7
0
def main():
    ## plot_training_phoeres_with_shape_and_fit()
    ## plot_smeared_phoeres_with_fit()
    ## plot_nominal_and_smeared_mmgmass()
    #colors = [ROOT.kRed - 3,
              #ROOT.kOrange - 2,
              ## ROOT.kYellow - 7,
              #ROOT.kSpring + 5,
              #ROOT.kAzure - 9,
              #ROOT.kBlack]
    colors = [
        ROOT.kRed + 1,
        ROOT.kGreen + 2,
        #ROOT.kCyan + 1,
        ROOT.kBlue + 1,
        ROOT.kMagenta + 2,
        ROOT.kBlack,
        ]
    #canvases.wheight = 600
    #canvases.wwidth = 600
    ROOT.gStyle.SetPadLeftMargin(0.15)
    #phoERes.setBins(140)
    #plot_phoeres_with_fit_for_multiple_smearings(
        #"PhoEResScaleScan",
        #stargets = [-10, -5, 0, 5, 10][:],
        #rtargets = [2,] * 5,
        #colors = colors,
        #plotrange = (-50, 20)
        #)
    mmgMass.setBins(90)
    plot_mmgmass_with_fit_for_multiple_smearings(
        "MmgMassScaleScan",
        stargets = [-10, -5, 0, 5, 10],
        rtargets = [2,] * 5,
        colors = colors,
        )
    #phoERes.setBins(60)
    #plot_phoeres_with_fit_for_multiple_smearings(
        #"PhoEResResolutionScan",
        #stargets = [0] * 5,
        #rtargets = [1, 1.5, 2, 3, 5],
        #colors = colors,
        #plotrange = (-10, 5)
        #)
    mmgMass.setBins(40)
    plot_mmgmass_with_fit_for_multiple_smearings(
        "MmgMassResolutionScan",
        stargets = [0] * 5,
        rtargets = [1, 1.5, 2, 3, 5],
        colors = colors,
        plotrange = (75, 95),
        )
    canvases.update()
Example #8
0
def make_plots(configurations):
    """
    For each configuration in the given list, overlays the graphs of 
    scale versus pt for all sets of measurements specified.
    These measurements are either from the true or the PHOSPHOR fit.
    """
    for cfg in configurations[:]:
        ## Only check EE 2011AB
        # if (not 'EE_lowR9' in cfg.name) or (not 'AB' in cfg.name):
        # continue
        ### Only check 2011AB
        # if not 'AB' in cfg.name:
        # continue
        ## MC, EB, 2011A+B, 1 of 4 statistically independent tests
        plotter = FitResultPlotter(
            cfg.sources[0],
            cfg.getters[0],
            cfg.xtitle,
            cfg.ytitle,
            title=cfg.titles[0],
            name=cfg.name,
            xasymmerrors=True,
            yasymmerrors=True,
            colors=[ROOT.kBlack],
        )

        for isources, igetters, ititle in zip(cfg.sources, cfg.getters, cfg.titles):
            plotter.sources = isources
            plotter.getters = igetters
            plotter.title = ititle
            plotter.getdata()
            plotter.makegraph()
            plotter.graph.Fit("pol1")

        canvases.next("c_" + cfg.name).SetGrid()
        plotter.graph.Draw("ap")
        plotter.graph.GetXaxis().SetTitle(cfg.xtitle)
        plotter.graph.GetYaxis().SetTitle(cfg.ytitle)
        # if 'EE_highR9' in cfg.name:
        # plotter.plotall(title = cfg.title,
        ##xrange = (0, 10),
        ##yrange = (0, 10),
        # legend_position = 'topright')
        # else:
        # plotter.plotall(title = cfg.title,
        ##xrange = (5, 55),
        # legend_position = 'topright')
        # plotter.graphs[0].Draw('p')
        canvases.canvases[-1].Modified()
        canvases.canvases[-1].Update()
        canvases.update()
        plotters.append(plotter)
Example #9
0
def make_plots(configurations):
    '''
    For each configuration in the given list, overlays the graphs of 
    scale versus pt for all sets of measurements specified.
    These measurements are either from the true or the PHOSPHOR fit.
    '''
    for cfg in configurations[:]:
        ## Only check EE 2011AB
        #if (not 'EE_lowR9' in cfg.name) or (not 'AB' in cfg.name):
            #continue
        ### Only check 2011AB
        #if not 'AB' in cfg.name:
            #continue
        ## MC, EB, 2011A+B, 1 of 4 statistically independent tests
        plotter = FitResultPlotter(cfg.sources[0], cfg.getters[0], cfg.xtitle, 
                                   cfg.ytitle, title = cfg.titles[0],
                                   name=cfg.name, yasymmerrors=True)                          

        for isources, igetters, ititle in zip(cfg.sources, 
                                              cfg.getters, 
                                              cfg.titles):
            plotter.sources = isources
            plotter.getters = igetters
            plotter.title = ititle
            plotter.getdata()
            plotter.makegraph()
            plotter.plot()

        canvases.next('c_' + cfg.name).SetGrid()

        ## Check if there is a problem with the ranges
        # yrange = 'auto'
        yrange = (-10, 10)
        for graph in plotter.graphs:
            if (graph.GetHistogram().GetMaximum() -
                graph.GetHistogram().GetMinimum()) < 0.1:
                print cfg.name, graph.GetTitle(), 'min:', graph.GetMaximum(),
                print ', max:', graph.GetMaximum
                yrange = (-5, 10)

        plotter.plotall(title = cfg.title,
                        xrange = (5, 55),
                        yrange = yrange,
                        legend_position = 'topright')

        #plotter.graphs[0].Draw('p')
        canvases.canvases[-1].Modified()
        canvases.canvases[-1].Update()
        canvases.update()
        plotters.append(plotter)
Example #10
0
def outro(make_plots=True, save_workspace=True):
    "Closing stuff"
    canvases.update()
    if make_plots:
        canvases.make_plots(["png", "eps"])

    if save_workspace:
        for c in canvases.canvases:
            if c:
                w.Import(c, "c_" + c.GetName())
        w.writeToFile(outputfile, False)

    check_timer("14. outro")

    ct, rt = sw2.CpuTime(), sw2.RealTime()
    print "+++ TOTAL CPU time:", ct, "s, real time: %.2f" % rt, "s"
Example #11
0
def outro(make_plots=True, save_workspace=True):
    'Closing stuff'
    canvases.update()
    if make_plots:
        canvases.make_plots(['png', 'eps'])

    if save_workspace:
        for c in canvases.canvases:
            if c:
                w.Import(c, 'c_' + c.GetName())
        w.writeToFile(outputfile, False)

    check_timer('14. outro')
    
    ct, rt = sw2.CpuTime(), sw2.RealTime()
    print '+++ TOTAL CPU time:', ct, 's, real time: %.2f' % rt, 's'
Example #12
0
 def plot_quantiles(self, granularity=100):
     '''
     Plots the quantile curve.
     '''
     ## Calculate the quantiles if need be
     if not hasattr(self, 'quantiles'):
         self.get_quantiles(granularity)
     canvas = canvases.next(self.GetName() + '_quant')
     canvas.SetGrid()
     self.quantiles.Draw('al')
     ## Decorate the axis
     self.quantiles.GetXaxis().SetTitle('Fraction of %s (%%)' %
                                        self.GetYaxis().GetTitle())
     self.quantiles.GetYaxis().SetTitle(self.GetXaxis().GetTitle())
     self.quantiles.GetYaxis().SetRangeUser(10., self.quantiles.Eval(95.))
     canvases.update()
Example #13
0
 def draw_plot(self, frame):
     ## Draw the plot on a canvas
     #print "## Draw the plot on a canvas"
     canvases.wwidth = 600
     canvases.wheight = 600
     canvas = canvases.next(self.name)
     canvas.SetGrid()
     canvas.SetLeftMargin(0.15)
     canvas.SetTopMargin(0.1)
     frame.GetYaxis().SetTitleOffset(1.0)
     frame.GetYaxis().SetTitle('E_{#gamma} Resolution '
                               '#sigma_{eff}/E (%)')
     if self.yrange:
         frame.GetYaxis().SetRangeUser(*self.yrange)
     frame.Draw()
     canvas.RedrawAxis('g')
     canvases.update()
Example #14
0
 def plot_quantiles(self, granularity=100):
     '''
     Plots the quantile curve.
     '''
     ## Calculate the quantiles if need be
     if not hasattr(self, 'quantiles'):
         self.get_quantiles(granularity)
     canvas = canvases.next(self.GetName() + '_quant')
     canvas.SetGrid()
     self.quantiles.Draw('al')
     ## Decorate the axis
     self.quantiles.GetXaxis().SetTitle(
         'Fraction of %s (%%)' % self.GetYaxis().GetTitle()
         )
     self.quantiles.GetYaxis().SetTitle(self.GetXaxis().GetTitle())
     self.quantiles.GetYaxis().SetRangeUser(10., self.quantiles.Eval(95.))
     canvases.update()
Example #15
0
    def run(self):
        ## P e r f o r m   c h i 2   f i t   t o   X + / - d x   a n d   Y + / - d Y   v a l u e s
        ## ---------------------------------------------------------------------------------------

        if self.noxerrors:
            ## Fit chi^2 using Y errors only
            self.fresult = self.f.chi2FitTo(self.dxy_noxerrors,
                                            roo.YVar(self.y), roo.Save(),
                                            roo.Minos())
        else:
            ## Fit chi^2 using X and Y errors
            self.fresult = self.f.chi2FitTo(self.dxy, roo.YVar(self.y), roo.Save(),
                                            roo.Minos())
        
        self.frame = self.make_plot()                
        self.draw_plot(self.frame)
        self.decorate_plot()
        canvases.update()
def make_scale_plots(configurations):
    '''
    For each configuration in the given list, overlays the graphs of 
    scale versus pt for all sets of measurements specified.
    These measurements are either from the true or the PHOSPHOR fit.
    '''
    for cfg in configurations[:2]:
        ## Only check EE 2011AB
        #if (not 'EE_lowR9' in cfg.name) or (not 'AB' in cfg.name):
            #continue
        ### Only check 2011AB
        #if not 'AB' in cfg.name:
            #continue
        ## MC, EB, 2011A+B, 1 of 4 statistically independent tests
        plotter = FitResultPlotter(cfg.sources[1], cfg.getters_true[1], cfg.xtitle, 
                                  cfg.ytitle, title = 'MC Truth 1', name=cfg.name)                          

        for i in range(1,5):
            plotter.sources = cfg.sources[i]
            plotter.getters = cfg.getters_true[i]
            plotter.title = 'MC Truth %d' % i
            plotter.getdata()
            plotter.makegraph()

        for i in range(1,5):
            plotter.sources = cfg.sources[i]
            plotter.getters = cfg.getters_fit[i]
            plotter.title = 'MC Fit %d' % i
            plotter.getdata()
            plotter.makegraph()

        canvases.next('c_' + cfg.name).SetGrid()
        plotter.plotall(title = cfg.title,
                        xrange = (0, 80),
                        legend_position = 'topright')
        plotter.graphs[0].Draw('p')
        canvases.canvases[-1].Modified()
        canvases.canvases[-1].Update()
        canvases.update()
        plotters.append(plotter)
Example #17
0
def plot_sanity_checks(data):
    pdfname = '_'.join(['bananaPdf', data.GetName()])
    pdf = ROOT.RooNDKeysPdf(pdfname, pdfname, ROOT.RooArgList(mmMass, mmgMass),
                            data, "a", 1.5)

    canvases.next(pdf.GetName() + '_mmgMassProj')
    plot = mmgMass.frame(roo.Range(60, 120))
    data.plotOn(plot)
    pdf.plotOn(plot)
    plot.Draw()

    canvases.next(pdf.GetName() + '_mmMassProj')
    plot = mmMass.frame(roo.Range(10, 120))
    data.plotOn(plot)
    pdf.plotOn(plot)
    plot.Draw()

    canvases.next(pdf.GetName()).SetGrid()
    h_pdf = pdf.createHistogram('h_' + pdf.GetName(), mmMass,
                                roo.Binning(40, 40, 80),
                                roo.YVar(mmgMass, roo.Binning(40, 70, 110)))
    h_pdf.Draw("cont1")

    canvases.next(data.GetName()).SetGrid()
    h_data = data.createHistogram(mmMass, mmgMass, 130, 100, '',
                                  'h_' + data.GetName())
    h_data.GetXaxis().SetRangeUser(40, 80)
    h_data.GetYaxis().SetRangeUser(70, 110)
    h_data.Draw("cont1")

    canvases.next('_'.join([pdf.GetName(), 'mmgMassSlices']))
    plot = mmgMass.frame(roo.Range(60, 120))
    for mmmassval, color in zip([55, 60, 65, 70],
                                'Red Orange Green Blue'.split()):
        mmMass.setVal(mmmassval)
        color = getattr(ROOT, 'k' + color)
        pdf.plotOn(plot, roo.LineColor(color))

    plot.Draw()
    canvases.update()
Example #18
0
def main():
    sw = ROOT.TStopwatch()
    sw.Start()

    init()
    get_data()

    ## plot_sanity_checks(data)

    ## sdata = calibrator.get_smeared_data(-10, 1.5)
    ## sdata.SetName('sdata_sm10_r1p5')
    ## plot_sanity_checks(sdata)

    ## sdata = calibrator.get_smeared_data(10, 1.5)
    ## sdata.SetName('sdata_s10_r1p5')
    ## plot_sanity_checks(sdata)

    test_substituting_for_mmgMassPhoGenE()

    canvases.update()
    sw.Stop()
    print 'CPU time:', sw.CpuTime(), 's, real time:', sw.RealTime(), 's'
Example #19
0
def main():
    ## plot_training_phoeres_with_shape_and_fit()
    ## plot_smeared_phoeres_with_fit()
    ## plot_nominal_and_smeared_mmgmass()
    colors = [ROOT.kRed - 3,
              ROOT.kOrange - 2,
              # ROOT.kYellow - 7,
              ROOT.kSpring + 5,
              ROOT.kAzure - 9,
              ROOT.kBlack]
    plot_phoeres_with_fit_for_multiple_smearings(
        "PhoEResScaleScan",
        stargets = [-10, -5, 0, 5, 10],
        rtargets = [2,] * 5,
        colors = colors,
        plotrange = (-50, 20)
        )
    plot_mmgmass_with_fit_for_multiple_smearings(
        "MmgMassScaleScan",
        stargets = [-10, -5, 0, 5, 10],
        rtargets = [2,] * 5,
        colors = colors,
        )
    plot_phoeres_with_fit_for_multiple_smearings(
        "PhoEResResolutionScan",
        stargets = [0] * 5,
        rtargets = [1, 2, 3, 5, 10],
        colors = colors,
        plotrange = (-30, 10)
        )
    plot_mmgmass_with_fit_for_multiple_smearings(
        "MMGMassResolutionScan",
        stargets = [0] * 5,
        rtargets = [1, 2, 3, 5, 10],
        colors = colors,
        )
    canvases.update()
Example #20
0
tdata.plotOn(plot)
pdf.plotOn(plot)
plot.Draw()
Latex(
    [
        's_{true}: %.3f #pm %.3f %%' % (calibrator.s.getVal(),
                                        calibrator.s.getError()),
        ## 's_{fit}: %.3f #pm %.3f %%' % (phoScale.getVal(),
        ##                                phoScale.getError()),
        'r_{true}: %.3f #pm %.3f %%' % (calibrator.r.getVal(),
                                        calibrator.r.getError()),
        'r_{fit}: %.3f ^{+%.3f}_{%.3f} %%' % (phoRes.getVal(),
                                                 phoRes.getErrorHi(),
                                                 phoRes.getErrorLo()),
        ],
    position=(0.2, 0.8)
    ).draw()

canvases.next('test_nll').SetGrid()
nll = pdf.createNLL(tdata, roo.Range(60, 120))
rframe = phoRes.frame(roo.Range(phoRes.getVal() + 3*phoRes.getErrorLo(),
                                phoRes.getVal() + 3*phoRes.getErrorHi()))
nll.plotOn(rframe, roo.ShiftToZero())
rframe.Draw()

canvases.update()
if __name__ == '__main__':
    # main()
    import user
    
Example #21
0
def main():
    plot_training_phoeres_with_shape_and_fit()
    plot_smeared_phoeres_with_fit()
    plot_nominal_and_smeared_mmgmass()
    canvases.update()
Example #22
0
plot.Draw()
Latex([
    's_{shape}: %.3f %%' % t2pdf.s0val,
    's_{fit}: %.3f #pm %.3f %%' % (phoScale.getVal(), phoScale.getError()),
    's_{fit} - s_{shape}: %.4f #pm %.4f %%' % (
        phoScale.getVal() - t2pdf.s0val,
        phoScale.getError()
        ),
    'r_{shape}: %.3f %%' % t2pdf.r0val,
    'r_{fit}: %.3f #pm %.3f %%' % (phoRes.getVal(), phoRes.getError()),
    'r_{fit}/r_{shape}: %.4f #pm %.4f' % (
        phoRes.getVal() / t2pdf.r0val,
        phoRes.getError() / t2pdf.r0val),
    ], position=(0.2, 0.75)).draw()

canvases.update()

t.setRange(*t1range)
xtpdf.fitTo(xtdata, roo.NumCPU(8), roo.Verbose(True), roo.Timer(True),
            roo.SumW2Error(True), roo.Minos(ROOT.RooArgSet(phoRes)))

## Plot fXT(t|s,r) fitted to data
## canvases.next('tpdf').SetGrid()
## t.setRange(5, 10)
## t.SetTitle('log(m_{#mu#mu#gamma}^{2} - m_{#mu#mu}^{2})')
## tpdf.fitTo(tdata, roo.Range(5.5, 9.5))
## plot = t.frame(roo.Range(6, 9))
## tdata.plotOn(plot)
## tpdf.plotOn(plot)
## tpdf.paramOn(plot)
## plot.Draw()