Esempio n. 1
0
def test_pbxpb_BB  () :
    logger.info ('Non-factorizeable background component:  ( Gauss + expo*P1 ) (x) ( Gauss + expo*P1 ) + (expo*P1)**2')
    model   = Models.Fit2D (
        suffix   = '_7' , 
        signal_x = signal1  ,
        signal_y = signal2s ,
        bkg_1x     = 1 , 
        bkg_1y     = 1 ,
        bkg_2D    = Models.ExpoPol2D_pdf ( 'P2D7' , m_x , m_y , nx = 1 , ny = 1 ) 
        )
    
    model.bkg_1x   .tau  .fix ( 0 )
    model.bkg_1y   .tau  .fix ( 0 )

    ## fit with fixed mass and sigma
    with rooSilent() : 
        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 )

    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 ) 
Esempio n. 2
0
def test_p2xp2():
    logger.info(
        'Simple (factorized) fit model:  ( Gauss + P1 ) (x) ( Gauss + P1 ) ')
    model = Models.Fit2D(
        suffix='_2',
        signal_1=signal1,
        signal_2=signal2s,
        bkg1=-1,
        bkg2=-1,
        bkgA=-1,
        bkgB=-1,
    )

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 3
0
def test_p1xp1_BB():
    logger.info(
        'Simplest non-factorized fit model:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + BB'
    )
    model = Models.Fit2D(suffix='_3',
                         signal_1=signal1,
                         signal_2=signal2s,
                         bkg1=-1,
                         bkg2=-1,
                         bkg2D=Models.PolyPos2D_pdf('P2D',
                                                    m_x,
                                                    m_y,
                                                    nx=2,
                                                    ny=2))

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 4
0
def test_psxps_BBs () :
        
    logger.info ('Non-factorizeable symmetric background component:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + (PS*P1)**2')
    PS      = Ostap.Math.PhaseSpaceNL( 1.0  , 5.0 , 2 , 5 )
    model   = Models.Fit2D (
        suffix   = '_11' , 
        signal_x = signal1  ,
        signal_y = signal2s ,
        bkg_1x     = -1 , 
        bkg_1y     = -1 ,
        bkg_2D    = Models.PSPol2Dsym_pdf ( 'P2D11' , m_x , m_y , ps = PS , n = 1 ) 
        )

    ## fit with fixed mass and sigma
    with rooSilent() : 
        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 )

    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 ) 
Esempio n. 5
0
def test_p1xp1_BBs():

    logger.info(
        'Non-factorized symmetric background fit model:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + BBsym'
    )
    model = Models.Fit2D(suffix='_4',
                         signal_x=signal1,
                         signal_y=signal2s,
                         bkg_1x=-1,
                         bkg_1y=-1,
                         bkg_2D=Models.PolyPos2Dsym_pdf('P2Ds', m_x, m_y, n=2))

    ## fit with fixed mass and sigma
    with rooSilent():
        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)
        model.draw1(dataset)
        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)
Esempio n. 6
0
def 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():
        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)
        model.draw1(dataset)
        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)
Esempio n. 7
0
def fit_2d():
    #variable inizialization
    im = ROOT.RooRealVar('im', 'im', 2.42, 2.52)
    m23 = ROOT.RooRealVar('m23', 'm23', 0.80, 1.00)

    #open and reduce dataset
    rfile = ROOT.TFile("../datasets/test_xic_100invpb.root", "READ")
    ds = rfile["da_lc"]
    ds = ds.reduce("im > 2.42 && im < 2.52 && m23 > 0.8 && m23 < 1.")
    dh = (ds.reduce(ROOT.RooArgSet(im, m23), "im>0 && m23>0")).binnedClone()

    #model creation
    signal_im = Models.Gauss_pdf('Gauss_x',
                                 xvar=im,
                                 mean=(2.45, 2.48),
                                 sigma=(0.001, 0.01))
    signal_m23 = Models.Gauss_pdf('Gauss_y',
                                  xvar=m23,
                                  mean=(0.8, 1.),
                                  sigma=(0.001, 0.01))
    bkg_poly_im = Models.Bkg_pdf('BkgGauss_x', xvar=im, power=0.)
    bkg_poly_m23 = Models.Bkg_pdf('BkgGauss_y', xvar=m23, power=0.)
    model_gauss = Models.Fit2D(signal_x=signal_im,
                               signal_y=signal_m23,
                               bkg_1x=bkg_poly_im,
                               bkg_1y=bkg_poly_m23)

    #model fitting
    result, frame = model_gauss.fitTo(dh)
    result, frame = model_gauss.fitTo(ds, draw=True)
    result.draw()
