Skip to content

Commit

Permalink
few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Feb 21, 2024
1 parent bb0aada commit 4304313
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
51 changes: 35 additions & 16 deletions ostap/fitting/pyselectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ def __init__ ( self ,
assert vmin < vmax, \
"Variable: invalid 'minmax' range (%g,%g)" % ( vmin , vmax )


if description : pass
elif isinstance ( accessor , str ) : description = accessor
else : description = "'%s'-variable" % var
Expand All @@ -444,18 +445,21 @@ def __init__ ( self ,

if isinstance ( accessor , str ) :
accessor = accessor.strip()
if accessor :
if accessor :
from ostap.trees.funcs import FuncFormula as FuncVar
self.__formula = accessor
accessor = FuncVar ( accessor )

accessor = FuncVar ( accessor )
assert callable ( accessor ), \
'Invalid accessor function! %s/%s' % ( accessor , type ( accessor ) )

self.__var = var
self.__minmax = var.minmax()
self.__accessor = accessor
self.__checked = False
self.__var = var
self.__minmax = var.minmax()
self.__accessor = accessor
self.__checked = False
self.__identity = self.formula and self.formula in ( self.name ,
'1.0*(%s)' % self.name ,
'(%s)*1.0' % self.name )

@property
def var ( self ) :
Expand Down Expand Up @@ -495,7 +499,10 @@ def accessor ( self ) :
def formula ( self ) :
"""'formula' - formula for this variable (when applicable)?"""
return self.__formula

@property
def identity ( self ) :
""" id: The same variable? """
return self.__identity
@property
def trivial ( self ) :
"""'trivial' - is this variable 'trivial'?"""
Expand Down Expand Up @@ -2041,18 +2048,22 @@ def fill_dataset2 ( self ,
selection = selector.selection

from ostap.utils.utils import ImplicitMT
from ostap.frames.frames import DataFrame
from ostap.frames.frames import DataFrame, frame_columns

total = len ( self )

frame = DataFrame ( self , enable = True )

frame_main = frame

if not silent :
pb = frame.ProgressBar ( len ( self ) )

columns = set ( frame.columns() )
if ( 6 , 29 ) <= root_info :
from ostap.frames.frames import frame_progress2
cnt = frame_progress2 ( frame )
else :
from ostap.frames.frames import frame_progress
cnt = frame_progress ( frame , total )

columns = set ( frame_columns ( frame ) )

vars = list ( selector.variables )
tvars = [ v for v in vars if v.trivial ] ## trivial vars
Expand All @@ -2061,7 +2072,8 @@ def fill_dataset2 ( self ,
scuts = []
rcuts = selector.roo_cuts

dvars = [ v.name for v in vars if v.name != v.formula and v.name in columns ]
## dvars = [ v.name for v in vars if v.name != v.formula and v.name in columns ]
dvars = [ v.name for v in vars if not v.identity and v.name in columns ]
assert not dvars, "Can't redefine existing variables: %s" % dvars

ranges = []
Expand All @@ -2079,8 +2091,15 @@ def fill_dataset2 ( self ,
vmax = v.vmax ,
accessor = v.name ) ## make it trivial!
nvars.append ( newv )
logger.debug ( 'PROCESS: define %s as %s ' % ( v.name , v.formula ) )
frame = frame.Define ( v.name , v.formula ) ## define new variable for the frame
logger.debug ( 'PROCESS: define %s as %s ' % ( v.name , v.formula ) )

## define new variable
if ( 6 , 26 ) <=root_info and v.name in columns :
frame = frame.Redefine ( v.name , v.formula ) ## REDEFINE
else :
frame = frame.Define ( v.name , v.formula ) ## define new variable for the frame

columns.add ( v.name )

if _minv < mn :
lcut = "(%.16g <= %s)" % ( mn , v.name )
Expand Down
18 changes: 12 additions & 6 deletions ostap/fitting/tests/test_fitting_horns.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
# =============================================================================
import ostap.fitting.roofit
import ostap.fitting.models as Models
from ostap.core.core import Ostap, VE, dsID, rooSilent
from ostap.core.core import Ostap, VE, dsID, rooSilent,rootError
from builtins import range
from ostap.utils.timing import timing
from ostap.plotting.canvas import use_canvas
from ostap.utils.utils import wait
import ROOT, random
import ROOT, random, warnings
# =============================================================================
# logging
# =============================================================================
Expand All @@ -44,14 +44,17 @@ def test_horns_1 () :
delta = ( 1 , 1 , 2 ) ,
resolution = 0.1 ) ,
S = 1000 ,
B = 1 ,
B = 10 ,
suffix = 'horns'
)

horns.signal.a .fix(7)
horns.signal.delta.fix(1)
dataset = horns.generate ( 5000 )
with wait ( 1 ) , use_canvas ( 'Test HORNSdini' ) :
with wait ( 1 ) , use_canvas ( 'Test HORNSdini' ) , warnings.catch_warnings(), rootError() :
warnings.simplefilter("ignore")
horns.S = 5000
horns.B = 50
result , _ = horns.fitTo ( dataset , draw = False , silent = True )
result , _ = horns.fitTo ( dataset , draw = True , silent = True )

Expand All @@ -77,14 +80,17 @@ def test_hill_1 () :
delta = ( 1 , 1 , 2 ) ,
resolution = 0.1 ) ,
S = 1000 ,
B = 1 ,
B = 10 ,
suffix = 'hill'
)

horns.signal.a .fix(7)
horns.signal.delta.fix(1)
dataset = horns.generate ( 5000 )
with wait ( 1 ) , use_canvas ( 'Test HILLdini' ) :
with wait ( 1 ) , use_canvas ( 'Test HILLdini' ) , warnings.catch_warnings() , rootError () :
warnings.simplefilter("ignore")
horns.S = 5000
horns.B = 50
result , _ = horns.fitTo ( dataset , draw = False , silent = True )
result , _ = horns.fitTo ( dataset , draw = True , silent = True )

Expand Down

0 comments on commit 4304313

Please sign in to comment.