Exemple #1
0
def make_qqplots(ux, uy):
    xyplot = uy.xvar.frame()
    xyplot.SetTitle("")
    xycorr = QQCorrector(ux.xvar, ux.xpdf, uy.xvar, uy.xpdf)
    xycorr.SetName("y")
    ux.data.addColumn(xycorr)
    uy.data.plotOn(xyplot, roo.LineColor(uy.color), roo.MarkerColor(uy.color))
    uy.xpdf.plotOn(xyplot, roo.LineColor(uy.color))
    ux.data.plotOn(xyplot, roo.LineColor(ux.color), roo.MarkerColor(ux.color))

    yxplot = ux.xvar.frame()
    yxplot.SetTitle("")
    yxcorr = QQCorrector(uy.xvar, uy.xpdf, ux.xvar, ux.xpdf)
    yxcorr.SetName("x")
    uy.data.addColumn(yxcorr)
    ux.data.plotOn(yxplot, roo.LineColor(ux.color), roo.MarkerColor(ux.color))
    ux.xpdf.plotOn(yxplot, roo.LineColor(ux.color))
    uy.data.plotOn(yxplot, roo.LineColor(uy.color), roo.MarkerColor(uy.color))

    canvases.next("qqxy")
    xyplot.Draw()

    canvases.next("qqyx")
    yxplot.Draw()

    return xyplot, yxplot
Exemple #2
0
def main():
    '''This is the entry point to execution.'''
    print 'Welcome to test_pkeys - test of the mode and effective sigma'
    print 'extraction for a generic distribution using ParametrizedKeysPdf.'

    w = ROOT.RooWorkspace('w', 'w')

    truepdf = w.factory('Gaussian::truepdf(x[-5,5],m[0],s[1])')
    data = truepdf.generate(ROOT.RooArgSet(w.var('x')), 10000)
    canvases.next('truepdf')
    plot = w.var('x').frame()
    data.plotOn(plot)
    truepdf.plotOn(plot)
    plot.Draw()

    toypdf = ParameterizedKeysPdf('toypdf',
                                  'toypdf',
                                  w.var('x'),
                                  w.factory('mtoy[0,-5,5]'),
                                  w.factory('stoy[1,0.1,5]'),
                                  data,
                                  rho=3)
    toypdf.shape.plotOn(plot, roo.LineColor(ROOT.kRed))
    toypdf.fitTo(data)
    toypdf.plotOn(plot, roo.LineColor(ROOT.kGreen))
    plot.Draw()

    canvases.update()
    print 'Exiting test_pkeys with success!'
Exemple #3
0
 def plot_inverse_transform(self):
     """
     Create a canvas showing the inverse of the transform.
     """
     if not self.tplot:
         self.make_tplot()
     tcurve = self.tplot.getCurve()
     self.itgraph = ROOT.TGraph(tcurve.GetN(), tcurve.GetY(), tcurve.GetX())
     self.itgraph.Sort()
     cname = "_".join([self.uniform_var.GetName(), "to", self.xvar.GetName(), "transform"])
     indexes = range(1, self.itgraph.GetN())
     indexes.reverse()
     for i in indexes:
         # print "i=", i, "x=", self.itgraph.GetX()[i],
         # print  "y=", self.itgraph.GetY()[i]
         if self.itgraph.GetX()[i] <= self.itgraph.GetX()[i - 1]:
             print "Removing point", i, "of", cname
             self.itgraph.RemovePoint(i)
     canvases.next(cname).SetGrid()
     self.itgraph.SetLineWidth(3)
     self.itgraph.SetLineColor(self.color)
     self.itgraph.SetTitle("")
     self.itgraph.Draw("ac")
     xtitle = self.uniform_var.GetTitle().replace("(" + self.xvar.GetTitle() + ")", "")
     ytitle = self.xvar.GetTitle() + "(" + xtitle + ")"
     self.itgraph.GetXaxis().SetTitle(xtitle)
     self.itgraph.GetYaxis().SetTitle(ytitle)
Exemple #4
0
def main():
    '''
    RooWorkspace main()
    This is the entry point of execution.  Returns a workspace with the results
    '''
    ntoys = 500
    wlist = []    
    for i in range(ntoys):
        w = ROOT.RooWorkspace('w%d' % i, 
                              'Per-bin p-value toy %d' % i)
        setup_model(w)
        generate_events(w)    
        calculate_pvalue_graph(w)
        make_pvalue_hist(w)        
        wlist.append(w)
   
    pvalue_hist_tot = wlist[0].obj('pvalue_hist').Clone('pvalue_hist_tot')
    for w in wlist[1:]:
        pvalue_hist_tot.Add( w.obj('pvalue_hist') )
        
    plot_all(wlist[0])

    canvases.next('pvalue_hist_tot')
    pvalue_hist_tot.Draw('e0')
    canvases.update()
    
    return wlist, pvalue_hist_tot    
Exemple #5
0
def main():
    '''This is the entry point to execution.'''
    print 'Welcome to test_pkeys - test of the mode and effective sigma'
    print 'extraction for a generic distribution using ParametrizedKeysPdf.'
    
    w = ROOT.RooWorkspace('w', 'w')
    
    truepdf = w.factory('Gaussian::truepdf(x[-5,5],m[0],s[1])')
    data = truepdf.generate(ROOT.RooArgSet(w.var('x')), 10000)
    canvases.next('truepdf')
    plot = w.var('x').frame()
    data.plotOn(plot)
    truepdf.plotOn(plot)
    plot.Draw()
    
    toypdf = ParameterizedKeysPdf('toypdf', 'toypdf', w.var('x'), 
                                  w.factory('mtoy[0,-5,5]'), 
                                  w.factory('stoy[1,0.1,5]'), data, rho=3)
    toypdf.shape.plotOn(plot, roo.LineColor(ROOT.kRed))
    toypdf.fitTo(data)
    toypdf.plotOn(plot, roo.LineColor(ROOT.kGreen))
    plot.Draw()
        
    
    canvases.update()
    print 'Exiting test_pkeys with success!'
Exemple #6
0
def main():
    '''
    RooWorkspace main()
    This is the entry point of execution.  Returns a workspace with the results
    '''
    ntoys = 500
    wlist = []
    for i in range(ntoys):
        w = ROOT.RooWorkspace('w%d' % i, 'Per-bin p-value toy %d' % i)
        setup_model(w)
        generate_events(w)
        calculate_pvalue_graph(w)
        make_pvalue_hist(w)
        wlist.append(w)

    pvalue_hist_tot = wlist[0].obj('pvalue_hist').Clone('pvalue_hist_tot')
    for w in wlist[1:]:
        pvalue_hist_tot.Add(w.obj('pvalue_hist'))

    plot_all(wlist[0])

    canvases.next('pvalue_hist_tot')
    pvalue_hist_tot.Draw('e0')
    canvases.update()

    return wlist, pvalue_hist_tot