Esempio n. 8
0
def test_model_13():

    logger.info(
        'Non-factorizeable fit component:  ( Gauss + expo*P1 ) (x) ( Gauss + expo*P1 ) + (Expo*PS)**2'
    )
    PS = Ostap.Math.PhaseSpaceNL(1.0, 5.0, 2, 5)
    model = Models.Fit2D(suffix='_13',
                         signal_1=Models.Gauss_pdf('Gx',
                                                   m_x.getMin(),
                                                   m_x.getMax(),
                                                   mass=m_x),
                         signal_2=Models.Gauss_pdf('Gy',
                                                   m_y.getMin(),
                                                   m_y.getMax(),
                                                   mass=m_y),
                         power1=1,
                         power2=1,
                         bkg2D=Models.ExpoPSPol2D_pdf('P2D13',
                                                      m_x,
                                                      m_y,
                                                      psy=PS,
                                                      nx=1,
                                                      ny=1))

    model.signal1.sigma.fix(m.error())
    model.signal2.sigma.fix(m.error())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.bkg1.tau.fix(0)
    model.bkg2.tau.fix(0)

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 9
0
def test_model_15():

    logger.info(
        'Non-factorized symmetric background component (spline):  ( Gauss + expo*P1 ) (x) ( Gauss + expo*P1 ) + Spline2Dsym'
    )
    SPLINES = Ostap.Math.Spline2DSym(spline1)
    model = Models.Fit2D(suffix='_15',
                         signal_1=Models.Gauss_pdf('Gx',
                                                   m_x.getMin(),
                                                   m_x.getMax(),
                                                   mass=m_x),
                         signal_2=Models.Gauss_pdf('Gy',
                                                   m_y.getMin(),
                                                   m_y.getMax(),
                                                   mass=m_y),
                         power1=1,
                         power2=1,
                         bkg2D=Models.Spline2Dsym_pdf('P2D15',
                                                      m_x,
                                                      m_y,
                                                      spline=SPLINES))

    model.signal1.sigma.fix(m.error())
    model.signal2.sigma.fix(m.error())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.bkg1.tau.fix(0)
    model.bkg2.tau.fix(0)

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 10
0
def test_p1xp1_BB():
    logger.info(
        'Simplest non-factorized fit model:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + BB'
    )
    model = Models.Fit2D(suffix='_3',
                         signal_1=Models.Gauss_pdf('Gx',
                                                   m_x.getMin(),
                                                   m_x.getMax(),
                                                   mass=m_x),
                         signal_2=Models.Gauss_pdf('Gy',
                                                   m_y.getMin(),
                                                   m_y.getMax(),
                                                   mass=m_y),
                         power1=1,
                         power2=1,
                         bkg2D=Models.PolyPos2D_pdf('P2D',
                                                    m_x,
                                                    m_y,
                                                    nx=2,
                                                    ny=2))

    model.signal1.sigma.fix(m.error())
    model.signal2.sigma.fix(m.error())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.bkg1.tau.fix(0)
    model.bkg2.tau.fix(0)

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 11
0
def test_p1xp1_BBss():
    logger.info(
        'Symmetrised fit model with non-factorized symmetric background:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + BBsym'
    )
    sb = ROOT.RooRealVar('sb', 'SB', 0, 10000)
    model = Models.Fit2D(suffix='_5',
                         signal_1=Models.Gauss_pdf('Gx',
                                                   m_x.getMin(),
                                                   m_x.getMax(),
                                                   mass=m_x),
                         signal_2=Models.Gauss_pdf('Gy',
                                                   m_y.getMin(),
                                                   m_y.getMax(),
                                                   mass=m_y),
                         power1=1,
                         power2=1,
                         bkg2D=Models.PolyPos2Dsym_pdf('P2Ds', m_x, m_y, n=2),
                         sb=sb,
                         bs=sb)

    model.signal1.sigma.fix(m.error())
    model.signal2.sigma.fix(m.error())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.bkg1.tau.fix(0)
    model.bkg2.tau.fix(0)

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 12
0
def test_model_13():

    logger = getLogger('test_model_13')

    logger.info(
        'Non-factorizeable fit component:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + (Expo*PS)**2'
    )
    PS = Ostap.Math.PhaseSpaceNL(1.0, 5.0, 2, 5)
    model = Models.Fit2D(suffix='_13',
                         signal_x=signal1,
                         signal_y=signal2s,
                         bkg_1x=-1,
                         bkg_1y=-1,
                         bkg_2D=Models.ExpoPSPol2D_pdf('P2D13',
                                                       m_x,
                                                       m_y,
                                                       psy=PS,
                                                       nx=1,
                                                       ny=1))

    ## fit with fixed mass and sigma
    with rooSilent():
        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)
        result, frame = model.fitTo(dataset)
    with use_canvas('test_model_13'):
        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)
