Skip to content

Commit

Permalink
1. tree_reduce : allow redefininition of existing variables (very …
Browse files Browse the repository at this point in the history
…useful for `tmva/chopping`) (only for 6.26<=ROOT
  • Loading branch information
VanyaBelyaev committed Feb 20, 2024
1 parent fca086c commit 0f9bfcc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ostap/frames/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def columns ( frame ) :
"""
names = [ str(c) for c in frame.GetColumnNames() ]
if ( 6 , 16 ) <= root_info :
names += [ str(c) for c in frame.GetDefinedColumnNames() ]
names += [ str ( c ) for c in frame.GetDefinedColumnNames() ]
return tuple ( sorted ( set ( names ) ) )

frame_columns = columns
Expand Down
17 changes: 11 additions & 6 deletions ostap/frames/tree_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# @author Vanya BELYAEV [email protected]
# @date 2018-06-16
# =============================================================================
"""Helper module to ``reduce'' tree using frames
"""Helper module to `reduce' tree using frames
- see Ostap.DataFrame
- see ROOT.ROOT.RDataFrame
"""
Expand All @@ -34,7 +34,7 @@
if '__main__' == __name__ : logger = getLogger( 'ostap.frames.tree_reduce' )
else : logger = getLogger( __name__ )
# =============================================================================
logger.debug ( "``Reduce'' TTree using ROOT::RDataFrame object")
logger.debug ( "`Reduce' TTree using ROOT::RDataFrame object")
# =============================================================================
## @class ReduceTree
# Reduce TTree object using intermediate (temporary
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__ ( self ,
tmp_keep = False , ## keep the temporary file
silent = False ): ## silent processing

from ostap.frames.frames import DataFrame, frame_prescale
from ostap.frames.frames import DataFrame, frame_prescale, frame_columns
frame = DataFrame ( chain )
report = None

Expand All @@ -80,13 +80,18 @@ def __init__ ( self ,
## add overall prescale (if requested)
if 1 != prescale :
frame = frame_prescale ( frame , prescale )


avars = set ( frame_columns ( frame ) )
nvars = []
## new variables
for nv in new_vars :
frame = frame.Define ( nv , new_vars [ nv ] )
if ( 6 , 26 ) <= root_info and nv in avars :
frame = frame.Redefine ( nv , new_vars [ nv ] ) ## REDEFINE!!!
else :
frame = frame.Define ( nv , new_vars [ nv ] )
nvars.append ( nv )

avars.add ( nv )

from ostap.core.ostap_types import ( string_types ,
listlike_types ,
dictlike_types )
Expand Down

0 comments on commit 0f9bfcc

Please sign in to comment.