Esempio n. 1
0
#######################################################
#            get the TChains for each sample          #
#######################################################
for s in backgrounds+signals:
  for plot in plots:
    plots[plot]['histo'][s['name']] = ROOT.TH1F(plot + "_" + s["name"], plot + "_" + s["name"], *(plots[plot]['binning']))


#######################################################
#            Start filling in the histograms          #
#######################################################
for i,s in enumerate(backgrounds+signals): #Enumerate returns a couple (index of key in array, dictionary)
  chain = s["chain"]
  print "Looping over %s" % s["name"]
  eList = getEList(chain, preselection) #Returns a list with events that pass the selection
  nEvents = eList.GetN()/reduceStat
  for ev in range(nEvents):
    chain.GetEntry(eList.GetEntry(ev))
    m_ll = getVarValue(chain, "dl_mass")
    ZVetoCut = abs(90.2-m_ll) > 15
    isSF = True if (getVarValue(chain, "isEE") == 1 or getVarValue(chain, "isMuMu") == 1) else False
    if (not isSF):
      ZVetoCut = True
    weight = reduceStat*getVarValue(chain, "weight")*lumi             
    if (ZVetoCut):
      for plot in plots.keys():   
        variable = getVarValue(chain, plots[plot]['variable'])
        plots[plot]['histo'][s["name"]].Fill(variable, weight)
  print (plots[plot]['histo'][s['name']].GetEntries())
Esempio n. 2
0
	t.Branch("njets", njets, "njets/I")
	t.Branch("nleptons", nleptons, "nleptons/I")
	t.Branch("nVertices", nVertices, "nVertices/I")
	t.Branch("isMC", isMC, "isMC/I")
	t.Branch("isElecElec", isElecElec, "isElecElec/I")
	t.Branch("isMuonMuon", isMuonMuon, "isMuonMuon/I")
	t.Branch("isMuonElec", isMuonElec, "isMuonElec/I")
	t.Branch("LeadingLepton","TLorentzVector",lepton1)
	t.Branch("SubLeadingLepton","TLorentzVector",lepton2)
	t.Branch('Process', Process, 'Process[200]/C')


	chain = s["chain"]

	if s['isData']==0:
		eList = getEList(chain, preselectionMC)
		nEvents = eList.GetN()/reduceStat
		print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselectionMC,nEvents)

	else:
		eList = getEList(chain, preselectionData)
		nEvents = eList.GetN()/reduceStat
		print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselectionData,nEvents)


	for ev in range(nEvents):

		if ev%10000==0:print "At %i/%i"%(ev,nEvents)
		chain.GetEntry(eList.GetEntry(ev))

		mt2Calc.reset()
Esempio n. 3
0
for s in backgrounds+data:
    #construct 1D histograms
    for lepton in plots.keys():
        for pk in plots[lepton].keys():
            for plot in plots[lepton][pk].keys():
                plots[lepton][pk][plot]['histo'][s["name"]] = ROOT.TH1D(plots[lepton][pk][plot]['name']+"_"+s["name"]+"_"+pk, plots[lepton][pk][plot]['name']+"_"+s["name"]+"_"+pk, *plots[lepton][pk][plot]['binning'])
                plots[lepton][pk][plot]['histo'][s["name"]].Sumw2()
    for lepton in plots_cut.keys():
        for pk in plots_cut[lepton].keys():
            for plot in plots_cut[lepton][pk].keys():
                plots_cut[lepton][pk][plot]['histo'][s["name"]] = ROOT.TH1D(plots_cut[lepton][pk][plot]['name']+"_"+s["name"]+"_"+pk, plots_cut[lepton][pk][plot]['name']+"_"+s["name"]+"_"+pk, *plots_cut[lepton][pk][plot]['binning'])
                plots_cut[lepton][pk][plot]['histo'][s["name"]].Sumw2()

    chain = s["chain"]

    eList = getEList(chain, preselection) if not s['isData'] else getEList(chain, preselection+'&&'+datacut)

    nEvents = eList.GetN()/reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)

    for ev in range(nEvents):

        increment = 50
        if nEvents>increment and ev%(nEvents/increment)==0:
            sys.stdout.write('\r' + "=" * (ev / (nEvents/increment)) +  " " * ((nEvents - ev)/ (nEvents/increment)) + "]" +  str(round((ev+1) / (float(nEvents)/100),2)) + "%")
            sys.stdout.flush()
            sys.stdout.write('\r')
        chain.GetEntry(eList.GetEntry(ev))

        #pileupweight = puReweighting(chain) if not s['isData'] else 1.
Esempio n. 4
0
        for o in coll:
            if deltaR(l, o) < dR and (l['pdgId'] == o['pdgId']
                                      or not checkPdgId):
                return True
        return False

    return match


for s in samples:
    #  for pk in plots.keys():
    #    plots[pk]['histo'][s['name']] = ROOT.TH1F("met_"+s["name"], "met_"+s["name"], *(plots[pk]['binning']))

    chain = s["chain"]
    print "Looping over %s" % s["name"]
    eList = getEList(chain, preselection + "&&dl_mt2ll>140")
    nEvents = eList.GetN() / reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (
        eList.GetN(), s["name"], preselection, nEvents)
    ntot = 0
    counterReco = {}
    counterRecoGen = {}
    counterRecoGen_muMatched = {}
    counterRecoGen_eleMatched = {}
    counterRecoGen_allMatched = {}
    counterRecoGen_oneMuMatchedToB = {}
    counterRecoGen_oneEleMatchedToB = {}
    counterRecoGen_oneMuMatchedToTau = {}
    counterRecoGen_oneEleMatchedToTau = {}
    counterRecoGen_recoTau = {}
    counterRecoGen_recoMatchedTau = {}
