Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Sep 19, 2024
1 parent 29e4fdc commit 98831ae
Show file tree
Hide file tree
Showing 5 changed files with 473 additions and 521 deletions.
3 changes: 1 addition & 2 deletions ostap/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def root_enum ( name , default = None ) :
# c1 = root_color ( 'KRED' )
# @endcode
def root_colors ( color ) :
"""Get predefiend ROOT color by name
""" Get predefiend ROOT color by name
>>> c1 = root_color ( 'Red' )
>>> c1 = root_color ( 'kRed' )
>>> c1 = root_color ( 'RED' )
Expand Down Expand Up @@ -592,7 +592,6 @@ def _TO_draw_ ( obj , option = '', *args , **kwargs ) :

if copy and hasattr ( obj , 'DrawCopy' ): result = obj.DrawCopy ( option , *args )
else : result = obj.Draw ( option , *args )


if pad and not ROOT.gPad :
c = pad.GetCanvas()
Expand Down
57 changes: 26 additions & 31 deletions ostap/fitting/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# @class C1Fun
# Helper wrapper for callable to TF1 object for fitting
class C1Fun(object) :
"""Helper wrapper for callable to TF1 object for fitting
""" Helper wrapper for callable to TF1 object for fitting
"""
def __init__ ( self , fun , xmin , xmax ) :

Expand All @@ -56,7 +56,7 @@ def __init__ ( self , fun , xmin , xmax ) :

## the actual call
def __call__ ( self , x , pars = ( 1.0 , 0.0 , 1.0 ) ) :
"""Call method"""
""" Call method"""
x0 = x if isinstance ( x , num_types ) else x [ 0 ]
#
norm = float ( pars [ 0 ] ) ## NORM
Expand All @@ -70,7 +70,7 @@ def __call__ ( self , x , pars = ( 1.0 , 0.0 , 1.0 ) ) :

## make fit
def Fit ( self , histo , opts = 'S' , gopts = '' , *args ) :
"""Make a fit
""" Make a fit
>>> obj = ...
>>> histo = ...
>>> obj.Fit ( histo , 'S0Q' )
Expand All @@ -82,15 +82,15 @@ def Fit ( self , histo , opts = 'S' , gopts = '' , *args ) :

## fix parameter
def fix ( self , index , value ) :
"""Fix parameter
""" Fix parameter
"""
assert isinstance ( index , integer_types ) and 0 <= index <= 2 , 'Invalid index %s' % index
value = float ( value )
self.__tf1.FixParameter ( index , value )

## set parameter
def set ( self , index , value , error = None ) :
"""Set parameter
""" Set parameter
"""
assert isinstance ( index , integer_types ) and 0 <= index <= 2 , 'Invalid index %s' % index
value = float ( value )
Expand All @@ -100,7 +100,7 @@ def set ( self , index , value , error = None ) :

## set limits for the parameter
def set_limits ( self , index , minv , maxv ) :
"""Set limits for the parameter
""" Set limits for the parameter
"""
assert isinstance ( index , integer_types ) and 0 <= index <= 2 , 'Invalid index %s' % index
minv = float ( minv )
Expand All @@ -116,15 +116,15 @@ def __setitem__ ( self , index , value ) :

## release parameter
def release ( self , index ) :
"""Release parameter
""" Release parameter
"""
assert isinstance ( index , integer_types ) and 0 <= index < 2 , 'Invalid index %s' % index
self.__tf1.ReleaseParameter ( index )

##
@property
def tf1 ( self ) :
"""Get corresponding ROOT.TF1 object
""" Get corresponding ROOT.TF1 object
"""
return self.__tf1

Expand Down Expand Up @@ -153,7 +153,6 @@ def draw ( self , *args , **kwargs ) :
# @class HFit
class HFIT(object) :
__metaclass__ = abc.ABCMeta

## constructor from hfit an dTF1 objects
def __init__ ( self , hfit , tf1 ) :

Expand All @@ -165,22 +164,20 @@ def __init__ ( self , hfit , tf1 ) :

@abc.abstractmethod
def norm ( self ) :
"""Is this object represent normalised function?"""
""" Is this object represent normalised function?"""
return True
@abc.abstractmethod
def npars ( self ) :
"""number of parameters"""
""" Number of parameters"""
return 0
@abc.abstractmethod
def __call__ ( self , x , pars = [] ) :
"""The main call method"""
""" The main call method """
return None

@property
def fun ( self ) :
"""'fun' : actual ROOT.TF1 object"""
return self.__fun

