splitParsDict[ ws[par] ].add( ws[cat] )

# create list of split parameters and categories
from P2VV.Utilities.General import createSplitParsList
splitPars = createSplitParsList(splitParsDict)

# build simultaneous mass PDF
print 'P2VV - INFO: createBs2JpsiKKDataSet: building simultaneous PDF "%s":' % ( massPdf.GetName() + '_simul' )
print 13 * ' ' + 'split parameters:'
for it, pars in enumerate(splitPars) :
    print 13 * ' ' + '%2d: pars: [ %s ]' % ( it, ', '.join( par.GetName() for par in pars[0] ) )
    print 13 * ' ' + '    cats: [ %s ]' % ', '.join( cat.GetName() for cat in pars[1] )
from P2VV.RooFitWrappers import SimultaneousPdf
sWeightMassPdf = SimultaneousPdf(  massPdf.GetName() + '_simul'
                                 , MasterPdf       = massPdf
                                 , SplitCategories = [ pars[1] for pars in splitPars ]
                                 , SplitParameters = [ pars[0] for pars in splitPars ]
                                )
massPdfObs  = sWeightMassPdf.getObservables(preDataSet)
massPdfPars = sWeightMassPdf.getParameters(preDataSet)

if model == 'ipatia2' :
    # set values of constant Ipatia 2 parameters
    from P2VV.Utilities.General import getSplitPar
    for splitCat in sWeightMassPdf.indexCat() :
        sWeightMassPdf.indexCat().setIndex( splitCat.getVal() )
        KKState = observables['KKMassCat'].getLabel()
        for it, parName in enumerate(constSplitPars) :
            par = getSplitPar( parName, KKState, massPdfPars )
            par.setVal( constSplitVals[KKState][it] )
        # integrate over time, normalize over time + angles
        intSet.append( time if tResModel in [ 'Gauss', '3fb' ] else trueTime )
        normSet.append( intSet[-1] )

    splitCats = [ ]
    splitPars = [ ]
    if tResPars :
        splitCats.append( [ runPeriod ] )
        splitPars.append( [ ws[par] for par in tResPars.iterkeys() ] )
    if SWaveAmps :
        splitCats.append( [ KKMassCat ] )
        splitPars.append( [ ws[par] for par in SWaveAmps.iterkeys() ] )
    if splitCats :
        # split PDF for run period and KK-mass bins
        from P2VV.RooFitWrappers import SimultaneousPdf
        pdf = SimultaneousPdf( protoPdf.GetName() + '_simul', MasterPdf = protoPdf
                              , SplitCategories = splitCats, SplitParameters = splitPars )

        # set values of split parameters
        for par, vals in tResPars.iteritems() :
            for cat, val in vals.iteritems() : ws[ par + '_' + cat ].setVal(val)
        for par, vals in SWaveAmps.iteritems() :
            for cat, val in vals.iteritems() : ws[ par + '_' + cat ].setVal(val)

    else :
        pdf = protoPdf

if parFileIn :
    # read parameter values from file
    from P2VV.Parameterizations.FullPDFs import PdfConfiguration
    pdfConfig = PdfConfiguration()
    pdfConfig.readParametersFromFile( filePath = parFileIn )
Exemple #3
0
fitOpts = dict(NumCPU=4, Optimize=2, Save=True, Timer=True, Minimizer="Minuit2", Offset=True)

mass_result = mass_pdf.fitTo(data, **fitOpts)

