Skip to content

Commit

Permalink
1. fix a bit strange "feature" with "derived" variable in `RooDataSe…
Browse files Browse the repository at this point in the history
…t` (thanks to Alexander Artamonov for rereporting). It happens that `RooDataSet::addColumn`RooDataSet::addColumns` behave a bit differently. the first one issues the error message and variable behaves weirdly.
  • Loading branch information
VanyaBelyaev committed Aug 10, 2020
1 parent dec0e72 commit 62321a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion ReleaseNotes/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
## Backward incompatible changes

## Bug fixes:

1. fix a bit strange "feature" with "derived" variable in `RooDataSet` (thanks to Alexander Artamonov for rereporting). It happens that `RooDataSet::addColumn`RooDataSet::addColumns` behave a bit differently. the first one issues the error message and variable behaves weirdly.


# v1.5.0.1

Expand Down
1 change: 1 addition & 0 deletions ostap/fitting/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ def _rds_addVar_ ( dataset , vname , formula ) :
#
vcol = ROOT.RooFormulaVar ( vname , formula , formula , vlst , False )
dataset.addColumn ( vcol )
del vcol
#
return dataset

Expand Down
5 changes: 4 additions & 1 deletion ostap/fitting/roocollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# =============================================================================
import ROOT, random
from ostap.core.core import Ostap
from ostap.core.ostap_types import string_types
import ostap.fitting.variables
# =============================================================================
# logging
Expand Down Expand Up @@ -58,7 +59,9 @@ def _ral_iter_ ( self ) :
def _ral_contains_ ( self , i ) :
"""Check the presence of element or index in the list
"""
if isinstance ( i , int ) : return 0<= i < len(self)
if isinstance ( i , int ) : return 0<= i < len(self)
elif isinstance ( i , string_types ) : return self.find ( i )
elif isinstance ( i , ROOT.RooAbsArg ) : return self.contains ( i )
obj = self.find ( i )
return True if obj else False
## return 0 <= self.index ( i )
Expand Down
20 changes: 11 additions & 9 deletions ostap/fitting/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
if '__main__' == __name__ : logger = getLogger ( 'ostap.fitting.selectors' )
else : logger = getLogger ( __name__ )
# =============================================================================
from ostap.core.core import cpp, Ostap, items_loop
from ostap.core.core import cpp, Ostap, items_loop, dsID
from ostap.core.ostap_types import num_types, string_types, integer_types
import ostap.fitting.roofit
# =============================================================================
Expand Down Expand Up @@ -545,7 +545,6 @@ def __init__ ( self ,
silence = False ) :

if not name :
from ostap.core.core import dsID
name = dsID()

if not fullname : fullname = name
Expand Down Expand Up @@ -1231,9 +1230,7 @@ def make_dataset ( tree , variables , selection = '' , name = '' , title = '' ,
varsete.add ( v.var )
stor.add ( v )

if not name :
from ostap.core.core import dsID
name = dsID ()
if not name : name = dsID ()
if not title and tree.GetName() != tree.GetTitle :
title = tree.GetTitle ()

Expand Down Expand Up @@ -1277,8 +1274,13 @@ def make_dataset ( tree , variables , selection = '' , name = '' , title = '' ,

with rooSilent ( ROOT.RooFit.ERROR + 1 , True ) :
with rootError( ROOT.kError ) :
ds.addColumns ( fcols )

## it causes some strange behaviour
## ds.addColumns ( fcols )
## it is ok:
for f in fcols : ds.addColumn ( f )
del fcols
del ffs

## apply cuts (if any) for the complex expressions
if fcuts :
fcuts = [ '(%s)' % f for f in fcuts ]
Expand Down Expand Up @@ -1308,11 +1310,11 @@ def make_dataset ( tree , variables , selection = '' , name = '' , title = '' ,
vs = ROOT.RooArgSet()
vrm = set ( )
for v in ds.get() :
if v in varset : vs .add ( v )
if v in varset : vs .add ( v )
else : vrm.add ( v.name )
if vrm and not silent :
logger.info ("make_dataset: temporary variables to be removed %s" % str ( tuple ( vrm) ) )
ds1 = ds.reduce ( vs )
ds1 = ds.reduce ( vs , '' )
ds.clear()
del ds
ds = ds1
Expand Down

0 comments on commit 62321a1

Please sign in to comment.