Ejemplo n.º 1
0
def _doMinos( solver, ipar=0, ptype="u" ):
    from ConstrainedFit import clsq
    par= clsq.createClsqPar( ipar, ptype, solver )
    result= par.getParVal()
    name= par.getParName()
    ca= clsq.clsqAnalysis( solver )
    errhi, errlo= ca.minos( par )
    fmtstr= "{0:>10s}: {1:10.4f} + {2:6.4f} - {3:6.4f}"
    print fmtstr.format( name, result, errhi, abs(errlo) )
Ejemplo n.º 2
0
def _doMinos( solver, ipar=0, ptype="u" ):
    from ConstrainedFit import clsq
    par= clsq.createClsqPar( ipar, ptype, solver )
    result= par.getParVal()
    name= par.getParName()
    ca= clsq.clsqAnalysis( solver )
    errhi, errlo= ca.minos( par )
    fmtstr= "{0:>10s}: {1:10.4f} + {2:6.4f} - {3:6.4f}"
    print( fmtstr.format( name, result, errhi, abs(errlo) ) )
Ejemplo n.º 3
0
def _doProfile2d( solver, ipar1=0, type1="u", ipar2=1, type2= "m" ):
    from ConstrainedFit import clsq
    from ROOT import TGraph2D, TMarker
    from array import array
    global tg2d, hist, te1, te2, te3, tm
    par1= clsq.createClsqPar( ipar1, type1, solver )
    par2= clsq.createClsqPar( ipar2, type2, solver )
    parval1, parerr1, name1= _getUMParErrName( par1 )
    parval2, parerr2, name2= _getUMParErrName( par2 )
    print "\nChi^2 profile plot " + name1 + " - " + name2 + ":"
    corr= solver.getCorrMatrix()
    icorr1= ipar1
    icorr2= ipar2
    if type1 == "u" or type2 == "u":
        nmpar= len(solver.getMpars())
        if type1 == "u":
            icorr1= nmpar + ipar1
        if type2 == "u":
            icorr2= nmpar + ipar2
    rho= corr[icorr1,icorr2]
    te1= _makeEllipse( parval1, parval2, parerr1, parerr2, rho )
    te2= _makeEllipse( parval1, parval2, 2.0*parerr1, 2.0*parerr2, rho )
    te3= _makeEllipse( parval1, parval2, 3.0*parerr1, 3.0*parerr2, rho )
    ca= clsq.clsqAnalysis( solver )
    points= ca.profile2d( par1, par2 )
    npoints= len(points)
    tg2d= TGraph2D( npoints )
    for i in range( npoints ):
        point= points[i]
        tg2d.SetPoint( i, point[0], point[1], point[2] )
    hist= tg2d.GetHistogram()
    contourlevels= array( "d", [ 1.0, 4.0, 9.0 ] )
    hist.SetContour( 3, contourlevels )     
    xa= hist.GetXaxis()
    ya= hist.GetYaxis()
    xa.SetTitle( name1 )
    ya.SetTitle( name2 )
    hist.Draw( "cont1" )
    tm= TMarker( parval1, parval2, 20 )
    tm.Draw( "s" )
    te1.Draw( "s" )
    te2.Draw( "s" )
    te3.Draw( "s" )
    return
Ejemplo n.º 4
0
def _doProfile2d( solver, ipar1=0, type1="u", ipar2=1, type2= "m" ):
    from ConstrainedFit import clsq
    from ROOT import TGraph2D, TMarker, gPad
    from array import array
    global tg2d, hist, te1, te2, te3, tm
    par1= clsq.createClsqPar( ipar1, type1, solver )
    par2= clsq.createClsqPar( ipar2, type2, solver )
    parval1, parerr1, name1= _getUMParErrName( par1 )
    parval2, parerr2, name2= _getUMParErrName( par2 )
    print( "\nChi^2 profile plot " + name1 + " - " + name2 + ":" )
    corr= solver.getCorrMatrix()
    icorr1= ipar1
    icorr2= ipar2
    if type1 == "u" or type2 == "u":
        nmpar= len(solver.getMpars())
        if type1 == "u":
            icorr1= nmpar + ipar1
        if type2 == "u":
            icorr2= nmpar + ipar2
    rho= corr[icorr1,icorr2]
    te1= _makeEllipse( parval1, parval2, parerr1, parerr2, rho )
    te2= _makeEllipse( parval1, parval2, 2.0*parerr1, 2.0*parerr2, rho )
    te3= _makeEllipse( parval1, parval2, 3.0*parerr1, 3.0*parerr2, rho )
    ca= clsq.clsqAnalysis( solver )
    points= ca.profile2d( par1, par2 )
    npoints= len(points)
    tg2d= TGraph2D( npoints )
    for i in range( npoints ):
        point= points[i]
        tg2d.SetPoint( i, point[0], point[1], point[2] )
    hist= tg2d.GetHistogram()
    contourlevels= array( "d", [ 1.0, 4.0, 9.0 ] )
    hist.SetContour( 3, contourlevels )
    hist.GetXaxis().SetTitle( name1 )
    hist.GetYaxis().SetTitle( name2 )
    hist.SetTitle( "Triangle fit "+name2+" vs "+name1 )
    hist.Draw( "cont1" )
    tm= TMarker( parval1, parval2, 20 )
    tm.Draw( "s" )
    te1.Draw( "s" )
    te2.Draw( "s" )
    te3.Draw( "s" )
    gPad.Print( "triangle_errorellipse.png" )
    return
