Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Nov 21, 2024
1 parent 05b80fd commit 80a82e4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
16 changes: 15 additions & 1 deletion ostap/fitting/funbasic.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def load_params ( self , params = {} , dataset = None , silent = False , **kwarg
# options = pdf.draw_option ( 'signal_style' )
# @endcode
def draw_option ( self , key , default = () , **kwargs ) :
"""Get the certain predefined drawing option
""" Get the certain predefined drawing option
>>> options = ROOT.RooFit.LineColor(2), ROOT.RooFit.LineWidth(4)
>>> pdf = ...
>>> pdf.draw_options['signal_style'] = [ options ]
Expand Down Expand Up @@ -720,6 +720,7 @@ def draw ( self ,
#
from ostap.plotting.style import useStyle

silent = kwargs.get ( 'silent' , True )
#
## again the context
#
Expand All @@ -733,6 +734,16 @@ def draw ( self ,
## the total fit curve
#
coptions = self.draw_option ( 'curve_options' , **kwargs )
if not silent and coptions :
rows = [ ( 'Curve draw' , ) ]
for o in coptions :
row = str ( o ) ,
rows.append ( row )
import ostap.logger.table as T
title = 'draw: curve-options'
table = T.table ( rows , title = 'Draw curve' ,prefix = '# ' )
self.info ( '%s:\n%s' % ( title , table ) )

self.plot_on ( self.fun , frame , *coptions )
kwargs.pop ( 'curve_options' , () )
#
Expand Down Expand Up @@ -775,13 +786,16 @@ def plot_on ( self , what , frame , *options ) :
assert all ( isinstance ( o , ROOT.RooCmdArg ) for o in options ), \
"plot_on: invalid argument types: %s" % list ( options )


## for "small' number of arguments use the standard function
if len ( options ) <= NARGS and root_info < ( 6 , 29 ) :
return what.plotOn ( frame , *options )

from ostap.fitting.roocmdarg import command
cmd = command ( *options )



return what.plotOn ( frame , cmd )

## ## merge arguments to get shorter list
Expand Down
70 changes: 52 additions & 18 deletions ostap/fitting/pdfbasic.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,18 @@ def _draw ( self , what , frame , options , style = None , args = () ) :
atup = args + tuple ( options ) + tuple ( st )
self.debug ( 'drawing component %s with options %s' % ( cmp.name , ( component, ) + atup ) )
self.plot_on ( self.pdf , frame , component , *atup )


# ================================================================================
## Helper method to draw total fit curve
def _draw_total ( self , frame , *args , **kwargs ) :
""" Helper method to draw total fit curve
"""
totoptions = self.draw_option ( 'total_fit_options' , **kwargs )
self.plot_on ( self.pdf , frame , *totoptions )

# ================================================================================
## helper method to draw "signal-like" components
def _draw_signals ( self , frame , *args , **kwargs ) :
def _draw_signals ( self , frame , *args , **kwargs ) :
""" Helper method to draw `signal-like' components
"""

Expand All @@ -641,7 +649,7 @@ def _draw_signals ( self , frame , *args , **kwargs ) :
if self.signals and drawit2 :
soptions = self.draw_option ( 'signal_options' , **kwargs )
sbstyle = self.draw_option ( 'signal_style' , **kwargs )
self._draw( self.signals , frame , soptions , sbstyle , args )
self._draw ( self.signals , frame , soptions , sbstyle , args )

# ================================================================================
## helper method to draw "crossterm-like" components
Expand All @@ -658,12 +666,12 @@ def _draw_crossterms ( self , frame , *args , **kwargs ) :
if self.crossterms1 and drawit1 :
ct1options = self.draw_option ( 'crossterm1_options' , **kwargs )
ct1bstyle = self.draw_option ( 'crossterm1_style' , **kwargs )
self._draw( self.crossterms1 , frame , ct1options , ct1bstyle , args )
self._draw ( self.crossterms1 , frame , ct1options , ct1bstyle , args )

if self.crossterms2 and drawit2 :
ct2options = self.draw_option ( 'crossterm2_options' , **kwargs )
ct2bstyle = self.draw_option ( 'crossterm2_style' , **kwargs )
self._draw( self.crossterms2 , frame , ct2options , ct2bstyle , args )
self._draw ( self.crossterms2 , frame , ct2options , ct2bstyle , args )

# ================================================================================
## helper method to draw "other" components
Expand All @@ -687,7 +695,7 @@ def _draw_components ( self , frame , *args , **kwargs ) :
if self.components and drawit2 :
coptions = self.draw_option ( 'component_options' , **kwargs )
cbstyle = self.draw_option ( 'component_style' , **kwargs )
self._draw( self.components , frame , coptions , cbstyle , args )
self._draw ( self.components , frame , coptions , cbstyle , args )

# ================================================================================
## helper method to draw "background-like" components
Expand All @@ -711,7 +719,7 @@ def _draw_backgrounds ( self , frame , *args , **kwargs ) :
if self.backgrounds and drawit2 :
boptions = self.draw_option ( 'background_options' , **kwargs )
bbstyle = self.draw_option ( 'background_style' , **kwargs )
self._draw( self.backgrounds , frame , boptions , bbstyle )
self._draw ( self.backgrounds , frame , boptions , bbstyle , args )

# ================================================================================
## draw fit results
Expand Down Expand Up @@ -859,8 +867,6 @@ def draw ( self ,
data_options = data_options + ( ROOT.RooFit.Binning ( nbins ) , )

if dataset :

commands = data_options
commands = data_options + args + ( ROOT.RooFit.Invisible() , )
self.plot_on ( dataset , frame , *commands )

Expand All @@ -882,20 +888,48 @@ def draw ( self ,
if dataset and not 'D' in draw_order :
self.info ( "Plotting of `data' is omitted" )

## now draw the classified components
## now draw the classified components
drawargs = args

for c in draw_order :
if 'S' == c : self._draw_signals ( frame , *args , **kwargs )
elif 'X' == c : self._draw_crossterms ( frame , *args , **kwargs )
elif 'C' == c : self._draw_components ( frame , *args , **kwargs )
elif 'B' == c : self._draw_backgrounds ( frame , *args , **kwargs )
if 'S' == c :
self._draw_signals ( frame , *drargs , **kwargs )
used_options.add ( 'draw_combined_signal' )
used_options.add ( 'draw_signals' )
used_options.add ( 'combined_signal_options' )
used_options.add ( 'combined_signal_style' )
used_options.add ( 'signal_options' )
used_options.add ( 'signal_style' )
elif 'X' == c :
self._draw_crossterms ( frame , *drargs , **kwargs )
used_options.add ( 'draw_crossterm1' )
used_options.add ( 'draw_crossterm2' )
used_options.add ( 'crossterm1_options' )
used_options.add ( 'crossterm1_style' )
used_options.add ( 'crossterm2_options' )
used_options.add ( 'crossterm2_style' )
elif 'C' == c :
self._draw_components ( frame , *drargs , **kwargs )
used_options.add ( 'draw_combined_component' )
used_options.add ( 'draw_components' )
used_options.add ( 'combined_component_options' )
used_options.add ( 'combined_component_style' )
used_options.add ( 'component_options' )
used_options.add ( 'component_style' )
elif 'B' == c :
self._draw_backgrounds ( frame , *drargs , **kwargs )
used_options.add ( 'draw_combined_background' )
used_options.add ( 'draw_backgrounds' )
used_options.add ( 'combined_background_options' )
used_options.add ( 'combined_background_style' )
used_options.add ( 'background_options' )
used_options.add ( 'background_style' )
elif 'T' == c :
## the total fit curve
totoptions = self.draw_option ( 'total_fit_options' , **kwargs )
self.plot_on ( self.pdf , frame , *totoptions )
self._draw_total ( frame , *drargs , **kwargs )
used_options.add ( 'total_fit_options' )
elif 'D' == c :
if dataset :
## draw data once more
## draw data once more
commands = data_options + args
self.plot_on ( dataset , frame , *commands )
else :
Expand Down
14 changes: 7 additions & 7 deletions ostap/stats/gof_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ def row ( self , what , result , width = 5 , precision = 3 ) :
fmt2 = '%s/%s' % ( fmtv , fmtv )

return ( what ,
fmtv % ( value / scale ) ,
( mean / scale ).toString ( fmt ) ,
fmtv % ( rms / scale ) ,
fmt2 % ( vmin / scale , vmax / scale ) ,
( '10^%+d' % expo if expo else '' ) ,
( 100 * pvalue ) .toString ( '%.2f +/- %-.2f' ) ,
( nsigma ) .toString ( '%.1f +/- %-.1f' ) )
fmtv % ( value / scale ) ,
( mean / scale ).toString ( fmt ) ,
fmtv % ( rms / scale ) ,
fmt2 % ( vmin / scale , vmax / scale ) ,
( '10^%+d' % expo if expo else '' ) ,
( 100 * pvalue ) .toString ( '%.3f +/- %-.3f' ) ,
( nsigma ) .toString ( '%.2f +/- %-.2f' ) )

# =========================================================================
## Make a summary table
Expand Down

0 comments on commit 80a82e4

Please sign in to comment.