Esempio n. 13
0
def test_components_2D():

    logger = getLogger('test_components_2D')

    logger.info('Test  multi-component  3d fit')

    model = Models.Fit2D(name='fit_comp',
                         signal_x=signal_x1,
                         signal_y=signal_y1,
                         bkg_1x=bkg_x,
                         bkg_1y=bkg_y,
                         components=[ss_cmp, sb_cmp, bs_cmp, bb_cmp])

    with rooSilent():
        ## components
        model.SS.fix(N_ss)
        model.SB.fix(N_sb)
        model.SB.fix(N_bs)
        model.BB.fix(N_bb)

        model.C[0].fix(5000)
        model.C[1].fix(500)
        model.C[2].fix(500)
        model.C[3].fix(1000)

        r = model.fitTo(dataset)

        model.SS.release()
        model.SB.release()
        model.BS.release()
        model.BB.release()

        model.C[0].release()
        model.C[1].release()
        model.C[2].release()
        model.C[3].release()

        r = model.fitTo(dataset)
        r = model.fitTo(dataset)
        r = model.fitTo(dataset)

        with use_canvas('test_components_2D'):

            model.draw1(dataset)
            model.draw2(dataset)

    logger.info('Model %s Fit result \n#%s ' % (model.name, r))
Esempio n. 14
0
def test_p1xp1_BBss():

    logger = getLogger('test_p1xp1_BBss')

    logger.info(
        'Symmetrised fit model with non-factorized symmetric background:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + BBsym'
    )
    sb = ROOT.RooRealVar('sb', 'SB', 2500, 0, 10000)
    model = Models.Fit2D(suffix='_5',
                         signal_x=signal1,
                         signal_y=signal2s,
                         bkg_1x=-1,
                         bkg_2D=Models.PolyPos2Dsym_pdf('P2Ds', m_x, m_y, n=1),
                         sb=sb,
                         bs=sb)

    model.SS = N_ss
    model.BB = N_bb
    model.SB = 2500

    ## fit with fixed mass and sigma
    with rooSilent(), use_canvas('test_p1xp1_BBss'):
        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)

        model.draw1(dataset)
        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)