Ejemplo n.º 5
0
def Triangle( opt="" ):

    from ConstrainedFit import clsq
    from math import sqrt, tan

    data= [ 10.0, 7.0, 9.0, 1.0 ]
    errors= [ 0.05, 0.2, 0.2, 0.02 ]
    covm= clsq.covmFromErrors( errors )
    mpnames= { 0: "a", 1: "b", 2: "c", 3: "gamma" }

    upar= [ 30.0 ]
    upnames= { 0: "A" }

    def triangleConstrFun( mpar, upar ):
        a= mpar[0]
        b= mpar[1]
        c= mpar[2]
        gamma= mpar[3]
        aa= upar[0]
        p= (a+b+c)/2.0
        s= sqrt( p*(p-a)*(p-b)*(p-c) )
        return [ tan(gamma/2.0)-s/(p*(p-c)), aa-s ]

    solver= clsq.clsqSolver( data, covm, upar, triangleConstrFun,
                             uparnames=upnames, mparnames=mpnames )

    print( "Constraints before solution" )
    print( solver.getConstraints() )
    lBlobel= False
    lCorr= False
    lResidual= True
    if "b" in opt:
        lBlobel= True
    if "corr" in opt:
        lCorr= True
    if "r" in opt:
        lResidual= False
    solver.solve( lBlobel=lBlobel, lResidual=lResidual )
    ca= clsq.clsqAnalysis( solver )
    ca.printResults( corr=lCorr )

    if "m" in opt:
        _doMinosAll( solver )

    if "cont" in opt:
        _doProfile2d( solver, ipar1=0, type1="u", ipar2=1, type2="m" )

    print( "Profile A" )
    par= clsq.createClsqPar( 0, "u", solver )
    results= ca.profile( par )
    print( results )

    return solver
Ejemplo n.º 6
0
def Triangle( opt="" ):

    from ConstrainedFit import clsq
    from math import sqrt, tan

    data= [ 10.0, 7.0, 9.0, 1.0 ]
    errors= [ 0.05, 0.2, 0.2, 0.02 ]
    covm= clsq.covmFromErrors( errors )
    mpnames= { 0: "a", 1: "b", 2: "c", 3: "gamma" }

    upar= [ 30.0 ]
    upnames= { 0: "A" }

    def triangleConstrFun( mpar, upar ):
        a= mpar[0]
        b= mpar[1]
        c= mpar[2]
        gamma= mpar[3]
        aa= upar[0]
        p= (a+b+c)/2.0
        s= sqrt( p*(p-a)*(p-b)*(p-c) )
        return [ tan(gamma/2.0)-s/(p*(p-c)), aa-s ]

    solver= clsq.clsqSolver( data, covm, upar, triangleConstrFun,
                             uparnames=upnames, mparnames=mpnames )
    print "Constraints before solution"
    print solver.getConstraints()
    lBlobel= False
    lCorr= False
    if "b" in opt:
        lBlobel= True
    if "corr" in opt:
        lCorr= True
    solver.solve( lBlobel=lBlobel )
    ca= clsq.clsqAnalysis( solver )
    ca.printResults( corr=lCorr )

    if "m" in opt:
        _doMinosAll( solver )

    if "cont" in opt:
        _doProfile2d( solver, ipar1=0, type1="u", ipar2=1, type2="m" )

    print "Profile A"
    par= clsq.createClsqPar( 0, "u", solver )
    results= ca.profile( par )
    print results

    return solver