Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_fit():
import ROOT
x = ROOT.RooRealVar('mbc', '', 0, 0, 1)
pdf = Gauss(x)
df = get_test_df(100)
pdf.fit(df)
assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)
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_AddPdf():
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)
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)
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_PDF_Gauss():
import ROOT
x = ROOT.RooRealVar('mbc', '', 0, 0, 1)
pdf = Gauss(x)
assert isinstance(pdf.roo_pdf, ROOT.RooAbsPdf)
from pyroofit.models import Gauss, Chebychev
from pyroofit.composites import SimFit
import numpy as np
import pandas as pd
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')], ['#sigma', *pdf_sig.get('sigma')]])
pdf.get()
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)
pdf.plot('simple_fit.pdf',)
pdf.get()
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()