Beispiel #1
0
def plot_nominal_mmgmass_with_shape_and_fit():
    """Plot the nominal MC mmg mass data overlayed with the pdf shape and
    fit."""
    canvases.next('NominalMmgMassWithShapeAndFit')
    plot = mmgMass.frame(roo.Range(75, 105))
    plot.SetTitle("m(#mu#mu#gamma) overlayed with PDF shape (blue) "
                  "and it's parametrized fit (dashed red)")
    data.plotOn(plot)
    ## Define the mmg mass model.
    mmgMassPdf = ParametrizedKeysPdf('mmgMassPdf', 'mmgMassPdf', mmgMass,
                                     massPeak, massWidth, data,
                                     ROOT.RooKeysPdf.NoMirror, 1.5)
    ## PDF shape
    mmgMassPdf.shape.plotOn(plot)
    ## Parametrized fit of the PDF shape
    mmgMassPdf.fitTo(data, roo.Range(60, 120), roo.PrintLevel(-1))
    mmgMassPdf.plotOn(plot, roo.LineColor(ROOT.kRed),
                      roo.LineStyle(ROOT.kDashed))
    plot.Draw()
    sshape = 100 * (mmgMassPdf.shapemode / mZ.getVal() - 1)
    rshape = 100 * mmgMassPdf.shapewidth / mmgMassPdf.shapemode
    Latex([
        's_{shape}: %.3f %%' % sshape,
        's_{fit}: %.3f #pm %.3f %%' %
        (massScale.getVal(), massScale.getError()),
        's_{fit} - s_{shape}: %.4f #pm %.4f %%' %
        (massScale.getVal() - sshape, massScale.getError()),
        'r_{shape}: %.3f %%' % rshape,
        'r_{fit}: %.3f #pm %.3f %%' % (massRes.getVal(), massRes.getError()),
        'r_{fit} - r_{shape}: %.4f #pm %.4f %%' %
        (massRes.getVal() - rshape, massRes.getError()),
        'r_{fit}/r_{shape}: %.4f #pm %.4f' %
        (massRes.getVal() / rshape, massRes.getError() / rshape),
    ],
          position=(0.2, 0.8)).draw()
Beispiel #2
0
def plot_training_phoeres_with_shape_and_fit():
    """Plot the nominal MC photon energy smearing overlayed with the pdf shape
    and fit."""
    canvases.next('TrainingPhoEResWithShapeAndFit')
    plot = phoERes.frame(roo.Range(-7.5, 5))
    plot.SetTitle("Photon energy smearing overlayed with PDF shape (blue) "
                  "and it's parametrized fit (dashed red)")
    data.plotOn(plot)
    ## Define model for the photon energy smearing function Ereco/Etrue - 1.
    phoEResPdf = ParametrizedKeysPdf('phoEResPdf', 'phoEResPdf', phoERes,
                                     phoScale, phoRes, data,
                                     ROOT.RooKeysPdf.NoMirror, 1.5)
    ## PDF shape
    phoEResPdf.shape.plotOn(plot)
    ## Parametrized fit of the PDF shape
    phoEResPdf.fitTo(data, roo.Range(-50, 50), roo.PrintLevel(-1))
    phoEResPdf.plotOn(plot, roo.LineColor(ROOT.kRed),
                      roo.LineStyle(ROOT.kDashed))
    plot.Draw()
    Latex([
        's_{shape}: %.3f %%' % phoEResPdf.shapemode,
        's_{fit}: %.3f #pm %.3f %%' % (phoScale.getVal(), phoScale.getError()),
        's_{fit} - s_{shape}: %.4f #pm %.4f %%' %
        (phoScale.getVal() - phoEResPdf.shapemode, phoScale.getError()),
        'r_{shape}: %.3f %%' % phoEResPdf.shapewidth,
        'r_{fit}: %.3f #pm %.3f %%' % (phoRes.getVal(), phoRes.getError()),
        'r_{fit} - r_{shape}: %.4f #pm %.4f %%' %
        (phoRes.getVal() - phoEResPdf.shapewidth, phoRes.getError()),
        'r_{fit}/r_{shape}: %.4f #pm %.4f' %
        (phoRes.getVal() / phoEResPdf.shapewidth,
         phoRes.getError() / phoEResPdf.shapewidth),
    ],
          position=(0.2, 0.8)).draw()
