Ejemplo n.º 1
0
def test_shapes_2d():

    logger = getLogger("test_shapes_2d")

    if root_info < (6, 18):
        logger.info("Test is distabled for ROOT %s" % str(root_info))
        return

    ## histogram as shape

    h2 = ROOT.TH2D(hID(), '', 40, -5, 5, 40, -10, 10)

    h2 += lambda x, y: 100 * gauss(x) * gauss(y, sigma=2)

    s2 = Models.Shape2D_pdf('S3', shape=h2, xvar=(-5, 5), yvar=(-10, 10))

    with wait(1), use_canvas("shape2d : histogram/x"):
        s2.draw1()
    with wait(1), use_canvas("shape2d : histogram/x in y-range"):
        s2.draw1(in_range=(-6, 6))

    with wait(1), use_canvas("shape2d : histogram/y"):
        s2.draw2()
    with wait(1), use_canvas("shape2d : histogram/y in x-range"):
        s2.draw2(in_range=(-3, 3))
def test_morphing1():

    logger = getLogger('test_morphing1')
    if ROOT.gROOT.GetVersionInt() < 62301:
        logger.warning('Test is disabled for ROOT version %s' %
                       ROOT.gROOT.GetVersion())
        return

    pdf1 = Models.Gauss_pdf('G1', xvar=mass, mean=10, sigma=1)
    pdf2 = Models.Gauss_pdf('G2', xvar=mass, mean=10, sigma=2)
    pdf3 = Models.Gauss_pdf('G3', xvar=mass, mean=10, sigma=3)
    pdf4 = Models.Gauss_pdf('G4', xvar=mass, mean=10, sigma=4)

    pdf = Morphing1D_pdf('M1', {
        1.0: pdf1,
        2.0: pdf2,
        3.0: pdf3,
        4.0: pdf4,
    },
                         xvar=mass)

    for mu in vrange(1, 3, 6):
        pdf.mu = mu
        logger.info('Mu= %s' % mu)
        with wait(1), use_canvas('test_morphing1'):
            pdf.draw()

    with wait(1), use_canvas('test_morphing1'):
        r, f = pdf.fitHisto(h1, draw=True, nbins=100, silent=True)
        logger.info('Morphing: \n%s' % r.table(prefix="# "))
Ejemplo n.º 3
0
def test_shapes_1d():

    logger = getLogger("test_shapes_1d")

    if root_info < (6, 18):
        logger.info("Test is distabled for ROOT %s" % str(root_info))
        return

    ## C++ callable as shape

    xvar = ROOT.RooRealVar('x', '', -5, 5)

    s1 = Models.Shape1D_pdf('S1',
                            shape=Ostap.Math.BifurcatedGauss(),
                            xvar=xvar)

    with wait(1), use_canvas("shape1d : C++ functor"):
        s1.draw()

    ## histogram as shape

    h2 = ROOT.TH1D(hID(), '', 50, -5, 5)
    h2 += lambda x: 100 * gauss(x)

    s2 = Models.Shape1D_pdf('S2', shape=h2, xvar=xvar)

    with wait(1), use_canvas("shape1d : histogram "):
        s2.draw()
Ejemplo n.º 4
0
def test_gauss3D():

    logger = getLogger("test_gauss3D")

    logger.info("Test Gauss3D_pdf")

    model = Models.Gauss3D_pdf('G3',
                               xvar=m_x,
                               yvar=m_y,
                               zvar=m_z,
                               muX=(5, 1, 9),
                               muY=(5, 1, 9),
                               muZ=(5, 1, 9),
                               sigmaX=(0.5, 0.1, 5),
                               sigmaY=(1.5, 0.1, 6),
                               sigmaZ=(2.5, 0.1, 6),
                               phi=(0.5, -1, 10),
                               theta=(1.0, -1, 10),
                               psi=(1.3, -1, 10))

    dataset = model.generate(1000)

    result = model.fitTo(dataset, silent=True)
    result = model.fitTo(dataset, silent=True)

    logger.info('Simple 3D-Gaussian model\n%s' % result.table(prefix="# "))

    with wait(2), use_canvas('test_gauss3D_x'):
        model.draw1(dataset)
    with wait(2), use_canvas('test_gauss3D_y'):
        model.draw2(dataset)
    with wait(2), use_canvas('test_gauss3D_z'):
        model.draw3(dataset)

    models.add(model)