# categories for splitting the PDF
if not options.prescaled:
    split_cats = [[excl_biased]]
    # get mass parameters that are split
    split_params = [[par for par in mass_pdf.Parameters() if par.getAttribute("Yield")]]

    # build simultaneous mass PDF
    from P2VV.RooFitWrappers import SimultaneousPdf

    sWeight_mass_pdf = SimultaneousPdf(
        mass_pdf.GetName() + "_simul", MasterPdf=mass_pdf, SplitCategories=split_cats, SplitParameters=split_params
    )

    # set yields for categories
    split_cat = sWeight_mass_pdf.indexCat()
    split_vars = sWeight_mass_pdf.getVariables()
    from P2VV.Utilities.General import getSplitPar
    from math import sqrt

    for state in split_cat:
        sigYield = getSplitPar("N_signal", state.GetName(), split_vars)
        bkgYield = getSplitPar("N_background", state.GetName(), split_vars)

        selStr = "{0} == {0}::{1}".format(split_cat.GetName(), state.GetName())

        nEv = data.sumEntries()
        splitPars.append( set( [par] ) )
        splitCats.append( splitParsDict.pop(par) )
        for par1 in pars :
            if par1 not in splitParsDict : continue
            if splitParsDict[par1] == splitCats[-1] :
                splitPars[-1].add(par1)
                splitParsDict.pop(par1)

    # build simultaneous mass PDF
    print 'P2VV - INFO: createB2CCFitNTuple: building simultaneous PDF "%s":' % ( massPdf.GetName() + '_simul' )
    print 13 * ' ' + 'splitting categories: [ %s ]' % ' ], [ '.join(', '.join(cat.GetName() for cat in cats) for cats in splitCats)
    print 13 * ' ' + 'split parameters:     [ %s ]' % ' ], [ '.join(', '.join(par.GetName() for par in pars) for pars in splitPars)
    from P2VV.RooFitWrappers import SimultaneousPdf
    sWeightMassPdf = SimultaneousPdf(  massPdf.GetName() + '_simul'
                                     , MasterPdf       = massPdf
                                     , SplitCategories = splitCats
                                     , SplitParameters = splitPars
                                    )

    # set yields for categories
    splitCat      = sWeightMassPdf.indexCat()
    splitCatIter  = splitCat.typeIterator()
    splitCatState = splitCatIter.Next()
    massPdfPars   = sWeightMassPdf.getVariables()
    from P2VV.Utilities.General import getSplitPar
    from math import sqrt
    while splitCatState :
        KKMassState = -1
        if splitCat.isFundamental() :
            selStr = '!(%s-%d)' % ( splitCat.GetName(), splitCatState.getVal() )
            if splitCat.GetName() == observables['KKMassCat'].GetName() : KKMassState = splitCatState.getVal()
            splitParsDict[ ws[par] ].add( ws[cat] )

# create list of split parameters and categories
from P2VV.Utilities.General import createSplitParsList
splitPars = createSplitParsList(splitParsDict)

# build simultaneous mass PDF
print 'P2VV - INFO: splitDataSetSigBkg: building simultaneous PDF "%s":' % ( massPdf.GetName() + '_simul' )
print 13 * ' ' + 'split parameters:'
for it, pars in enumerate(splitPars) :
    print 13 * ' ' + '%2d: pars: [ %s ]' % ( it, ', '.join( par.GetName() for par in pars[0] ) )
    print 13 * ' ' + '    cats: [ %s ]' % ', '.join( cat.GetName() for cat in pars[1] )
from P2VV.RooFitWrappers import SimultaneousPdf
simMassPdf = SimultaneousPdf(  massPdf.GetName() + '_simul'
                             , MasterPdf       = massPdf
                             , SplitCategories = [ pars[1] for pars in splitPars ]
                             , SplitParameters = [ pars[0] for pars in splitPars ]
                            )
massPdfObs  = simMassPdf.getObservables(dataSet)
massPdfPars = simMassPdf.getParameters(dataSet)

# create PDF configuration object
from P2VV.Parameterizations.FullPDFs import PdfConfiguration as PdfConfig
pdfConfig = PdfConfig()

# read parameters from file
print 120 * '='
pdfConfig.readParametersFromFile( filePath = args.parFilePathIn )
pdfConfig.setParametersInPdf(simMassPdf)
print 'P2VV - INFO: splitDataSetSigBkg: observables in mass PDF:'
massPdfObs.Print('v')