Skip to content

Commit 4c5036c

Browse files
committed
(1) add more PDFs (2) add caches into MoreMath
1 parent 1b31948 commit 4c5036c

File tree

11 files changed

+3488
-797
lines changed

11 files changed

+3488
-797
lines changed

ostap/fitting/distributions.py

Lines changed: 1020 additions & 532 deletions
Large diffs are not rendered by default.

ostap/fitting/fit1d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ def __rmod__ ( self , other ) :
454454
return pdf_convolution ( other , self )
455455

456456
__rmatmult__ = __rmod__
457+
457458

458459
# =============================================================================
459460
## @class Fit1D

ostap/fitting/fithelpers.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
'Phases' , ## helper class for Ostap polynomial/PDFs
2929
'ParamsPoly' , ## helper class for RooFit polynomials
3030
'ShiftScalePoly' , ## helper class for RooFit polynomials
31+
##
32+
'Shift' , ## helper mixin to add shift-parameter
33+
'Scale' , ## helper mixin to add scale-parameter
34+
'ShiftAndScale' , ## helper mixin to add shift&scale parameters
3135
#
3236
'NameDuplicates' , ## allow/disallow name duplicates
3337
'SETPARS' , ## context manager to keep/preserve parameters
@@ -3333,6 +3337,88 @@ def power ( self ) :
33333337
"""'power' : polynomial degree """
33343338
return len ( self.__phis )
33353339

3340+
# =============================================================================
3341+
## @class Shift
3342+
# Helper MIXIN class to add `shift` parameter
3343+
# @author Vanya Belyaev Vanya.Belyaev@CERN.CH
3344+
class Shift ( object ) :
3345+
""" Helper MIXIN class to add `shift` and `scale` parameters
3346+
"""
3347+
def __init__ ( self ,
3348+
shift = None ,
3349+
shift_name = '' ,
3350+
shift_title = '' ) :
3351+
3352+
if shift is None : shift = ROOT.RooFit.RooConst ( 0 )
3353+
##
3354+
name = self.name
3355+
if not shift_name : shift_name = 'shift_%s' % name
3356+
if not shift_title : shift_title = 'shift(%s)' % name
3357+
## shift parameter
3358+
self.__shift = self.make_var ( shift ,
3359+
shift_name ,
3360+
shift_title ,
3361+
None , shift )
3362+
3363+
@property
3364+
def shift ( self ) :
3365+
"""`shift'-parameter"""
3366+
return self.__shift
3367+
@shift.setter
3368+
def shift ( self , value ) :
3369+
self.set_value ( self.__shift , value )
3370+
3371+
# =============================================================================
3372+
## @class Scale
3373+
# Helper MIXIN class to add `scale` parameter
3374+
# @author Vanya Belyaev Vanya.Belyaev@CERN.CH
3375+
class Scale ( object ) :
3376+
""" Helper MIXIN class to add `shift` and `scale` parameters
3377+
"""
3378+
def __init__ ( self ,
3379+
scale = None ,
3380+
scale_name = '' ,
3381+
scale_title = '' ) :
3382+
3383+
if scale is None : scale = ROOT.RooFit.RooConst ( 1 )
3384+
##
3385+
name = self.name
3386+
if not scale_name : scale_name = 'scale_%s' % name
3387+
if not scale_title : scale_title = 'scale(%s)' % name
3388+
## scale parameter
3389+
self.__scale = self.make_var ( scale ,
3390+
scale_name ,
3391+
scale_title ,
3392+
None , scale , 1.e-6 )
3393+
3394+
@property
3395+
def scale ( self ) :
3396+
"""`scale'-parameter"""
3397+
return self.__scale
3398+
@scale.setter
3399+
def scale ( self , value ) :
3400+
self.set_value ( self.__scale , value )
3401+
3402+
# =============================================================================
3403+
## @class ShiftAndScale
3404+
# Helper MIXIN class to add `shift` and `scale` parameters
3405+
# @author Vanya Belyaev Vanya.Belyaev@CERN.CH
3406+
class ShiftAndScale (Shift,Scale) :
3407+
""" Helper MIXIN class to add `shift` and `scale` parameters
3408+
"""
3409+
def __init__ ( self ,
3410+
scale = ROOT.RooFit.RooConst ( 1 ) ,
3411+
shift = ROOT.RooFit.RooConst ( 0 ) ,
3412+
scale_name = '' ,
3413+
scale_title = '' ,
3414+
shift_name = '' ,
3415+
shift_title = '' ) :
3416+
3417+
Shift.__init__ ( self , shift = shift , shift_name = shift_name , shift_title = shifT_title )
3418+
Scale.__init__ ( self , scale = scale , scale_name = scale_name , scale_title = scale_title )
3419+
3420+
# =============================================================================
3421+
33363422

