maxN = 5 if options.small else -1 exec('allSamples=[' + options.allSamples + ']') chunks, sumWeight = [], 0. allData = False not in [s.isData for s in allSamples] allMC = True not in [s.isData for s in allSamples] assert allData or len(set([ s.xSection for s in allSamples ])) == 1, "Not all samples have the same xSection: %s !" % (",".join( [s.name for s in allSamples])) assert allMC or len(allSamples) == 1, "Don't concatenate data samples" if allMC: puRW = getReweightingFunction(data="PU_2100_XSecCentral", mc="Spring15") puRWDown = getReweightingFunction(data="PU_2100_XSecDown", mc="Spring15") puRWUp = getReweightingFunction(data="PU_2100_XSecUp", mc="Spring15") assert False not in [ hasattr(s, 'path') for s in allSamples ], "Not all samples have a path: " + ", ".join([s.name for s in allSamples]) for i, s in enumerate(allSamples): tchunks, tsumWeight = getChunks(s, maxN=maxN) chunks += tchunks sumWeight += tsumWeight print "Now %i chunks from sample %s with sumWeight now %f" % ( len(chunks), s.name, sumWeight) sample = allSamples[0]
from math import cos,sin,sqrt,cosh,pi import os, copy, sys import itertools small = False from StopsDilepton.samples.cmgTuples_Spring15_50ns_postProcessed import * from StopsDilepton.samples.cmgTuples_Spring15_25ns_postProcessed import * from StopsDilepton.samples.cmgTuples_Data50ns_1l_postProcessed import * from StopsDilepton.samples.cmgTuples_Data25ns_postProcessed import * from StopsDilepton.tools.objectSelection import getLeptons, getMuons, getElectrons, getGoodMuons, getGoodElectrons, getGoodLeptons, mZ from StopsDilepton.tools.helpers import getVarValue, getYieldFromChain, getChain from StopsDilepton.tools.localInfo import plotDir from simplePlotHelpers import plot, stack, loopAndFill, drawNMStacks from StopsDilepton.tools.puReweighting import getReweightingFunction puReweightingFunc = getReweightingFunction(era="Run2015D_205pb") #puReweightingFunc = getReweightingFunction(era="Run2015D_205pb_doubleMu_onZ_isOS") puReweighting = lambda c:puReweightingFunc(getVarValue(c, "nVert")) cutBranches = ["weight", "leptonPt", "met*", "nVert",\ 'Jet_pt', "Jet_id", "Jet_eta", "Jet_phi", "Jet_btagCSV", "LepGood_pdgId", "LepGood_mediumMuonId", "LepGood_miniRelIso", "LepGood_sip3d", "LepGood_dxy", "LepGood_dz", "LepGood_convVeto", "LepGood_lostHits", "Flag_HBHENoiseFilter", "Flag_HBHENoiseIsoFilter", "Flag_HBHENoiseFilterMinZeroPatched", "Flag_goodVertices", "Flag_CSCTightHaloFilter", "Flag_eeBadScFilter", "HLT_mumuIso", "HLT_ee_DZ", "HLT_mue", "is*","dl_*","l1_*","l2_*", "nGoodMuons", "nGoodElectrons" ] subdir = "png25ns_2l" #preprefixes = ["PUDoubleMuOnZIsOS"] preprefixes = [] def getZCut(mode):
if len(samples)>1: sample_name = samples[0].name+"_comb" logger.info( "Combining samples %s to %s.", ",".join(s.name for s in samples), sample_name ) sample = Sample.combine(sample_name, samples, maxN = maxN) # Clean up for s in samples: sample.clear() elif len(samples)==1: sample = samples[0] else: raise ValueError( "Need at least one sample. Got %r",samples ) lumiScaleFactor = xSection*targetLumi/float(sample.normalization) if xSection is not None else None from StopsDilepton.tools.puReweighting import getReweightingFunction puRW = getReweightingFunction(data="PU_2100_XSecCentral", mc="Fall15") puRWDown = getReweightingFunction(data="PU_2100_XSecDown", mc="Fall15") puRWUp = getReweightingFunction(data="PU_2100_XSecUp", mc="Fall15") # output directory outDir = os.path.join(options.targetDir, options.processingEra, "gen", sample.name) if os.path.exists(outDir) and options.overwrite: if options.nJobs > 1: logger.warning( "NOT removing directory %s because nJobs = %i", outDir, options.nJobs ) else: logger.info( "Output directory %s exists. Deleting.", outDir ) shutil.rmtree(outDir) try: #Avoid trouble with race conditions in multithreading
from StopsDilepton.tools.puReweighting import getReweightingFunction #Get the PU reweighting function era = "Run2015D_205pb" puReweightingFunc = getReweightingFunction(era=era) n=17 w=puReweightingFunc(n) print "Found %i vertices, reweighting according to %s is %f"%(n,era,w)