Exemple #7
0
def make_qqplots(ux, uy):
    xyplot = uy.xvar.frame()
    xyplot.SetTitle('')
    xycorr = QQCorrector(ux.xvar, ux.xpdf, uy.xvar, uy.xpdf)
    xycorr.SetName('y')
    ux.data.addColumn(xycorr)
    uy.data.plotOn(xyplot, roo.LineColor(uy.color), roo.MarkerColor(uy.color))
    uy.xpdf.plotOn(xyplot, roo.LineColor(uy.color))
    ux.data.plotOn(xyplot, roo.LineColor(ux.color), roo.MarkerColor(ux.color))

    yxplot = ux.xvar.frame()
    yxplot.SetTitle('')
    yxcorr = QQCorrector(uy.xvar, uy.xpdf, ux.xvar, ux.xpdf)
    yxcorr.SetName('x')
    uy.data.addColumn(yxcorr)
    ux.data.plotOn(yxplot, roo.LineColor(ux.color), roo.MarkerColor(ux.color))
    ux.xpdf.plotOn(yxplot, roo.LineColor(ux.color))
    uy.data.plotOn(yxplot, roo.LineColor(uy.color), roo.MarkerColor(uy.color))

    canvases.next('qqxy')
    xyplot.Draw()

    canvases.next('qqyx')
    yxplot.Draw()

    return xyplot, yxplot
def make_comparison_plot(data_raw, data_target, x_corr):
    '''
    Plot x data with the overlayed fitted model.
    '''
    data_corr = get_corrected_data(data_raw, x_corr)
    # global plot
    if plot_range:
        plot = x.frame(roo.Range(*plot_range))
    else:
        plot = x.frame()
    plot.SetTitle('Raw (red) vs Corrected (blue) vs Target (black) Data')
    if b_corr.getVal() > 1.:
        data_raw.plotOn(plot, roo.LineColor(ROOT.kRed), 
                        roo.MarkerColor(ROOT.kRed))
        data_corr.plotOn(plot, roo.LineColor(ROOT.kBlue), 
                         roo.MarkerColor(ROOT.kBlue))
        data_target.plotOn(
          plot, 
          roo.Rescale(data_raw.sumEntries() / data_target.sumEntries())
          )
    else:
        data_target.plotOn(plot)
        data_raw.plotOn(
            plot, roo.LineColor(ROOT.kRed), roo.MarkerColor(ROOT.kRed),
            roo.Rescale(data_target.sumEntries() / data_raw.sumEntries())
            )
        data_corr.plotOn(
            plot, roo.LineColor(ROOT.kBlue), roo.MarkerColor(ROOT.kBlue),
            roo.Rescale(data_target.sumEntries() / data_corr.sumEntries())
            )
        
    canvases.next('Raw_vs_Corrected_vs_Target_Data').SetGrid()
    plot.Draw()
    canvases.update()
Exemple #9
0
 def plot_inverse_transform(self):
     '''
     Create a canvas showing the inverse of the transform.
     '''
     if not self.tplot:
         self.make_tplot()
     tcurve = self.tplot.getCurve()
     self.itgraph = ROOT.TGraph(tcurve.GetN(), tcurve.GetY(), tcurve.GetX())
     self.itgraph.Sort()
     cname = '_'.join([
         self.uniform_var.GetName(), 'to',
         self.xvar.GetName(), 'transform'
     ])
     indexes = range(1, self.itgraph.GetN())
     indexes.reverse()
     for i in indexes:
         #print "i=", i, "x=", self.itgraph.GetX()[i],
         #print  "y=", self.itgraph.GetY()[i]
         if self.itgraph.GetX()[i] <= self.itgraph.GetX()[i - 1]:
             print 'Removing point', i, 'of', cname
             self.itgraph.RemovePoint(i)
     canvases.next(cname).SetGrid()
     self.itgraph.SetLineWidth(3)
     self.itgraph.SetLineColor(self.color)
     self.itgraph.SetTitle('')
     self.itgraph.Draw("ac")
     xtitle = self.uniform_var.GetTitle().replace(
         "(" + self.xvar.GetTitle() + ")", "")
     ytitle = self.xvar.GetTitle() + "(" + xtitle + ")"
     self.itgraph.GetXaxis().SetTitle(xtitle)
     self.itgraph.GetYaxis().SetTitle(ytitle)
Exemple #10
0
 def make_width_profiles_plot(self):
     canvases.next(self.name + '_width_profiles').SetGrid()
     self.widths[0].graph.SetLineColor(ROOT.kRed)
     self.widths[0].graph.Draw('al')
     self.widths[1].graph.Draw('l')
     graphs = [w.graph for w in self.widths]
     titles = [x.GetTitle() for x in self.variables]
     Legend(graphs, titles, opt='l').draw()
Exemple #11
0
 def make_width_profiles_plot(self):
     canvases.next(self.name + '_width_profiles').SetGrid()
     self.widths[0].graph.SetLineColor(ROOT.kRed)
     self.widths[0].graph.Draw('al')
     self.widths[1].graph.Draw('l')
     graphs = [w.graph for w in self.widths]
     titles = [x.GetTitle() for x in self.variables]
     Legend(graphs, titles, opt = 'l').draw()
Exemple #12
0
def make_uuplot(ux, uy):
    plot = ux.uniform_var.frame()
    ux.data.plotOn(plot, roo.LineColor(ux.color), roo.MarkerColor(ux.color))
    ux.uniform_pdf.plotOn(plot, roo.LineColor(ux.color), roo.Range(0, 1))
    uy.uniform_pdf.plotOn(plot, roo.LineColor(uy.color), roo.Range(0, 1), roo.LineStyle(ROOT.kDashed))
    uy.data.plotOn(plot, roo.LineColor(uy.color), roo.MarkerColor(uy.color), roo.MarkerStyle(4))
    canvases.next("uu")
    plot.Draw()
    return plot
Exemple #13
0
 def plot_transform(self):
     '''
     Create a canvas showing the transform.
     '''
     self.make_tplot()
     canvases.next(self.xvar.GetTitle() + '_transform').SetGrid()
     self.tplot.SetTitle('')
     self.tplot.GetYaxis().SetTitle(self.uniform_var.GetTitle())
     self.tplot.Draw()
Exemple #14
0
 def plot_transform(self):
     """
     Create a canvas showing the transform.
     """
     self.make_tplot()
     canvases.next(self.xvar.GetTitle() + "_transform").SetGrid()
     self.tplot.SetTitle("")
     self.tplot.GetYaxis().SetTitle(self.uniform_var.GetTitle())
     self.tplot.Draw()