Esempio n. 5
0
    return False

ele_MVAID_cuts_vloose = {(0,0.8):-0.16 , (0.8, 1.479):-0.65, (1.57, 999): -0.74}
ele_MVAID_cuts_loose = {(0,0.8):0.35 , (0.8, 1.479):0.20, (1.57, 999): -0.52}
ele_MVAID_cuts_tight = {(0,0.8):0.87 , (0.8, 1.479):0.60, (1.57, 999):  0.17}


def looseEleID(l, ptCut=10, absEtaCut=2.5):
    if  l["pt"]>=ptCut  and abs(l["eta"])<absEtaCut and abs(l["pdgId"])==11 and l["convVeto"] and cmgMVAEleID(l, ele_MVAID_cuts_loose):
        if abs(l['eta'])<1.479:
            return l["relIso03"]<0.076 and abs(l["sip3d"])<4.0 and abs(l['dz'])< 0.373  and abs(l['dxy'])< 0.0118 and l["lostHits"]<=2
        else:
            return l["relIso03"]<0.0678  and abs(l["sip3d"])<4.0 and abs(l['dz'])<  0.602   and abs(l['dxy'])<  0.0739 and l["lostHits"]<=1
    else: return False

eList = getEList(c, preselection)
nEvents = eList.GetN()
print "Found %i events after preselection %s, looping over %i" % (eList.GetN(),preselection,nEvents)

bins = [
(3,3,0,0),
(3,3,1,1),
(3,3,2,-1),
(4,-1,0,0),
(4,-1,1,1),
(4,-1,2,-1),
]

def getBinName(b):
    res=""
    if b[0]==b[1]:res+="=="+str(b[0])+'j'