Ejemplo n.º 5
0
def test_simfit2():

    logger = getLogger('test_simfit2')
    # =========================================================================
    signal1 = Models.Gauss_pdf('G1',
                               xvar=mass1,
                               mean=(1.5, 6.5),
                               sigma=(0.1, 2.5))

    model1 = Models.Fit1D(suffix='M1', signal=signal1, background=-1)
    model1.S = NS1
    model1.B = NB1

    mean2 = signal1.vars_add(signal1.mean, 10.0)
    sigma2 = signal1.vars_multiply(signal1.sigma, 0.5)

    signal2 = Models.Gauss_pdf('G2', xvar=mass2, mean=mean2, sigma=sigma2)

    model2 = Models.Fit1D(suffix='M2', signal=signal2, background=-1)
    model2.S = NS2
    model2.B = NB2

    with use_canvas('test_simfit2'):
        # =========================================================================
        ## fit 1
        with wait(1):
            r1, f1 = model1.fitTo(dataset1, draw=True, nbins=50, silent=True)
            title = 'Results of fit to dataset1'
            logger.info('%s\n%s' % (title, r1.table(title=title, prefix='# ')))
        ## fit 2
        with wait(1):
            r2, f2 = model2.fitTo(dataset2, draw=True, nbins=50, silent=True)
            title = 'Results of fit to dataset2'
            logger.info('%s\n%s' % (title, r2.table(title=title, prefix='# ')))
        # =========================================================================

    ## combine data
    sample = ROOT.RooCategory('sample', 'sample', 'A', 'B')

    ## combine datasets
    from ostap.fitting.simfit import combined_data
    vars = ROOT.RooArgSet(mass1, mass2)
    dataset = combined_data(sample, vars, {'A': dataset1, 'B': dataset2})

    ## combine PDFs
    model_sim = Models.SimFit(sample, {'A': model1, 'B': model2}, name='X')

    # =========================================================================
    r, f = model_sim.fitTo(dataset, silent=True)
    r, f = model_sim.fitTo(dataset, silent=True)

    title = 'Results of simultaneous fit'
    logger.info('%s\n%s' % (title, r.table(title=title, prefix='# ')))

    with use_canvas('test_simfit2'):
        with wait(1):
            fA = model_sim.draw('A', dataset, nbins=50)
        with wait(1):
            fB = model_sim.draw('B', dataset, nbins=50)
Ejemplo n.º 6
0
def test_simfit2():

    logger = getLogger('test_simfit2')
    # =========================================================================
    signal1 = Models.Gauss_pdf('G1',
                               xvar=mass1,
                               mean=(1.5, 6.5),
                               sigma=(0.1, 2.5))

    model1 = Models.Fit1D(suffix='M1', signal=signal1, background=-1)
    model1.S = NS1
    model1.B = NB1

    mean2 = signal1.vars_add(signal1.mean, 10.0)
    sigma2 = signal1.vars_multiply(signal1.sigma, 0.5)

    signal2 = Models.Gauss_pdf('G2', xvar=mass2, mean=mean2, sigma=sigma2)

    model2 = Models.Fit1D(suffix='M2', signal=signal2, background=-1)
    model2.S = NS2
    model2.B = NB2

    with use_canvas('test_simfit2'):
        # =========================================================================
        ## fit 1
        with wait(1):
            r1, f1 = model1.fitTo(dataset1, draw=True, nbins=50, silent=True)
        ## fit 2
        with wait(1):
            r2, f2 = model2.fitTo(dataset2, draw=True, nbins=50, silent=True)
        # =========================================================================

    ## combine data
    sample = ROOT.RooCategory('sample', 'sample', 'A', 'B')

    ## combine datasets
    from ostap.fitting.simfit import combined_data
    vars = ROOT.RooArgSet(mass1, mass2)
    dataset = combined_data(sample, vars, {'A': dataset1, 'B': dataset2})

    ## combine PDFs
    model_sim = Models.SimFit(sample, {'A': model1, 'B': model2}, name='X')

    # =========================================================================
    r, f = model_sim.fitTo(dataset, silent=True)
    r, f = model_sim.fitTo(dataset, silent=True)

    with use_canvas('test_simfit2'):
        with wait(1):
            fA = model_sim.draw('A', dataset, nbins=50)
        with wait(1):
            fB = model_sim.draw('B', dataset, nbins=50)

    ## fNLL  = model_sim.draw_nll ( 'SM2' , dataset , range =   (0,1000)  )
    ## significance
    ## wilks = model_sim.wilks    ( 'SM2' , dataset  )

    logger.info('Fit  results are: %s ' % r)
