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() # generate data with (1 + x) / 2
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 ) ] #indices = [ ( PIndex, YIndex0, YIndex1 ) for PIndex in range(4) for YIndex0 in range(4) for YIndex1 in range( -YIndex0, YIndex0 + 1 )\ # if PIndex == 3 or YIndex0 == 3 ] #indices = [ ( 0, YIndex0, YIndex1 ) for YIndex0 in range(6) for YIndex1 in range( -YIndex0, YIndex0 + 1 ) ] #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 )
########################################################################################################################################### ## 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_' ) momPDFTerms1 = moments.buildPDFTerms( MinSignificance = 3., Names = names1, Scale = scale, CoefNamePrefix = 'C1_' )