Esempio n. 15
0
def test_pbxpb_BBs():
    logger.info(
        'Non-factorizeable background component:  ( Gauss + expo*P1 ) (x) ( Gauss + expo*P1 ) + Sym(expo*P1)**2'
    )
    model = Models.Fit2D(suffix='_8',
                         signal_1=Models.Gauss_pdf('Gx',
                                                   m_x.getMin(),
                                                   m_x.getMax(),
                                                   mass=m_x),
                         signal_2=Models.Gauss_pdf('Gy',
                                                   m_y.getMin(),
                                                   m_y.getMax(),
                                                   mass=m_y),
                         power1=1,
                         power2=1,
                         bkg2D=Models.ExpoPol2Dsym_pdf('P2D8', m_x, m_y, n=1))

    model.signal1.sigma.fix(m.error())
    model.signal2.sigma.fix(m.error())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.bkg1.tau.fix(0)
    model.bkg2.tau.fix(0)

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 16
0
def test_const():

    logger.info(
        'Simplest (factorized) fit model:  ( Gauss + const ) x ( Gauss + const ) '
    )
    model = Models.Fit2D(signal_1=Models.Gauss_pdf('Gx',
                                                   m_x.getMin(),
                                                   m_x.getMax(),
                                                   mass=m_x),
                         signal_2=Models.Gauss_pdf('Gy',
                                                   m_y.getMin(),
                                                   m_y.getMax(),
                                                   mass=m_y))

    model.signal1.sigma.fix(m.error())
    model.signal2.sigma.fix(m.error())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.signal1.mean.fix(m.value())
    model.signal2.mean.fix(m.value())
    model.bkg1.tau.fix(0)
    model.bkg2.tau.fix(0)
    model.bkgA.tau.fix(0)
    model.bkgB.tau.fix(0)

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 17
0
def test_model_14():

    logger = getLogger('test_model_14')
    logger.info(
        'Non-factorazeable background component (spline):  ( Gauss + P1 ) (x) ( Gauss + P1 ) + Spline2D'
    )
    SPLINE = Ostap.Math.PositiveSpline2D(spline1, spline1)
    model = Models.Fit2D(suffix='_14',
                         signal_x=signal1,
                         signal_y=signal2s,
                         bkg_1x=-1,
                         bkg_1y=-1,
                         bkg_2D=Models.Spline2D_pdf('P2D14',
                                                    m_x,
                                                    m_y,
                                                    spline=SPLINE))

    ## fit with fixed mass and sigma
    with rooSilent():
        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)
        result, frame = model.fitTo(dataset)
    with use_canvas('test_model_14'):
        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)
Esempio n. 18
0
def test_p1xp1_BB():

    logger = getLogger('test_p1xp1_BB')

    logger.info(
        'Simplest non-factorized fit model:  ( Gauss + P1 ) (x) ( Gauss + P1 ) + BB'
    )
    model = Models.Fit2D(suffix='_3',
                         signal_x=signal1,
                         signal_y=signal2s,
                         bkg_1x=-1,
                         bkg_1y=-1,
                         bkg_2D=Models.PolyPos2D_pdf('P2D',
                                                     m_x,
                                                     m_y,
                                                     nx=2,
                                                     ny=2))

    ## fit with fixed mass and sigma
    with rooSilent(), use_canvas('test_p1xp1_BB'):
        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)
Esempio n. 19
0
def test_comp_2dfit():

    logger.info('Test  multi-component  3d fit')

    model = Models.Fit2D(name='fit_comp',
                         signal_x=signal_x1,
                         signal_y=signal_y1,
                         bkg_1x=bkg_x,
                         bkg_1y=bkg_y,
                         components=[ss_cmp, sb_cmp, bs_cmp, bb_cmp])

    with rooSilent():
        ## components
        model.SS.fix(5000)
        model.SB.fix(500)
        model.SB.fix(500)
        model.BB.fix(1000)

        model.C[0].fix(5000)
        model.C[1].fix(500)
        model.C[2].fix(500)
        model.C[3].fix(1000)

        r = model.fitTo(dataset, ncpu=8)

        model.SS.release()
        model.SB.release()
        model.BS.release()
        model.BB.release()

        model.C[0].release()
        model.C[1].release()
        model.C[2].release()
        model.C[3].release()

        r = model.fitTo(dataset, ncpu=8)

        model.draw1(dataset, ncpu=8)
        model.draw2(dataset, ncpu=8)

    logger.info('Model %s Fit result \n#%s ' % (model.name, r))
