Esempio n. 1
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)
Esempio n. 2
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')
Esempio n. 3
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()
Esempio n. 4
0
    '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()
canvases.update()
sw.Stop()
print 'CPU time:', sw.CpuTime(), 's, real time:', sw.RealTime(), 's'
 
Esempio n. 5
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))