Exemple #1
0
def sumPlotObjects(objs_list, weights=None):
    res = {}
    aux = {}
    if weights is None:
        weights = [1] * len(objs_list)
    if len(weights) != len(objs_list):
        logging.error("Numbers of regions and weights given do not match!")
        return

    for objs, w in zip(objs_list, weights):
        for k, v in objs.iteritems():
            if k == "error" or k == "chi2":  # meaningless to sum them
                continue
            short = getCompName(k)
            if not short in aux:
                aux[short] = k
                # pay attention not to modify the objects we are working with. They might be reused elsewhere.
                if isinstance(v, TObject):
                    res[k] = v.Clone()
                    if isinstance(v, TGraphAsymmErrors):  # data
                        scaleTGraphAsymmErrors(res[k], w)
                    else:
                        res[k].Scale(w)
                elif k == "prefit":
                    res[k] = [v[0].Clone(), v[1]]
                    res[k][0].Scale(w)
                else:
                    res[k] = v
            else:
                idx = aux[short]
                if short != k:  # that's one standard component
                    res[idx].Add(v, w)
                elif k == "prefit":
                    res[idx][0].Add(v[0], w)
                elif k == "data":
                    if w == 1:
                        res[idx] = RooHist(res[idx], v)
                    else:
                        res[idx] = RooHist(res[idx], v, 1, w, RooAbsData.SumW2)
    return res
Exemple #2
0
def addHists(hist1, hist2):
    from ROOT import RooHist
    from math import sqrt

    newHist = RooHist(hist1)

    for i in range(0, newHist.GetN()):
        newHist.SetPoint(i,
                         newHist.GetX()[i],
                         hist1.GetY()[i] + hist2.GetY()[i])
        newHist.SetPointError(i, hist1.GetErrorXlow(i), hist1.GetErrorXhigh(i),
                              sqrt(hist1.GetErrorYlow(i)**2 + \
                                   hist2.GetErrorYlow(i)**2),
                              sqrt(hist1.GetErrorYhigh(i)**2 + \
                                   hist2.GetErrorYhigh(i)**2)
                              )
    return newHist
Exemple #3
0
fit2.__class__ = ROOT.RooCurve

turnon2 = TurnOnPlot.TurnOn(Name="Stage2",
                            Histo=histo2,
                            MarkerColor=ROOT.kRed,
                            MarkerStyle=20,
                            LineColor=ROOT.kRed,
                            LineStyle=1,
                            Legend="New pedestals")

plots[0].addTurnOn(turnon)
plots[0].addTurnOn(turnon2)

#Plot the difference:
diffcurve = RooCurve("diff", "diff", fit, fit2, 1, -1)
diffhist = RooHist(histo, histo2, 1, -1, RooAbsData.SumW2)
turnondiff = TurnOnPlot.TurnOn(Name="Stage2",
                               Histo=diffhist,
                               Fit=diffcurve,
                               MarkerColor=ROOT.kBlack,
                               MarkerStyle=20,
                               LineColor=ROOT.kBlue,
                               LineStyle=1,
                               Legend="Data-New_pedestals")

plots[1].addTurnOn(turnondiff)

canvas = []
for plot in plots:
    canvas.append(plot.plot())
Exemple #4
0
        oldDataHist.Draw()
        theData.Draw("pz")
        gPad.Update()
        gPad.WaitPrimitive()

        oldDataHist = templateMorph.scaleUnwidth(oldDataHist)

        oldDataHist.Print()

    bgHist = TH1D(SignalHist)
    bgHist.Reset('ices')
    bgHist.SetName(theData.GetName())
    bgHist.SetTitle(theData.GetTitle())
    bgHist = curveToHist(bgCurve, bgHist, debug=opts.debug)

    tmpData = RooHist(bgHist, 0, 1, RooAbsData.SumW2)
    tmpHist = TH1D(bgHist)

    # if opts.debug:
    #     print 'drawing toy data bg residuals before signal addition...'
    #     resid = tmpData.makeResidHist(bfile.Get('h_total'))
    #     resid.Draw('apz')
    #     gPad.Update()
    #     gPad.WaitPrimitive()

    bgHist = templateMorph.scaleUnwidth(bgHist)
    print 'background only'
    bgHist.Print()

    bgHist.Add(SignalHist)