Esempio n. 20
0
def test_model_15():

    logger.info(
        'Non-factorized symmetric background component (spline):  ( Gauss + expo*P1 ) (x) ( Gauss + expo*P1 ) + Spline2Dsym'
    )
    SPLINES = Ostap.Math.PositiveSpline2DSym(spline1)
    model = Models.Fit2D(suffix='_15',
                         signal_x=signal1,
                         signal_y=signal2s,
                         bkg_1x=-1,
                         bkg_1y=-1,
                         bkg_2D=Models.Spline2Dsym_pdf('P2D15',
                                                       m_x,
                                                       m_y,
                                                       spline=SPLINES))

    ## fit with fixed mass and sigma
    with rooSilent():
        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)
        model.draw1(dataset)
        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)
Esempio n. 21
0
def test_model_14():

    logger.info(
        'Non-factorazeable background component (spline):  ( Gauss + P1 ) (x) ( Gauss + P1 ) + Spline2D'
    )
    SPLINE = Ostap.Math.Spline2D(spline1, spline1)
    model = Models.Fit2D(suffix='_14',
                         signal_1=signal1,
                         signal_2=signal2s,
                         bkg1=-1,
                         bkg2=-1,
                         bkg2D=Models.Spline2D_pdf('P2D14',
                                                   m_x,
                                                   m_y,
                                                   spline=SPLINE))

    ## fit with fixed mass and sigma
    with rooSilent():
        result, frame = model.fitTo(dataset)
        model.signal1.sigma.release()
        model.signal2.sigma.release()
        model.signal1.mean.release()
        model.signal2.mean.release()
        result, frame = model.fitTo(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)
Esempio n. 22
0
# |  - bkg_1y          : y-background component for S(x)*B(y) term
# |  - bkg_2x          : x-background component for B(x)*B(y) term, if bkg2D is not specified
# |  - bkg_2y          : y-background component for B(x)*B(y) term, if bkg2D is not specified
# |  - bkg_2D          : PDF for 2D-background component for B(x,y)    term
# |  - sig_2D          : PDF for 2D-signal component S(x,y) term
# |  - ss              : the yield of  S(x,y)    component
# |  - sb              : the yield of  S(x)*B(y) component
# |  - bs              : the yield of  B(x)*S(y) component
# |  - bb              : the yield of  B(x,y)    component
# |  - components      : the list of other 2D-components
# |  - xvar            : the x-variable
# |  - yvar            : the y-variable
# |  - name            : the name of PDF
model_xy = Models.Fit2D(signal_x=sig_x,
                        signal_y=sig_y,
                        bkg_1x=bkg_1x,
                        bkg_1y=bkg_1y,
                        bkg_2x=bkg_2x,
                        bkg_2y=bkg_2y)
small_dh = (small_ds.reduce(ROOT.RooArgSet(im, m12), "im>0")).binnedClone()

# Fit
#r, w = model_x.fitTo( small_ds , draw=True, silent=True)
#r, w = model_y.fitTo( small_ds , draw=True, silent=True)
r, w = model_xy.fitTo(small_dh, draw=True, silent=True)
r, w = model_xy.fitTo(small_ds, draw=True, silent=True)

