Skip to content

Commit

Permalink
1. suppress CloneData argument for NLL creation for 6.28<=ROOT
Browse files Browse the repository at this point in the history
  1. change default `silent=True` to `silent=False` for `graph_profile`
  1. modify a bit treatment of `residual=` and `pull=` in `PDF.draw`
  • Loading branch information
VanyaBelyaev committed Nov 29, 2024
1 parent e7d130f commit e78185c
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .aux/test_with_lcg
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ CMTCONFIG=$2
source /cvmfs/sft.cern.ch/lcg/views/${LCG}/${CMTCONFIG}/setup.sh
source build/INSTALL/thisostap.sh
cd build
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j2 --output-on-failure --test-output-size-failed 5000000
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j2 -R fitt --output-on-failure --test-output-size-failed 5000000
5 changes: 4 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
1. add parallelisation to `GoF1DToys`
1. add `style=None` or `style=''` argument for many `table`-methods
1. add empirical cumulative functions for weighted data

1. suppress `CloneData` argument for NLL creation for 6.28<=ROOT
1. change default `silent=True` to `silent=False` for `graph_profile`
1. modify a bit treatment of `residual=` and `pull=` in `PDF.draw`

## Backward incompatible

## Bug fixes
Expand Down
6 changes: 5 additions & 1 deletion ostap/fitting/fithelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,11 @@ def parse_args ( self , dataset = None , *args , **kwargs ) :

_args.append ( ROOT.RooFit.Save ( a ) )

elif key in args_clonedata and isinstance ( a , bool ) :
elif key in args_clonedata and ( 6 , 28 ) <= root_info < ( 6, 28 ) :

self.warning ( "Ignore obsolete `CloneData' argument" )

elif key in args_clonedata and isinstance ( a , bool ) and root_info < ( 6, 28 ) :

_args.append ( ROOT.RooFit.CloneData ( a ) )