Ejemplo n.º 7
0
def test_bootstrap  ( ) :
    """Perform toys-study for possible fit bias and correct uncertainty evaluation
    - generate `nToys` pseudoexperiments with some PDF `pdf`
    - fit each experiment with the same PDF
    - store  fit results
    - calculate statistics of pulls
    - fill distributions of fit results
    - fill distributions of pulls 
    """

    logger = getLogger ( 'test_bootstrap' )

    N = 200 
    dataset = model.generate ( N , sample = False )

    ## prefit the whole dataset
    with use_canvas ( title = 'test_booststrap' ) : 
        res , f = model.fitTo ( dataset , draw = True , nbins = 100 , silent = True , refit = 5 )

    more_vars   = { 'vm' : lambda  r, *_ : ( r.mean_G - 0.4 ) / 0.1      ,
                    'vs' : lambda  r, *_ :   r.sigma_G        / 0.1 - 1  ,
                    'vr' : lambda  r, *_ :   r.sigma_G * 1    / r.mean_G } 
                    

    ## start Jackknife process 
    results , stats = Toys.make_bootstrap (
        pdf         = model    ,
        size        = 400      , 
        data        = dataset  , 
        fit_config  = { 'silent' : True , 'refit'   : 5   } ,
        fit_pars    = { 'mean_G' : 0.4  , 'sigma_G' : 0.1 } ,
        more_vars   = more_vars , 
        silent      = True ,
        progress    = True ,
        frequency   = 100  )

    ## fit the whole sample 
    with use_canvas ( title = 'test_booststrap' ) : 
        res , f = model.fitTo ( dataset , draw = True  , nbins = 100 , silent = True , refit = 5 )
    ## print fit results 
    logger.info  ('Fit results:\n%s' % res.table ( title     = 'Fit results' ,
                                                   prefix    = '# '          ,
                                                   more_vars = more_vars     ) ) 
    ## print the final table
    Toys.print_bootstrap ( res   ,
                           stats ,
                           morevars = dict ( (k,more_vars[k](res,model)) for k in more_vars ),
                           logger   = logger )

    time.sleep ( 2 ) 
Ejemplo n.º 8
0
def test_polypossym2D():

    logger = getLogger('test_polypossym2D')

    logger.info('Test PolyPos2Dsym_pdf: Symmetric positive polynomial')
    model = Models.PolyPos2Dsym_pdf('P2Ds ', m_x, m_y, n=2)

    with rooSilent():
        result, f = model.fitTo(dataset)
    with use_canvas('test_polypossym2D'):
        with wait(1):
            model.draw1(dataset)
        with wait(1):
            model.draw2(dataset)

    result, f = model.fitTo(dataset, silent=True)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        logger.info('Bernstein Coefficients:\n%s' % model.pars())

    models.add(model)
def test_multiprocessing_function():
    """Test parallel processnig with multiprocessing
    """

    logger = getLogger("ostap.test_multiprocessing_function")
    logger.info('Test job submission with module %s' % multiprocessing)

    ncpus = multiprocessing.cpu_count()

    from multiprocessing import Pool

    pool = Pool(ncpus)

    jobs = pool.imap_unordered(make_histos, zip(count(), inputs))

    result = None
    for h in progress_bar(jobs, max_value=len(inputs)):
        if not result: result = h
        else: result.Add(h)

    pool.close()
    pool.join()

    logger.info("Histogram is %s" % result.dump(80, 20))
    logger.info("Entries  %s/%s" % (result.GetEntries(), sum(inputs)))

    with wait(5), use_canvas('test_multiprocessing_function'):
        result.draw()

    return result