Beispiel #3
0
def plot_mmgmass_with_fit_for_multiple_smearings(name, stargets, rtargets,
                                                 colors, plotrange=(60, 105)):
    """Plot the smeared mmg mass for a number of different smearings."""
    canvases.next(name).SetGrid()
    mmgMass.setRange('plot', *plotrange)
    plot = mmgMass.frame(roo.Range('plot'))
    plot.SetTitle("")
    slabels = []
    rlabels = []
    ## Loop over the various smearings.
    for starget, rtarget, color in zip(stargets, rtargets, colors):
        mydata = calibrator.get_smeared_data(starget, rtarget)
        model = ParametrizedKeysPdf('model',
                                    'model',
                                    mmgMass, mmgMassSmearPeak,
                                    mmgMassSmearWidth, mydata,
                                    ROOT.RooKeysPdf.NoMirror, 1.5)
        model.fitTo(mydata, roo.PrintLevel(-1), roo.Range(60, 120),
                    roo.SumW2Error(False))
        mydata.plotOn(plot, roo.LineColor(color), roo.MarkerColor(color))
        model.plotOn(plot, roo.LineColor(color), roo.Range('plot'),
                     roo.NormRange('plot'))
        slabels.append([
            's\' = % 3.f %%,  ' % starget +
            '#Delta m_{#mu#mu#gamma} = %.2f #pm %.2f %%' % (
                100 * (mmgMassSmearPeak.getVal() / 91.2 - 1.),
                100 * mmgMassSmearPeak.getError() / 91.2
                ),
            ])
        rlabels.append([
            'r\' = %.1f %%,  ' % rtarget +
            '#sigma_{eff}/#mu(m_{\mu\mu\gamma}) = % .2f #pm %.2f %%' % (
                100 * mmgMassSmearWidth.getVal() / mmgMassSmearPeak.getVal(),
                100 * mmgMassSmearWidth.getError() / mmgMassSmearPeak.getVal(),
                ),
            ])
    ## End of loop over the various smearings.
    plot.Draw()
    for i, (labels, color) in enumerate(zip(slabels, colors)):
        latex = Latex(labels, position=(0.18, 0.85 - i*0.055))
        latex.SetTextColor(color)
        latex.draw()
    for i, (labels, color) in enumerate(zip(rlabels, colors)):
        latex = Latex(labels,
                      position=(0.18, 0.85 - (len(slabels)+1) * 0.055 - i*0.055))
        latex.SetTextColor(color)
        latex.draw()
Beispiel #4
0
def plot_nominal_mmgmass_with_shape_and_fit():
    """Plot the nominal MC mmg mass data overlayed with the pdf shape and
    fit."""
    canvases.next('NominalMmgMassWithShapeAndFit')
    plot = mmgMass.frame(roo.Range(75, 105))
    plot.SetTitle("m(#mu#mu#gamma) overlayed with PDF shape (blue) "
                  "and it's parametrized fit (dashed red)")
    data.plotOn(plot)
    ## Define the mmg mass model.
    mmgMassPdf = ParametrizedKeysPdf('mmgMassPdf', 'mmgMassPdf', mmgMass,
                                     massPeak, massWidth, data,
                                     ROOT.RooKeysPdf.NoMirror, 1.5)
    ## PDF shape
    mmgMassPdf.shape.plotOn(plot)
    ## Parametrized fit of the PDF shape
    mmgMassPdf.fitTo(data, roo.Range(60, 120), roo.PrintLevel(-1))
    mmgMassPdf.plotOn(plot, roo.LineColor(ROOT.kRed),
                      roo.LineStyle(ROOT.kDashed))
    plot.Draw()
    sshape = 100 * (mmgMassPdf.shapemode / mZ.getVal() - 1)
    rshape = 100 * mmgMassPdf.shapewidth / mmgMassPdf.shapemode
    Latex([
        's_{shape}: %.3f %%' % sshape,
        's_{fit}: %.3f #pm %.3f %%' % (massScale.getVal(),
                                       massScale.getError()),
        's_{fit} - s_{shape}: %.4f #pm %.4f %%' % (
            massScale.getVal() - sshape,
            massScale.getError()
            ),
        'r_{shape}: %.3f %%' % rshape,
        'r_{fit}: %.3f #pm %.3f %%' % (
            massRes.getVal(), massRes.getError()
            ),
        'r_{fit} - r_{shape}: %.4f #pm %.4f %%' % (
            massRes.getVal() - rshape,
            massRes.getError()),
        'r_{fit}/r_{shape}: %.4f #pm %.4f' % (
            massRes.getVal() / rshape,
            massRes.getError() / rshape),
        ], position=(0.2, 0.8)).draw()