Esempio n. 6
0
def cutflow(sig):
    #######################################################
    #        SELECT WHAT YOU WANT TO DO HERE              #
    #######################################################
    reduceStat = 100  #recude the statistics, i.e. 10 is ten times less samples to look at

    #######################################################
    #         Define cutflow you want to make             #
    #######################################################
    mt2llcut = 80.
    metcut = 40.
    lumi = 10000.

    baselineamount = {
        'samples': {},
        'SoverB': None,
    }

    cutflow = {\
      'metsig':{'baseline': 0.,
                'cuts': {\
                  3:{'samples':{}, 'SoverB': None},
                  4:{'samples':{}, 'SoverB': None},
                  5:{'samples':{}, 'SoverB': None},
                  6:{'samples':{}, 'SoverB': None},
                  7:{'samples':{}, 'SoverB': None},
                  8:{'samples':{}, 'SoverB': None},
                  9:{'samples':{}, 'SoverB': None},
                  10:{'samples':{}, 'SoverB': None},
                  10:{'samples':{}, 'SoverB': None},
                  },
                'event': None,
                },
      'nbjets':{'baseline': 1.,
                'cuts': {\
                  0:{'samples':{}, 'SoverB': None},
                  1:{'samples':{}, 'SoverB': None},
                  2:{'samples':{}, 'SoverB': None},
                  3:{'samples':{}, 'SoverB': None},
                  4:{'samples':{}, 'SoverB': None},
                  5:{'samples':{}, 'SoverB': None},
                  },
                'event': None,
                },
      'njets': {'baseline': 2.,
                'cuts': {\
                  1:{'samples':{}, 'SoverB': None},
                  2:{'samples':{}, 'SoverB': None},
                  3:{'samples':{}, 'SoverB': None},
                  4:{'samples':{}, 'SoverB': None},
                  5:{'samples':{}, 'SoverB': None},
                  6:{'samples':{}, 'SoverB': None},
                  7:{'samples':{}, 'SoverB': None},
                  },
                'event': None,
                },
      'ht':    {'baseline': 0.,
                'cuts': {\
                  50: {'samples':{}, 'SoverB': None},
                  100:{'samples':{}, 'SoverB': None},
                  200:{'samples':{}, 'SoverB': None},
                  300:{'samples':{}, 'SoverB': None},
                  400:{'samples':{}, 'SoverB': None},
                  500:{'samples':{}, 'SoverB': None},
                  },
                'event': None,
                },
    }

    #preselection: MET>40, njets>=2, n_bjets>=1, n_lep>=2
    #For now see here for the Sum$ syntax: https://root.cern.ch/root/html/TTree.html#TTree:Draw@2
    preselection = 'met_pt>' + str(metcut) + '&&Sum$(LepGood_pt>20)==2'

    #######################################################
    #                 load all the samples                #
    #######################################################
    backgrounds = [singleTop_50ns, DY_50ns, TTJets_50ns]
    #signals = [SMS_T2tt_2J_mStop425_mLSP325, SMS_T2tt_2J_mStop500_mLSP325, SMS_T2tt_2J_mStop650_mLSP325, SMS_T2tt_2J_mStop850_mLSP100]
    signal = [sig]

    #######################################################
    #            get the TChains for each sample          #
    #######################################################
    for s in backgrounds + signal:
        s['chain'] = getChain(s, histname="")

    #######################################################
    #            Start filling in the histograms          #
    #######################################################
    for s in backgrounds + signal:
        for cuttype in cutflow.keys():
            for cut in cutflow[cuttype]['cuts'].keys():
                cutflow[cuttype]['cuts'][cut]['samples'][s["name"]] = 0

        baselineamount['samples'][s['name']] = 0

        chain = s["chain"]
        #Using Event loop
        #get EList after preselection
        print "Looping over %s" % s["name"]
        eList = getEList(chain, preselection)
        nEvents = eList.GetN() / reduceStat
        print "Found %i events in %s after preselection %s, looping over %i" % (
            eList.GetN(), s["name"], preselection, nEvents)

        for ev in range(nEvents):
            increment = 50
            if nEvents > increment and ev % (nEvents / increment) == 0:
                sys.stdout.write(
                    '\r' + "=" * (ev / (nEvents / increment)) + " " *
                    ((nEvents - ev) / (nEvents / increment)) + "]" +
                    str(round((ev + 1) / (float(nEvents) / 100), 2)) + "%")
                sys.stdout.flush()
                sys.stdout.write('\r')
            chain.GetEntry(eList.GetEntry(ev))
            mt2Calc.reset()
            #event weight (L= 4fb^-1)
            weight = reduceStat * getVarValue(chain, "weight")

            weight = weight * (lumi / 4000.)

            #MET
            met = getVarValue(chain, "met_pt")
            metPhi = getVarValue(chain, "met_phi")
            #jetpt
            leadingjetpt = getVarValue(chain, "Jet_pt", 0)
            subleadingjetpt = getVarValue(chain, "Jet_pt", 1)
            #Leptons
            allLeptons = getLeptons(chain)
            muons = filter(looseMuID, allLeptons)
            electrons = filter(looseEleID, allLeptons)
            nlep = len(allLeptons)

            #SF and OF channels
            leptons = {\
              'mu':   {'name': 'mumu', 'file': muons},
              'e':   {'name': 'ee', 'file': electrons},
              'emu': {'name': 'emu', 'file': [electrons,muons]},
              }
            for lep in leptons.keys():
                twoleptons = False
                #Same Flavor
                if lep != 'emu':
                    if len(leptons[lep]['file']) == 2 and leptons[lep]['file'][
                            0]['pdgId'] * leptons[lep]['file'][1]['pdgId'] < 0:

                        twoleptons = True
                        l0pt, l0eta, l0phi = leptons[lep]['file'][0][
                            'pt'], leptons[lep]['file'][0]['eta'], leptons[
                                lep]['file'][0]['phi']
                        l1pt, l1eta, l1phi = leptons[lep]['file'][1][
                            'pt'], leptons[lep]['file'][1]['eta'], leptons[
                                lep]['file'][1]['phi']
                        leadingleptonpt = l0pt
                        subleadingleptonpt = l1pt
                        mll = sqrt(2. * l0pt * l1pt *
                                   (cosh(l0eta - l1eta) - cos(l0phi - l1phi)))
                        zveto = True
                #Opposite Flavor
                if lep == 'emu':
                    if len(leptons[lep]['file'][0]) == 1 and len(
                            leptons[lep]['file']
                        [1]) == 1 and leptons[lep]['file'][0][0][
                            'pdgId'] * leptons[lep]['file'][1][0]['pdgId'] < 0:

                        twoleptons = True
                        l0pt, l0eta, l0phi = leptons[lep]['file'][0][0][
                            'pt'], leptons[lep]['file'][0][0]['eta'], leptons[
                                lep]['file'][0][0]['phi']
                        l1pt, l1eta, l1phi = leptons[lep]['file'][1][0][
                            'pt'], leptons[lep]['file'][1][0]['eta'], leptons[
                                lep]['file'][1][0]['phi']
                        if l1pt > l0pt:
                            leadingleptonpt = l1pt
                            subleadingleptonpt = l0pt
                        else:
                            leadingleptonpt = l0pt
                            subleadingleptonpt = l1pt
                        mll = sqrt(2. * l0pt * l1pt *
                                   (cosh(l0eta - l1eta) - cos(l0phi - l1phi)))
                        zveto = False
                if (twoleptons and mll > 20
                        and not zveto) or (twoleptons and mll > 20 and zveto
                                           and abs(mll - 91.2) > 15):
                    mt2Calc.setMet(met, metPhi)
                    mt2Calc.setLeptons(l0pt, l0eta, l0phi, l1pt, l1eta, l1phi)
                    mt2ll = mt2Calc.mt2ll()
                    jets = filter(
                        lambda j: j['pt'] > 30 and abs(j['eta']) < 2.4 and j[
                            'id'], getJets(chain))
                    bjetspt = filter(lambda j: j['btagCSV'] > 0.89, jets)
                    nobjets = filter(lambda j: j['btagCSV'] <= 0.89, jets)
                    nmuons = len(muons)
                    nelectrons = len(electrons)
                    ht = sum([j['pt'] for j in jets])

                    if len(jets) < 1: continue
                    if mt2ll < mt2llcut: continue

                    cutflow['metsig']['event'] = met / sqrt(ht)
                    cutflow['nbjets']['event'] = len(bjetspt)
                    cutflow['njets']['event'] = len(jets)
                    cutflow['ht']['event'] = ht

                    for cuttype in cutflow.keys():
                        eventisgood = True
                        for cuttype2 in cutflow.keys():
                            if cuttype2 != cuttype:
                                if cutflow[cuttype2]['event'] < cutflow[
                                        cuttype2]['baseline']:
                                    eventisgood = False
                        if eventisgood:
                            for cut in cutflow[cuttype]['cuts']:
                                if cutflow[cuttype]['event'] >= cut:
                                    cutflow[cuttype]['cuts'][cut]['samples'][
                                        s['name']] += weight

                    baselineisgood = True
                    for cuttype in cutflow.keys():
                        if cutflow[cuttype]['event'] < cutflow[cuttype][
                                'baseline']:
                            baselineisgood = False
                    if baselineisgood:
                        baselineamount['samples'][s['name']] += weight

        del eList

    sigtot = baselineamount['samples'][signal[0]['name']]
    bkgtot = sum(baselineamount['samples'].values()) - sigtot

    if bkgtot > 0: baselineamount['SoverB'] = 100 * (sigtot / sqrt(bkgtot))
    else: baselineamount['SoverB'] = 0.

    for cuttype in cutflow.keys():
        for cut in cutflow[cuttype]['cuts']:
            sigtot = cutflow[cuttype]['cuts'][cut]['samples'][signal[0]
                                                              ['name']]
            bkgtot = sum(
                cutflow[cuttype]["cuts"][cut]['samples'].values()) - sigtot
            if bkgtot > 0:
                cutflow[cuttype]['cuts'][cut]['SoverB'] = 100 * (sigtot /
                                                                 sqrt(bkgtot))
            else:
                cutflow[cuttype]['cuts'][cut]['SoverB'] = 0.

    maketable(baselineamount, cutflow, mt2llcut, metcut, signal, lumi)