Exemple #15
0
 def plot_x(self):
     """
     Create a canvas with x data overlayed with its PDF.
     """
     self.xplot = self.xvar.frame()
     self.data.plotOn(self.xplot, roo.LineColor(self.color), roo.MarkerColor(self.color))
     self.xpdf.plotOn(self.xplot, roo.LineColor(self.color))
     canvases.next(self.xvar.GetTitle()).SetGrid()
     self.xplot.SetTitle("")
     self.xplot.Draw()
Exemple #16
0
 def plot_x(self):
     '''
     Create a canvas with x data overlayed with its PDF.
     '''
     self.xplot = self.xvar.frame()
     self.data.plotOn(self.xplot, roo.LineColor(self.color),
                      roo.MarkerColor(self.color))
     self.xpdf.plotOn(self.xplot, roo.LineColor(self.color))
     canvases.next(self.xvar.GetTitle()).SetGrid()
     self.xplot.SetTitle('')
     self.xplot.Draw()
Exemple #17
0
def make_uuplot(ux, uy):
    plot = ux.uniform_var.frame()
    ux.data.plotOn(plot, roo.LineColor(ux.color), roo.MarkerColor(ux.color))
    ux.uniform_pdf.plotOn(plot, roo.LineColor(ux.color), roo.Range(0, 1))
    uy.uniform_pdf.plotOn(plot, roo.LineColor(uy.color), roo.Range(0, 1),
                          roo.LineStyle(ROOT.kDashed))
    uy.data.plotOn(plot, roo.LineColor(uy.color), roo.MarkerColor(uy.color),
                   roo.MarkerStyle(4))
    canvases.next('uu')
    plot.Draw()
    return plot
Exemple #18
0
 def plot_uniform(self):
     """
     Create a canvas with transformed x data overlayed with a uniform pdf.
     """
     self.uplot = self.uniform_var.frame()
     self.data.plotOn(self.uplot, roo.LineColor(self.color), roo.MarkerColor(self.color))
     self.uniform_pdf.plotOn(self.uplot, roo.Range(0, 1), roo.LineColor(self.color))
     cname = "_".join([self.uniform_var.GetName(), "of", self.xvar.GetName()])
     canvases.next(cname).SetGrid()
     self.uplot.SetTitle("")
     self.uplot.Draw()
def make_plot(x, data, model):
    '''
    Plot x data with the overlayed fitted model.
    '''
    global plot
    plot = x.frame()
    data.plotOn(plot)
    model.plotOn(plot)
    model.paramOn(plot)
    canvases.next(workspace)
    plot.Draw()
    canvases.update()
def make_plot(x, data, model, name=name):
    '''
    Plot x data with the overlayed fitted model.
    '''
    global plot
    plot = x.frame(roo.Range('plot'))
    data.plotOn(plot)
    model.plotOn(plot)
    model.paramOn(plot)
    canvases.next(name)
    plot.Draw()
    canvases.update()
def make_plot(x, data, model):
    '''
    Plot x data with the overlayed fitted model.
    '''
    global plot
    plot = x.frame()
    data.plotOn(plot)
    model.plotOn(plot)
    model.paramOn(plot)
    canvases.next(workspace)
    plot.Draw()
    canvases.update()
Exemple #22
0
 def make_width_ratio_plot(self):
     canvases.next(self.name + '_width_ratio').SetGrid()        
     self.copy_axes_titles(self.width_ratio, self.errors_rms)
     #self.errors_rms.GetXaxis().SetTitle(self.width_ratio.GetXaxis().GetTitle())
     #self.errors_rms.GetYaxis().SetTitle(self.width_ratio.GetYaxis().GetTitle())
     self.errors_rms.SetFillColor(ROOT.kGreen)
     #self.errors_rms.GetYaxis().SetRangeUser(0.9, 1.1)
     #self.errors_rms.GetXaxis().SetRangeUser(0.05, 0.95)
     self.errors_rms.DrawCopy('E4')
     self.errors_rms.SetFillColor(ROOT.kWhite)
     self.errors_rms.DrawCopy('HIST L SAME')
     self.width_ratio.SetLineColor(ROOT.kRed)
     self.width_ratio.Draw('L')        
Exemple #23
0
 def make_width_ratio_plot(self):
     canvases.next(self.name + '_width_ratio').SetGrid()
     self.copy_axes_titles(self.width_ratio, self.errors_rms)
     #self.errors_rms.GetXaxis().SetTitle(self.width_ratio.GetXaxis().GetTitle())
     #self.errors_rms.GetYaxis().SetTitle(self.width_ratio.GetYaxis().GetTitle())
     self.errors_rms.SetFillColor(ROOT.kGreen)
     #self.errors_rms.GetYaxis().SetRangeUser(0.9, 1.1)
     #self.errors_rms.GetXaxis().SetRangeUser(0.05, 0.95)
     self.errors_rms.DrawCopy('E4')
     self.errors_rms.SetFillColor(ROOT.kWhite)
     self.errors_rms.DrawCopy('HIST L SAME')
     self.width_ratio.SetLineColor(ROOT.kRed)
     self.width_ratio.Draw('L')
Exemple #24
0
def drawhistos():
    global hx, hy, hz, hmean, hxd, hmeand, hw, hwm, hxw, hyw, hzw, hxwm 
    global hywm, hzwm, hxy, hxz, hyz

    for hist in [hx, hy, hz, hmean, hxd, hmeand, hw, hwm, hxw, hyw, hzw, hxwm, 
                 hywm, hzwm]:
        canvases.next(hist.GetName())
        hist.Draw()
    
    for hist in [hxy, hxz, hyz]:
        canvases.next(hist.GetName())
        hist.Draw('colz')
    
    canvases.next('ioverlay')
    hxd.Draw()
    hxw.Draw('same')
    hyw.Draw('same')
    hzw.Draw('same')
    
    canvases.next('moverlay')
    hxd.Draw()
    hxwm.Draw('same')
    hywm.Draw('same')
    hzwm.Draw('same')

    canvases.update()
Exemple #25
0
def drawhistos():
    global hx, hy, hz, hmean, hxd, hmeand, hw, hwm, hxw, hyw, hzw, hxwm
    global hywm, hzwm, hxy, hxz, hyz

    for hist in [
            hx, hy, hz, hmean, hxd, hmeand, hw, hwm, hxw, hyw, hzw, hxwm, hywm,
            hzwm
    ]:
        canvases.next(hist.GetName())
        hist.Draw()

    for hist in [hxy, hxz, hyz]:
        canvases.next(hist.GetName())
        hist.Draw('colz')

    canvases.next('ioverlay')
    hxd.Draw()
    hxw.Draw('same')
    hyw.Draw('same')
    hzw.Draw('same')

    canvases.next('moverlay')
    hxd.Draw()
    hxwm.Draw('same')
    hywm.Draw('same')
    hzwm.Draw('same')

    canvases.update()
