Exemple #1
0
 def pdf(self, **kwargs ) :
     from P2VV.Utilities.DataMoments import RealMomentsBuilder
     mb = RealMomentsBuilder()
     mb.appendPYList( self._angles, kwargs.pop('Indices') )
     mb.compute( self._splot.data( kwargs.pop('Component') ) )
     if kwargs.pop('Verbose',False) : 
         mb.Print()
         print 'computed moments, creating PDF with name %s' % kwargs['Name']
     return mb.createPDF( **kwargs )
#indices = [ ( PIndex, 2, YIndex1 ) for PIndex in range(40) for YIndex1 in [ +1, -1 ] ]

basisMoments = RealMomentsBuilder()
if normPdf :
    basisMoments.appendPYList( angleFuncs.angles, indices, PDF = pdf, IntSet = intSet, NormSet = normSet )
else :
    basisMoments.appendPYList( angleFuncs.angles, indices )

PDFInt = 1. if normPdf else 8. * pi
if readMoments :
    # read moments from file
    physMoments.read(  momentsFile + '_Phys'  )
    basisMoments.read( momentsFile + '_Basis' )
else :
    # compute moments from data set
    physMoments.compute(data)
    basisMoments.compute(data)

    physMoments.write(  momentsFile + '_Phys',  Scale = PDFInt / 16. / sqrt(pi) )
    basisMoments.write( momentsFile + '_Basis', Scale = PDFInt                  )

# print moments to screen
physMoments.Print(  Scale = PDFInt / 16. / sqrt(pi)                       )
physMoments.convertEffWeightsToMoments( OutputFilePath = momentsFile + '_Basis_weights', Scale = PDFInt / 16. / sqrt(pi) )
basisMoments.Print( Scale = PDFInt /  2. / sqrt(pi)                       )
basisMoments.Print( Scale = PDFInt /  2. / sqrt(pi), MinSignificance = 5. )


###########################################################################################################################################
## add efficiency weights column to data set ##
###############################################
####################################################

# build angular moment basis functions
indices  = [ ( PIndex, YIndex0, YIndex1 ) for PIndex in range(4) for YIndex0 in range(3) for YIndex1 in range( -YIndex0, YIndex0 + 1 ) ]

# construct moment names strings
names0 = 'p2vvab_0000'
names1 = names0 + '|p2vvab_001.|p2vvab_100.|p2vvab_101.'

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')
Exemple #4
0
        print 'iteration %d' % it
        sys.stdout.flush()

    # generate data with (1 + x) / 2
    RooRandom.randomGenerator().SetSeed( 100000 + it )
    noWeightData.reset()
    weightData.reset()
    for evIt in range(nEvents) :
        weight = RooRandom.uniform()
        obs.setVal( 2. * weight - 1. )
        if RooRandom.uniform() <= weight :
            noWeightData.add(obsSet)
        weightData.add( obsSet, weight )

    # compute moments of functions
    moms.compute(  noWeightData, ResetFirst = True, Verbose = False )
    momsW.compute( weightData,   ResetFirst = True, Verbose = False )

    # update covariance sums
    momCoefs  = moms.coefficients()
    momCoefsW = momsW.coefficients()
    for name1 in funcNames :
        for name2 in funcNames :
            covs[name1][name2]  += ( momCoefs[name1][0]  - funcMeans[name1] ) * ( momCoefs[name2][0]  - funcMeans[name2] )
            covsW[name1][name2] += ( momCoefsW[name1][0] - funcMeans[name1] ) * ( momCoefsW[name2][0] - funcMeans[name2] )

# divide covariance sums by number of entries to get covariances
for name1 in funcNames :
    for name2 in funcNames :
        covs[name1][name2]  /= float(nIters)
        covsW[name1][name2] /= float(nIters)
Exemple #5
0
    if reweightPhysics: PhysicsReweight.setDataFitParameters(dataParameters) 
    else:               PhysicsReweight.setMonteCarloParameters()

physMoments = RealMomentsBuilder( Moments = ( RealEffMoment( Name = func.GetName(), 
                                                             BasisFunc = func,
                                                             Norm      = 1., 
                                                             PDF       = PhysicsReweight.getPdf(), 
                                                             IntSet    = [],
                                                             NormSet   = angles
                                                             )\
       for complexFunc in PhysicsReweight.getAngleFunctions().functions.itervalues() for func in complexFunc if func )
                                  )
  
scaleFactor = 1 / 16. / sqrt(pi)
physMoments.initCovariances()
physMoments.compute(mcDataMngr.getDataSet()) 
physMoments.write( 'Sim08_{0}_{1}_Phys_{2}'.format(MCProd,outputEffMomentsBaselineName,iterNumb), Scale=scaleFactor )

# normalize effciency moments
normalizeMoments( 'Sim08_{0}_{1}_Phys_{2}'.format(MCProd,outputEffMomentsBaselineName,iterNumb),
                  'Sim08_{0}_{1}_Phys_norm_{2}'.format(MCProd,outputEffMomentsBaselineName,iterNumb),
                  normMoment = PhysicsReweight.getParNamePrefix() + '_Re_ang_A0_A0',
                  printMoms  = delIntermediateMoms
                  )
if delIntermediateMoms: os.remove('Sim08_{0}_{1}_Phys_{2}'.format(MCProd,outputEffMomentsBaselineName,iterNumb) )

# combine 2011, 2012 acceptances
if combineEffMoments:
    angAcc2011  = 'Sim08_2011_%s_Phys_norm_%s'%(outputEffMomentsBaselineName,iterNumb) 
    angAcc2012  = 'Sim08_2012_%s_Phys_norm_%s'%(outputEffMomentsBaselineName,iterNumb) 
    combAccName = 'Sim08_20112012_{0}_Phys_norm_{1}'.format(outputEffMomentsBaselineName,iterNumb)