diff --git a/ostap/fitting/dataset.py b/ostap/fitting/dataset.py index 7d412f77..eaec9799 100644 --- a/ostap/fitting/dataset.py +++ b/ostap/fitting/dataset.py @@ -824,165 +824,137 @@ def _rds_make_unique_ ( dataset , # >>> dataset.project ( h1 , 'm', 'chi2<10' ) ## use histo # # @endcode -# @attention For 2D&3D cases if varibales specifed as singel string, the order is Z,Y,X, -# Otherwide the natural order is used. # @see RooDataSet # @author Vanya BELYAEV Ivan.Belyaev@itep.ru # @date 2013-07-06 -def ds_project ( dataset , histo , what , cuts = '' , first = 0 , last = -1 , progress = False ) : +def ds_project ( dataset , + histo , + what , + cuts = '' , + cut_range = '' , + first = 0 , + last = None , + progress = False ) : """Helper project method for RooDataSet/DataFrame/... and similar objects - + >>> h1 = ROOT.TH1D(... ) >>> dataset.project ( h1.GetName() , 'm', 'chi2<10' ) ## project variable into histo >>> h1 = ROOT.TH1D(... ) >>> dataset.project ( h1 , 'm', 'chi2<10' ) ## use histo - - - For 2D&3D cases if variables specifed as singel string, the order is Z,Y,X, - - Otherwide the natural order is used. """ - target = histo - - ## input historgam? + ## 1) redirect to approproate methods + if isinstance ( dataset , ROOT.TTree ) : + assert not cut_range, "ds_project(tree,...) cannot be used with cut_range %s" % cut_range + from ostap.trees.trees import tree_project + return tree_project ( datatet , histo , + what = what , + cuts = cuts , + first = first , + last = last ) + + ## 2) if the histogram is specified by the name, try to locate it ROOT memory + if isinstance ( histo , string_types ) : + hname = histo + groot = ROOT.ROOT.GetROOT() + h = groot.FindObject ( hname ) + assert h , 'Cannot get locate histo by name %s' % histos + assert isinstance ( h , ROOT.TH1 ) , 'the object %s i snot ROOT.TH1' % type ( h ) + histo = h + + + target = histo + + ## input historgam? input_histo = isinstance ( target , ROOT.TH1 ) - - from ostap.trees.param import ( param_types_1D , param_types_2D , - param_types_3D , param_types_4D ) - assert input_histo or \ - isinstance ( target , param_types_1D ) or \ - isinstance ( target , param_types_2D ) or \ - isinstance ( target , param_types_3D ) or \ - isinstance ( target , param_types_4D ) , "Invalid type of 'histo/target' %s" % type ( histo ) + from ostap.trees.param import param_types_nD + assert input_histo or isinstance ( target , param_types_nD ) , 'Invalid target/histo type %s' % type ( target ) - ## reset targer - if input_histo : target.Reset() - else : target *= 0.0 + ## (4) dimension of the target + dim = target.dim () + assert 1 <= dim <= 4 , 'Invalid dimension of target: %s' % dim + + ## (5) parse input expressions + varlst, cuts, input_string = vars_and_cuts ( what , cuts ) + + print ( 'VARIABLES/1', varlst, cuts ) + nvars = len ( varlst ) + assert ( 1 == dim and dim <= nvars ) or dim == nvars , \ + 'Mismatch between the target/histo dimension %d and input variables %s' % ( dim , varlst ) + + print ( 'PROJECT-7' ) - if isinstance ( histo , ROOT.TProfile2D ) : - histo.Reset() - logger.error ('ds_project: TProfile2D is not (yet) supported') - return histo - elif isinstance ( histo , ROOT.TProfile ) : - logger.error ('ds_project: TProfile is not (yet) supported') - return histo - - assert not cuts or \ - isinstance ( cuts , string_types ) or \ - isinstance ( cuts , ROOT.RooAbsReal ) or \ - isinstance ( cuts , ROOT.TCut ) , \ - "Invalid 'cuts' %s" % type ( cuts ) - if isinstance ( dataset , ROOT.RooAbsData ) : - - first = max ( first , 0 ) - nevents = len ( dataset ) - last = nevents if last < 0 else min ( nevents , last ) - - # NO ACTION ? - if last <= first or nevents <= first : return histo ## NO ACTION - events = first , last - + ## 3) adjust the first/last + length = len ( dataset ) + if not last : last = length + 1 + elif last < 0 : last += length + if first < 0 : first += length + assert 0 <= first <= last , 'Invalid first/last setting %s/^s' % ( first , last ) + tail = cuts , cut_range , first , last else : + assert not cut_range , 'cut-range is not allowed!' + logger.warning ( 'ds_project(%s): ignored first/last %s/%s ' % ( type ( dataset ) , first , last ) ) + from ostap.frames.frames import as_rnode + frame = as_rnode ( dataset ) + dataset = frame + tail = () + - if 0 != first or 0 < last : - logger.warning ( "ds_project: 'first' and 'last' arguments (%s/%s) are ignored " % ( first , last ) ) - events = () - - if isinstance ( cuts , str ) : cuts = cuts.strip() - if isinstance ( what , str ) : what = what.strip() + args = ( target , ) + varlst + tail + + ## copy/clone the target + def target_copy ( t ) : return t.Clone() if isinstance ( t , ROOT.TH1 ) else type ( t ) ( t ) + ## reset the target + def target_reset ( t ) : + if isinstance ( t , ROOT.TH1 ) : t.Reset() + else : t *= 0.0 + return t - tail = first , last , progress + ## reset the target + target = target_reset ( target ) - if isinstance ( what , string_types ) : - - ## ATTENTION reverse here! - what = tuple ( reversed ( [ v.strip() for v in split_string ( what , var_separators , strip = True , respect_groups = True ) ] ) ) - return ds_project ( dataset , histo , what , cuts , *events , progress = progress ) + from ostap.utils.progress_conf import progress_conf - elif isinstance ( what , ROOT.RooArgList ) and isinstance ( dataset , ROOT.RooAbsData ) : - - what = tuple ( v for v in what ) - return ds_project ( dataset , histo , what , cuts , *events , progress = progress ) - - assert isinstance ( what , list_types ) and what , "ds_project: invalid 'what' %s" % what - - - if input_histo : hdim = target.dim() - elif isinstance ( target , param_types_1D ) : hdim = 1 - elif isinstance ( target , param_types_2D ) : hdim = 2 - elif isinstance ( target , param_types_3D ) : hdim = 3 - elif isinstance ( target , param_types_4D ) : hdim = 4 - - assert len ( what ) == hdim or ( 1 == hdim and hdim < len ( what ) ) , \ - "ds_project: invalid 'what' %s" % what - - ok1 = all ( isinstance ( v , string_types ) for v in what ) - ok2 = all ( isinstance ( v , ROOT.RooAbsReal ) for v in what ) - - assert ok1 or ok2 , "ds_project: Invalid 'what': %s/%s " % ( type ( what ) , what ) - - what = tuple ( what ) - - if ok2 : ## need to have RooFit version of cuts - if not cuts : vcuts = ROOT.nullptr - elif isinstance ( cuts , ROOT.RoOAbsReal ) : vcuts = cuts - else : vcuts = make_formula ( cuts , cuts , dataset.get() ) - - cuts = vcuts - - ## special treatment for 1D histograms: several variables are summed/projected together - if 1 == hdim and input_histo and isinstance ( histo , ROOT.TH1 ) and hdim < len ( what ) : - htmp = histo.clone() - for w in what : - htmp = ds_project ( dataset , - histo = htmp , - what = w , - cuts = cuts , - first = first , - last = last , - progress = progress ) - histo += htmp - del htmp + if isinstance ( histo , ROOT.TProfile2D ) : + histo.Reset() + logger.error ('ds_project: TProfile2D is not (yet) supported') + return histo + elif isinstance ( histo , ROOT.TProfile ) : + logger.error ('ds_project: TProfile is not (yet) supported') return histo - elif 1 == hdim and hdim < len ( what ) : - tobj = type ( target ) - htmp = tobj ( target ) - for w in what : - htmp = ds_project ( dataset , - histo = htmp , - what = w , - cuts = cuts , - first = first , - last = last , - progress = progress ) - target += htmp - del htmp - return target - - - args = ( target , ) + what + ( cuts , ) + events - - from ostap.utils.progress_conf import progress_conf - - ## finally fill the histograms - if 4 == hdim : - if progress : sc = Ostap.HistoProject.project4 ( dataset , progress_conf () , *args ) - else : sc = Ostap.HistoProject.project4 ( dataset , *args ) - if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project3 %s" % sc ) - elif 3 == hdim : - if progress : sc = Ostap.HistoProject.project3 ( dataset , progress_conf () , *args ) - else : sc = Ostap.HistoProject.project3 ( dataset , *args ) - if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project3 %s" % sc ) - elif 2 == hdim : - if progress : sc = Ostap.HistoProject.project2 ( dataset , progress_conf () , *args ) - else : sc = Ostap.HistoProject.project2 ( dataset , *args ) - if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project3 %s" % sc ) - elif 1 == hdim : + + ## very special case of projection several expressions into the same target + if 1 == dim and dim < nvars : + ## very special case of projection several expressions into the same target + htmp = target_copy ( target ) ## prepare temporary object + for var in varlst : + htmp = target_reset ( htmp ) ## rest the temporary object + args = ( htmp , var ) + tail + if progress : sc = Ostap.HistoProject.project ( dataset , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project ( dataset , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project %s" % sc ) + ## update results + target += htmp + del htmp + elif 1 == dim : if progress : sc = Ostap.HistoProject.project ( dataset , progress_conf () , *args ) else : sc = Ostap.HistoProject.project ( dataset , *args ) - if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project3 %s" % sc ) - + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project %s" % sc ) + elif 2 == dim : + if progress : sc = Ostap.HistoProject.project2 ( dataset , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project2 ( dataset , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc ) + elif 3 == dim : + if progress : sc = Ostap.HistoProject.project3 ( dataset , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project3 ( dataset , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc ) + elif 4 == dim : + if progress : sc = Ostap.HistoProject.project4 ( dataset , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project4 ( dataset , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc ) + return target if sc.isSuccess() else None # ============================================================================= diff --git a/ostap/trees/param.py b/ostap/trees/param.py index b4402300..36512316 100644 --- a/ostap/trees/param.py +++ b/ostap/trees/param.py @@ -16,10 +16,11 @@ __date__ = "2011-06-07" __all__ = ( 'param_types_1D' , ## list of valid 1D-types for parameterisation - 'param_types_2D' , ## list of valid 1D-types for parameterisation - 'param_types_3D' , ## list of valid 1D-types for parameterisation - 'param_types_4D' , ## list of valid 1D-types for parameterisation - ) + 'param_types_2D' , ## list of valid 2D-types for parameterisation + 'param_types_3D' , ## list of valid 3D-types for parameterisation + 'param_types_4D' , ## list of valid 4D-types for parameterisation + 'param_types_nD' , ## all types for parameterisation +) # ============================================================================= from ostap.core.core import Ostap import ostap.math.models @@ -38,7 +39,8 @@ param_types_1D = Ostap.Math.LegendreSum , Ostap.Math.Bernstein , Ostap.Math.ChebyshevSum param_types_2D = Ostap.Math.LegendreSum2 , Ostap.Math.Bernstein2D , param_types_3D = Ostap.Math.LegendreSum3 , Ostap.Math.Bernstein3D , -param_types_4D = Ostap.Math.LegendreSum4 , +param_types_4D = Ostap.Math.LegendreSum4 , +param_types_nD = param_types_1D + param_types_2D + param_types_3D + param_types_4D # ============================================================================= ## parameterize 1D unbinned distribution from TTree in terms of # Legendre/chebyshev/Bernstein sums diff --git a/ostap/trees/trees.py b/ostap/trees/trees.py index facb7a3b..f2c49140 100755 --- a/ostap/trees/trees.py +++ b/ostap/trees/trees.py @@ -3,7 +3,6 @@ # ============================================================================= ## @file ostap/trees/trees.py # Module with decoration of Tree/Chain objects for efficient use in python -# # @author Vanya BELYAEV Ivan.Belyaev@itep.ru # @date 2011-06-07 # ============================================================================= @@ -37,6 +36,7 @@ from ostap.utils.scp_copy import scp_copy from ostap.math.reduce import root_factory from ostap.utils.progress_bar import progress_bar +from ostap.trees.cuts import vars_and_cuts import ostap.trees.treereduce import ostap.histos.histos import ostap.trees.param @@ -51,7 +51,7 @@ # ============================================================================= logger.debug ( 'Some useful decorations for Tree/Chain objects') # ============================================================================= -import ostap.trees.cuts + # ============================================================================= _large = ROOT.TVirtualTreePlayer.kMaxEntries # ============================================================================= @@ -109,7 +109,8 @@ def _iter_cuts_ ( tree , cuts = '' , first = 0 , last = _large , progress = Fals """ # last = min ( last , len ( tree ) ) - first = max ( 0 , first ) + first = max ( 0 , first ) + ## # if not cuts : cuts = '1' # @@ -367,7 +368,7 @@ def tree_project ( tree , what , cuts = '' , first = 0 , - last = -1 , + last = None , use_frame = True , ## use DataFrame ? progress = False ) : """Helper project method @@ -387,124 +388,135 @@ def tree_project ( tree , - what : variable/expression to project. It can be expression or list/tuple of expression or comma (or semicolumn) separated expression - cuts : selection criteria/weights - - For 2D&3D cases if variables specifed as single string, the order is Z,Y,X, - - Otherwide the natural order is used. + - for 2D&3D cases the natural order of varibales is used. """ - # - target = histo + print ( 'PROJECT-0' ) + ## 1) adjust the first/last + length = len ( tree ) + if not last : last = length + 1 + elif last < 0 : last += length + if first < 0 : first += length + assert 0 <= first <= last , 'Invalid first/last setting %s/^s' % ( first , last ) + + print ( 'PROJECT-1' ) + ## 2) if the histogram is specified by the name, try to locate it ROOT memory + if isinstance ( histo , string_types ) : + hname = histo + groot = ROOT.ROOT.GetROOT() + h = groot.FindObject ( hname ) + assert h , 'Cannot get locate histo by name %s' % histos + assert isinstance ( h , ROOT.TH1 ) , 'the object %s i snot ROOT.TH1' % type ( h ) + histo = h + + print ( 'PROJECT-2' ) + ## 3) redirect to the appropriate method - ## input historgam? + ## chain helper object? + if isinstance ( tree , Chain ) : tree = tree.chain + elif isinstance ( tree , ROOT.RooAbsData ) : + from ostap.fitting.dataset import ds_project as _ds_project_ + return _ds_project_ ( tree , histo , what , cuts = cuts , first = first , last = last , progress = progress ) + + print ( 'PROJECT-3' ) + assert isinstance ( tree , ROOT.TTree ) , "Invalid type of 'tree': %s" % type ( tree ) + + ## 3) target + target = histo + + print ( 'PROJECT-4' ) + + ## if isinsatnce ( target , param_types_nD ) : + ## return tree_parameterize ( tree , targer , what = what , cuts = cuts , first = first , last = last , progress = progrees ) + + ## input historgam? input_histo = isinstance ( target , ROOT.TH1 ) + from ostap.trees.param import param_types_nD + assert input_histo or isinstance ( target , param_types_nD ) , 'Invalid target/histo type %s' % type ( target ) - from ostap.trees.param import ( param_types_1D , param_types_2D , - param_types_3D , param_types_4D ) - assert input_histo or \ - isinstance ( target , param_types_1D ) or \ - isinstance ( target , param_types_2D ) or \ - isinstance ( target , param_types_3D ) or \ - isinstance ( target , param_types_4D ) , "Invalid type of 'histo/target' %s" % type ( histo ) + print ( 'PROJECT-5' ) - ## reset targer - target.Reset() + ## use frame if requested and if/when possible + if use_frame and input_histo and 0 == first and len ( tree ) <= last : + if ( 6 , 19 ) <= root_info : + import ostap.frames.frames as F + frame = F.DataFrame ( tree ) + if progress : frame , _ = frame_progress ( frame , len ( tree ) ) + result = frame_project ( frame , target , expressions = what , cuts = cuts , lazy = False ) + return result - ## check cuts - assert not cuts or \ - isinstance ( cuts , string_types ) or \ - isinstance ( cuts , ROOT.TCut ) , \ - "Invalid 'cuts' %s" % type ( cuts ) - - first = max ( first , 0 ) + print ( 'PROJECT-6' ) - ## chain helper object? - if isinstance ( tree , Chain ) : tree = tree.chain - elif isinstance ( tree , ROOT.RooAbsData ) : - from ostap.fitting.dataset import ds_project as _ds_project_ - return _ds_project_ ( tree , histo , what , cuts , first , last , progress ) + ## dimension of the target + dim = target.dim () + assert 1 <= dim <= 4 , 'Invalid dimension of target: %s' % dim - nevents = len ( tree ) - last = nevents if last < 0 else min ( nevents , last ) + ## 3) parse input expressions + varlst, cuts, input_string = vars_and_cuts ( what , cuts ) - if isinstance ( cuts , ROOT.TCut ) : cuts = str ( cuts ) - elif not cuts : cuts = '' + print ( 'VARIABLES/1', varlst, cuts ) - tail = first , last , use_frame , progress + nvars = len ( varlst ) + + print ( 'VARIABLES/2', input_histo and 1 == dim and dim <= nvars , dim == nvars ) + + assert ( 1 == dim and dim <= nvars ) or dim == nvars , \ + 'Mismatch between the target/histo dimension %d and input variables %s' % ( dim , varlst ) + + print ( 'PROJECT-7' ) - if isinstance ( what , string_types ) : - - ## ATTENTION reverse here! - what = tuple ( reversed ( [ v.strip() for v in split_string ( what , var_separators , strip = True , respect_groups = True ) ] ) ) - return tree_project ( tree , histo , what , cuts , *tail ) - - assert isinstance ( what , list_types ) , "tree_project: invalid 'what' %s" % what - - if input_histo : hdim = target.dim() - elif isinstance ( target , param_types_1D ) : hdim = 1 - elif isinstance ( target , param_types_2D ) : hdim = 2 - elif isinstance ( target , param_types_3D ) : hdim = 3 - elif isinstance ( target , param_types_4D ) : hdim = 4 - - assert len ( what ) == hdim or ( 1 == hdim and hdim < len ( what ) ) , \ - "tree_project: invalid 'what' %s" % what - - ## special treatment for 1D histograms: several variables are summed/projected together - if 1 == hdim and input_histo and hdim < len ( what ) : - htmp = histo.clone() - for w in what : - htmp = tree_project ( tree , htmp , w , cuts , *tail ) - histo += htmp - del htmp - return histo - elif 1 == hdim and hdim < len ( what ) : - tobj = type ( target ) - htmp = tobj ( target ) - for w in what : - htmp = tree_project ( tree , htmp , w , cuts , *tail ) - target += htmp - del htmp - return target ## ATTENTION! + tail = cuts , first , last + args = ( target , ) + varlst + tail - ## use frame if requested and if/when possible - if use_frame and input_histo and isinstance ( tree , ROOT.TTree ) and 0 == first and len ( tree ) <= last : - import ostap.frames.frames as F - frame = F.DataFrame ( tree ) - if progress : counter = F.frame_progress ( frame , len ( tree ) ) - else : counter = frame.Count() - fargs = what + ( cuts , ) - result = F.frame_project ( frame , histo , *fargs ) - cnt = counter.GetValue() - return result - - ## use 'old' method since it is slightly more efficient - if not progress and input_histo and isinstance ( tree , ROOT.TTree ) : - hname = histo.GetName() - what = ' : '.join ( reversed ( what ) ) - num = tree.Project ( hname , what , '' , '' , last - first , first ) - return histo - - active = tree.the_variables ( cuts , *what ) - from ostap.utils.progress_conf import progress_conf - with ActiveBranches ( tree , *active ) : - - args = ( target , ) + what + ( cuts , first , last ) - if 4 == hdim : - if progress : sc = Ostap.HistoProject.project4 ( tree , progress_conf () , *args ) - else : sc = Ostap.HistoProject.project4 ( tree , *args ) - if not sc.isSuccess () : logger.error ( "Error from Ostap.HistoProject.project4 %s" % sc ) - if 3 == hdim : - if progress : sc = Ostap.HistoProject.project3 ( tree , progress_conf () , *args ) - else : sc = Ostap.HistoProject.project3 ( tree , *args ) - if not sc.isSuccess () : logger.error ( "Error from Ostap.HistoProject.project3 %s" % sc ) - elif 2 == hdim : + ## copy/clone the target + def target_copy ( t ) : return t.Clone() if isinstance ( t , ROOT.TH1 ) else type ( t ) ( t ) + ## reset the target + def target_reset ( t ) : + if isinstance ( t , ROOT.TH1 ) : t.Reset() + else : t *= 0.0 + return t + + ## reset the target + target = target_reset ( target ) + + ## get the list of active branches + active = tree.the_variables ( cuts , *varlst ) + from ostap.utils.progress_conf import progress_conf + + with ActiveBranches ( tree , *active ) : + + ## very special case of projection several expressions into the same target + if 1 == dim and dim < nvars : + ## very special case of projection several expressions into the same target + htmp = target_copy ( target ) ## prepare temporary object + for var in varlst : + htmp = target_reset ( htmp ) ## rest the temporary object + args = ( htmp , var ) + tail + if progress : sc = Ostap.HistoProject.project ( tree , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project ( tree , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project %s" % sc ) + ## update results + target += htmp + del htmp + elif 1 == dim : + if progress : sc = Ostap.HistoProject.project ( tree , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project ( tree , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project %s" % sc ) + elif 2 == dim : if progress : sc = Ostap.HistoProject.project2 ( tree , progress_conf () , *args ) else : sc = Ostap.HistoProject.project2 ( tree , *args ) if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc ) - elif 1 == hdim : - if progress : sc = Ostap.HistoProject.project ( tree , progress_conf () , *args ) - else : sc = Ostap.HistoProject.project ( tree , *args ) - if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project1 %s" % sc ) + elif 3 == dim : + if progress : sc = Ostap.HistoProject.project3 ( tree , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project3 ( tree , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc ) + elif 4 == dim : + if progress : sc = Ostap.HistoProject.project4 ( tree , progress_conf () , *args ) + else : sc = Ostap.HistoProject.project4 ( tree , *args ) + if not sc.isSuccess() : logger.error ( "Error from Ostap.HistoProject.project2 %s" % sc ) + ## return None on error return target if sc.isSuccess() else None ROOT.TTree .project = tree_project diff --git a/source/include/Ostap/BSpline.h b/source/include/Ostap/BSpline.h index 53126193..af5a81e3 100644 --- a/source/include/Ostap/BSpline.h +++ b/source/include/Ostap/BSpline.h @@ -127,6 +127,8 @@ namespace Ostap inline unsigned short degree () const { return order() ; } // number of inner knots inline unsigned short inner () const { return m_inner ; } + /// dimension + inline unsigned short dim () const { return 1 ; } // ====================================================================== public: // technical: get the effective position for knot "index" // ====================================================================== @@ -381,8 +383,10 @@ namespace Ostap // ====================================================================== public: // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// get number of parameters - std::size_t npars () const { return m_sphere.nPhi() ; } + std::size_t npars () const { return m_sphere.nPhi() ; } /// set k-parameter bool setPar ( const unsigned short k , const double value ) ; /// set k-parameter @@ -856,6 +860,11 @@ namespace Ostap double xinner () const { return m_xspline.inner () ; } double yinner () const { return m_yspline.inner () ; } // ====================================================================== + public: + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // few useful methdod // ====================================================================== /// simple manipulations with polynoms: shift it! @@ -1068,6 +1077,11 @@ namespace Ostap double xinner () const { return m_spline.inner () ; } double yinner () const { return m_spline.inner () ; } // ====================================================================== + public: + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // few useful methdod // ====================================================================== /// simple manipulations with polynoms: shift it! @@ -1243,6 +1257,11 @@ namespace Ostap double xinner () const { return m_spline.xinner () ; } double yinner () const { return m_spline.yinner () ; } // ====================================================================== + public: + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // generic integrals // ====================================================================== /** get the integral over 2D-region @@ -1372,6 +1391,11 @@ namespace Ostap double xinner () const { return m_spline.xinner () ; } double yinner () const { return m_spline.yinner () ; } // ====================================================================== + public: + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // generic integration // ====================================================================== /** get the integral over 2D-region @@ -1380,8 +1404,11 @@ namespace Ostap * @param ylow low edge in y * @param yhigh high edge in y */ - double integral ( const double xlow , const double xhigh , - const double ylow , const double yhigh ) const + double integral + ( const double xlow , + const double xhigh , + const double ylow , + const double yhigh ) const { return m_spline.integral ( xlow , xhigh , ylow , yhigh ) ; } /** get the integral over X for given Y * @param y (INPU) y-value diff --git a/source/include/Ostap/Bernstein1D.h b/source/include/Ostap/Bernstein1D.h index 7408b9fa..a7997387 100644 --- a/source/include/Ostap/Bernstein1D.h +++ b/source/include/Ostap/Bernstein1D.h @@ -79,6 +79,8 @@ namespace Ostap // ====================================================================== public: // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// the degree of polynomial unsigned short degree () const { return m_bernstein.degree () ; } /// number of parameters @@ -431,8 +433,10 @@ namespace Ostap // ====================================================================== public: // some characteristics // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// degree - unsigned short degree () const { return m_bernstein.degree() ; } + unsigned short degree () const { return m_bernstein.degree() ; } // ====================================================================== public: // ====================================================================== @@ -635,25 +639,6 @@ namespace Ostap const double xmin = 0 , const double xmax = 1 ) ; // ===================================================================== - /** constructor from the sequence of parameters - * @param begin start-iterator for sequence of coefficients - * @param end start-iterator for sequence of coefficients - * @param xmin low-edge - * @param xmax high-edge - */ - // template::value_type , - // typename = std::enable_if::value> > - // PositiveEven - // ( ITERATOR begin , - // ITERATOR end , - // const double xmin = 0 , - // const double xmax = 1 ) - - // ... - - - // ====================================================================== public: // ====================================================================== /// get the value @@ -688,8 +673,10 @@ namespace Ostap // ====================================================================== public: // some characteristics // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// degree - unsigned short degree () const { return m_even.degree() ; } + unsigned short degree () const { return m_even.degree() ; } // ====================================================================== public: // ====================================================================== @@ -954,6 +941,8 @@ namespace Ostap // ====================================================================== public: // some characteristics // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// degree unsigned short degree () const { return m_bernstein.degree() ; } // ====================================================================== @@ -1250,6 +1239,8 @@ namespace Ostap // ====================================================================== public: // some characteristics // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// degree unsigned short degree () const { return m_bernstein.degree() ; } // ====================================================================== @@ -1469,6 +1460,8 @@ namespace Ostap // ====================================================================== public: // some characteristics // ====================================================================== + /// dimension + unsigned short dim () const { return 1 ; } /// degree unsigned short degree () const { return m_bernstein.degree() ; } // ====================================================================== diff --git a/source/include/Ostap/Bernstein2D.h b/source/include/Ostap/Bernstein2D.h index c70029ab..11e4ceb8 100644 --- a/source/include/Ostap/Bernstein2D.h +++ b/source/include/Ostap/Bernstein2D.h @@ -168,6 +168,11 @@ namespace Ostap /// get the polynomial order (Y) unsigned short nY () const { return m_ny ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // transformations // ====================================================================== double x ( const double tx ) const @@ -504,6 +509,11 @@ namespace Ostap unsigned short nX () const { return m_bernstein.nX () ; } unsigned short nY () const { return m_bernstein.nY () ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // ====================================================================== // transform variables @@ -735,6 +745,11 @@ namespace Ostap unsigned short nX () const { return n () ; } unsigned short nY () const { return n () ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // ====================================================================== double x ( const double tx ) const @@ -976,6 +991,11 @@ namespace Ostap unsigned short nX () const { return m_bernstein.nX () ; } unsigned short nY () const { return m_bernstein.nY () ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // ====================================================================== double tx ( const double x ) const { return m_bernstein.tx ( x ) ; } diff --git a/source/include/Ostap/Bernstein3D.h b/source/include/Ostap/Bernstein3D.h index 66445b97..f25dbcbd 100644 --- a/source/include/Ostap/Bernstein3D.h +++ b/source/include/Ostap/Bernstein3D.h @@ -194,6 +194,11 @@ namespace Ostap /// get the polynomial order (Y) unsigned short nZ () const { return m_nz ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // transformations // ====================================================================== double x ( const double tx ) const @@ -775,6 +780,11 @@ namespace Ostap /// get the polynomial order (Y) unsigned short nZ () const { return nY() ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // transformations // ====================================================================== double x ( const double tx ) const @@ -1182,6 +1192,11 @@ namespace Ostap /// get the polynomial order (Y) unsigned short nZ () const { return m_nz ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // transformations // ====================================================================== double x ( const double tx ) const @@ -1556,6 +1571,11 @@ namespace Ostap unsigned short nY () const { return m_bernstein.nY () ; } unsigned short nZ () const { return m_bernstein.nZ () ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // ====================================================================== // transform variables @@ -1842,6 +1862,11 @@ namespace Ostap unsigned short nY () const { return m_bernstein.nY () ; } unsigned short nZ () const { return m_bernstein.nZ () ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // ====================================================================== // transform variables @@ -2135,6 +2160,11 @@ namespace Ostap unsigned short nY () const { return m_bernstein.nY () ; } unsigned short nZ () const { return m_bernstein.nZ () ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // ====================================================================== // transform variables diff --git a/source/include/Ostap/HistoProject.h b/source/include/Ostap/HistoProject.h index f84103f3..1e16a905 100644 --- a/source/include/Ostap/HistoProject.h +++ b/source/include/Ostap/HistoProject.h @@ -63,10 +63,11 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project - ( const RooAbsData* data , - TH1* histo , - const std::string& expression , - const std::string& selection = "" , + ( const RooAbsData* data , + TH1* histo , + const std::string& expression , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -76,15 +77,17 @@ namespace Ostap * @param histo (UPDATE) histogram * @param expression (INPUT) expression * @param selection (INPUT) selection criteria/weight + * @param range (INPUT) cut-range * @param first (INPUT) the first event to process * @param last (INPUT) the last event to process */ static Ostap::StatusCode project - ( const RooAbsData* data , - const Ostap::Utils::ProgressConf& progress , - TH1* histo , - const std::string& expression , - const std::string& selection = "" , + ( const RooAbsData* data , + const Ostap::Utils::ProgressConf& progress , + TH1* histo , + const std::string& expression , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -98,11 +101,12 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project2 - ( const RooAbsData* data , - TH2* histo , - const std::string& xexpression , - const std::string& yexpression , - const std::string& selection = "" , + ( const RooAbsData* data , + TH2* histo , + const std::string& xexpression , + const std::string& yexpression , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -117,12 +121,13 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project2 - ( const RooAbsData* data , - const Ostap::Utils::ProgressConf& progress , - TH2* histo , - const std::string& xexpression , - const std::string& yexpression , - const std::string& selection = "" , + ( const RooAbsData* data , + const Ostap::Utils::ProgressConf& progress , + TH2* histo , + const std::string& xexpression , + const std::string& yexpression , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -137,12 +142,13 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project3 - ( const RooAbsData* data , - TH3* histo , - const std::string& xexpression , - const std::string& yexpression , - const std::string& zexpression , - const std::string& selection = "" , + ( const RooAbsData* data , + TH3* histo , + const std::string& xexpression , + const std::string& yexpression , + const std::string& zexpression , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; @@ -159,13 +165,14 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project3 - ( const RooAbsData* data , + ( const RooAbsData* data , const Ostap::Utils::ProgressConf& progress , - TH3* histo , - const std::string& xexpression , - const std::string& yexpression , - const std::string& zexpression , - const std::string& selection = "" , + TH3* histo , + const std::string& xexpression , + const std::string& yexpression , + const std::string& zexpression , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -180,10 +187,11 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project - ( const RooAbsData* data , - TH1* histo , - const RooAbsReal& expression , - const RooAbsReal* selection = 0 , + ( const RooAbsData* data , + TH1* histo , + const RooAbsReal& expression , + const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -197,11 +205,12 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project - ( const RooAbsData* data , - const Ostap::Utils::ProgressConf& progress , - TH1* histo , - const RooAbsReal& expression , - const RooAbsReal* selection = 0 , + ( const RooAbsData* data , + const Ostap::Utils::ProgressConf& progress , + TH1* histo , + const RooAbsReal& expression , + const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -215,11 +224,12 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project2 - ( const RooAbsData* data , - TH2* histo , - const RooAbsReal& xexpression , - const RooAbsReal& yexpression , - const RooAbsReal* selection = 0 , + ( const RooAbsData* data , + TH2* histo , + const RooAbsReal& xexpression , + const RooAbsReal& yexpression , + const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -234,12 +244,13 @@ namespace Ostap * @param last (INPUT) the last event to process */ static Ostap::StatusCode project2 - ( const RooAbsData* data , - const Ostap::Utils::ProgressConf& progress , - TH2* histo , - const RooAbsReal& xexpression , - const RooAbsReal& yexpression , - const RooAbsReal* selection = 0 , + ( const RooAbsData* data , + const Ostap::Utils::ProgressConf& progress , + TH2* histo , + const RooAbsReal& xexpression , + const RooAbsReal& yexpression , + const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -259,7 +270,8 @@ namespace Ostap const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal& zexpression , - const RooAbsReal* selection = 0 , + const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -277,11 +289,12 @@ namespace Ostap static Ostap::StatusCode project3 ( const RooAbsData* data , const Ostap::Utils::ProgressConf& progress , - TH3* histo , - const RooAbsReal& xexpression , - const RooAbsReal& yexpression , - const RooAbsReal& zexpression , - const RooAbsReal* selection = 0 , + TH3* histo , + const RooAbsReal& xexpression , + const RooAbsReal& yexpression , + const RooAbsReal& zexpression , + const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -419,6 +432,7 @@ namespace Ostap Ostap::Math::LegendreSum& object , const RooAbsReal& expression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -437,6 +451,7 @@ namespace Ostap Ostap::Math::LegendreSum& object , const RooAbsReal& expression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -453,6 +468,7 @@ namespace Ostap Ostap::Math::ChebyshevSum& object , const RooAbsReal& expression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -471,6 +487,7 @@ namespace Ostap Ostap::Math::ChebyshevSum& object , const RooAbsReal& expression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -487,6 +504,7 @@ namespace Ostap Ostap::Math::Bernstein& object , const RooAbsReal& expression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -505,6 +523,7 @@ namespace Ostap Ostap::Math::Bernstein& object , const RooAbsReal& expression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -523,6 +542,7 @@ namespace Ostap const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -544,6 +564,7 @@ namespace Ostap const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -562,6 +583,7 @@ namespace Ostap const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -583,6 +605,7 @@ namespace Ostap const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -603,6 +626,7 @@ namespace Ostap const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -626,6 +650,7 @@ namespace Ostap const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -646,6 +671,7 @@ namespace Ostap const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -669,6 +695,7 @@ namespace Ostap const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -691,6 +718,7 @@ namespace Ostap const RooAbsReal& zexpression , const RooAbsReal& uexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -716,6 +744,7 @@ namespace Ostap const RooAbsReal& zexpression , const RooAbsReal& uexpression , const RooAbsReal* selection = nullptr , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -734,6 +763,7 @@ namespace Ostap Ostap::Math::LegendreSum& object , const std::string& expression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -752,6 +782,7 @@ namespace Ostap Ostap::Math::LegendreSum& object , const std::string& expression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -767,7 +798,8 @@ namespace Ostap ( const RooAbsData* data , Ostap::Math::ChebyshevSum& object , const std::string& expression , - const std::string& selection = "" , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -786,6 +818,7 @@ namespace Ostap Ostap::Math::ChebyshevSum& object , const std::string& expression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -802,6 +835,7 @@ namespace Ostap Ostap::Math::Bernstein& object , const std::string& expression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -820,6 +854,7 @@ namespace Ostap Ostap::Math::Bernstein& object , const std::string& expression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -838,6 +873,7 @@ namespace Ostap const std::string& xexpression , const std::string& yexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -857,6 +893,7 @@ namespace Ostap const std::string& xexpression , const std::string& yexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -875,6 +912,7 @@ namespace Ostap const std::string& xexpression , const std::string& yexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -894,6 +932,7 @@ namespace Ostap const std::string& xexpression , const std::string& yexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -914,6 +953,7 @@ namespace Ostap const std::string& yexpression , const std::string& zexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -936,6 +976,7 @@ namespace Ostap const std::string& yexpression , const std::string& zexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -955,7 +996,8 @@ namespace Ostap const std::string& xexpression , const std::string& yexpression , const std::string& zexpression , - const std::string& selection = "" , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -977,7 +1019,8 @@ namespace Ostap const std::string& xexpression , const std::string& yexpression , const std::string& zexpression , - const std::string& selection = "" , + const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -1000,6 +1043,7 @@ namespace Ostap const std::string& zexpression , const std::string& uexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== @@ -1023,6 +1067,7 @@ namespace Ostap const std::string& zexpression , const std::string& uexpression , const std::string& selection = "" , + const char* range = nullptr , const unsigned long first = 0 , const unsigned long last = std::numeric_limits::max() ) ; // ======================================================================== diff --git a/source/include/Ostap/Parameterization.h b/source/include/Ostap/Parameterization.h index df70c864..cc4a0924 100644 --- a/source/include/Ostap/Parameterization.h +++ b/source/include/Ostap/Parameterization.h @@ -100,6 +100,11 @@ namespace Ostap std::size_t nX () const { return m_NX ; } std::size_t nY () const { return m_NY ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 2 ; } + // ====================================================================== public: // ====================================================================== using Parameters::par ; @@ -453,6 +458,11 @@ namespace Ostap std::size_t nY () const { return m_NY ; } std::size_t nZ () const { return m_NZ ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 3 ; } + // ====================================================================== public: // ====================================================================== double x ( const double tx ) const @@ -841,6 +851,11 @@ namespace Ostap std::size_t nZ () const { return m_NZ ; } std::size_t nU () const { return m_NU ; } // ====================================================================== + public : + // ====================================================================== + /// dimension + unsigned short dim () const { return 4 ; } + // ====================================================================== public: // ====================================================================== double x ( const double tx ) const diff --git a/source/include/Ostap/Polynomials.h b/source/include/Ostap/Polynomials.h index d272f505..c9cba531 100644 --- a/source/include/Ostap/Polynomials.h +++ b/source/include/Ostap/Polynomials.h @@ -1309,6 +1309,8 @@ namespace Ostap unsigned short degree () const { return m_pars.empty() ? 0 : m_pars.size() - 1 ; } /// degree of polynomial unsigned short n () const { return degree () ; } + /// dimension + unsigned short dim () const { return 1 ; } // ====================================================================== } ; // ======================================================================== diff --git a/source/src/HistoProject.cpp b/source/src/HistoProject.cpp index 8ae04d39..fc2f0976 100644 --- a/source/src/HistoProject.cpp +++ b/source/src/HistoProject.cpp @@ -914,6 +914,7 @@ Ostap::HistoProject::project TH1* histo , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -931,6 +932,7 @@ Ostap::HistoProject::project const double xmin = histo->GetXaxis()->GetXmin () ; const double xmax = histo->GetXaxis()->GetXmax () ; // + Ostap::Utils::ProgressBar bar ( nEntries - first , progress ) ; for ( unsigned long entry = first ; entry < nEntries ; ++entry , ++bar ) { @@ -990,6 +992,7 @@ Ostap::HistoProject::project Ostap::Math::LegendreSum& object , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1000,6 +1003,7 @@ Ostap::HistoProject::project object , expression , selection , + range , first , last ) ; } @@ -1021,6 +1025,7 @@ Ostap::HistoProject::project Ostap::Math::LegendreSum& object , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1031,7 +1036,7 @@ Ostap::HistoProject::project object , expression , selection , - nullptr , + range , object.xmin () , object.xmax () , first , @@ -1053,6 +1058,7 @@ Ostap::HistoProject::project Ostap::Math::ChebyshevSum& object , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1063,6 +1069,7 @@ Ostap::HistoProject::project object , expression , selection , + range , first , last ) ; } @@ -1084,6 +1091,7 @@ Ostap::HistoProject::project Ostap::Math::ChebyshevSum& object , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1094,7 +1102,7 @@ Ostap::HistoProject::project object , expression , selection , - nullptr , + range , object.xmin () , object.xmax () , first , @@ -1116,6 +1124,7 @@ Ostap::HistoProject::project Ostap::Math::Bernstein& object , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1126,6 +1135,7 @@ Ostap::HistoProject::project object , expression , selection , + range , first , last ) ; } @@ -1147,6 +1157,7 @@ Ostap::HistoProject::project Ostap::Math::Bernstein& object , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1157,7 +1168,7 @@ Ostap::HistoProject::project object , expression , selection , - nullptr , + range , object.xmin () , object.xmax () , first , @@ -1181,6 +1192,7 @@ Ostap::HistoProject::project2 const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1192,6 +1204,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , + range , first , last ) ; } @@ -1214,6 +1227,7 @@ Ostap::HistoProject::project2 const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1225,7 +1239,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1251,6 +1265,7 @@ Ostap::HistoProject::project2 const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1262,6 +1277,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , + range , first , last ) ; } @@ -1284,6 +1300,7 @@ Ostap::HistoProject::project2 const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1295,7 +1312,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1323,6 +1340,7 @@ Ostap::HistoProject::project3 const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1335,6 +1353,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , + range , first , last ) ; } @@ -1360,6 +1379,7 @@ Ostap::HistoProject::project3 const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1372,7 +1392,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1402,6 +1422,7 @@ Ostap::HistoProject::project3 const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1414,6 +1435,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , + range , first , last ) ; } @@ -1439,6 +1461,7 @@ Ostap::HistoProject::project3 const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1451,7 +1474,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1483,6 +1506,7 @@ Ostap::HistoProject::project4 const RooAbsReal& zexpression , const RooAbsReal& uexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1496,6 +1520,7 @@ Ostap::HistoProject::project4 zexpression , uexpression , selection , + range , first , last ) ; } @@ -1522,6 +1547,7 @@ Ostap::HistoProject::project4 const RooAbsReal& zexpression , const RooAbsReal& uexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1535,7 +1561,7 @@ Ostap::HistoProject::project4 zexpression , uexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1563,6 +1589,7 @@ Ostap::HistoProject::project Ostap::Math::LegendreSum& object , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1573,6 +1600,7 @@ Ostap::HistoProject::project object , expression , selection , + range , first , last ) ; } @@ -1594,6 +1622,7 @@ Ostap::HistoProject::project Ostap::Math::LegendreSum& object , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1604,7 +1633,7 @@ Ostap::HistoProject::project object , expression , selection , - nullptr , + range , object.xmin () , object.xmax () , first , @@ -1626,6 +1655,7 @@ Ostap::HistoProject::project Ostap::Math::ChebyshevSum& object , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1636,6 +1666,7 @@ Ostap::HistoProject::project object , expression , selection , + range , first , last ) ; } @@ -1657,6 +1688,7 @@ Ostap::HistoProject::project Ostap::Math::ChebyshevSum& object , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1667,7 +1699,7 @@ Ostap::HistoProject::project object , expression , selection , - nullptr , + range , object.xmin () , object.xmax () , first , @@ -1689,6 +1721,7 @@ Ostap::HistoProject::project Ostap::Math::Bernstein& object , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1699,6 +1732,7 @@ Ostap::HistoProject::project object , expression , selection , + range , first , last ) ; } @@ -1719,7 +1753,8 @@ Ostap::HistoProject::project const Ostap::Utils::ProgressConf& progress , Ostap::Math::Bernstein& object , const std::string& expression , - const std::string& selection , + const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1730,7 +1765,7 @@ Ostap::HistoProject::project object , expression , selection , - nullptr , + range , object.xmin () , object.xmax () , first , @@ -1753,9 +1788,10 @@ Ostap::HistoProject::project2 Ostap::Math::LegendreSum2& object , const std::string& xexpression , const std::string& yexpression , - const std::string& selection , - const unsigned long first , - const unsigned long last ) + const std::string& selection , + const char* range , + const unsigned long first , + const unsigned long last ) { /// make a fake progress bar Ostap::Utils::ProgressConf progress { 0 } ; @@ -1765,6 +1801,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , + range , first , last ) ; } @@ -1788,6 +1825,7 @@ Ostap::HistoProject::project2 const std::string& xexpression , const std::string& yexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1799,7 +1837,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1824,9 +1862,10 @@ Ostap::HistoProject::project2 Ostap::Math::Bernstein2D& object , const std::string& xexpression , const std::string& yexpression , - const std::string& selection , - const unsigned long first , - const unsigned long last ) + const std::string& selection , + const char* range , + const unsigned long first , + const unsigned long last ) { /// make a fake progress bar Ostap::Utils::ProgressConf progress { 0 } ; @@ -1836,6 +1875,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , + range , first , last ) ; } @@ -1859,6 +1899,7 @@ Ostap::HistoProject::project2 const std::string& xexpression , const std::string& yexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1870,7 +1911,7 @@ Ostap::HistoProject::project2 xexpression , yexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1897,9 +1938,10 @@ Ostap::HistoProject::project3 const std::string& xexpression , const std::string& yexpression , const std::string& zexpression , - const std::string& selection , - const unsigned long first , - const unsigned long last ) + const std::string& selection , + const char* range , + const unsigned long first , + const unsigned long last ) { /// make a fake progress bar Ostap::Utils::ProgressConf progress { 0 } ; @@ -1910,6 +1952,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , + range , first , last ) ; } @@ -1935,6 +1978,7 @@ Ostap::HistoProject::project3 const std::string& yexpression , const std::string& zexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -1947,7 +1991,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -1976,9 +2020,10 @@ Ostap::HistoProject::project3 const std::string& xexpression , const std::string& yexpression , const std::string& zexpression , - const std::string& selection , - const unsigned long first , - const unsigned long last ) + const std::string& selection , + const char* range , + const unsigned long first , + const unsigned long last ) { /// make a fake progress bar Ostap::Utils::ProgressConf progress { 0 } ; @@ -1989,6 +2034,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , + range , first , last ) ; } @@ -2014,6 +2060,7 @@ Ostap::HistoProject::project3 const std::string& yexpression , const std::string& zexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2026,7 +2073,7 @@ Ostap::HistoProject::project3 yexpression , zexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -2058,6 +2105,7 @@ Ostap::HistoProject::project4 const std::string& zexpression , const std::string& uexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2071,6 +2119,7 @@ Ostap::HistoProject::project4 zexpression , uexpression , selection , + range , first , last ) ; } @@ -2098,6 +2147,7 @@ Ostap::HistoProject::project4 const std::string& zexpression , const std::string& uexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2111,7 +2161,7 @@ Ostap::HistoProject::project4 zexpression , uexpression , selection , - nullptr , + range , object.xmin () , object.xmax () , object.ymin () , @@ -2139,6 +2189,7 @@ Ostap::HistoProject::project TH1* histo , const RooAbsReal& expression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2148,7 +2199,8 @@ Ostap::HistoProject::project progress , histo , expression , - selection , + selection , + range , first , last ) ; } @@ -2172,6 +2224,7 @@ Ostap::HistoProject::project2 const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2191,11 +2244,16 @@ Ostap::HistoProject::project2 const double ymin = histo -> GetYaxis () -> GetXmin () ; const double ymax = histo -> GetYaxis () -> GetXmax () ; // + const bool has_range = range && 1 <= std::strlen ( range ) ; + // Ostap::Utils::ProgressBar bar ( nEntries - first , progress ) ; for ( unsigned long entry = first ; entry < nEntries ; ++entry , ++bar ) { // - if ( 0 == data->get( entry) ) { break ; } // BREAK + const RooArgSet* vars = data->get( entry ) ; + if ( nullptr == vars ) { break ; } // BREAK + // + if ( has_range && !vars->allInRange ( range ) ) { continue ; } // CONTINUE // // data weight const double dw = weighted ? data -> weight () : 1.0 ; @@ -2255,6 +2313,7 @@ Ostap::HistoProject::project2 const RooAbsReal& xexpression , const RooAbsReal& yexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2265,7 +2324,8 @@ Ostap::HistoProject::project2 histo , xexpression , yexpression , - selection , + selection , + range , first , last ) ; } @@ -2291,6 +2351,7 @@ Ostap::HistoProject::project3 const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2312,11 +2373,16 @@ Ostap::HistoProject::project3 const double zmin = histo -> GetZaxis () -> GetXmin () ; const double zmax = histo -> GetZaxis () -> GetXmax () ; // + const bool has_range = range && 1 <= std::strlen ( range ) ; + // Ostap::Utils::ProgressBar bar ( nEntries - first , progress ) ; for ( unsigned long entry = first ; entry < nEntries ; ++entry , ++bar ) { // - if ( 0 == data->get( entry) ) { break ; } // BREAK + const RooArgSet* vars = data->get( entry ) ; + if ( nullptr == vars ) { break ; } // BREAK + // + if ( has_range && !vars->allInRange ( range ) ) { continue ; } // CONTINUE // // data weight const double dw = weighted ? data -> weight () : 1.0 ; @@ -2379,6 +2445,7 @@ Ostap::HistoProject::project3 const RooAbsReal& yexpression , const RooAbsReal& zexpression , const RooAbsReal* selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2390,7 +2457,8 @@ Ostap::HistoProject::project3 xexpression , yexpression , zexpression , - selection , + selection , + range , first , last ) ; } @@ -2412,6 +2480,7 @@ Ostap::HistoProject::project TH1* histo , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2443,16 +2512,17 @@ Ostap::HistoProject::project const RooAbsReal* x_var = get_var ( *aset , expression ) ; std::unique_ptr xwhat ; if ( 0 == x_var ) - { - xwhat.reset( new Ostap::FormulaVar( expression , alst , false ) ) ; - if ( !xwhat->ok() ) { return Ostap::StatusCode(303) ; } // RETURN + { + xwhat.reset( new Ostap::FormulaVar( expression , alst , false ) ) ; + if ( !xwhat->ok() ) { return Ostap::StatusCode(303) ; } // RETURN } // return project ( data , progress , histo , 0 != x_var ? *x_var : *xwhat , - 0 != cut_var ? cut_var : cuts.get() , first , last ) ; + 0 != cut_var ? cut_var : cuts.get() , + range , first , last ) ; } // ============================================================================ /* make a projection of RooDataSet into the histogram @@ -2470,6 +2540,7 @@ Ostap::HistoProject::project TH1* histo , const std::string& expression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2479,7 +2550,8 @@ Ostap::HistoProject::project progress , histo , expression , - selection , + selection , + range , first , last ) ; } @@ -2503,6 +2575,7 @@ Ostap::HistoProject::project2 const std::string& xexpression , const std::string& yexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2552,7 +2625,8 @@ Ostap::HistoProject::project2 histo , 0 != x_var ? *x_var : *xwhat , 0 != y_var ? *y_var : *ywhat , - 0 != cut_var ? cut_var : cuts.get() , first , last ) ; + 0 != cut_var ? cut_var : cuts.get() , + range , first , last ) ; } // ============================================================================ /* make a projection of RooDataSet into the histogram @@ -2572,6 +2646,7 @@ Ostap::HistoProject::project2 const std::string& xexpression , const std::string& yexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2582,7 +2657,8 @@ Ostap::HistoProject::project2 histo , xexpression , yexpression , - selection , + selection , + range , first , last ) ; } @@ -2608,6 +2684,7 @@ Ostap::HistoProject::project3 const std::string& yexpression , const std::string& zexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2666,7 +2743,8 @@ Ostap::HistoProject::project3 0 != x_var ? *x_var : *xwhat , 0 != y_var ? *y_var : *ywhat , 0 != z_var ? *z_var : *zwhat , - 0 != cut_var ? cut_var : cuts.get() , first , last ) ; + 0 != cut_var ? cut_var : cuts.get() , + range , first , last ) ; } // ============================================================================ /* make a projection of RooDataSet into the histogram @@ -2689,6 +2767,7 @@ Ostap::HistoProject::project3 const std::string& yexpression , const std::string& zexpression , const std::string& selection , + const char* range , const unsigned long first , const unsigned long last ) { @@ -2700,7 +2779,8 @@ Ostap::HistoProject::project3 xexpression , yexpression , zexpression , - selection , + selection , + range , first , last ) ; } @@ -2902,7 +2982,7 @@ Ostap::StatusCode Ostap::HistoProject::project3 // ============================================================================ -// TTree +// TTree -> histograms // ============================================================================ // ============================================================================ @@ -3200,6 +3280,7 @@ Ostap::StatusCode Ostap::HistoProject::project3 + // ============================================================================ // TTree -> non-histograms (1D) // ============================================================================ @@ -3736,7 +3817,7 @@ Ostap::HistoProject::project4 yexpression , zexpression , uexpression , - selection , + selection , first , last ) ; }