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 )
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 ) ) else : from P2VV.RooFitWrappers import RealMoment physMoments = RealMomentsBuilder( Moments = ( RealMoment( Name = func.GetName(), BasisFunc = func, Norm = 1. )\ for complexFunc in angleFuncs.functions.itervalues() for func in complexFunc if func ) ) physMoments.initCovariances() # moments builder with angular basis functions 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 ) ]
ws.factory('Legendre::one(x,0,0)') # 1 ws.factory('Legendre::cos(x,1,0)') # x = cos(theta) ws.factory('prod::sin(minus[-1.],Legendre::P11(x,1,1))') # sqrt(1 - x^2) = sin(theta) ws.factory('prod::sin2(min23[0.],Legendre::P21(x,2,1))') # 2x * sqrt(1 - x^2) = sin(2*theta) ws['min23'].setVal( -2. / 3. ) # create data sets from ROOT import RooDataSet noWeightData = RooDataSet( 'noWeightData', 'noWeightData', obsSet ) weightData = RooDataSet( 'weightData', 'weightData', obsWSet, 'weight' ) # build moments builders from P2VV.Utilities.DataMoments import RealMomentsBuilder from P2VV.RooFitWrappers import RealMoment moms = RealMomentsBuilder( Moments = [ RealMoment( Name = ws[func].GetName(), BasisFunc = ws[func], Norm = 1. ) for func in funcNames ] ) momsW = RealMomentsBuilder( Moments = [ RealMoment( Name = ws[func].GetName(), BasisFunc = ws[func], Norm = 1. ) for func in funcNames ] ) moms.initCovariances() momsW.initCovariances() # initialize variables for calculation of covariances covs = dict( [ ( name1, dict( [ ( name2, 0. ) for name2 in funcNames ] ) ) for name1 in funcNames ] ) covsW = dict( [ ( name1, dict( [ ( name2, 0. ) for name2 in funcNames ] ) ) for name1 in funcNames ] ) # generate data and compute moments in loop import sys from ROOT import RooRandom for it in range(nIters) : if it % 100 == 0 : print 'iteration %d' % it sys.stdout.flush()
pdf.fitTo( data, **fitOpts ) ########################################################################################################################################### ## compute angular moments and build moments PDFs ## #################################################### # 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_' )
########################################################################################################################################### ## compute angular moments and build moments PDFs ## #################################################### # build angular moment basis functions indices = [ ( PIndex, YIndex0, YIndex1 ) for PIndex in range(3) for YIndex0 in range(3) for YIndex1 in range( -YIndex0, YIndex0 + 1 ) ] #indices += [ ( PIndex, 2, YIndex1 ) for PIndex in range( 3, 10 ) for YIndex1 in [ -2, 1 ] ] # construct moment names strings names0 = 'p2vvab_00..' names1 = names0 + '|p2vvab_10..' names2 = names1 + '|p2vvab_20..' from P2VV.Utilities.DataMoments import RealMomentsBuilder moments = RealMomentsBuilder() moments.appendPYList( angleFuncs.angles, indices ) if computeMoments : # 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 )
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 physPdf : from P2VV.RooFitWrappers import RealEffMoment physMoments = RealMomentsBuilder( Moments = ( RealEffMoment( Name = func.GetName(), BasisFunc = func, Norm = 1., PDF = pdf, IntSet = [ ], NormSet = angles )\ for complexFunc in angleFuncs.functions.itervalues() for func in complexFunc if func ) ) else : from P2VV.RooFitWrappers import RealMoment physMoments = RealMomentsBuilder( Moments = ( RealMoment( Name = func.GetName(), BasisFunc = func, Norm = 1. )\ for complexFunc in angleFuncs.functions.itervalues() for func in complexFunc if func ) ) physMoments.initCovariances() # moments builder with angular basis functions 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 ) ]
angleFuncs = AngleFuncs( cpsi = 'trcospsi', ctheta = 'trcostheta', phi = 'trphi' ) else : from P2VV.Parameterizations.AngularFunctions import JpsiphiHelicityAngles as AngleFuncs angleFuncs = AngleFuncs( cpsi = 'helcosthetaK', ctheta = 'helcosthetaL', phi = 'helphi' ) angles = [ angleFuncs.angles[ang] for ang in [ 'cpsi', 'ctheta', 'phi' ] ] from P2VV.Utilities.DataMoments import RealMomentsBuilder from math import sqrt, pi indices = [ ( PIndex, YIndex0, YIndex1 ) for PIndex in range(6) for YIndex0 in range(6)\ 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
KKmomentaReweight.reweight( iterNumb, source() ) KmomentaWeightsName = 'hor' + KmomentaWeightsName mcDataMngr.setDataSet( KKmomentaReweight.getDataSet(), KmomentaWeightsName ) # compute angular efficiency moments from the new reweighted mc dataset. # set data pars to pdf (reweighted data has the data physics now) if KKmomWeightsOnly: PhysicsReweight.setMonteCarloParameters() else: 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