Skip to content

Commit

Permalink
fix for old ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaBelyaev committed Mar 13, 2024
1 parent e955728 commit 53cf14d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
53 changes: 28 additions & 25 deletions ostap/fitting/pyselectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def __init__ ( self , total = 0 , processed = 0 , skipped = 0 ) :
"Invalid counters: %s/%s/%s" % ( total, processed , skipped)

self.__total = total
self.__processed = processed
self.__processed = processed ## passed cuts
self.__skipped = skipped

@property
Expand All @@ -690,7 +690,7 @@ def processed ( self , value ) :

@property
def skipped ( self ) :
"""'skipped' : number of skipped events (e.g. due to variabel ranges)"""
"""'skipped' : number of skipped events (e.g. due to variable ranges)"""
return self.__skipped
@skipped.setter
def skipped ( self , value ) :
Expand Down Expand Up @@ -892,7 +892,7 @@ def __init__ ( self ,
## self.__triv_sel = False
if not selection : self.__triv_sel = True
elif tree and tree.valid_formula ( selection ) : self.__triv_sel = True
elif valid_formula ( selection , self.varset ) :
elif tree and valid_formula ( selection , self.varset ) :
if not roo_cuts : roo_cuts = selection
else : roo_cuts = '(%s)*(%s)' % ( roo_cuts, selection )
selection = ''
Expand Down Expand Up @@ -965,11 +965,12 @@ def __init__ ( self ,
self.__roo_formula = None

if roo_cuts :
varlist = self.__data.varlist()
roosel = make_formula ( roo_cuts , roo_cuts , varlist )
self.__roo_formula = roosel
vlst = ROOT.RooArgList()
for v in self.varset : vlst.add ( v )
self.__varlist = vlst
self.__roo_formula = make_formula ( roo_cuts , roo_cuts , vlst )
self.__roo_cuts = roo_cuts

## it is still very puzzling for me: should this line be here at all??
ROOT.SetOwnership ( self.__data , False )

Expand Down Expand Up @@ -1119,7 +1120,7 @@ def process_entry ( self ):
## == for more convenience
#
bamboo = self.tree
##
##
return self.fill ( bamboo )

# =========================================================================
Expand Down Expand Up @@ -1149,8 +1150,8 @@ def fill ( self , bamboo ) :
return 0 ## RETURN

var.setVal ( value )

## no roo-cuts are specified or roo-cuts are satisfied
## no roo-cuts are specified or roo-cuts are satisfied
if ( not self.__roo_formula ) or self.__roo_formula.getVal() :
self.__data .add ( self.varset )

Expand Down Expand Up @@ -1364,10 +1365,11 @@ def Begin ( self , tree = ROOT.nullptr ) :
# reset Roo-formula (if specified)
if self.roo_cuts :
roo_cuts = self.roo_cuts
del self.__roo_formula
varlist = self.__data.varlist()
roosel = make_formula ( roo_cuts , roo_cuts , varlist )
self.__roo_formula = roosel
del self.__roo_formula
vlst = ROOT.RooArgList ()
for v in self.varset : vlst.add ( v )
self.__varlist = vlst
self.__roo_formula = make_formula ( roo_cuts , roo_cuts , vlst )

## take care on the progress bar
if self.__progress and not self.silence :
Expand All @@ -1391,14 +1393,14 @@ def SlaveBegin ( self , tree ) :
#
assert self.ok () , 'SlaveBegin::Formula is invalid!'
#
#
# reset Roo-formula (if specified)
# reset Roo-formula (if specified)
if self.roo_cuts :
roo_cuts = self.roo_cuts
del self.__roo_formula
varlist = self.__data.varlist()
roosel = make_formula ( roo_cuts , roo_cuts , varlist )
self.__roo_formula = roosel
roo_cuts = self.roo_cuts
del self.__roo_formula
vlst = ROOT.RooArgList ()
for v in self.varset : vlst.add ( v )
self.__varlist = vlst
self.__roo_formula = make_formula ( roo_cuts , roo_cuts , vlst )

## take care on the progress bar
if not self.__progress and not self.silence :
Expand Down Expand Up @@ -1766,7 +1768,8 @@ def make_dataset_old ( tree ,
ffs = []
fcuts = []
for f in formulas :
fv = make_formula ( f.name , f.description , f.formula , ds )
fv = make_formula ( f.name , f.formula , ds )
fv.title = f.description
ffs.append ( fv )
fcols.add ( fv )
mn , mx = f.minmax
Expand Down Expand Up @@ -2023,9 +2026,9 @@ def fill_dataset2 ( self ,
>>> chain.fill_dataset2 ( selector ) ## NB: note lowercase 'process' here !!!
"""

## if use_frame and root_info < (6,15) :
## logger.warning ( 'Processing via DataFrame is disabled for %s' % str ( root_info ) )
## use_frame = False
if use_frame and root_info < (6,15) :
## logger.warning ( 'Processing via DataFrame is disabled for %s' % str ( root_info ) )
use_frame = False

## process all events?
all = ( 0 == first ) and ( nevents < 0 or len ( self ) <= nevents )
Expand Down
10 changes: 5 additions & 5 deletions ostap/fitting/tests/test_fitting_fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def xvar ( s ) : return (s.mass+s.pt+s.eta)/s.eta

# =============================================================================
def test_fitting_fill_1 () :
## if 1 < 2 :

logger = getLogger ('test_fitting_fill_1' )

## prepare data
Expand All @@ -149,13 +149,14 @@ def test_fitting_fill_1 () :
( 'x' , 'some variable' , 0 , 5000 , '(mass+pt+eta)/eta' )
]

config = { 'variables' : variables , 'selection' : "pt>7 && eta<3" }
config = { 'variables' : variables , 'selection' : "(pt>7) && (eta<3)" }

with timing ( "No SHORTCUT, no FRAME" , logger = None ) as t1 :
logger.info ( attention ( t1.name ) )
selector = SelectorWithVars ( **config )
chain.fill_dataset ( selector , shortcut = False , use_frame = False )
ds1_1 = selector.data

with timing ( " SHORTCUT, no FRAME" , logger = None ) as t2 :
logger.info ( attention ( t2.name ) )
selector = SelectorWithVars ( **config )
Expand All @@ -176,7 +177,7 @@ def test_fitting_fill_1 () :
with timing ( " pure-FRAME (new) " , logger = None ) as t5 :
logger.info ( attention ( t5.name ) )
ds1_5 , _ = chain.make_dataset ( silent = False , **config )

table = [ ('Configuration' , 'CPU' ) ]

table.append ( ( t1.name , '%.3fs' % t1.delta ) )
Expand All @@ -199,7 +200,6 @@ def test_fitting_fill_1 () :
if DataSet_NEW_FILL :
if ds1_1 != ds1_5 : logger.error ('Datasets ds1_1 and ds1_5 are different!' )


with timing ( "No SHORTCUT, no FRAME" , logger = None ) as t1 :
logger.info ( attention ( t1.name ) )
selector = SelectorWithVars ( **config )
Expand Down Expand Up @@ -237,6 +237,7 @@ def test_fitting_fill_1 () :
if ds1_3 != ds1p_3 : logger.error ('Datasets ds1_3 and ds1p_3 are different!' )
if ds1_4 != ds1p_4 : logger.error ('Datasets ds1_4 and ds1p_4 are different!' )


# =========================================================================
logger.info ( attention( 'Trivial variables + CUT' ) )
# =========================================================================
Expand Down Expand Up @@ -583,7 +584,6 @@ def test_fitting_fill_1 () :
logger.info ( '%s\n%s' % ( title4 , table4 ) )
logger.info ( '%s\n%s' % ( title4p , table4p ) )


# =============================================================================
if '__main__' == __name__ :

Expand Down
3 changes: 1 addition & 2 deletions ostap/fitting/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,6 @@ def make_formula ( name , formula , *variables ) :
>>> var = make_formula ( 'F1' , 'a+b' , variables )
"""


if variables and 1 == len ( variables ) and isinstance ( variables [ 0 ] , ROOT.RooArgList ) :

varlist = variables [ 0 ]
Expand All @@ -2341,7 +2340,7 @@ def make_formula ( name , formula , *variables ) :
elif isinstance ( var , sequence_types ) :
vlst = [ v for v in var ]
assert all ( isinstance ( vv , ROOT.RooAbsArg ) for vv in vlst ) , \
"Invalid element in 'variables[%d]': %s" % ( i . str ( vlst ) )
"Invalid element in 'variables[%d]': %s" % ( i , str ( vlst ) )
for vv in vlst : varlist.add ( v )
else :
raise TypeError ( "Invalid type for 'variables[%d]' %s/%s" % ( i ,
Expand Down
22 changes: 10 additions & 12 deletions source/src/FormulaVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,18 @@ Ostap::makeFormula
const std::string vname { Ostap::tmp_name ( "test_formula1_" , expression ) } ;
//
// ========================================================================
// gErrorIgnoreLevel = kFatal + 1 ;
// ========================================================================
#if ROOT_VERSION_CODE < ROOT_VERSION(6,20,0)
//
std::unique_ptr<RooFormula> ptr ;
try
{
ESentry sentry {} ;
ptr.reset ( new RooFormula ( vname .c_str () ,
expression.c_str () ,
dependents ) } ;
ptr.reset ( new RooFormula ( vname .c_str () ,
expression.c_str () ,
dependents ) ) ;
}
catch ( std::invalid_argument& /* e1 */ ){ return nullptr ; }
catch ( std::runtime_error& /* e2 */ ){ return nullptr ; }
catch ( std::invalid_argument& /* e1 */ ){ return nullptr ; }
catch ( std::runtime_error& /* e2 */ ){ return nullptr ; }
//
if ( !ptr || !ptr->ok() ) { return nullptr ; }
const RooArgList used { ::usedVariables ( *ptr , dependents ) } ;
Expand Down Expand Up @@ -187,11 +185,11 @@ Ostap::makeFormula
if ( !ptr || !ptr->ok() ) { return nullptr ; }
//
std::unique_ptr<Ostap::FormulaVar> result
{ new Ostap::FormulaVar ( name ,
title ,
expression ,
used ,
true ) } ;
( new Ostap::FormulaVar ( name ,
title ,
expression ,
used ,
true ) ) ;
//
if ( !result || !result->ok() ) { return nullptr ; }
//
Expand Down

0 comments on commit 53cf14d

Please sign in to comment.