Example #1
0
    def preselection(self, row, cut_flow_trk = None, LT_threshold = 80.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        double_mu_pass = row.doubleMuPass #and \
            ## row.m1MatchesDoubleMu2011Paths > 0 and \
            ## row.m2MatchesDoubleMu2011Paths > 0
        if not ( double_mu_pass ): return False
        cut_flow_trk.Fill('trigger')

        if row.m1Pt < row.m2Pt:                   return False
        if row.m1Pt < 20:                         return False
        if not selections.muSelection(row, 'm1'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
        cut_flow_trk.Fill('obj1 Presel')

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

        if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ)
        if not row.tAntiElectronMVA3Loose:        return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.m1_m2_SS and row.m1_t_SS: return False #remove three SS leptons
        if row.m1_m2_Mass < 20:          return False
        if not selections.vetos(row):    return False #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')
        cut_flow_trk.Fill('charge_fakes') #no charge fakes here

        return True
Example #2
0
    def preselection(self, row, cut_flow_trk = None, LT_threshold = 80.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if not row.doubleEPass:                   return False
	if not (row.e1MatchesDoubleEPath > 0 and \
		row.e2MatchesDoubleEPath > 0): return False 
        cut_flow_trk.Fill('trigger')

        if not selections.eSelection(row, 'e1'):  return False
        cut_flow_trk.Fill('obj1 Presel')

        if not selections.eSelection(row, 'e2'):  return False
        cut_flow_trk.Fill('obj2 Presel')

        if not selections.tauSelection(row, 't'): return False
        if not row.tAntiMuonLoose:   return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.e1_e2_SS and row.e1_t_SS         : return False #remove three SS leptons
        if row.e1_e2_Mass < 20:                   return False
        if not selections.vetos(row):             return False #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')

        #REMOVE CHARGE FAKES!
        if not self.logic_cut_met(row, 1.): return False
        cut_flow_trk.Fill('charge_fakes')  

        return True
Example #3
0
    def preselection( self, row, cut_flow_trk = None, LT_threshold = 80.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        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.mu17ele8Pass and row.mPt < 20)
        if not (mu17e8 or mu8e17):                return False
        cut_flow_trk.Fill('trigger')

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

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

        if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ)
        if row.tMuOverlap:         return False
        if not row.tAntiMuonTight: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold:            return False
        cut_flow_trk.Fill('LT')

        if row.e_m_SS and row.e_t_SS: return False #remove three SS leptons
        if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')
        cut_flow_trk.Fill('charge_fakes') #no charge fakes here

        return True
Example #4
0
    def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if row.e_t_DR < 0.5 or row.m_t_DR < 0.5 or row.e_m_DR < 0.5: return False
        cut_flow_trk.Fill('DR separation')

        if self.hfunc['subMass'](row, 1)[0] < 20: return False
        cut_flow_trk.Fill('sub mass cut')

        mu17e8, mu8e17 = False, False
        if use_iso_trigger:
            mu17e8 = row.mu17ele8isoPass and \
                row.mMatchesMu17Ele8IsoPath > 0 and \
                row.eMatchesMu17Ele8IsoPath > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17isoPass and \
                row.mMatchesMu8Ele17IsoPath > 0 and \
                row.eMatchesMu8Ele17IsoPath > 0 and \
                row.ePt >= 20
        else:
            mu17e8 = row.mu17ele8Pass and \
                row.mMatchesMu17Ele8Path > 0 and \
                row.eMatchesMu17Ele8Path > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17Pass and \
                row.mMatchesMu8Ele17Path > 0 and \
                row.eMatchesMu8Ele17Path > 0 and \
                row.ePt >= 20
            
        if not (mu17e8 or mu8e17):                return False
        cut_flow_trk.Fill('trigger')

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

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

        if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ)
        if row.tPt < taupt_thr: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold:            return False
        cut_flow_trk.Fill('LT')

        if row.e_m_Mass < 20:          return False
        cut_flow_trk.Fill('dilepton mass cut')

        if not selections.vetos(row, cut_flow_trk): return False #applies mu bjet e additional tau vetoes

        cut_flow_trk.Fill('charge_fakes') #no charge fakes here

        return True
Example #5
0
    def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        double_mu_pass =  row.doubleMuPass and \
            row.m1MatchesDoubleMuPaths > 0 and \
            row.m2MatchesDoubleMuPaths > 0
        double_muTrk_pass = row.doubleMuTrkPass and \
             row.m1MatchesDoubleMuTrkPaths > 0 and \
             row.m2MatchesDoubleMuTrkPaths > 0
        if not ( double_mu_pass or double_muTrk_pass ): return False
        cut_flow_trk.Fill('trigger')

        if row.m1Pt < row.m2Pt:                   return False
        if row.m1Pt < 20:                         return False
        if not selections.muSelection(row, 'm1'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
        cut_flow_trk.Fill('obj1 Presel')
        #cut_flow_trk.Fill('pt requirements 1', 'eta requirements 1', 'MissingHits 1', 'HasConversion 1', 'JetBtag 1', 'DZ 1',)


        if not selections.muSelection(row, 'm2'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
        cut_flow_trk.Fill('obj2 Presel')
        #cut_flow_trk.Fill('pt requirements 2', 'eta requirements 2', 'MissingHits 2', 'HasConversion 2', 'JetBtag 2', 'DZ 2',)

        if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ)
        if not row.tAntiElectronMVA3Loose:        return False
        if row.tPt < taupt_thr: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.m1_m2_SS and row.m1_t_SS: return False #remove three SS leptons
        if row.m1_m2_Mass < 20:          return False
        if not selections.vetos(row):    return False #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')
        #cut_flow_trk.Fill('ChargeIdTight')
        cut_flow_trk.Fill('charge_fakes') #no charge fakes here
        
        #FIXME: ONLY FOR CUT-FLOW PRODUCTION
        #if not row.m1PFIDTight: return False
        #cut_flow_trk.Fill('obj1 ID')
        #if not selections.lepton_id_iso(row, 'm1', 'h2taucuts'): return False
        #cut_flow_trk.Fill('obj1 Iso')
        #if not row.m2PFIDTight: return False
        #cut_flow_trk.Fill('obj2 ID')
        #if not selections.lepton_id_iso(row, 'm2', 'h2taucuts'): return False
        #cut_flow_trk.Fill('obj2 Iso')
        #if not row.tLooseIso3Hits: return False
        #cut_flow_trk.Fill('obj3 IDIso')
        
        return True
Example #6
0
    def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''

        #
        # NEW EXPLICIT CUT, BEFORE IT WAS IMPLICIT AND MADE WHILE PLOTTING!
        #
        if row.m1_t_DR < 0.5 or row.m2_t_DR < 0.5 or row.m1_m2_DR < 0.5: return False
        cut_flow_trk.Fill('DR separation')

        if row.m2_t_Mass < 20: return False
        cut_flow_trk.Fill('sub mass cut')

        double_mu_pass =  row.doubleMuPass and \
            row.m1MatchesDoubleMuPaths > 0 and \
            row.m2MatchesDoubleMuPaths > 0
        double_muTrk_pass = row.doubleMuTrkPass and \
             row.m1MatchesMu17TrkMu8Path  > 0 and \
             row.m2MatchesMu17TrkMu8Path  > 0
        if not ( double_mu_pass or double_muTrk_pass ): return False
        cut_flow_trk.Fill('trigger')

        if row.m1Pt < row.m2Pt:                   return False
        if row.m1Pt < 20:                         return False
        if not selections.muSelection(row, 'm1'): return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
        cut_flow_trk.Fill('obj1 Presel')

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

        if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ)
        if not row.tAntiElectronMVA3Loose:        return False
        if row.tPt < taupt_thr: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.m1_m2_Mass < 20:          return False
        cut_flow_trk.Fill('dilepton mass cut')

        if not selections.vetos(row, cut_flow_trk):    return False #applies mu bjet e additional tau vetoes
        
        return True
