def test_simfit2 ( ) : # ========================================================================= signal1 = Models.Gauss_pdf ( 'G1' , xvar = mass1 , mean = (1.5 , 6.5 ) , sigma = (0.1 , 2.5 ) ) model1 = Models.Fit1D ( suffix = 'M1' , signal = signal1 , background = -1 ) model1.S = NS1 model1.B = NB1 mean2 = signal1.vars_add ( signal1.mean , 10.0 ) sigma2 = signal1.vars_multiply ( signal1.sigma , 0.5 ) signal2 = Models.Gauss_pdf ( 'G2' , xvar = mass2 , mean = mean2 , sigma = sigma2 ) model2 = Models.Fit1D ( suffix = 'M2' , signal = signal2 , background = -1 ) model2.S = NS2 model2.B = NB2 # ========================================================================= ## fit 1 r1 , f1 = model1.fitTo ( dataset1 , draw = True , nbins = 50 , silent = True ) ## fit 2 r2 , f2 = model2.fitTo ( dataset2 , draw = True , nbins = 50 , silent = True ) # ========================================================================= ## combine data sample = ROOT.RooCategory ('sample','sample' , 'A' , 'B' ) ## combine datasets from ostap.fitting.simfit import combined_data vars = ROOT.RooArgSet ( mass1 , mass2 ) dataset = combined_data ( sample , vars , { 'A' : dataset1 , 'B' : dataset2 } ) ## combine PDFs model_sim = Models.SimFit ( sample , { 'A' : model1 , 'B' : model2 } , name = 'X' ) # ========================================================================= r , f = model_sim.fitTo ( dataset , silent = True ) r , f = model_sim.fitTo ( dataset , silent = True ) fA = model_sim.draw ( 'A' , dataset , nbins = 50 ) fB = model_sim.draw ( 'B' , dataset , nbins = 50 ) fNLL = model_sim.draw_nll ( 'SM2' , dataset , range = (0,1000) ) ## significance wilks = model_sim.wilks ( 'SM2' , dataset ) logger.info ( 'Fit results are: %s ' % r )
def test_simfit2(): logger = getLogger('test_simfit2') # ========================================================================= signal1 = Models.Gauss_pdf('G1', xvar=mass1, mean=(1.5, 6.5), sigma=(0.1, 2.5)) model1 = Models.Fit1D(suffix='M1', signal=signal1, background=-1) model1.S = NS1 model1.B = NB1 mean2 = signal1.vars_add(signal1.mean, 10.0) sigma2 = signal1.vars_multiply(signal1.sigma, 0.5) signal2 = Models.Gauss_pdf('G2', xvar=mass2, mean=mean2, sigma=sigma2) model2 = Models.Fit1D(suffix='M2', signal=signal2, background=-1) model2.S = NS2 model2.B = NB2 with use_canvas('test_simfit2'): # ========================================================================= ## fit 1 with wait(1): r1, f1 = model1.fitTo(dataset1, draw=True, nbins=50, silent=True) title = 'Results of fit to dataset1' logger.info('%s\n%s' % (title, r1.table(title=title, prefix='# '))) ## fit 2 with wait(1): r2, f2 = model2.fitTo(dataset2, draw=True, nbins=50, silent=True) title = 'Results of fit to dataset2' logger.info('%s\n%s' % (title, r2.table(title=title, prefix='# '))) # ========================================================================= ## combine data sample = ROOT.RooCategory('sample', 'sample', 'A', 'B') ## combine datasets from ostap.fitting.simfit import combined_data vars = ROOT.RooArgSet(mass1, mass2) dataset = combined_data(sample, vars, {'A': dataset1, 'B': dataset2}) ## combine PDFs model_sim = Models.SimFit(sample, {'A': model1, 'B': model2}, name='X') # ========================================================================= r, f = model_sim.fitTo(dataset, silent=True) r, f = model_sim.fitTo(dataset, silent=True) title = 'Results of simultaneous fit' logger.info('%s\n%s' % (title, r.table(title=title, prefix='# '))) with use_canvas('test_simfit2'): with wait(1): fA = model_sim.draw('A', dataset, nbins=50) with wait(1): fB = model_sim.draw('B', dataset, nbins=50)
def test_simfit1(): logger = getLogger('test_simfit1') signal1 = Models.Gauss_pdf('G1', xvar=mass, mean=(0.5, 2.5), sigma=(0.1, 1.0)) model1 = Models.Fit1D(suffix='M1', signal=signal1, background=-1) model1.S = NS1 model1.B = NB1 mean2 = signal1.vars_add(signal1.mean, 1.0) sigma2 = signal1.vars_multiply(signal1.sigma, 0.5) signal2 = Models.Gauss_pdf('G2', xvar=mass, mean=mean2, sigma=sigma2) model2 = Models.Fit1D(suffix='M2', signal=signal2, background=model1.background) model2.S = NS2 model2.B = NB2 with use_canvas('test_simfit1'): # ========================================================================= ## fit 1 with wait(1): r1, f1 = model1.fitTo(dataset1, draw=True, nbins=50, silent=True) ## fit 2 with wait(1): r2, f2 = model2.fitTo(dataset2, draw=True, nbins=50, silent=True) # ========================================================================= ## combine data sample = ROOT.RooCategory('sample', 'sample', 'A', 'B') ## combine datasets from ostap.fitting.simfit import combined_data vars = ROOT.RooArgSet(mass) dataset = combined_data(sample, vars, {'A': dataset1, 'B': dataset2}) ## combine PDFs model_sim = Models.SimFit(sample, {'A': model1, 'B': model2}, name='X') # ========================================================================= r, f = model_sim.fitTo(dataset, silent=True) r, f = model_sim.fitTo(dataset, silent=True) with use_canvas('test_simfit1'): with wait(1): fA = model_sim.draw('A', dataset, nbins=50) with wait(1): fB = model_sim.draw('B', dataset, nbins=50) logger.info('Fit results are: %s ' % r)
def test_extended2(): logger.info('Test extended combined multi-component fit') model = Models.Fit1D( name='E2', signal=signal_1, othersignals=[signal_2, signal_3], background=Models.Bkg_pdf('P1', xvar=mass, power=0, tau=0), otherbackgrounds=[wide_1, wide_2], others=[narrow_1, narrow_2], combine_signals=True, ## ATTENTION! combine_others=True, ## ATTENTION! combine_backgrounds=True, ## ATTENTION! ) with rooSilent(): model.S.fix(15000) model.B.fix(7000) model.C.fix(2000) r, f = model.fitTo(dataset, draw=False, silent=True) model.S.release() model.B.release() model.C.release() r, f = model.fitTo(dataset, draw=False, silent=True) logger.info('Model %s Fit result \n#%s ' % (model.name, r))
def test_voigt(): logger.info('Test Voigt_pdf: Breit-Wigner convoluted with Gauss') model = Models.Fit1D(signal=Models.Voigt_pdf('V', xvar=mass, m0=signal_gauss.mean, sigma=signal_gauss.sigma), background=Models.Bkg_pdf('BkgV', xvar=mass, power=0), S=S, B=B) signal = model.signal signal.sigma.fix(m.error()) signal.gamma.fix(0.002) signal.m0.fix() model.B.setVal(500) model.S.setVal(5000) with rooSilent(): result, frame = model.fitTo(dataset0) result, frame = model.fitTo(dataset0) signal.sigma.release() result, frame = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Voigt function\n%s" % result.table(prefix="# ")) models.add(model)
def test_losev(): logger.info("Test Losev: asymmetric hyperbilic secant distribution") model = Models.Fit1D(signal=Models.Losev_pdf('LOSEV', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgLOSEV', xvar=mass, power=0), S=S, B=B) signal = model.signal model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.alpha.release() signal.beta.release() result, f = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Asymmetric hyperbolic secant/Losev distribution\n%s" % result.table(prefix="# ")) models.add(model)
def test_atlas(): logger.info("Test ATLAS: Modified Gaussian, used by ATLAS/Zeus") model = Models.Fit1D(signal=Models.Atlas_pdf('ATLAS', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgATLAS', xvar=mass, power=0), S=S, B=B) signal = model.signal model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.sigma.release() result, f = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("ATLAS function\n%s" % result.table(prefix="# ")) models.add(model)
def test_studentT(): logger.info('Test StudentT_pdf: Student-t distribution') model_student = Models.Fit1D(signal=Models.StudentT_pdf( name='ST', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgST', xvar=mass, power=0), S=S, B=B) model_student.signal.n.setVal(20) model_student.signal.sigma.setVal(0.013) model_student.S.setVal(5000) model_student.B.setVal(500) with rooSilent(): result, frame = model_student.fitTo(dataset0) result, frame = model_student.fitTo(dataset0) model_student.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Student's t-function\n%s" % result.table(prefix="# ")) models.add(model_student)
def test_skewgauss(): logger.info('Test SkewGauss_pdf: Skew Gaussian function') model_gauss_skew = Models.Fit1D(signal=Models.SkewGauss_pdf( name='GSk', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgSkG', xvar=mass, power=0), S=S, B=B) model_gauss_skew.signal.alpha.fix(0) model_gauss_skew.S.setVal(5000) model_gauss_skew.B.setVal(500) with rooSilent(): result, frame = model_gauss_skew.fitTo(dataset0) result, frame = model_gauss_skew.fitTo(dataset0) model_gauss_skew.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('skew Gaussian function\n%s' % result.table(prefix="# ")) models.add(model_gauss_skew)
def test_crystalball(): logger.info('Test CrystalBall_pdf: Crystal Ball function') ## composite model: signal + background model_cb = Models.Fit1D( signal=Models.CrystalBall_pdf( name='CB', ## the name xvar=mass, ## the variable alpha=(2, 1, 5), ## tail parameter n=(3, 1, 9), ## tail parameter sigma=signal_gauss.sigma, ## reuse sigma from gauss mean=signal_gauss.mean), ## reuse mean from gauss background=Models.Bkg_pdf('BkgCB', xvar=mass, power=0), S=S, B=B) model_cb.signal.n.fix(8) with rooSilent(): result, frame = model_cb.fitTo(dataset0) model_cb.signal.alpha.release() result, frame = model_cb.fitTo(dataset0) result, frame = model_cb.fitTo(dataset0) model_cb.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Crystal Ball function\n%s' % result.table(prefix="# ")) models.add(model_cb)
def test_laplace(): logger.info('Test Asymmetric Laplace shape') model = Models.Fit1D( signal=Models.AsymmetricLaplace_pdf(name='AL', xvar=mass, mean=signal_gauss.mean, slope=signal_gauss.sigma), background=None, S=S, B=B) signal = model.signal signal.slope.release() signal.mean.fix() model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, frame = model.fitTo(dataset0) result, frame = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("asymmetric Laplace function\n%s" % result.table(prefix="# ")) models.add(model)
def test_logistic(): logger.info("Test LOGISTIC: Logistic distribution") model = Models.Fit1D(signal=Models.Logistic_pdf('LOGI', mass=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgLOGI', mass=mass, power=0)) signal = model.signal model.s.setVal(5000) model.b.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.sigma.release() result, f = model.fitTo(dataset0) 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: logger.info('Signal & Background are: %-28s & %-28s ' % (result('S')[0], result('B')[0])) logger.info('Mean is: %-28s ' % result(signal.mean)[0]) logger.info('Sigma is: %-28s ' % result(signal.sigma)[0]) models.add(model)
def test_atlas(): logger.info("Test ATLAS: Modified Gaussian, used by ATLAS/Zeus") model = Models.Fit1D(signal=Models.Atlas_pdf('ATLAS', mass=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgATLAS', mass=mass, power=0)) signal = model.signal model.s.setVal(5000) model.b.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.sigma.release() result, f = model.fitTo(dataset0) 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: logger.info('Signal & Background are: %-28s & %-28s ' % (result('S')[0], result('B')[0])) logger.info('Mean is: %-28s ' % result(signal.mean)[0]) logger.info('Sigma is: %-28s ' % result(signal.sigma)[0]) models.add(model)
def test_gauss(): logger.info('Test Gauss_pdf: simple Gaussian signal') ## release the sigma of signal: signal_gauss.mean.release() ## simple fit with gaussian only result = signal_gauss.fitTo(dataset0, silent=True) ## construct composite model: signal + background model_gauss = Models.Fit1D(signal=signal_gauss, background=Models.Bkg_pdf('BkgGauss', mass=mass, power=0)) model_gauss.background.tau.fix(0) with rooSilent(): result, frame = model_gauss.fitTo(dataset0) result, frame = model_gauss.fitTo(dataset0) 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: logger.info('Signal & Background are: %-28s & %-28s ' % (result('S')[0], result('B')[0])) logger.info('Mean & Sigma are: %-28s & %-28s ' % (result('mean_Gauss')[0], result('sigma_Gauss')[0])) models.add(model_gauss) signal_gauss.mean.fix(m.value())
def test_studentT(): logger.info('Test StudentT_pdf: Student-t distribution') model_student = Models.Fit1D(signal=Models.StudentT_pdf( name='ST', mass=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgST', mass=mass, power=0)) model_student.signal.n.setVal(20) model_student.signal.sigma.setVal(0.013) model_student.s.setVal(5000) model_student.b.setVal(500) with rooSilent(): result, frame = model_student.fitTo(dataset0) result, frame = model_student.fitTo(dataset0) 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: logger.info('Signal & Background are: %-28s & %-28s ' % (result('S')[0], result('B')[0])) logger.info('Mean is : %-28s ' % result('mean_Gauss')[0]) models.add(model_student)
def test_2gauss(): logger.info('Test DoubleGauss_pdf: Double Gaussian') signal_2gauss = Models.DoubleGauss_pdf(name='Gau2', mean=signal_gauss.mean, sigma=signal_gauss.sigma, xvar=mass, fraction=0.9, scale=1.2) model_2gauss = Models.Fit1D(signal=signal_2gauss, background=Models.Bkg_pdf('Bkg22G', xvar=mass, power=0), S=S, B=B) model_2gauss.B.setVal(500) model_2gauss.S.setVal(6000) with rooSilent(): result, frame = model_2gauss.fitTo(dataset0) signal_2gauss.fraction.release() result, frame = model_2gauss.fitTo(dataset0) model_2gauss.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('double Gaussian function\n%s' % result.table(prefix="# ")) models.add(model_2gauss)
def test_gengauss_v1(): logger.info('Test GenGaussV1_pdf: Generalized Gaussian V1') model_gauss_gv1 = Models.Fit1D(signal=Models.GenGaussV1_pdf( name='Gv1', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgGGV1', xvar=mass, power=0), S=S, B=B) model_gauss_gv1.signal.beta.fix(2) model_gauss_gv1.signal.mean.fix(m.value()) model_gauss_gv1.S.setVal(5000) model_gauss_gv1.B.setVal(500) with rooSilent(): result, frame = model_gauss_gv1.fitTo(dataset0) model_gauss_gv1.signal.alpha.release() result, frame = model_gauss_gv1.fitTo(dataset0) model_gauss_gv1.signal.mean.release() result, frame = model_gauss_gv1.fitTo(dataset0) model_gauss_gv1.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('generalized Gaussian(v1) function\n%s' % result.table(prefix="# ")) models.add(model_gauss_gv1)
def test_rasingcosine(): logger.info("Test RaisingCosine") model = Models.Fit1D(signal=Models.RaisingCosine_pdf( 'RC', xvar=mass, mean=signal_gauss.mean), background=1, S=S, B=B) signal = model.signal model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.scale.release() result, f = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Raising cosine function\n%s" % result.table(prefix="# ")) models.add(model)
def test_qgauss(): logger.info('Test QGaussian_pdf: q-Gaussian') model_qgauss = Models.Fit1D(signal=Models.QGaussian_pdf( name='qG', xvar=mass, q=(1, 0.7, 1.2), mean=signal_gauss.mean, scale=signal_gauss.sigma), background=Models.Bkg_pdf('BkgQG', xvar=mass, power=0), S=S, B=B) s = model_qgauss.signal s.scale = 0.015 with rooSilent(): result, frame = model_qgauss.fitTo(dataset0) model_qgauss.signal.scale.release() result, frame = model_qgauss.fitTo(dataset0) model_qgauss.signal.q.release() result, frame = model_qgauss.fitTo(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Q-Gaussian function\n%s' % result.table(prefix="# ")) models.add(model_qgauss)
def test_hyperbolic(): logger.info( 'Test Hyperbolic_pdf: hyperbolic distribution (exponential tails)') model_hyperbolic = Models.Fit1D(signal=Models.Hyperbolic_pdf( name='HB', xvar=mass, mu=signal_gauss.mean, sigma=signal_gauss.sigma, zeta=(1, -1, 1e+6), kappa=(0, -1, 1)), background=Models.Bkg_pdf('BkgHB', xvar=mass, power=0), S=S, B=B) model_hyperbolic.S.value = 5000 model_hyperbolic.B.value = 500 with rooSilent(): model_hyperbolic.signal.kappa.fix(0) result, frame = model_hyperbolic.fitTo(dataset0) model_hyperbolic.signal.kappa.release() result, frame = model_hyperbolic.fitTo(dataset0) model_hyperbolic.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Hyperbolic function\n%s' % result.table(prefix="# ")) models.add(model_hyperbolic)
def test_johnsonSU(): logger.info("Test JohnsonSU-Distribution") model = Models.Fit1D(signal=Models.JohnsonSU_pdf('JSU', xvar=mass, xi=signal_gauss.mean), background=Models.Bkg_pdf('BkgJSU', xvar=mass, power=0), S=S, B=B) signal = model.signal model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.lambd.release() signal.delta.release() result, f = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Johnson-SU function\n%s" % result.table(prefix="# ")) models.add(model)
def test_crystalball_RS(): logger.info('Test CrystalBallRS_pdf: right-side Crystal Ball function') model_cbrs = Models.Fit1D(signal=Models.CrystalBallRS_pdf( name='CBRS', xvar=mass, sigma=signal_gauss.sigma, alpha=(1.5, 0.5, 3.0), n=(5, 1, 10), mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgCBRS', xvar=mass, power=0), S=S, B=B) model_cbrs.S.value = 5000 model_cbrs.B.value = 500 with rooSilent(): result, frame = model_cbrs.fitTo(dataset0) model_cbrs.signal.alpha.release() result, frame = model_cbrs.fitTo(dataset0) result, frame = model_cbrs.fitTo(dataset0) model_cbrs.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('right-side Crystal Ball function\n%s' % result.table(prefix="# ")) models.add(model_cbrs)
def test_sech(): logger.info("Test SECH: Sech(1/cosh) distribution") model = Models.Fit1D(signal=Models.Sech_pdf('SECH', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgSECH', xvar=mass, power=0), S=S, B=B) signal = model.signal model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.sigma.release() result, f = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Hyperbolic secant/sech function\n%s" % result.table(prefix="# ")) models.add(model)
def test_needham(): logger.info('Test Needham_pdf: Crystal Ball with alpha=f(sigma)') model_matt = Models.Fit1D(signal=Models.Needham_pdf( name='Matt', xvar=mass, sigma=signal_gauss.sigma, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgMATT', xvar=mass, power=0), S=S, B=B) with rooSilent(): result, frame = model_matt.fitTo(dataset0) model_matt.signal.mean.release() model_matt.signal.sigma.release() result, frame = model_matt.fitTo(dataset0) result, frame = model_matt.fitTo(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Needham function\n%s' % result.table(prefix="# ")) models.add(model_matt)
def test_logistic(): logger.info("Test LOGISTIC: Logistic distribution") model = Models.Fit1D(signal=Models.Logistic_pdf('LOGI', xvar=mass, mean=signal_gauss.mean), background=Models.Bkg_pdf('BkgLOGI', xvar=mass, power=0), S=S, B=B) signal = model.signal model.S.setVal(5000) model.B.setVal(500) with rooSilent(): result, f = model.fitTo(dataset0) result, f = model.fitTo(dataset0) signal.mean.release() signal.sigma.release() result, f = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("Logistic distribution\n%s" % result.table(prefix="# ")) models.add(model)
def test_apollonios(): logger.info( 'Test Apollonios_pdf: Modified gaussian with power-law and exponential tails' ) model_apollonios = Models.Fit1D(signal=Models.Apollonios_pdf( name='APO', xvar=mass, mean=signal_gauss.mean, sigma=signal_gauss.sigma, b=1, n=10, alpha=3), background=Models.Bkg_pdf('BkgAPO', xvar=mass, power=0), S=S, B=B) model_apollonios.S.setVal(5000) model_apollonios.B.setVal(500) with rooSilent(): result, frame = model_apollonios.fitTo(dataset0) result, frame = model_apollonios.fitTo(dataset0) model_apollonios.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Apollonios function\n%s' % result.table(prefix="# ")) models.add(model_apollonios)
def test_pvoigt(): logger.info('Test PSeudoVoigt_pdf: fast approximation to Voigt profile') model = Models.Fit1D( signal=Models.PseudoVoigt_pdf('PV', xvar=mass, m0=signal_gauss.mean, sigma=signal_gauss.sigma), background=Models.Bkg_pdf('BkgPV', xvar=mass, power=0), S=S, B=B) signal = model.signal signal.m0.fix() signal.sigma.fix(m.error()) signal.gamma.fix(0.002) model.B.setVal(500) model.S.setVal(5000) with rooSilent(): result, frame = model.fitTo(dataset0) result, frame = model.fitTo(dataset0) model.signal.sigma.release() result, frame = model.fitTo(dataset0) model.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info("pseudo-Voigt function\n%s" % result.table(prefix="# ")) models.add(model)
def test_apollonios2(): logger.info( 'Test Apollonios2_pdf: modified Gaussian with exponential tails') model_apollonios2 = Models.Fit1D(signal=Models.Apollonios2_pdf( name='AP2', xvar=mass, mean=signal_gauss.mean, sigma=signal_gauss.sigma, beta=(0.5, 2), asymmetry=0), background=Models.Bkg_pdf('BkgAPO2', xvar=mass, power=0), S=S, B=B) model_apollonios2.signal.mean.fix(m.value()) model_apollonios2.S.value = 5000 model_apollonios2.B.value = 500 model_apollonios2.signal.sigma.release() with rooSilent(): result, frame = model_apollonios2.fitTo(dataset0) model_apollonios2.signal.asym.release() result, frame = model_apollonios2.fitTo(dataset0) model_apollonios2.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Apollonios2 function\n%s' % result.table(prefix="# ")) models.add(model_apollonios2)
def test_nonextended1(): logger.info('Test non-extended multi-component fit') model = Models.Fit1D( name='N1', signal=signal_1, othersignals=[signal_2, signal_3], background=Models.Bkg_pdf('P2', xvar=mass, power=0, tau=0), otherbackgrounds=[wide_1, wide_2], others=[narrow_1, narrow_2], extended=False ## ATTENTION! ) model.F[0].setVal(0.20) model.F[1].setVal(0.25) model.F[2].setVal(0.36) model.F[3].setVal(0.65) model.F[4].setVal(0.05) model.F[5].setVal(0.25) model.F[6].setVal(0.50) r, f = model.fitTo(dataset, draw=False, silent=True) logger.info('Model %s Fit result \n#%s ' % (model.name, r))
def test_bifurcated(): logger.info('Test BifurcatedGauss_pdf: Bifurcated Gaussian') signal_bifurcated = Models.BifurcatedGauss_pdf(name='BfGau', mean=signal_gauss.mean, sigma=signal_gauss.sigma, xvar=mass) signal_bifurcated.asym.setVal(0) model_bifurcated = Models.Fit1D(signal=signal_bifurcated, background=Models.Bkg_pdf('BkgBFG', xvar=mass, power=0), S=S, B=B) model_bifurcated.B.setVal(500) model_bifurcated.S.setVal(6000) with rooSilent(): result, frame = model_bifurcated.fitTo(dataset0) result, frame = model_bifurcated.fitTo(dataset0) model_bifurcated.draw(dataset0) if 0 != result.status() or 3 != result.covQual(): logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % (result.status(), result.covQual())) logger.info('Bifurcated Gaussian function\n%s' % result.table(prefix="# ")) models.add(model_bifurcated)