Ejemplo n.º 10
0
def test_vars2 () :
    
    logger = getLogger ( 'test_vars2' )

    from ostap.fitting.roofuncs import MonotonicPoly as MP 

    f      = MP ( 'G' , xvar = x , increasing = True , power = 4 )
    f.pars = 0.6 , 0.8 , -0.1 , -0.6
    f.a    = 0.06
    f.b    = 2.72
    f.a.release ()
    f.b.release ()

    eff2   = Efficiency1D ( 'E4' , f , cut = acc  , xvar = x )
    
    r2     = eff2.fitTo ( ds )
    
    with use_canvas ( 'test_vars2' ) : 
        f2     = eff2.draw  ( ds )
    
    for p in points :
        e  = eff2 ( p , error = True )
        ev = e.value()
        e0 = eff0 ( p ) / emax  
        logger.info (' Point/Eff %4.1f %s%% (%.2f%%)'   % ( p , (100*e).toString ( '(%5.2f+-%4.2f)' ) ,  e0 * 100 ) )
Ejemplo n.º 11
0
def test_splinesym2D():

    logger = getLogger('test_splinesym2D')

    logger.info('Test Spline2Dsym_pdf: Symetric 2D-spline')

    ss = Ostap.Math.BSpline(m_x.xmin(), m_x.xmax(), 1, 2)
    ss3 = Ostap.Math.PositiveSpline2DSym(ss)

    model = Models.Spline2Dsym_pdf('SS2D', m_x, m_y, ss3)

    with rooSilent():
        result, f = model.fitTo(dataset)
    with use_canvas('test_splinesym2D'):
        with wait(1):
            model.draw1(dataset)
        with wait(1):
            model.draw2(dataset)

    result, f = model.fitTo(dataset, silent=True)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)

    models.add(model)
Ejemplo n.º 12
0
def test_parallel_pathos_pp_generic ( ) :
    """Test parallel processnig with parallel_pathos (use generic task)
    """
    logger  = getLogger ("ostap.test_parallel_pathos_mp_generic")
    if not WorkManager :
        logger.error ("Failure to import WorkManager")
        return
    
    logger.info ('Test job submission with %s' % WorkManager  ) 

    if DILL_PY3_issue : 
        logger.warning ("test is disabled (DILL/ROOT/PY3 issue)" )
        return

    ## create the manager 
    manager = WorkManager ( silent = False  , pp = True )

    ## create the task 
    task     = GenericTask ( processor = make_histo   ,
                             merger    = merge_histos )    

    ## process the task 
    result   = manager.process ( task ,  inputs ) 
    
    logger.info ( "Histogram is %s" % result.dump ( 80 , 10 )  )
    logger.info ( "Entries  %s/%s" % ( result.GetEntries() , sum ( inputs ) ) ) 
    
    with wait ( 1 ) , use_canvas ( 'test_parallel_pathos_pp_generic' ) : 
        result.draw (   ) 

    return result
Ejemplo n.º 13
0
def test_parallel_gaudi_mp_generic ( ) :
    """Test parallel processnig with parallel_gaudi (use generic task)
    """
    logger  = getLogger ("ostap.test_parallel_gaudi_mp_generic")
    if not WorkManager :
        logger.error ("Failure to import WorkManager")
        return
    
    logger.info ('Test job submission with %s' % WorkManager  ) 

    ## vi = sys.version_info
    ## if 3<= vi.major and 6 <= vi.minor :
    ##     vip = '%s.%s.%s' % ( vi.major , vi.minor , vi.micro ) 
    ##     logger.warning ("test is disabled for Python %s (dill/ROOT issue)" % vip )
    ##     return
    
    ## create the manager 
    manager = WorkManager ( silent = False  )

    ## create the task 
    task    = GenericTask ( processor = make_histo   ,
                            merger    = merge_histos )    
    
    ## process the task 
    result   = manager.process ( task ,  inputs ) 
    
    logger.info ( "Histogram is %s" % result.dump ( 80 , 10 )  )
    logger.info ( "Entries  %s/%s" % ( result.GetEntries() , sum ( inputs ) ) ) 
    
    with wait ( 1 ) , use_canvas ( 'test_parallel_gaudi_mp_generic' ) : 
        result.draw (   ) 
        
    return result
