Skip to content

Commit

Permalink
modify stats
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Jul 23, 2024
1 parent c55be13 commit 0e4929c
Show file tree
Hide file tree
Showing 18 changed files with 1,084 additions and 1,148 deletions.
2 changes: 1 addition & 1 deletion .aux/test_with_lcg
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ 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 -j8 -R '(stat|frame)' --output-on-failure
ctest -N && cmake .. -DCMAKE_INSTALL_PREFIX=./INSTALL/ && ctest -j8 --output-on-failure

4 changes: 2 additions & 2 deletions ostap/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def split_string_respect ( text , separators = ',;:' , strip = True ) :
## strip items if required
if strip : items = [ item.strip() for item in items ]
## remove empty items
return [ item for item in items if item ]
return tuple ( item for item in items if item )

# =============================================================================
## split string using separators:
Expand Down Expand Up @@ -1088,7 +1088,7 @@ def split_string ( line ,
## strip items if required
if strip : items = [ i.strip() for i in items ]
## remove empty items
return [ item for item in items if item ]
return tuple ( item for item in items if item )



Expand Down
48 changes: 24 additions & 24 deletions ostap/fitting/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
list_types , sequence_types )
from ostap.math.base import islong
from ostap.fitting.variables import valid_formula, make_formula
import ostap.trees.cuts
from ostap.trees.cuts import expression_types, vars_and_cuts
import ostap.fitting.roocollections
import ostap.fitting.printable
import ROOT, random, math, sys, ctypes
Expand Down Expand Up @@ -1143,6 +1143,14 @@ def ds_var_minmax ( dataset , var , cuts = '' , delta = 0.0 ) :
>>> mn,mx = data.vminmax('pt')
>>> mn,mx = data.vminmax('pt','y>3')
"""

assert isinstance ( var , expression_types ) , 'Invalid expression!'
assert isinstance ( cuts , expression_types ) , 'Invalid expression!'

var = str ( var )
cuts = str ( cuts ).strip()


if isinstance ( var , ROOT.RooAbsReal ) : var = var.GetName()
if cuts : s = dataset.statVar ( var , cuts )
else : s = dataset.statVar ( var )
Expand Down Expand Up @@ -1188,8 +1196,12 @@ def _ds_has_entry_ ( dataset , selection , *args ) :
>>> dataset.hasEntry ( 'pt>100' , 0, 1000 ) ##
>>> dataset.hasEntry ( 'pt>100' , 'fit_range' ) ##
>>> dataset.hasEntry ( 'pt>100' , 'fit_range' , 0 , 1000 ) ##
- see Ostap.StatVar.hasEntru
- see Ostap.StatVar.hasEntry
"""

assert isinstance ( selection , expression_types ) , 'Invalid expression!'
selection = str ( selection ).strip()

result = Ostap.StatVar.hasEntry ( dataset , selection , *args )
return True if result else False

Expand Down Expand Up @@ -1853,24 +1865,12 @@ def _ds_table_0_ ( dataset ,
if not valid_pointer ( varset ) :
logger.error('Invalid dataset')
return ''

if isinstance ( variables , str ) :
variables = split_string ( variables , var_separators , strip = True , respect_groups = True )

if 1 == len ( variables ) : variables = variables [0]

if isinstance ( variables , str ) :

if variables in varset :
vars = [ variables ]
else :
vars = list ( dataset.branches ( variables ) )

elif variables : vars = [ i.GetName() for i in varset if i.GetName() in variables ]
else : vars = [ i.GetName() for i in varset ]

if variables : vars , cuts = vars_and_cuts ( variables , cuts )
else : vars , cuts = [ v.name for v in varset ] , str ( cuts ).strip()

vars = [ i.GetName() for i in varset if i.GetName() in vars ]

#

_vars = []

stat = dataset.statVars ( vars , cuts , first , last )
Expand Down Expand Up @@ -2067,11 +2067,12 @@ def _ds_table_1_ ( dataset ,
"""Print data set as table
"""

if isinstance ( variables , str ) :
variables = split_string ( variables , var_separators , strip = True , respect_groups = True )


if variables : vars , cuts = vars_and_cuts ( variables , cuts )
else : vars , cuts = [ v.name for v in varset ] , str ( cuts ).strip()

_vars = []
vvars = tuple ( sorted ( variables ) )
vvars = tuple ( sorted ( vars ) )
stat = dataset.statVars ( vvars , cuts , first , last )
for v in stat :
s = stat [ v ]
Expand All @@ -2087,7 +2088,6 @@ def _ds_table_1_ ( dataset ,
_vars.append ( r )
_vars.sort()


tt = dataset.GetTitle()

if not title :
Expand Down
33 changes: 1 addition & 32 deletions ostap/frames/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,37 +345,6 @@ def frame_statCov ( frame ,
## possible types of expressions
expression_types = string_types + ( ROOT.TCut , )
# ==============================================================================
## Prepare the arguments: variable names and cuts
# @code
# vars_lst, cuts, input_string = vars_and_cuts ( 'x', 'y<0' )
# vars_lst, cuts, input_string = vars_and_cuts ( ('x','y','z') , 'y<0' )
# @endcode
def vars_and_cuts ( expressions , cuts ) :
"""Prepare the arguments: variable names and cuts
>>> vars_lst, cuts, input_string = vars_and_cuts ( 'x', 'y<0' )
>>> vars_lst, cuts, input_string = vars_and_cuts ( ('x','y','z') , 'y<0' )
"""

## single string as input
input_string = False
if isinstance ( expressions , expression_types ) :
input_string = True
expressions = [ expressions ]

assert expressions and all ( s and isinstance ( s , expression_types ) for s in expressions ) , \
"Invalid expression(s) : %s" % str ( expressions )

exprs = tuple ( str(s).strip() for s in expressions )
assert exprs and all ( exprs ) , "Invalid expression(s): %s" % str ( exprs )

assert isinstance ( cuts , expression_types ) or not cuts , \
'Invaild type of cuts: %s' % str ( cuts )

cuts = str ( cuts ) if cuts else ''

return exprs, cuts, input_string

# ==================================================================================
## helper functionm that defines expression and cuts
# @code
# frame = ...
Expand All @@ -387,7 +356,7 @@ def _fr_helper_ ( frame , expressions , cuts = '' ) :
>>> current , vexpr , cexpr = _fr_helper_ ( frame , 'x*x' , 'z<0' )
"""

exprs, cuts, input_string = vars_and_cuts ( expressions , cuts )
exprs, cuts, input_string = SV.vars_and_cuts ( expressions , cuts )

## Frame/Tree ?
if isinstance ( frame , ROOT.TTree ) : frame = DataFrame ( frame )
Expand Down
Loading

0 comments on commit 0e4929c

Please sign in to comment.