def dRMatch(coll, dR=0.4):
  def match(l):
    for o in coll:
      if deltaR(l,o)<dR: return True
    return False
  return match


 
for s in samples:
#  for pk in plots.keys():
#    plots[pk]['histo'][s['name']] = ROOT.TH1F("met_"+s["name"], "met_"+s["name"], *(plots[pk]['binning']))

  chain = s["chain"]
  print "Looping over %s" % s["name"]
  eList = getEList(chain, preselection+"&&dl_mt2ll>140") 
  nEvents = eList.GetN()/reduceStat
  print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)
  ntot=0
  counterReco={}
  counterRecoGen={}
  counterRecoGen_muMatched={}
  counterRecoGen_eleMatched={}
  counterRecoGen_allMatched={}
  counterRecoGen_oneMuMatchedToB={}
  counterRecoGen_oneEleMatchedToB={}
  counterRecoGen_oneMuMatchedToTau={}
  counterRecoGen_oneEleMatchedToTau={}
  for mode in ["isMuMu", "isEE", "isEMu"]:
    counterReco[mode]=0
    counterRecoGen[mode]={}
Esempio n. 8
0
def cutflow(sig):
  #######################################################
  #        SELECT WHAT YOU WANT TO DO HERE              #
  #######################################################
  reduceStat = 100 #recude the statistics, i.e. 10 is ten times less samples to look at


  #######################################################
  #         Define cutflow you want to make             #
  #######################################################
  mt2llcut = 80.
  metcut = 40.
  lumi = 10000.

  baselineamount = { 'samples':{}, 'SoverB': None,}

  cutflow = {\
    'metsig':{'baseline': 0., 
              'cuts': {\
                3:{'samples':{}, 'SoverB': None}, 
                4:{'samples':{}, 'SoverB': None}, 
                5:{'samples':{}, 'SoverB': None}, 
                6:{'samples':{}, 'SoverB': None},
                7:{'samples':{}, 'SoverB': None},
                8:{'samples':{}, 'SoverB': None},
                9:{'samples':{}, 'SoverB': None},
                10:{'samples':{}, 'SoverB': None},
                10:{'samples':{}, 'SoverB': None},
                },
              'event': None,
              },
    'nbjets':{'baseline': 1., 
              'cuts': {\
                0:{'samples':{}, 'SoverB': None}, 
                1:{'samples':{}, 'SoverB': None}, 
                2:{'samples':{}, 'SoverB': None}, 
                3:{'samples':{}, 'SoverB': None},
                4:{'samples':{}, 'SoverB': None},
                5:{'samples':{}, 'SoverB': None},
                },
              'event': None,
              },
    'njets': {'baseline': 2., 
              'cuts': {\
                1:{'samples':{}, 'SoverB': None}, 
                2:{'samples':{}, 'SoverB': None}, 
                3:{'samples':{}, 'SoverB': None},
                4:{'samples':{}, 'SoverB': None},
                5:{'samples':{}, 'SoverB': None},
                6:{'samples':{}, 'SoverB': None},
                7:{'samples':{}, 'SoverB': None},
                },
              'event': None,
              },
    'ht':    {'baseline': 0., 
              'cuts': {\
                50: {'samples':{}, 'SoverB': None}, 
                100:{'samples':{}, 'SoverB': None}, 
                200:{'samples':{}, 'SoverB': None},
                300:{'samples':{}, 'SoverB': None},
                400:{'samples':{}, 'SoverB': None},
                500:{'samples':{}, 'SoverB': None},
                },
              'event': None,
              },
  }

  #preselection: MET>40, njets>=2, n_bjets>=1, n_lep>=2
  #For now see here for the Sum$ syntax: https://root.cern.ch/root/html/TTree.html#TTree:Draw@2
  preselection = 'met_pt>'+str(metcut)+'&&Sum$(LepGood_pt>20)==2'

  #######################################################
  #                 load all the samples                #
  #######################################################
  backgrounds = [singleTop_50ns,DY_50ns,TTJets_50ns]
  #signals = [SMS_T2tt_2J_mStop425_mLSP325, SMS_T2tt_2J_mStop500_mLSP325, SMS_T2tt_2J_mStop650_mLSP325, SMS_T2tt_2J_mStop850_mLSP100]
  signal = [sig]

  #######################################################
  #            get the TChains for each sample          #
  #######################################################
  for s in backgrounds+signal:
    s['chain'] = getChain(s,histname="")


  #######################################################
  #            Start filling in the histograms          #
  #######################################################
  for s in backgrounds+signal:
    for cuttype in cutflow.keys():
      for cut in cutflow[cuttype]['cuts'].keys():
        cutflow[cuttype]['cuts'][cut]['samples'][s["name"]] = 0

    baselineamount['samples'][s['name']] = 0

    chain = s["chain"]
    #Using Event loop
    #get EList after preselection
    print "Looping over %s" % s["name"]
    eList = getEList(chain, preselection) 
    nEvents = eList.GetN()/reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)

    for ev in range(nEvents):
      increment = 50
      if nEvents>increment and ev%(nEvents/increment)==0: 
        sys.stdout.write('\r' + "=" * (ev / (nEvents/increment)) +  " " * ((nEvents - ev)/ (nEvents/increment)) + "]" +  str(round((ev+1) / (float(nEvents)/100),2)) + "%")
        sys.stdout.flush()
        sys.stdout.write('\r')
      chain.GetEntry(eList.GetEntry(ev))
      mt2Calc.reset()
      #event weight (L= 4fb^-1)
      weight = reduceStat*getVarValue(chain, "weight")

      weight = weight*(lumi/4000.)

      #MET
      met = getVarValue(chain, "met_pt")
      metPhi = getVarValue(chain, "met_phi")
      #jetpt
      leadingjetpt = getVarValue(chain, "Jet_pt",0)
      subleadingjetpt = getVarValue(chain, "Jet_pt",1)
      #Leptons 
      allLeptons = getLeptons(chain) 
      muons = filter(looseMuID, allLeptons)    
      electrons = filter(looseEleID, allLeptons)
      nlep = len(allLeptons)

      #SF and OF channels
      leptons = {\
        'mu':   {'name': 'mumu', 'file': muons},
        'e':   {'name': 'ee', 'file': electrons},
        'emu': {'name': 'emu', 'file': [electrons,muons]},
        }
      for lep in leptons.keys():
        twoleptons = False
        #Same Flavor
        if lep != 'emu':
          if len(leptons[lep]['file'])==2 and leptons[lep]['file'][0]['pdgId']*leptons[lep]['file'][1]['pdgId']<0:

            twoleptons = True
            l0pt, l0eta, l0phi = leptons[lep]['file'][0]['pt'],  leptons[lep]['file'][0]['eta'],  leptons[lep]['file'][0]['phi']
            l1pt, l1eta, l1phi = leptons[lep]['file'][1]['pt'],  leptons[lep]['file'][1]['eta'],  leptons[lep]['file'][1]['phi']
            leadingleptonpt = l0pt
            subleadingleptonpt = l1pt
            mll = sqrt(2.*l0pt*l1pt*(cosh(l0eta-l1eta)-cos(l0phi-l1phi)))
            zveto = True
        #Opposite Flavor
        if lep == 'emu':
          if len(leptons[lep]['file'][0])==1 and len(leptons[lep]['file'][1])==1 and leptons[lep]['file'][0][0]['pdgId']*leptons[lep]['file'][1][0]['pdgId']<0:

            twoleptons = True
            l0pt, l0eta, l0phi = leptons[lep]['file'][0][0]['pt'],  leptons[lep]['file'][0][0]['eta'],  leptons[lep]['file'][0][0]['phi']
            l1pt, l1eta, l1phi = leptons[lep]['file'][1][0]['pt'],  leptons[lep]['file'][1][0]['eta'],  leptons[lep]['file'][1][0]['phi']
            if l1pt > l0pt :
              leadingleptonpt = l1pt
              subleadingleptonpt = l0pt
            else:
              leadingleptonpt = l0pt
              subleadingleptonpt = l1pt
            mll = sqrt(2.*l0pt*l1pt*(cosh(l0eta-l1eta)-cos(l0phi-l1phi)))
            zveto = False
        if (twoleptons and mll>20 and not zveto) or (twoleptons and mll > 20 and zveto and abs(mll-90.2)>15):
          mt2Calc.setMet(met,metPhi)
          mt2Calc.setLeptons(l0pt, l0eta, l0phi, l1pt, l1eta, l1phi)        
          mt2ll = mt2Calc.mt2ll()
          jets = filter(lambda j:j['pt']>30 and abs(j['eta'])<2.4 and j['id'], getJets(chain))
          bjetspt = filter(lambda j:j['btagCSV']>0.89, jets)
          nobjets = filter(lambda j:j['btagCSV']<=0.89, jets)
          nmuons = len(muons)
          nelectrons = len(electrons)
          ht = sum([j['pt'] for j in jets])


          if len(jets)<1: continue
          if mt2ll<mt2llcut: continue 

          cutflow['metsig']['event'] = met/sqrt(ht)
          cutflow['nbjets']['event'] = len(bjetspt)
          cutflow['njets']['event'] = len(jets)
          cutflow['ht']['event'] = ht

          for cuttype in cutflow.keys():
            eventisgood = True
            for cuttype2 in cutflow.keys():
              if cuttype2 != cuttype:
                if cutflow[cuttype2]['event'] < cutflow[cuttype2]['baseline']:
                  eventisgood = False
            if eventisgood:
              for cut in cutflow[cuttype]['cuts']:
                if cutflow[cuttype]['event'] >= cut:
                  cutflow[cuttype]['cuts'][cut]['samples'][s['name']] += weight

          baselineisgood = True
          for cuttype in cutflow.keys():
            if cutflow[cuttype]['event'] < cutflow[cuttype]['baseline']:
              baselineisgood = False
          if baselineisgood:
            baselineamount['samples'][s['name']] += weight

    del eList

  sigtot = baselineamount['samples'][signal[0]['name']]
  bkgtot = sum(baselineamount['samples'].values()) - sigtot

  if bkgtot > 0: baselineamount['SoverB'] = 100 * (sigtot/sqrt(bkgtot))
  else:          baselineamount['SoverB'] = 0.

  for cuttype in cutflow.keys(): 
    for cut in cutflow[cuttype]['cuts']:
      sigtot = cutflow[cuttype]['cuts'][cut]['samples'][signal[0]['name']]
      bkgtot = sum(cutflow[cuttype]["cuts"][cut]['samples'].values()) - sigtot
      if bkgtot > 0: cutflow[cuttype]['cuts'][cut]['SoverB'] = 100 * (sigtot/sqrt(bkgtot))
      else:          cutflow[cuttype]['cuts'][cut]['SoverB'] = 0.

  maketable(baselineamount, cutflow, mt2llcut, metcut,signal,lumi)
