def process(self):
        def preselection(row):
            if not row.doubleEPass:
                return False
            if not (row.e1MatchesDoubleEPath > 0 and row.e2MatchesDoubleEPath > 0):
                return False
            if row.e1Pt < 20:
                return False
            if not selections.eSelection(row, "e1"):
                return False
            if not selections.eSelection(row, "e2"):
                return False
            if any([row.muVetoPt5, row.tauVetoPt20, row.eVetoCicTightIso]):
                return False
            if not (row.jetVeto40 >= 1):
                return False
            if row.e1_e2_Mass < 40:
                return False
            return True

        histos = self.histograms
        pucorrector = self.pucorrector
        for row in self.tree:
            if not preselection(row):
                continue

            evt_weight = pucorrector(row.nTruePU) * mcCorrectors.get_electron_corrections(row, "e1", "e2")

            for iso_label in lep_id:
                if not selections.lepton_id_iso(row, "e1", iso_label):
                    continue
                if not selections.lepton_id_iso(row, "e2", iso_label):
                    continue
                folder = "%s" % iso_label

                if row.e1GenPdgId != -999 and row.e2GenPdgId != -999:
                    if row.e1_e2_SS:
                        histos["%s/ss_trkMass" % folder].Fill(row.e1_e2_Mass, evt_weight)
                    else:
                        histos["%s/os_trkMass" % folder].Fill(row.e1_e2_Mass, evt_weight)

                for el in ["e1", "e2"]:
                    pdgid = getattr(row, name_mapping(el, "GenPdgId"))
                    if pdgid != -999:
                        eta = getattr(row, name_mapping(el, "AbsEta"))
                        pt = getattr(row, name_mapping(el, "Pt"))
                        charge = getattr(row, name_mapping(el, "Charge"))
                        if eta < barrelThr:
                            histos["%s/pt_in_barrel" % folder].Fill(pt, evt_weight)
                        elif eta < accThr:
                            histos["%s/pt_in_endcap" % folder].Fill(pt, evt_weight)
                        histos["%s/matched_electrons" % folder].Fill(eta, pt, evt_weight)
                        single_hist = "%s/matched_%s" % (folder, el)
                        histos[single_hist].Fill(eta, pt, evt_weight)
                        if charge * (11) == pdgid:  ##e- --> -11; e+ --> 11 MISMEASURED ELECTRON
                            single_hist = "%s/flipped_%s" % (folder, el)
                            histos[single_hist].Fill(eta, pt, evt_weight)
                            histos["%s/flipped_electrons" % folder].Fill(eta, pt, evt_weight)
Example #2
0
def control_region_muon(row):
    # Figure out what control region we are in.
    if selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts') and row.eMtToMET > 35 and row.mMtToMET < 35 and row.bjetCSVVetoZHLike == 0:
        return 'MwjetsLtLow'
    elif selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts') and row.eMtToMET > 35 and row.mMtToMET < 35 and row.bjetCSVVetoZHLike > 0:
        return 'Mttbar'
    elif row.eRelPFIsoDB > 0.3 and row.type1_pfMetEt < 25: # selections.electronIds['eid12Medium'](row, 'e') and
        return 'Mqcd'
    else:
        return None
Example #3
0
        def fill(the_histos, row, fillNtuple=False):
            weight = 1
            if row.run == 1:
                weight = self.pucorrector(row.nTruePU)

            the_histos['electronPt'].Fill(row.e2Pt)
            the_histos['electronJetPt'].Fill(max(row.e2JetPt, row.e2Pt))
            the_histos['electronAbsEta'].Fill(row.e2AbsEta)
            #the_histos['metSignificance'].Fill(row.metSignificance)
            the_histos['e1MtToMET'].Fill(row.e1MtToMET)
            the_histos['e2MtToMET'].Fill(row.e2MtToMET)
            the_histos['MET'].Fill(row.type1_pfMetEt)
            the_histos['OSS'].Fill(int(row.e1_e2_SS))

            the_histos['e2JetptD'].Fill(row.e2JetptD)
            the_histos['e2Jetmult'].Fill(row.e2Jetmult)

            the_histos['e2Jetmultvse2JetPt'].Fill(max(row.e2JetPt, row.e2Pt),row.e2Jetmult)
            the_histos['e2JetptDvse2JetPt'].Fill(max(row.e2JetPt, row.e2Pt),row.e2JetptD) 
                
            the_histos['e1e2Mass'].Fill(row.e1_e2_Mass)
            the_histos['doubleEPrescale'].Fill(row.doubleEPrescale)

            if fillNtuple:
                id_iso_vals = [  selections.lepton_id_iso(row, 'e2', label)  for label in self.lepIds]
                #print id_iso_vals
                #print self.lepIds
                id_iso_vals = [float( i ) for i in id_iso_vals ]
                the_histos['electronInfo'].Fill( array("f", [row.e2Pt, row.e2JetPt, weight]+id_iso_vals) )