def make_plot(x, data, model, name=name, title=name):
    '''
    Plot x data with the overlayed fitted model.
    '''
    global plot
    x.setBins(30)
    plot = x.frame(roo.Range('plot'))
    plot.SetTitle(title)
    data.plotOn(plot)
    model.plotOn(plot, roo.Range('plot'), roo.NormRange('plot'))
    #model.paramOn(plot)
    canvases.next(name)
    plot.Draw()
    canvases.update()
Exemple #27
0
 def plot_uniform(self):
     '''
     Create a canvas with transformed x data overlayed with a uniform pdf.
     '''
     self.uplot = self.uniform_var.frame()
     self.data.plotOn(self.uplot, roo.LineColor(self.color),
                      roo.MarkerColor(self.color))
     self.uniform_pdf.plotOn(self.uplot, roo.Range(0, 1),
                             roo.LineColor(self.color))
     cname = '_'.join(
         [self.uniform_var.GetName(), 'of',
          self.xvar.GetName()])
     canvases.next(cname).SetGrid()
     self.uplot.SetTitle('')
     self.uplot.Draw()
Exemple #28
0
def main():
    '''
    Main entry point of execution.
    '''
    global workspaces
    workspaces = get_workspaces()
    plots = []
    global period, category
    for period in '7TeV 8TeV'.split():
        for category in get_categories(period):
            fit_model(category, period)
            plot = make_plot(category, period)
            canvases.next('_'.join([category, period]))
            plot.Draw()
            plots.append(plot)
Exemple #29
0
def plot_model_and_data_overlayed(w):
    '''
    void plot_model_and_data_overlayed(w)
    
    Plots model `gaus' and dataset `data' overlayed on top of each other.
    
    Preconditions: Model and data are present in the given workspace w.
    
    Postconditions: A canvas `Gaussian_PDF_with_data' is created and displayed.
    '''
    xframe = get_plot_of_data_overlayed_with_model(w)

    ## Create a canvas and draw the plot frame on it.
    canvases.next('Gaussian_PDF_with_data')
    xframe.Draw()
Exemple #30
0
def plot_model_and_data_overlayed(w):
    '''
    void plot_model_and_data_overlayed(w)
    
    Plots model `gaus' and dataset `data' overlayed on top of each other.
    
    Preconditions: Model and data are present in the given workspace w.
    
    Postconditions: A canvas `Gaussian_PDF_with_data' is created and displayed.
    '''
    xframe = get_plot_of_data_overlayed_with_model(w)

    ## Create a canvas and draw the plot frame on it.
    canvases.next('Gaussian_PDF_with_data')
    xframe.Draw()
def make_plot(x, data, model):
    '''
    Plot x data with the overlayed fitted model.
    '''
    # global plot
    if plot_range:
        plot = x.frame(roo.Range(*plot_range), roo.Title(data.GetName()))
    else:
        plot = x.frame(roo.Title(data.GetName()))
    data.plotOn(plot)
    model.plotOn(plot)
    model.paramOn(plot)
    canvases.next(data.GetName()).SetGrid()
    plot.Draw()
    canvases.update()
    def makeplot(self):
        '''Produces a canvas with a plot. Assumes configuration 
        Data is present.'''
        self.sourcepath = os.path.join(basepath, 
                                       self.sourcedir, 
                                       self.sourcefilename)
        self.source = ROOT.TFile.Open(self.sourcepath)
        histo = self.source.Get(self.sourcehistoname).Clone()
        ## Set the titles
        for obj, txt in [(histo           , self.title ),
                         (histo.GetXaxis(), self.xtitle), 
                         (histo.GetYaxis(), self.ytitle)]:
            obj.SetTitle(txt)

        histo.SetStats(False)

        self.canvas = canvases.next(self.name)
        histo.DrawCopy('colz')
        self.histo = self.canvas.GetListOfPrimitives().FindObject(
            histo.GetName()
            )
        self.histo.GetZaxis().SetRangeUser(0.9, 1.0)
        Latex([self.leftlabel], (0.15, 0.92), textsize=25).draw()
        Latex([self.rightlabel], (0.615, 0.92), textsize=25).draw()

        canvases.update()
    def make_fixed_range_log_plot(self):
        c1 = canvases.next(self.name + "_log_fixedrange")
        c1.SetGrid()
        c1.SetLogy()
        self.canvases.append(c1)

        ## Use the ModalInterval class to display the shortest range containing
        ## 100% of all the entries.
        mi = self.modal_interval
        mi.setFraction(1)

        fullrange = (mi.lowerBound(), mi.upperBound())
        plot = self.deltaE.frame(roo.Range(*self.fixed_range_log))
        plot.SetTitle(", ".join(self.labels))
        self.fit_data.plotOn(
            plot, roo.MarkerColor(self.color_data), roo.MarkerStyle(self.marker_style), roo.LineColor(self.color_data)
        )
        self.model.plotOn(plot, roo.LineColor(self.color_model))
        if fullrange[0] + fullrange[1] > 0:
            layout = (0.6, 0.9, 0.87)
        else:
            layout = (0.2, 0.5, 0.87)
        self.model.paramOn(plot, roo.Format("NEU", roo.AutoPrecision(2)), roo.Layout(*layout))
        ## Fine tune the y-axis range so that we see all the events.
        plot.SetMinimum(0.5)
        ## Add a larger top margin to the y-axis range
        plot.SetMaximum(pow(plot.GetMaximum(), 1.1))
        plot.Draw()
        self.plots.append(plot)
Exemple #34
0
    def make_fixed_range_log_plot(self):
        c1 = canvases.next(self.name + '_log_fixedrange')
        c1.SetGrid()
        c1.SetLogy()
        self.canvases.append(c1)

        ## Use the ModalInterval class to display the shortest range containing
        ## 100% of all the entries.
        mi = self.modal_interval
        mi.setFraction(1)

        fullrange = (mi.lowerBound(), mi.upperBound())
        plot = self.deltaE.frame(roo.Range(*self.fixed_range_log))
        plot.SetTitle(', '.join(self.labels))
        self.fit_data.plotOn(plot, roo.MarkerColor(self.color_data),
                             roo.MarkerStyle(self.marker_style),
                             roo.LineColor(self.color_data))
        self.model.plotOn(plot, roo.LineColor(self.color_model))
        if fullrange[0] + fullrange[1] > 0:
            layout = (0.6, 0.9, 0.87)
        else:
            layout = (0.2, 0.5, 0.87)
        self.model.paramOn(plot, roo.Format("NEU", roo.AutoPrecision(2)),
                           roo.Layout(*layout))
        ## Fine tune the y-axis range so that we see all the events.
        plot.SetMinimum(0.5)
        ## Add a larger top margin to the y-axis range
        plot.SetMaximum(pow(plot.GetMaximum(), 1.1))
        plot.Draw()
        self.plots.append(plot)