Esempio n. 9
0
    if l["pt"] >= ptCut and abs(l["eta"]) < absEtaCut and abs(
            l["pdgId"]) == 11 and l["convVeto"] and cmgMVAEleID(
                l, ele_MVAID_cuts_loose):
        if abs(l['eta']) < 1.479:
            return l["relIso03"] < 0.076 and abs(l["sip3d"]) < 4.0 and abs(
                l['dz']) < 0.373 and abs(
                    l['dxy']) < 0.0118 and l["lostHits"] <= 2
        else:
            return l["relIso03"] < 0.0678 and abs(l["sip3d"]) < 4.0 and abs(
                l['dz']) < 0.602 and abs(
                    l['dxy']) < 0.0739 and l["lostHits"] <= 1
    else:
        return False


eList = getEList(c, preselection)
nEvents = eList.GetN()
print "Found %i events after preselection %s, looping over %i" % (
    eList.GetN(), preselection, nEvents)

bins = [
    (3, 3, 0, 0),
    (3, 3, 1, 1),
    (3, 3, 2, -1),
    (4, -1, 0, 0),
    (4, -1, 1, 1),
    (4, -1, 2, -1),
]


def getBinName(b):
Esempio n. 10
0
#            Start filling in the histograms          #
#######################################################
for s in sample:
    #construct 1D histograms
    for lepton in plots.keys():
        for plot in plots[lepton].keys():
            plots[lepton][plot]['histo'][s["name"]] = ROOT.TH1D(
                plots[lepton][plot]['name'] + "_" + s["name"],
                plots[lepton][plot]['name'] + "_" + s["name"],
                *plots[lepton][plot]['binning'])
            plots[lepton][plot]['histo'][s["name"]].Sumw2()

    chain = s["chain"]

    if (s == DoubleMuon_Run2015D):
        eList = getEList(chain,
                         preselection + '&&' + datacut + '&&HLT_mumuIso')
    elif (s == DoubleEG_Run2015D):
        eList = getEList(chain, preselection + '&&' + datacut + '&&HLT_ee_DZ')
    elif (s == MuonEG_Run2015D):
        eList = getEList(chain, preselection + '&&' + datacut + '&&HLT_mue')
    else:
        eList = getEList(chain, preselection)

    nEvents = eList.GetN() / reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (
        eList.GetN(), s["name"], preselection, nEvents)

    #start event loop
    for ev in range(nEvents):

        ##################################
