def test_kisa(): logger = getLogger('ostap.test_kisa') if 62400 <= ROOT.gROOT.GetVersionInt() < 62406: logger.warning('Test can fail for %s' % ROOT.gROOT.GetVersion()) h1 = ROOT.TH1D('h1', '', 200, 3, 3.2) h2 = h1.clone() chain = data.chain with timing('SEQUENTIAL(%s):' % len(chain), logger): chain.project(h1, 'mass', '3<=mass && mass<=3.2 && 0<=c2dtf && c2dtf<5') logger.info(h1.dump(100, 30)) with timing('PARALLEL(%s):' % len(chain), logger): chain.pproject(h2, 'mass', '3<=mass && mass<=3.2 && 0<=c2dtf && c2dtf<5', silent=False) logger.info(h2.dump(100, 30))
def test_kisa2 () : logger = getLogger ( 'ostap.test_kisa2' ) if 62400 <= ROOT.gROOT.GetVersionInt() < 62406 : logger.warning ('Test can fail for %s' % ROOT.gROOT.GetVersion() ) from ostap.fitting.pyselectors import SelectorWithVars, Variable variables = [ Variable ( 'mass' , 'mass(mu+mu-)' , 3.09 , 3.11 ) , Variable ( 'c2dtf' , 'chi2(dtf)' , -1 , 10 ) , Variable ( 'mass2' , 'mass(mu+mu-)' , 1 , 5 , MASS() ) , Variable ( 'mass3' , 'mass(mu+mu-)' , 1 , 5 , 'mass' ) ] from sys import version_info as python_version if python_version.major < 3 : variables.append ( Variable ( 'mass1' , 'mass(mu+mu-)' , 2 , 4 , lambda s : s.mass ) ) ppservers = () ## 'lxplus051' , ) ## ppservers = 'auto' nf = len ( data.files ) nf //= 40 nf += 1 nf = min ( nf , 25 ) with timing('%d files in sequence %s' % ( nf , len( data.chain ) ) ) : selector = SelectorWithVars ( variables = variables , selection = '2<=mass && mass<4 && 0<=c2dtf && c2dtf<5' , silence = False ) chain = data.chain[:nf] st = chain.process ( selector , silent = False , shortcut = True ) ds = selector.data del selector logger.info ( 'Dataset (sequential):\n%s' % ds.table() ) with timing('%s files in parallel %s' % ( len ( data.files ) , len( data.chain ) ) ) : selector = SelectorWithVars ( variables = variables , selection = '2<=mass && mass<4 && 0<=c2dtf && c2dtf<5' , silence = True ) st = data.chain.parallel_fill ( selector , silent = False , chunk_size = -1 , max_files = 1 , ppservers = ppservers ) ds = selector.data del selector logger.info ( 'Dataset (paralell):\n%s' % ds.table ( prefix = '# ' ) )
def test_kisa2 () : from ostap.fitting.selectors import SelectorWithVars, Variable variables = [ Variable ( 'mass' , 'mass(mu+mu-)' , 3.09 , 3.11 ) , Variable ( 'c2dtf' , 'chi2(dtf)' , -1 , 10 ) , Variable ( 'mass2' , 'mass(mu+mu-)' , 1 , 5 , MASS() ) , Variable ( 'mass3' , 'mass(mu+mu-)' , 1 , 5 , 'mass' ) ] from sys import version_info as python_version if python_version.major < 3 : variables.append ( Variable ( 'mass1' , 'mass(mu+mu-)' , 2 , 4 , lambda s : s.mass ) ) ppservers = () ## 'lxplus051' , ) ## ppservers = 'auto' nf = len ( data.files ) nf //= 40 nf += 1 nf = min ( nf , 25 ) with timing('%d files in sequence %s' % ( nf , len( data.chain ) ) ) : selector = SelectorWithVars ( variables = variables , selection = '2<=mass && mass<4 && 0<=c2dtf && c2dtf<5' , silence = False ) chain = data.chain[:nf] st = chain.process ( selector , silent = False , shortcut = True ) ds = selector.data del selector logger.info ( 'Dataset:\n%s' % ds ) with timing('%s files in parallel %s' % ( len ( data.files ) , len( data.chain ) ) ) : selector = SelectorWithVars ( variables = variables , selection = '2<=mass && mass<4 && 0<=c2dtf && c2dtf<5' , silence = True ) st = data.chain.pprocess ( selector , silent = False , chunk_size = -1 , max_files = 1 , ppservers = ppservers ) ds = selector.data del selector logger.info ( 'Dataset:\n%s' % ds )
def test_kisa3(): logger = getLogger('ostap.test_kisa3') if 62400 <= ROOT.gROOT.GetVersionInt() < 62406: logger.warning('Test can fail for %s' % ROOT.gROOT.GetVersion()) h1 = ROOT.TH1D('h1', '', 100, 0, 20) h1 += lambda x: x ## from ostap.trees.funcs import H1DFunc ## xh1 = H1DFunc ( histo = h1 , xvar = 'pt' ) ## from ostap.trees.funcs import FuncTH1 ## xh1 = FuncTH1 ( histo = h1 , xvar = 'pt' ) from ostap.fitting.pyselectors import SelectorWithVars, Variable variables = [ ## Variable ( 'mass1' , 'mass(mu+mu-)' , 2 , 4 , lambda s : s.mass ) , Variable('mass', 'mass(mu+mu-)', 3.09, 3.11), Variable('c2dtf', 'chi2(dtf)', -1, 10), ## Variable ( 'xpt' , 'xpt' , -1 , 30 , xh1 ) , Variable('mass2', 'mass(mu+mu-)', 1, 5, MASS()), Variable('mass3', 'mass(mu+mu-)', 1, 5, 'mass') ] with timing('fill it!'): selector = SelectorWithVars( variables=variables, selection='2<=mass && mass<4 && 0<=c2dtf && c2dtf<5', silence=True) chain = data.chain st = chain.pprocess(selector, silent=False, shortcut=True) ds = selector.data del selector logger.info('Dataset (paralell):\n%s' % ds.table(prefix='# '))
def test_loop_with_cuts(): """More advanced test - loop over the good entries in the chain, - fill dataset """ logger = getLogger("test_loop_with_cuts") with timing("Loop with cuts", logger): varset = ROOT.RooArgSet(mass, c2dtf, pt) dataset = ROOT.RooDataSet(dsID(), 'Test Data set-1', varset) for i in data.chain.withCuts(cuts): v_mass = i.mass v_c2dtf = i.c2dtf v_pt = i.pt ## fill dataset mass.value = v_mass c2dtf.value = v_c2dtf pt.value = v_pt dataset.add(varset) logger.info("Data set (loop-with-cuts):\n%s" % dataset.table(prefix="# "))
def test_simple_loop(): """Simple test - loop over the entries in the chain - select good entries - fill dataset """ logger = getLogger("test_simple_loop") with timing("Simple loop", logger): varset = ROOT.RooArgSet(mass, c2dtf, pt) dataset = ROOT.RooDataSet(dsID(), 'Test Data set-1', varset) for i in data.chain: v_mass = float(i.mass) v_c2dtf = float(i.c2dtf) v_pt = float(i.pt) ## apply cuts if not 3.015 < v_mass < 3.150: continue if not 0.0 < v_c2dtf < 3.0: continue if not 1.5 < v_pt < 10: continue ## fill dataset mass.value = v_mass c2dtf.value = v_c2dtf pt.value = v_pt dataset.add(varset) logger.info("Data set (simple-loop):\n%s" % dataset.table(prefix="# "))
def derivative_testing ( der_type , func , der_exact , logger , **kwargs ) : IMAX = der_type.IMAX cnt1 = {} for i in range ( IMAX ) : cnt1 [i] = SE() ders = [ der_type ( func , I , **kwargs ) for I in range ( IMAX ) ] with timing ( 'derivative test' , logger = logger ) : for i in range(10000) : x = random.uniform ( 0 , pi ) d_true = der_exact ( x ) for I , dd in enumerate ( ders ) : delta = dd ( x ) - d_true cnt1 [I] += delta rows = [ ('I' , 'rms' , 'min' , 'max' ) ] for i,c in cnt1.items() : row = '%d' % i , '% .4g' % c.rms () , '% .4g' % c.min() , '% .4g' % c.max() rows.append ( row ) table = T.table ( rows , title = 'Test numerical derivatives' , prefix = '# ' , alignment = 'clll' ) logger.info ( 'Test numerical derivatives\n%s' % table )
def test_db() : logger.info('Saving all objects into DBASE') import ostap.io.zipshelve as DBASE from ostap.utils.timing import timing with timing( name = 'Save everything to DBASE'), DBASE.tmpdb() as db : db['models' ] = models db.ls()
def test_kisa () : h1 = ROOT.TH1D( 'h1' , '' , 200 , 3 , 3.2 ) h2 = h1.clone() chain = data.chain with timing('SEQUENTIAL(%s):' % len(chain) , logger ) : chain. project ( h1 , 'mass' , '3<=mass && mass<=3.2 && 0<=c2dtf && c2dtf<5' ) logger.info ( h1.dump(100,30) ) with timing('PARALLEL(%s):' % len(chain) , logger ) : chain.pproject ( h2 , 'mass' , '3<=mass && mass<=3.2 && 0<=c2dtf && c2dtf<5' , silent = False ) logger.info ( h2.dump(100,30) )
def test_db(): logger.info('Saving all objects into DBASE') with timing(name='Save everything to DBASE'), DBASE.tmpdb() as db: db['m_x'] = m_x db['m_y'] = m_y db['vars'] = varset db['models'] = models db['dataset'] = dataset db.ls()
def test_positive_pdf(): logger = getLogger("test_positive_pdf") with timing('Positive [4]', logger): params = [h.pdf_positive(4, silent=True, draw=True) for h in histos] for h, f in zip(histos, params): f.plot.draw() logger.info("%-25s : difference %s" % (h.title, diff1(f, h))) time.sleep(1)
def test_convex_3(): with timing('Convex [4]', logger): rB1 = h1.pdf_convex_decreasing(4, silent=True, draw=True) rB2 = h2.pdf_convex_increasing(4, silent=True, draw=True) rB3 = h3.pdf_concave_increasing(4, silent=True, draw=True) rB4 = h4.pdf_concave_decreasing(4, silent=True, draw=True) logger.info( 'Convex [4]: diff %s ' % [diff1(*p) for p in [(rB1, h1), (rB2, h2), (rB3, h3), (rB4, h4)]])
def test_monotonic_3(): with timing('Monotonic[4]', logger): rB1 = h1.pdf_decreasing(4, silent=True, draw=True) rB2 = h2.pdf_increasing(4, silent=True, draw=True) rB3 = h3.pdf_increasing(4, silent=True, draw=True) rB4 = h4.pdf_decreasing(4, silent=True, draw=True) logger.info( 'Monotonic[4]: diff %s ' % [diff1(*p) for p in [(rB1, h1), (rB2, h2), (rB3, h3), (rB4, h4)]])
def test_convex(): with timing('Convex[4]', logger): rL1 = h1.convex(4, increasing=False, convex=True) rL2 = h2.convex(4, increasing=True, convex=True) rL3 = h3.convex(4, increasing=True, convex=False) rL4 = h4.convex(4, increasing=False, convex=False) logger.info( 'Convex[4]: diff %s ' % [diff2(*p) for p in [(rL1, h1), (rL2, h2), (rL3, h3), (rL4, h4)]])
def test_monotonic(): with timing('Monotonic[4]', logger): rL1 = h1.monotonic(4, increasing=False) rL2 = h2.monotonic(4, increasing=True) rL3 = h3.monotonic(4, increasing=True) rL4 = h4.monotonic(4, increasing=False) logger.info( 'Monotonic[4]: diff %s ' % [diff2(*p) for p in [(rL1, h1), (rL2, h2), (rL3, h3), (rL4, h4)]])
def test_db(): logger.info('Saving all objects into DBASE') import ostap.io.zipshelve as DBASE from ostap.utils.timing import timing with timing('Save everything to DBASE', logger), DBASE.tmpdb() as db: for i, m in enumerate(models): db['model/%-2d: %s' % (i, m.name)] = m db['models'] = models db.ls()
def test_db() : with timing ( 'Save everything to DBASE' , logger ), DBASE.tmpdb() as db : db['m_x' ] = m_x db['m_y' ] = m_y db['vars' ] = varset for m in models : db[ 'model:' + m.name ] = m db['models' ] = models db['dataset' ] = dataset db.ls()
def test_positive_spline_pdf () : logger = getLogger("test_positive_spline_pdf") with timing ('P-spline [3,2]' , logger ) : params = [ h.pdf_pSpline ( (5,2) , silent = True , draw = True ) for h in histos ] for h , f in zip ( histos , params ) : with wait ( 1 ) , use_canvas ( 'test_positive_spline_pdf: ' + h.GetTitle() ) : f.plot.draw () logger.info ( "%-25s : difference %s" % ( h.title , diff1 ( f , h ) ) )
def test_db(): logger.info('Saving all objects into DBASE') import ostap.io.zipshelve as DBASE from ostap.utils.timing import timing with timing(name='Save everything to DBASE'), DBASE.tmpdb() as db: db['mass,vars'] = mass, varset0 db['dataset'] = dataset0 for m in models: db['model:' + m.name] = m db['models'] = models db.ls()
def test_positive_spline(): logger = getLogger("test_positive_spline") with timing('P-spline [2,2]', logger): params = [h.pSpline(degree=2, knots=2) for h in histos] for h, f in zip(histos, params): h.draw() f.tf1.draw('same') logger.info("%-25s : difference %s" % (h.title, diff2(f, h))) time.sleep(1)
def test_generic_spline(): logger = getLogger("test_generic_spline") with timing('B-spline [1,4]', logger): params = [h.bSpline(degree=1, knots=4) for h in histos] for h, f in zip(histos, params): h.draw() f.tf1.draw('same') logger.info("%-25s : difference %s" % (h.title, diff2(f, h))) time.sleep(1)
def test_fourier(): logger = getLogger("test_fourier") with timing('Fourier [4]', logger): params = [h5.fourier(4), h6.fourier(6)] for h, f in zip((h5, h6), params): h.draw() f.tf1.draw('same') logger.info("%-25s : difference %s" % (h.title, diff2(f, h))) time.sleep(1)
def test_positive(): logger = getLogger("test_positive") with timing('Positive [4]', logger): params = [h.positive(4) for h in histos] for h, f in zip(histos, params): h.draw() f.tf1.draw('same') logger.info("%-25s : difference %s" % (h.title, diff2(f, h))) time.sleep(1)
def test_positive() : logger = getLogger("test_positive") with timing ( 'Positive [4]' , logger ) : params = [ h.positive ( 4 ) for h in histos ] for h , f in zip ( histos , params ) : with wait ( 2 ) , use_canvas ( 'test_positive %s' % h.GetTitle() ) : h .draw() f.tf1.draw('same') logger.info ( "%-25s : difference %s" % ( h.title , diff2 ( f , h ) ) )
def test_positive_spline () : logger = getLogger("test_positive_spline") with timing ('P-spline [2,3]' , logger ) : params = [ h.pSpline ( degree = 2 , knots = 3 ) for h in histos ] for h , f in zip ( histos , params ) : with wait ( 2 ) , use_canvas ( 'test_positive_spline: %s' % h.GetTitle() ) : h .draw() f.tf1.draw('same') logger.info ( "%-25s : difference %s" % ( h.title , diff2 ( f , h ) ) )
def test_db(): logger = getLogger('test_db') logger.info('Saving all objects into DBASE') import ostap.io.zipshelve as DBASE from ostap.utils.timing import timing with timing('Save everything to DBASE', logger), DBASE.tmpdb() as db: for i, f in enumerate(functions, start=1): db['%03d:%s' % (i, f.__class__.__name__)] = f db['functions'] = functions db.ls()
def test_db(): logger = getLogger('test_db') logger.info('Saving all objects into DBASE') with timing('Save everything to DBASE', logger), DBASE.tmpdb() as db: db['m_x'] = m_x db['m_y'] = m_y for m in models: db['model:' + m.name] = m db['models'] = models db.ls()
def test_frame1(): c = 0 for mt in (False, True, False, True): with implicitMT(mt): logger.info('MT enabled? %s/%s' % (ROOT.ROOT.IsImplicitMTEnabled(), ROOT.ROOT.GetImplicitMTPoolSize())) for obj in ((tree, 'Tree'), (frame, 'Frame'), (tree, 'Tree')): with timing(obj[1], logger): ##logger.info ('Kurtosis: %s ' % obj[0].kurtosis ( 'b1' , 'b1/(b2+1)' ) ) c += obj[0].kurtosis('b1', 'b1/(b2+1)')
def test_chebyshev_sum() : logger = getLogger("test_chebyshev_sum") with timing ( 'Chebyshev-sum[6]' , logger ) : params = [ h.chebyshev_sum ( 8 ) for h in histos ] for h , f in zip ( histos , params ) : with wait ( 1 ) , use_canvas ( 'test_chebyshev_sum: ' + h.GetTitle() ) : h.draw() f.draw('same') logger.info ( "%-25s : difference %s" % ( h.title , diff1 ( f , h ) ) )
def test_fourier(): with timing('Fourier[8]', logger): rF1 = h1.fourier(8) rF2 = h2.fourier(8) rF3 = h3.fourier(8) rF4 = h4.fourier(8) rF5 = h5.fourier(8) rF6 = h6.fourier(8) logger.info('Fourier[8] : diff %s ' % [ diff2(*p) for p in [(rF1, h1), (rF2, h2), (rF3, h3), (rF4, h4), (rF5, h5), (rF6, h6)] ])