Exemple #35
0
 def makeplot(self):
     self.canvas = canvases.next()
     self.plot = self.x.frame()
     self.data.plotOn(self.plot)
     self.model.plotOn(self.plot)
     self.model.paramOn(self.plot)
     self.plot.Draw()
     self.canvas.Update()
Exemple #36
0
    def plot_variable(self, varname, selection='', label='', title=''):
        '''
        Makes a canvas of the variable spectrum for MC overlayed with data.
        Uses binning named "plot" unless binning of the same name as title
        exists which is then used.
        '''

        hvar = self.w.var(varname)

        if hvar.hasBinning(title):
            hbins = hvar.getBinning(title)
        else:
            hbins = hvar.getBinning('plot')

        if label:
            name = '_'.join([hvar.GetName(), label])
        else:
            name = hvar.GetName()
            
        ## Book the histograms
        htitle = '%s;%s;Events / %g %s' % (title, hvar.GetTitle(),
                                           hbins.averageBinWidth(),
                                           hvar.getUnit())
        
        hmc = ROOT.TH1F('hmc_' + name, htitle, hbins.numBins(), hbins.array())
        hdata = hmc.Clone('hdata_' + name)

        ## Make sure we use PU weights.
        if selection:
            selection = 'weight * (%s)' % selection
        else:
            selection = 'weight'
            
        ## Fill the histograms
        for source, hist in [('mc', hmc), ('data', hdata)]:
            # hist.Sumw2()
            hist.SetStats(0)
            expression = hvar.GetName() + '>>' + hist.GetName()
            self.w.data(source).tree().Draw(expression, selection, 'goff')

        ## Normalize mc to data.
        hmc.Scale(hdata.Integral() / hmc.Integral())

        ## Add the histograms to the workspace
        self.w.Import(hmc)
        self.w.Import(hdata)

        hmc = self.w.obj(hmc.GetName())
        hdata = self.w.obj(hdata.GetName())

        ## Make the canvas
        canvas = canvases.next('c_' + name)
        canvas.SetGrid()
        hmc.Draw('hist')
        hdata.Draw('same e0')
        self.draw_legend({hdata: 'Data', hmc: 'Simulation'})

        self.w.Import(canvas, canvas.GetName())
Exemple #37
0
    def plot_variable(self, varname, selection='', label='', title=''):
        '''
        Makes a canvas of the variable spectrum for MC overlayed with data.
        Uses binning named "plot" unless binning of the same name as title
        exists which is then used.
        '''

        hvar = self.w.var(varname)

        if hvar.hasBinning(title):
            hbins = hvar.getBinning(title)
        else:
            hbins = hvar.getBinning('plot')

        if label:
            name = '_'.join([hvar.GetName(), label])
        else:
            name = hvar.GetName()

        ## Book the histograms
        htitle = '%s;%s;Events / %g %s' % (
            title, hvar.GetTitle(), hbins.averageBinWidth(), hvar.getUnit())

        hmc = ROOT.TH1F('hmc_' + name, htitle, hbins.numBins(), hbins.array())
        hdata = hmc.Clone('hdata_' + name)

        ## Make sure we use PU weights.
        if selection:
            selection = 'weight * (%s)' % selection
        else:
            selection = 'weight'

        ## Fill the histograms
        for source, hist in [('mc', hmc), ('data', hdata)]:
            # hist.Sumw2()
            hist.SetStats(0)
            expression = hvar.GetName() + '>>' + hist.GetName()
            self.w.data(source).tree().Draw(expression, selection, 'goff')

        ## Normalize mc to data.
        hmc.Scale(hdata.Integral() / hmc.Integral())

        ## Add the histograms to the workspace
        self.w.Import(hmc)
        self.w.Import(hdata)

        hmc = self.w.obj(hmc.GetName())
        hdata = self.w.obj(hdata.GetName())

        ## Make the canvas
        canvas = canvases.next('c_' + name)
        canvas.SetGrid()
        hmc.Draw('hist')
        hdata.Draw('same e0')
        self.draw_legend({hdata: 'Data', hmc: 'Simulation'})

        self.w.Import(canvas, canvas.GetName())
Exemple #38
0
def plot_all_throughputs_overlaid():
    canvases.next('Overlaid').SetGrid()
    tree.Draw('read + write : 5 * (i + 1)')
    graph_total = customize(beautify(get_graph()),
                            ytitle = 'Cluster Filesystem Throughput (Gb/s)',
                            yrange = (0,11))
    tree.Draw('read : 5 * (i + 1)')
    graph_read = customize(beautify(get_graph()), color = ROOT.kBlue)
    tree.Draw('write : 5 * (i + 1)')
    graph_write = customize(beautify(get_graph()), color = ROOT.kRed)
    graph_total.Draw('alp')
    graph_read.Draw('lp')
    graph_write.Draw('lp')
    gstack = [graph_total, graph_write, graph_read]
    titles = ['Aggregate (%.1f #pm %.1f)' % get_mean_rms('read + write'),
              'Reading (%.1f #pm %.1f)' % get_mean_rms('read'),
              'Writing (%.1f #pm %.1f)' % get_mean_rms('write')]
    Legend(gstack, titles, position = (0.5, 0.9, 0.92, 0.7)).draw()
    graphs.extend(gstack)
Exemple #39
0
def test_downsampling():
    '''
    Tests the downsampling.
    '''
    import FWLite.Tools.canvases as canvases
    print '== Downsampling Test =='
    big_data = get_toy_data(1000)
    resampler = Resampler(big_data)
    small_data = resampler.downsample(50)
    keep(big_data, small_data)
    big_data.Print()
    small_data.Print()

    xvar = big_data.get()['x']
    xvar.setBins(20)
    plot = xvar.frame()
    big_data.plotOn(plot, roo.MarkerColor(ROOT.kRed), roo.LineColor(ROOT.kRed))
    small_data.plotOn(plot, roo.MarkerStyle(24))
    canvases.next('downsampling_test')
    plot.Draw()
    keep(plot)
Exemple #40
0
def plot_model_and_change_parameter_values(w):
    '''
    void plot_model_and_change_parameter_values(w)
    
    Plots model `gaus' and changes the parameter values.
    '''
    ## Construct plot frame in 'x'
    xframe = w.var('x').frame(roo.Title('Gaussian PDF'))
    
    ## Plot gauss in frame (i.e. in x).
    w.pdf('gauss').plotOn(xframe)
    
    ## Change the value of sigma to 3.
    w.var('sigma').setVal(3)
    
    ## Plot gauss in frame (i.e. in x) and draw frame on canvases.
    w.pdf('gauss').plotOn(xframe, roo.LineColor(ROOT.kRed))
    
    ## Create a canvas and draw the plot frame on it.
    canvases.next('Gaussian_PDF')
    xframe.Draw()