fx = model_xy.draw1(small_ds, nbins=90)
fx.Draw()
canvas >> "TEMP"
fy = model_xy.draw2(small_ds, nbins=50)
fy.Draw()
Esempio n. 23
0
def test_fitting_in_range_2d():

    logger = getLogger('test_fitting_in_range_2d')
    ## make simple test mass
    m_x = ROOT.RooRealVar('m_x', 'Some test mass(X)', 0, 5)
    m_y = ROOT.RooRealVar('m_y', 'Some test mass(Y)', 6, 10)

    ## book very simple data set
    varset = ROOT.RooArgSet(m_x, m_y)
    dataset = ROOT.RooDataSet(dsID(), 'Test Data set-1', varset)

    m1 = VE(3, 0.10**2)
    m2 = VE(7, 0.10**2)

    ## fill it with three gausissians, 5k events each
    N_ss = 5000
    N_sb = 1000
    N_bs = 500
    N_bb = 100

    random.seed(0)

    ## S x S
    for i in range(N_ss):
        m_x.value = m1.gauss()
        m_y.value = m2.gauss()
        dataset.add(varset)

    ## S x B
    for i in range(N_sb):
        m_x.value = m1.gauss()
        m_y.value = random.uniform(*m_y.minmax())
        dataset.add(varset)

    ## B x S
    for i in range(N_bs):
        m_x.value = random.uniform(*m_x.minmax())
        m_y.value = m2.gauss()
        dataset.add(varset)

    ## B x B
    for i in range(N_bb):
        m_x.value = random.uniform(*m_x.minmax())
        m_y.value = random.uniform(*m_y.minmax())
        dataset.add(varset)

    logger.info('Dataset:\n%s' % dataset.table(prefix='# '))

    ## various fit components
    signal_x1 = Models.Gauss_pdf('G1x',
                                 xvar=m_x,
                                 mean=m1.value(),
                                 sigma=m1.error())
    signal_y1 = Models.Gauss_pdf(name='G1y',
                                 xvar=m_y,
                                 mean=m2.value(),
                                 sigma=m2.error())

    bkg_x = make_bkg(-1, 'Bx', m_x)
    bkg_y = make_bkg(-1, name='By', xvar=m_y)

    ## build fit model
    model = Models.Fit2D(name='fit_comp',
                         signal_x=signal_x1,
                         signal_y=signal_y1,
                         bkg_1x=bkg_x,
                         bkg_1y=bkg_y)
    model.SS = N_ss
    model.SB = N_sb
    model.BS = N_bs
    model.BB = N_bb

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

    dataset.m_y.setRange('fit', 8, 10.)
    model.yvar.setRange('fit', 8, 10.)

    with use_canvas('test_fitting_in_range_2d'):
        with wait(2):
            model.draw1(dataset, nbins=200, in_range=(6, 8))
        with wait(2):
            model.draw1(dataset, nbins=200, in_range='fit')

    dataset.m_x.setRange('fit2', 0, 2.5)
    model.xvar.setRange('fit2', 0, 2.5)

    with use_canvas('test_fitting_in_range_2d'):
        with wait(2):
            model.draw2(dataset, nbins=200, in_range=(2.5, 5))
        with wait(2):
            model.draw2(dataset, nbins=200, in_range='fit2')
Esempio n. 24
0
## various fit components
signal_x1 = Models.Gauss_pdf ( 'G1x'  , xvar = m_x  , mean = m1.value() , sigma = m1.error() )  
signal_y1 = Models.Gauss_pdf ( name='G1y'  , xvar = m_y  , mean = m2.value() , sigma = m2.error()  ) 

bkg_x= make_bkg ( -1 , 'Bx' , m_x )
bkg_y= make_bkg ( -1 , name= 'By' , xvar =m_y )





model = Models.Fit2D (
        name    = 'fit_comp', 
        signal_x    = signal_x1, 
        signal_y    = signal_y1,
        bkg_1x  = bkg_x ,
        bkg_1y  = bkg_y ,
        )
with rooSilent() : 
        ## components
        model.SS.setVal ( 5000 )
        model.SB.setVal ( 1000 )
        model.BS.setVal ( 500 )
        model.BB.setVal ( 100 )

                
        r = model.fitTo ( dataset , ncpu=8 )


def draw_x() :