Esempio n. 1
0
    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]
if len(allSamples) > 1:
    sample.name = sample.name + '_comb'

doTopPtReweighting = sample.name.startswith(
    "TTJets") or sample.name.startswith("TTLep")
if doTopPtReweighting:
    print "Sample %s will have top pt reweights!" % sample.name
topPtReweightingFunc = getUnscaledTopPairPtReweightungFunction(
) if doTopPtReweighting else None
Esempio n. 2
0
    for etaBin in etaBins:
      mceff[tuple(ptBin)][tuple(etaBin)] = {}
      etaCut = "abs(Jet_eta)>"+str(etaBin[0])+"&&abs(Jet_eta)<"+str(etaBin[1])
      ptCut = "abs(Jet_pt)>"+str(ptBin[0])
      if ptBin[1]>0:
        ptCut += "&&abs(Jet_pt)<"+str(ptBin[1])
      c.Draw("(Jet_btagCSV>0.890)>>hbQuark(100,-1,2)",cut+"&&Jet_id>0&&abs(Jet_hadronFlavour)==5&&                     "+etaCut+"&&"+ptCut)
      c.Draw("(Jet_btagCSV>0.890)>>hcQuark(100,-1,2)",cut+"&&Jet_id>0&&abs(Jet_hadronFlavour)==4&&                     "+etaCut+"&&"+ptCut)
      c.Draw("(Jet_btagCSV>0.890)>>hOther(100,-1,2)" ,cut+"&&Jet_id>0&&(abs(Jet_hadronFlavour) < 4  || abs(Jet_hadronFlavour) > 5)&&  "+etaCut+"&&"+ptCut)
      hbQuark = ROOT.gDirectory.Get("hbQuark")
      hcQuark = ROOT.gDirectory.Get("hcQuark")
      hOther = ROOT.gDirectory.Get("hOther")
      mceff[tuple(ptBin)][tuple(etaBin)]["b"]     = hbQuark.GetMean()
      mceff[tuple(ptBin)][tuple(etaBin)]["c"]     = hcQuark.GetMean()
      mceff[tuple(ptBin)][tuple(etaBin)]["other"] = hOther.GetMean()
      print "Eta",etaBin,etaCut,"Pt",ptBin,ptCut,"Found b/c/other", mceff[tuple(ptBin)][tuple(etaBin)]["b"], mceff[tuple(ptBin)][tuple(etaBin)]["c"], mceff[tuple(ptBin)][tuple(etaBin)]["other"]
      del hbQuark, hcQuark, hOther
  return mceff

#for sample in [TTJets, TTJets_Lep]:
#for sample in [ TTJets_DiLepton, TTJets]:
c = getChain(getChunks(TTJets_DiLepton)[0] + getChunks(TTJets_DiLepton_ext)[0], treeName="tree")
res=  getBTagMCTruthEfficiencies(c, 
  cut="(Sum$(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id))>=2&&Sum$(LepGood_pt>20&&abs(LepGood_eta)<2.4)>=2"
)
print "Efficiencies:"
print res
pickle.dump(res, \
  file(os.path.expandvars('$CMSSW_BASE/src/StopsDilepton/tools/data/btagEfficiencyData/TTJets_DiLepton_comb_2j_2l.pkl'), 'w')
)
Esempio n. 3
0
                "(Jet_btagCSV>0.890)>>hOther(100,-1,2)", cut +
                "&&Jet_id>0&&(abs(Jet_hadronFlavour) < 4  || abs(Jet_hadronFlavour) > 5)&&  "
                + etaCut + "&&" + ptCut)
            hbQuark = ROOT.gDirectory.Get("hbQuark")
            hcQuark = ROOT.gDirectory.Get("hcQuark")
            hOther = ROOT.gDirectory.Get("hOther")
            mceff[tuple(ptBin)][tuple(etaBin)]["b"] = hbQuark.GetMean()
            mceff[tuple(ptBin)][tuple(etaBin)]["c"] = hcQuark.GetMean()
            mceff[tuple(ptBin)][tuple(etaBin)]["other"] = hOther.GetMean()
            print "Eta", etaBin, etaCut, "Pt", ptBin, ptCut, "Found b/c/other", mceff[
                tuple(ptBin)][tuple(etaBin)]["b"], mceff[tuple(ptBin)][tuple(
                    etaBin)]["c"], mceff[tuple(ptBin)][tuple(etaBin)]["other"]
            del hbQuark, hcQuark, hOther
    return mceff


#for sample in [TTJets, TTJets_Lep]:
#for sample in [ TTJets_DiLepton, TTJets]:
c = getChain(getChunks(TTJets_DiLepton)[0] + getChunks(TTJets_DiLepton_ext)[0],
             treeName="tree")
res = getBTagMCTruthEfficiencies(
    c,
    cut=
    "(Sum$(Jet_pt>30&&abs(Jet_eta)<2.4&&Jet_id))>=2&&Sum$(LepGood_pt>20&&abs(LepGood_eta)<2.4)>=2"
)
print "Efficiencies:"
print res
pickle.dump(res, \
    file(os.path.expandvars('$CMSSW_BASE/src/StopsDilepton/tools/data/btagEfficiencyData/TTJets_DiLepton_comb_2j_2l.pkl'), 'w')
            )