Ejemplo n.º 14
0
def test_carlson_E():
    """Test expression for complete elliptic integral E(k)` via Carlson's symmetruc forms
    - see Ostap.Math.elliptic_E 
    - see Ostap.Math.carlson_RG
    """

    logger = getLogger('test_carlson_E')
    logger.info('Test expression for E(k) via Carlson Forms')

    from ostap.math.models import f1_draw

    def e1(k):
        return Ostap.Math.elliptic_E(k)

    def e2(k):
        return 2 * Ostap.Math.carlson_RG(1 - k * k, 1, 0)

    with wait(3), use_canvas('test_carlson_E'):
        f1_draw(e1, xmin=0, xmax=1, min=0, linecolor=2, linewidth=2)
        f1_draw(e2,
                'same',
                xmin=0,
                xmax=1,
                min=0,
                linecolor=4,
                linewidth=2,
                linestyle=9)

        logger.info('Red   line : E (k) complete elliptic integral')
        logger.info(
            "Blue  line : E (k) expressed via symmetric Carlson's RG function")
Ejemplo n.º 15
0
def test_hypatia () :
    
    logger = getLogger ( 'test_hypatia' )

    logger.info ('Test Hyperbolic: symmetric generalised Hyperbolic resolution model' )
    from   ostap.fitting.resolution import ResoHypatia
    reso = ResoHypatia ( 'Hypatia' , mass ,
                         sigma  = ( 0.1 , 0.01 , 5.0 ) ,
                         zeta   = ( 1.0 , 1.e-5 , 1.e+5 ) ,
                         lambd  = ( -20,20 ) ,
                         sigma0 = 0.01 )
    
    for i in range ( 6 ) :
        result, frame = reso. fitTo ( dataset , silent = True  )
        
    with wait ( 1 ) , use_canvas ( 'test_genhyperbolic' ) : 
        result, frame = reso. fitTo ( dataset , silent = True , draw = True )
        
    if 0 != result.status() or 3 != result.covQual() :
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' % ( result.status() , result.covQual () ) )
        print(result)
    else :     
        make_print ( reso , result , 'Symmetric Hypatia', logger )
 
    models.add ( reso)
Ejemplo n.º 16
0
def test_pp_callable():
    """Test parallel python with callable  
    """
    logger = getLogger("ostap.test_pp_callable")
    logger.info('Test job submission with %s' % pp)

    logger.warning("test is disabled for UNKNOWN REASON")
    return

    job_server = pp.Server()

    jobs = [(i, job_server.submit(mh.__call__, (i, n)))
            for (i, n) in enumerate(inputs)]

    result = None
    for input, job in progress_bar(uimap(jobs), max_value=len(jobs)):
        histo = job()
        if not result: result = histo
        else:
            result.Add(histo)
            del histo

    logger.info("Histogram is %s" % result.dump(80, 10))
    logger.info("Entries  %s/%s" % (result.GetEntries(), sum(inputs)))

    with wait(1), use_canvas('test_pp_callable'):
        result.draw()

    return result
Ejemplo n.º 17
0
def test_pp_function():
    """Test parallel python with plain function
    """
    logger = getLogger("ostap.test_pp_function")
    logger.info('Test job submission with %s' % pp)

    from ostap.core.known_issues import DILL_ROOT_issue
    if DILL_ROOT_issue:
        logger.warning("test is disabled for Python %s (dill/ROOT issue)")
        return

    job_server = pp.Server()

    jobs = [(i, job_server.submit(make_histo, (i, n)))
            for (i, n) in enumerate(inputs)]

    result = None
    for input, job in progress_bar(uimap(jobs), max_value=len(jobs)):
        histo = job()
        if not result: result = histo
        else:
            result.Add(histo)
            del histo

    logger.info("Histogram is %s" % result.dump(80, 10))
    logger.info("Entries  %s/%s" % (result.GetEntries(), sum(inputs)))

    job_server.print_stats()

    with wait(1), use_canvas('test_pp_function'):
        result.draw()

    return result
