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 _get_mctruth_scale_and_resolution(self):
        ## Enlarge the range of the observable to get vanishing tails for
        ## the photon energy scale resolution
        # savrange = (self.phoERes.getMin(), self.phoERes.getMax())
        # self.phoERes.setRange(savrange[0] - 10, savrange[1] + 10)

        ## Build the model for the photon energy resolution.
        self.phoEResPdf = ParametrizedKeysPdf('phoEResPdf', 'phoEResPdf',
                                              self.phoERes, self.s, self.r,
                                              self.data,
                                              ROOT.RooKeysPdf.NoMirror,
                                              self.rho)
        # self.phoERes.setRange(*savrange)
        ## Set sensible initial values
        self.s.setVal(self.phoEResPdf.shapemode)
        self.r.setVal(self.phoEResPdf.shapewidth)

        ## Extract the MC truth scale and resolution from MC
        self.fitresult_mctruth = self.phoEResPdf.fitTo(
            self.data, roo.PrintLevel(self.printlevel), roo.SumW2Error(False),
            roo.Range(-50, 50), roo.Save(), roo.Strategy(2))
        self.w.Import(self.fitresult_mctruth)

        ## Store the MC truth scale and resolution
        for source, target in zip([self.s, self.r], [self.s0, self.r0]):
            target.setVal(source.getVal())
            target.setError(source.getError())
            target.setAsymError(source.getErrorLo(), source.getErrorHi())
        # self.s0.setVal(self.s.getVal())
        # self.r0.setVal(self.r.getVal())
        self.w.saveSnapshot('sr_mctruth', self.sr)
        self.w.saveSnapshot('sr0_mctruth', self.sr0)
        self.s0.setConstant(True)
        self.r0.setConstant(True)
Beispiel #4
0
 def _fit_smeared_data(self, name):
     'Fit the current smeared data to get the smeared s and r.'
     self.fitresult_sdata = self.phoEResPdf.fitTo(
         self.sdata, roo.PrintLevel(self.printlevel), roo.SumW2Error(False),
         roo.Range(-50, 50), roo.Save(), roo.Strategy(2))
     self.w.saveSnapshot(name + '_sr', self.sr)
     self.w.Import(self.fitresult_sdata, name + '_fitresult')
Beispiel #5
0
def plot_smeared_phoeres_with_fit():
    phoEResPdf.fitTo(datasmeared, roo.PrintLevel(-1), roo.SumW2Error(False))
    canvases.next('SmearedSampleWithFit')
    plot = phoERes.frame(roo.Range(-30, 30))
    plot.SetTitle("Smeared MC with paremetrized fit")
    datasmeared.plotOn(plot)
    phoEResPdf.plotOn(plot)
    phoEResPdf.paramOn(plot)
    plot.Draw()
    Latex([
        'target s: %.3g %%' % targets,
        'target r: %.3g %%' % targetr,
    ],
          position=(0.2, 0.75)).draw()
Beispiel #6
0
phoScale = w.factory('phoScale[0,-50,50]')
phoRes = w.factory('phoRes[5,0.01,50]')

for x in [phoScale, phoRes]:
    x.setUnit('%')

range_save = (phoERes.getMin(), phoERes.getMax())
## Enlarge the range of the observable to get vanishing tails.
phoERes.setRange(-90, 150)
phoEResPdf = ParametrizedKeysPdf('phoEResPdf', 'phoEResPdf', phoERes, phoScale,
                                 phoRes, data, ROOT.RooKeysPdf.NoMirror, 1.5)
phoERes.setRange(*range_save)

##------------------------------------------------------------------------------
## Extract the MC truth scale and resolution from MC
phoEResPdf.fitTo(data, roo.PrintLevel(-1), roo.SumW2Error(False))
phoScaleRef = phoScale.getVal()
phoResRef = phoRes.getVal()

##------------------------------------------------------------------------------
## Define the smearing formulas for photon energy and mmg invariant mass
phoEResSmear = w.factory('phoEResSmear[-100,200]')
phoEResSmearFunc = w.factory('''expr::phoEResSmearFunc(
    "{m} + {s} * ({x} - {m0}) / {s0}",
    {{{x}}}
    )'''.format(x='phoERes',
                m=targets,
                s=targetr,
                m0=phoScaleRef,
                s0=phoResRef))