def test_fit_bins(): import ROOT x = ROOT.RooRealVar('mbc', '', 0, 0, 1) pdf = Gauss(x) df = get_test_df(100) pdf.fit(df, nbins=5) assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)
def test_Convolution(): import ROOT df = get_test_df() assert isinstance(df, pd.DataFrame) bkg = Chebychev(('mbc', 0, 1)) sig = Gauss(('mbc', 0, 1)) pdf = Convolution(bkg, sig) assert isinstance(pdf, Convolution) assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)
def test_ProdPdf(): import ROOT df = get_test_df() assert isinstance(df, pd.DataFrame) bkg = Chebychev(('mbc', 0, 1)) sig = Gauss(('mbc', 0, 1)) pdf = sig * bkg assert isinstance(pdf, ProdPdf) assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)
def test_AddPdf_fit(): import ROOT df = get_test_df() assert isinstance(df, pd.DataFrame) bkg = Chebychev(('mbc', 0, 1)) sig = Gauss(('mbc', 0, 1)) pdf = sig + bkg pdf.fit(df) #pdf.plot('test2.pdf') assert isinstance(pdf, AddPdf) assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)
# -*- coding: utf-8 -*- """ Simple fit to a gaussian distribution (binned) In this example a fit is performed to a simple gaussion distribution. Observables can be initialised by a list with the column name / variable name as first argument, followed by the range and/or with the initial value and range: x = ('x', -3, 3) x = ('mass', -3, 0.02, 3) Parameters are initialised with a tuple: sigma=(0,1) or again including a starting parameter: sigma=(0.01, 0, 1) The order here is not important. All parameters and observables can also be initialised by a ROOT.RooRealVar. """ from pyroofit.models import Gauss import numpy as np data = np.random.normal(0, 1, 1000) pdf = Gauss(('x', -3, 3), mean=(-1, 0, 1)) pdf.fit(data, nbins=10) pdf.plot('simple_fit_binning.pdf',) pdf.get()
import ROOT df_mixed = { 'mass': np.append( np.random.random_sample(1000) * 7 - 3.5, np.random.normal(0, 0.5, 1000)) } df_mixed = pd.DataFrame(df_mixed) df_bkg = {'mass': np.random.random_sample(2000) * 7 - 3.5} df_bkg = pd.DataFrame(df_bkg) x = ROOT.RooRealVar('mass', 'M', 0, -3, 3, 'GeV') pdf_sig = Gauss(x, mean=(-1, 1)) pdf_bkg = Chebychev(x, n=1) pdf = pdf_sig + pdf_bkg sf = SimFit(pdf, pdf_bkg) sf.use_extended = True # bug sf.use_minos = True sf.fit([(pdf, df_mixed), (pdf_bkg, df_bkg)]) #pdf_bkg.plot('simultaneous_fit_bkg.pdf', df_bkg) pdf.plot('simultaneous_fit.pdf', df_mixed, nbins=20, extra_info=[["Legend"], ["More Legend"], ['#mu', *pdf_sig.get('mean')],
""" from pyroofit.models import Gauss, Chebychev from pyroofit.composites import AddPdf import numpy as np import pandas as pd import ROOT dist_signal = np.append(np.random.normal(750, 1.5, 500), np.random.normal(750, .5, 1000)) dist_background = np.random.random_sample(1000) * 10 + 745, df = pd.DataFrame({'mass': np.append(dist_signal, dist_background)}) x = ROOT.RooRealVar('mass', 'M', 750, 745, 755, 'GeV') # or x = ('mass', 745, 755) pdf_sig1 = Gauss(x, mean=(745, 755), sigma=(0.1, 1, 2), name="Gauss1") # We want to furthermore constrain the mean to be the same pdf_sig2 = Gauss(x, mean=pdf_sig1.parameters.mean, sigma=(0.1, 1, 2), name="Gauss2") pdf_bkg = Chebychev(x, n=1, name="bkg") pdf = AddPdf([pdf_sig1, pdf_sig2, pdf_bkg], name="model") pdf.fit(df) pdf.plot('multiple_pdfs.pdf', legend=True) pdf.get()
# -*- coding: utf-8 -*- """ Simple product pdf """ from pyroofit.models import Gauss import numpy as np import pandas as pd # Creating some pseudo data mean = (1, 2) cov = [[1, -.1], [-.1, 1]] x = np.random.multivariate_normal(mean, cov, 300) df = pd.DataFrame({'x': x[:, 0], 'y': x[:, 1]}) # Initialize the PDF pdf_x = Gauss(['x', -1, 5], mean=[0, 3], sigma=[0.1, 2], name='gx') pdf_y = Gauss(['y', -1, 5], mean=[0, 3], sigma=pdf_x.parameters.sigma, name='gy') pdf = pdf_x * pdf_y # Fit pdf.fit(df) pdf.get()
The order here is not important. All parameters and observables can also be initialised by a ROOT.RooRealVar. """ from pyroofit.models import Gauss, Chebychev import numpy as np import pandas as pd import ROOT df = { 'mass': np.append( np.random.random_sample(1000) * 10 + 745, np.random.normal(750, 1, 1000)) } df = pd.DataFrame(df) x = ROOT.RooRealVar('mass', 'M', 750, 745, 755, 'GeV') # or x = ('mass', 745, 755) pdf_sig = Gauss(x, mean=(745, 755), sigma=(0.1, 1, 2), title="Signal") pdf_bkg = Chebychev(x, n=1, title="Background") pdf = pdf_sig + pdf_bkg pdf.fit(df) pdf.plot('signal_and_background.pdf', legend=True) pdf.get()
def test_PDF_Gauss(): import ROOT x = ROOT.RooRealVar('mbc', '', 0, 0, 1) pdf = Gauss(x) assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)