From d558db95b15c16a522d0f2af5a990f4a524fc2fd Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Fri, 6 Apr 2018 12:24:02 +0200 Subject: [PATCH 01/28] Added the double crystal ball function --- probfit/pdf.pyx | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/probfit/pdf.pyx b/probfit/pdf.pyx index 275554b..1280781 100644 --- a/probfit/pdf.pyx +++ b/probfit/pdf.pyx @@ -218,6 +218,43 @@ cpdef double crystalball(double x, double alpha, double n, double mean, double s ret = A*pow(B-d,-n) return ret +cpdef double doublecrystalball(double x, double alpha, double alpha2, double n, double n2, double mean, double sigma): + """ + Unnormalized double crystal ball function + A gaussian core with two power tails + + + + """ + cdef double d = 0. + cdef double ret = 0 + cdef double A = 0 + cdef double B = 0 + cdef double A2 = 0 + cdef double B2 = 0 + if sigma < smallestdiv: + ret = badvalue + elif fabs(alpha) < smallestdiv: + ret = badvalue + elif n<1.: + ret = badvalue + else: + d = (x-mean)/sigma + if d<-alpha: + al = fabs(alpha) + A=pow(n/al,n)*exp(-al**2/2.) + B=n/al-al + ret = A*pow(B-d,-n) + + elif d < alpha2 : + ret = exp(-0.5*d**2) + else: + al2 = fabs(alpha2) + A2=pow(n2/al2,n2)*exp(-al2**2/2.) + B2=n2/a2-a2 + ret = A2*pow(B2+d,-n2) + return ret + #Background stuff cpdef double argus(double x, double c, double chi, double p): From 563a3a897c896f12d49f25e31380f1b47c177126 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Mon, 9 Apr 2018 23:26:33 +0200 Subject: [PATCH 02/28] add double crystal ball function --- probfit/pdf.pxd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/probfit/pdf.pxd b/probfit/pdf.pxd index 307a050..64af693 100644 --- a/probfit/pdf.pxd +++ b/probfit/pdf.pxd @@ -21,3 +21,5 @@ cpdef double novosibirsk(double x, double width, double peak, double tail) cpdef double rtv_breitwigner(double x, double m, double gamma) cpdef double cauchy(double x, double m, double gamma) + +cpdef double doublecrystalball(double x, double alpha, double alpha2, double n, double n2, double mean, double sigma) From 8e962d988d5d5b2efd455ad4ab3c341dfa695b22 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Tue, 10 Apr 2018 10:22:56 +0200 Subject: [PATCH 03/28] Update __init__.py --- probfit/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/probfit/__init__.py b/probfit/__init__.py index 4209527..eaa54f7 100644 --- a/probfit/__init__.py +++ b/probfit/__init__.py @@ -38,6 +38,7 @@ 'cauchy', 'rtv_breitwigner', 'crystalball', + 'doublecrystalball', 'describe', 'doublegaussian', 'draw_compare', From 54f9362a8e34e87e36f0eec4fcc937e7dc88a2d9 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Tue, 10 Apr 2018 10:23:38 +0200 Subject: [PATCH 04/28] Update __init__.py --- probfit/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/probfit/__init__.py b/probfit/__init__.py index eaa54f7..14f0990 100644 --- a/probfit/__init__.py +++ b/probfit/__init__.py @@ -6,7 +6,7 @@ """ from .costfunc import UnbinnedLH, BinnedLH, Chi2Regression, BinnedChi2, SimultaneousFit -from .pdf import doublegaussian, ugaussian, gaussian, crystalball, \ +from .pdf import doublegaussian, doublecrystalball, ugaussian, gaussian, crystalball, \ argus, cruijff, linear, poly2, poly3, novosibirsk, \ Polynomial, HistogramPdf, cauchy, rtv_breitwigner from .toy import gen_toy, gen_toyn From a9b30022b9154a00e736b237f91a60ce6439bd9e Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 15:57:29 +0200 Subject: [PATCH 05/28] Create doublecrystalball.py --- doc/pyplots/pdf/doublecrystalball.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 doc/pyplots/pdf/doublecrystalball.py diff --git a/doc/pyplots/pdf/doublecrystalball.py b/doc/pyplots/pdf/doublecrystalball.py new file mode 100644 index 0000000..627a86a --- /dev/null +++ b/doc/pyplots/pdf/doublecrystalball.py @@ -0,0 +1,14 @@ +from probfit.pdf import doublecrystalball +from probfit.plotting import draw_normed_pdf +import matplotlib.pyplot as plt + +bound = (5.22, 5.30) + +arg = dict(alpha=1.,alpha2=1., n=2.,n2=2, mean=5.28, sigma=0.01) +draw_normed_pdf(crystalball, arg=arg, bound=bound, label=str(arg), density=True) + +arg = dict(alpha=0.5, alpha2=0.5, n=10., n2=10., mean=5.28, sigma=0.005) +draw_normed_pdf(crystalball, arg=arg, bound=bound, label=str(arg), density=True) + +plt.grid(True) +plt.legend().get_frame().set_alpha(0.5) From 43cbb529ef52c2e59772e6bbddd01fe6173aae1a Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 16:00:57 +0200 Subject: [PATCH 06/28] Update api.rst --- doc/api.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/api.rst b/doc/api.rst index caa63fc..9e7af08 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -173,6 +173,13 @@ crystalball .. plot:: pyplots/pdf/crystalball.py :class: lightbox +doublecrystalball +^^^^^^^^^^^ +.. autofunction:: doublecrystalball + +.. plot:: pyplots/pdf/doublecrystalball.py + :class: lightbox + cruijff ^^^^^^^ .. autofunction:: cruijff From 1615ee26238403897535139a06e30da22ea664dc Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 16:02:44 +0200 Subject: [PATCH 07/28] Update index.rst --- doc/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/index.rst b/doc/index.rst index 215c36b..9610b85 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -100,6 +100,7 @@ and send us pull request. .. autosummary:: gaussian crystalball + doublecrystalball cruijff cauchy rtv_breitwigner From 4af40eb87665551ff895d2eb560ef7083bb68bbf Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 17:16:09 +0200 Subject: [PATCH 08/28] Update pdf.pyx --- probfit/pdf.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/probfit/pdf.pyx b/probfit/pdf.pyx index 1280781..e980500 100644 --- a/probfit/pdf.pyx +++ b/probfit/pdf.pyx @@ -251,7 +251,7 @@ cpdef double doublecrystalball(double x, double alpha, double alpha2, double n, else: al2 = fabs(alpha2) A2=pow(n2/al2,n2)*exp(-al2**2/2.) - B2=n2/a2-a2 + B2=n2/al2-al2 ret = A2*pow(B2+d,-n2) return ret From 44cb01a4ed7f1fcae4cd76c367a479b389e59418 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 17:27:15 +0200 Subject: [PATCH 09/28] Update test_toy.py --- tests/test_toy.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test_toy.py b/tests/test_toy.py index d5a9aa4..8a87892 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -2,7 +2,7 @@ import matplotlib matplotlib.use('Agg', warn=False) from probfit.nputil import mid -from probfit.pdf import crystalball, gaussian +from probfit.pdf import crystalball, gaussian, doublecrystalball from probfit.functor import Normalized from probfit.toy import gen_toy from probfit._libstat import compute_chi2 @@ -35,7 +35,32 @@ def test_gen_toy(): print(chi2, len(bins), chi2 / len(bins)) assert (0.9 < (chi2 / len(bins)) < 1.1) + +def test_gen_toy3(): + np.random.seed(0) + bound = (-1, 2) + ntoy = 100000 + toy = gen_toy(doublecrystalball, ntoy, bound=bound, + alpha=1., alpha2=1., n=2.,n2=2., mean=1., sigma=0.3, quiet=False) + + assert len(toy) == ntoy + htoy, bins = np.histogram(toy, bins=1000, range=bound) + + ncball = Normalized(doublecrystalball, bound) + + f = lambda x: ncball(x, 1., 1., 2., 2., 1., 0.3) + + expected = vector_apply(f, mid(bins)) * ntoy * (bins[1] - bins[0]) + + htoy = htoy * 1.0 + err = np.sqrt(expected) + + chi2 = compute_chi2(htoy, expected, err) + + print(chi2, len(bins), chi2 / len(bins)) + + assert (0.9 < (chi2 / len(bins)) < 1.1) def test_gen_toy2(): pdf = gaussian From 39c09c0cd77a13ed77115990effb3bb5a74c43e9 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 17:34:55 +0200 Subject: [PATCH 10/28] Update test_func.py --- tests/test_func.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_func.py b/tests/test_func.py index fe66993..2193593 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -66,7 +66,15 @@ def test_crystalball(): assert_allclose(pdf.crystalball(14, 1, 2, 10, 2), 0.1353352832366127) assert_allclose(pdf.crystalball(6, 1, 2, 10, 2), 0.26956918209450376) - +# cpdef double doubecrystalball(double x,double alpha,double alpha2, double n,double n2, double mean,double sigma) +def test_doublecrystalball(): + assert describe(pdf.doublecrystalball) == ['x', 'alpha', 'alpha2', 'n', 'n2', 'mean', 'sigma'] + assert_allclose(pdf.doublecrystalball(10, 1, 1, 2, 2, 10, 2), 1.) + assert_allclose(pdf.doublecrystalball(11, 1, 1, 2, 2, 10, 2), 0.8824969025845955) + assert_allclose(pdf.doublecrystalball(12, 1, 1, 2, 2, 10, 2), 0.6065306597126334) + assert_allclose(pdf.doublecrystalball(14, 1, 1, 2, 2, 10, 2), 0.1353352832366127) + assert_allclose(pdf.doublecrystalball(6, 1, 1, 2, 2, 10, 2), 0.26956918209450376) + # cpdef double argus(double x, double c, double chi, double p) def test_argus(): assert describe(pdf.argus) == ['x', 'c', 'chi', 'p'] From 92af27b6f8162a33b75c9d53617b5c1c547009e2 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 17:54:35 +0200 Subject: [PATCH 11/28] Update test_func.py --- tests/test_func.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_func.py b/tests/test_func.py index 2193593..ddad30a 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -72,7 +72,7 @@ def test_doublecrystalball(): assert_allclose(pdf.doublecrystalball(10, 1, 1, 2, 2, 10, 2), 1.) assert_allclose(pdf.doublecrystalball(11, 1, 1, 2, 2, 10, 2), 0.8824969025845955) assert_allclose(pdf.doublecrystalball(12, 1, 1, 2, 2, 10, 2), 0.6065306597126334) - assert_allclose(pdf.doublecrystalball(14, 1, 1, 2, 2, 10, 2), 0.1353352832366127) + assert_allclose(pdf.doublecrystalball(14, 1, 1, 2, 2, 10, 2), 0.26956918209450376) assert_allclose(pdf.doublecrystalball(6, 1, 1, 2, 2, 10, 2), 0.26956918209450376) # cpdef double argus(double x, double c, double chi, double p) From 08d9ff426cdf63294931bc373d0fb53660c84e10 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sat, 19 May 2018 18:42:22 +0200 Subject: [PATCH 12/28] Update test_plotting.py --- tests/test_plotting.py | 89 ++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 46 deletions(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 5fa3b92..203c574 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -17,7 +17,7 @@ from matplotlib import pyplot as plt from iminuit import Minuit from probfit.plotting import draw_pdf, draw_compare_hist -from probfit.pdf import gaussian, linear +from probfit.pdf import gaussian, linear, doublecrystalball from probfit.funcutil import rename from probfit.functor import Extended, AddPdfNorm, AddPdf from probfit.costfunc import UnbinnedLH, BinnedLH, BinnedChi2, Chi2Regression, \ @@ -43,25 +43,22 @@ def wrapped(): @image_comparison('draw_pdf.png') def test_draw_pdf(): - f = gaussian - draw_pdf(f, {'mean': 1., 'sigma': 2.}, bound=(-10, 10)) + f = doublecrystalball + draw_pdf(f, {'mean': 1., 'alpha' = 1, 'alpha2'=1, 'n'=2, 'n2'=2 ,'sigma': 2.}, bound=(-10, 10)) -@image_comparison('draw_pdf_linear.png') -def test_draw_pdf_linear(): - f = linear - draw_pdf(f, {'m': 1., 'c': 2.}, bound=(-10, 10)) + # There is a slight difference in the x-axis tick label positioning for this # plot between Python 2 and 3, it's not important here so increase the RMS # slightly such that it's ignored -@image_comparison('draw_compare_hist_gaussian.png', tolerance=2.05) +@image_comparison('draw_compare_hist_doublecrystalball.png', tolerance=2.05) def test_draw_compare_hist(): np.random.seed(0) data = np.random.randn(10000) - f = gaussian - draw_compare_hist(f, {'mean': 0., 'sigma': 1.}, data, normed=True) + f = doublecrystalball + draw_compare_hist(f, {'mean': 1., 'alpha' = 1, 'alpha2'=1, 'n'=2, 'n2'=2 ,'sigma': 2.}, data, normed=True) # There is a slight difference in the x-axis tick label positioning for this @@ -71,56 +68,56 @@ def test_draw_compare_hist(): def test_draw_compare_hist_no_norm(): np.random.seed(0) data = np.random.randn(10000) - f = Extended(gaussian) - draw_compare_hist(f, {'mean': 0., 'sigma': 1., 'N': 10000}, data, normed=False) + f = Extended(doublecrystalball) + draw_compare_hist(f, {'mean': 1., 'alpha' = 1, 'alpha2'=1, 'n'=2, 'n2'=2 ,'sigma': 2.}, data, normed=False) @image_comparison('draw_ulh.png') def test_draw_ulh(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(gaussian, data) - ulh.draw(args=(0., 1.)) + ulh = UnbinnedLH(doublecrystalball, data) + ulh.draw(args=(1., 1.,2.,2.,1.,2.)) @image_comparison('draw_ulh_extend.png') def test_draw_ulh_extend(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(Extended(gaussian), data, extended=True) - ulh.draw(args=(0., 1., 1000)) + ulh = UnbinnedLH(Extended(doublecrystalball), data, extended=True) + ulh.draw(args=(1., 1.,2.,2.,1.,2., 1000)) @image_comparison('draw_residual_ulh.png') def test_draw_residual_ulh(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(gaussian, data) - ulh.draw_residual(args=(0., 1.)) + ulh = UnbinnedLH(doublecrystalball, data) + ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.)) @image_comparison('draw_residual_ulh_norm.png') def test_draw_residual_ulh_norm(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(gaussian, data) - ulh.draw_residual(args=(0., 1.), norm=True) + ulh = UnbinnedLH(doublecrystalball, data) + ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True) @image_comparison('draw_residual_ulh_norm_no_errbars.png') def test_draw_residual_ulh_norm(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(gaussian, data) - ulh.draw_residual(args=(0., 1.), norm=True, show_errbars=False) + ulh = UnbinnedLH(doublecrystalball, data) + ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, show_errbars=False) @image_comparison('draw_residual_ulh_norm_options.png') def test_draw_residual_ulh_norm_options(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(gaussian, data) - ulh.draw_residual(args=(0., 1.), norm=True, color='green', capsize=2, + ulh = UnbinnedLH(doublecrystalball, data) + ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, color='green', capsize=2, grid=False, zero_line=False) @@ -128,16 +125,16 @@ def test_draw_residual_ulh_norm_options(): def test_draw_ulh_extend_residual_norm(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(Extended(gaussian), data, extended=True) - ulh.draw_residual(args=(0., 1., 1000), norm=True) + ulh = UnbinnedLH(Extended(doublecrystalball), data, extended=True) + ulh.draw_residual(args=(1., 1.,2.,2.,1.,2., 1000), norm=True) @image_comparison('draw_ulh_with_minuit.png') def test_draw_ulh_with_minuit(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(gaussian, data) - minuit = Minuit(ulh, mean=0, sigma=1) + ulh = UnbinnedLH(doublecrystalball, data) + minuit = Minuit(ulh, mean=0, sigma=1, alpha = 1, alpha2 =1, n=2, n2=2) ulh.draw(minuit) @@ -145,40 +142,40 @@ def test_draw_ulh_with_minuit(): def test_draw_blh(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(gaussian, data) - blh.draw(args=(0., 1.)) + blh = BinnedLH(doublecrystalball, data) + blh.draw(args=(1., 1.,2.,2.,1.,2.)) @image_comparison('draw_blh_extend.png') def test_draw_blh_extend(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(Extended(gaussian), data, extended=True) - blh.draw(args=(0., 1., 1000)) + blh = BinnedLH(Extended(doublecrystalball), data, extended=True) + blh.draw(args=(1., 1.,2.,2.,1.,2., 1000)) @image_comparison('draw_residual_blh.png') def test_draw_residual_blh(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(gaussian, data) - blh.draw_residual(args=(0., 1.)) + blh = BinnedLH(doublecrystalball, data) + blh.draw_residual(args=(1., 1.,2.,2.,1.,2.)) @image_comparison('draw_residual_blh_norm.png') def test_draw_residual_blh_norm(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(gaussian, data) - blh.draw_residual(args=(0., 1.), norm=True) + blh = BinnedLH(doublecrystalball, data) + blh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True) @image_comparison('draw_residual_blh_norm_options.png') def test_draw_residual_blh_norm_options(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(gaussian, data) - blh.draw_residual(args=(0., 1.), norm=True, color='green', capsize=2, + blh = BinnedLH(doublecrystalball, data) + blh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, color='green', capsize=2, grid=False, zero_line=False) @@ -186,34 +183,34 @@ def test_draw_residual_blh_norm_options(): def test_draw_residual_blh_norm(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(gaussian, data) - blh.draw_residual(args=(0., 1.), norm=True, show_errbars=False) + blh = BinnedLH(doublecrystalball, data) + blh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, show_errbars=False) @image_comparison('draw_blh_extend_residual_norm.png') def test_draw_blh_extend_residual_norm(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(Extended(gaussian), data, extended=True) - blh.draw_residual(args=(0., 1., 1000), norm=True) + blh = BinnedLH(Extended(doublecrystalball), data, extended=True) + blh.draw_residual(args=(1., 1.,2.,2.,1.,2., 1000), norm=True) @image_comparison('draw_bx2.png') def test_draw_bx2(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedChi2(Extended(gaussian), data) - blh.draw(args=(0., 1., 1000)) + blh = BinnedChi2(Extended(doublecrystalball), data) + blh.draw(args=(1., 1.,2.,2.,1.,2., 1000)) @image_comparison('draw_x2reg.png') def test_draw_x2reg(): np.random.seed(0) x = np.linspace(0, 1, 100) - y = 10. * x + np.random.randn(100) + y = doublecrystalball(x, 1,1,2,2,0,3) + np.random.randn(100) err = np.array([1] * 100) blh = Chi2Regression(linear, x, y, err) - blh.draw(args=(10., 0.)) + blh.draw(args=(1,1,2,2,0,3)) @image_comparison('draw_ulh_with_parts.png') From c4807eb288e5577b5dde55ac9b784e3443e5c19b Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 14:38:32 +0200 Subject: [PATCH 13/28] Update test_plotting.py --- tests/test_plotting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 203c574..a2d8103 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -44,7 +44,7 @@ def wrapped(): @image_comparison('draw_pdf.png') def test_draw_pdf(): f = doublecrystalball - draw_pdf(f, {'mean': 1., 'alpha' = 1, 'alpha2'=1, 'n'=2, 'n2'=2 ,'sigma': 2.}, bound=(-10, 10)) + draw_pdf(f, {'mean': 1., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, bound=(-10, 10)) @@ -58,7 +58,7 @@ def test_draw_compare_hist(): np.random.seed(0) data = np.random.randn(10000) f = doublecrystalball - draw_compare_hist(f, {'mean': 1., 'alpha' = 1, 'alpha2'=1, 'n'=2, 'n2'=2 ,'sigma': 2.}, data, normed=True) + draw_compare_hist(f, {'mean': 1., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=True) # There is a slight difference in the x-axis tick label positioning for this @@ -69,7 +69,7 @@ def test_draw_compare_hist_no_norm(): np.random.seed(0) data = np.random.randn(10000) f = Extended(doublecrystalball) - draw_compare_hist(f, {'mean': 1., 'alpha' = 1, 'alpha2'=1, 'n'=2, 'n2'=2 ,'sigma': 2.}, data, normed=False) + draw_compare_hist(f, {'mean': 1., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) @image_comparison('draw_ulh.png') From 8e9b3b5826ba01e2e79141dda55c7439be88404a Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 14:47:55 +0200 Subject: [PATCH 14/28] Update test_plotting.py --- tests/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index a2d8103..adb5af6 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -209,7 +209,7 @@ def test_draw_x2reg(): x = np.linspace(0, 1, 100) y = doublecrystalball(x, 1,1,2,2,0,3) + np.random.randn(100) err = np.array([1] * 100) - blh = Chi2Regression(linear, x, y, err) + blh = Chi2Regression(doublecrystalball, x, y, err) blh.draw(args=(1,1,2,2,0,3)) From 0ab2b8b700c467bb5a1476bbc385a1d78dc58c1d Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 15:00:13 +0200 Subject: [PATCH 15/28] Update test_plotting.py --- tests/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index adb5af6..6da01b5 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -69,7 +69,7 @@ def test_draw_compare_hist_no_norm(): np.random.seed(0) data = np.random.randn(10000) f = Extended(doublecrystalball) - draw_compare_hist(f, {'mean': 1., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) + draw_compare_hist(f, {'mean': 0., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) @image_comparison('draw_ulh.png') From bb01ed14a9dd4bff4e5ca3f1459ee9b15519cebf Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 15:06:47 +0200 Subject: [PATCH 16/28] Update test_plotting.py --- tests/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 6da01b5..b1f612e 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -69,7 +69,7 @@ def test_draw_compare_hist_no_norm(): np.random.seed(0) data = np.random.randn(10000) f = Extended(doublecrystalball) - draw_compare_hist(f, {'mean': 0., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) + draw_compare_hist(f, {'mean': 1, 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) @image_comparison('draw_ulh.png') From fef8b621b32e9779fa7a503b9042ec8bf79f7834 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 15:15:42 +0200 Subject: [PATCH 17/28] Update test_toy.py --- tests/test_toy.py | 39 +-------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/tests/test_toy.py b/tests/test_toy.py index 8a87892..f5a3a73 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -9,34 +9,8 @@ from probfit.nputil import vector_apply from probfit.costfunc import BinnedLH - -def test_gen_toy(): - np.random.seed(0) - bound = (-1, 2) - ntoy = 100000 - toy = gen_toy(crystalball, ntoy, bound=bound, - alpha=1., n=2., mean=1., sigma=0.3, quiet=False) - - assert len(toy) == ntoy - - htoy, bins = np.histogram(toy, bins=1000, range=bound) - - ncball = Normalized(crystalball, bound) - - f = lambda x: ncball(x, 1., 2., 1., 0.3) - - expected = vector_apply(f, mid(bins)) * ntoy * (bins[1] - bins[0]) - - htoy = htoy * 1.0 - err = np.sqrt(expected) - - chi2 = compute_chi2(htoy, expected, err) - - print(chi2, len(bins), chi2 / len(bins)) - - assert (0.9 < (chi2 / len(bins)) < 1.1) -def test_gen_toy3(): +def test_gen_toy(): np.random.seed(0) bound = (-1, 2) ntoy = 100000 @@ -62,14 +36,3 @@ def test_gen_toy3(): assert (0.9 < (chi2 / len(bins)) < 1.1) -def test_gen_toy2(): - pdf = gaussian - np.random.seed(0) - toy = gen_toy(pdf, 10000, (-5, 5), mean=0, sigma=1) - binlh = BinnedLH(pdf, toy, bound=(-5, 5), bins=100) - lh = binlh(0., 1.) - for x in toy: - assert (x < 5) - assert (x >= -5) - assert len(toy) == 10000 - assert lh / 100. < 1. From f3592a7b6a51b45412acb7feeedf512fce8e821b Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 15:30:51 +0200 Subject: [PATCH 18/28] Update test_plotting.py --- tests/test_plotting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index b1f612e..355e82a 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -207,10 +207,10 @@ def test_draw_bx2(): def test_draw_x2reg(): np.random.seed(0) x = np.linspace(0, 1, 100) - y = doublecrystalball(x, 1,1,2,2,0,3) + np.random.randn(100) + y = 10. * x + np.random.randn(100) err = np.array([1] * 100) - blh = Chi2Regression(doublecrystalball, x, y, err) - blh.draw(args=(1,1,2,2,0,3)) + blh = Chi2Regression(linear, x, y, err) + blh.draw(args=(10., 0.)) @image_comparison('draw_ulh_with_parts.png') From 413589a6ba866c319430b58394256ade77951063 Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 15:37:20 +0200 Subject: [PATCH 19/28] Update test_plotting.py --- tests/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 355e82a..bfad67e 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -69,7 +69,7 @@ def test_draw_compare_hist_no_norm(): np.random.seed(0) data = np.random.randn(10000) f = Extended(doublecrystalball) - draw_compare_hist(f, {'mean': 1, 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) + draw_compare_hist(f, {'mean': 0, 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) @image_comparison('draw_ulh.png') From 13f9a252d3aecd6012493cf2fcf185ffc4cd9c4e Mon Sep 17 00:00:00 2001 From: andreas01060 Date: Sun, 20 May 2018 15:42:22 +0200 Subject: [PATCH 20/28] Update test_plotting.py --- tests/test_plotting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index bfad67e..089d8ff 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -68,8 +68,8 @@ def test_draw_compare_hist(): def test_draw_compare_hist_no_norm(): np.random.seed(0) data = np.random.randn(10000) - f = Extended(doublecrystalball) - draw_compare_hist(f, {'mean': 0, 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=False) + f = Extended(gaussian) + draw_compare_hist(f, {'mean': 0., 'sigma': 1., 'N': 10000}, data, normed=False) @image_comparison('draw_ulh.png') From 7a75783ed1c28370b30694858d75a8286489f2ed Mon Sep 17 00:00:00 2001 From: Andreas Bally Date: Thu, 8 Nov 2018 15:50:35 +0100 Subject: [PATCH 21/28] Update test_toy.py --- tests/test_toy.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/test_toy.py b/tests/test_toy.py index f5a3a73..e26e3b4 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -2,7 +2,7 @@ import matplotlib matplotlib.use('Agg', warn=False) from probfit.nputil import mid -from probfit.pdf import crystalball, gaussian, doublecrystalball +from probfit.pdf import crystalball, gaussian from probfit.functor import Normalized from probfit.toy import gen_toy from probfit._libstat import compute_chi2 @@ -14,16 +14,15 @@ def test_gen_toy(): np.random.seed(0) bound = (-1, 2) ntoy = 100000 - toy = gen_toy(doublecrystalball, ntoy, bound=bound, - alpha=1., alpha2=1., n=2.,n2=2., mean=1., sigma=0.3, quiet=False) - + toy = gen_toy(crystalball, ntoy, bound=bound, + alpha=1., n=2., mean=1., sigma=0.3, quiet=False) assert len(toy) == ntoy htoy, bins = np.histogram(toy, bins=1000, range=bound) - ncball = Normalized(doublecrystalball, bound) + ncball = Normalized(crystalball, bound) - f = lambda x: ncball(x, 1., 1., 2., 2., 1., 0.3) + f = lambda x: ncball(x, 1., 2., 1., 0.3) expected = vector_apply(f, mid(bins)) * ntoy * (bins[1] - bins[0]) @@ -36,3 +35,15 @@ def test_gen_toy(): assert (0.9 < (chi2 / len(bins)) < 1.1) + +def test_gen_toy2(): + pdf = gaussian + np.random.seed(0) + toy = gen_toy(pdf, 10000, (-5, 5), mean=0, sigma=1) + binlh = BinnedLH(pdf, toy, bound=(-5, 5), bins=100) + lh = binlh(0., 1.) + for x in toy: + assert (x < 5) + assert (x >= -5) + assert len(toy) == 10000 + assert lh / 100. < 1. From 3acf20a53fefbfc759d33fba5437c4d0e1141293 Mon Sep 17 00:00:00 2001 From: Andreas Bally Date: Thu, 8 Nov 2018 16:01:21 +0100 Subject: [PATCH 22/28] Update test_plotting.py --- tests/test_plotting.py | 71 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index ee7a68e..7f7d929 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -18,7 +18,7 @@ from iminuit import Minuit import sys from probfit.plotting import draw_pdf, draw_compare_hist -from probfit.pdf import gaussian, linear, doublecrystalball +from probfit.pdf import gaussian, linear from probfit.funcutil import rename from probfit.functor import Extended, AddPdfNorm, AddPdf from probfit.costfunc import UnbinnedLH, BinnedLH, BinnedChi2, Chi2Regression, \ @@ -49,21 +49,23 @@ def wrapped(): @image_comparison('draw_pdf.png') def test_draw_pdf(): - f = doublecrystalball - draw_pdf(f, {'mean': 1., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, bound=(-10, 10)) - - + f = gaussian + draw_pdf(f, {'mean': 1., 'sigma': 2.}, bound=(-10, 10)) +@image_comparison('draw_pdf_linear.png') +def test_draw_pdf_linear(): + f = linear + draw_pdf(f, {'m': 1., 'c': 2.}, bound=(-10, 10)) # There is a slight difference in the x-axis tick label positioning for this # plot between Python 2 and 3, it's not important here so increase the RMS # slightly such that it's ignored -@image_comparison('draw_compare_hist_doublecrystalball.png', tolerance=2.05) +@image_comparison('draw_compare_hist_gaussian.png', tolerance=2.05) def test_draw_compare_hist(): np.random.seed(0) data = np.random.randn(10000) - f = doublecrystalball - draw_compare_hist(f, {'mean': 1., 'alpha' : 1, 'alpha2':1, 'n':2, 'n2':2 ,'sigma': 2.}, data, normed=True) + f = gaussian + draw_compare_hist(f, {'mean': 0., 'sigma': 1.}, data, normed=True) # There is a slight difference in the x-axis tick label positioning for this @@ -81,24 +83,24 @@ def test_draw_compare_hist_no_norm(): def test_draw_ulh(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(doublecrystalball, data) - ulh.draw(args=(1., 1.,2.,2.,1.,2.)) + ulh = UnbinnedLH(gaussian, data) + ulh.draw(args=(0., 1.)) @image_comparison('draw_ulh_extend.png') def test_draw_ulh_extend(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(Extended(doublecrystalball), data, extended=True) - ulh.draw(args=(1., 1.,2.,2.,1.,2., 1000)) + ulh = UnbinnedLH(Extended(gaussian), data, extended=True) + ulh.draw(args=(0., 1., 1000)) @image_comparison('draw_residual_ulh.png') def test_draw_residual_ulh(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(doublecrystalball, data) - ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.)) + ulh = UnbinnedLH(gaussian, data) + ulh.draw_residual(args=(0., 1.)) @image_comparison('draw_residual_ulh_norm.png') @@ -116,16 +118,16 @@ def test_draw_residual_ulh_norm(): def test_draw_residual_ulh_norm(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(doublecrystalball, data) - ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, show_errbars=False) + ulh = UnbinnedLH(gaussian, data) + ulh.draw_residual(args=(0., 1.), norm=True, show_errbars=False) @image_comparison('draw_residual_ulh_norm_options.png') def test_draw_residual_ulh_norm_options(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(doublecrystalball, data) - ulh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, color='green', capsize=2, + ulh = UnbinnedLH(gaussian, data) + ulh.draw_residual(args=(0., 1.), norm=True, color='green', capsize=2, grid=False, zero_line=False) @@ -143,8 +145,8 @@ def test_draw_ulh_extend_residual_norm(): def test_draw_ulh_with_minuit(): np.random.seed(0) data = np.random.randn(1000) - ulh = UnbinnedLH(doublecrystalball, data) - minuit = Minuit(ulh, mean=0, sigma=1, alpha = 1, alpha2 =1, n=2, n2=2) + ulh = UnbinnedLH(gaussian, data) + minuit = Minuit(ulh, mean=0, sigma=1) ulh.draw(minuit) @@ -152,24 +154,25 @@ def test_draw_ulh_with_minuit(): def test_draw_blh(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(doublecrystalball, data) - blh.draw(args=(1., 1.,2.,2.,1.,2.)) + blh = BinnedLH(gaussian, data) + blh.draw(args=(0., 1.)) @image_comparison('draw_blh_extend.png') def test_draw_blh_extend(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(Extended(doublecrystalball), data, extended=True) - blh.draw(args=(1., 1.,2.,2.,1.,2., 1000)) + blh = BinnedLH(Extended(gaussian), data, extended=True) + blh.draw(args=(0., 1., 1000)) @image_comparison('draw_residual_blh.png') def test_draw_residual_blh(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(doublecrystalball, data) - blh.draw_residual(args=(1., 1.,2.,2.,1.,2.)) + blh = BinnedLH(gaussian, data) + blh.draw_residual(args=(0., 1.)) + @image_comparison('draw_residual_blh_norm.png') @@ -187,8 +190,8 @@ def test_draw_residual_blh_norm(): def test_draw_residual_blh_norm_options(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(doublecrystalball, data) - blh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, color='green', capsize=2, + blh = BinnedLH(gaussian, data) + blh.draw_residual(args=(0., 1.), norm=True, color='green', capsize=2, grid=False, zero_line=False) @@ -196,24 +199,24 @@ def test_draw_residual_blh_norm_options(): def test_draw_residual_blh_norm(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(doublecrystalball, data) - blh.draw_residual(args=(1., 1.,2.,2.,1.,2.), norm=True, show_errbars=False) + blh = BinnedLH(gaussian, data) + blh.draw_residual(args=(0., 1.), norm=True, show_errbars=False) @image_comparison('draw_blh_extend_residual_norm.png') def test_draw_blh_extend_residual_norm(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedLH(Extended(doublecrystalball), data, extended=True) - blh.draw_residual(args=(1., 1.,2.,2.,1.,2., 1000), norm=True) + blh = BinnedLH(Extended(gaussian), data, extended=True) + blh.draw_residual(args=(0., 1., 1000), norm=True) @image_comparison('draw_bx2.png') def test_draw_bx2(): np.random.seed(0) data = np.random.randn(1000) - blh = BinnedChi2(Extended(doublecrystalball), data) - blh.draw(args=(1., 1.,2.,2.,1.,2., 1000)) + blh = BinnedChi2(Extended(gaussian), data) + blh.draw(args=(0., 1., 1000)) @image_comparison('draw_x2reg.png') From 97184dad53fb389eb31001a8173621c827e6eaf6 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Thu, 8 Nov 2018 17:05:20 +0100 Subject: [PATCH 23/28] whitespace --- tests/test_plotting.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 7f7d929..3857a6b 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -52,11 +52,13 @@ def test_draw_pdf(): f = gaussian draw_pdf(f, {'mean': 1., 'sigma': 2.}, bound=(-10, 10)) + @image_comparison('draw_pdf_linear.png') def test_draw_pdf_linear(): f = linear draw_pdf(f, {'m': 1., 'c': 2.}, bound=(-10, 10)) + # There is a slight difference in the x-axis tick label positioning for this # plot between Python 2 and 3, it's not important here so increase the RMS # slightly such that it's ignored @@ -113,7 +115,6 @@ def test_draw_residual_ulh_norm(): plt.xlim(-4., 3.) - @image_comparison('draw_residual_ulh_norm_no_errbars.png', tolerance=special_tol) def test_draw_residual_ulh_norm(): np.random.seed(0) @@ -140,7 +141,6 @@ def test_draw_ulh_extend_residual_norm(): plt.ylim(-7.,3.) - @image_comparison('draw_ulh_with_minuit.png') def test_draw_ulh_with_minuit(): np.random.seed(0) @@ -174,7 +174,6 @@ def test_draw_residual_blh(): blh.draw_residual(args=(0., 1.)) - @image_comparison('draw_residual_blh_norm.png') def test_draw_residual_blh_norm(): np.random.seed(0) @@ -185,7 +184,6 @@ def test_draw_residual_blh_norm(): plt.xlim(-4., 3.) - @image_comparison('draw_residual_blh_norm_options.png') def test_draw_residual_blh_norm_options(): np.random.seed(0) From 47c1e799fefb3fb73005ce0d794a09c535842291 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Fri, 9 Nov 2018 09:20:00 +0100 Subject: [PATCH 24/28] whitespace --- tests/test_plotting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 3857a6b..0043a08 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -52,7 +52,7 @@ def test_draw_pdf(): f = gaussian draw_pdf(f, {'mean': 1., 'sigma': 2.}, bound=(-10, 10)) - + @image_comparison('draw_pdf_linear.png') def test_draw_pdf_linear(): f = linear From 467d284a42d3e4e14fac2d1091a9bea3008e79be Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Fri, 9 Nov 2018 09:20:36 +0100 Subject: [PATCH 25/28] whitespace --- tests/test_toy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_toy.py b/tests/test_toy.py index e26e3b4..c9074b2 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -9,7 +9,7 @@ from probfit.nputil import vector_apply from probfit.costfunc import BinnedLH - + def test_gen_toy(): np.random.seed(0) bound = (-1, 2) From 2d0edf3614cd82a834d0419eb85649a45114b394 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Fri, 9 Nov 2018 09:21:13 +0100 Subject: [PATCH 26/28] whitespace --- tests/test_toy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_toy.py b/tests/test_toy.py index c9074b2..ab06875 100644 --- a/tests/test_toy.py +++ b/tests/test_toy.py @@ -35,7 +35,7 @@ def test_gen_toy(): assert (0.9 < (chi2 / len(bins)) < 1.1) - + def test_gen_toy2(): pdf = gaussian np.random.seed(0) From df6510f0274abb80c9366e4fe8700e77d537d909 Mon Sep 17 00:00:00 2001 From: Andreas Bally Date: Fri, 9 Nov 2018 12:59:04 +0100 Subject: [PATCH 27/28] Update test_func.py --- tests/test_func.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_func.py b/tests/test_func.py index 443e92c..c157274 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -74,6 +74,13 @@ def test_doublecrystalball(): assert_allclose(pdf.doublecrystalball(12, 1, 1, 2, 2, 10, 2), 0.6065306597126334) assert_allclose(pdf.doublecrystalball(14, 1, 1, 2, 2, 10, 2), 0.26956918209450376) assert_allclose(pdf.doublecrystalball(6, 1, 1, 2, 2, 10, 2), 0.26956918209450376) + assert_allclose(pdf.doublecrystalball(-10, 1, 5, 3, 4, 10, 2), 0.00947704155801) + assert_allclose(pdf.doublecrystalball(0, 1, 5, 3, 4, 10, 2), 0.047744395954055) + assert_allclose(pdf.doublecrystalball(11, 1, 5, 3, 4, 10, 2), 0.8824969025846) + assert_allclose(pdf.doublecrystalball(20, 1, 5, 3, 4, 10, 2), 0.0000037266531720786) + assert_allclose(pdf.doublecrystalball(25, 1, 5, 3, 4, 10, 2), 0.00000001287132228271) + + # cpdef double argus(double x, double c, double chi, double p) def test_argus(): From 1d9f89d80fbe21fbcca1b8848dc562e338c4e055 Mon Sep 17 00:00:00 2001 From: Andreas Bally Date: Fri, 9 Nov 2018 16:29:19 +0100 Subject: [PATCH 28/28] asymmetric double crystal ball instead of symmetric The original plots were symmetric double crystal balls not showing the full extend of the double crystal ball. --- doc/pyplots/pdf/doublecrystalball.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/pyplots/pdf/doublecrystalball.py b/doc/pyplots/pdf/doublecrystalball.py index 627a86a..2d73ece 100644 --- a/doc/pyplots/pdf/doublecrystalball.py +++ b/doc/pyplots/pdf/doublecrystalball.py @@ -2,12 +2,12 @@ from probfit.plotting import draw_normed_pdf import matplotlib.pyplot as plt -bound = (5.22, 5.30) +bound = (-2, 12) -arg = dict(alpha=1.,alpha2=1., n=2.,n2=2, mean=5.28, sigma=0.01) +arg = dict(alpha=1.,alpha2=2., n=2.,n2=4, mean=5, sigma=1) draw_normed_pdf(crystalball, arg=arg, bound=bound, label=str(arg), density=True) -arg = dict(alpha=0.5, alpha2=0.5, n=10., n2=10., mean=5.28, sigma=0.005) +arg = dict(alpha=2, alpha2=1, n=7., n2=10., mean=5, sigma=1) draw_normed_pdf(crystalball, arg=arg, bound=bound, label=str(arg), density=True) plt.grid(True)