Exemple #41
0
def plot_model_and_change_parameter_values(w):
    '''
    void plot_model_and_change_parameter_values(w)
    
    Plots model `gaus' and changes the parameter values.
    '''
    ## Construct plot frame in 'x'
    xframe = w.var('x').frame(roo.Title('Gaussian PDF'))

    ## Plot gauss in frame (i.e. in x).
    w.pdf('gauss').plotOn(xframe)

    ## Change the value of sigma to 3.
    w.var('sigma').setVal(3)

    ## Plot gauss in frame (i.e. in x) and draw frame on canvases.
    w.pdf('gauss').plotOn(xframe, roo.LineColor(ROOT.kRed))

    ## Create a canvas and draw the plot frame on it.
    canvases.next('Gaussian_PDF')
    xframe.Draw()
Exemple #42
0
def plot_all_throughputs_overlaid():
    canvases.next('Overlaid').SetGrid()
    tree.Draw('read + write : 5 * (i + 1)')
    graph_total = customize(beautify(get_graph()),
                            ytitle='Cluster Filesystem Throughput (Gb/s)',
                            yrange=(0, 11))
    tree.Draw('read : 5 * (i + 1)')
    graph_read = customize(beautify(get_graph()), color=ROOT.kBlue)
    tree.Draw('write : 5 * (i + 1)')
    graph_write = customize(beautify(get_graph()), color=ROOT.kRed)
    graph_total.Draw('alp')
    graph_read.Draw('lp')
    graph_write.Draw('lp')
    gstack = [graph_total, graph_write, graph_read]
    titles = [
        'Aggregate (%.1f #pm %.1f)' % get_mean_rms('read + write'),
        'Reading (%.1f #pm %.1f)' % get_mean_rms('read'),
        'Writing (%.1f #pm %.1f)' % get_mean_rms('write')
    ]
    Legend(gstack, titles, position=(0.5, 0.9, 0.92, 0.7)).draw()
    graphs.extend(gstack)
Exemple #43
0
def make_more_canvases(hist):
    '''
    Creates more of example canvases and draws the given histogram on them.
    '''
    ## You can customize the default canvas window width and height
    canvases.wwidth = 600
    canvases.wheight = 600
    canvases.next('gauss_square')
    hist.DrawCopy()

    ## You can customize the period of the staggering on the monitor
    ## like this:
    canvases.yperiod = 1
    ## Now, all the canvases will be rendered at the top of the screen
    ## since they are all the first in the y-period
    canvases.next(title='Red at the top of the display')
    hist.SetLineColor(ROOT.kRed)  ## Just for fun
    hist.DrawCopy()

    ## The same for the position of the canvas window on the display along
    ## the x-direction (left-right)
    canvases.xperiod = len(canvases.canvases)
    canvases.next(title='Blue at the left side of the display')
    hist.SetLineColor(ROOT.kBlue)  ## Just for fun
    hist.DrawCopy()
Exemple #44
0
def make_more_canvases(hist):    
    '''
    Creates more of example canvases and draws the given histogram on them.
    '''
    ## You can customize the default canvas window width and height
    canvases.wwidth = 600
    canvases.wheight = 600
    canvases.next('gauss_square')
    hist.DrawCopy()
        
    ## You can customize the period of the staggering on the monitor
    ## like this:
    canvases.yperiod = 1
    ## Now, all the canvases will be rendered at the top of the screen
    ## since they are all the first in the y-period
    canvases.next(title='Red at the top of the display')
    hist.SetLineColor(ROOT.kRed)  ## Just for fun
    hist.DrawCopy()
    
    ## The same for the position of the canvas window on the display along
    ## the x-direction (left-right)
    canvases.xperiod = len(canvases.canvases)
    canvases.next(title='Blue at the left side of the display')
    hist.SetLineColor(ROOT.kBlue)  ## Just for fun
    hist.DrawCopy()
 def make_fixed_range_zoom_plot(self):
     c1 = canvases.next(self.name + "_lin_fixedrange")
     c1.SetGrid()
     self.canvases.append(c1)
     plot = self.deltaE.frame(roo.Range(*self.fixed_range_zoom))
     plot.SetTitle(", ".join(self.labels))
     self.fit_data.plotOn(
         plot, roo.MarkerColor(self.color_data), roo.MarkerStyle(self.marker_style), roo.LineColor(self.color_data)
     )
     self.model.plotOn(plot, roo.LineColor(self.color_model))
     self.model.paramOn(plot, roo.Format("NEU", roo.AutoPrecision(2)), roo.Layout(0.2, 0.52, 0.87))
     plot.Draw()
     self.plots.append(plot)
Exemple #46
0
def plot_pulls_and_pvalues(w):
    '''
    void plot_pulls_and_pvalues(w)
    
    Plots the graphs of pulls and pvalues above each other.
    
    Preconditions: The `pull_graph' and `pvalue_graph' are in the given 
        workspace.
        
    Postconditions: There is a canvas with the plotted graphs.
    '''
    ## Get the graphs from the workspace.
    pull_graph = w.obj('pull_graph')
    pvalue_graph = w.obj('pvalue_graph')
    pvalue_hist = w.obj('pvalue_hist')
        
    ## Create a new canvas to display pulls and pvalues together.
    canvas = canvases.next('pulls_and_pvalue_graph')
    canvas.SetGrid()
    canvas.Divide(1,2)

    ## Plot the pull graph.
    pull_graph.SetTitle('')
    canvas.cd(1)
    pull_graph.Draw('ap')
    pull_graph.GetXaxis().SetTitle('x')
    pull_graph.GetYaxis().SetTitle('(observed - expected) / #sqrt{expected}')

    ## Plot the p-value graph.
    pvalue_graph.SetTitle('')
    canvas.cd(2)
    pvalue_graph.Draw('ap')
    pvalue_graph.GetXaxis().SetTitle('x')
    pvalue_graph.GetYaxis().SetTitle('p-value')
    
    ## Plot the p-value histogram.
    canvases.next('pvalue_hist')
    pvalue_hist.Draw()