Esempio n. 11
0
  chain.SetBranchStatus("nGoodElectrons",1)
  chain.SetBranchStatus("isOS",1)
  chain.SetBranchStatus("isEE",1)
  chain.SetBranchStatus("isEMu",1)
  chain.SetBranchStatus("isMuMu",1)
  if s not in data: 
    chain.SetBranchStatus("genWeight",1)
    chain.SetBranchStatus("Jet_mcMatchFlav",1)
    chain.SetBranchStatus("xsec",1)
    chain.SetBranchStatus("Jet_partonId",1)

  #Using Event loop
  #get EList after preselection
  print '\n', "Looping over %s" % s["name"]

  if s == DY_25ns: eList = getEList(chain, preselection+"&&Sum$(Jet_pt)<150")
  else: eList = getEList(chain, preselection)

  nEvents = eList.GetN()/reduceStat
  print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)
 
  for ev in range(nEvents):

    increment = 50
    if nEvents>increment and ev%(nEvents/increment)==0: 
      sys.stdout.write('\r' + "=" * (ev / (nEvents/increment)) +  " " * ((nEvents - ev)/ (nEvents/increment)) + "]" +  str(round((ev+1) / (float(nEvents)/100),2)) + "%")
      sys.stdout.flush()
      sys.stdout.write('\r')
    chain.GetEntry(eList.GetEntry(ev))
    mt2Calc.reset()
    #event weight (L= 4fb^-1)
Esempio n. 12
0

