def test_parallel_significance_toys(): """Perform toy-study for significance of the signal - generate `nToys` pseudoexperiments using background-only hypothesis - fit each experiment with signal+background hypothesis - store fit results - fill distributions for fit results """ ## only background hypothesis bkg_only = Models.Bkg_pdf("BKG", xvar=mass, power=0, tau=0) signal = Models.Gauss_pdf('S', xvar=mass, mean=0.5, sigma=0.1) signal.mean.fix(0.4) signal.sigma.fix(0.1) ## signal + background hypothesis model = Models.Fit1D(signal=signal, background=1) model.background.tau.fix(0) results, stats = Toys.parallel_toys2( gen_pdf=bkg_only, fit_pdf=model, nToys=1000, nSplit=20, data=[mass], gen_config={ 'nEvents': 100, 'sample': True }, fit_config={'silent': True}, gen_pars={'tau_BKG': 0.}, ## initial values for generation fit_pars={ 'B': 100, 'S': 10, 'phi0_Bkg_S': 0.0 }, ## initial fit values for parameters silent=True, progress=False) for p in stats: logger.info("Toys: %-20s : %s" % (p, stats[p])) h_S = ROOT.TH1F(hID(), '#S', 60, 0, 60) for r in results['S']: h_S.Fill(r) for h in (h_S, ): h.draw() logger.info("%s :\n%s" % (h.GetTitle(), h.dump(30, 10))) time.sleep(1)
def test_parallel_toys2(): """Perform toys-study for possible fit bias and correct uncertainty evaluation - generate `nToys` pseudoexperiments with some PDF `gen_pdf` - fit teach experiment with the PDF `fit_pdf` - store fit results - fill distributions of fit results """ results, stats = Toys.parallel_toys2(gen_pdf=gen_gauss, fit_pdf=fit_gauss, nToys=1000, nSplit=20, data=[mass], gen_config={ 'nEvents': 200, 'sample': True }, fit_config={'silent': True}, gen_pars={ 'mean_GG': 0.4, 'sigma_GG': 0.1 }, fit_pars={ 'mean_GF': 0.4, 'sigma_GF': 0.1 }, silent=True, progress=False) for p in stats: logger.info("Toys: %-20s : %s" % (p, stats[p])) ## make histos h_mean = ROOT.TH1F(hID(), 'mean of Gauss ', 50, 0, 0.80) h_sigma = ROOT.TH1F(hID(), 'sigma of Gauss', 50, 0.05, 0.15) for r in results['mean_FG']: h_mean.Fill(r) for r in results['sigma_FG']: h_sigma.Fill(r) for h in (h_mean, h_sigma): h.draw() logger.info("%s :\n%s" % (h.GetTitle(), h.dump(30, 10))) time.sleep(1)