@property
def hfit ( self ) :
"""'hfin' : actual `hfit' object"""
Expand All @@ -194,15 +191,14 @@ def Draw ( self , *args , **kwargs ) : return self.fun.draw ( *args ,
def fit ( self , histo , opts = 'S' , *args ) : return h.Fit ( self.fun , opts , *args )
def Fit ( self , histo , opts = 'S' , *args ) : return h.Fit ( self.fun , opts , *args )


# =============================================================================
## @class H_fit
# simple function to fit/represent the histogram with bernstein/spline
# and other types of function expansion
# @author Vanya BELYAEV [email protected]
# @date 2014-05-09
class H_fit(HFIT) :
"""Simple helper function to fit/represent the histogram with sum of
""" Simple helper function to fit/represent the histogram with sum of
Bernstein/b-spline/legendre/chebyshev, etc functions
"""
def __init__ ( self , hfit , xmin = None , xmax = None ) :
Expand Down Expand Up @@ -277,15 +273,14 @@ def __call__ ( self , x , pars = [] ) :

return norm * self.hfit( x0 )


# =============================================================================
## helper class to wrap 1D-histogram as function
# Optionally normalization, bias and scale are applied
# Seful e.g. for using a histogram as function fitting
# @author Vanya BELYAEV [email protected]
# @date 2011-06-07
class H1Func(object) :
"""Helper class to wrap 1D-histogram as function
""" Helper class to wrap 1D-histogram as function
>>> histo =
>>> func = H1Func ( histo )
Expand Down Expand Up @@ -326,7 +321,7 @@ def __call__ ( self , x , pars = [ 1 , 0 , 1 ] ) :

## get corresponding ROOT.TF1 object
def tf1 ( self ) :
"""Get corresponding ROOT.TF1 object
""" Get corresponding ROOT.TF1 object
"""
if not hasattr ( self , '_tf1' ) :

Expand Down Expand Up @@ -362,15 +357,15 @@ def __init__ ( self , histo , func = lambda s : s.value() , interpolate = True )
def __call__ ( self , x ) :
""" Evaluate the function
"""
x0 = x[0]
y0 = x[1]
x0 = x [ 0 ]
y0 = x [ 1 ]
return self._func ( self._histo ( x0 , y0 , interpolate = self._interp ) )


# ==============================================================================
## create function object
def _funobj0_ ( self ) :
"""Create function object
""" Create function object
"""
if hasattr ( self , '_bfit' ) : return self._bfit
self._bfit = H_fit( self )
Expand All @@ -379,7 +374,7 @@ def _funobj0_ ( self ) :
# ==============================================================================
## create function object
def _funobjN_ ( self ) :
"""Create function object
""" Create function object
"""
if hasattr ( self , '_bfit' ) : return self._bfit
self._bfit = H_Nfit( self )
Expand All @@ -388,7 +383,7 @@ def _funobjN_ ( self ) :
# ==============================================================================
## draw spline object
def _sp_draw_ ( self , opts = '' ) :
"""Draw spline object
""" Draw spline object
>>> spline = ...
>>> spline.draw()
"""
Expand Down Expand Up @@ -420,7 +415,7 @@ def _sp_draw_ ( self , opts = '' ) :
# @author Vanya BELYAEV [email protected]
# @date 2011-06-07
def _h1_as_fun_ ( self , func = lambda s : s.value () , *args , **kwargs ) :
"""Construct the function from the histogram
""" Construct the function from the histogram
>>> histo = ...
>>> fun = histo.asFunc()
"""
Expand All @@ -431,7 +426,7 @@ def _h1_as_fun_ ( self , func = lambda s : s.value () , *args , **kwargs ) :
# @author Vanya BELYAEV [email protected]
# @date 2011-06-07
def _h2_as_fun_ ( self , func = lambda s : s.value () , *args , **kwargs ) :
"""Construct the helper function object from the histogram
""" Construct the helper function object from the histogram
>>> histo = ...
>>> fun = histo.asFunc()
"""
Expand All @@ -443,12 +438,12 @@ def _h2_as_fun_ ( self , func = lambda s : s.value () , *args , **kwargs ) :
# @date 2011-06-07
def _h1_as_tf1_ ( self ,
func = lambda s : s.value () , *args , **kwargs ) :
"""Construct the TF1-function from the 1D-histogram
""" Construct the TF1-function from the 1D-histogram
>>> histo = ...
>>> fun1 = histo.asTF1 ()
"""
#
fun = _h1_as_fun_ ( self , func , *args , **kwargs )
fun = _h1_as_fun_ ( self , func , *args , **kwargs )
f1 = fun .tf1 ()
nb = self.nbins()
f1._tmp_fun = fun
Expand All @@ -472,7 +467,7 @@ def _h1_as_tf1_ ( self ,
# @author Vanya BELYAEV [email protected]
# @date 2015-08-31
def _h1_integral_ ( histo , xlow , xhigh , *args , **kwargs ) :
"""Calculate the integral of TH1
""" Calculate the integral of TH1
(convert ROOT::TH1 to ROOT::TF1 and use ROOT::TF1::Integral)
>>> histo = ...
>>> i1 = histo.integral ( 0.2 , 0.16 )
Expand All @@ -490,7 +485,7 @@ def _h1_integral_ ( histo , xlow , xhigh , *args , **kwargs ) :
# @author Vanya BELYAEV [email protected]
# @date 2011-06-07
def _h2_as_tf2_ ( self , func = lambda s : s.value () , *args , **kwargs ) :
"""Construct the function from the histogram
""" Construct the function from the histogram
>>> fun = h2.asFunc()
>>> fun = h2.asTF () ## ditto
>>> fun = h2.asTF1 () ## ditto
Expand Down Expand Up @@ -526,7 +521,7 @@ def _h2_as_tf2_ ( self , func = lambda s : s.value () , *args , **kwargs ) :
# @author Vanya BELYAEV [email protected]
# @date 2015-08-31
def _h2_integral_ ( histo , xlow , xhigh , ylow , yhigh , *args , **kwargs ) :
"""Calculate the integral of TH2
""" Calculate the integral of TH2
(convert ROOT::TH2 to ROOT::TF2 and use ROOT::TF2::Integral)
>>> histo = ...
>>> i = histo.integral ( 0.2 , 0.16 , 0.1 , 1.0 )
Expand Down
Loading

0 comments on commit 98831ae

Please sign in to comment.