#######################################################
#            Start filling in the histograms          #
#######################################################
for s in sample:
    #construct 1D histograms
    for lepton in plots.keys():
        for plot in plots[lepton].keys():
                plots[lepton][plot]['histo'][s["name"]] = ROOT.TH1D(plots[lepton][plot]['name']+"_"+s["name"], plots[lepton][plot]['name']+"_"+s["name"], *plots[lepton][plot]['binning'])
                plots[lepton][plot]['histo'][s["name"]].Sumw2()

    chain = s["chain"]

    if (s == DoubleMuon_Run2015D):
        eList =  getEList(chain, preselection+'&&'+datacut+'&&HLT_mumuIso')
    elif (s == DoubleEG_Run2015D):
        eList =  getEList(chain, preselection+'&&'+datacut+'&&HLT_ee_DZ')
    elif (s == MuonEG_Run2015D):
        eList =  getEList(chain, preselection+'&&'+datacut+'&&HLT_mue')
    else:
        eList = getEList(chain, preselection)

    nEvents = eList.GetN()/reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)

      #start event loop
    for ev in range(nEvents):

        ##################################
        #        Processing output       #
Esempio n. 13
0

#######################################################
#            Start filling in the histograms          #
#######################################################
for s in backgrounds+data:
  #construct 1D histograms
  for lepton in plots.keys():
    for plot in plots[lepton].keys():
        plots[lepton][plot]['histo'][s["name"]] = ROOT.TH1D(plots[lepton][plot]['name']+"_"+s["name"], plots[lepton][plot]['name']+"_"+s["name"], *plots[lepton][plot]['binning'])
        plots[lepton][plot]['histo'][s["name"]].Sumw2()

  chain = s["chain"]

  if (s == DoubleMuon_Run2015D): 
    eList = getEList(chain, preselection) if not s['isData'] else getEList(chain, preselection+'&&'+datacut+'&&HLT_mumuIso')
  elif (s == DoubleEG_Run2015D):
    eList = getEList(chain, preselection) if not s['isData'] else getEList(chain, preselection+'&&'+datacut+'&&HLT_ee_DZ')
  elif (s == MuonEG_Run2015D):   
    eList = getEList(chain, preselection) if not s['isData'] else getEList(chain, preselection+'&&'+datacut+'&&HLT_mue')
  else:
    eList = getEList(chain, preselection) if not s['isData'] else getEList(chain, preselection)
  
  nEvents = eList.GetN()/reduceStat
  print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)
 
   #start event loop
  for ev in range(nEvents):

    ##################################
    #        Processing output       #
Esempio n. 14
0
    chain.SetBranchStatus("isOS", 1)
    chain.SetBranchStatus("isEE", 1)
    chain.SetBranchStatus("isEMu", 1)
    chain.SetBranchStatus("isMuMu", 1)
    if s not in data:
        chain.SetBranchStatus("genWeight", 1)
        chain.SetBranchStatus("Jet_mcMatchFlav", 1)
        chain.SetBranchStatus("xsec", 1)
        chain.SetBranchStatus("Jet_partonId", 1)

    #Using Event loop
    #get EList after preselection
    print '\n', "Looping over %s" % s["name"]

    if s == DY_25ns:
        eList = getEList(chain, preselection + "&&Sum$(Jet_pt)<150")
    else:
        eList = getEList(chain, preselection)

    nEvents = eList.GetN() / reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (
        eList.GetN(), s["name"], preselection, nEvents)

    for ev in range(nEvents):

        increment = 50
        if nEvents > increment and ev % (nEvents / increment) == 0:
            sys.stdout.write('\r' + "=" * (ev / (nEvents / increment)) + " " *
                             ((nEvents - ev) / (nEvents / increment)) + "]" +
                             str(round((ev + 1) /
                                       (float(nEvents) / 100), 2)) + "%")
Esempio n. 15
0
    t.Branch("njets", njets, "njets/I")
    t.Branch("nleptons", nleptons, "nleptons/I")
    t.Branch("nVertices", nVertices, "nVertices/I")
    t.Branch("isMC", isMC, "isMC/I")
    t.Branch("isElecElec", isElecElec, "isElecElec/I")
    t.Branch("isMuonMuon", isMuonMuon, "isMuonMuon/I")
    t.Branch("isMuonElec", isMuonElec, "isMuonElec/I")
    t.Branch("EventNumber", EventNumber, "EventNumber/I")
    t.Branch("LeadingLepton", "TLorentzVector", lepton1)
    t.Branch("SubLeadingLepton", "TLorentzVector", lepton2)
    t.Branch('Process', Process, 'Process[200]/C')

    chain = s["chain"]

    if s['isData'] == 0:
        eList = getEList(chain, preselectionMC)
        nEvents = eList.GetN() / reduceStat
        print "Found %i events in %s after preselection %s, looping over %i" % (
            eList.GetN(), s["name"], preselectionMC, nEvents)

    else:
        eList = getEList(chain, preselectionData)
        nEvents = eList.GetN() / reduceStat
        print "Found %i events in %s after preselection %s, looping over %i" % (
            eList.GetN(), s["name"], preselectionData, nEvents)

    for ev in range(nEvents):

        if ev % 10000 == 0: print "At %i/%i" % (ev, nEvents)
        chain.GetEntry(eList.GetEntry(ev))