Example #4
0
 def fill(the_histos, row, fillNtuple=False):
     weight = 1
     if row.run == 1:
         weight = self.pucorrector(row.nTruePU) *\
                  mcCorrectors.correct_mueg_mu(row.mPt, row.mAbsEta) * \
                  mcCorrectors.correct_mueg_e(row.ePt, row.eAbsEta)
     
     the_histos['ePt'].Fill(row.ePt)
     the_histos['eJetPt'].Fill(max(row.eJetPt, row.ePt))
     the_histos['eAbsEta'].Fill(row.eAbsEta)
     #the_histos['metSignificance'].Fill(row.metSignificance)
     the_histos['mMtToMET'].Fill(row.mMtToMET)
     the_histos['eJetptD'].Fill(row.mJetptD)
     the_histos['eJetmult'].Fill(row.mJetmult)
     the_histos['eJetmultvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetmult)
     the_histos['eJetptDvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetptD) 
     if fillNtuple:
         id_iso_vals = [ float( selections.lepton_id_iso(row, 'e', label) ) for label in self.lepIds]
         the_histos['electronInfo'].Fill( array("f", [row.ePt, row.eJetPt, weight]+id_iso_vals) )
Example #5
0
        def fill(the_histos, row, fillNtuple=False):
            weight = 1
            if row.run == 1:
                weight = self.pucorrector(row.nTruePU) *\
                         mcCorrectors.correct_mueg_mu(row.mPt, row.mAbsEta) * \
                         mcCorrectors.correct_mueg_e(row.ePt, row.eAbsEta)
            
            the_histos['ePt'].Fill(row.ePt)
            the_histos['eJetPt'].Fill(max(row.eJetPt, row.ePt))
            the_histos['eAbsEta'].Fill(row.eAbsEta)
            #the_histos['metSignificance'].Fill(row.metSignificance)
            the_histos['mMtToMET'].Fill(row.mMtToMET)
            the_histos['eJetptD'].Fill(row.mJetptD)
            the_histos['eJetmult'].Fill(row.mJetmult)
            the_histos['eJetmultvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetmult)
            the_histos['eJetptDvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetptD) 
            if fillNtuple:
                id_iso_vals = [ float( selections.lepton_id_iso(row, 'e', label) ) for label in self.lepIds]
                electron_jet_mass = -1. #inv_mass(row.ePt, row.eEta, row.ePhi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi)
                
                the_histos['electronInfo'].Fill( array("f", [row.ePt, max(row.eJetPt, row.ePt), max(0, row.eJetCSVBtag), 
                                                             electron_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) )

                the_histos['evtInfo'].Fill(row)
Example #6
0
 def obj2_id( row, ledleptonId='h2taucuts', subledleptonId='h2taucuts'):
     return selections.lepton_id_iso(row, 'e', subledleptonId)
Example #7
0
 def obj2_id(self, row):
     return selections.lepton_id_iso(row, 'e2', subleading_iso)
Example #8
0
 def obj1_id(self, row):
     return selections.lepton_id_iso(row, 'e1', leading_iso)
Example #9
0
 def obj2_id(row, leadleptonId=None, subleadleptonId='eid13Looseh2taucuts'):
     return selections.lepton_id_iso(row, 'e2', subleadleptonId)
Example #10
0
    def process(self):
        cut_flow_histo = self.cut_flow_histo
        cut_flow_trk   = cut_flow_tracker(cut_flow_histo)

        def preselection(row):
            if not row.e_m_SS: return False
            cut_flow_trk.Fill('e_m_SS')

            if row.e_m_DR < 0.5:                      return False
            cut_flow_trk.Fill('e_m_DR')

            if not selections.muSelection(row, 'm'):  return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
            cut_flow_trk.Fill('mu presel')

            if not selections.eSelection(row, 'e'):   return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight)
            if not row.eChargeIdTight:                return False
            cut_flow_trk.Fill('e presel')

            #if not (row.jetVeto40_DR05 >= 1):         return False
            if row.jetVeto20 == 0: return False
            cut_flow_trk.Fill('jet presence')

            if not selections.vetos(row, cut_flow_trk, False):  return False #applies mu bjet e additional tau vetoes
            #DO NOT APPLY BJet veto. It is used for ttbar CR
            return True
        #if self.is7TeV:
            #base_selection = 'mu17ele8Pass && ' + base_selection

        def fill(the_histos, row, fillNtuple=False):
            weight = 1
            if row.run == 1:
                weight = self.pucorrector(row.nTruePU) *\
                         mcCorrectors.correct_mueg_mu(row.mPt, row.mAbsEta) * \
                         mcCorrectors.correct_mueg_e(row.ePt, row.eAbsEta)
            
            the_histos['ePt'].Fill(row.ePt)
            the_histos['eJetPt'].Fill(max(row.eJetPt, row.ePt))
            the_histos['eAbsEta'].Fill(row.eAbsEta)
            #the_histos['metSignificance'].Fill(row.metSignificance)
            the_histos['mMtToMET'].Fill(row.mMtToMET)
            the_histos['eJetptD'].Fill(row.mJetptD)
            the_histos['eJetmult'].Fill(row.mJetmult)
            the_histos['eJetmultvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetmult)
            the_histos['eJetptDvseJetPt'].Fill(max(row.eJetPt, row.ePt),row.eJetptD) 
            if fillNtuple:
                id_iso_vals = [ float( selections.lepton_id_iso(row, 'e', label) ) for label in self.lepIds]
                electron_jet_mass = -1. #inv_mass(row.ePt, row.eEta, row.ePhi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi)
                
                the_histos['electronInfo'].Fill( array("f", [row.ePt, max(row.eJetPt, row.ePt), max(0, row.eJetCSVBtag), 
                                                             electron_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight]+id_iso_vals) )

                the_histos['evtInfo'].Fill(row)

        def fill_muon(the_histos, row, fillNtuple=False):
            weight = 1.
            if row.run == 1:
                weight = self.pucorrector(row.nTruePU) *\
                         mcCorrectors.correct_mueg_mu(row.mPt, row.mAbsEta) * \
                         mcCorrectors.correct_mueg_e(row.ePt, row.eAbsEta)
                        
            the_histos['muonPt'].Fill(row.mPt, weight)
            the_histos['eMtToMET'].Fill(row.eMtToMET)
            the_histos['muonJetPt'].Fill(max(row.mJetPt, row.mPt), weight)
            the_histos['muonAbsEta'].Fill(row.mAbsEta, weight)
            the_histos['muonPtRatio'].Fill(row.mPt/max(row.mJetPt, row.mPt), weight)
            the_histos['muonPtDiff'].Fill(max(row.mJetPt, row.mPt) - row.mPt, weight)
            if fillNtuple:
                pfidiso02    = float( row.mPFIDTight and row.mRelPFIsoDB < 0.2)
                h2taucuts    = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.15 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.1 ))
                h2taucuts020 = float( row.mPFIDTight and ((row.mRelPFIsoDB < 0.20 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.15))
                muon_jet_mass = -1. #inv_mass(row.mPt, row.mEta, row.mPhi, row.leadingJetPt, row.leadingJetEta, row.leadingJetPhi)
                
                the_histos['muonInfo'].Fill( array("f", [row.mPt, max(row.mJetPt, row.mPt), max(0, row.mJetCSVBtag), 
                                                         muon_jet_mass, row.jetVeto20, row.jetVeto40_DR05, weight, 
                                                         pfidiso02, h2taucuts, h2taucuts020] ) )

                the_histos['evtInfo'].Fill(row)
                
        def fill_region(region,pt_cut):
            if region is None:
                return None
            fill(histos[(region, pt_cut)], row, True)

            for idlabel, idfcn in selections.electronIds.iteritems():                
                if not idfcn(row, 'e'): #if it does not pass id skip!
                    continue

                if row.eRelPFIsoDB < 0.2:
                    fill(histos[(region, pt_cut, idlabel+'_idiso02')], row)

                if (row.eRelPFIsoDB < 0.15 and row.eAbsEta < 1.479) or row.eRelPFIsoDB < 0.1:
                    fill(histos[(region, pt_cut, idlabel+'_h2taucuts')], row)

                if (row.eRelPFIsoDB < 0.20 and row.eAbsEta < 1.479) or row.eRelPFIsoDB < 0.15:
                    fill(histos[(region, pt_cut, idlabel+'_h2taucuts020')], row)

        def fill_muon_region(region, tag):
            if region is None:
                return None
            # This is a QCD or Wjets
            fill_muon(histos[(region, tag)], row, True)
            
            if row.mPFIDTight:
                if row.mRelPFIsoDB < 0.2:
                    fill_muon(histos[(region, tag, 'pfidiso02')], row)
                    
                if (row.mRelPFIsoDB < 0.15 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.1:
                    fill_muon(histos[(region, tag, 'h2taucuts')], row)

                if (row.mRelPFIsoDB < 0.20 and row.mAbsEta < 1.479) or row.mRelPFIsoDB < 0.15:
                    fill_muon(histos[(region, tag, 'h2taucuts020')], row)

                
        histos = self.histograms
        for row in self.tree:
            cut_flow_trk.new_row(row.run,row.lumi,row.evt)
            cut_flow_trk.Fill('bare')
            if not preselection(row):
                continue
            region = control_region(row)
            muon_region = control_region_muon(row)

            is7TeV = bool('7TeV' in os.environ['jobid'])
            use_iso_trigger = not is7TeV
            mu17e8 = (row.mu17ele8isoPass and row.mPt >= 20) if use_iso_trigger else (row.mu17ele8Pass and row.mPt >= 20)
            mu8e17 = (row.mu8ele17isoPass and row.ePt >= 20) if use_iso_trigger else (row.mu8ele17Pass and row.ePt >= 20)

            if env_lepton and env_lepton == 'e':
                if mu17e8:
                    cut_flow_trk.Fill('trigger')
                    if row.mPFIDTight and row.mRelPFIsoDB < 0.15:
                        cut_flow_trk.Fill('tag ID ISO')
                        if row.mMtToMET > 35:
                            cut_flow_trk.Fill('tag MT')
                            if row.eMtToMET < 35:
                                cut_flow_trk.Fill('probe MT')

            elif env_lepton and env_lepton == 'm':
                if mu8e17:
                    cut_flow_trk.Fill('trigger')
                    if selections.lepton_id_iso(row, 'e', 'eid12Medium_h2taucuts'):
                        cut_flow_trk.Fill('tag ID ISO')
                        if row.eMtToMET > 35:
                            cut_flow_trk.Fill('tag MT')
                            if row.mMtToMET < 35:
                                cut_flow_trk.Fill('probe MT')

            cut_flow_trk.flush()

            if mu17e8:
                fill_region(region,'pt10')
                if region == 'wjetsLtLow' and row.mMtToMET > 55:
                    fill_region('wjets', 'pt10')
            if mu8e17:
                fill_region(region,'pt20')
                if region == 'wjetsLtLow' and row.mMtToMET > 55:
                    fill_region('wjets', 'pt20')
                if muon_region:
                    fill_muon_region(muon_region, 'pt10')
                    if muon_region == 'MwjetsLtLow' and row.eMtToMET > 55:
                        fill_muon_region('Mwjets', 'pt10')
                    if row.mPt > 20:
                        fill_muon_region(muon_region, 'pt20')
                        if muon_region == 'MwjetsLtLow' and row.eMtToMET > 55:
                            fill_muon_region('Mwjets', 'pt20')
Example #11
0
 def obj2_id(row, leadleptonId=None, subleadleptonId='h2taucuts'):
     return selections.lepton_id_iso(row, 'm2', subleadleptonId)
Example #12
0
 def obj1_id(row, leadleptonId='h2taucuts', subleadleptonId=None):
     return selections.lepton_id_iso(row, 'm1', leadleptonId)
Example #13
0
 def obj2_id(self, row):
     return selections.lepton_id_iso(row, 'm2', subleptonId )
Example #14
0
 def obj1_id(self, row):
     return selections.lepton_id_iso(row, 'm1', leadleptonId)