def test_laplace():

    logger = getLogger('test_laplace')

    logger.info('Test Asymmetric Laplace shape')
    laplace = Models.AsymmetricLaplace_pdf(name='AL', xvar=x, mean=5, slope=1)

    from ostap.fitting.convolution import Convolution_pdf

    ## constant resolution
    laplace_1 = Convolution_pdf(name='L1', pdf=laplace, resolution=0.75)

    ## resolution PDF
    from ostap.fitting.resolution import ResoApo2
    rAp = ResoApo2('A', x, 0.75)

    ## resolution as PDF
    laplace_2 = Convolution_pdf(name='L2', pdf=laplace, resolution=rAp)

    with use_canvas('test_laplace'):
        f = laplace.draw(silent=True)
        f1 = laplace_1.draw(silent=True)
        f2 = laplace_2.draw()

        with wait(2):
            f.draw()
            f1.draw('same')
            f2.draw('same')

    models.add(laplace)
    models.add(laplace_1)
    models.add(laplace_2)
Ejemplo n.º 19
0
def test_const():

    logger = getLogger('test_const')
    logger.info(
        'Simplest (factorized) fit model:  ( Gauss + const ) x ( Gauss + const ) '
    )
    model = Models.Fit2D(
        signal_x=signal1,
        signal_y=signal2s,
    )

    ## fit with fixed mass and sigma
    with rooSilent(), use_canvas('test_const'):
        result, frame = model.fitTo(dataset)
        model.signal_x.sigma.release()
        model.signal_y.sigma.release()
        model.signal_x.mean.release()
        model.signal_y.mean.release()
        result, frame = model.fitTo(dataset)
        with wait(1):
            model.draw1(dataset)
        with wait(1):
            model.draw2(dataset)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        logger.info('S1xS2 : %20s' % result(model.SS)[0])
        logger.info('S1xB2 : %20s' % result(model.SB)[0])
        logger.info('B1xS2 : %20s' % result(model.BS)[0])
        logger.info('B1xB2 : %20s' % result(model.BB)[0])

    models.add(model)
Ejemplo n.º 20
0
def test_interpolation():
    """Test spline interpolation
    """

    if 62006 <= root_version_int:
        logger.warning("Test_interpolation segfaults for ROOT %s" %
                       root_version_int)
        return

    from math import sin, pi, sqrt

    fun = lambda x: sin(2 * pi * x)

    bs = ostap.math.bspline.interpolate(
        fun, None, [0] + [random.uniform(0.01, 0.99) for i in range(30)] + [1],
        2)

    from ostap.stats.counters import SE
    s = SE()
    for i in range(10000):
        x = random.uniform(0, 1)
        vf = fun(x)
        vb = bs(x)
        s += vf - vb

    logger.info('Interpolation quality %s' % s)

    functions.add(bs)

    with wait(3), use_canvas('test_interpolation'):
        f1_draw(fun, xmin=0, xmax=1, linecolor=2)
        bs.draw('same', linecolor=4)
Ejemplo n.º 21
0
def test_expopoly2():

    logger = getLogger('test_expopoly2')

    logger.info("Test  Poly(2)*Expo -Distribution")
    model = Models.Bkg_pdf('P2e', x, power=2)
    model.tau.fix(-1.25)

    result, f = model.fitTo(dataset, silent=True)
    model.tau.release()
    result, f = model.fitTo(dataset, silent=True)

    with wait(1), use_canvas('test_expopoly2'):
        model.draw(dataset)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        logger.info("\tTau:          tau= %-17s " % result(model.tau)[0])
        for phi in model.phis:
            logger.info("\tExpoPoly2:    phi= %-17s " % phi.ve())

    models.add(model)
Ejemplo n.º 22
0
def test_gauss():

    logger = getLogger('test_gauss')

    logger.info('Test ResoGauss: bifurcated Gaussian resolution model')
    from ostap.fitting.resolution import ResoGauss
    reso = ResoGauss('Gauss',
                     mass,
                     mean=(0.0, -1, +1),
                     sigma=(0.5, 0.1, 1.0),
                     kappa=(0.0, -1.0, 1.0))

    result, frame = reso.fitTo(dataset, silent=True)
    result, frame = reso.fitTo(dataset, silent=True)
    with wait(1), use_canvas('test_gauss'):
        result, frame = reso.fitTo(dataset, silent=True, draw=True)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        make_print(reso, result, 'Asymmetric Gaussian', logger)

    models.add(reso)
