def test_monotonic5(): logger = getLogger('test_monotonic5') logger.info("Test monotonic Poly(5)-Distribution") model = Models.Monotonic_pdf('M4', x, power=4, increasing=False) result, f = model.fitTo(dataset, silent=True, refit=5) with wait(1), use_canvas('test_monotonic5'): model.draw(dataset) title = 'Positive decreasing polynomial' logger.info('%s \n%s' % (title, result.table(title=title, prefix='# '))) models.add(model)
def test_monotonic4(): logger.info("Test monotonic Poly(4)-Distribution") model = Models.Monotonic_pdf('M4', x, power=4, increasing=False) with rooSilent(): result, f = model.fitTo(dataset) result, f = model.fitTo(dataset) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) print(result) else: for phi in model.phis: logger.info("\tMonotonic4: phi= %-17s " % phi.ve()) models.add(model)
def test_pdf(): logger = getLogger('test_pdf') effPdf = Models.Monotonic_pdf('P6', xvar=x, power=4, increasing=True) maxe = margin * effPdf(xmax) s0 = min(1.0 / emax, 1.0 / maxe) scale = ROOT.RooRealVar('scaleX', 'scaleX', s0, 0.2 * s0, 5.0 * s0) eff2 = Efficiency1D('E2', effPdf, cut=acc, scale=scale) r2 = eff2.fitTo(ds) logger.info("Fit result using-Monotonic_pdf \n%s" % r2.table(prefix="# ")) logger.info("Compare with true efficiency (using Monotonic_pdf)\n%s" % make_table(eff2, title='using Monotonic_pdf')) with wait(2), use_canvas('test_pdf'): f2 = eff2.draw(ds, nbins=25)
def test_pdf () : effPdf = Models.Monotonic_pdf ( 'P6' , xvar = x , power = 3 , increasing = True ) maxe = margin * effPdf ( xmax ) s0 = min ( 1.0 / emax , 1.0 / maxe ) scale = ROOT.RooRealVar ( 'scaleX' , 'scaleX' , s0 , 0.2 * s0 , 5.0 * s0 ) eff2 = Efficiency1D ( 'E2' , effPdf , cut = acc , scale = scale ) 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 ) )
if '__main__' == __name__ or '__builtin__' == __name__: logger = getLogger('test_fitting_efficiency') else: logger = getLogger(__name__) # ============================================================================= ## make x = ROOT.RooRealVar('x', 'test', 0, 10) xmin, xmax = x.minmax() acc = ROOT.RooCategory('cut', 'cut') acc.defineType('accept', 1) acc.defineType('reject', 0) varset = ROOT.RooArgSet(x, acc) ds = ROOT.RooDataSet(dsID(), 'test data', varset) eff0 = Models.Monotonic_pdf('E0', xvar=x, power=2, increasing=True) eff0.phis = 3.1415 / 2, 3.1415 / 2 margin = 1.25 emax = margin * eff0(x.getMax()) for i in range(10000): xv = random.uniform(xmin, xmax) x.setVal(xv) ev = random.uniform(0, emax) if eff0(xv) > ev: acc.setIndex(1) else: acc.setIndex(0)