print '\nData set:'
data.Print()

if normPdf :
    print '\nPDF:'
    pdf.Print()
    print '\nIntegration set for PDF:'
    for var in intSet : print var.GetName(),
    print '\n\nNormalization set for PDF:'
    for var in normSet : print var.GetName(),
    print '\n\nLifetime resolution model:'
    timeResModel['model'].Print()
    print '\nVariables in PDF:'
    for var in pdf.getObservables(data) : var.Print()
    print '\nParameters in PDF:'
    for par in pdf.getParameters(data) : par.Print()
    print

else :
    print '\nUsing uniform angular PDF'
    print

# moments builder with angular functions from physics PDF
from P2VV.Utilities.DataMoments import RealMomentsBuilder
if normPdf :
    from P2VV.RooFitWrappers import RealEffMoment
    physMoments = RealMomentsBuilder( Moments = ( RealEffMoment( Name = func.GetName(), BasisFunc = func,Norm = 1., PDF = pdf
                                                                , IntSet = intSet, NormSet = normSet )\
                                                  for complexFunc in angleFuncs.functions.itervalues() for func in complexFunc if func
                                                )
                                    )
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] )

if parFileIn or parFileOut :
    # create PDF configuration object
    from P2VV.Parameterizations.FullPDFs import PdfConfiguration as PdfConfig
    pdfConfig = PdfConfig()
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')
print 'P2VV - INFO: splitDataSetSigBkg: parameters in mass PDF:'
massPdfPars.Print('v')