Ejemplo n.º 23
0
def test_ppft_callable():
    """Test parallel python with callable  
    """
    logger = getLogger("ostap.test_ppft_callable")
    logger.info('Test job submission with %s' % ppft)

    if not ppft:
        logger.error("ppft is not available")
        return

    if DILL_PY3_issue:
        logger.warning("test is disabled for Python %s (DILL/ROOT/PY3 issue)")
        return

    job_server = ppft.Server()

    jobs = [(i, job_server.submit(mh.__call__, (i, n)))
            for (i, n) in enumerate(inputs)]

    result = None
    for input, job in progress_bar(jobs):
        histo = job()
        if not result: result = histo
        else:
            result.Add(histo)
            del histo

    logger.info("Histogram is %s" % result.dump(80, 20))
    logger.info("Entries  %s/%s" % (result.GetEntries(), sum(inputs)))

    with wait(1), use_canvas('test_ppft_callable'):
        result.draw()

    return result
Ejemplo n.º 24
0
def test_pspolsym2D():

    logger = getLogger('test_pspolsym2D')

    logger.info(
        'Test PSPol2Dsym_pdf: *SYMMETRIC* product of phase space factors, modulated by positive polynomial in X and Y '
    )

    ## "fictive phase space"
    ps = Ostap.Math.PhaseSpaceNL(0, 10, 2, 10)
    model = Models.PSPol2Dsym_pdf('PS2Ds', m_x, m_y, ps, n=2)

    with rooSilent():
        result, f = model.fitTo(dataset)
    with use_canvas('test_pspolsym2D'):
        with wait(1):
            model.draw1(dataset)
        with wait(1):
            model.draw2(dataset)

    result, f = model.fitTo(dataset, silent=True)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        logger.info('Bernstein Coefficients:\n%s' % model.pars())

    models.add(model)
Ejemplo n.º 25
0
def test_parallel_pathos_pp_bare ( ) :
    """Test parallel processnig with parallel_pathos (bare interface) 
    """
    logger  = getLogger ("ostap.test_parallel_pathos_mp_bare")
    if not WorkManager :
        logger.error ("Failure to import WorkManager")
        return 
    
    logger.info ('Test job submission with %s' % WorkManager  ) 

    if DILL_PY3_issue : 
        logger.warning ("test is disabled (DILL/ROOT/PY3 issue)" )
        return

    ## create the manager 
    manager  = WorkManager ( silent = False  , pp = True )
        
    result   = None
    ## use the bare interface 
    for res in manager.iexecute ( make_histo2 , zip ( count() , inputs ) , progress = True ) :
        if result is None  : result = res
        else               : result.Add ( res )  

    logger.info ( "Histogram is %s" % result.dump ( 80 , 10 )  )
    logger.info ( "Entries  %s/%s" % ( result.GetEntries() , sum ( inputs ) ) ) 
    
    with wait ( 1 ) , use_canvas ( 'test_parallel_pathos_pp_bare' ) : 
        result.draw (   ) 

    return result 
Ejemplo n.º 26
0
def test_expopspol2D():

    logger = getLogger('test_expopspol2D')

    logger.info(
        'Test ExpoPSPol2D_pdf: Exponential times phase space factor, modulated by positive polynomial in X and Y '
    )

    ## "fictive phase space"
    psy = Ostap.Math.PhaseSpaceNL(0, 10, 2, 10)
    model = Models.ExpoPSPol2D_pdf('EPS', m_x, m_y, psy, nx=2, ny=2)

    with rooSilent():
        result, f = model.fitTo(dataset)
    with use_canvas('test_expopspol2D'):
        with wait(1):
            model.draw1(dataset)
        with wait(1):
            model.draw2(dataset)

    result, f = model.fitTo(dataset, silent=True)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        logger.info('Bernstein Coefficients:\n%s' % model.pars())

    models.add(model)