Exemple #47
0
def plot_pulls_and_pvalues(w):
    '''
    void plot_pulls_and_pvalues(w)
    
    Plots the graphs of pulls and pvalues above each other.
    
    Preconditions: The `pull_graph' and `pvalue_graph' are in the given 
        workspace.
        
    Postconditions: There is a canvas with the plotted graphs.
    '''
    ## Get the graphs from the workspace.
    pull_graph = w.obj('pull_graph')
    pvalue_graph = w.obj('pvalue_graph')
    pvalue_hist = w.obj('pvalue_hist')

    ## Create a new canvas to display pulls and pvalues together.
    canvas = canvases.next('pulls_and_pvalue_graph')
    canvas.SetGrid()
    canvas.Divide(1, 2)

    ## Plot the pull graph.
    pull_graph.SetTitle('')
    canvas.cd(1)
    pull_graph.Draw('ap')
    pull_graph.GetXaxis().SetTitle('x')
    pull_graph.GetYaxis().SetTitle('(observed - expected) / #sqrt{expected}')

    ## Plot the p-value graph.
    pvalue_graph.SetTitle('')
    canvas.cd(2)
    pvalue_graph.Draw('ap')
    pvalue_graph.GetXaxis().SetTitle('x')
    pvalue_graph.GetYaxis().SetTitle('p-value')

    ## Plot the p-value histogram.
    canvases.next('pvalue_hist')
    pvalue_hist.Draw()
Exemple #48
0
 def make_fixed_range_zoom_plot(self):
     c1 = canvases.next(self.name + '_lin_fixedrange')
     c1.SetGrid()
     self.canvases.append(c1)
     plot = self.deltaE.frame(roo.Range(*self.fixed_range_zoom))
     plot.SetTitle(', '.join(self.labels))
     self.fit_data.plotOn(plot, roo.MarkerColor(self.color_data),
                          roo.MarkerStyle(self.marker_style),
                          roo.LineColor(self.color_data))
     self.model.plotOn(plot, roo.LineColor(self.color_model))
     self.model.paramOn(plot, roo.Format("NEU", roo.AutoPrecision(2)),
                        roo.Layout(0.2, 0.52, 0.87))
     plot.Draw()
     self.plots.append(plot)
Exemple #49
0
def test_bootstrapping():
    '''
    Test the prescaling.
    '''
    import FWLite.Tools.canvases as canvases
    print '== Bootstrapping Test =='
    data = get_toy_data(5)
    resampler = Resampler(data)
    data_boot1 = resampler.bootstrap(name='boot1')
    data_boot2 = resampler.bootstrap(name='boot2')
    for d in [data, data_boot1, data_boot2]:
        d.Print()
        for i in range(d.numEntries()):
            print 'Entry', i, 
            d.get(i).Print('v')
    print
    
    data = get_toy_data(20)
    xvar = data.get()['x']
    
    resampler = Resampler(data)
    boot_mean_hist = ROOT.TH1F('mean', 'mean', 100, -1, 1)
    boot_rms_hist = ROOT.TH1F('RMS', 'RMS', 100, 0, 2)
    for i in range(1000):
        boot_mean_hist.Fill(resampler.bootstrap().mean(xvar))
        boot_rms_hist.Fill(resampler.bootstrap().rmsVar(xvar).getVal())
    
    canvases.next('boot_mean')
    boot_mean_hist.DrawCopy()
    canvases.next('boot_rms')
    boot_rms_hist.DrawCopy()
    canvases.update()

    data.meanVar(xvar).Print()
    print '  bootstrap error:', boot_mean_hist.GetRMS()
    data.rmsVar(xvar).Print()
    print '  bootstrap error:', boot_rms_hist.GetRMS()
def test(max_entries=-1):
    '''
    Tests the PhotonIdCorrector class.
    '''
    global raw_data, target_data, corr, vplot
    varname = 'setab'
    option = 'skim10k'
    raw_name = 's12-zllm50-v7n'
    target_name = 'r12a-pho-j22-v1'
    raw_data = get_dataset(raw_name, varname, max_entries, option)
    target_data = get_dataset(target_name, varname, max_entries, option)
    xvar = raw_data.get().first()

    raw_data.SetTitle('Raw ' + raw_name.split('-')[0].capitalize())
    target_data.SetTitle('Raw ' + target_name.split('-')[0].capitalize())

    corr = PhotonIdCorrector(raw_data, target_data, rho=0.7)
    corr.SetName('_'.join([
        raw_name.split('-')[0], 'to',
        target_name.split('-')[0], varname, 'qqcorrector'
    ]))
    corr.SetTitle(' '.join([
        raw_name.split('-')[0].capitalize(), 'to',
        target_name.split('-')[0].capitalize(),
        xvar.GetTitle(), 'Q-Q Corrector'
    ]))

    plot = xvar.frame(roo.Title(raw_data.GetTitle()))
    raw_data.plotOn(plot)
    corr.xpdf.plotOn(plot)
    canvases.next(varname + '_' + raw_name.split('-')[0]).SetGrid()
    draw_and_append(plot)

    plot = xvar.frame(roo.Title(target_data.GetTitle()))
    target_data.plotOn(plot)
    corr.ypdf.plotOn(plot)
    canvases.next(varname + '_' + target_name.split('-')[0]).SetGrid()
    draw_and_append(plot)

    canvases.next(corr.GetName()).SetGrid()
    draw_and_append(corr.get_correction_plot())

    canvases.next(corr.GetName() + '_validation').SetGrid()
    draw_and_append(corr.get_validation_plot())

    canvases.update()
Exemple #51
0
 def make_width_ratio_booterrors_plot(self):
     canvas = canvases.next(self.name + '_width_ratio_booterrors')
     canvas.SetGrid()
     self.copy_axes_titles(self.width_ratio, self.errors_mi1)
     self.copy_axes_titles(self.width_ratio, self.errors_mi2)
     self.errors_mi1.SetFillColor(ROOT.kYellow)
     self.errors_mi2.SetFillColor(ROOT.kGreen)
     # self.errors_mi2.GetYaxis().SetRangeUser(0.9, 1.1)
     self.errors_mi2.Draw('3a')
     self.errors_mi1.Draw('3')
     self.errors_mi1.Draw('lx')
     self.width_ratio.SetLineColor(ROOT.kRed)
     self.width_ratio.Draw('l')
     ## Some ROOT Voodoo to make the grid lines appear above the bands
     self.errors_mi2.GetHistogram().Draw('sameaxig')
     canvas.RedrawAxis('g')
Exemple #52
0
 def make_width_ratio_booterrors_plot(self):
     canvas = canvases.next(self.name + '_width_ratio_booterrors')
     canvas.SetGrid()
     self.copy_axes_titles(self.width_ratio, self.errors_mi1)
     self.copy_axes_titles(self.width_ratio, self.errors_mi2)
     self.errors_mi1.SetFillColor(ROOT.kYellow)
     self.errors_mi2.SetFillColor(ROOT.kGreen)
     # self.errors_mi2.GetYaxis().SetRangeUser(0.9, 1.1)
     self.errors_mi2.Draw('3a')
     self.errors_mi1.Draw('3')
     self.errors_mi1.Draw('lx')
     self.width_ratio.SetLineColor(ROOT.kRed)
     self.width_ratio.Draw('l')
     ## Some ROOT Voodoo to make the grid lines appear above the bands
     self.errors_mi2.GetHistogram().Draw('sameaxig')
     canvas.RedrawAxis('g')