Beispiel #5
0
def plot_training_phoeres_with_shape_and_fit():
    """Plot the nominal MC photon energy smearing overlayed with the pdf shape
    and fit."""
    canvases.next('TrainingPhoEResWithShapeAndFit')
    plot = phoERes.frame(roo.Range(-7.5, 5))
    plot.SetTitle("Photon energy smearing overlayed with PDF shape (blue) "
                  "and it's parametrized fit (dashed red)")
    data.plotOn(plot)
    ## Define model for the photon energy smearing function Ereco/Etrue - 1.
    phoEResPdf = ParametrizedKeysPdf('phoEResPdf', 'phoEResPdf', phoERes,
                                     phoScale, phoRes, data,
                                     ROOT.RooKeysPdf.NoMirror, 1.5)
    ## PDF shape
    phoEResPdf.shape.plotOn(plot)
    ## Parametrized fit of the PDF shape
    phoEResPdf.fitTo(data, roo.Range(-50, 50), roo.PrintLevel(-1))
    phoEResPdf.plotOn(plot, roo.LineColor(ROOT.kRed),
                      roo.LineStyle(ROOT.kDashed))
    plot.Draw()
    Latex([
        's_{shape}: %.3f %%' % phoEResPdf.shapemode,
        's_{fit}: %.3f #pm %.3f %%' % (phoScale.getVal(),
                                       phoScale.getError()),
        's_{fit} - s_{shape}: %.4f #pm %.4f %%' % (
            phoScale.getVal() - phoEResPdf.shapemode,
            phoScale.getError()
            ),
        'r_{shape}: %.3f %%' % phoEResPdf.shapewidth,
        'r_{fit}: %.3f #pm %.3f %%' % (phoRes.getVal(), phoRes.getError()),
        'r_{fit} - r_{shape}: %.4f #pm %.4f %%' % (
            phoRes.getVal() - phoEResPdf.shapewidth,
            phoRes.getError()),
        'r_{fit}/r_{shape}: %.4f #pm %.4f' % (
            phoRes.getVal() / phoEResPdf.shapewidth,
            phoRes.getError() / phoEResPdf.shapewidth),
        ], position=(0.2, 0.8)).draw()
Beispiel #6
0
##                                    pdflist=','.join(spdflist),
##                                    mreflist=','.join(sreflist)))
## w.Import(pdf)

w.Print()

pdf.fitTo(data, roo.Range(60, 120), roo.Minos())

tdata = calibrator.get_smeared_data(stest, rtest)
tdata.SetName('tdata')
pdf.fitTo(tdata, roo.Range(60, 120), roo.Minos())
calibrator.phoEResPdf.fitTo(tdata, roo.Range(-50, 50))
canvases.next('test_fit')
plot = mmgMass.frame(roo.Range(70, 110))
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()
Beispiel #7
0
phoERes.setRange(-90, 150)
phoEResPdf = ParametrizedKeysPdf('phoEResPdf', 'phoEResPdf',
                                 phoERes, phoScale, phoRes, data,
                                 ROOT.RooKeysPdf.NoMirror, 1.5)
phoERes.setRange(*range_save)

##------------------------------------------------------------------------------
## Plot the phoEResPdf for various values of the scale
canvases.next('ShapeScaleScan').SetGrid()
phoRes.setVal(1)
plot = phoERes.frame(roo.Range(-10, 10))
latexlabels = []
for i, color in enumerate('Red Yellow Green Blue Black'.split()):
    scale = -4 + 2*i
    phoScale.setVal(scale)
    phoEResPdf.plotOn(plot, roo.LineColor(getattr(ROOT, 'k' + color)))
    label = Latex(['s: %d %%' % scale,],
                  position=(0.8, 0.75 - (i+1) * 0.055))
    label.SetTextColor(getattr(ROOT, 'k' + color))
    latexlabels.append(label)

