diff --git a/ostap/fitting/dataset.py b/ostap/fitting/dataset.py index e1725c48..f91cef66 100644 --- a/ostap/fitting/dataset.py +++ b/ostap/fitting/dataset.py @@ -25,7 +25,8 @@ ) # ============================================================================= from builtins import range -from collections import defaultdict +from collections import defaultdict +from ostap.core.meta_info import root_info from ostap.core.core import ( Ostap, VE, SE , hID , dsID , strings , valid_pointer , split_string , @@ -2272,7 +2273,7 @@ def _ds_symmetrize_ ( ds , var1 , var2 , *vars ) : # ============================================================================= -## get the name of weigth variable in dataset +## get the name of weight variable in dataset # @code # dataset = ... # wname = dataset.wname() @@ -2288,8 +2289,12 @@ def _ds_wname_ ( dataset ) : attr = '_weight_var_name' if not hasattr ( dataset , attr ) : - - wn = Ostap.Utils.getWeight ( dataset ) + + if ( 6 , 26 ) <= root_info : + wv = dataset.weightVar() + wn = wv.name if wv else Ostap.Utils.getWeight ( dataset ) + else : wn = Ostap.Utils.getWeight ( dataset ) + setattr ( dataset , attr , wn ) return getattr ( dataset , attr , '' ) diff --git a/ostap/fitting/ds2numpy.py b/ostap/fitting/ds2numpy.py index 0ee4690a..fb16719c 100644 --- a/ostap/fitting/ds2numpy.py +++ b/ostap/fitting/ds2numpy.py @@ -46,36 +46,6 @@ -# input: -# dataset - initial dataset -# var_lst - name of variables to add in numpy array -# weight - Bool value, which work with weights vars in dataset -#ds = DS_to_Numpy(data, ['evt', 'run'], weight) -#ds = DS_to_Numpy_for_old_version(data, ['evt', 'run']) - for old ROOT package version -# output: -# data - numpy array with values of the required variables - -#Check the list of variables for duplicates -def find_dublicates_in_var_list(var_lst): - return len(var_lst) != len(set(var_lst)) - -#add weight variable in numpy array -def add_weight ( ds , data ): - - if not ds.isWeighted() : return data - - weight = ds.weightVar().GetName() - - ## creathe the weight array - weights = np.zeros( len ( ds ) , dtype=np.float64) - - ## fill it - for i in ds : weight_array[i] = ds.weight() - - data [ weight ] = weights - - return data - # ============================================================================= if np and ( 6 , 26 ) <= root_info : ## 6.26 <= ROOT # ============================================================================= @@ -142,7 +112,7 @@ def ds2numpy ( dataset , var_lst , silent = True ) : categories = [ v.name for v in vars if isinstance ( v , ROOT.RooAbsCategory ) ] ## name of weight variable - weight = '' if not dataset.isWeighted() else dataset.weightVar().GetName () + weight = '' if not dataset.isWeighted() else dataset.wname () dtypes = [] for v in vnames : @@ -247,7 +217,7 @@ def ds2numpy ( dataset , var_lst , silent = False ) : categories = [ v.name for v in vars if isinstance ( v , ROOT.RooAbsCategory ) ] ## name of weight variable - weight = '' if not dataset.isWeighted() else dataset.weightVar().GetName () + weight = '' if not dataset.isWeighted() else dataset.wname () dtypes = [] for v in vnames :