Ejemplo n.º 27
0
def test_phasespace3_compare():
    ## if 1 < 2 :

    masses = (3, 1, 0.1)

    fun1 = lambda x: Ostap.Kinematics.phasespace3i(x, *masses
                                                   )  ## numerical integration
    fun2 = lambda x: Ostap.Kinematics.phasespace3s(x, *masses
                                                   )  ## symmetric form
    fun3 = lambda x: Ostap.Kinematics.phasespace3a(x, *masses
                                                   )  ## non-symmetric form
    fun4 = lambda x: Ostap.Kinematics.phasespace3nr(
        x, *masses)  ## non-relativistic limit

    xmin = sum(masses)

    with wait(3), use_canvas('test_phasespace3_compare'):

        for i, f in enumerate((fun1, fun2, fun3, fun4)):

            color = i + 2

            if i == 0:
                f1_draw(f, line_color=color, linewidth=2, xmin=xmin, xmax=40)
            else:
                f1_draw(f,
                        'same',
                        line_color=color,
                        linewidth=2,
                        xmin=xmin,
                        xmax=40)
Ejemplo n.º 28
0
def test_expopolsym2D():

    logger = getLogger('test_expopolsym2D')

    logger.info(
        'Test ExpoPol2Dsym_pdf: symmetric exponential times exponential modulated by positive polynomial in X and Y'
    )

    model = Models.ExpoPol2Dsym_pdf('EPs', m_x, m_y, n=2)

    with rooSilent():
        result, f = model.fitTo(dataset)
    with use_canvas('test_expopolsym2D'):
        with wait(1):
            model.draw1(dataset)
        with wait(1):
            model.draw2(dataset)

    result, f = model.fitTo(dataset, silent=True)

    if 0 != result.status() or 3 != result.covQual():
        logger.warning('Fit is not perfect MIGRAD=%d QUAL=%d ' %
                       (result.status(), result.covQual()))
        print(result)
    else:
        logger.info('Bernstein Coefficients:\n%s' % model.pars())

    models.add(model)
Ejemplo n.º 29
0
def test_carlson_PS3():
    """Test 3-body phase space calculation via elliptic integrals
    - see Ostap.Math.PhaseSpace3
    - see Ostap.Math.PhaseSpace3s
    - see Ostap.Kinematics.phasespace3
    - see https://indico.cern.ch/event/368497/contributions/1786992/attachments/1134067/1621999/davydychev.PDF
    - see http://cds.cern.ch/record/583358/files/0209233.pdf
    - see https://www.researchgate.net/publication/2054534_Three-body_phase_space_symmetrical_treatments
    """
    logger = getLogger('test_carlson_PS3')
    logger.info('Test 3-body phase space calculation via elliptic integrals')

    ps1 = Ostap.Math.PhaseSpace3(3, 1, 0.1)
    ps2 = Ostap.Math.PhaseSpace3s(3, 1, 0.1)  ## <--- HERE

    with wait(3), use_canvas('test_carlson_PS3'):
        ps1.draw(xmin=ps1.threshold(), xmax=50, linecolor=2, linewidth=2)
        logger.info('Red  line - 3-body phase space via numerical integration')
        ps2.draw('same',
                 xmin=ps2.threshold(),
                 xmax=50,
                 linecolor=4,
                 linewidth=2)
        logger.info(
            'Blue line - analytic expression of 3-body phase space via elliptic integrals'
        )
Ejemplo n.º 30
0
def test_vars3 () :

    logger = getLogger ( 'test_vars3' )

    a  = ROOT.RooRealVar  ( 'A', 'a' , 0.05  ,   0   , 1   )
    b  = ROOT.RooRealVar  ( 'B', 'b' , 0.02  , -0.05 , 0.1 )
    c  = ROOT.RooRealVar  ( 'C', 'c' , 0.005 ,   0   , 0.1 )

    import ostap.fitting.roofuncs as     R
    from   ostap.fitting.funbasic import Fun1D 
    X   = Fun1D ( x , xvar = x , name = 'X' )
    
    ##F   = (X**2) * c + X * b + a 
    F   = a +  b * X + c * X**2
    
    eff2   = Efficiency1D ( 'E5' , F , cut = acc  , xvar = x )
    
    r2     = eff2.fitTo ( ds )
    
    with use_canvas ( 'test_vars3' ) : 
        f2     = eff2.draw  ( ds )
    
    
    for p in points :
        e  = eff2 ( p , error = True )
        ev = e.value()
        e0 = eff0 ( p ) / emax  
        logger.info (' Point/Eff %4.1f %s%% (%.2f%%)'   % ( p , (100*e).toString ( '(%5.2f+-%4.2f)' ) ,  e0 * 100 ) )