plot.SetTitle('Scale Parametrization Closure')
plot.GetYaxis().SetTitle('a. u.')
plot.Draw()
Latex(cutlabels, position=(0.2, 0.75)).draw()
Latex(['r: 1 %',], position=(0.8, 0.75)).draw()
for l in latexlabels:
    l.draw()

##------------------------------------------------------------------------------
## Plot the phoEResPdf for various values of the effective sigma
## Build the model for fT(t|s,r) = fT1(t1) * fT2(t2|s,r)
t.setRange(5, 10)
t.setBins(1000, "cache")
tpdf = ROOT.RooFFTConvPdf('tpdf', 'tpdf', t, t1pdf, t2pdf)
tpdf.setBufferFraction(0.1)

##------------------------------------------------------------------------------
## Plot fT1(t1) with training data.
canvases.next('t1pdf').SetGrid()
t.setRange(5, 10)
t.SetTitle('log(m_{#mu#mu#gamma,E_{gen}^{#gamma}}^{2} - m_{#mu#mu}^{2})')
plot = t.frame(roo.Range(6, 9))
t1data.plotOn(plot)
t1pdf.shape.plotOn(plot)
t1pdf.plotOn(plot, roo.LineColor(ROOT.kRed), roo.LineStyle(ROOT.kDashed))
plot.Draw()
Latex([
    's_{shape}: %.3f' % t1pdf.shapemode,
    's_{fit}: %.3f #pm %.3f' % (t1mode.getVal(),
                                   t1mode.getError()),
    's_{fit} - s_{shape}: %.4f #pm %.4f' % (
        t1mode.getVal() - t1pdf.shapemode,
        t1mode.getError()
        ),
    'r_{shape}: %.3f' % t1pdf.shapewidth,
    'r_{fit}: %.3f #pm %.3f' % (t1width.getVal(), t1width.getError()),
    'r_{fit} - r_{shape}: %.4f #pm %.4f' % (
        t1width.getVal() - t1pdf.shapewidth,
        t1width.getError()),
    'r_{fit}/r_{shape}: %.4f #pm %.4f' % (
Beispiel #9
0
res1 = (phoScale.getVal(), phoScale.getError())
mmgMassModel2.fitTo(fitdata, roo.Range(60, 120), roo.SumW2Error(True),
                   roo.Strategy(2), roo.InitialHesse(True), roo.Minos(True),
                   roo.Timer(True))
res2 = (phoScale.getVal(), phoScale.getError())

##------------------------------------------------------------------------------
canvases.next('data')
plot = mmgMass.frame(roo.Range(70, 110))
data.plotOn(plot)
mmgMassPdf.shape.plotOn(plot)
## mmgMass.setRange(50, 130)
## mmgMassPdf.fitTo(data, roo.Range(60,120), roo.SumW2Error(True),
##                  roo.InitialHesse(True), roo.Minos(True), roo.Strategy(2),
##                  roo.Timer(True))
mmgMassPdf.plotOn(plot, roo.LineColor(ROOT.kRed), roo.LineStyle(ROOT.kDashed))
print 'Plotting', plot.GetName(), 'on', canvases.canvases[-1].GetName()
plot.Draw()
Latex(
    ['m(E^{#gamma}_{reco}/E^{#gamma}_{gen}-1): %.3f #pm %.3f %%' % (
        calibrator.s.getVal(), calibrator.s.getError()
        ),
     '#sigma_{eff}(E^{#gamma}_{reco}/E^{#gamma}_{gen}-1): %.3f #pm %.3f %%' % (
         calibrator.r.getVal(), calibrator.r.getError()
         ),
     'm(m_{#mu#mu#gamma})',
     '  shape: %.3f GeV' % mmgMassPdf.shapemode,
     '  fit: %.3f #pm %.3f GeV' % (
         mmgMassPeak.getVal(), mmgMassPeak.getError()
         ),
     '#sigma_{eff}(m_{#mu#mu#gamma})',
Beispiel #10
0
                          rho=1.5)

## Build the model for fT(t|s,r) = fT1(t1) * fT2(t2|s,r)
t.setRange(5, 10)
t.setBins(1000, "cache")
tpdf = ROOT.RooFFTConvPdf('tpdf', 'tpdf', t, t1pdf, t2pdf)
tpdf.setBufferFraction(0.1)

## Plot fT1(t1) with training data.
canvases.next('t1pdf').SetGrid()
t.setRange(5, 10)
t.SetTitle('log(m_{#mu#mu#gamma,E_{gen}^{#gamma}}^{2} - m_{#mu#mu}^{2})')
plot = t.frame(roo.Range(6, 9))
t1data.plotOn(plot)
t1pdf.shape.plotOn(plot)
t1pdf.plotOn(plot, roo.LineColor(ROOT.kRed), roo.LineStyle(ROOT.kDashed))
plot.Draw()
Latex([
    's_{shape}: %.3f' % t1pdf.shapemode,
    's_{fit}: %.3f #pm %.3f' % (t1mode.getVal(), t1mode.getError()),
    's_{fit} - s_{shape}: %.4f #pm %.4f' %
    (t1mode.getVal() - t1pdf.shapemode, t1mode.getError()),
    'r_{shape}: %.3f' % t1pdf.shapewidth,
    'r_{fit}: %.3f #pm %.3f' % (t1width.getVal(), t1width.getError()),
    'r_{fit} - r_{shape}: %.4f #pm %.4f' %
    (t1width.getVal() - t1pdf.shapewidth, t1width.getError()),
    'r_{fit}/r_{shape}: %.4f #pm %.4f' %
    (t1width.getVal() / t1pdf.shapewidth,
     t1width.getError() / t1pdf.shapewidth),
],
      position=(0.2, 0.8)).draw()
Beispiel #11
0
##                                    pdflist=','.join(spdflist),
##                                    mreflist=','.join(sreflist)))
## w.Import(pdf)

w.Print()

pdf.fitTo(data, roo.Range(60, 120), roo.Minos())

tdata = calibrator.get_smeared_data(stest, rtest)
tdata.SetName('tdata')
pdf.fitTo(tdata, roo.Range(60, 120), roo.Minos())
calibrator.phoEResPdf.fitTo(tdata, roo.Range(-50, 50))
canvases.next('test_fit')
plot = mmgMass.frame(roo.Range(70, 110))
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()
sw.Start()

init()
get_data()

phoEResPdf = ParametrizedKeysPdf(
    'phoEResPdf', 'phoEResPdf', phoERes, phoScale, phoRes, data,
    ROOT.RooKeysPdf.NoMirror, 1.5
    )

phoEResPdf.fitTo(data, roo.Range(-50, 50))

canvases.next('phoEResPdf').SetGrid()
plot = phoERes.frame(roo.Range(-10, 10))
data.plotOn(plot)
phoEResPdf.plotOn(plot)
phoEResPdf.paramOn(plot)
plot.Draw()

t = w.factory('t[0,-1,1]')
t.SetTitle('log(E_{reco}^{#gamma}/E_{gen}^{#gamma})')
tfunc = w.factory('expr::tfunc("log(0.01 * phoERes + 1)", {phoERes})')
tfunc.SetName('t')
data.addColumn(tfunc)

## Build the model for log(Ereco/Egen) ft2(t2|r,s)
t2pdf = LogPhoeresKeysPdf('t2pdf', 't2pdf', phoERes, t, phoScale, phoRes, data,
                          rho=1.5)

## Fit nominal data with ft2(t2|r,s)
canvases.next('t2pdf').SetGrid()
Beispiel #13
0
##------------------------------------------------------------------------------
sw = ROOT.TStopwatch()
sw.Start()

init()
get_data()

phoEResPdf = ParametrizedKeysPdf('phoEResPdf', 'phoEResPdf', phoERes, phoScale,
                                 phoRes, data, ROOT.RooKeysPdf.NoMirror, 1.5)

phoEResPdf.fitTo(data, roo.Range(-50, 50))

canvases.next('phoEResPdf').SetGrid()
plot = phoERes.frame(roo.Range(-10, 10))
data.plotOn(plot)
phoEResPdf.plotOn(plot)
phoEResPdf.paramOn(plot)
plot.Draw()

t = w.factory('t[0,-1,1]')
t.SetTitle('log(E_{reco}^{#gamma}/E_{gen}^{#gamma})')
tfunc = w.factory('expr::tfunc("log(0.01 * phoERes + 1)", {phoERes})')
tfunc.SetName('t')
data.addColumn(tfunc)

## Build the model for log(Ereco/Egen) ft2(t2|r,s)
t2pdf = LogPhoeresKeysPdf('t2pdf',
                          't2pdf',
                          phoERes,
                          t,
                          phoScale,