def test_pdf(): effPdf = Models.PolyPos_pdf('B', xvar=x, power=6) eff2 = Efficiency1D('E2', effPdf, cut=acc) r2 = eff2.fitTo(ds) f2 = eff2.draw(ds) print r2 for p in points: print ' Point/Eff %.1f %s%%' % (p, ( 100 * eff2(p, error=True)).toString('(%5.2f+-%4.2f)'))
def test_poly4(): logger = getLogger('test_poly4') logger.info("Test Poly(4)-Distribution") model = Models.PolyPos_pdf('P4', x, power=3) result, f = model.fitTo(dataset, silent=True, refit=5) with wait(1), use_canvas('test_poly4'): model.draw(dataset) title = 'Positive polynomial' logger.info('%s \n%s' % (title, result.table(title=title, prefix='# '))) models.add(model)
def test_poly4(): logger.info("Test Poly(4)-Distribution") model = Models.PolyPos_pdf('P4', x, power=4) result, f = model.fitTo(dataset, silent=True) 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("\tPoly4: phi= %-17s " % phi.ve()) models.add(model)
def test_simfit5(): logger = getLogger('test_simfit5') # ========================================================================= ## resoltuion for the left peak # ========================================================================= reso1 = Models.ResoGauss('RG1', xvar=dm1, sigma=(sigma1, sigma1 / 2, sigma1 * 2), mean=(0, -1, 1)) # fit DM1 dataset for resolution r1, f1 = reso1.fitTo(dset1, silent=True) r1, f1 = reso1.fitTo(dset1, silent=True, draw=True, nbins=100) # ========================================================================= ## resoltuion for the central peak # ========================================================================= reso2 = Models.ResoGauss('RG2', xvar=dm2, sigma=(sigma2, sigma2 / 2, sigma2 * 2), mean=(0, -1, 1)) # fit DM2 dataset for resolution r2, f2 = reso2.fitTo(dset2, silent=True) r2, f2 = reso2.fitTo(dset2, silent=True, draw=True, nbins=100) # ========================================================================= ## resoltuion for the right peak # ========================================================================= reso3 = Models.ResoGauss('RG3', xvar=dm3, sigma=(sigma3, sigma3 / 2, sigma3 * 2), mean=(0, -1, 1)) # fit DM2 dataset for resolution r3, f3 = reso3.fitTo(dset3, silent=True) r3, f3 = reso3.fitTo(dset3, silent=True, draw=True, nbins=100) # ========================================================================= # model for data fit # ========================================================================= signal1 = Models.Gauss_pdf('G1', xvar=mass, sigma=reso1.sigma, mean=(mean1, mean1 - 1, mean1 + 1)) signal2 = Models.Gauss_pdf('G2', xvar=mass, sigma=reso2.sigma, mean=(mean2, mean2 - 1, mean2 + 1)) signal3 = Models.Gauss_pdf('G3', xvar=mass, sigma=reso3.sigma, mean=(mean3, mean3 - 1, mean3 + 1)) background = Models.PolyPos_pdf('Bkg', xvar=mass, power=1) model = Models.Fit1D(signals=[signal1, signal2, signal3], background=background) model.S = NS1, NS2, NS3 model.B = NB # ========================================================================= ## Fit data (without resolution samples) # ========================================================================= r0, f0 = model.fitTo(dataset, silent=True) r0, f0 = model.fitTo(dataset, silent=True, draw=True, nbins=100) logger.info('Fit result (only data):\n%s' % r0.table(prefix="# ")) ## combine PDFs model_sim = Models.SimFit(category, { 'data': model, 'dm1': reso1, 'dm2': reso2, 'dm3': reso3 }, name='X') # ========================================================================= ## Simultanegous fit data with resolution samples) # ========================================================================= r_1, f_1 = model_sim.fitTo(cdataset1, silent=True) r_1, f_1 = model_sim.fitTo(cdataset1, silent=True) logger.info('Simultaneous fit result (unbinned reso):\n%s' % r_1.table(prefix="# ")) with use_canvas('test_simfit5'), wait(1): with wait(1): fdm1 = model_sim.draw('dm1', cdataset1, nbins=100) with wait(1): fdm2 = model_sim.draw('dm2', cdataset1, nbins=100) with wait(1): fdm3 = model_sim.draw('dm3', cdataset1, nbins=100) with wait(1): fd = model_sim.draw('data', cdataset1, nbins=100) # ========================================================================= ## Simultanegous fit data with resolution samples) # ========================================================================= r_2, f_2 = model_sim.fitTo(cdataset2, silent=True, sumw2=True) r_2, f_2 = model_sim.fitTo(cdataset2, silent=True, sumw2=True) logger.info('Simultaneous fit result (binned reso):\n%s' % r_2.table(prefix="# ")) with use_canvas('test_simfit5'), wait(1): with wait(1): fdm1 = model_sim.draw('dm1', cdataset2, nbins=100) with wait(1): fdm2 = model_sim.draw('dm2', cdataset2, nbins=100) with wait(1): fdm3 = model_sim.draw('dm3', cdataset2, nbins=100) with wait(1): fd = model_sim.draw('data', cdataset2, nbins=100)
import ROOT import ostap.fitting.models as Models from ostap.core.core import cpp #variables imc = ROOT.RooRealVar('imc', 'imc', 1., 3.) pk = ROOT.RooRealVar('pk', 'peak', 0.) #signal bw = cpp.Ostap.Math.BreitWigner(pk) sig_bw = Models.BreitWigner_pdf('sig_bw', breitwigner=bw, xvar=imc) sig_bw.gamma.setVal(0.20) sig_bw.gamma.setError(0.01) sig_bw.mean.setVal(2.10) sig_bw.mean.setError(0.10) #background bkg0 = Models.PolyPos_pdf('bkg', imc, power=1) bkg0.phis[0].setVal(2.72) bkg0.phis[0].setError(0.02) #compound model model = Models.Fit1D(signal=sig_bw, background=bkg0) model.draw()