def test_vars3(): a = ROOT.RooRealVar('A', 'a', 0.05, 0, 1) b = ROOT.RooRealVar('B', 'b', 0.02, -0.05, 0.1) c = ROOT.RooRealVar('C', 'c', 0.005, 0, 0.1) import ostap.fitting.roofuncs as R from ostap.fitting.funbasic import Fun1D X = Fun1D(x, xvar=x, name='X') ##F = (X**2) * c + X * b + a F = a + b * X + c * X**2 eff2 = Efficiency1D('E5', F, cut=acc, xvar=x) r2 = eff2.fitTo(ds) f2 = eff2.draw(ds) print(r2) for p in points: e = eff2(p, error=True) ev = e.value() e0 = eff0(p) / emax print(' Point/Eff %4.1f %s%% (%.2f%%)' % (p, (100 * e).toString('(%5.2f+-%4.2f)'), e0 * 100))
def __init__ ( self , name , efficiency , ## the function, FUNC or PDF cut , xvar = None , accept = 'accept' , scale = None ) : self.__eff = efficiency if isinstance ( efficiency , PDF ) : eff_pdf = efficiency xvar = efficiency.xvar eff_fun = None elif isinstance ( efficiency , FUNC ) : eff_fun = efficiency.fun xvar = efficiency.xvar eff_pdf = None elif isinstance ( efficiency , ROOT.RooAbsPdf ) and xvar and isinstance ( xvar , ROOT.RooAbsReal ) : eff_pdf = Generic1D_pdf ( efficiency , xvar ) eff_fun = None elif isinstance ( efficiency , ROOT.RooAbsReal ) and xvar and isinstance ( xvar , ROOT.RooAbsReal ) : eff_pdf = Fun1D ( efficiency , xvar = xvar ) eff_fun = efficiency else : raise AttributeError('Invalid efficiency/xvar combination %s/%s;%s/%s' % ( efficiency , type(efficiency) , xvar , type(xvar) ) ) self.__xvar = xvar Efficiency.__init__ ( self , name , eff_pdf , eff_fun , ( xvar,) , cut , accept , scale )
def test_vars3(): logger = getLogger('test_vars3') a = ROOT.RooRealVar('A', 'a', 0.05, 0, 1) b = ROOT.RooRealVar('B', 'b', 0.02, -0.05, 0.1) c = ROOT.RooRealVar('C', 'c', 0.005, 0, 0.1) import ostap.fitting.roofuncs as R from ostap.fitting.funbasic import Fun1D X = Fun1D(x, xvar=x, name='X') ##F = (X**2) * c + X * b + a F = a + b * X + c * X**2 eff2 = Efficiency1D('E5', F, cut=acc, xvar=x) r2 = eff2.fitTo(ds) logger.info("Fit result using-Fun1D \n%s" % r2.table(prefix="# ")) logger.info("Compare with true efficiency (using Fun1D)\n%s" % make_table(eff2, title='using Fnu1D')) with wait(2), use_canvas('test_vars3'): f2 = eff2.draw(ds, nbins=25)
def test_transform(): logger = getLogger('test_transform') if not 62000 <= ROOT.gROOT.GetVersionInt(): logger.info("Not for this version of ROOT") return x = ROOT.RooRealVar('x', '', 1, 100000) mean = 1000 sigma = 1000 ## book very simple data set varset = ROOT.RooArgSet(x) dataset = ROOT.RooDataSet(dsID(), 'Test Data set', varset) while len(dataset) < 5000: v = random.gauss(mean, sigma) if v in x: x.value = v dataset.add(varset) dataset.add_var('lx', 'log10(x)') dataset.lx.setMin(0) dataset.lx.setMax(5) ## original PDF gauss = Models.Gauss_pdf('G', xvar=x, mean=(mean, mean / 2, mean * 2), sigma=(sigma, sigma / 2, sigma * 2)) with use_canvas('test_transform'), wait(1): r1, f1 = gauss.fitTo(dataset, draw=True, silent=True) logger.info('Fit x:\n%s' % r1.table()) lx = dataset.lx LX = Fun1D(lx, lx) NX = 10**LX ## transformed PDF tgauss = TrPDF(pdf=gauss, new_var=NX) with use_canvas('test_transform'), wait(1): r2, f2 = tgauss.fitTo(dataset, draw=True, silent=True) logger.info('Fit log10(x):\n%s' % r2.table())