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 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] )