From 8e342eca921117e422a523e40d2e41344aa2da16 Mon Sep 17 00:00:00 2001 From: Vanya Belyaev Date: Wed, 7 Aug 2024 14:28:40 +0200 Subject: [PATCH] fix ? --- ostap/fitting/dataset.py | 14 ++------------ ostap/fitting/ds2numpy.py | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/ostap/fitting/dataset.py b/ostap/fitting/dataset.py index 006f7abb..b4d2d8fe 100644 --- a/ostap/fitting/dataset.py +++ b/ostap/fitting/dataset.py @@ -2406,25 +2406,15 @@ def _ds_store_asym_error_ ( dataset ) : - see Ostap::Utils::storeAsymError """ - print ( 'STORE_ASYM_ERROR/0' , dataset.isWeighted() ) - if not dataset.isWeighted() : return False ## UNWEIGHTED! attr = '_store_asym_weight_error_' - print ( 'STORE_ASYM_ERROR/1' , attr ) - if not hasattr ( dataset , attr ) : - - print ( 'STORE_ASYM_ERROR/2' , attr ) - + ## wn = Ostap.Utils.storeAsymError ( dataset ) wn = True if wn else False - - print ( 'STORE_ASYM_ERROR/3' , attr , wn ) - + ## setattr ( dataset , attr , wn ) - - print ( 'STORE_ASYM_ERROR/4' , attr , hasattr ( dataset , attr ) ) return getattr ( dataset , attr , '' ) diff --git a/ostap/fitting/ds2numpy.py b/ostap/fitting/ds2numpy.py index eaa6687f..e147415e 100644 --- a/ostap/fitting/ds2numpy.py +++ b/ostap/fitting/ds2numpy.py @@ -44,14 +44,10 @@ except ImportError : np = None # ============================================================================= -_new_methods_ = [] +_new_methods_ = [] - - -# ============================================================================= -if np and ( 6 , 28 ) <= root_info : ## 6.26 <= ROOT # ============================================================================= - +if np and ( 6 , 28 ) <= root_info : ## 6.26 <= ROOT # ========================================================================= ## Convert dataset into numpy array using ROOT.RooAbsData interface # @see ROOT.RooAbsData.getBatches @@ -176,7 +172,6 @@ def ds2numpy ( dataset , var_lst , silent = True , more_vars = {} ) : if dname in doubles : part [ dname ] = d.second - elif dname == weight : part [ dname ] = d.second del dpart @@ -224,8 +219,6 @@ def ds2numpy ( dataset , var_lst , silent = True , more_vars = {} ) : # ============================================================================= elif np : ## ROOT < 6.26 -# ============================================================================= - # ========================================================================= ## Convert dataset into numpy array using (slow) explicit loops def ds2numpy ( dataset , var_lst , silent = False , more_vars = {} ) : @@ -287,7 +280,8 @@ def ds2numpy ( dataset , var_lst , silent = False , more_vars = {} ) : categories = [ v.name for v in vars if isinstance ( v , ROOT.RooAbsCategory ) ] ## name of weight variable - weight = '' if not dataset.isWeighted() else dataset.wname () + weighted = dataset.isWeighted () + weight = '' if not weighted else dataset.wname () dtypes = [] for v in vnames : @@ -300,15 +294,19 @@ def ds2numpy ( dataset , var_lst , silent = False , more_vars = {} ) : ## create data data = np.zeros ( len ( dataset ) , dtype = dtypes ) + ## make an explict loop: - for i , evt in enumerate ( progress_bar ( dataset , silent = silent ) ) : + for i , item in enumerate ( progress_bar ( dataset , silent = silent ) ) : + if weighted : evt, the_weight = item + else : evt = item + for v in evt : vname = v.name if vname in doubles : data [ vname ] [ i ] = float ( v ) elif vname in categories : data [ vname ] [ i ] = int ( v ) - - if weight : data [ weight ] [ i ] = dataset.weight() + + if weighted and weight : data [ weight ] [ i ] = float ( the_weight ) ## add PDF values for vname , func , obsvars in funcs :