Exemple #53
0
    def make_plots(self):
        '''
        Makes plots of the raw and target source, the corrector function,
        and the corrected data.
        '''
        for src in [self.raw, self.target]:
            plot = self.get_plot_of_source(src)
            canvases.next(src.varname + '_' + src.data.GetName()).SetGrid()
            self.draw_and_append(plot)
            ## Also with log scale on y-axis
            c = canvases.next(src.varname + '_' + src.data.GetName() + '_logy')
            c.SetGrid()
            c.SetLogy()
            plot.Draw()

        canvases.next(self.corrector.GetName()).SetGrid()
        self.draw_and_append(self.corrector.get_correction_plot())

        canvases.next(self.corrector.GetName() + '_adiff').SetGrid()
        self.draw_and_append(self.corrector.get_absolute_difference_plot())

        canvases.next(self.corrector.GetName() + '_rdiff').SetGrid()
        self.draw_and_append(self.corrector.get_relative_difference_plot())

        plot = self.corrector.get_validation_plot()
        cname = self.corrector.GetName() + '_validation'
        canvases.next(cname).SetGrid()
        self.draw_and_append(plot)
        ## Also y-axis log-scale
        canvases.next(cname + '_logy').SetGrid()
        canvases.canvases[-1].SetLogy()
        plot.Draw()
Exemple #54
0
import FWLite.Tools.canvases as canvases
## Provides RooCauchy
import FWLite.Tools.tools as tools

from FWLite.Tools.qqcorrector import QQCorrector

#______________________________________________________________________________
# Setup
w = ROOT.RooWorkspace('w', 'Q-Q Corrections test')
g1 = w.factory('Gaussian::g1(x[-5, 5], m1[0], s1[1])')
g2 = w.factory('BreitWigner::g2(y[-5, 7], m2[1], s2[1.2])')

#______________________________________________________________________________
xplot = w.var('x').frame()
g1.plotOn(xplot)
canvases.next('g1_x').SetGrid()
xplot.Draw()

#______________________________________________________________________________
yplot = w.var('y').frame()
g2.plotOn(yplot)
canvases.next('g2_y').SetGrid()
yplot.Draw()

#______________________________________________________________________________
qq12 = QQCorrector(w.var('x'), g1, w.var('y'), g2, 1e-4)
plot12 = w.var('x').frame()
plot12.SetTitle('')
plot12.GetXaxis().SetTitle('Raw x')
plot12.GetYaxis().SetTitle('Corrected x')
qq12.plotOn(plot12)
    's4ratiob',
    's4ratioe',
]

output_filename = trees.analysis + '_' + dataset + '_id-histos.root'
destination = os.path.join(trees.base_dir, trees.analysis, 'histos',
                           output_filename)

tree = trees.get(dataset, option)
outfile = ROOT.TFile(destination, 'recreate')

hist = {}

for variable in variables_to_plot:
    cfg = config_map[variable]
    canvases.next(cfg.name).SetGrid()
    option = ''
    for expression, selection in zip(cfg.expressions, cfg.selections):
        if not ROOT.gDirectory.Get(cfg.name):
            varexp = expression + '>>' + cfg.name
            if hasattr(cfg, 'binning'):
                varexp += '(' + cfg.binning + ')'
        else:
            varexp = expression + '>>+' + cfg.name
        tree.Draw(varexp, selection, option)
    hist[cfg.name] = ihist = ROOT.gDirectory.Get(cfg.name)
    binwidth = ihist.GetBinWidth(1)
    title_item = lambda e, c: c and '%s {%s}' % (e, c) or e
    title = ', '.join(
        [title_item(e, c) for e, c in zip(cfg.expressions, cfg.selections)])
    xtitle = cfg.title
Exemple #56
0
def main():
    '''
    Main entry point of execution.
    '''
    ## C r e a t e   d a t a s e t   w i t h   X   a n d   Y   v a l u e s
    ## -------------------------------------------------------------------

    ## Make weighted XY dataset with asymmetric errors stored
    ## The StoreError() argument is essential as it makes
    ## the dataset store the error in addition to the values
    ## of the observables. If errors on one or more observables
    ## are asymmetric, one can store the asymmetric error
    ## using the StoreAsymError() argument
    x = ROOT.RooRealVar('x', 'x', -11, 11)
    y = ROOT.RooRealVar('y', 'y', -10, 200)
    dxy = ROOT.RooDataSet('dxy', 'dxy', ROOT.RooArgSet(x, y),
                          roo.StoreError(ROOT.RooArgSet(x, y)))

    ## Fill an example dataset with X,err(X),Y,err(Y) values
    for i in range(11):

        ## Set X value and error
        x.setVal(-10 + 2 * i)
        if i < 5:
            x.setError(0.5 / 1.)
        else:
            x.setError(1.0 / 1.)

        ## Set Y value and error
        y.setVal(x.getVal() * x.getVal() + 4 * math.fabs(ROOT.gRandom.Gaus()))
        y.setError(math.sqrt(y.getVal()))

        dxy.add(ROOT.RooArgSet(x, y))
    ## End of loop over dxy entries

    ## 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
    ## ---------------------------------------------------------------------------------------

    ## Make fit function
    a = ROOT.RooRealVar('a', 'a', 0.0, -10, 10)
    b = ROOT.RooRealVar('b', 'b', 0, -100, 100)
    f = ROOT.RooPolyVar('f', 'f', x, ROOT.RooArgList(b, a, roo.RooConst(1)))

    ## Plot dataset in X-Y interpretation
    frame = x.frame(
        roo.Title('#chi^{2} fit of function set of '
                  '(X#pmdX,Y#pmdY) values'))
    dxy.plotOnXY(frame, roo.YVar(y))

    ## Fit chi^2 using X and Y errors
    f.chi2FitTo(dxy, roo.YVar(y))

    ## Overlay fitted function
    f.plotOn(frame)

    ## Alternative: fit chi^2 integrating f(x) over ranges defined by X errors,
    ## rather than taking point at center of bin
    f.chi2FitTo(dxy, roo.YVar(y), roo.Integrate(True))

    ## Overlay alternate fit result
    f.plotOn(frame, roo.LineStyle(ROOT.kDashed), roo.LineColor(ROOT.kRed))

    ## Draw the plot on a canvas
    canvases.wwidth = 600
    canvases.wheight = 600
    canvases.next('rf609_xychi2fit')
    ROOT.gPad.SetLeftMargin(0.15)
    ROOT.gPad.SetTopMargin(0.1)
    frame.GetYaxis().SetTitleOffset(1.0)
    frame.Draw()
    canvases.update()