## 0) The weighter object weighter = Weight(dbname, weightings) # ========================================================================= ## 1a) create new "weighted" mcdataset mcds = mcds_.Clone() with timing('Add weight to MC-dataset', logger=logger): ## 1b) add "weight" variable to dataset mcds.add_reweighting(weighter, name='weight') logger.info('MCDATA:\n%s' % mcds) # ========================================================================= ## 2) update weights plots = [WeightingPlot('y:x', 'weight', '2D-reweight', hdata, hmc)] if 2 < iter: plots = [ WeightingPlot('x', 'weight', 'x-reweight', hxdata, hmcx), WeightingPlot('y', 'weight', 'y-reweight', hydata, hmcy), WeightingPlot('y:x', 'weight', '2D-reweight', hdata, hmc, 0.99), ] with timing('Make one reweighting iteration:', logger=logger): # ========================================================================= ## 2a) the most important line: perform single iteration step more = makeWeights( mcds, ## what to be reweighted plots, ## reweighting plots/setup dbname, ## DBASE with reweigting constant delta=0.04, ## stopping criteria
Variable('weight', 'weight', accessor=weighter) ] # ## create new "weighted" mcdataset # selector = SelectorWithVars(variables, '0<x && x<100 ') mctree.pprocess(selector, chunk_size=len(mctree) // 20) ##mctree.process ( selector ) mcds = selector.data ## new reweighted dataset # ## update weights # plots = [WeightingPlot('x', 'weight', 'x-reweight', hdata, hmc)] more = makeWeights(mcds, plots, dbname, delta=0.001) ## make MC-histogram mcds.project(hmc, 'x', 'weight') logger.info('Compare DATA and MC for iteration #%d' % iter) # ## compare the basic properties: mean, rms, skewness and kurtosis # hdata.cmp_prnt(hmc, 'DATA', 'MC', 'DATA vs MC') # ## calculate the distances # dist = hdata.cmp_dist(hmc, density=True)
# ## create new "weighted" mcdataset # selector = SelectorWithVars ( variables , '0<x && x<100 ' ) mctree.process ( selector ) mcds = selector.data ## new reweighted dataset # ## update weights # plots = [ WeightingPlot( 'pt_x' , 'weight' , 'x-reweight' , hdata , hmc ) ] more = makeWeights ( mcds , plots , dbname , delta = 0.001 ) ## make MC-histogram mcds .project ( hmc , 'pt_x' , 'weight' ) logger.info ( 'Compare DATA and MC for iteration #%d' % iter ) # ## compare the basic properties: mean, rms, skewness and kurtosis # hdata.cmp_prnt ( hmc , 'DATA' , 'MC' , 'DATA vs MC' ) # ## calculate the distances #
## 0) The weighter object weighter = Weight(dbname, weightings) # ========================================================================= ## 1a) create new "weighted" mcdataset mcds = mcds_.Clone() with timing(tag + ': add weight to MC-dataset', logger=logger): ## 1b) add "weight" variable to dataset mcds.add_reweighting(weighter, name='weight') if 1 == iter % 10: logger.info((tag + ' MCDATA:\n%s') % mcds) # ========================================================================= ## 2) update weights plots = [ WeightingPlot('x', 'weight', 'x-reweight', hxdata, hmcx), WeightingPlot('y', 'weight', 'y-reweight', hydata, hmcy), WeightingPlot('y:x', 'weight', '2D-reweight', hdata, hmc), ] if iter <= 3: power = 0.75 elif iter <= 10: power = lambda nactive: 1.5 / nactive if 1 < nactive else 0.90 elif iter <= 15: power = lambda nactive: 1.3 / nactive if 1 < nactive else 0.90 else: power = lambda nactive: 1.1 / nactive if 1 < nactive else 0.90 with timing(tag + ': make actual reweighting:', logger=logger): # =========================================================================