Example #7
0
    def preselection(self,
                     row,
                     cut_flow_trk=None,
                     LT_threshold=80.,
                     taupt_thr=0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if row.e1_t_DR < 0.5 or row.e2_t_DR < 0.5 or row.e1_e2_DR < 0.5:
            return False
        cut_flow_trk.Fill('DR separation')

        if row.e2_t_Mass < 20: return False
        cut_flow_trk.Fill('sub mass cut')

        if not row.doubleEPass: return False
        if not (row.e1MatchesDoubleEPath > 0 and \
         row.e2MatchesDoubleEPath > 0):
            return False
        cut_flow_trk.Fill('trigger')

        if row.e1Pt < 20: return False
        if not selections.eSelection(row, 'e1'): return False
        cut_flow_trk.Fill('obj1 Presel')

        if not selections.eSelection(row, 'e2'): return False
        cut_flow_trk.Fill('obj2 Presel')

        if not selections.tauSelection(row, 't'): return False
        if row.tPt < taupt_thr: return False
        if not row.tAntiMuonLoose: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        #if row.e1_e2_SS and row.e1_t_SS: return False #remove three SS leptons
        if row.e1_e2_Mass < 20: return False
        cut_flow_trk.Fill('dilepton mass cut')

        if not selections.vetos(row, cut_flow_trk):
            return False  #applies mu bjet e additional tau vetoes

        return True
Example #8
0
    def process(self):

        #print self.tree.inputfilename
        for row in self.tree:
            jn = row.jetVeto30
            if jn > 3: jn = 3

            if not bool(row.singleE27WP80Pass): continue

            if not bool(row.eMatchesSingleE27WP80): continue

            if row.bjetCSVVeto30 != 0: continue
            if not selections.eLowPtSelection(row, 'e'): continue
            if not selections.lepton_id_iso(row, 'e', 'eid13Loose_idantiso'):
                continue
            if abs(row.eEta) > 1.4442 and abs(row.eEta < 1.566): continue

            if not selections.tauSelection(row, 't'): continue
            if row.tPt < 30: continue

            if not row.tAntiMuon2Loose: continue
            if not row.tAntiElectronMVA5Tight: continue  #was 3
            if row.tauVetoPt20EleTight3MuLoose: continue
            #if row.tauHpsVetoPt20 : continue
            if row.muVetoPt5IsoIdVtx: continue
            if row.eVetoCicLooseIso: continue  # change it with Loose

            sign = 'ss' if row.e_t_SS else 'os'
            if row.tLooseIso3Hits:
                tauiso = 'tLoose'
                folder = sign + '/' + tauiso
                self.fill_histos(row, folder)
                folder = folder + '/' + str(int(jn))
                self.fill_histos(row, folder)

            if row.tTightIso3Hits:
                tauiso = 'tTigh'
                folder = sign + '/' + tauiso
                self.fill_histos(row, folder)
                folder = folder + '/' + str(int(jn))
                self.fill_histos(row, folder)
Example #9
0
    def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if row.e1_t_DR < 0.5 or row.e2_t_DR < 0.5 or row.e1_e2_DR < 0.5: return False
        cut_flow_trk.Fill('DR separation')

        if row.e2_t_Mass < 20: return False
        cut_flow_trk.Fill('sub mass cut')

        if not row.doubleEPass:                   return False
	if not (row.e1MatchesDoubleEPath > 0 and \
		row.e2MatchesDoubleEPath > 0): return False 
        cut_flow_trk.Fill('trigger')

	if row.e1Pt < 20:           return False
        if not selections.eSelection(row, 'e1'):  return False
	cut_flow_trk.Fill('obj1 Presel')

        if not selections.eSelection(row, 'e2'):  return False
        cut_flow_trk.Fill('obj2 Presel')

        if not selections.tauSelection(row, 't'): return False
        if row.tPt < taupt_thr: return False
        if not row.tAntiMuonLoose:   return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        #if row.e1_e2_SS and row.e1_t_SS: return False #remove three SS leptons
        if row.e1_e2_Mass < 20:          return False
        cut_flow_trk.Fill('dilepton mass cut')

        if not selections.vetos(row, cut_flow_trk):    return False #applies mu bjet e additional tau vetoes

        return True
Example #10
0
    def preselection(self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if not row.doubleEPass:                   return False
	if not (row.e1MatchesDoubleEPath > 0 and \
		row.e2MatchesDoubleEPath > 0): return False 
        cut_flow_trk.Fill('trigger')

	if row.e1Pt < 20:           return False
        if not selections.eSelection(row, 'e1'):  return False
	cut_flow_trk.Fill('obj1 Presel')
        #FIXME
    	#if row.e1Pt < 20:           return False
	#cut_flow_trk.Fill('pt requirements 1')
    	#if row.e1AbsEta > 2.5:      return False
	#cut_flow_trk.Fill('eta requirements 1')
    	#if row.e1MissingHits:       return False
	#cut_flow_trk.Fill('MissingHits 1')
    	#if row.e1HasConversion:     return False
	#cut_flow_trk.Fill('HasConversion 1')
    	#if row.e1JetBtag > 3.3:     return False
	#cut_flow_trk.Fill('JetBtag 1')
    	#if abs(row.e1DZ) > 0.2:     return False
	#cut_flow_trk.Fill('DZ 1')

        if not selections.eSelection(row, 'e2'):  return False
        cut_flow_trk.Fill('obj2 Presel')
        #FIXME
    	#if row.e2Pt < 10:           return False
	#cut_flow_trk.Fill('pt requirements 2')
    	#if row.e2AbsEta > 2.5:      return False
	#cut_flow_trk.Fill('eta requirements 2')
    	#if row.e2MissingHits:       return False
	#cut_flow_trk.Fill('MissingHits 2')
    	#if row.e2HasConversion:     return False
	#cut_flow_trk.Fill('HasConversion 2')
    	#if row.e2JetBtag > 3.3:     return False
	#cut_flow_trk.Fill('JetBtag 2')
    	#if abs(row.e2DZ) > 0.2:     return False
	#cut_flow_trk.Fill('DZ 2')

        if not selections.tauSelection(row, 't'): return False
        if row.tPt < taupt_thr: return False
        if not row.tAntiMuonLoose:   return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.e1_e2_SS and row.e1_t_SS: return False #remove three SS leptons
        if row.e1_e2_Mass < 20:          return False
        if not selections.vetos(row):    return False #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')

        #REMOVE CHARGE FAKES!
        #FIXME
    	#if not row.e1ChargeIdLoose: return False
    	#if not row.e2ChargeIdLoose: return False
	#cut_flow_trk.Fill('ChargeIdLoose')
        #cut_flow_trk.Fill('charge_fakes')  

        #FIXME: ONLY FOR CUT-FLOW PRODUCTION
        #if not selections.summer_2013_eid(row, 'e1'): return False
        #cut_flow_trk.Fill('obj1 ID')
        #if not selections.lepton_id_iso(row, 'e1', 'eid13Looseh2taucuts'): return False
        #cut_flow_trk.Fill('obj1 Iso')
        #if not selections.summer_2013_eid(row, 'e2'): return False
        #cut_flow_trk.Fill('obj2 ID')
        #if not selections.lepton_id_iso(row, 'e2', 'eid13Looseh2taucuts'): return False
        #cut_flow_trk.Fill('obj2 Iso')
        #if not row.tLooseIso3Hits: return False
        #cut_flow_trk.Fill('obj3 IDIso')

        return True
Example #11
0
    def process(self):
        logging.debug('Starting processing')
        systematics = self.systematics

        frw = []
        lock = ()
        ievt = 0
        logging.debug('Starting evt loop')

        #pre-compute static things
        sys_shifts = systematics['trig']  # + \
        #         systematics['pu'] + \
        #         systematics['eid'] + \
        #         systematics['eiso'] #+ \

        jes_dirs = [i.strip('_') for i in systematics['jes']]
        #anyway the first is always ""
        tes_dirs = [i.strip('_') for i in systematics['tes']][1:]
        ees_dirs = [i.strip('_') for i in systematics['ees']][1:]

        for row in self.tree:
            if (ievt % 100) == 0:
                logging.debug('New event')
            ievt += 1
            #avoid double counting events!
            evt_id = (row.run, row.lumi, row.evt)
            if evt_id == lock: continue
            if lock != () and evt_id == lock:
                logging.info('Removing duplicate of event: %d %d %d' % evt_id)

            #
            #preselection, common to everything and everyone
            #
            #trigger
            if self.is_embedded:
                if not bool(row.doubleMuPass): continue
            else:
                if not bool(row.singleE27WP80Pass): continue
                if not bool(row.eMatchesSingleE27WP80): continue

            #objects
            if not selections.eSelection(row, 'e'): continue
            #if row.ePt < 30 : continue
            if not selections.tauSelection(row, 't'): continue
            if not row.tAntiElectronMVA5Tight: continue
            if not row.tAntiMuon2Loose: continue
            if not row.tLooseIso3Hits: continue
            logging.debug('object selection passed')
            #e ID/ISO
            if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'):
                continue
            logging.debug('Passed preselection')

            #
            # Compute event weight
            #
            #event weight
            #sys_shifts is precomputed

            #set_trace()
            weight_map = self.event_weight(row, sys_shifts)

            #Fill embedded sample normalization BEFORE the vetoes
            #        if not row.e_t_SS:
            #            self.fill_histos('os/gg/ept30', row, weight_map[''])

            # it is better vetoing on b-jets  after the histo for the DY embedded
            #bjet veto
            if row.bjetCSVVeto30 != 0: continue

            #tau ID, id Tau is tight then go in full selection, otherwise use for fakes
            isTauTight = bool(row.tTightIso3Hits)
            isETight = bool(
                selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'))
            #         etau_category = ['']
            #         if (not isETight) and (not isTauTight):
            #             etau_category = ['etLoose', 'etLoose/Up', 'etLoose/Down']
            #         elif (not isTauTight):
            #             etau_category = ['tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight']
            #         elif (not isETight):
            #             etau_category = ['eLoose', 'eLoose/Up', 'eLoose/Down']

            #jet category
            central = struct(njets=min(row.jetVeto30, 3),
                             tPt=row.tPt,
                             ePt=row.ePt)
            jets = [
                min(row.jetVeto30, 3),
                min(row.jetVeto30jes_plus, 3),
                min(row.jetVeto30jes_minus, 3)
            ]
            tpts = [row.tPt_tes_plus, row.tPt_tes_minus]
            epts = [row.ePt_ees_plus, row.ePt_ees_minus]
            sys_effects = [(name, central.clone(njets=jnum))
                           for name, jnum in zip(jes_dirs, jets)]
            #            sys_effects.extend(
            #                [(name, central.clone(tPt = pt)) for name, pt in zip(tes_dirs, tpts)]
            #                )
            #            sys_effects.extend(
            #                [(name, central.clone(ePt = pt)) for name, pt in zip(ees_dirs, epts)]
            #                )

            #
            # Full tight selection
            #
            passes_full_selection = False
            selection_categories = []
            #  for name, shifted in sys_effects:
            #preselection. flat pt values
            if row.ePt < 30 and row.tPt < 30:
                #        selection_categories.append((name, '%i' % shifted.njets, ''))
                #   else:
                continue

            #   if shifted.njets == 0 :
            #       if shifted.tPt < 35: continue
            #       if shifted.ePt < 40: continue
            #       if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue
            #       if row.tMtToPfMet > 50 : continue
            #       selection_categories.append((name, '0', 'selected'))
            #       passes_full_selection = True
            #   elif shifted.njets == 1 :
            #       if shifted.tPt < 40: continue
            #       if shifted.ePt < 35: continue
            #       if row.tMtToPfMet > 35 : continue
            #       selection_categories.append((name, '1', 'selected'))
            #       passes_full_selection = True
            #   elif shifted.njets == 2 :
            #       if shifted.tPt < 40: continue
            #       if shifted.ePt < 30: continue
            #       if row.tMtToPfMet > 35 : continue
            #       if row.vbfMass < 550 : continue
            #       if row.vbfDeta < 3.5 : continue
            #       selection_categories.append((name, '2', 'selected'))
            #       passes_full_selection = True
            #dir_name1 = os.path.join(sys, selection_sys, sign, processtype,
            #                        e_thr, jet_dir, selection_step)
    #       tvetoes = [row.tauVetoPt20EleTight3MuLoose, row.tauVetoPt20EleTight3MuLoose_tes_plus, row.tauVetoPt20EleTight3MuLoose_tes_minus]
    #       mvetoes = [row.muVetoPt5IsoIdVtx          , row.muVetoPt5IsoIdVtx_mes_plus          , row.muVetoPt5IsoIdVtx_mes_minus          ]
    #       evetoes = [row.eVetoCicLooseIso           , row.eVetoCicLooseIso_ees_plus           , row.eVetoCicLooseIso_ees_minus           ]

    #       tdirs = [ i for i, j in zip( systematics['tvetos'], tvetoes) if not j]
    #       mdirs = [ i for i, j in zip( systematics['mvetos'], mvetoes) if not j]
    #       edirs = [ i for i, j in zip( systematics['evetos'], evetoes) if not j]

    #if any of the lists is empty
    #set_trace()
    #       if not tdirs or not mdirs or not edirs:
    #           continue
    #       logging.debug('Passed Vetoes')
            jet0panel = [('tPtcut', 1, 1, 30, 70), ('ePtcut', 1, 1, 30, 70),
                         ('deltaPhicut', 1, 1, 20, 35),
                         ('tMtToPFMETcut', 1, 1, 20, 80)]
            jet1panel = [('tPtcut', 1, 1, 30, 70), ('ePtcut', 1, 1, 30, 70),
                         ('tMtToPFMETcut', 1, 1, 20, 80)]
            jet2panel = [('tPtcut', 1, 1, 30, 70), ('ePtcut', 1, 1, 30, 70),
                         ('tMtToPFMETcut', 1, 1, 20, 80),
                         ('vbfMasscut', 1, 4, 300, 700),
                         ('vbfDetacut', 1, 1, 20, 60)]
            jet0refer = (30, 30, 2, 80)
            jet1refer = (30, 30, 80)
            jet2refer = (30, 30, 80, 300, 2)
            if (not isETight) or (not isTauTight):
                continue
            jn = row.jetVeto30
            if jn > 3: jn = 3
            jetlist = [(int(jn), str(int(jn)))]
            for jet in jetlist:
                foldertofill = 'os/gg/ept30/' + jet[1] + '/selected'
                if jets[0] == 0:
                    for nbjet0, jetwhole0 in enumerate(jet0panel):
                        if nbjet0 == 0 and jetwhole0[1] == 1:
                            for j in range(jetwhole0[3], jetwhole0[4],
                                           jetwhole0[2]):
                                if row.tPt < j: continue
                                if row.ePt < jet0refer[1]: continue
                                if deltaPhi(row.ePhi, row.tPhi) < jet0refer[2]:
                                    continue
                                if row.tMtToPfMet > jet0refer[3]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole0[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet0 == 1 and jetwhole0[1] == 1:
                            for j in range(jetwhole0[3], jetwhole0[4],
                                           jetwhole0[2]):
                                if row.tPt < jet0refer[0]: continue
                                if row.ePt < j: continue
                                if deltaPhi(row.ePhi, row.tPhi) < jet0refer[2]:
                                    continue
                                if row.tMtToPfMet > jet0refer[3]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole0[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet0 == 2 and jetwhole0[1] == 1:
                            for j in range(jetwhole0[3], jetwhole0[4],
                                           jetwhole0[2]):
                                if row.tPt < jet0refer[0]: continue
                                if row.ePt < jet0refer[1]: continue
                                if deltaPhi(row.ePhi, row.tPhi) < j / 10.0:
                                    continue
                                if row.tMtToPfMet > jet0refer[3]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole0[0], j / 10.0,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet0 == 3 and jetwhole0[1] == 1:
                            for j in range(jetwhole0[3], jetwhole0[4],
                                           jetwhole0[2]):
                                if row.tPt < jet0refer[0]: continue
                                if row.ePt < jet0refer[1]: continue
                                if deltaPhi(row.ePhi, row.tPhi) < jet0refer[2]:
                                    continue
                                if row.tMtToPfMet > j: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole0[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                elif jets[0] == 1:
                    for nbjet1, jetwhole1 in enumerate(jet1panel):
                        if nbjet1 == 0 and jetwhole1[1] == 1:
                            for j in range(jetwhole1[3], jetwhole1[4],
                                           jetwhole1[2]):
                                if row.tPt < j: continue
                                if row.ePt < jet1refer[1]: continue
                                if row.tMtToPfMet > jet1refer[2]: continue
                                #   selection_categories.append((name, '1', 'selected'))
                                passes_full_selection = True
                                self.fill_histos3(jetwhole1[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet1 == 1 and jetwhole1[1] == 1:
                            for j in range(jetwhole1[3], jetwhole1[4],
                                           jetwhole1[2]):
                                if row.tPt < jet1refer[0]: continue
                                if row.ePt < j: continue
                                if row.tMtToPfMet > jet1refer[2]: continue
                                #   selection_categories.append((name, '1', 'selected'))
                                passes_full_selection = True
                                self.fill_histos3(jetwhole1[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet1 == 2 and jetwhole1[1] == 1:
                            for j in range(jetwhole1[3], jetwhole1[4],
                                           jetwhole1[2]):
                                if row.tPt < jet1refer[0]: continue
                                if row.ePt < jet1refer[1]: continue
                                if row.tMtToPfMet > j: continue
                                #   selection_categories.append((name, '1', 'selected'))
                                passes_full_selection = True
                                self.fill_histos3(jetwhole1[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                elif jets[0] == 2:
                    for nbjet2, jetwhole2 in enumerate(jet2panel):
                        if nbjet2 == 0 and jetwhole2[1] == 1:
                            for j in range(jetwhole2[3], jetwhole2[4],
                                           jetwhole2[2]):
                                if row.tPt < j: continue
                                if row.ePt < jet2refer[1]: continue
                                if row.tMtToPfMet > jet2refer[2]: continue
                                if row.vbfMass < jet2refer[3]: continue
                                if row.vbfDeta < jet2refer[4]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole2[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet2 == 1 and jetwhole2[1] == 1:
                            for j in range(jetwhole2[3], jetwhole2[4],
                                           jetwhole2[2]):
                                if row.tPt < jet2refer[0]: continue
                                if row.ePt < j: continue
                                if row.tMtToPfMet > jet2refer[2]: continue
                                if row.vbfMass < jet2refer[3]: continue
                                if row.vbfDeta < jet2refer[4]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole2[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet2 == 2 and jetwhole2[1] == 1:
                            for j in range(jetwhole2[3], jetwhole2[4],
                                           jetwhole2[2]):
                                if row.tPt < jet2refer[0]: continue
                                if row.ePt < jet2refer[1]: continue
                                if row.tMtToPfMet > j: continue
                                if row.vbfMass < jet2refer[3]: continue
                                if row.vbfDeta < jet2refer[4]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole2[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet2 == 3 and jetwhole2[1] == 1:
                            for j in range(jetwhole2[3], jetwhole2[4],
                                           jetwhole2[2]):
                                if row.tPt < jet2refer[0]: continue
                                if row.ePt < jet2refer[1]: continue
                                if row.tMtToPfMet > jet2refer[2]: continue
                                if row.vbfMass < j: continue
                                if row.vbfDeta < jet2refer[4]: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole2[0], j,
                                                  foldertofill, row,
                                                  weight_map[''])
                        if nbjet2 == 4 and jetwhole2[1] == 1:
                            for j in range(jetwhole2[3], jetwhole2[4],
                                           jetwhole2[2]):
                                if row.tPt < jet2refer[0]: continue
                                if row.ePt < jet2refer[1]: continue
                                if row.tMtToPfMet > jet2refer[2]: continue
                                if row.vbfMass < jet2refer[3]: continue
                                if row.vbfDeta < j / 10.0: continue
                                passes_full_selection = True
                                self.fill_histos3(jetwhole2[0], j / 10.0,
                                                  foldertofill, row,
                                                  weight_map[''])
                #   selection_categories.append((name, '2', 'selected'))

            if passes_full_selection:
                logging.debug('Passed full selection')
Example #12
0
    def process(self):
        logging.debug('Starting processing')
        systematics = self.systematics

        frw = []
        lock = ()
        ievt = 0
        logging.debug('Starting evt loop')

        #pre-compute static things
        sys_shifts = systematics['trig'] + \
            systematics['pu'] + \
            systematics['eid'] + \
            systematics['eiso'] #+ \

        jes_dirs = [i.strip('_') for i in systematics['jes']]
        #anyway the first is always ""
        tes_dirs = [i.strip('_') for i in systematics['tes']][1:]
        ees_dirs = [i.strip('_') for i in systematics['ees']][1:]

        for row in self.tree:
            if (ievt % 100) == 0:
                logging.debug('New event')
            ievt += 1
            #avoid double counting events!
            evt_id = (row.run, row.lumi, row.evt)
            if evt_id == lock: continue
            if lock != () and evt_id == lock:
                logging.info('Removing duplicate of event: %d %d %d' % evt_id)

            #
            #preselection, common to everything and everyone
            #
            #trigger
            if self.is_embedded:
                if not bool(row.doubleMuPass): continue
            else:
                if not bool(row.singleE27WP80Pass): continue
                if not bool(row.eMatchesSingleE27WP80): continue

            #objects
            if not selections.eSelection(row, 'e'): continue
            #if row.ePt < 30 : continue
            if not selections.tauSelection(row, 't'): continue
            if not row.tAntiElectronMVA5Tight: continue
            if not row.tAntiMuon2Loose: continue
            if not row.tLooseIso3Hits: continue
            logging.debug('object selection passed')
            #e ID/ISO
            if not selections.lepton_id_iso(row, 'e', 'eid13Tight_idiso02'):
                continue
            logging.debug('Passed preselection')

            #
            # Compute event weight
            #
            #event weight
            #sys_shifts is precomputed

            #set_trace()
            weight_map = self.event_weight(row, sys_shifts)

            #Fill embedded sample normalization BEFORE the vetoes
            if not row.e_t_SS:
                self.fill_histos('os/gg/ept30', row, weight_map[''])

            # it is better vetoing on b-jets  after the histo for the DY embedded
            #bjet veto
            if row.bjetCSVVeto30 == 0: continue

            #tau ID, id Tau is tight then go in full selection, otherwise use for fakes
            isTauTight = bool(row.tTightIso3Hits)
            isETight = bool(
                selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'))
            etau_category = ['']
            if (not isETight) and (not isTauTight):
                etau_category = ['etLoose', 'etLoose/Up', 'etLoose/Down']
            elif (not isTauTight):
                etau_category = [
                    'tLoose', 'tLoose/Up', 'tLoose/Down', 'tLooseUnweight'
                ]
            elif (not isETight):
                etau_category = ['eLoose', 'eLoose/Up', 'eLoose/Down']

            #jet category
            central = struct(
                njets=2,
                #njets = min(row.jetVeto30, 3),
                tPt=row.tPt,
                ePt=row.ePt)
            #jets = [min(row.jetVeto30, 3), min(row.jetVeto30jes_plus, 3),  min(row.jetVeto30jes_minus, 3)]
            jets = [2, 2, 2]
            tpts = [row.tPt_tes_plus, row.tPt_tes_minus]
            epts = [row.ePt_ees_plus, row.ePt_ees_minus]
            sys_effects = [(name, central.clone(njets=jnum))
                           for name, jnum in zip(jes_dirs, jets)]
            sys_effects.extend([(name, central.clone(tPt=pt))
                                for name, pt in zip(tes_dirs, tpts)])
            sys_effects.extend([(name, central.clone(ePt=pt))
                                for name, pt in zip(ees_dirs, epts)])

            #
            # Full tight selection
            #
            passes_full_selection = False
            selection_categories = []
            for name, shifted in sys_effects:
                #preselection. flat pt values
                if shifted.ePt > 30 and shifted.tPt > 30:
                    selection_categories.append(
                        (name, '%i' % shifted.njets, ''))
                else:
                    continue

                ##if shifted.njets == 0 :
                ##    if shifted.tPt < 35: continue
                ##    if shifted.ePt < 40: continue
                ##    if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue
                ##    if row.tMtToPfMet > 50 : continue
                ##    selection_categories.append((name, '0', 'selected'))
                ##    passes_full_selection = True
                ##elif shifted.njets == 1 :
                ##    if shifted.tPt < 40: continue
                ##    if shifted.ePt < 35: continue
                ##    if row.tMtToPfMet > 35 : continue
                ##    selection_categories.append((name, '1', 'selected'))
                ##    passes_full_selection = True
                ##el
                if shifted.njets == 2:
                    if shifted.tPt < 40: continue
                    if shifted.ePt < 30: continue
                    if row.tMtToPfMet > 35: continue
                    if row.vbfMass < 550: continue
                    if row.vbfDeta < 3.5: continue
                    selection_categories.append((name, '2', 'selected'))
                    passes_full_selection = True

            if passes_full_selection:
                logging.debug('Passed full selection')

            #
            #different selections
            #
            sign = 'ss' if row.e_t_SS else 'os'
            processtype = 'gg'
            ptthreshold = ['ept30']

            #
            # Lepton vetoes
            #
            tvetoes = [
                row.tauVetoPt20EleTight3MuLoose,
                row.tauVetoPt20EleTight3MuLoose_tes_plus,
                row.tauVetoPt20EleTight3MuLoose_tes_minus
            ]
            mvetoes = [
                row.muVetoPt5IsoIdVtx, row.muVetoPt5IsoIdVtx_mes_plus,
                row.muVetoPt5IsoIdVtx_mes_minus
            ]
            evetoes = [
                row.eVetoCicLooseIso, row.eVetoCicLooseIso_ees_plus,
                row.eVetoCicLooseIso_ees_minus
            ]

            tdirs = [
                i for i, j in zip(systematics['tvetos'], tvetoes) if not j
            ]
            mdirs = [
                i for i, j in zip(systematics['mvetos'], mvetoes) if not j
            ]
            edirs = [
                i for i, j in zip(systematics['evetos'], evetoes) if not j
            ]

            #if any of the lists is empty
            #set_trace()
            if not tdirs or not mdirs or not edirs:
                continue
            logging.debug('Passed Vetoes')

            #make all possible veto combos...
            all_dirs = [
                ''.join(i) for i in itertools.product(tdirs, mdirs, edirs)
            ]
            #...and choose only the meaningful ones
            veto_sys = set(systematics['tvetos'] + systematics['mvetos'] +
                           systematics['evetos'])
            all_dirs = [i for i in all_dirs if i in veto_sys]

            sys_directories = all_dirs + sys_shifts
            #remove duplicates
            sys_directories = list(set(sys_directories))

            #at least one loose object
            if (not isETight) or (not isTauTight):
                #if is a loose tau just compute the fakes!
                sys_directories = etau_category

                #gather the one and only weight we do care about
                mc_weight = weight_map['']

                #weights are the fr ones...
                weight_map = self.fakerate_weights(row.tEta)
                for i in weight_map:
                    #...times the mc weight (if any)
                    weight_map[i] *= mc_weight

            #Fill histograms in appropriate direcotries
            #if passes_full_selection:
            #dirs = [os.path.join(sys, sign, processtype, e_thr, jet_dir) for sys, e_thr, jet_dir in itertools.product(sys_directories, ptthreshold, jet_directories)]
            #if len(dirs) <> len(set(dirs)):
            #    set_trace()
            for sys, e_thr, selection in itertools.product(
                    sys_directories, ptthreshold, selection_categories):
                selection_sys, jet_dir, selection_step = selection
                #if we have multiple systematic shifts applied
                #reject the combination
                if selection_sys and sys:
                    continue

                #if we fill a histogram, lock the event
                lock = evt_id
                dir_name = os.path.join(sys, selection_sys, sign, processtype,
                                        e_thr, jet_dir, selection_step)
                if dir_name[-1] == '/':
                    dir_name = dir_name[:-1]
                if passes_full_selection:
                    logging.debug('Filling %s' % dir_name)
                #fill them!
                weight_to_use = weight_map[
                    sys] if sys in weight_map else weight_map['']
                self.fill_histos(dir_name, row, weight_to_use)
Example #13
0
    def process(self):
        
        

        central_weights = fakerate_central_histogram(25,0, 2.5)
        
        p1s_weights = fakerate_p1s_histogram(25,0, 2.5)#fakerate_p1s_histogram(25,0, 2.5)
        
        m1s_weights = fakerate_m1s_histogram(25,0, 2.5)#fakerate_m1s_histogram(25,0, 2.5)
        
                
        
        frw = []
        myevent =()
        for row in self.tree:
        #for n, row in enumerate(self.tree):
            
            sign = 'ss' if row.e_t_SS else 'os'
            processtype = '' ## use a line as for sign when the vbf when selections are defined            
            ptthreshold = [30]
            processtype ='gg'##changed from 20
            jn = row.jetVeto30
            if jn > 3 : jn = 3
            jn_jes_plus = row.jetVeto30jes_plus
            jn_jes_minus = row.jetVeto30jes_minus

            if jn_jes_plus >3 :  jn_jes_plus=3
            if jn_jes_minus >3 : jn_jes_minus=3

            #if row.run > 2 : #apply the trigger to data only (MC triggers enter in the scale factors)
            
            if self.is_embedded :

                if not bool(row.doubleMuPass) : continue
            else: 
                if not bool(row.singleE27WP80Pass) : continue
                if  not  bool(row.eMatchesSingleE27WP80): continue
                        
            if not selections.eSelection(row, 'e'): continue
               
            if not selections.lepton_id_iso(row, 'e', 'eid13Tight_etauiso01'): continue
                        
            if abs(row.eEta) > 1.4442 and abs(row.eEta) < 1.566 : continue
            if not selections.tauSelection(row, 't'): continue
                        
            if row.ePt < 30 : continue
            #if row.eMtToPFMET <40 : continue
            
            if not row.tAntiElectronMVA5Tight : continue
            if not row.tAntiMuon2Loose : continue
            if not row.tLooseIso3Hits : continue
            
            #isTauTight = False
            frw=self.fakerate_weights(row.tEta, central_weights, p1s_weights, m1s_weights )

            #if row.tauVetoPt20EleTight3MuLoose : continue 
            #if row.muVetoPt5IsoIdVtx : continue
            #if row.eVetoCicLooseIso : continue # change it with Loose

            if row.tauVetoPt20EleTight3MuLoose  and row.tauVetoPt20EleTight3MuLoose_tes_minus and row.tauVetoPt20EleTight3MuLoose_tes_plus: continue 
            if row.muVetoPt5IsoIdVtx and row.muVetoPt5IsoIdVtx_mes_minus and row.muVetoPt5IsoIdVtx_mes_plus : continue
            if row.eVetoCicLooseIso and row.eVetoCicLooseIso_ees_minus and row.eVetoCicLooseIso_ees_plus : continue
            
            standardSelection=True
            tesminus =True
            tesplus  =True
            mesminus =True
            mesplus  =True
            eesminus =True
            eesplus  =True        
            
            if  row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or  row.eVetoCicLooseIso : standardSelection =  False             

            if  row.tauVetoPt20EleTight3MuLoose_tes_minus or row.muVetoPt5IsoIdVtx or  row.eVetoCicLooseIso : tesminus =  False 
            if  row.tauVetoPt20EleTight3MuLoose_tes_plus or row.muVetoPt5IsoIdVtx or  row.eVetoCicLooseIso  : tesplus  =  False 
            if  row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_minus or  row.eVetoCicLooseIso : mesminus =  False 
            if  row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx_mes_plus or  row.eVetoCicLooseIso  : mesplus  =  False 
            if  row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or  row.eVetoCicLooseIso_ees_minus : eesminus =  False 
            if  row.tauVetoPt20EleTight3MuLoose or row.muVetoPt5IsoIdVtx or  row.eVetoCicLooseIso_ees_plus  : eesplus  =  False 
            
            dirpaths = [(standardSelection, sign+'/'+processtype), (mesplus, 'mVetoUp/'+sign+'/'+processtype),  (mesminus, 'mVetoDown/'+sign+'/'+processtype), \
                        (eesplus, 'eVetoUp/'+sign+'/'+processtype),  (eesminus, 'eVetoDown/'+sign+'/'+processtype), \
                        (tesplus, 'tVetoUp/'+sign+'/'+processtype),  (tesminus, 'tVetoDown/'+sign+'/'+processtype)]

            
            
            if (row.run, row.lumi, row.evt)==myevent: continue
            if myevent!=() and (row.run, row.lumi, row.evt)==(myevent[0], myevent[1], myevent[2]): print row.ePt, row.tPt
            
            myevent=(row.run, row.lumi, row.evt)

            isTauTight = bool(row.tTightIso3Hits)
            folder = dirpaths[0][1]+'/ept30'
            if dirpaths[0][0] == True and sign=='os':
                self.fill_histos(row, folder,isTauTight, frw)
                   
            
            if row.bjetCSVVeto30!=0 : continue # it is better vetoing on b-jets  after the histo for the DY embedded

            for n,dirpath in enumerate(dirpaths):
                jetlist = [(int(jn), str(int(jn)))]
                if  dirpath[0]==False : continue 
                if n==0:
                    jetlist.extend([(int(jn_jes_plus), str(int(jn_jes_plus))+'_jes_plus'), (int(jn_jes_minus), str(int(jn_jes_plus))+'_jes_minus')])
                for jet in jetlist:
                    #for j in ptthreshold:
                    folder = dirpath[1]+'/ept30/'+jet[1]
                                        
                        #print row.tLooseIso3Hits, row.tTightIso3Hits, isTauTight
                                                
                    self.fill_histos(row, folder,isTauTight, frw)
                
                    if jet[0] == 0 :
                        if row.tPt < 35: continue 
                        if row.ePt < 40 : continue
                        if deltaPhi(row.ePhi, row.tPhi) < 2.7 : continue
                        if row.tMtToPFMET > 50 : continue
                    if jet[0] == 1 :
                        if row.tPt < 40: continue 
                        if row.ePt < 35 : continue
                        if row.tMtToPFMET > 35 : continue
                    if jet[0] == 2 :
                        if row.tPt < 40: continue 
                        if row.ePt < 30 : continue # no cut as only electrons with pt>30 are in the ntuples
                        if row.tMtToPFMET > 35 : continue
                        if row.vbfMass < 550 : continue
                        if row.vbfDeta < 3.5 : continue
                    folder = dirpath[1]+'/ept30/'+jet[1]+'/selected'
                    self.fill_histos(row, folder, isTauTight,frw)
Example #14
0
    def preselection( self, row, cut_flow_trk = None, LT_threshold = 80., taupt_thr = 0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        mu17e8, mu8e17 = False, False
        if use_iso_trigger:
            mu17e8 = row.mu17ele8isoPass and \
                row.mMatchesMu17Ele8IsoPath > 0 and \
                row.eMatchesMu17Ele8IsoPath > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17isoPass and \
                row.mMatchesMu8Ele17IsoPath > 0 and \
                row.eMatchesMu8Ele17IsoPath > 0 and \
                row.ePt >= 20
        else:
            mu17e8 = row.mu17ele8Pass and \
                row.mMatchesMu17Ele8Path > 0 and \
                row.eMatchesMu17Ele8Path > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17Pass and \
                row.mMatchesMu8Ele17Path > 0 and \
                row.eMatchesMu8Ele17Path > 0 and \
                row.ePt >= 20
            
        if not (mu17e8 or mu8e17):                return False
        cut_flow_trk.Fill('trigger')

        if not selections.muSelection(row, 'm'):  return False #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
        #cut_flow_trk.Fill('pt requirements 1', 'eta requirements 1', 'MissingHits 1', 'HasConversion 1', 'JetBtag 1', 'DZ 1',)
        cut_flow_trk.Fill('obj1 Presel')

        if not selections.eSelection(row, 'e'):   return False #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight)
        cut_flow_trk.Fill('obj2 Presel')
        #FIXME
        #if row.ePt < 10:           return False
	#cut_flow_trk.Fill('pt requirements 2')
    	#if row.eAbsEta > 2.5:      return False
	#cut_flow_trk.Fill('eta requirements 2')
    	#if row.eMissingHits:       return False
	#cut_flow_trk.Fill('MissingHits 2')
    	#if row.eHasConversion:     return False
	#cut_flow_trk.Fill('HasConversion 2')
    	#if row.eJetBtag > 3.3:     return False
	#cut_flow_trk.Fill('JetBtag 2')
    	#if abs(row.eDZ) > 0.2:     return False
	#cut_flow_trk.Fill('DZ 2')


        if not selections.tauSelection(row, 't'): return False #applies basic selection (eta, pt > 20, DZ)
        if row.tPt < taupt_thr: return False
        if row.tMuOverlap:         return False
        if not row.tAntiMuonTight: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold:            return False
        cut_flow_trk.Fill('LT')

        if row.e_m_SS and row.e_t_SS: return False #remove three SS leptons
        if not selections.vetos(row): return False #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')
        #FIXME
    	if not row.eChargeIdTight: return False
        #cut_flow_trk.Fill('ChargeIdTight')
       
        if e_m_Mass < 20:          return False
        cut_flow_trk.Fill('charge_fakes') #no charge fakes here

        #FIXME: ONLY FOR CUT-FLOW PRODUCTION
        #if not row.mPFIDTight: return False
        #cut_flow_trk.Fill('obj1 ID')
        #if not selections.lepton_id_iso(row, 'm', 'h2taucuts'): return False
        #cut_flow_trk.Fill('obj1 Iso')
        #if not selections.summer_2013_eid(row, 'e'): return False
        #cut_flow_trk.Fill('obj2 ID')
        #if not selections.lepton_id_iso(row, 'e', 'h2taucuts'): return False
        #cut_flow_trk.Fill('obj2 Iso')
        #if not row.tLooseIso3Hits: return False
        #cut_flow_trk.Fill('obj3 IDIso')

        return True
    def process(self):
        
        cut_flow_histo = self.cut_flow_histo
        cut_flow_trk   = cut_flow_tracker(cut_flow_histo)
        myevent =()
        #print self.tree.inputfilename
        for row in self.tree:
            jn = row.jetVeto30
            if jn > 3 : jn = 3
            
            #if row.run > 2: 
            if not bool(row.singleE27WP80Pass) : continue
            #            if hasattr(self.tree, 'row.e1MatchesEle27WP80') and hasattr(self.tree, 'row.e2MatchesEle27WP80') :
            #if not bool(row.e1MatchesEle27WP80) and not bool(row.e2MatchesEle27WP80) : continue
            
            #else :
            if not bool(row.e1MatchesSingleE27WP80) and  not bool(row.e2MatchesSingleE27WP80) : continue
                #if not bool(row.singleEPass) : continue
                #if not bool(row.e1MatchesSingleE) and  not bool(row.e2MatchesSingleE) : continue
                
            if row.bjetCSVVeto30!=0 : continue 
            if row.e1Pt < 30 : continue
            if row.e2Pt < 30 : continue
                       
#        for i, row in enumerate(self.tree):
#            if  i >= 100:
#                return
           # print bool(cut_flow_trk.disabled)
            cut_flow_trk.new_row(row.run,row.lumi,row.evt)
            #print row.run,row.lumi,row.evt
            cut_flow_trk.Fill('allEvents')
            if not selections.eSelection(row, 'e1'): continue
            cut_flow_trk.Fill('e1sel')
            if not selections.lepton_id_iso(row, 'e1', 'eid13Tight_etauiso01'): continue
            if abs(row.e1Eta) > 1.4442 and abs(row.e1Eta < 1.566) : continue
            
            
            cut_flow_trk.Fill('e1IDiso')
            if not selections.eSelection(row, 'e2'): continue
            cut_flow_trk.Fill('e2sel')
            if not selections.lepton_id_iso(row, 'e2', 'eid13Tight_etauiso01'): continue
            if abs(row.e2Eta) > 1.4442 and abs(row.e2Eta) < 1.566 : continue
            
            cut_flow_trk.Fill('e2IDiso')
            if not abs(row.e1_e2_Mass-91.2) < 20: continue
            cut_flow_trk.Fill('ZMass')
            if not selections.tauSelection(row, 't'): continue
            if row.tPt < 30 : continue
            cut_flow_trk.Fill('tsel')

            if not row.tAntiMuon2Loose: continue
            cut_flow_trk.Fill('tAntiMuon')
            if not row.tAntiElectronMVA5Tight: continue #was 3
            cut_flow_trk.Fill('tAntiEle')

            if row.tauVetoPt20EleTight3MuLoose : continue 
            #if row.tauHpsVetoPt20 : continue
            if row.muVetoPt5IsoIdVtx : continue
            if row.eVetoCicLooseIso : continue # change it with Loose

            
            # if not row.tMtToMET < 50:  continue
            cut_flow_trk.Fill('MtToMet')
            
            #            if  etDR(row) < 1. : continue 
            if (row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)==myevent: continue
            myevent=(row.run, row.lumi, row.evt, row.e1Pt, row.e2Pt)

            tauiso = 'tNoCuts'
            sign = 'ss' if row.e1_e2_SS else 'os'
            folder = sign+'/'+tauiso
          
            self.fill_histos(row, folder)
            folder=folder+'/'+str(int(jn))
            self.fill_histos(row, folder)
            
            
            if  row.tPt < 90 and row.tPt>65 : 
                folder = folder+'/tptregion'
                self.fill_histos(row, folder)
                folder = sign+'/'+tauiso+'/tptregion'
                self.fill_histos(row, folder)
                
            if not row.tRawIso3Hits < 10 : continue
            cut_flow_trk.Fill('tRawIso10')
            tauiso = 'tSuperSuperLoose'
            folder = sign+'/'+tauiso
            self.fill_histos(row, folder)
            folder=folder+'/'+str(int(jn))
            self.fill_histos(row, folder)
            if  row.tPt < 90 and row.tPt>65 : 
                folder = folder+'/tptregion'
                self.fill_histos(row, folder)
                folder = sign+'/'+tauiso+'/tptregion'
                self.fill_histos(row, folder)
                
            if not row.tRawIso3Hits < 5 : continue
            cut_flow_trk.Fill('tRawIso5')
            tauiso = 'tSuperLoose'
            folder = sign+'/'+tauiso
            self.fill_histos(row, folder)
            folder=folder+'/'+str(int(jn))
            self.fill_histos(row, folder)
            if  row.tPt < 90 and row.tPt>65 : 
                folder = folder+'/tptregion'
                self.fill_histos(row, folder)
                folder = sign+'/'+tauiso+'/tptregion'
                self.fill_histos(row, folder)

                        
            if  row.tLooseIso3Hits : 
                tauiso = 'tLoose'
                folder = sign+'/'+tauiso
                self.fill_histos(row,  folder)
                cut_flow_trk.Fill('tLooseIso')
                folder=folder+'/'+str(int(jn))
                self.fill_histos(row, folder)
                if  row.tPt < 90 and row.tPt>65 : 
                    folder = folder+'/tptregion'
                    self.fill_histos(row, folder)
                    folder = sign+'/'+tauiso+'/tptregion'
                    self.fill_histos(row, folder)

            if row.tTightIso3Hits :
                tauiso = 'tTigh' 
                folder = sign+'/'+tauiso
                self.fill_histos(row,  folder)
                cut_flow_trk.Fill('tTightIso')
                folder=folder+'/'+str(int(jn))
                self.fill_histos(row, folder)
                if  row.tPt < 90 and row.tPt>65 : 
                    folder = folder+'/tptregion'
                    self.fill_histos(row, folder)
                    folder = sign+'/'+tauiso+'/tptregion'
                    self.fill_histos(row, folder)
                    
 
             
        cut_flow_trk.flush()
Example #16
0
    def preselection(self,
                     row,
                     cut_flow_trk=None,
                     LT_threshold=80.,
                     taupt_thr=0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if row.e_t_DR < 0.5 or row.m_t_DR < 0.5 or row.e_m_DR < 0.5:
            return False
        cut_flow_trk.Fill('DR separation')

        if self.hfunc['subMass'](row, 1)[0] < 20: return False
        cut_flow_trk.Fill('sub mass cut')

        mu17e8, mu8e17 = False, False
        if use_iso_trigger:
            mu17e8 = row.mu17ele8isoPass and \
                row.mMatchesMu17Ele8IsoPath > 0 and \
                row.eMatchesMu17Ele8IsoPath > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17isoPass and \
                row.mMatchesMu8Ele17IsoPath > 0 and \
                row.eMatchesMu8Ele17IsoPath > 0 and \
                row.ePt >= 20
        else:
            mu17e8 = row.mu17ele8Pass and \
                row.mMatchesMu17Ele8Path > 0 and \
                row.eMatchesMu17Ele8Path > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17Pass and \
                row.mMatchesMu8Ele17Path > 0 and \
                row.eMatchesMu8Ele17Path > 0 and \
                row.ePt >= 20

        if not (mu17e8 or mu8e17): return False
        cut_flow_trk.Fill('trigger')

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

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

        if not selections.tauSelection(row, 't'):
            return False  #applies basic selection (eta, pt > 20, DZ)
        if row.tPt < taupt_thr: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.e_m_Mass < 20: return False
        cut_flow_trk.Fill('dilepton mass cut')

        if not selections.vetos(row, cut_flow_trk):
            return False  #applies mu bjet e additional tau vetoes

        cut_flow_trk.Fill('charge_fakes')  #no charge fakes here

        return True
Example #17
0
    def preselection(self,
                     row,
                     cut_flow_trk=None,
                     LT_threshold=80.,
                     taupt_thr=0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        if not row.doubleEPass: return False
        if not (row.e1MatchesDoubleEPath > 0 and \
         row.e2MatchesDoubleEPath > 0):
            return False
        cut_flow_trk.Fill('trigger')

        if row.e1Pt < 20: return False
        if not selections.eSelection(row, 'e1'): return False
        cut_flow_trk.Fill('obj1 Presel')
        #FIXME
        #if row.e1Pt < 20:           return False
        #cut_flow_trk.Fill('pt requirements 1')
        #if row.e1AbsEta > 2.5:      return False
        #cut_flow_trk.Fill('eta requirements 1')
        #if row.e1MissingHits:       return False
        #cut_flow_trk.Fill('MissingHits 1')
        #if row.e1HasConversion:     return False
        #cut_flow_trk.Fill('HasConversion 1')
        #if row.e1JetBtag > 3.3:     return False
        #cut_flow_trk.Fill('JetBtag 1')
        #if abs(row.e1DZ) > 0.2:     return False
        #cut_flow_trk.Fill('DZ 1')

        if not selections.eSelection(row, 'e2'): return False
        cut_flow_trk.Fill('obj2 Presel')
        #FIXME
        #if row.e2Pt < 10:           return False
        #cut_flow_trk.Fill('pt requirements 2')
        #if row.e2AbsEta > 2.5:      return False
        #cut_flow_trk.Fill('eta requirements 2')
        #if row.e2MissingHits:       return False
        #cut_flow_trk.Fill('MissingHits 2')
        #if row.e2HasConversion:     return False
        #cut_flow_trk.Fill('HasConversion 2')
        #if row.e2JetBtag > 3.3:     return False
        #cut_flow_trk.Fill('JetBtag 2')
        #if abs(row.e2DZ) > 0.2:     return False
        #cut_flow_trk.Fill('DZ 2')

        if not selections.tauSelection(row, 't'): return False
        if row.tPt < taupt_thr: return False
        if not row.tAntiMuonLoose: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.e1_e2_SS and row.e1_t_SS: return False  #remove three SS leptons
        if row.e1_e2_Mass < 20: return False
        if not selections.vetos(row):
            return False  #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')

        #REMOVE CHARGE FAKES!
        #FIXME
        #if not row.e1ChargeIdLoose: return False
        #if not row.e2ChargeIdLoose: return False
        #cut_flow_trk.Fill('ChargeIdLoose')
        #cut_flow_trk.Fill('charge_fakes')

        #FIXME: ONLY FOR CUT-FLOW PRODUCTION
        #if not selections.summer_2013_eid(row, 'e1'): return False
        #cut_flow_trk.Fill('obj1 ID')
        #if not selections.lepton_id_iso(row, 'e1', 'eid13Looseh2taucuts'): return False
        #cut_flow_trk.Fill('obj1 Iso')
        #if not selections.summer_2013_eid(row, 'e2'): return False
        #cut_flow_trk.Fill('obj2 ID')
        #if not selections.lepton_id_iso(row, 'e2', 'eid13Looseh2taucuts'): return False
        #cut_flow_trk.Fill('obj2 Iso')
        #if not row.tLooseIso3Hits: return False
        #cut_flow_trk.Fill('obj3 IDIso')

        return True
Example #18
0
    def preselection(self,
                     row,
                     cut_flow_trk=None,
                     LT_threshold=80.,
                     taupt_thr=0.):
        ''' Preselection applied to events.

        Excludes FR object IDs and sign cut.
        '''
        mu17e8, mu8e17 = False, False
        if use_iso_trigger:
            mu17e8 = row.mu17ele8isoPass and \
                row.mMatchesMu17Ele8IsoPath > 0 and \
                row.eMatchesMu17Ele8IsoPath > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17isoPass and \
                row.mMatchesMu8Ele17IsoPath > 0 and \
                row.eMatchesMu8Ele17IsoPath > 0 and \
                row.ePt >= 20
        else:
            mu17e8 = row.mu17ele8Pass and \
                row.mMatchesMu17Ele8Path > 0 and \
                row.eMatchesMu17Ele8Path > 0 and \
                row.mPt >= 20
            mu8e17 = row.mu8ele17Pass and \
                row.mMatchesMu8Ele17Path > 0 and \
                row.eMatchesMu8Ele17Path > 0 and \
                row.ePt >= 20

        if not (mu17e8 or mu8e17): return False
        cut_flow_trk.Fill('trigger')

        if not selections.muSelection(row, 'm'):
            return False  #applies basic selection (eta, pt > 10, DZ, pixHits, jetBTag)
        #cut_flow_trk.Fill('pt requirements 1', 'eta requirements 1', 'MissingHits 1', 'HasConversion 1', 'JetBtag 1', 'DZ 1',)
        cut_flow_trk.Fill('obj1 Presel')

        if not selections.eSelection(row, 'e'):
            return False  #applies basic selection (eta, pt > 10, DZ, missingHits, jetBTag, HasConversion and chargedIdTight)
        cut_flow_trk.Fill('obj2 Presel')
        #FIXME
        #if row.ePt < 10:           return False
        #cut_flow_trk.Fill('pt requirements 2')
        #if row.eAbsEta > 2.5:      return False
        #cut_flow_trk.Fill('eta requirements 2')
        #if row.eMissingHits:       return False
        #cut_flow_trk.Fill('MissingHits 2')
        #if row.eHasConversion:     return False
        #cut_flow_trk.Fill('HasConversion 2')
        #if row.eJetBtag > 3.3:     return False
        #cut_flow_trk.Fill('JetBtag 2')
        #if abs(row.eDZ) > 0.2:     return False
        #cut_flow_trk.Fill('DZ 2')

        if not selections.tauSelection(row, 't'):
            return False  #applies basic selection (eta, pt > 20, DZ)
        if row.tPt < taupt_thr: return False
        if row.tMuOverlap: return False
        if not row.tAntiMuonTight: return False
        cut_flow_trk.Fill('obj3 Presel')

        if row.LT < LT_threshold: return False
        cut_flow_trk.Fill('LT')

        if row.e_m_SS and row.e_t_SS: return False  #remove three SS leptons
        if not selections.vetos(row):
            return False  #applies mu bjet e additional tau vetoes
        cut_flow_trk.Fill('vetos')
        #FIXME
        if not row.eChargeIdTight: return False
        #cut_flow_trk.Fill('ChargeIdTight')

        if e_m_Mass < 20: return False
        cut_flow_trk.Fill('charge_fakes')  #no charge fakes here

        #FIXME: ONLY FOR CUT-FLOW PRODUCTION
        #if not row.mPFIDTight: return False
        #cut_flow_trk.Fill('obj1 ID')
        #if not selections.lepton_id_iso(row, 'm', 'h2taucuts'): return False
        #cut_flow_trk.Fill('obj1 Iso')
        #if not selections.summer_2013_eid(row, 'e'): return False
        #cut_flow_trk.Fill('obj2 ID')
        #if not selections.lepton_id_iso(row, 'e', 'h2taucuts'): return False
        #cut_flow_trk.Fill('obj2 Iso')
        #if not row.tLooseIso3Hits: return False
        #cut_flow_trk.Fill('obj3 IDIso')

        return True