33373423
# =============================================================================
33383424
## @class ShiftScalePoly
@@ -3428,6 +3514,9 @@ def pars_lst ( self ) :
34283514
"""'pars_lst' : polynomial parameters as RooArgList"""
34293515
return self.phis_lst
34303516

3517+
3518+
3519+
34313520
# =============================================================================
34323521
## @class Fractions
34333522
# Helper MIXIN class for implementatiorn of SumXD objects

ostap/fitting/rooreduce.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,23 @@ def _rgenbetap_reduce_ ( pdf ):
20732073

20742074
Ostap.Models.GenBetaPrime.__reduce__ = _rgenbetap_reduce_
20752075

2076+
# =============================================================================
2077+
## reduce GenBeta
2078+
def _r_GenBeta_reduce_ ( pdf ):
2079+
""" Reduce GenBeta"""
2080+
return root_store_factory , ( type ( pdf ) ,
2081+
pdf.name ,
2082+
pdf.title ,
2083+
pdf.x () ,
2084+
pdf.a () ,
2085+
pdf.b () ,
2086+
pdf.gamma () ,
2087+
pdf.p () ,
2088+
pdf.q () ,
2089+
pdf.shift () )
2090+
2091+
Ostap.Models.GenBeta .__reduce__ = _r_GenBeta_reduce_
2092+
20762093
# =============================================================================
20772094
## reduce Landau
20782095
def _rlandau_reduce_ ( pdf ):
@@ -2240,6 +2257,121 @@ def _rBS_reduce_ ( pdf ) :
22402257

22412258
Ostap.Models.BirnbaumSaunders.__reduce__ = _rBS_reduce_
22422259

2260+
# =============================================================================
2261+
## reduce Frechet
2262+
def _r_Frechet_reduce_ ( pdf ) :
2263+
""" Reduce Frechet"""
2264+
return root_store_factory , ( type ( pdf ) ,
2265+
pdf.name ,
2266+
pdf.title ,
2267+
pdf.x () ,
2268+
pdf.alpha () ,
2269+
pdf.scale () ,
2270+
pdf.shift () )
2271+
2272+
Ostap.Models.Frechet.__reduce__ = _r_Frechet_reduce_
2273+
2274+
# =============================================================================
2275+
## reduce Dagum
2276+
def _r_Dagum_reduce_ ( pdf ) :
2277+
""" Reduce Dagum"""
2278+
return root_store_factory , ( type ( pdf ) ,
2279+
pdf.name ,
2280+
pdf.title ,
2281+
pdf.x () ,
2282+
pdf.p () ,
2283+
pdf.a () ,
2284+
pdf.b () ,
2285+
pdf.shift () )
2286+
2287+
Ostap.Models.Dagum.__reduce__ = _r_Dagum_reduce_
2288+
2289+
# =============================================================================
2290+
## reduce BenktanderI&II
2291+
def _r_Benktander_reduce_ ( pdf ) :
2292+
""" Reduce BenktanderI&II"""
2293+
return root_store_factory , ( type ( pdf ) ,
2294+
pdf.name ,
2295+
pdf.title ,
2296+
pdf.x () ,
2297+
pdf.a () ,
2298+
pdf.r () ,
2299+
pdf.scale () ,
2300+
pdf.shift () )
2301+
2302+
Ostap.Models.BenktanderI .__reduce__ = _r_Benktander_reduce_
2303+
Ostap.Models.BenktanderII .__reduce__ = _r_Benktander_reduce_
2304+
2305+
# =============================================================================
2306+
## reduce LogNormal
2307+
def _r_LogNormal_reduce_ ( pdf ) :
2308+
""" Reduce LogNormal"""
2309+
return root_store_factory , ( type ( pdf ) ,
2310+
pdf.name ,
2311+
pdf.title ,
2312+
pdf.x () ,
2313+
pdf.shape () ,
2314+
pdf.scale () ,
2315+
pdf.shift () )
2316+
2317+
Ostap.Models.LogNormal .__reduce__ = _r_LogNormal_reduce_
2318+
2319+
# =============================================================================
2320+
## reduce ExpoLog
2321+
def _r_ExpoLog_reduce_ ( pdf ) :
2322+
""" Reduce ExpoLog"""
2323+
return root_store_factory , ( type ( pdf ) ,
2324+
pdf.name ,
2325+
pdf.title ,
2326+
pdf.x () ,
2327+
pdf.beta () ,
2328+
pdf.psi () ,
2329+
pdf.shift () )
2330+
2331+
Ostap.Models.ExpoLog .__reduce__ = _r_ExpoLog_reduce_
2332+
2333+
# =============================================================================
2334+
## reduce Davis
2335+
def _r_Davis_reduce_ ( pdf ) :
2336+
""" Reduce Davis"""
2337+
return root_store_factory , ( type ( pdf ) ,
2338+
pdf.name ,
2339+
pdf.title ,
2340+
pdf.x () ,
2341+
pdf.b () ,
2342+
pdf.n () ,
2343+
pdf.mu () )
2344+
2345+
Ostap.Models.Davis .__reduce__ = _r_Davis_reduce_
2346+
2347+
# =============================================================================
2348+
## reduce Kumaraswami
2349+
def _r_Kumaraswami_reduce_ ( pdf ) :
2350+
""" Reduce Kumaraswami"""
2351+
return root_store_factory , ( type ( pdf ) ,
2352+
pdf.name ,
2353+
pdf.title ,
2354+
pdf.x () ,
2355+
pdf.a () ,
2356+
pdf.b () ,
2357+
pdf.scale () ,
2358+
pdf.shift () )
2359+
2360+
Ostap.Models.Kumaraswami.__reduce__ = _r_Kumaraswami_reduce_
2361+
2362+
# =============================================================================
2363+
## reduce InverseGamma
2364+
def _r_InverseGamma_reduce_ ( pdf ) :
2365+
""" Reduce InverseGamma"""
2366+
return root_store_factory , ( type ( pdf ) ,
2367+
pdf.name ,
2368+
pdf.title ,
2369+
pdf.x () ,
2370+
pdf.alpha () ,
2371+
pdf.beta () ,
2372+
pdf.shift () )
2373+
2374+
Ostap.Models.InverseGamma.__reduce__ = _r_InverseGamma_reduce_
22432375

