From 5f423f1f45372521ec258000f12c93de16af33e4 Mon Sep 17 00:00:00 2001 From: DavidLP Date: Thu, 30 Jun 2016 17:35:26 +0200 Subject: [PATCH] ENH: the functions are now defined with mu = MPV as it should be --- pyLandau/cpp/pylandau.cpp | 2453 ++++++++++++++++++++----------------- pyLandau/cpp/pylandau.pyx | 69 +- 2 files changed, 1399 insertions(+), 1123 deletions(-) diff --git a/pyLandau/cpp/pylandau.cpp b/pyLandau/cpp/pylandau.cpp index 249a7be..16620ce 100644 --- a/pyLandau/cpp/pylandau.cpp +++ b/pyLandau/cpp/pylandau.cpp @@ -862,6 +862,9 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact); + #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { PyTypeObject* tp = Py_TYPE(obj); @@ -893,9 +896,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); -static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact); - static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY @@ -1189,13 +1189,15 @@ static char __pyx_k_h[] = "h"; static char __pyx_k_i[] = "i"; static char __pyx_k_l[] = "l"; static char __pyx_k_q[] = "q"; +static char __pyx_k_x[] = "x"; +static char __pyx_k_y[] = "y"; static char __pyx_k_Zd[] = "Zd"; static char __pyx_k_Zf[] = "Zf"; static char __pyx_k_Zg[] = "Zg"; static char __pyx_k_mu[] = "mu"; static char __pyx_k_np[] = "np"; static char __pyx_k_eta[] = "eta"; -static char __pyx_k_max[] = "max"; +static char __pyx_k_mpv[] = "mpv"; static char __pyx_k_main[] = "__main__"; static char __pyx_k_test[] = "__test__"; static char __pyx_k_array[] = "array"; @@ -1203,13 +1205,17 @@ static char __pyx_k_numpy[] = "numpy"; static char __pyx_k_range[] = "range"; static char __pyx_k_sigma[] = "sigma"; static char __pyx_k_value[] = "value"; +static char __pyx_k_y_pre[] = "y_pre"; static char __pyx_k_arange[] = "arange"; +static char __pyx_k_argmax[] = "argmax"; static char __pyx_k_import[] = "__import__"; static char __pyx_k_landau[] = "landau"; static char __pyx_k_langau[] = "langau"; static char __pyx_k_result[] = "result"; static char __pyx_k_maximum[] = "maximum"; static char __pyx_k_pylandau[] = "pylandau"; +static char __pyx_k_mpv_shift[] = "mpv_shift"; +static char __pyx_k_precision[] = "precision"; static char __pyx_k_ValueError[] = "ValueError"; static char __pyx_k_get_landau[] = "get_landau"; static char __pyx_k_get_langau[] = "get_langau"; @@ -1217,6 +1223,7 @@ static char __pyx_k_landau_pdf[] = "landau_pdf"; static char __pyx_k_langau_pdf[] = "langau_pdf"; static char __pyx_k_RuntimeError[] = "RuntimeError"; static char __pyx_k_get_gauss_pdf[] = "get_gauss_pdf"; +static char __pyx_k_index_maximum[] = "index_maximum"; static char __pyx_k_get_landau_pdf[] = "get_landau_pdf"; static char __pyx_k_get_langau_pdf[] = "get_langau_pdf"; static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous"; @@ -1234,6 +1241,7 @@ static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor; static PyObject *__pyx_n_s_RuntimeError; static PyObject *__pyx_n_s_ValueError; static PyObject *__pyx_n_s_arange; +static PyObject *__pyx_n_s_argmax; static PyObject *__pyx_n_s_array; static PyObject *__pyx_n_s_eta; static PyObject *__pyx_n_s_get_gauss_pdf; @@ -1242,18 +1250,21 @@ static PyObject *__pyx_n_s_get_landau_pdf; static PyObject *__pyx_n_s_get_langau; static PyObject *__pyx_n_s_get_langau_pdf; static PyObject *__pyx_n_s_import; +static PyObject *__pyx_n_s_index_maximum; static PyObject *__pyx_n_s_landau; static PyObject *__pyx_n_s_landau_pdf; static PyObject *__pyx_n_s_langau; static PyObject *__pyx_n_s_langau_pdf; static PyObject *__pyx_n_s_main; -static PyObject *__pyx_n_s_max; static PyObject *__pyx_n_s_maximum; +static PyObject *__pyx_n_s_mpv; +static PyObject *__pyx_n_s_mpv_shift; static PyObject *__pyx_n_s_mu; static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous; static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou; static PyObject *__pyx_n_s_np; static PyObject *__pyx_n_s_numpy; +static PyObject *__pyx_n_s_precision; static PyObject *__pyx_n_s_pylandau; static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_result; @@ -1261,18 +1272,22 @@ static PyObject *__pyx_n_s_sigma; static PyObject *__pyx_n_s_test; static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd; static PyObject *__pyx_n_s_value; +static PyObject *__pyx_n_s_x; +static PyObject *__pyx_n_s_y; +static PyObject *__pyx_n_s_y_pre; static PyObject *__pyx_pf_8pylandau_get_landau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta); /* proto */ static PyObject *__pyx_pf_8pylandau_2get_gauss_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_sigma); /* proto */ static PyObject *__pyx_pf_8pylandau_4get_langau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma); /* proto */ -static PyObject *__pyx_pf_8pylandau_6get_landau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_A); /* proto */ -static PyObject *__pyx_pf_8pylandau_8get_langau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A); /* proto */ -static PyObject *__pyx_pf_8pylandau_10landau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta); /* proto */ -static PyObject *__pyx_pf_8pylandau_12langau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma); /* proto */ -static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_A); /* proto */ -static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A); /* proto */ +static PyObject *__pyx_pf_8pylandau_6landau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta); /* proto */ +static PyObject *__pyx_pf_8pylandau_8langau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma); /* proto */ +static PyObject *__pyx_pf_8pylandau_10get_landau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_A, PyObject *__pyx_v_precision); /* proto */ +static PyObject *__pyx_pf_8pylandau_12get_langau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A, PyObject *__pyx_v_precision); /* proto */ +static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_A, CYTHON_UNUSED PyObject *__pyx_v_precision); /* proto */ +static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A, PyObject *__pyx_v_precision); /* proto */ static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */ -static PyObject *__pyx_float_0_1; +static PyObject *__pyx_float_0_01; +static PyObject *__pyx_float_0_001; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_5; @@ -1399,7 +1414,7 @@ static PyObject *__pyx_f_8pylandau_data_to_numpy_array_double(__pyx_t_5numpy_dou /* "pylandau.pyx":29 * - * + * # The pdf are defined by the original algorithm where mu != MPV * def get_landau_pdf(value, mu=0, eta=1): # <<<<<<<<<<<<<< * return landauPDF( value, mu, eta) * @@ -1494,7 +1509,7 @@ static PyObject *__pyx_pf_8pylandau_get_landau_pdf(CYTHON_UNUSED PyObject *__pyx __Pyx_RefNannySetupContext("get_landau_pdf", 0); /* "pylandau.pyx":30 - * + * # The pdf are defined by the original algorithm where mu != MPV * def get_landau_pdf(value, mu=0, eta=1): * return landauPDF( value, mu, eta) # <<<<<<<<<<<<<< * @@ -1518,7 +1533,7 @@ static PyObject *__pyx_pf_8pylandau_get_landau_pdf(CYTHON_UNUSED PyObject *__pyx /* "pylandau.pyx":29 * - * + * # The pdf are defined by the original algorithm where mu != MPV * def get_landau_pdf(value, mu=0, eta=1): # <<<<<<<<<<<<<< * return landauPDF( value, mu, eta) * @@ -1819,36 +1834,33 @@ static PyObject *__pyx_pf_8pylandau_4get_langau_pdf(CYTHON_UNUSED PyObject *__py /* "pylandau.pyx":41 * * - * def get_landau(value, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * result = get_landau_pdf(value, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< + * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) + * return data_to_numpy_array_double(result, array.shape[0]) */ /* Python wrapper */ -static PyObject *__pyx_pw_8pylandau_7get_landau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8pylandau_7get_landau = {"get_landau", (PyCFunction)__pyx_pw_8pylandau_7get_landau, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8pylandau_7get_landau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_value = 0; +static PyObject *__pyx_pw_8pylandau_7landau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8pylandau_7landau_pdf = {"landau_pdf", (PyCFunction)__pyx_pw_8pylandau_7landau_pdf, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_8pylandau_7landau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyArrayObject *__pyx_v_array = 0; PyObject *__pyx_v_mu = 0; PyObject *__pyx_v_eta = 0; - PyObject *__pyx_v_A = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_landau (wrapper)", 0); + __Pyx_RefNannySetupContext("landau_pdf (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_mu,&__pyx_n_s_eta,&__pyx_n_s_A,0}; - PyObject* values[4] = {0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mu,&__pyx_n_s_eta,0}; + PyObject* values[3] = {0,0,0}; values[1] = ((PyObject *)__pyx_int_0); values[2] = ((PyObject *)__pyx_int_1); - values[3] = ((PyObject *)__pyx_int_1); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -1858,7 +1870,7 @@ static PyObject *__pyx_pw_8pylandau_7get_landau(PyObject *__pyx_self, PyObject * kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_array)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { @@ -1870,18 +1882,12 @@ static PyObject *__pyx_pw_8pylandau_7get_landau(PyObject *__pyx_self, PyObject * PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_eta); if (value) { values[2] = value; kw_args--; } } - case 3: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_A); - if (value) { values[3] = value; kw_args--; } - } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_landau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "landau_pdf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -1889,293 +1895,143 @@ static PyObject *__pyx_pw_8pylandau_7get_landau(PyObject *__pyx_self, PyObject * default: goto __pyx_L5_argtuple_error; } } - __pyx_v_value = values[0]; + __pyx_v_array = ((PyArrayObject *)values[0]); __pyx_v_mu = values[1]; __pyx_v_eta = values[2]; - __pyx_v_A = values[3]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_landau", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("landau_pdf", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("pylandau.get_landau", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pylandau.landau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8pylandau_6get_landau(__pyx_self, __pyx_v_value, __pyx_v_mu, __pyx_v_eta, __pyx_v_A); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8pylandau_6landau_pdf(__pyx_self, __pyx_v_array, __pyx_v_mu, __pyx_v_eta); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_8pylandau_6get_landau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_A) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_maximum = NULL; +static PyObject *__pyx_pf_8pylandau_6landau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta) { + double *__pyx_v_result; + __Pyx_LocalBuf_ND __pyx_pybuffernd_array; + __Pyx_Buffer __pyx_pybuffer_array; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; + double __pyx_t_1; + double __pyx_t_2; + double *__pyx_t_3; + PyObject *__pyx_t_4 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_landau", 0); + __Pyx_RefNannySetupContext("landau_pdf", 0); + __pyx_pybuffer_array.pybuffer.buf = NULL; + __pyx_pybuffer_array.refcount = 0; + __pyx_pybuffernd_array.data = NULL; + __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0]; /* "pylandau.pyx":42 * - * def get_landau(value, mu=0, eta=1, A=1): - * result = get_landau_pdf(value, mu, eta) # <<<<<<<<<<<<<< - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) - * return result / maximum * A # Numerical scaling maximum to A - */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_landau_pdf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_value); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_mu); - __Pyx_INCREF(__pyx_v_eta); - __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_eta); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pylandau.pyx":43 - * def get_landau(value, mu=0, eta=1, A=1): - * result = get_landau_pdf(value, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) # <<<<<<<<<<<<<< - * return result / maximum * A # Numerical scaling maximum to A + * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): + * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) # <<<<<<<<<<<<<< + * return data_to_numpy_array_double(result, array.shape[0]) * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_arange); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyNumber_Subtract(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = PyNumber_Add(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_float_0_1, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_4 = 1; - } - } - __pyx_t_12 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_t_7); - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_7 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_4 = 1; - } - } - __pyx_t_12 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_6); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_v_mu); - __Pyx_INCREF(__pyx_v_eta); - __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_v_eta); - __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_mu); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_eta); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + try { + __pyx_t_3 = getLandauPDFData(((double *&)__pyx_v_array->data), ((unsigned int const &)(__pyx_v_array->dimensions[0])), ((double const &)__pyx_t_1), ((double const &)__pyx_t_2)); + } catch(...) { + __Pyx_CppExn2PyErr(); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_maximum = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_v_result = __pyx_t_3; - /* "pylandau.pyx":44 - * result = get_landau_pdf(value, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) - * return result / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< + /* "pylandau.pyx":43 + * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): + * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) + * return data_to_numpy_array_double(result, array.shape[0]) # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_result, __pyx_v_maximum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_A); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_t_4 = __pyx_f_8pylandau_data_to_numpy_array_double(__pyx_v_result, (__pyx_v_array->dimensions[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; goto __pyx_L0; /* "pylandau.pyx":41 * * - * def get_landau(value, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * result = get_landau_pdf(value, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< + * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) + * return data_to_numpy_array_double(result, array.shape[0]) */ /* function exit code */ __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); - __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("pylandau.get_landau", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_4); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("pylandau.landau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + goto __pyx_L2; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_maximum); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); + __pyx_L2:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pylandau.pyx":47 +/* "pylandau.pyx":46 * * - * def get_langau(value, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * result = get_langau_pdf(value, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: */ /* Python wrapper */ -static PyObject *__pyx_pw_8pylandau_9get_langau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8pylandau_9get_langau = {"get_langau", (PyCFunction)__pyx_pw_8pylandau_9get_langau, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8pylandau_9get_langau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_value = 0; +static PyObject *__pyx_pw_8pylandau_9langau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8pylandau_9langau_pdf = {"langau_pdf", (PyCFunction)__pyx_pw_8pylandau_9langau_pdf, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_8pylandau_9langau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyArrayObject *__pyx_v_array = 0; PyObject *__pyx_v_mu = 0; PyObject *__pyx_v_eta = 0; PyObject *__pyx_v_sigma = 0; - PyObject *__pyx_v_A = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("get_langau (wrapper)", 0); + __Pyx_RefNannySetupContext("langau_pdf (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_mu,&__pyx_n_s_eta,&__pyx_n_s_sigma,&__pyx_n_s_A,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mu,&__pyx_n_s_eta,&__pyx_n_s_sigma,0}; + PyObject* values[4] = {0,0,0,0}; values[1] = ((PyObject *)__pyx_int_0); values[2] = ((PyObject *)__pyx_int_1); values[3] = ((PyObject *)__pyx_int_1); - values[4] = ((PyObject *)__pyx_int_1); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -2186,7 +2042,7 @@ static PyObject *__pyx_pw_8pylandau_9get_langau(PyObject *__pyx_self, PyObject * kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_array)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { @@ -2203,18 +2059,12 @@ static PyObject *__pyx_pw_8pylandau_9get_langau(PyObject *__pyx_self, PyObject * PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sigma); if (value) { values[3] = value; kw_args--; } } - case 4: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_A); - if (value) { values[4] = value; kw_args--; } - } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_langau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "langau_pdf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { - case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -2223,295 +2073,172 @@ static PyObject *__pyx_pw_8pylandau_9get_langau(PyObject *__pyx_self, PyObject * default: goto __pyx_L5_argtuple_error; } } - __pyx_v_value = values[0]; + __pyx_v_array = ((PyArrayObject *)values[0]); __pyx_v_mu = values[1]; __pyx_v_eta = values[2]; __pyx_v_sigma = values[3]; - __pyx_v_A = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get_langau", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("langau_pdf", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("pylandau.get_langau", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pylandau.langau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_8pylandau_8get_langau(__pyx_self, __pyx_v_value, __pyx_v_mu, __pyx_v_eta, __pyx_v_sigma, __pyx_v_A); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8pylandau_8langau_pdf(__pyx_self, __pyx_v_array, __pyx_v_mu, __pyx_v_eta, __pyx_v_sigma); /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_8pylandau_8get_langau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A) { - PyObject *__pyx_v_result = NULL; - PyObject *__pyx_v_maximum = NULL; +static PyObject *__pyx_pf_8pylandau_8langau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma) { + double *__pyx_v_result; + __Pyx_LocalBuf_ND __pyx_pybuffernd_array; + __Pyx_Buffer __pyx_pybuffer_array; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; - PyObject *__pyx_t_5 = NULL; + double __pyx_t_1; + double __pyx_t_2; + double __pyx_t_3; + double *__pyx_t_4; + int __pyx_t_5; PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("get_langau", 0); + __Pyx_RefNannySetupContext("langau_pdf", 0); + __pyx_pybuffer_array.pybuffer.buf = NULL; + __pyx_pybuffer_array.refcount = 0; + __pyx_pybuffernd_array.data = NULL; + __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array; + { + __Pyx_BufFmt_StackElem __pyx_stack[1]; + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0]; - /* "pylandau.pyx":48 + /* "pylandau.pyx":47 * - * def get_langau(value, mu=0, eta=1, sigma=1, A=1): - * result = get_langau_pdf(value, mu, eta, sigma) # <<<<<<<<<<<<<< - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) - * return result / maximum * A # Numerical scaling maximum to A + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) # <<<<<<<<<<<<<< + * if result != NULL: + * return data_to_numpy_array_double(result, array.shape[0]) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_langau_pdf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_mu); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_eta); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_sigma); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + try { + __pyx_t_4 = getLangauPDFData(((double *&)__pyx_v_array->data), ((unsigned int const &)(__pyx_v_array->dimensions[0])), ((double const &)__pyx_t_1), ((double const &)__pyx_t_2), ((double const &)__pyx_t_3)); + } catch(...) { + __Pyx_CppExn2PyErr(); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_value); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_mu); - __Pyx_INCREF(__pyx_v_eta); - __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_eta); - __Pyx_INCREF(__pyx_v_sigma); - __Pyx_GIVEREF(__pyx_v_sigma); - PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, __pyx_v_sigma); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_result = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_v_result = __pyx_t_4; - /* "pylandau.pyx":49 - * def get_langau(value, mu=0, eta=1, sigma=1, A=1): - * result = get_langau_pdf(value, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) # <<<<<<<<<<<<<< - * return result / maximum * A # Numerical scaling maximum to A + /* "pylandau.pyx":48 + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: # <<<<<<<<<<<<<< + * return data_to_numpy_array_double(result, array.shape[0]) * */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_langau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_arange); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyNumber_Subtract(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = PyNumber_Add(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_float_0_1, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_11); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_4 = 1; - } - } - __pyx_t_12 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; - } - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_t_7); - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_7 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - __pyx_t_8 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { - __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); - if (likely(__pyx_t_8)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); - __Pyx_INCREF(__pyx_t_8); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_4 = 1; - } - } - __pyx_t_12 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; - } - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_6); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_v_mu); - __Pyx_INCREF(__pyx_v_eta); - __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_v_eta); - __Pyx_INCREF(__pyx_v_sigma); - __Pyx_GIVEREF(__pyx_v_sigma); - PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_4, __pyx_v_sigma); - __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = NULL; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); - } - } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_maximum = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_5 = ((__pyx_v_result != NULL) != 0); + if (__pyx_t_5) { - /* "pylandau.pyx":50 - * result = get_langau_pdf(value, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) - * return result / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< + /* "pylandau.pyx":49 + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: + * return data_to_numpy_array_double(result, array.shape[0]) # <<<<<<<<<<<<<< * * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_result, __pyx_v_maximum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_A); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - goto __pyx_L0; + __Pyx_XDECREF(__pyx_r); + __pyx_t_6 = __pyx_f_8pylandau_data_to_numpy_array_double(__pyx_v_result, (__pyx_v_array->dimensions[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_6); + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; - /* "pylandau.pyx":47 + /* "pylandau.pyx":48 + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: # <<<<<<<<<<<<<< + * return data_to_numpy_array_double(result, array.shape[0]) * + */ + } + + /* "pylandau.pyx":46 * - * def get_langau(value, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * result = get_langau_pdf(value, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: */ /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_XDECREF(__pyx_t_3); - __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); - __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); - __Pyx_AddTraceback("pylandau.get_langau", __pyx_clineno, __pyx_lineno, __pyx_filename); + { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; + __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); + __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} + __Pyx_AddTraceback("pylandau.langau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; + goto __pyx_L2; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_result); - __Pyx_XDECREF(__pyx_v_maximum); + __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); + __pyx_L2:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pylandau.pyx":53 - * +/* "pylandau.pyx":55 + * # This is done numerically very simple, stability might suffer * - * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< - * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) - * return data_to_numpy_array_double(result, array.shape[0]) + * def get_landau(value, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* Python wrapper */ -static PyObject *__pyx_pw_8pylandau_11landau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8pylandau_11landau_pdf = {"landau_pdf", (PyCFunction)__pyx_pw_8pylandau_11landau_pdf, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8pylandau_11landau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_array = 0; - PyObject *__pyx_v_mu = 0; +static PyObject *__pyx_pw_8pylandau_11get_landau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8pylandau_11get_landau = {"get_landau", (PyCFunction)__pyx_pw_8pylandau_11get_landau, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_8pylandau_11get_landau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_value = 0; + PyObject *__pyx_v_mpv = 0; PyObject *__pyx_v_eta = 0; + PyObject *__pyx_v_A = 0; + PyObject *__pyx_v_precision = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("landau_pdf (wrapper)", 0); + __Pyx_RefNannySetupContext("get_landau (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mu,&__pyx_n_s_eta,0}; - PyObject* values[3] = {0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_mpv,&__pyx_n_s_eta,&__pyx_n_s_A,&__pyx_n_s_precision,0}; + PyObject* values[5] = {0,0,0,0,0}; values[1] = ((PyObject *)__pyx_int_0); values[2] = ((PyObject *)__pyx_int_1); + values[3] = ((PyObject *)__pyx_int_1); + values[4] = ((PyObject *)__pyx_float_0_01); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -2521,11 +2248,11 @@ static PyObject *__pyx_pw_8pylandau_11landau_pdf(PyObject *__pyx_self, PyObject kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_array)) != 0)) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mu); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mpv); if (value) { values[1] = value; kw_args--; } } case 2: @@ -2533,12 +2260,24 @@ static PyObject *__pyx_pw_8pylandau_11landau_pdf(PyObject *__pyx_self, PyObject PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_eta); if (value) { values[2] = value; kw_args--; } } + case 3: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_A); + if (value) { values[3] = value; kw_args--; } + } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_precision); + if (value) { values[4] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "landau_pdf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_landau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -2546,143 +2285,345 @@ static PyObject *__pyx_pw_8pylandau_11landau_pdf(PyObject *__pyx_self, PyObject default: goto __pyx_L5_argtuple_error; } } - __pyx_v_array = ((PyArrayObject *)values[0]); - __pyx_v_mu = values[1]; + __pyx_v_value = values[0]; + __pyx_v_mpv = values[1]; __pyx_v_eta = values[2]; + __pyx_v_A = values[3]; + __pyx_v_precision = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("landau_pdf", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("get_landau", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; - __Pyx_AddTraceback("pylandau.landau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("pylandau.get_landau", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8pylandau_10landau_pdf(__pyx_self, __pyx_v_array, __pyx_v_mu, __pyx_v_eta); + __pyx_r = __pyx_pf_8pylandau_10get_landau(__pyx_self, __pyx_v_value, __pyx_v_mpv, __pyx_v_eta, __pyx_v_A, __pyx_v_precision); /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_8pylandau_10landau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta) { - double *__pyx_v_result; - __Pyx_LocalBuf_ND __pyx_pybuffernd_array; - __Pyx_Buffer __pyx_pybuffer_array; +static PyObject *__pyx_pf_8pylandau_10get_landau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_A, PyObject *__pyx_v_precision) { + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y_pre = NULL; + PyObject *__pyx_v_index_maximum = NULL; + PyObject *__pyx_v_maximum = NULL; + PyObject *__pyx_v_mpv_shift = NULL; + PyObject *__pyx_v_y = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - double __pyx_t_1; - double __pyx_t_2; - double *__pyx_t_3; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + Py_ssize_t __pyx_t_7; + PyObject *__pyx_t_8 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("landau_pdf", 0); - __pyx_pybuffer_array.pybuffer.buf = NULL; - __pyx_pybuffer_array.refcount = 0; - __pyx_pybuffernd_array.data = NULL; - __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_RefNannySetupContext("get_landau", 0); + + /* "pylandau.pyx":57 + * def get_landau(value, mpv=0, eta=1, A=1, precision=0.01): + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum # <<<<<<<<<<<<<< + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyNumber_Add(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_v_precision, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; + } } - __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0]; + __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_x = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":58 + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift # <<<<<<<<<<<<<< + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; + } + } + __pyx_t_2 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_x); + __Pyx_INCREF(__pyx_v_mpv); + __Pyx_GIVEREF(__pyx_v_mpv); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_mpv); + __Pyx_INCREF(__pyx_v_eta); + __Pyx_GIVEREF(__pyx_v_eta); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_7, __pyx_v_eta); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_y_pre = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":59 + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) # <<<<<<<<<<<<<< + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_argmax); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_y_pre); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + } else { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_y_pre); + __Pyx_GIVEREF(__pyx_v_y_pre); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_y_pre); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_index_maximum = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":60 + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] # <<<<<<<<<<<<<< + * mpv_shift = mpv - x[index_maximum] + * + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_y_pre, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_maximum = __pyx_t_1; + __pyx_t_1 = 0; - /* "pylandau.pyx":54 + /* "pylandau.pyx":61 + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] # <<<<<<<<<<<<<< * - * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): - * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) # <<<<<<<<<<<<<< - * return data_to_numpy_array_double(result, array.shape[0]) + * y = get_landau_pdf(value, mpv + mpv_shift, eta) # Shift original mu parameter to get a Landau with mu = MPV + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_x, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_mpv_shift = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pylandau.pyx":63 + * mpv_shift = mpv - x[index_maximum] + * + * y = get_landau_pdf(value, mpv + mpv_shift, eta) # Shift original mu parameter to get a Landau with mu = MPV # <<<<<<<<<<<<<< + * return y / maximum * A # Numerical scaling maximum to A * */ - __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_mu); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_eta); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - try { - __pyx_t_3 = getLandauPDFData(((double *&)__pyx_v_array->data), ((unsigned int const &)(__pyx_v_array->dimensions[0])), ((double const &)__pyx_t_1), ((double const &)__pyx_t_2)); - } catch(...) { - __Pyx_CppExn2PyErr(); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_landau_pdf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyNumber_Add(__pyx_v_mpv, __pyx_v_mpv_shift); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_7 = 1; + } } - __pyx_v_result = __pyx_t_3; + __pyx_t_5 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_value); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_t_8); + __Pyx_INCREF(__pyx_v_eta); + __Pyx_GIVEREF(__pyx_v_eta); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_7, __pyx_v_eta); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_y = __pyx_t_2; + __pyx_t_2 = 0; - /* "pylandau.pyx":55 - * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): - * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) - * return data_to_numpy_array_double(result, array.shape[0]) # <<<<<<<<<<<<<< + /* "pylandau.pyx":64 + * + * y = get_landau_pdf(value, mpv + mpv_shift, eta) # Shift original mu parameter to get a Landau with mu = MPV + * return y / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __pyx_f_8pylandau_data_to_numpy_array_double(__pyx_v_result, (__pyx_v_array->dimensions[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_y, __pyx_v_maximum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_A); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pylandau.pyx":53 - * + /* "pylandau.pyx":55 + * # This is done numerically very simple, stability might suffer * - * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< - * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) - * return data_to_numpy_array_double(result, array.shape[0]) + * def get_landau(value, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* function exit code */ __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("pylandau.landau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pylandau.get_landau", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - goto __pyx_L2; __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); - __pyx_L2:; + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y_pre); + __Pyx_XDECREF(__pyx_v_index_maximum); + __Pyx_XDECREF(__pyx_v_maximum); + __Pyx_XDECREF(__pyx_v_mpv_shift); + __Pyx_XDECREF(__pyx_v_y); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pylandau.pyx":58 +/* "pylandau.pyx":67 * * - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: + * def get_langau(value, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* Python wrapper */ -static PyObject *__pyx_pw_8pylandau_13langau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_8pylandau_13langau_pdf = {"langau_pdf", (PyCFunction)__pyx_pw_8pylandau_13langau_pdf, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_8pylandau_13langau_pdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyArrayObject *__pyx_v_array = 0; - PyObject *__pyx_v_mu = 0; +static PyObject *__pyx_pw_8pylandau_13get_langau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyMethodDef __pyx_mdef_8pylandau_13get_langau = {"get_langau", (PyCFunction)__pyx_pw_8pylandau_13get_langau, METH_VARARGS|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_8pylandau_13get_langau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_value = 0; + PyObject *__pyx_v_mpv = 0; PyObject *__pyx_v_eta = 0; PyObject *__pyx_v_sigma = 0; + PyObject *__pyx_v_A = 0; + PyObject *__pyx_v_precision = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("langau_pdf (wrapper)", 0); + __Pyx_RefNannySetupContext("get_langau (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mu,&__pyx_n_s_eta,&__pyx_n_s_sigma,0}; - PyObject* values[4] = {0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_value,&__pyx_n_s_mpv,&__pyx_n_s_eta,&__pyx_n_s_sigma,&__pyx_n_s_A,&__pyx_n_s_precision,0}; + PyObject* values[6] = {0,0,0,0,0,0}; values[1] = ((PyObject *)__pyx_int_0); values[2] = ((PyObject *)__pyx_int_1); values[3] = ((PyObject *)__pyx_int_1); + values[4] = ((PyObject *)__pyx_int_1); + values[5] = ((PyObject *)__pyx_float_0_01); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -2693,11 +2634,11 @@ static PyObject *__pyx_pw_8pylandau_13langau_pdf(PyObject *__pyx_self, PyObject kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: - if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_array)) != 0)) kw_args--; + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_value)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mu); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mpv); if (value) { values[1] = value; kw_args--; } } case 2: @@ -2710,12 +2651,24 @@ static PyObject *__pyx_pw_8pylandau_13langau_pdf(PyObject *__pyx_self, PyObject PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sigma); if (value) { values[3] = value; kw_args--; } } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_A); + if (value) { values[4] = value; kw_args--; } + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_precision); + if (value) { values[5] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "langau_pdf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_langau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -2724,142 +2677,317 @@ static PyObject *__pyx_pw_8pylandau_13langau_pdf(PyObject *__pyx_self, PyObject default: goto __pyx_L5_argtuple_error; } } - __pyx_v_array = ((PyArrayObject *)values[0]); - __pyx_v_mu = values[1]; - __pyx_v_eta = values[2]; - __pyx_v_sigma = values[3]; + __pyx_v_value = values[0]; + __pyx_v_mpv = values[1]; + __pyx_v_eta = values[2]; + __pyx_v_sigma = values[3]; + __pyx_v_A = values[4]; + __pyx_v_precision = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("get_langau", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("pylandau.get_langau", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_8pylandau_12get_langau(__pyx_self, __pyx_v_value, __pyx_v_mpv, __pyx_v_eta, __pyx_v_sigma, __pyx_v_A, __pyx_v_precision); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_8pylandau_12get_langau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_value, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A, PyObject *__pyx_v_precision) { + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y_pre = NULL; + PyObject *__pyx_v_index_maximum = NULL; + PyObject *__pyx_v_maximum = NULL; + PyObject *__pyx_v_mpv_shift = NULL; + PyObject *__pyx_v_y = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + Py_ssize_t __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("get_langau", 0); + + /* "pylandau.pyx":69 + * def get_langau(value, mpv=0, eta=1, sigma=1, A=1, precision=0.01): + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum # <<<<<<<<<<<<<< + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) + */ + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyNumber_Add(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_v_precision, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; + } + } + __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; + } + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_x = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":70 + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift # <<<<<<<<<<<<<< + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_8 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; + } + } + __pyx_t_2 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (__pyx_t_8) { + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8); __pyx_t_8 = NULL; + } + __Pyx_INCREF(__pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_x); + __Pyx_INCREF(__pyx_v_mpv); + __Pyx_GIVEREF(__pyx_v_mpv); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_mpv); + __Pyx_INCREF(__pyx_v_eta); + __Pyx_GIVEREF(__pyx_v_eta); + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_7, __pyx_v_eta); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_y_pre = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":71 + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) # <<<<<<<<<<<<<< + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_argmax); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("langau_pdf", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("pylandau.langau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8pylandau_12langau_pdf(__pyx_self, __pyx_v_array, __pyx_v_mu, __pyx_v_eta, __pyx_v_sigma); - - /* function exit code */ - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_pf_8pylandau_12langau_pdf(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma) { - double *__pyx_v_result; - __Pyx_LocalBuf_ND __pyx_pybuffernd_array; - __Pyx_Buffer __pyx_pybuffer_array; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - double __pyx_t_1; - double __pyx_t_2; - double __pyx_t_3; - double *__pyx_t_4; - int __pyx_t_5; - PyObject *__pyx_t_6 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("langau_pdf", 0); - __pyx_pybuffer_array.pybuffer.buf = NULL; - __pyx_pybuffer_array.refcount = 0; - __pyx_pybuffernd_array.data = NULL; - __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array; - { - __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_y_pre); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + } else { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_y_pre); + __Pyx_GIVEREF(__pyx_v_y_pre); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_y_pre); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } - __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0]; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_index_maximum = __pyx_t_1; + __pyx_t_1 = 0; - /* "pylandau.pyx":59 + /* "pylandau.pyx":72 + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] # <<<<<<<<<<<<<< + * mpv_shift = mpv - x[index_maximum] * - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) # <<<<<<<<<<<<<< - * if result != NULL: - * return data_to_numpy_array_double(result, array.shape[0]) */ - __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_mu); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_eta); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_sigma); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - try { - __pyx_t_4 = getLangauPDFData(((double *&)__pyx_v_array->data), ((unsigned int const &)(__pyx_v_array->dimensions[0])), ((double const &)__pyx_t_1), ((double const &)__pyx_t_2), ((double const &)__pyx_t_3)); - } catch(...) { - __Pyx_CppExn2PyErr(); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_v_result = __pyx_t_4; + __pyx_t_1 = PyObject_GetItem(__pyx_v_y_pre, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_maximum = __pyx_t_1; + __pyx_t_1 = 0; - /* "pylandau.pyx":60 - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: # <<<<<<<<<<<<<< - * return data_to_numpy_array_double(result, array.shape[0]) + /* "pylandau.pyx":73 + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] # <<<<<<<<<<<<<< * + * y = get_langau_pdf(value, mpv + mpv_shift, eta, sigma) */ - __pyx_t_5 = ((__pyx_v_result != NULL) != 0); - if (__pyx_t_5) { + __pyx_t_1 = PyObject_GetItem(__pyx_v_x, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_mpv_shift = __pyx_t_2; + __pyx_t_2 = 0; - /* "pylandau.pyx":61 - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: - * return data_to_numpy_array_double(result, array.shape[0]) # <<<<<<<<<<<<<< + /* "pylandau.pyx":75 + * mpv_shift = mpv - x[index_maximum] * + * y = get_langau_pdf(value, mpv + mpv_shift, eta, sigma) # <<<<<<<<<<<<<< + * return y / maximum * A # Numerical scaling maximum to A * */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_6 = __pyx_f_8pylandau_data_to_numpy_array_double(__pyx_v_result, (__pyx_v_array->dimensions[0])); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_r = __pyx_t_6; - __pyx_t_6 = 0; - goto __pyx_L0; + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_get_langau_pdf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyNumber_Add(__pyx_v_mpv, __pyx_v_mpv_shift); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_7 = 1; + } + } + __pyx_t_5 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_v_value); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_t_8); + __Pyx_INCREF(__pyx_v_eta); + __Pyx_GIVEREF(__pyx_v_eta); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_7, __pyx_v_eta); + __Pyx_INCREF(__pyx_v_sigma); + __Pyx_GIVEREF(__pyx_v_sigma); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_7, __pyx_v_sigma); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_y = __pyx_t_2; + __pyx_t_2 = 0; - /* "pylandau.pyx":60 - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: # <<<<<<<<<<<<<< - * return data_to_numpy_array_double(result, array.shape[0]) + /* "pylandau.pyx":76 + * + * y = get_langau_pdf(value, mpv + mpv_shift, eta, sigma) + * return y / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< + * * */ - } + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_y, __pyx_v_maximum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_A); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; - /* "pylandau.pyx":58 + /* "pylandau.pyx":67 * * - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: + * def get_langau(value, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; - __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); - __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} - __Pyx_AddTraceback("pylandau.langau_pdf", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("pylandau.get_langau", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; - goto __pyx_L2; __pyx_L0:; - __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); - __pyx_L2:; + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y_pre); + __Pyx_XDECREF(__pyx_v_index_maximum); + __Pyx_XDECREF(__pyx_v_maximum); + __Pyx_XDECREF(__pyx_v_mpv_shift); + __Pyx_XDECREF(__pyx_v_y); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pylandau.pyx":64 +/* "pylandau.pyx":79 * * - * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * landau = landau_pdf(array, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* Python wrapper */ @@ -2867,9 +2995,10 @@ static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__p static PyMethodDef __pyx_mdef_8pylandau_15landau = {"landau", (PyCFunction)__pyx_pw_8pylandau_15landau, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_array = 0; - PyObject *__pyx_v_mu = 0; + PyObject *__pyx_v_mpv = 0; PyObject *__pyx_v_eta = 0; PyObject *__pyx_v_A = 0; + CYTHON_UNUSED PyObject *__pyx_v_precision = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -2877,15 +3006,17 @@ static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("landau (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mu,&__pyx_n_s_eta,&__pyx_n_s_A,0}; - PyObject* values[4] = {0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mpv,&__pyx_n_s_eta,&__pyx_n_s_A,&__pyx_n_s_precision,0}; + PyObject* values[5] = {0,0,0,0,0}; values[1] = ((PyObject *)__pyx_int_0); values[2] = ((PyObject *)__pyx_int_1); values[3] = ((PyObject *)__pyx_int_1); + values[4] = ((PyObject *)__pyx_float_0_01); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -2900,7 +3031,7 @@ static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__p else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mu); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mpv); if (value) { values[1] = value; kw_args--; } } case 2: @@ -2913,12 +3044,18 @@ static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__p PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_A); if (value) { values[3] = value; kw_args--; } } + case 4: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_precision); + if (value) { values[4] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "landau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "landau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); @@ -2928,20 +3065,21 @@ static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__p } } __pyx_v_array = ((PyArrayObject *)values[0]); - __pyx_v_mu = values[1]; + __pyx_v_mpv = values[1]; __pyx_v_eta = values[2]; __pyx_v_A = values[3]; + __pyx_v_precision = values[4]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("landau", 0, 1, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("landau", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pylandau.landau", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8pylandau_14landau(__pyx_self, __pyx_v_array, __pyx_v_mu, __pyx_v_eta, __pyx_v_A); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8pylandau_14landau(__pyx_self, __pyx_v_array, __pyx_v_mpv, __pyx_v_eta, __pyx_v_A, __pyx_v_precision); /* function exit code */ goto __pyx_L0; @@ -2952,9 +3090,13 @@ static PyObject *__pyx_pw_8pylandau_15landau(PyObject *__pyx_self, PyObject *__p return __pyx_r; } -static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_A) { - PyObject *__pyx_v_landau = NULL; +static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_A, CYTHON_UNUSED PyObject *__pyx_v_precision) { + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y_pre = NULL; + PyObject *__pyx_v_index_maximum = NULL; PyObject *__pyx_v_maximum = NULL; + PyObject *__pyx_v_mpv_shift = NULL; + PyObject *__pyx_v_y = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_array; __Pyx_Buffer __pyx_pybuffer_array; PyObject *__pyx_r = NULL; @@ -2962,15 +3104,11 @@ static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; + PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_7; PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -2981,115 +3119,78 @@ static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0]; - /* "pylandau.pyx":65 - * - * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): - * landau = landau_pdf(array, mu, eta) # <<<<<<<<<<<<<< - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) - * return landau / maximum * A # Numerical scaling maximum to A + /* "pylandau.pyx":81 + * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, A=1, precision=0.01): + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum # <<<<<<<<<<<<<< + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - __pyx_t_5 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(((PyObject *)__pyx_v_array)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_array)); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_array)); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_mu); - __Pyx_INCREF(__pyx_v_eta); - __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_eta); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_landau = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pylandau.pyx":66 - * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): - * landau = landau_pdf(array, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) # <<<<<<<<<<<<<< - * return landau / maximum * A # Numerical scaling maximum to A - * - */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Add(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_arange); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyNumber_Subtract(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = PyNumber_Add(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_float_0_1, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_11); + __pyx_t_2 = PyNumber_Multiply(__pyx_float_0_001, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_4 = 1; + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; } } - __pyx_t_12 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; } - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_t_7); - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_7 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_x = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":82 + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift # <<<<<<<<<<<<<< + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = NULL; - __pyx_t_4 = 0; + __pyx_t_7 = 0; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_8)) { @@ -3097,79 +3198,164 @@ static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_4 = 1; + __pyx_t_7 = 1; } } - __pyx_t_12 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8); __pyx_t_8 = NULL; } - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_6); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_v_mu); + __Pyx_INCREF(__pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_x); + __Pyx_INCREF(__pyx_v_mpv); + __Pyx_GIVEREF(__pyx_v_mpv); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_mpv); __Pyx_INCREF(__pyx_v_eta); __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_v_eta); - __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_7, __pyx_v_eta); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_y_pre = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":83 + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) # <<<<<<<<<<<<<< + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_argmax); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + } + } + if (!__pyx_t_3) { + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_y_pre); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + } else { + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_y_pre); + __Pyx_GIVEREF(__pyx_v_y_pre); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_y_pre); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_index_maximum = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":84 + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] # <<<<<<<<<<<<<< + * mpv_shift = mpv - x[index_maximum] + * + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_y_pre, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_maximum = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":85 + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] # <<<<<<<<<<<<<< + * + * y = landau_pdf(array, mpv + mpv_shift, eta) + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_x, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_mpv_shift = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pylandau.pyx":87 + * mpv_shift = mpv - x[index_maximum] + * + * y = landau_pdf(array, mpv + mpv_shift, eta) # <<<<<<<<<<<<<< + * return y / maximum * A # Numerical scaling maximum to A + * + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = PyNumber_Add(__pyx_v_mpv, __pyx_v_mpv_shift); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_7 = 1; } } - if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_1); - } else { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_5 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; } + __Pyx_INCREF(((PyObject *)__pyx_v_array)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_array)); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, ((PyObject *)__pyx_v_array)); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_t_8); + __Pyx_INCREF(__pyx_v_eta); + __Pyx_GIVEREF(__pyx_v_eta); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_7, __pyx_v_eta); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_v_maximum = __pyx_t_1; - __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_y = __pyx_t_2; + __pyx_t_2 = 0; - /* "pylandau.pyx":67 - * landau = landau_pdf(array, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) - * return landau / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< + /* "pylandau.pyx":88 + * + * y = landau_pdf(array, mpv + mpv_shift, eta) + * return y / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< * * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_landau, __pyx_v_maximum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_y, __pyx_v_maximum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_A); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_A); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pylandau.pyx":64 + /* "pylandau.pyx":79 * * - * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * landau = landau_pdf(array, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* function exit code */ @@ -3177,14 +3363,10 @@ static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); @@ -3195,19 +3377,23 @@ static PyObject *__pyx_pf_8pylandau_14landau(CYTHON_UNUSED PyObject *__pyx_self, __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); __pyx_L2:; - __Pyx_XDECREF(__pyx_v_landau); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y_pre); + __Pyx_XDECREF(__pyx_v_index_maximum); __Pyx_XDECREF(__pyx_v_maximum); + __Pyx_XDECREF(__pyx_v_mpv_shift); + __Pyx_XDECREF(__pyx_v_y); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "pylandau.pyx":70 +/* "pylandau.pyx":91 * * - * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * langau = langau_pdf(array, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* Python wrapper */ @@ -3215,10 +3401,11 @@ static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__p static PyMethodDef __pyx_mdef_8pylandau_17langau = {"langau", (PyCFunction)__pyx_pw_8pylandau_17langau, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_array = 0; - PyObject *__pyx_v_mu = 0; + PyObject *__pyx_v_mpv = 0; PyObject *__pyx_v_eta = 0; PyObject *__pyx_v_sigma = 0; PyObject *__pyx_v_A = 0; + PyObject *__pyx_v_precision = 0; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -3226,16 +3413,18 @@ static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("langau (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mu,&__pyx_n_s_eta,&__pyx_n_s_sigma,&__pyx_n_s_A,0}; - PyObject* values[5] = {0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_array,&__pyx_n_s_mpv,&__pyx_n_s_eta,&__pyx_n_s_sigma,&__pyx_n_s_A,&__pyx_n_s_precision,0}; + PyObject* values[6] = {0,0,0,0,0,0}; values[1] = ((PyObject *)__pyx_int_0); values[2] = ((PyObject *)__pyx_int_1); values[3] = ((PyObject *)__pyx_int_1); values[4] = ((PyObject *)__pyx_int_1); + values[5] = ((PyObject *)__pyx_float_0_01); if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); @@ -3251,7 +3440,7 @@ static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__p else goto __pyx_L5_argtuple_error; case 1: if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mu); + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mpv); if (value) { values[1] = value; kw_args--; } } case 2: @@ -3269,12 +3458,18 @@ static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__p PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_A); if (value) { values[4] = value; kw_args--; } } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_precision); + if (value) { values[5] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "langau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "langau") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); @@ -3285,21 +3480,22 @@ static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__p } } __pyx_v_array = ((PyArrayObject *)values[0]); - __pyx_v_mu = values[1]; + __pyx_v_mpv = values[1]; __pyx_v_eta = values[2]; __pyx_v_sigma = values[3]; __pyx_v_A = values[4]; + __pyx_v_precision = values[5]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("langau", 0, 1, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("langau", 0, 1, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("pylandau.langau", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_8pylandau_16langau(__pyx_self, __pyx_v_array, __pyx_v_mu, __pyx_v_eta, __pyx_v_sigma, __pyx_v_A); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_array), __pyx_ptype_5numpy_ndarray, 1, "array", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_8pylandau_16langau(__pyx_self, __pyx_v_array, __pyx_v_mpv, __pyx_v_eta, __pyx_v_sigma, __pyx_v_A, __pyx_v_precision); /* function exit code */ goto __pyx_L0; @@ -3310,9 +3506,13 @@ static PyObject *__pyx_pw_8pylandau_17langau(PyObject *__pyx_self, PyObject *__p return __pyx_r; } -static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mu, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A) { - PyObject *__pyx_v_langau = NULL; +static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_array, PyObject *__pyx_v_mpv, PyObject *__pyx_v_eta, PyObject *__pyx_v_sigma, PyObject *__pyx_v_A, PyObject *__pyx_v_precision) { + PyObject *__pyx_v_x = NULL; + PyObject *__pyx_v_y_pre = NULL; + PyObject *__pyx_v_index_maximum = NULL; PyObject *__pyx_v_maximum = NULL; + PyObject *__pyx_v_mpv_shift = NULL; + PyObject *__pyx_v_y = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_array; __Pyx_Buffer __pyx_pybuffer_array; PyObject *__pyx_r = NULL; @@ -3320,15 +3520,11 @@ static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_t_1 = NULL; PyObject *__pyx_t_2 = NULL; PyObject *__pyx_t_3 = NULL; - Py_ssize_t __pyx_t_4; + PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_7; PyObject *__pyx_t_8 = NULL; - PyObject *__pyx_t_9 = NULL; - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -3339,117 +3535,78 @@ static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, __pyx_pybuffernd_array.rcbuffer = &__pyx_pybuffer_array; { __Pyx_BufFmt_StackElem __pyx_stack[1]; - if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_array.rcbuffer->pybuffer, (PyObject*)__pyx_v_array, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_pybuffernd_array.diminfo[0].strides = __pyx_pybuffernd_array.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_array.diminfo[0].shape = __pyx_pybuffernd_array.rcbuffer->pybuffer.shape[0]; - /* "pylandau.pyx":71 - * - * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): - * langau = langau_pdf(array, mu, eta, sigma) # <<<<<<<<<<<<<< - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) - * return langau / maximum * A # Numerical scaling maximum to A + /* "pylandau.pyx":93 + * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, sigma=1, A=1, precision=0.01): + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum # <<<<<<<<<<<<<< + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_langau_pdf); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_3); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - __pyx_t_4 = 1; - } - } - __pyx_t_5 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - if (__pyx_t_3) { - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; - } - __Pyx_INCREF(((PyObject *)__pyx_v_array)); - __Pyx_GIVEREF(((PyObject *)__pyx_v_array)); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_array)); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_mu); - __Pyx_INCREF(__pyx_v_eta); - __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_4, __pyx_v_eta); - __Pyx_INCREF(__pyx_v_sigma); - __Pyx_GIVEREF(__pyx_v_sigma); - PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_4, __pyx_v_sigma); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_arange); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_v_langau = __pyx_t_1; - __pyx_t_1 = 0; - - /* "pylandau.pyx":72 - * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): - * langau = langau_pdf(array, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) # <<<<<<<<<<<<<< - * return langau / maximum * A # Numerical scaling maximum to A - */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyNumber_Add(__pyx_v_mpv, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_langau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_arange); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_8); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = PyNumber_Subtract(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_9); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_int_5, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_10 = PyNumber_Add(__pyx_v_mu, __pyx_t_7); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - __pyx_t_7 = PyNumber_Multiply(__pyx_float_0_1, __pyx_v_eta); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_11 = NULL; - __pyx_t_4 = 0; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_8))) { - __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_8); - if (likely(__pyx_t_11)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); - __Pyx_INCREF(__pyx_t_11); + __pyx_t_2 = PyNumber_Multiply(__pyx_v_precision, __pyx_v_eta); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_8, function); - __pyx_t_4 = 1; + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_7 = 1; } } - __pyx_t_12 = PyTuple_New(3+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - if (__pyx_t_11) { - __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; + __pyx_t_8 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + if (__pyx_t_6) { + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6); __pyx_t_6 = NULL; } - __Pyx_GIVEREF(__pyx_t_9); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_9); - __Pyx_GIVEREF(__pyx_t_10); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_t_10); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_t_7); - __pyx_t_9 = 0; - __pyx_t_10 = 0; - __pyx_t_7 = 0; - __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_7, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_7, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_7, __pyx_t_2); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_x = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":94 + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift # <<<<<<<<<<<<<< + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_landau_pdf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = NULL; - __pyx_t_4 = 0; + __pyx_t_7 = 0; if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_8)) { @@ -3457,80 +3614,164 @@ static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); - __pyx_t_4 = 1; + __pyx_t_7 = 1; } } - __pyx_t_12 = PyTuple_New(4+__pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); + __pyx_t_2 = PyTuple_New(3+__pyx_t_7); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); if (__pyx_t_8) { - __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_8); __pyx_t_8 = NULL; + __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_8); __pyx_t_8 = NULL; } - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_4, __pyx_t_6); - __Pyx_INCREF(__pyx_v_mu); - __Pyx_GIVEREF(__pyx_v_mu); - PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_4, __pyx_v_mu); + __Pyx_INCREF(__pyx_v_x); + __Pyx_GIVEREF(__pyx_v_x); + PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_7, __pyx_v_x); + __Pyx_INCREF(__pyx_v_mpv); + __Pyx_GIVEREF(__pyx_v_mpv); + PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_7, __pyx_v_mpv); __Pyx_INCREF(__pyx_v_eta); __Pyx_GIVEREF(__pyx_v_eta); - PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_4, __pyx_v_eta); - __Pyx_INCREF(__pyx_v_sigma); - __Pyx_GIVEREF(__pyx_v_sigma); - PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_4, __pyx_v_sigma); - __pyx_t_6 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_7, __pyx_v_eta); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_y_pre = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":95 + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) # <<<<<<<<<<<<<< + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] + */ + __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_argmax); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) { - __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5); + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_5, function); + __Pyx_DECREF_SET(__pyx_t_2, function); } } if (!__pyx_t_3) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_y_pre); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); } else { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_12); - __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); __pyx_t_3 = NULL; - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL; + __Pyx_INCREF(__pyx_v_y_pre); + __Pyx_GIVEREF(__pyx_v_y_pre); + PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_y_pre); + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_index_maximum = __pyx_t_1; + __pyx_t_1 = 0; + + /* "pylandau.pyx":96 + * y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] # <<<<<<<<<<<<<< + * mpv_shift = mpv - x[index_maximum] + * + */ + __pyx_t_1 = PyObject_GetItem(__pyx_v_y_pre, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); __pyx_v_maximum = __pyx_t_1; __pyx_t_1 = 0; - /* "pylandau.pyx":73 - * langau = langau_pdf(array, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) - * return langau / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< + /* "pylandau.pyx":97 + * index_maximum = np.argmax(y_pre) + * maximum = y_pre[index_maximum] + * mpv_shift = mpv - x[index_maximum] # <<<<<<<<<<<<<< + * + * y = langau_pdf(array, mpv+mpv_shift, eta, sigma) */ - __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_langau, __pyx_v_maximum); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetItem(__pyx_v_x, __pyx_v_index_maximum); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyNumber_Subtract(__pyx_v_mpv, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_mpv_shift = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pylandau.pyx":99 + * mpv_shift = mpv - x[index_maximum] + * + * y = langau_pdf(array, mpv+mpv_shift, eta, sigma) # <<<<<<<<<<<<<< + * return y / maximum * A # Numerical scaling maximum to A + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_langau_pdf); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = PyNumber_Multiply(__pyx_t_1, __pyx_v_A); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyNumber_Add(__pyx_v_mpv, __pyx_v_mpv_shift); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_3 = NULL; + __pyx_t_7 = 0; + if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_7 = 1; + } + } + __pyx_t_5 = PyTuple_New(4+__pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3) { + __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; + } + __Pyx_INCREF(((PyObject *)__pyx_v_array)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_array)); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, ((PyObject *)__pyx_v_array)); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_t_8); + __Pyx_INCREF(__pyx_v_eta); + __Pyx_GIVEREF(__pyx_v_eta); + PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_7, __pyx_v_eta); + __Pyx_INCREF(__pyx_v_sigma); + __Pyx_GIVEREF(__pyx_v_sigma); + PyTuple_SET_ITEM(__pyx_t_5, 3+__pyx_t_7, __pyx_v_sigma); + __pyx_t_8 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; + __pyx_v_y = __pyx_t_2; + __pyx_t_2 = 0; + + /* "pylandau.pyx":100 + * + * y = langau_pdf(array, mpv+mpv_shift, eta, sigma) + * return y / maximum * A # Numerical scaling maximum to A # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_y, __pyx_v_maximum); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyNumber_Multiply(__pyx_t_2, __pyx_v_A); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; goto __pyx_L0; - /* "pylandau.pyx":70 + /* "pylandau.pyx":91 * * - * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * langau = langau_pdf(array, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ /* function exit code */ @@ -3538,14 +3779,10 @@ static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); - __Pyx_XDECREF(__pyx_t_9); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); @@ -3556,8 +3793,12 @@ static PyObject *__pyx_pf_8pylandau_16langau(CYTHON_UNUSED PyObject *__pyx_self, __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_array.rcbuffer->pybuffer); __pyx_L2:; - __Pyx_XDECREF(__pyx_v_langau); + __Pyx_XDECREF(__pyx_v_x); + __Pyx_XDECREF(__pyx_v_y_pre); + __Pyx_XDECREF(__pyx_v_index_maximum); __Pyx_XDECREF(__pyx_v_maximum); + __Pyx_XDECREF(__pyx_v_mpv_shift); + __Pyx_XDECREF(__pyx_v_y); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; @@ -5737,6 +5978,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1}, {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1}, {&__pyx_n_s_arange, __pyx_k_arange, sizeof(__pyx_k_arange), 0, 0, 1, 1}, + {&__pyx_n_s_argmax, __pyx_k_argmax, sizeof(__pyx_k_argmax), 0, 0, 1, 1}, {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1}, {&__pyx_n_s_eta, __pyx_k_eta, sizeof(__pyx_k_eta), 0, 0, 1, 1}, {&__pyx_n_s_get_gauss_pdf, __pyx_k_get_gauss_pdf, sizeof(__pyx_k_get_gauss_pdf), 0, 0, 1, 1}, @@ -5745,18 +5987,21 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_get_langau, __pyx_k_get_langau, sizeof(__pyx_k_get_langau), 0, 0, 1, 1}, {&__pyx_n_s_get_langau_pdf, __pyx_k_get_langau_pdf, sizeof(__pyx_k_get_langau_pdf), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_index_maximum, __pyx_k_index_maximum, sizeof(__pyx_k_index_maximum), 0, 0, 1, 1}, {&__pyx_n_s_landau, __pyx_k_landau, sizeof(__pyx_k_landau), 0, 0, 1, 1}, {&__pyx_n_s_landau_pdf, __pyx_k_landau_pdf, sizeof(__pyx_k_landau_pdf), 0, 0, 1, 1}, {&__pyx_n_s_langau, __pyx_k_langau, sizeof(__pyx_k_langau), 0, 0, 1, 1}, {&__pyx_n_s_langau_pdf, __pyx_k_langau_pdf, sizeof(__pyx_k_langau_pdf), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, - {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1}, {&__pyx_n_s_maximum, __pyx_k_maximum, sizeof(__pyx_k_maximum), 0, 0, 1, 1}, + {&__pyx_n_s_mpv, __pyx_k_mpv, sizeof(__pyx_k_mpv), 0, 0, 1, 1}, + {&__pyx_n_s_mpv_shift, __pyx_k_mpv_shift, sizeof(__pyx_k_mpv_shift), 0, 0, 1, 1}, {&__pyx_n_s_mu, __pyx_k_mu, sizeof(__pyx_k_mu), 0, 0, 1, 1}, {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0}, {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0}, {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1}, {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1}, + {&__pyx_n_s_precision, __pyx_k_precision, sizeof(__pyx_k_precision), 0, 0, 1, 1}, {&__pyx_n_s_pylandau, __pyx_k_pylandau, sizeof(__pyx_k_pylandau), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1}, @@ -5764,6 +6009,9 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0}, {&__pyx_n_s_value, __pyx_k_value, sizeof(__pyx_k_value), 0, 0, 1, 1}, + {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, + {&__pyx_n_s_y, __pyx_k_y, sizeof(__pyx_k_y), 0, 0, 1, 1}, + {&__pyx_n_s_y_pre, __pyx_k_y_pre, sizeof(__pyx_k_y_pre), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { @@ -5847,7 +6095,7 @@ static int __Pyx_InitCachedConstants(void) { /* "pylandau.pyx":29 * - * + * # The pdf are defined by the original algorithm where mu != MPV * def get_landau_pdf(value, mu=0, eta=1): # <<<<<<<<<<<<<< * return landauPDF( value, mu, eta) * @@ -5884,74 +6132,74 @@ static int __Pyx_InitCachedConstants(void) { /* "pylandau.pyx":41 * * - * def get_landau(value, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * result = get_landau_pdf(value, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< + * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) + * return data_to_numpy_array_double(result, array.shape[0]) */ - __pyx_tuple__13 = PyTuple_Pack(6, __pyx_n_s_value, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_A, __pyx_n_s_result, __pyx_n_s_maximum); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__13 = PyTuple_Pack(4, __pyx_n_s_array, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_result); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__13); __Pyx_GIVEREF(__pyx_tuple__13); - __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(4, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_get_landau, 41, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(3, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_landau_pdf, 41, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "pylandau.pyx":47 + /* "pylandau.pyx":46 * * - * def get_langau(value, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * result = get_langau_pdf(value, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: */ - __pyx_tuple__15 = PyTuple_Pack(7, __pyx_n_s_value, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_sigma, __pyx_n_s_A, __pyx_n_s_result, __pyx_n_s_maximum); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__15 = PyTuple_Pack(5, __pyx_n_s_array, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_sigma, __pyx_n_s_result); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__15); __Pyx_GIVEREF(__pyx_tuple__15); - __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(5, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_get_langau, 47, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(4, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_langau_pdf, 46, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "pylandau.pyx":53 - * + /* "pylandau.pyx":55 + * # This is done numerically very simple, stability might suffer * - * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< - * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) - * return data_to_numpy_array_double(result, array.shape[0]) + * def get_landau(value, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_tuple__17 = PyTuple_Pack(4, __pyx_n_s_array, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_result); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__17 = PyTuple_Pack(11, __pyx_n_s_value, __pyx_n_s_mpv, __pyx_n_s_eta, __pyx_n_s_A, __pyx_n_s_precision, __pyx_n_s_x, __pyx_n_s_y_pre, __pyx_n_s_index_maximum, __pyx_n_s_maximum, __pyx_n_s_mpv_shift, __pyx_n_s_y); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__17); __Pyx_GIVEREF(__pyx_tuple__17); - __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(3, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_landau_pdf, 53, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(5, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__17, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_get_landau, 55, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "pylandau.pyx":58 + /* "pylandau.pyx":67 * * - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: + * def get_langau(value, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_tuple__19 = PyTuple_Pack(5, __pyx_n_s_array, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_sigma, __pyx_n_s_result); if (unlikely(!__pyx_tuple__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__19 = PyTuple_Pack(12, __pyx_n_s_value, __pyx_n_s_mpv, __pyx_n_s_eta, __pyx_n_s_sigma, __pyx_n_s_A, __pyx_n_s_precision, __pyx_n_s_x, __pyx_n_s_y_pre, __pyx_n_s_index_maximum, __pyx_n_s_maximum, __pyx_n_s_mpv_shift, __pyx_n_s_y); if (unlikely(!__pyx_tuple__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__19); __Pyx_GIVEREF(__pyx_tuple__19); - __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(4, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_langau_pdf, 58, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(6, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_get_langau, 67, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "pylandau.pyx":64 + /* "pylandau.pyx":79 * * - * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * landau = landau_pdf(array, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_tuple__21 = PyTuple_Pack(6, __pyx_n_s_array, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_A, __pyx_n_s_landau, __pyx_n_s_maximum); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__21 = PyTuple_Pack(11, __pyx_n_s_array, __pyx_n_s_mpv, __pyx_n_s_eta, __pyx_n_s_A, __pyx_n_s_precision, __pyx_n_s_x, __pyx_n_s_y_pre, __pyx_n_s_index_maximum, __pyx_n_s_maximum, __pyx_n_s_mpv_shift, __pyx_n_s_y); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__21); __Pyx_GIVEREF(__pyx_tuple__21); - __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(4, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_landau, 64, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__22 = (PyObject*)__Pyx_PyCode_New(5, 0, 11, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__21, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_landau, 79, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "pylandau.pyx":70 + /* "pylandau.pyx":91 * * - * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * langau = langau_pdf(array, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_tuple__23 = PyTuple_Pack(7, __pyx_n_s_array, __pyx_n_s_mu, __pyx_n_s_eta, __pyx_n_s_sigma, __pyx_n_s_A, __pyx_n_s_langau, __pyx_n_s_maximum); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__23 = PyTuple_Pack(12, __pyx_n_s_array, __pyx_n_s_mpv, __pyx_n_s_eta, __pyx_n_s_sigma, __pyx_n_s_A, __pyx_n_s_precision, __pyx_n_s_x, __pyx_n_s_y_pre, __pyx_n_s_index_maximum, __pyx_n_s_maximum, __pyx_n_s_mpv_shift, __pyx_n_s_y); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple__23); __Pyx_GIVEREF(__pyx_tuple__23); - __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(5, 0, 7, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_langau, 70, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_codeobj__24 = (PyObject*)__Pyx_PyCode_New(6, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__23, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_C_Users_DavidLP_git_pyLandau_pyL, __pyx_n_s_langau, 91, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -5961,7 +6209,8 @@ static int __Pyx_InitCachedConstants(void) { static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; - __pyx_float_0_1 = PyFloat_FromDouble(0.1); if (unlikely(!__pyx_float_0_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_float_0_01 = PyFloat_FromDouble(0.01); if (unlikely(!__pyx_float_0_01)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_float_0_001 = PyFloat_FromDouble(0.001); if (unlikely(!__pyx_float_0_001)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -6102,13 +6351,13 @@ PyMODINIT_FUNC PyInit_pylandau(void) * * cdef cnp.double_t* result = NULL # <<<<<<<<<<<<<< * - * + * # The pdf are defined by the original algorithm where mu != MPV */ __pyx_v_8pylandau_result = NULL; /* "pylandau.pyx":29 * - * + * # The pdf are defined by the original algorithm where mu != MPV * def get_landau_pdf(value, mu=0, eta=1): # <<<<<<<<<<<<<< * return landauPDF( value, mu, eta) * @@ -6145,73 +6394,73 @@ PyMODINIT_FUNC PyInit_pylandau(void) /* "pylandau.pyx":41 * * - * def get_landau(value, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * result = get_landau_pdf(value, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< + * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) + * return data_to_numpy_array_double(result, array.shape[0]) */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_7get_landau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_7landau_pdf, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_landau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_landau_pdf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pylandau.pyx":47 + /* "pylandau.pyx":46 * * - * def get_langau(value, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * result = get_langau_pdf(value, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< + * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) + * if result != NULL: */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_9get_langau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_9langau_pdf, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_langau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_langau_pdf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pylandau.pyx":53 - * + /* "pylandau.pyx":55 + * # This is done numerically very simple, stability might suffer * - * def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): # <<<<<<<<<<<<<< - * result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) - * return data_to_numpy_array_double(result, array.shape[0]) + * def get_landau(value, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_11landau_pdf, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_11get_landau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_landau_pdf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_landau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pylandau.pyx":58 + /* "pylandau.pyx":67 * * - * def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): # <<<<<<<<<<<<<< - * result = getLangauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta, < const double&> sigma) - * if result != NULL: + * def get_langau(value, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_13langau_pdf, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_13get_langau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_langau_pdf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_langau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pylandau.pyx":64 + /* "pylandau.pyx":79 * * - * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): # <<<<<<<<<<<<<< - * landau = landau_pdf(array, mu, eta) - * maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) + * def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_15landau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_15landau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_landau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_landau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "pylandau.pyx":70 + /* "pylandau.pyx":91 * * - * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): # <<<<<<<<<<<<<< - * langau = langau_pdf(array, mu, eta, sigma) - * maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) + * def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, sigma=1, A=1, precision=0.01): # <<<<<<<<<<<<<< + * # Determine maximum and MPV shift + * x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_17langau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_8pylandau_17langau, NULL, __pyx_n_s_pylandau); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_langau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_d, __pyx_n_s_langau, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "pylandau.pyx":1 @@ -7002,6 +7251,32 @@ static void __Pyx_RaiseArgtupleInvalid( (num_expected == 1) ? "" : "s", num_found); } +static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) { + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", + name, type->tp_name, Py_TYPE(obj)->tp_name); +} +static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, + const char *name, int exact) +{ + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (none_allowed && obj == Py_None) return 1; + else if (exact) { + if (likely(Py_TYPE(obj) == type)) return 1; + #if PY_MAJOR_VERSION == 2 + else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(PyObject_TypeCheck(obj, type))) return 1; + } + __Pyx_RaiseArgumentTypeInvalid(name, obj, type); + return 0; +} + static PyObject *__Pyx_GetBuiltinName(PyObject *name) { PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name); if (unlikely(!result)) { @@ -7104,32 +7379,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObjec } #endif -static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) { - PyErr_Format(PyExc_TypeError, - "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)", - name, type->tp_name, Py_TYPE(obj)->tp_name); -} -static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, - const char *name, int exact) -{ - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - if (none_allowed && obj == Py_None) return 1; - else if (exact) { - if (likely(Py_TYPE(obj) == type)) return 1; - #if PY_MAJOR_VERSION == 2 - else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; - #endif - } - else { - if (likely(PyObject_TypeCheck(obj, type))) return 1; - } - __Pyx_RaiseArgumentTypeInvalid(name, obj, type); - return 0; -} - #if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { diff --git a/pyLandau/cpp/pylandau.pyx b/pyLandau/cpp/pylandau.pyx index f6d377e..fe3e54e 100644 --- a/pyLandau/cpp/pylandau.pyx +++ b/pyLandau/cpp/pylandau.pyx @@ -25,7 +25,7 @@ cdef data_to_numpy_array_double(cnp.double_t * ptr, cnp.npy_intp N): cdef cnp.double_t* result = NULL - +# The pdf are defined by the original algorithm where mu != MPV def get_landau_pdf(value, mu=0, eta=1): return landauPDF( value, mu, eta) @@ -38,18 +38,6 @@ def get_langau_pdf(value, mu=0, eta=1, sigma=1): return landauGaussPDF( value, mu, eta, sigma) -def get_landau(value, mu=0, eta=1, A=1): - result = get_landau_pdf(value, mu, eta) - maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) - return result / maximum * A # Numerical scaling maximum to A - - -def get_langau(value, mu=0, eta=1, sigma=1, A=1): - result = get_langau_pdf(value, mu, eta, sigma) - maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) - return result / maximum * A # Numerical scaling maximum to A - - def landau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1): result = getLandauPDFData(< double*& > array.data, < const unsigned int&> array.shape[0], < const double&> mu, < const double&> eta) return data_to_numpy_array_double(result, array.shape[0]) @@ -61,13 +49,52 @@ def langau_pdf(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1): return data_to_numpy_array_double(result, array.shape[0]) -def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, A=1): - landau = landau_pdf(array, mu, eta) - maximum = np.max(landau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta)) - return landau / maximum * A # Numerical scaling maximum to A +# These function add a amplitude parameter A and shift the function that mu = MPV +# This is done numerically very simple, stability might suffer + +def get_landau(value, mpv=0, eta=1, A=1, precision=0.01): + # Determine maximum and MPV shift + x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + index_maximum = np.argmax(y_pre) + maximum = y_pre[index_maximum] + mpv_shift = mpv - x[index_maximum] + + y = get_landau_pdf(value, mpv + mpv_shift, eta) # Shift original mu parameter to get a Landau with mu = MPV + return y / maximum * A # Numerical scaling maximum to A + + +def get_langau(value, mpv=0, eta=1, sigma=1, A=1, precision=0.01): + # Determine maximum and MPV shift + x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + index_maximum = np.argmax(y_pre) + maximum = y_pre[index_maximum] + mpv_shift = mpv - x[index_maximum] + + y = get_langau_pdf(value, mpv + mpv_shift, eta, sigma) + return y / maximum * A # Numerical scaling maximum to A + + +def landau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, A=1, precision=0.01): + # Determine maximum and MPV shift + x = np.arange(mpv - 5 * eta, mpv + 5 * eta, 0.001 * eta) # Has to cover maximum, precision defines x deviation around maximum + y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + index_maximum = np.argmax(y_pre) + maximum = y_pre[index_maximum] + mpv_shift = mpv - x[index_maximum] + + y = landau_pdf(array, mpv + mpv_shift, eta) + return y / maximum * A # Numerical scaling maximum to A + +def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mpv=0, eta=1, sigma=1, A=1, precision=0.01): + # Determine maximum and MPV shift + x = np.arange(mpv - 5 * eta, mpv + 5 * eta, precision * eta) # Has to cover maximum, precision defines x deviation around maximum + y_pre = landau_pdf(x, mpv, eta) # Get Landau in original definition first to be able to correct for MPV / mu shift + index_maximum = np.argmax(y_pre) + maximum = y_pre[index_maximum] + mpv_shift = mpv - x[index_maximum] -def langau(cnp.ndarray[cnp.double_t, ndim=1] array, mu=0, eta=1, sigma=1, A=1): - langau = langau_pdf(array, mu, eta, sigma) - maximum = np.max(langau_pdf(np.arange(mu - 5 * eta, mu + 5 * eta, 0.1 * eta), mu, eta, sigma)) - return langau / maximum * A # Numerical scaling maximum to A + y = langau_pdf(array, mpv+mpv_shift, eta, sigma) + return y / maximum * A # Numerical scaling maximum to A