Exemplo n.º 1
0
    print 'converting dataset to n-tuple'
    from ROOT import TFile, TObject
    dataFile = TFile.Open( dataSetFile, 'RECREATE' )
    nTuple = data.buildTree( Name = nTupleName, Title = nTupleName, WeightName = weightVar, RooFitFormat = False )
    print 'writing n-tuple to file %s' % dataSetFile
    dataFile.Write( dataSetFile, TObject.kOverwrite )
    dataFile.Close()


###########################################################################################################################################
## make some plots ##
#####################

if makePlots and normPdf :
    # build efficiency function
    effTerms = basisMoments.buildPDFTerms()
    effFunc = effTerms.buildAddition('effFunc')

    from ROOT import RooArgSet
    ctkSet = RooArgSet( angles[1], angles[2] )
    ctlSet = RooArgSet( angles[0], angles[2] )
    phiSet = RooArgSet( angles[0], angles[1] )
    effFuncCtk = effFunc.createIntegral( ctkSet, RooArgSet() )
    effFuncCtl = effFunc.createIntegral( ctlSet, RooArgSet() )
    effFuncPhi = effFunc.createIntegral( phiSet, RooArgSet() )

    # import plotting tools
    from P2VV.Load import LHCbStyle
    from P2VV.Utilities.Plotting import plot
    from ROOT import TCanvas, kBlue, kRed, kGreen
Exemplo n.º 2
0
    # compute moments from data set
    moments.compute(data)
    moments.write(momentsFile, Scale = scale)

else :
    # read moments from file
    moments.read(momentsFile)

# print moments to screen
moments.Print( Scale = scale, MinSignificance = 3., Names = names0 )
moments.Print( Scale = scale, MinSignificance = 3., Names = names1 )
moments.Print( Scale = scale, MinSignificance = 3., Names = names2 )
moments.Print( Scale = scale, MinSignificance = 0.                 )

# build new PDFs with angular moments
momPDFTerms0 = moments.buildPDFTerms(MinSignificance = 3., Names = names0, Scale = scale, CoefNamePrefix = 'C0_')
momPDFTerms1 = moments.buildPDFTerms(MinSignificance = 3., Names = names1, Scale = scale, CoefNamePrefix = 'C1_')
momPDFTerms2 = moments.buildPDFTerms(MinSignificance = 3., Names = names2, Scale = scale, CoefNamePrefix = 'C2_')
momPDFTerms  = moments.buildPDFTerms(MinSignificance = 0.                , Scale = scale                        , RangeNumStdDevs = 5.)

momPDF0 = momPDFTerms0.buildSumPdf('angMomentsPDF0')
momPDF1 = momPDFTerms1.buildSumPdf('angMomentsPDF1')
momPDF2 = momPDFTerms2.buildSumPdf('angMomentsPDF2')
momPDF  = momPDFTerms.buildSumPdf('angMomentsPDF')

#for event in range( data.numEntries() ) :
#    varSet = data.get(event)
#    angles[0].setVal( varSet.getRealValue('cthetaK') )
#    angles[1].setVal( varSet.getRealValue('cthetal') )
#    angles[2].setVal( varSet.getRealValue('phi') )
#    if momPDF.getVal() < 0. : print angles[0].getVal(), angles[1].getVal(), angles[2].getVal(), momPDF.getVal()
Exemplo n.º 3
0
from P2VV.Utilities.DataMoments import RealMomentsBuilder
moments = RealMomentsBuilder()
moments.appendPYList( angleFuncs.angles, indices )
moments.initCovariances()

# compute moments from data set
moments.compute(data)
moments.write( momentsFile, Scale = scale )

# print moments to screen
moments.Print( Scale = scale, MinSignificance = 3.                 )
moments.Print( Scale = scale, MinSignificance = 3., Names = names0 )
moments.Print( Scale = scale, MinSignificance = 3., Names = names1 )

# build new PDFs with angular moments
momPDFTerms  = moments.buildPDFTerms( MinSignificance = 0.                , Scale = scale                        , RangeNumStdDevs = 5. )
momPDFTerms0 = moments.buildPDFTerms( MinSignificance = 3., Names = names0, Scale = scale, CoefNamePrefix = 'C0_'                       )
momPDFTerms1 = moments.buildPDFTerms( MinSignificance = 3., Names = names1, Scale = scale, CoefNamePrefix = 'C1_'                       )

momPDF  = momPDFTerms.buildSumPdf('angMomentsPDF')
momPDF0 = momPDFTerms0.buildSumPdf('angMomentsPDF0')
momPDF1 = momPDFTerms1.buildSumPdf('angMomentsPDF1')

if fitDataMoments :
    # fit angular moments PDF to data
    momPDF.fitTo( data, **fitOpts )


###########################################################################################################################################
## build a PDF from angular basis functions and do a fit ##
###########################################################
Exemplo n.º 4
0
                                          for YIndex1 in range( -YIndex0, YIndex0 + 1 ) ]
#indices  = [ ( PIndex, YIndex0, 0 ) for PIndex in range(5) for YIndex0 in range(5) ]
#indices  = [ ( PIndex, YIndex0, YIndex1 ) for PIndex in range(3) for YIndex0 in range(3)\
#                                          for YIndex1 in range( -YIndex0, YIndex0 + 1 ) ]
#indices += [ ( 0, 4, 0 ), ( 0, 4, 2 ), ( 0, 4, 4 ) ]
moments = RealMomentsBuilder()
moments.appendPYList( angleFuncs.angles, indices )
for file, fac in zip( momentsFiles, addFactors ) :
    moments.read( file, AddMoments = fac )
moments.Print(  Scale = 1. / 2. / sqrt(pi)
              , Names = '|'.join( 'p2vvab_%d0%d%s%d' % ( moms[0], moms[1], 'm' if moms[2] < 0 else '', moms[2] ) for moms in signMoms )
             )
moments.Print( Scale = 1. / 2. / sqrt(pi), MinSignificance = 2.5 )

momFuncTerms = moments.buildPDFTerms( CoefNamePrefix = 'transC_' if transAngles else 'helC_'
                                     , Names = '|'.join( 'p2vvab_%d0%d%s%d' % ( moms[0], moms[1], 'm' if moms[2] < 0 else '', moms[2] )\
                                                        for moms in signMoms )
                                    )
momFunc = momFuncTerms.buildAddition( 'efficiency' + ( 'Trans' if transAngles else 'Hel' ) )

# create efficiency functions with alternative angular values for slices
from ROOT import RooRealVar, RooCustomizer
angles1 = [ RooRealVar(ang._var) for ang in angles ]
angles2 = [ RooRealVar(ang._var) for ang in angles ]
momFuncCust1 = RooCustomizer( momFunc._var, '_1' )
momFuncCust2 = RooCustomizer( momFunc._var, '_2' )
for ang, ang1, ang2 in zip( angles, angles1, angles2 ) :
    momFuncCust1.replaceArg( ang._var, ang1 )
    momFuncCust2.replaceArg( ang._var, ang2 )
momFunc1 = momFuncCust1.build()
momFunc2 = momFuncCust2.build()