Esempio n. 16
0
  chain.SetBranchStatus("Jet_pt",1)
  chain.SetBranchStatus("Jet_phi",1)
  chain.SetBranchStatus("Jet_btagCMVA",1)
  chain.SetBranchStatus("Jet_btagCSV",1)
  chain.SetBranchStatus("Jet_id",1)
  chain.SetBranchStatus("weight",1)
  if s not in data: 
    chain.SetBranchStatus("genWeight",1)
    chain.SetBranchStatus("Jet_mcMatchFlav",1)
    chain.SetBranchStatus("xsec",1)
    chain.SetBranchStatus("Jet_partonId",1)

  #Using Event loop
  #get EList after preselection
  print '\n', "Looping over %s" % s["name"]
  eList = getEList(chain, preselection) 
  nEvents = eList.GetN()/reduceStat
  print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)
 
  for ev in range(nEvents):

    increment = 50
    if nEvents>increment and ev%(nEvents/increment)==0: 
      sys.stdout.write('\r' + "=" * (ev / (nEvents/increment)) +  " " * ((nEvents - ev)/ (nEvents/increment)) + "]" +  str(round((ev+1) / (float(nEvents)/100),2)) + "%")
      sys.stdout.flush()
      sys.stdout.write('\r')
    chain.GetEntry(eList.GetEntry(ev))
    mt2Calc.reset()
    #event weight (L= 4fb^-1)
    weight = reduceStat*getVarValue(chain, "weight")
Esempio n. 17
0
                    pk, plots[lepton][pk][plot]['name'] + "_" + s["name"] +
                    "_" + pk, *plots[lepton][pk][plot]['binning'])
                plots[lepton][pk][plot]['histo'][s["name"]].Sumw2()
    for lepton in plots_cut.keys():
        for pk in plots_cut[lepton].keys():
            for plot in plots_cut[lepton][pk].keys():
                plots_cut[lepton][pk][plot]['histo'][s["name"]] = ROOT.TH1D(
                    plots_cut[lepton][pk][plot]['name'] + "_" + s["name"] +
                    "_" + pk, plots_cut[lepton][pk][plot]['name'] + "_" +
                    s["name"] + "_" + pk,
                    *plots_cut[lepton][pk][plot]['binning'])
                plots_cut[lepton][pk][plot]['histo'][s["name"]].Sumw2()

    chain = s["chain"]

    eList = getEList(chain, preselection) if not s['isData'] else getEList(
        chain, preselection + '&&' + datacut)

    nEvents = eList.GetN() / reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (
        eList.GetN(), s["name"], preselection, nEvents)

    for ev in range(nEvents):

        increment = 50
        if nEvents > increment and ev % (nEvents / increment) == 0:
            sys.stdout.write('\r' + "=" * (ev / (nEvents / increment)) + " " *
                             ((nEvents - ev) / (nEvents / increment)) + "]" +
                             str(round((ev + 1) /
                                       (float(nEvents) / 100), 2)) + "%")
            sys.stdout.flush()
Esempio n. 18
0
#            Start filling in the histograms          #
#######################################################
for s in backgrounds + data:
    #construct 1D histograms
    for lepton in plots.keys():
        for plot in plots[lepton].keys():
            plots[lepton][plot]['histo'][s["name"]] = ROOT.TH1D(
                plots[lepton][plot]['name'] + "_" + s["name"],
                plots[lepton][plot]['name'] + "_" + s["name"],
                *plots[lepton][plot]['binning'])
            plots[lepton][plot]['histo'][s["name"]].Sumw2()

    chain = s["chain"]

    if (s == DoubleMuon_Run2015D):
        eList = getEList(chain, preselection) if not s['isData'] else getEList(
            chain, preselection + '&&' + datacut + '&&HLT_mumuIso')
    elif (s == DoubleEG_Run2015D):
        eList = getEList(chain, preselection) if not s['isData'] else getEList(
            chain, preselection + '&&' + datacut + '&&HLT_ee_DZ')
    elif (s == MuonEG_Run2015D):
        eList = getEList(chain, preselection) if not s['isData'] else getEList(
            chain, preselection + '&&' + datacut + '&&HLT_mue')
    else:
        eList = getEList(chain, preselection) if not s['isData'] else getEList(
            chain, preselection)

    nEvents = eList.GetN() / reduceStat
    print "Found %i events in %s after preselection %s, looping over %i" % (
        eList.GetN(), s["name"], preselection, nEvents)
Esempio n. 19
0
  if s in data:
    chain.SetBranchStatus("HLT_mumuIso",1)
    chain.SetBranchStatus("HLT_ee_DZ",1)
    chain.SetBranchStatus("HLT_mue",1)
  if s not in data: 
    chain.SetBranchStatus("genWeight",1)
    chain.SetBranchStatus("Jet_mcMatchFlav",1)
    chain.SetBranchStatus("xsec",1)
    chain.SetBranchStatus("Jet_partonId",1)
    chain.SetBranchStatus("puWeight",1)

  #Using Event loop
  #get EList after preselection
  print '\n', "Looping over %s" % s["name"]

  if s['isData'] : eList = getEList(chain, preselection+'&&'+dataCut)
  else:            eList = eList = getEList(chain, preselection)

  nEvents = eList.GetN()/reduceStat
  print "Found %i events in %s after preselection %s, looping over %i" % (eList.GetN(),s["name"],preselection,nEvents)
 
  for ev in range(nEvents):

    increment = 50
    if nEvents>increment and ev%(nEvents/increment)==0: 
      sys.stdout.write('\r' + "=" * (ev / (nEvents/increment)) +  " " * ((nEvents - ev)/ (nEvents/increment)) + "]" +  str(round((ev+1) / (float(nEvents)/100),2)) + "%")
      sys.stdout.flush()
      sys.stdout.write('\r')
    chain.GetEntry(eList.GetEntry(ev))
    mt2Calc.reset()
    #event weight (L= 4fb^-1)