22442376

22452377
# =============================================================================

ostap/math/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,8 @@ def _tf3_getattr_ ( self , attr ) :
11761176
Ostap.Math.LogNormal ,
11771177
Ostap.Math.ExpoLog ,
11781178
Ostap.Math.Davis ,
1179+
Ostap.Math.Kumaraswami ,
1180+
Ostap.Math.InverseGamma ,
11791181
## Ostap.Math.Swanson ,
11801182
Ostap.Math.Argus ,
11811183
Ostap.Math.GenArgus ,
@@ -2592,6 +2594,8 @@ def _g3d_random_ ( g3d , N , xmin , xmax , ymin , ymax , zmin , zmax ) :
25922594
Ostap.Math.LogNormal ,
25932595
Ostap.Math.ExpoLog ,
25942596
Ostap.Math.Davis ,
2597+
Ostap.Math.Kumaraswami ,
2598+
Ostap.Math.InverseGamma ,
25952599
## Ostap.Math.Swanson ,
25962600
Ostap.Math.Argus ,
25972601
Ostap.Math.GenArgus ,

ostap/math/more_reduce.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,35 @@ def _om_davis_reduce_ ( peak ) :
820820

821821
Ostap.Math.Davis . __reduce__ = _om_davis_reduce_
822822

823+
# =============================================================================
824+
## Reduce Ostap::Math::Kumaraswami
825+
# @see Ostap::Math::Kumaraswami
826+
def _om_kumaraswami_reduce_ ( peak ) :
827+
"""Reduce `Ostap.Math.Kumaraswami`
828+
- see `Ostap.Math.Kumaraswami`
829+
"""
830+
return root_factory , ( type ( peak ) ,
831+
peak.a () ,
832+
peak.b () ,
833+
peak.scale () ,
834+
peak.shift () )
835+
836+
Ostap.Math.Kumaraswami . __reduce__ = _om_kumaraswami_reduce_
837+
838+
# =============================================================================
839+
## Reduce Ostap::Math::InverseGamma
840+
# @see Ostap::Math::InverseGamma
841+
def _om_inversegamma_reduce_ ( peak ) :
842+
"""Reduce `Ostap.Math.InverseGamma`
843+
- see `Ostap.Math.InverseGamma`
844+
"""
845+
return root_factory , ( type ( peak ) ,
846+
peak.alpha () ,
847+
peak.beta () ,
848+
peak.shift () )
849+
850+
Ostap.Math.InverseGamma . __reduce__ = _om_inversegamma_reduce_
851+
823852
# =============================================================================
824853
## Reduce Ostap::Math::Slash
825854
# @see Ostap::Math::Slash

0 commit comments

Comments
 (0)