Esempio n. 4
0
import ROOT
from StopsDilepton.samples.cmgTuples_Spring15_mAODv2_25ns_1l import *
from StopsDilepton.tools.helpers import getChain, getYieldFromChain, getEList, getChunks, closestOSDLMassToMZ, mZ, deltaR, getObjFromFile
from StopsDilepton.tools.objectSelection import getLeptons, getOtherLeptons, leptonVars, getGoodJets
from math import sqrt

sample = TTZToLLNuNu

c = ROOT.TChain('tree')
chunks, sumWeight = getChunks(TTZToLLNuNu)
for chunk in chunks:
    c.Add(chunk['file'])

targetLumi = 2100
lumiScaleFactor = sample.xSection * targetLumi / float(sumWeight)

preselection = "Sum$(Jet_pt>30&&abs(Jet_eta)<2.5)>=3"
postfix = "corrSys_Q2PDFshape"
maxN = None

Muon_mediumMuonId = 1
Muon_relIso03 = 0.1
Muon_sip3d = 4.0
Muon_dxy = 0.05
Muon_dz = 0.1


def looseMuID(l, ptCut=10, absEtaCut=2.4):
    return \
        l["pt"]>=ptCut\
        and abs(l["pdgId"])==13\
Esempio n. 5
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]
if len(allSamples)>1:
  sample.name=sample.name+'_comb'  

doTopPtReweighting = sample.name.startswith("TTJets") or sample.name.startswith("TTLep")
if doTopPtReweighting:
  print "Sample %s will have top pt reweights!"% sample.name
topPtReweightingFunc = getUnscaledTopPairPtReweightungFunction() if doTopPtReweighting else None

if options.fastSim:
  leptonFastSimSF = leptonFastSimSF_()
 
Esempio n. 6
0
  stop  = int(toFrac*nTot)
  ROOT.gDirectory.cd('PyROOT:/')
  print "Copy tree from source: total number of events found:",nTot,"Split counter: ",iSplit,"<",nSplit,"first Event:",start,"nEvents:",stop-start
  t = tc.CopyTree(skimCond,"",stop-start,start)
  tc.Delete()
  del tc
  rf.Close()
  del rf
  return t
   
exec('allSamples=['+options.allSamples+']')
for isample, sample in enumerate(allSamples):
  outDir = options.targetDir+'/'+"/".join([options.skim, sample['name']])

  maxN = 1 if options.small else -1
  chunks, sumWeight = getChunks(sample, maxN=maxN)
  
  if os.path.exists(outDir) and os.listdir(outDir) != [] and not options.overwrite:
    print "Found non-empty directory: %s -> skipping!"%outDir
    continue
  tmpDir = outDir+'/tmp/'
  os.system('mkdir -p '+outDir) 
  os.system('mkdir -p '+tmpDir)
  os.system('rm -rf '+tmpDir+'/*')

  if sample['isData']: 
    lumiScaleFactor=1
    branchKeepStrings = branchKeepStrings_DATAMC + branchKeepStrings_DATA 
    jetMCInfo = []
  else:
    lumiScaleFactor = xsec[sample['dbsName']]*target_lumi/float(sumWeight)
    sample.name = sample.name + '_comb'

outDir = os.path.join(options.targetDir, options.skim, sample.name)
if os.path.exists(outDir) and any([
        True for f in os.listdir(outDir) if f.endswith('.root')
]) and not options.overwrite:
    print "Found non-empty directory: %s -> skipping!" % outDir
    sys.exit(0)
else:
    tmpDir = os.path.join(outDir, 'tmp')
    if os.path.exists(outDir): shutil.rmtree(outDir)
    os.makedirs(outDir)
    os.makedirs(tmpDir)

for iSample, sample in enumerate(allSamples):
    tchunks, tsumWeight = getChunks(sample, maxN=maxN)
    chunks += tchunks
    sumWeight += tsumWeight
    print "Now %i chunks from sample %s with sumWeight now %f" % (
        len(chunks), sample.name, sumWeight)

if options.skim.lower().count('tiny'):
    #branches to be kept for data and MC
    branchKeepStrings_DATAMC = [
        "run",
        "lumi",
        "evt",
        "isData",
        "nVert",
        "met_pt",
        "met_phi",
Esempio n. 8
0
import ROOT
from StopsDilepton.samples.cmgTuples_Spring15_mAODv2_25ns_1l import *
from StopsDilepton.tools.helpers import getChain, getYieldFromChain, getEList, getChunks, closestOSDLMassToMZ, mZ, deltaR, getObjFromFile
from StopsDilepton.tools.objectSelection import getLeptons, getOtherLeptons, leptonVars, getGoodJets
from math import sqrt

sample = TTZToLLNuNu

c = ROOT.TChain('tree')
chunks, sumWeight = getChunks(TTZToLLNuNu)
for chunk in chunks:
    c.Add(chunk['file'])

targetLumi=2100
lumiScaleFactor = sample.xSection*targetLumi/float(sumWeight)

preselection="Sum$(Jet_pt>30&&abs(Jet_eta)<2.5)>=3"
postfix="corrSys_Q2PDFshape"
maxN = None

Muon_mediumMuonId = 1
Muon_relIso03 = 0.1
Muon_sip3d = 4.0
Muon_dxy = 0.05
Muon_dz = 0.1

def looseMuID(l, ptCut=10, absEtaCut=2.4):
    return \
        l["pt"]>=ptCut\
        and abs(l["pdgId"])==13\
        and abs(l["eta"])<absEtaCut\