Expand Down
60 changes: 43 additions & 17 deletions ostap/fitting/pdfbasic.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def fitTo ( self ,
## mnv , mxv ) )

if not silent and opts and nontrivial_arg ( ( 'Save' , 'NumCPU' ) , *opts ) :
## self.info ('fitTo options: %s ' % list ( flat_args ( *opts ) ) )
rows = [ ( 'Option' , ) ]
for o in opts :
row = str ( o ) ,
Expand Down Expand Up @@ -984,18 +983,17 @@ def draw ( self ,
if 0 < binw : self.info ( 'chi2/ndf: %.3f, binwidth: %s' % ( frame.chi2ndf , binw ) )
else : self.info ( 'chi2/ndf: %.3f' % frame.chi2ndf )

## a bit strange action but it helps to avoid decolorization/reset for the last created frame
frame = frame.copy ()
if not kwargs.get ( 'draw_axis_title' , False ) :
frame.SetXTitle ( '' )
frame.SetYTitle ( '' )
frame.SetZTitle ( '' )


if not residual and not pull:
frame = frame.copy () ## a bit strange action but it helps to avoid decolorization/reset for the last created frame
if frame and not kwargs.get ( 'draw_axis_title' , False ) :
frame.SetXTitle ( '' )
frame.SetYTitle ( '' )
frame.SetZTitle ( '' )
return frame

rframe = None
if residual :
if residual and frame :
if residual is True : residual = "P" ,
elif isinstance ( residual , str ) : residual = residual ,
rframe = frame.emptyClone ( rootID ( 'residual_' ) )
Expand All @@ -1009,7 +1007,7 @@ def draw ( self ,
rframe.SetZTitle ( '' )

pframe = None
if pull :
if pull and frame :
if pull is True : pull = "P",
elif isinstance ( pull , str ) : pull = pull ,
pframe = frame.emptyClone ( rootID ( 'pull_' ) )
Expand All @@ -1022,6 +1020,26 @@ def draw ( self ,
pframe.SetYTitle ( '' )
pframe.SetZTitle ( '' )

## a bit strange action but it helps to avoid decolorization/reset for the last created frame
frame = frame.copy () if frame else frame
rframe = rframe.copy () if rframe else rframe
pframe = pframe.copy () if pframe else pframe

if frame and not kwargs.get ( 'draw_axis_title' , False ) :
frame.SetXTitle ( '' )
frame.SetYTitle ( '' )
frame.SetZTitle ( '' )

if rframe and not kwargs.get ( 'draw_axis_title' , False ) :
rframe.SetXTitle ( '' )
rframe.SetYTitle ( '' )
rframe.SetZTitle ( '' )

if pframe and not kwargs.get ( 'draw_axis_title' , False ) :
pframe.SetXTitle ( '' )
pframe.SetYTitle ( '' )
pframe.SetZTitle ( '' )

return frame, rframe, pframe

# =========================================================================
Expand Down Expand Up @@ -1322,9 +1340,10 @@ def nll ( self ,
if not isinstance ( dataset , ROOT.RooAbsData ) and hasattr ( dataset , 'dset' ) :
dataset = dataset.dset

clone = kwargs.pop ( 'clone' , False )
kwargs [ 'clone' ] = clone
if not clone : kwargs['optimize'] = False
if root_info < ( 6 , 28 ) :
clone = kwargs.pop ( 'clone' , False )
kwargs [ 'clone' ] = clone
if not clone : kwargs [ 'optimize' ] = False

opts = self.parse_args ( dataset , *args , **kwargs )

Expand All @@ -1338,13 +1357,20 @@ def nll ( self ,
ok.append ( o )

opts = tuple ( ok )
if not silent and opts : self.info ('NLL options: %s ' % list ( opts ) )

if not silent and opts and nontrivial_arg ( ( 'Save' , 'NumCPU' ) , *opts ) :
rows = [ ( 'Option' , ) ]
for o in opts :
row = str ( o ) ,
rows.append ( row )
import ostap.logger.table as T
title = 'nll: createNLL options'
table = T.table ( rows , title = 'CreateNLL options' , prefix = '# ' )
self.info ( '%s:\n%s' % ( title , table ) )

## get s-Factor
sf = dataset.sFactor()

self.debug ( 'nll: createNLL args: %s'% list ( opts ) )

if ( 6 , 32 ) <= root_info :
return Ostap.MoreRooFit.createNLL ( self.pdf , dataset , *opts ), sf

Expand Down Expand Up @@ -1442,7 +1468,7 @@ def graph_profile ( self ,
values ,
dataset ,
fix = [] ,
silent = True ,
silent = False ,
draw = False ,
subtract = True ,
args = () , **kwargs ) :
Expand Down
16 changes: 8 additions & 8 deletions ostap/fitting/simfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,18 +1362,18 @@ def __getitem__ ( self , param ) :
return self.pdf.__getitem__ ( param )

# =========================================================================
## get NLL/profile-graph for the variable, using the specified bscissas
## get NLL/profile-graph for the variable, using the specified abscissas
# @code
# pdf = ...
# graph = pdf.graph_nll ( 'S' ,
# range ( 0 , 100 ) ,
# dataset )
# graph = pdf.graph_nll ( 'S' ,
# vrange ( 0 , 100 ) ,
# dataset )
# @endcode
def graph_nll ( self , *args , **kwargs ) :
""" Get NLL/profile-graph for the variable, using the specified abscissas
>>> pdf = ...
>>> graph = pdf.graph_nll ( 'S' ,
... range ( 0 , 100 ) ,
... vrange ( 0 , 100 ) ,
... dataset )
"""
return self.pdf.graph_nll ( *args , **kwargs )
Expand All @@ -1389,9 +1389,9 @@ def graph_nll ( self , *args , **kwargs ) :
def graph_profile ( self , *args , **kwargs ) :
""" Get profile-graph for the variable, using the specified abscissas
>>> pdf = ...
>>> graph = pdf.graph_profile ( 'S' ,
... range ( 0 , 12.5 , 20 ) ,
... dataset )
>>> graph = pdf.graph_profile ( 'S' ,
... vrange ( 0 , 12.5 , 20 ) ,
... dataset )
"""
return self.pdf.graph_profile ( *args , **kwargs )

Expand Down
19 changes: 17 additions & 2 deletions ostap/fitting/tests/test_fitting_simfit1.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,27 @@ def test_simfit1 () :
with use_canvas ( 'test_simfit1: fit both datasets & draw B' , wait = 2 ) :
fB = model_sim.draw ( 'B' , dataset , nbins = 50 )
graphs.append ( fB )
with use_canvas ( 'test_simfit1: graph-NLL for S_M2' , wait = 2 ) :
from ostap.utils.utils import vrange
grs = model_sim.graph_nll ( 'S_M2' , vrange ( 0 , 1000 , 100 ) , dataset , draw = True )
grs.draw('apl')
graphs.append ( grs )
with use_canvas ( 'test_simfit1: graph-profile for S_M2' , wait = 2 ) :
from ostap.utils.utils import vrange
grs = model_sim.graph_profile ( 'S_M2' , vrange ( 0 , 1000 , 100 ) , dataset , draw = True )
grs = model_sim.graph_profile ( 'S_M2' , vrange ( 0 , 1000 , 50 ) , dataset , draw = True )
grs.draw('apl')
graphs.append ( grs )

with use_canvas ( 'test_simfit1: residual for S_M2' , wait = 2 ) :
_ , residual , _ = model_sim.draw ( 'A' , dataset , nbins = 50 , residual = 'P' )
residual.draw()
graphs.append ( residual )

with use_canvas ( 'test_simfit1: pull for S_M2' , wait = 2 ) :
_ , _ , pull = model_sim.draw ( 'A' , dataset , nbins = 50 , pull = 'P' )
pull.draw()
graphs.append ( pull )

models.add ( model1 )
models.add ( model2 )
models.add ( model_sim )
Expand Down Expand Up @@ -232,7 +247,6 @@ def test_simfit1 () :
title = 'Results of simultaneous fit to generated dataset'
logger.info ( '%s\n%s' % ( title , rg.table ( title = title , prefix = '# ' ) ) )


# =============================================================================
## check that everything is serializable
# =============================================================================
Expand All @@ -254,6 +268,7 @@ def test_db() :
db['models' ] = models
for r in results : db['result' + r.name ] = r
db['results' ] = results
db['graphs' ] = graphs
db.ls()

# =============================================================================
Expand Down

0 comments on commit e78185c

Please sign in to comment.