コード例 #1
0
    def processEvent(self, tree):
        currentEntry = tree.GetReadEntry()
        # if current entry has not been processed yet
        if currentEntry != self.lastEntry and not self.isData:
            self.lastEntry = currentEntry

            zElectrons = vLeptonSelector(tree).getZelectrons()

            # require two electrons
            if len(zElectrons) == 2:
                sfIdIso = self.getIdIsoSf(
                    eta=zElectrons[0].eta,
                    pt=zElectrons[0].pt) * self.getIdIsoSf(
                        eta=zElectrons[1].eta, pt=zElectrons[1].pt)
                sfTrigger = self.getTriggerSf(eta1=zElectrons[0].eta,
                                              pt1=zElectrons[0].pt,
                                              eta2=zElectrons[1].eta,
                                              pt2=zElectrons[1].pt)
                self.branchBuffers['electronSF'][0] = sfIdIso * sfTrigger
                self.branchBuffers['electronSF_IdIso'][0] = sfIdIso
                self.branchBuffers['electronSF_trigger'][0] = sfTrigger
            else:
                self.branchBuffers['electronSF'][0] = 1.0
                self.branchBuffers['electronSF_IdIso'][0] = 1.0
                self.branchBuffers['electronSF_trigger'][0] = 1.0
        return True
コード例 #2
0
ファイル: ElectronSFfromJSON.py プロジェクト: perrozzi/Xbb
    def processEvent(self, tree):
        currentEntry = tree.GetReadEntry()
        # if current entry has not been processed yet
        if currentEntry != self.lastEntry and not self.isData:
            self.lastEntry = currentEntry

            zElectrons = vLeptonSelector(tree).getZelectrons()
            
            for syst in self.systVariations:
                # require two electrons
                if len(zElectrons) == 2: 
                    sfIdIso = self.getIdIsoSf(eta=zElectrons[0].eta, pt=zElectrons[0].pt, syst=syst) * self.getIdIsoSf(eta=zElectrons[1].eta, pt=zElectrons[1].pt, syst=syst)
                    sfTrigger = self.getTriggerSf(eta1=zElectrons[0].eta, pt1=zElectrons[0].pt, eta2=zElectrons[1].eta, pt2=zElectrons[1].pt, syst=syst)
                else:
                    sfIdIso = 1.0
                    sfTrigger = 1.0
                # Up/Down variations should be taken from individual components instead of total during the datacard creation
                self.branchBuffers['electronSF' + (syst if syst else '')][0] = sfIdIso * sfTrigger
                self.branchBuffers['electronSF_IdIso' + (syst if syst else '')][0] = sfIdIso
                self.branchBuffers['electronSF_trigger' + (syst if syst else '')][0] = sfTrigger
        return True
コード例 #3
0
    def processEvent(self, tree):
        currentEntry = tree.GetReadEntry()
        # if current entry has not been processed yet
        if currentEntry != self.lastEntry and not self.isData:
            self.lastEntry = currentEntry

            zElectrons = vLeptonSelector(tree, config=self.config).getZelectrons()
            
            for syst in self.systVariations:
                # require two electrons
                if len(zElectrons) == 2: 
                    sfIdIso = self.getIdIsoSf(eta=zElectrons[0].eta, pt=zElectrons[0].pt, syst=syst) * self.getIdIsoSf(eta=zElectrons[1].eta, pt=zElectrons[1].pt, syst=syst)
                    sfTrigger = self.getTriggerSf(eta1=zElectrons[0].eta, pt1=zElectrons[0].pt, eta2=zElectrons[1].eta, pt2=zElectrons[1].pt, syst=syst)
                else:
                    sfIdIso = 1.0
                    sfTrigger = 1.0
                # Up/Down variations should be taken from individual components instead of total during the datacard creation
                self.branchBuffers['electronSF' + (syst if syst else '')][0] = sfIdIso * sfTrigger
                self.branchBuffers['electronSF_IdIso' + (syst if syst else '')][0] = sfIdIso
                self.branchBuffers['electronSF_trigger' + (syst if syst else '')][0] = sfTrigger
        return True
コード例 #4
0
ファイル: MuonSFfromJSON.py プロジェクト: perrozzi/Xbb
    def processEvent(self, tree):
        currentEntry = tree.GetReadEntry()
        # if current entry has not been processed yet
        if currentEntry != self.lastEntry and not self.isData:
            self.lastEntry = currentEntry

            vLeptons = vLeptonSelector(tree)
            zMuons = vLeptons.getZmuons()

            # require two muons
            if len(zMuons) == 2:
                sfIdIso = self.getIdIsoSf(eta=zMuons[0].eta, pt=zMuons[0].pt) * self.getIdIsoSf(eta=zMuons[1].eta, pt=zMuons[1].pt) 
                sfTrigger = self.getTriggerSf(eta1=zMuons[0].eta, pt1=zMuons[0].pt, eta2=zMuons[1].eta, pt2=zMuons[1].pt)
                self.branchBuffers['muonSF'][0] = sfIdIso * sfTrigger
                self.branchBuffers['muonSF_IdIso'][0] = sfIdIso
                self.branchBuffers['muonSF_trigger'][0] = sfTrigger
            else:
                self.branchBuffers['muonSF'][0] = 1.0
                self.branchBuffers['muonSF_IdIso'][0] = 1.0
                self.branchBuffers['muonSF_trigger'][0] = 1.0
        return True
コード例 #5
0
    def processEvent(self, tree):
        isGoodEvent = True
        currentEntry = tree.GetReadEntry()
        # if current entry has not been processed yet
        if currentEntry != self.lastEntry:
            self.lastEntry = currentEntry
            # ================ Lepton Scale Factors =================
            # For custom made form own JSON files

            if self.channel == 'Zll' or len(self.channel) < 1:
                #Reinitialize all the variables
                for branchName in [
                        'weight_SF_LooseID', 'weight_SF_LooseISO',
                        'weight_SF_LooseIDnISO', 'weight_SF_TRK',
                        'weight_SF_Lepton', 'eTrigSFWeight_doubleEle80x',
                        'muTrigSFWeight_doublemu'
                ]:
                    self.branchBuffers[branchName][0] = 1.0
                    self.branchBuffers[branchName][1] = 0.0
                    self.branchBuffers[branchName][2] = 0.0
                for branchName in [
                        'weight_SF_LooseIDnISO_B', 'weight_SF_LooseIDnISO_E'
                ]:
                    self.branchBuffers[branchName][0] = 0.0
                    self.branchBuffers[branchName][1] = 0.0

                muID_BCDEF = [1., 0., 0.]
                muID_GH = [1., 0., 0.]
                muISO_BCDEF = [1., 0., 0.]
                muISO_GH = [1., 0., 0.]
                muTRK_BCDEF = [1.0, 0., 0.]
                muTRK_GH = [1.0, 0., 0.]
                btagSF = [1., 0., 0.]
                #for muon trigger
                #Run BCDEFG
                effDataBCDEFG_leg8 = []
                effDataBCDEFG_leg17 = []
                effMCBCDEFG_leg8 = []
                effMCBCDEFG_leg17 = []
                #Run H
                effDataH_leg8 = []
                effDataH_leg17 = []
                effMCH_leg8 = []
                effMCH_leg17 = []
                #Run H dZ
                effDataH_DZ = []
                effMCH_DZ = []

                wdir = self.config.get('Directories', 'vhbbpath')

                jsons = {
                    #
                    #Muon
                    #
                    #ID and ISO
                    wdir + '/python/json/V25/muon_ID_BCDEFv2.json': [
                        'MC_NUM_LooseID_DEN_genTracks_PAR_pt_eta',
                        'abseta_pt_ratio'
                    ],
                    wdir + '/python/json/V25/muon_ID_GHv2.json': [
                        'MC_NUM_LooseID_DEN_genTracks_PAR_pt_eta',
                        'abseta_pt_ratio'
                    ],
                    wdir + '/python/json/V25/muon_ISO_BCDEFv2.json':
                    ['LooseISO_LooseID_pt_eta', 'abseta_pt_ratio'],
                    wdir + '/python/json/V25/muon_ISO_GHv2.json':
                    ['LooseISO_LooseID_pt_eta', 'abseta_pt_ratio'],
                    #Tracker
                    wdir + '/python/json/V25/trk_SF_RunBCDEF.json':
                    ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                    wdir + '/python/json/V25/trk_SF_RunGH.json': [
                        'Graph', 'ratio_eff_eta3_dr030e030_corr'
                    ],
                    #Trigg
                    #BCDEFG
                    wdir + '/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8.json':
                    [
                        'MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_DATA'
                    ],
                    wdir + '/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17.json':
                    [
                        'MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_DATA'
                    ],
                    wdir + '/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8.json':
                    [
                        'MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_MC'
                    ],
                    wdir + '/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17.json':
                    [
                        'MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_MC'
                    ],
                    #H
                    #no DZ
                    wdir + '/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg8.json':
                    [
                        'MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_DATA'
                    ],
                    wdir + '/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg17.json':
                    [
                        'MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_DATA'
                    ],
                    wdir + '/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg8.json':
                    [
                        'MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_MC'
                    ],
                    wdir + '/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg17.json':
                    [
                        'MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta',
                        'abseta_pt_MC'
                    ],
                    #with DZ
                    wdir + '/python/json/V25/DATA_EfficienciesAndSF_dZ_numH.json':
                    [
                        'MC_NUM_dZ_DEN_hlt_Mu17_Mu8_OR_TkMu8_loose_PAR_eta1_eta2',
                        'tag_abseta_abseta_DATA'
                    ],
                    wdir + '/python/json/V25/MC_EfficienciesAndSF_dZ_numH.json':
                    [
                        'MC_NUM_dZ_DEN_hlt_Mu17_Mu8_OR_TkMu8_loose_PAR_eta1_eta2',
                        'tag_abseta_abseta_MC'
                    ],
                    #
                    #Electron
                    #
                    #ID and ISO
                    wdir + '/python/json/V25/EIDISO_ZH_out.json': [
                        'EIDISO_ZH', 'eta_pt_ratio'
                    ],
                    #Tracker
                    wdir + '/python/json/V25/ScaleFactor_etracker_80x.json': [
                        'ScaleFactor_tracker_80x', 'eta_pt_ratio'
                    ],
                    #Trigg
                    wdir + '/python/json/V25/DiEleLeg1AfterIDISO_out.json': [
                        'DiEleLeg1AfterIDISO', 'eta_pt_ratio'
                    ],
                    wdir + '/python/json/V25/DiEleLeg2AfterIDISO_out.json': [
                        'DiEleLeg2AfterIDISO', 'eta_pt_ratio'
                    ]
                }
                for j, name in jsons.iteritems():

                    self.weight = []
                    lepCorrIdentifier = j + '_' + name[0] + '_' + name[1]
                    if lepCorrIdentifier not in self.leptonSF:
                        self.leptonSF[lepCorrIdentifier] = LeptonSF(
                            j, name[0], name[1])
                    lepCorr = self.leptonSF[lepCorrIdentifier]

                    # recompute vLeptons
                    vLepSelector = vLeptonSelector(tree, config=self.config)
                    Vtype = vLepSelector.getVtype()
                    vLeptons = vLepSelector.getVleptons()

                    # cross check vtypes
                    if Vtype != tree.Vtype:
                        print "\x1b[97m\x1b[41mVtype mismatch!!!!!\x1b[0m"
                        print zMuons, zElectrons, wMuons, wElectrons
                        print "vLeptons:", vLeptons
                        raise Exception("VtypeMismatch")

                    #2-D binned SF
                    if not j.find('trk_SF_Run') != -1 and not j.find(
                            'EfficienciesAndSF_dZ_numH') != -1:
                        if 'abseta' in name[1]:
                            self.weight.append(
                                lepCorr.get_2D(eta=abs(vLeptons[0].eta),
                                               pt=vLeptons[0].pt))
                            self.weight.append(
                                lepCorr.get_2D(eta=abs(vLeptons[1].eta),
                                               pt=vLeptons[1].pt))
                        else:
                            self.weight.append(
                                lepCorr.get_2D(eta=vLeptons[0].eta,
                                               pt=vLeptons[0].pt))
                            self.weight.append(
                                lepCorr.get_2D(eta=vLeptons[1].eta,
                                               pt=vLeptons[1].pt))
                    elif not j.find('trk_SF_Run') != -1 and j.find(
                            'EfficienciesAndSF_dZ_numH') != -1:
                        #???????
                        self.weight.append(
                            lepCorr.get_2D(vLeptons[0].eta, vLeptons[1].eta))
                        self.weight.append(
                            lepCorr.get_2D(vLeptons[1].eta, vLeptons[0].eta))
                    #1-D binned SF
                    else:
                        self.weight.append(lepCorr.get_1D(vLeptons[0].eta))
                        self.weight.append(lepCorr.get_1D(vLeptons[1].eta))

                    if tree.Vtype == 0:
                        #IDISO
                        if j.find('muon_ID_BCDEF') != -1:
                            self.computeSF(muID_BCDEF)
                        elif j.find('muon_ID_GH') != -1:
                            self.computeSF(muID_GH)
                        elif j.find('muon_ISO_BCDEF') != -1:
                            self.computeSF(muISO_BCDEF)
                        elif j.find('muon_ISO_GH') != -1:
                            self.computeSF(muISO_GH)
                        #TRK
                        elif j.find('trk_SF_RunBCDEF') != -1:
                            self.computeSF(muTRK_BCDEF)
                        elif j.find('trk_SF_RunGH') != -1:
                            self.computeSF(muTRK_GH)
                        #TRIG
                        elif j.find(
                                'EfficienciesAndSF_doublehlt_perleg') != -1:
                            #BCDEFG
                            if j.find(
                                    'Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8'
                            ) != -1:
                                #compute the efficiency for both legs
                                effDataBCDEFG_leg8.append(
                                    self.computeSF_leg(0))
                                effDataBCDEFG_leg8.append(
                                    self.computeSF_leg(1))
                            elif j.find(
                                    'Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17'
                            ) != -1:
                                effDataBCDEFG_leg17.append(
                                    self.computeSF_leg(0))
                                effDataBCDEFG_leg17.append(
                                    self.computeSF_leg(1))
                            elif j.find(
                                    'MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8'
                            ) != -1:
                                effMCBCDEFG_leg8.append(self.computeSF_leg(0))
                                effMCBCDEFG_leg8.append(self.computeSF_leg(1))
                            elif j.find(
                                    'MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17'
                            ) != -1:
                                effMCBCDEFG_leg17.append(self.computeSF_leg(0))
                                effMCBCDEFG_leg17.append(self.computeSF_leg(1))
                                #H
                            elif j.find(
                                    'Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg8'
                            ) != -1:
                                effDataH_leg8.append(self.computeSF_leg(0))
                                effDataH_leg8.append(self.computeSF_leg(1))
                            elif j.find(
                                    'Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg17'
                            ) != -1:
                                effDataH_leg17.append(self.computeSF_leg(0))
                                effDataH_leg17.append(self.computeSF_leg(1))
                            elif j.find(
                                    'MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg8'
                            ) != -1:
                                effMCH_leg8.append(self.computeSF_leg(0))
                                effMCH_leg8.append(self.computeSF_leg(1))
                            elif j.find(
                                    'MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg17'
                            ) != -1:
                                effMCH_leg17.append(self.computeSF_leg(0))
                                effMCH_leg17.append(self.computeSF_leg(1))
                                #H dZ only
                        elif j.find('DATA_EfficienciesAndSF_dZ_numH') != -1:
                            effDataH_DZ.append(self.computeSF_leg(0))
                            effDataH_DZ.append(self.computeSF_leg(1))
                        elif j.find('MC_EfficienciesAndSF_dZ_numH') != -1:
                            effMCH_DZ.append(self.computeSF_leg(0))
                            effMCH_DZ.append(self.computeSF_leg(1))

                    elif tree.Vtype == 1:
                        #IDISO
                        if j.find('EIDISO_ZH_out') != -1:
                            self.computeSF(
                                self.branchBuffers['weight_SF_LooseIDnISO'])
                            self.computeSF_region(
                                self.branchBuffers['weight_SF_LooseIDnISO_B'],
                                self.branchBuffers['weight_SF_LooseIDnISO_E'],
                                vLeptons[0].eta, vLeptons[1].eta, 1.566)
                        #TRK
                        elif j.find('ScaleFactor_etracker_80x') != -1:
                            self.computeSF(self.branchBuffers['weight_SF_TRK'])
                        #TRIG
                        elif j.find('DiEleLeg1AfterIDISO_out') != -1:
                            eff1 = self.weight[0][0]
                            eff1Up = (self.weight[0][0] + self.weight[0][1])
                            eff1Down = (self.weight[0][0] - self.weight[0][1])
                        elif j.find('DiEleLeg2AfterIDISO_out') != -1:
                            eff2 = self.weight[1][0]
                            eff2Up = (self.weight[1][0] + self.weight[1][1])
                            eff2Down = (self.weight[1][0] - self.weight[1][1])
                #//// from 6ae102d
                if tree.Vtype == 0:
                    #print 'muTRK_BCDEF is', muTRK_BCDEF
                    #print 'muTRK_GH is', muTRK_GH
                    #print 'muID_BCDEF is', muID_BCDEF
                    #print 'muID_GH is', muID_GH
                    #print 'muISO_BCDEF is', muISO_BCDEF
                    #print 'muISO_GH is', muISO_GH

                    #Tracker
                    self.getLumiAvrgSF(muTRK_BCDEF, (20.1 / 36.4), muTRK_GH,
                                       (16.3 / 36.4),
                                       self.branchBuffers['weight_SF_TRK'])
                    #ID and ISO
                    self.getLumiAvrgSF(muID_BCDEF, (20.1 / 36.4), muID_GH,
                                       (16.3 / 36.4),
                                       self.branchBuffers['weight_SF_LooseID'])
                    self.getLumiAvrgSF(
                        muISO_BCDEF, (20.1 / 36.4), muISO_GH, (16.3 / 36.4),
                        self.branchBuffers['weight_SF_LooseISO'])

                    self.branchBuffers['weight_SF_LooseIDnISO'][
                        0] = self.branchBuffers['weight_SF_LooseID'][
                            0] * self.branchBuffers['weight_SF_LooseISO'][0]
                    self.branchBuffers['weight_SF_LooseIDnISO'][
                        1] = self.branchBuffers['weight_SF_LooseID'][
                            1] * self.branchBuffers['weight_SF_LooseISO'][1]
                    self.branchBuffers['weight_SF_LooseIDnISO'][
                        2] = self.branchBuffers['weight_SF_LooseID'][
                            2] * self.branchBuffers['weight_SF_LooseISO'][2]
                    #Trigger
                    #BCDEFG no DZ
                    EffData_BCDEFG = [1.0, 0.]
                    EffMC_BCDEFG = [1.0, 0.]
                    SF_BCDEFG = [1.0, 0., 0.]
                    EffData_BCDEFG = self.computeEventSF_fromleg(
                        effDataBCDEFG_leg8, effDataBCDEFG_leg17)
                    EffMC_BCDEFG = self.computeEventSF_fromleg(
                        effMCBCDEFG_leg8, effMCBCDEFG_leg17)
                    SF_BCDEFG[0] = (EffData_BCDEFG[0] / EffMC_BCDEFG[0])
                    SF_BCDEFG[1] = (
                        1 - math.sqrt(EffData_BCDEFG[1]**2 +
                                      EffMC_BCDEFG[1]**2)) * SF_BCDEFG[0]
                    SF_BCDEFG[2] = (
                        1 + math.sqrt(EffData_BCDEFG[1]**2 +
                                      EffMC_BCDEFG[1]**2)) * SF_BCDEFG[0]
                    #H no DZ
                    EffData_H = [1.0, 0.]
                    EffMC_H = [1.0, 0.]
                    SF_H = [1.0, 0., 0.]
                    EffData_H = self.computeEventSF_fromleg(
                        effDataH_leg8, effDataH_leg17)
                    EffMC_H = self.computeEventSF_fromleg(
                        effMCH_leg8, effMCH_leg17)
                    SF_H[0] = (EffData_H[0] / EffMC_H[0])
                    SF_H[1] = (1 - math.sqrt(EffData_H[1]**2 +
                                             EffMC_H[1]**2)) * SF_H[0]
                    SF_H[2] = (1 + math.sqrt(EffData_H[1]**2 +
                                             EffMC_H[1]**2)) * SF_H[0]
                    #H DZ SF
                    EffData_DZ = [1.0, 0.]
                    EffMC_DZ = [1.0, 0.]
                    SF_DZ = [1.0, 0., 0.]
                    EffData_DZ = self.computeEvenSF_DZ(effDataH_DZ)
                    EffMC_DZ = self.computeEvenSF_DZ(effMCH_DZ)
                    SF_DZ[0] = (EffData_DZ[0] / EffMC_DZ[0])
                    SF_DZ[1] = (1 - math.sqrt(EffData_DZ[1]**2 +
                                              EffMC_DZ[1]**2)) * SF_DZ[0]
                    SF_DZ[2] = (1 + math.sqrt(EffData_DZ[1]**2 +
                                              EffMC_DZ[1]**2)) * SF_DZ[0]

                    #print 'List of all the double trigger SF + uncert'
                    #print 'SF_BCDEFG:', SF_BCDEFG[0], '+', SF_BCDEFG[1], '-', SF_BCDEFG[2]
                    #print 'SF_H:', SF_H[0], '+', SF_H[1], '-', SF_H[2]
                    #print 'SF_DZ:', SF_DZ[0], '+', SF_DZ[1], '-', SF_DZ[2]
                    #Final weight
                    self.branchBuffers['muTrigSFWeight_doublemu'][0] = (
                        27.221 / 35.827) * SF_BCDEFG[0] + (
                            8.606 / 35.827) * SF_H[0] * SF_DZ[0]
                    self.branchBuffers['muTrigSFWeight_doublemu'][1] = (
                        27.221 / 35.827) * SF_BCDEFG[1] + (
                            8.606 / 35.827) * SF_H[1] * SF_DZ[1]
                    self.branchBuffers['muTrigSFWeight_doublemu'][2] = (
                        27.221 / 35.827) * SF_BCDEFG[2] + (
                            8.606 / 35.827) * SF_H[2] * SF_DZ[2]

                if tree.Vtype == 1:
                    self.branchBuffers['eTrigSFWeight_doubleEle80x'][
                        0] = eff1 * (1 - eff2) * eff1 + eff2 * (
                            1 - eff1) * eff2 + eff1 * eff1 * eff2 * eff2
                    self.branchBuffers['eTrigSFWeight_doubleEle80x'][
                        1] = eff1Down * (1 - eff2Down) * eff1Down + eff2Down * (
                            1 - eff1Down
                        ) * eff2Down + eff1Down * eff1Down * eff2Down * eff2Down
                    self.branchBuffers['eTrigSFWeight_doubleEle80x'][
                        2] = eff1Up * (1 - eff2Up) * eff1Up + eff2Up * (
                            1 - eff1Up
                        ) * eff2Up + eff1Up * eff1Up * eff2Up * eff2Up

                #////

                self.branchBuffers['weight_SF_Lepton'][
                    0] = self.branchBuffers['weight_SF_TRK'][
                        0] * self.branchBuffers['weight_SF_LooseIDnISO'][0]
                self.branchBuffers['weight_SF_Lepton'][
                    1] = self.branchBuffers['weight_SF_TRK'][
                        1] * self.branchBuffers['weight_SF_LooseIDnISO'][1]
                self.branchBuffers['weight_SF_Lepton'][
                    2] = self.branchBuffers['weight_SF_TRK'][
                        2] * self.branchBuffers['weight_SF_LooseIDnISO'][2]
                #print "::", tree.Vtype_new, self.branchBuffers['weight_SF_Lepton']
                #print self.branchBuffers
                #raw_input()

            if self.channel == 'Wlv' or self.channel == 'Zvv' or len(
                    self.channel) < 1:
                # recompute vLeptons
                vLepSelector = vLeptonSelector(tree, config=self.config)
                Vtype = vLepSelector.getVtype()
                vLeptons = vLepSelector.getVleptons()

                # cross check vtypes
                if Vtype != tree.Vtype:
                    print "\x1b[97m\x1b[41mVtype mismatch!!!!!\x1b[0m"
                    print "vLeptons:", vLeptons
                    print "Vtype:", Vtype
                    print "Vtype(tree)", tree.Vtype
                    print "MET:", tree.MET_pt, tree.MET_Pt
                    raise Exception("VtypeMismatch")

                for branchName in [
                        'weight_SF_TightID', 'weight_SF_TightISO',
                        'weight_SF_TightIDnISO', 'weight_SF_TRK',
                        'weight_SF_Lepton', 'eTrigSFWeight_singleEle80',
                        'muTrigSFWeight_singlemu'
                ]:
                    self.branchBuffers[branchName][0] = 1.0
                    self.branchBuffers[branchName][1] = 0.0
                    self.branchBuffers[branchName][2] = 0.0

                if tree.Vtype != 4 and tree.Vtype != 5:
                    #print 'yeaaaaaaaaaaaaaaaaaaaaaah'
                    muID_BCDEF = [1., 0., 0.]
                    muID_GH = [1., 0., 0.]
                    muISO_BCDEF = [1., 0., 0.]
                    muISO_GH = [1., 0., 0.]
                    muTRK_BCDEF = [1.0, 0., 0.]
                    muTRK_GH = [1.0, 0., 0.]
                    muTrigg_BCDEF = [1.0, 0., 0.]
                    muTrigg_GH = [1.0, 0., 0.]
                    wdir = self.config.get('Directories', 'vhbbpath')

                    jsons = {
                        #
                        #Muon
                        #
                        #ID and ISO
                        wdir + '/python/json/V25/muon_ID_BCDEFv2.json': [
                            'MC_NUM_TightID_DEN_genTracks_PAR_pt_eta',
                            'abseta_pt_ratio'
                        ],  #eta pt
                        wdir + '/python/json/V25/muon_ID_GHv2.json': [
                            'MC_NUM_TightID_DEN_genTracks_PAR_pt_eta',
                            'abseta_pt_ratio'
                        ],
                        ###
                        wdir + '/python/json/V25/muon_ISO_BCDEFv2.json':
                        ['TightISO_TightID_pt_eta', 'abseta_pt_ratio'],
                        wdir + '/python/json/V25/muon_ISO_GHv2.json':
                        ['TightISO_TightID_pt_eta', 'abseta_pt_ratio'],
                        #Tracker
                        wdir + '/python/json/V25/trk_SF_RunBCDEF.json':
                        ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                        wdir + '/python/json/V25/trk_SF_RunGH.json':
                        ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                        #Trigg
                        #BCDEF
                        wdir + '/python/json/V25/EfficienciesAndSF_RunBtoF.json':
                        ['IsoMu24_OR_IsoTkMu24_PtEtaBins', 'abseta_pt_ratio'],
                        #GH
                        wdir + '/python/json/V25/theJSONfile_Period4.json':
                        ['IsoMu24_OR_IsoTkMu24_PtEtaBins', 'abseta_pt_ratio'],
                        ##
                        ##Electron
                        ##
                        ##ID and ISO (grouped as MVAid for electron)
                        wdir + '/python/json/V25/EIDISO_WH_out.json':
                        ['EIDISO_WH', 'eta_pt_ratio'],
                        #Tracker
                        wdir + '/python/json/V25/ScaleFactor_etracker_80x.json':
                        ['ScaleFactor_tracker_80x', 'eta_pt_ratio'],
                        #Trigg
                        wdir + '/python/json/V25/Tight27AfterIDISO_out.json':
                        ['Tight27AfterIDISO', 'eta_pt_ratio'],
                    }

                    for j, name in jsons.iteritems():
                        #print 'yeaaaaaaaaaaaaaaaaaaaaaah2'

                        self.weight = []
                        lepCorrIdentifier = j + '_' + name[0] + '_' + name[1]
                        if lepCorrIdentifier not in self.leptonSF:
                            self.leptonSF[lepCorrIdentifier] = LeptonSF(
                                j, name[0], name[1])
                        lepCorr = self.leptonSF[lepCorrIdentifier]

                        #2-D binned SF
                        #print 'vtype is', tree.Vtype
                        #print 'j is',j
                        if not j.find('trk_SF_Run') != -1:
                            if 'abseta' in name[1]:
                                self.weight.append(
                                    lepCorr.get_2D(vLeptons[0].pt,
                                                   abs(vLeptons[0].eta)))
                            else:
                                self.weight.append(
                                    lepCorr.get_2D(vLeptons[0].pt,
                                                   vLeptons[0].eta))
                        ## SF are not applied on "main" electron but on the veto electron
                        #elif j.find('failingVeto_out') != -1 and tree.Vtype == 3:
                        #    # in case no electron has been vetoed, set SF to 1
                        #    if tree.nElectron < 2:
                        #        w = [1., 0]
                        #        self.weight.append(w)
                        #        #self.weight[0][0] = 1.
                        #        #self.weight[0][1] = 0.
                        #    else:
                        #        for i in range(tree.nElectron):
                        #            if i == tree.VElectronIdx: continue #not additional lepton but main lepton
                        #            self.weight.append(lepCorr.get_2D(tree.Electron_pt[i],tree.Electron_eta[i]))
                        #            break
                        #    #print 'nElectron', tree.nElectron
                        #    #print 'weight is', self.weight[0][0]
                        ##1-D binned SF
                        elif j.find('trk_SF_Run') != -1:
                            self.weight.append(lepCorr.get_1D(vLeptons[0].eta))

                        if tree.Vtype == 2:
                            #Not filling the branches yet because need to separate run BCDEF and GH
                            #IDISO
                            if j.find('muon_ID_BCDEF') != -1:
                                self.computeSF_SingleLep(muID_BCDEF)
                            elif j.find('muon_ID_GH') != -1:
                                self.computeSF_SingleLep(muID_GH)
                            elif j.find('muon_ISO_BCDEF') != -1:
                                self.computeSF_SingleLep(muISO_BCDEF)
                            elif j.find('muon_ISO_GH') != -1:
                                self.computeSF_SingleLep(muISO_GH)
                            #TRK
                            elif j.find('trk_SF_RunBCDEF') != -1:
                                self.computeSF_SingleLep(muTRK_BCDEF)
                            elif j.find('trk_SF_RunGH') != -1:
                                self.computeSF_SingleLep(muTRK_GH)
                            #TRIG
                            elif j.find('EfficienciesAndSF_RunBtoF') != -1:
                                self.computeSF_SingleLep(muTrigg_BCDEF)
                            elif j.find('theJSONfile_Period4') != -1:
                                self.computeSF_SingleLep(muTrigg_GH)
                        elif tree.Vtype == 3:
                            #Here the branches are filled directly
                            #IDISO
                            if j.find('EIDISO_WH_out') != -1:
                                self.computeSF_SingleLep(
                                    self.branchBuffers['weight_SF_TightIDnISO']
                                )
                            #TRK
                            elif j.find('ScaleFactor_etracker_80x') != -1:
                                self.computeSF_SingleLep(
                                    self.branchBuffers['weight_SF_TRK'])
                            #TRIG
                            elif j.find('Tight27AfterIDISO_out') != -1:
                                self.computeSF_SingleLep(
                                    self.
                                    branchBuffers['eTrigSFWeight_singleEle80'])
                            ##VETO
                            #elif j.find('failingVeto_out') != -1:
                            #    self.computeSF_SingleLep(self.branchBuffers['eVeto'])

                    #Fill muon triggers
                    if tree.Vtype == 2:
                        #Fill branches for muon
                        #Tracker
                        self.getLumiAvrgSF(muTRK_BCDEF, (20.1 / 36.4),
                                           muTRK_GH, (16.3 / 36.4),
                                           self.branchBuffers['weight_SF_TRK'])
                        #ID and ISO
                        self.getLumiAvrgSF(
                            muID_BCDEF, (20.1 / 36.4), muID_GH, (16.3 / 36.4),
                            self.branchBuffers['weight_SF_TightID'])
                        self.getLumiAvrgSF(
                            muISO_BCDEF, (20.1 / 36.4), muISO_GH,
                            (16.3 / 36.4),
                            self.branchBuffers['weight_SF_TightISO'])

                        self.branchBuffers['weight_SF_TightIDnISO'][
                            0] = self.branchBuffers['weight_SF_TightID'][
                                0] * self.branchBuffers['weight_SF_TightISO'][0]
                        self.branchBuffers['weight_SF_TightIDnISO'][
                            1] = self.branchBuffers['weight_SF_TightID'][
                                1] * self.branchBuffers['weight_SF_TightISO'][1]
                        self.branchBuffers['weight_SF_TightIDnISO'][
                            2] = self.branchBuffers['weight_SF_TightID'][
                                2] * self.branchBuffers['weight_SF_TightISO'][2]

                        #Trigger
                        self.getLumiAvrgSF(
                            muTrigg_BCDEF, (20.1 / 36.4), muTrigg_GH,
                            (16.3 / 36.4),
                            self.branchBuffers['muTrigSFWeight_singlemu'])

                    self.branchBuffers['weight_SF_Lepton'][
                        0] = self.branchBuffers['weight_SF_TRK'][
                            0] * self.branchBuffers['weight_SF_TightIDnISO'][0]
                    self.branchBuffers['weight_SF_Lepton'][
                        1] = self.branchBuffers['weight_SF_TRK'][
                            1] * self.branchBuffers['weight_SF_TightIDnISO'][1]
                    self.branchBuffers['weight_SF_Lepton'][
                        2] = self.branchBuffers['weight_SF_TRK'][
                            2] * self.branchBuffers['weight_SF_TightIDnISO'][2]
        return isGoodEvent
コード例 #6
0
ファイル: LeptonWeightsNano.py プロジェクト: perrozzi/Xbb
    def processEvent(self, tree):
        isGoodEvent = True
        currentEntry = tree.GetReadEntry()
        # if current entry has not been processed yet
        if currentEntry != self.lastEntry:
            self.lastEntry = currentEntry
            # ================ Lepton Scale Factors =================
            # For custom made form own JSON files

            if self.channel == 'Zll' or len(self.channel) < 1:
                #Reinitialize all the variables
                for branchName in ['weight_SF_LooseID','weight_SF_LooseISO','weight_SF_LooseIDnISO', 'weight_SF_TRK', 'weight_SF_Lepton', 'eTrigSFWeight_doubleEle80x', 'muTrigSFWeight_doublemu']:
                    self.branchBuffers[branchName][0] = 1.0
                    self.branchBuffers[branchName][1] = 0.0
                    self.branchBuffers[branchName][2] = 0.0
                for branchName in ['weight_SF_LooseIDnISO_B', 'weight_SF_LooseIDnISO_E']:
                    self.branchBuffers[branchName][0] = 0.0
                    self.branchBuffers[branchName][1] = 0.0

                muID_BCDEF = [1.,0.,0.]
                muID_GH = [1.,0.,0.]
                muISO_BCDEF = [1.,0.,0.]
                muISO_GH = [1.,0.,0.]
                muTRK_BCDEF= [1.0,0.,0.]
                muTRK_GH = [1.0,0.,0.]
                btagSF = [1.,0.,0.]
                #for muon trigger
                 #Run BCDEFG
                effDataBCDEFG_leg8 = []
                effDataBCDEFG_leg17= []
                effMCBCDEFG_leg8= []
                effMCBCDEFG_leg17 = []
                 #Run H
                effDataH_leg8 = []
                effDataH_leg17 = []
                effMCH_leg8 = []
                effMCH_leg17 = []
                 #Run H dZ
                effDataH_DZ= []
                effMCH_DZ= []

                wdir = self.config.get('Directories', 'vhbbpath')

                jsons = {
                    #
                    #Muon
                    #
                    #ID and ISO
                    wdir+'/python/json/V25/muon_ID_BCDEFv2.json' : ['MC_NUM_LooseID_DEN_genTracks_PAR_pt_eta', 'abseta_pt_ratio'],
                    wdir+'/python/json/V25/muon_ID_GHv2.json' : ['MC_NUM_LooseID_DEN_genTracks_PAR_pt_eta', 'abseta_pt_ratio'],
                    wdir+'/python/json/V25/muon_ISO_BCDEFv2.json' : ['LooseISO_LooseID_pt_eta', 'abseta_pt_ratio'],
                    wdir+'/python/json/V25/muon_ISO_GHv2.json' : ['LooseISO_LooseID_pt_eta', 'abseta_pt_ratio'],
                    #Tracker
                    wdir+'/python/json/V25/trk_SF_RunBCDEF.json' : ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                    wdir+'/python/json/V25/trk_SF_RunGH.json' : ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                    #Trigg
                        #BCDEFG
                    wdir+'/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8.json' : ['MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_DATA'],
                    wdir+'/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17.json' : ['MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_DATA'],
                    wdir+'/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8.json' : ['MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_MC'],
                    wdir+'/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17.json' : ['MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_MC'],
                        #H
                            #no DZ
                    wdir+'/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg8.json' : ['MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_DATA'],
                    wdir+'/python/json/V25/Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg17.json' : ['MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_DATA'],
                    wdir+'/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg8.json' : ['MC_NUM_hlt_Mu17_Mu8_OR_TkMu8_leg8_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_MC'],
                    wdir+'/python/json/V25/MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg17.json' : ['MC_NUM_hlt_Mu17Mu8_leg17_DEN_LooseIDnISO_PAR_pt_eta', 'abseta_pt_MC'],
                            #with DZ
                    wdir+'/python/json/V25/DATA_EfficienciesAndSF_dZ_numH.json' : ['MC_NUM_dZ_DEN_hlt_Mu17_Mu8_OR_TkMu8_loose_PAR_eta1_eta2', 'tag_abseta_abseta_DATA'],
                    wdir+'/python/json/V25/MC_EfficienciesAndSF_dZ_numH.json' : ['MC_NUM_dZ_DEN_hlt_Mu17_Mu8_OR_TkMu8_loose_PAR_eta1_eta2', 'tag_abseta_abseta_MC'],
                    #
                    #Electron
                    #
                    #ID and ISO
                    wdir+'/python/json/V25/EIDISO_ZH_out.json' : ['EIDISO_ZH', 'eta_pt_ratio'],
                    #Tracker
                    wdir+'/python/json/V25/ScaleFactor_etracker_80x.json' : ['ScaleFactor_tracker_80x', 'eta_pt_ratio'],
                    #Trigg
                    wdir+'/python/json/V25/DiEleLeg1AfterIDISO_out.json' : ['DiEleLeg1AfterIDISO', 'eta_pt_ratio'],
                    wdir+'/python/json/V25/DiEleLeg2AfterIDISO_out.json' : ['DiEleLeg2AfterIDISO', 'eta_pt_ratio']
                    }
                for j, name in jsons.iteritems():

                    self.weight = []
                    lepCorrIdentifier = j + '_' + name[0] + '_' + name[1]
                    if lepCorrIdentifier not in self.leptonSF:
                        self.leptonSF[lepCorrIdentifier] = LeptonSF(j , name[0], name[1])
                    lepCorr = self.leptonSF[lepCorrIdentifier] 

                    # recompute vLeptons
                    vLepSelector = vLeptonSelector(tree)
                    Vtype = vLepSelector.getVtype()
                    vLeptons = vLepSelector.getVleptons()
                            
                    # cross check vtypes
                    if Vtype != tree.Vtype:
                        print "\x1b[97m\x1b[41mVtype mismatch!!!!!\x1b[0m"
                        print zMuons, zElectrons, wMuons, wElectrons
                        print "vLeptons:", vLeptons
                        raise Exception("VtypeMismatch")

                    #2-D binned SF
                    if not j.find('trk_SF_Run') != -1 and not j.find('EfficienciesAndSF_dZ_numH') != -1:
                        if 'abseta' in  name[1]:
                            self.weight.append(lepCorr.get_2D(eta=abs(vLeptons[0].eta), pt=vLeptons[0].pt))
                            self.weight.append(lepCorr.get_2D(eta=abs(vLeptons[1].eta), pt=vLeptons[1].pt))
                        else:
                            self.weight.append(lepCorr.get_2D(eta=vLeptons[0].eta, pt=vLeptons[0].pt))
                            self.weight.append(lepCorr.get_2D(eta=vLeptons[1].eta, pt=vLeptons[1].pt))
                    elif not j.find('trk_SF_Run') != -1 and j.find('EfficienciesAndSF_dZ_numH') != -1:
                        #???????
                        self.weight.append(lepCorr.get_2D(vLeptons[0].eta, vLeptons[1].eta))
                        self.weight.append(lepCorr.get_2D(vLeptons[1].eta, vLeptons[0].eta))
                    #1-D binned SF
                    else:
                        self.weight.append(lepCorr.get_1D(vLeptons[0].eta))
                        self.weight.append(lepCorr.get_1D(vLeptons[1].eta))

                    if tree.Vtype == 0:
                        #IDISO
                        if j.find('muon_ID_BCDEF') != -1:
                            self.computeSF(muID_BCDEF)
                        elif j.find('muon_ID_GH') != -1:
                            self.computeSF(muID_GH)
                        elif j.find('muon_ISO_BCDEF') != -1:
                            self.computeSF(muISO_BCDEF)
                        elif j.find('muon_ISO_GH') != -1:
                            self.computeSF(muISO_GH)
                        #TRK
                        elif j.find('trk_SF_RunBCDEF') != -1:
                            self.computeSF(muTRK_BCDEF)
                        elif j.find('trk_SF_RunGH') != -1:
                            self.computeSF(muTRK_GH)
                        #TRIG
                        elif j.find('EfficienciesAndSF_doublehlt_perleg') != -1:
                                #BCDEFG
                            if   j.find('Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8') != -1:
                                #compute the efficiency for both legs
                                effDataBCDEFG_leg8.append(self.computeSF_leg(0))
                                effDataBCDEFG_leg8.append(self.computeSF_leg(1))
                            elif j.find('Data_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17') != -1:
                                effDataBCDEFG_leg17.append(self.computeSF_leg(0))
                                effDataBCDEFG_leg17.append(self.computeSF_leg(1))
                            elif j.find('MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg8') != -1:
                                effMCBCDEFG_leg8.append(self.computeSF_leg(0))
                                effMCBCDEFG_leg8.append(self.computeSF_leg(1))
                            elif j.find('MC_EfficienciesAndSF_doublehlt_perleg_RunBCDEFG_leg17') != -1:
                                effMCBCDEFG_leg17.append(self.computeSF_leg(0))
                                effMCBCDEFG_leg17.append(self.computeSF_leg(1))
                                #H
                            elif j.find('Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg8') != -1:
                                effDataH_leg8.append(self.computeSF_leg(0))
                                effDataH_leg8.append(self.computeSF_leg(1))
                            elif j.find('Data_EfficienciesAndSF_doublehlt_perleg_RunH_leg17') != -1:
                                effDataH_leg17.append(self.computeSF_leg(0))
                                effDataH_leg17.append(self.computeSF_leg(1))
                            elif j.find('MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg8') != -1:
                                effMCH_leg8.append(self.computeSF_leg(0))
                                effMCH_leg8.append(self.computeSF_leg(1))
                            elif j.find('MC_EfficienciesAndSF_doublehlt_perleg_RunH_leg17') != -1:
                                effMCH_leg17.append(self.computeSF_leg(0))
                                effMCH_leg17.append(self.computeSF_leg(1))
                                #H dZ only
                        elif j.find('DATA_EfficienciesAndSF_dZ_numH') != -1:
                            effDataH_DZ.append(self.computeSF_leg(0))
                            effDataH_DZ.append(self.computeSF_leg(1))
                        elif j.find('MC_EfficienciesAndSF_dZ_numH') != -1:
                            effMCH_DZ.append(self.computeSF_leg(0))
                            effMCH_DZ.append(self.computeSF_leg(1))

                    elif tree.Vtype == 1:
                        #IDISO
                        if j.find('EIDISO_ZH_out') != -1:
                            self.computeSF(self.branchBuffers['weight_SF_LooseIDnISO'])
                            self.computeSF_region(self.branchBuffers['weight_SF_LooseIDnISO_B'], self.branchBuffers['weight_SF_LooseIDnISO_E'], vLeptons[0].eta, vLeptons[1].eta, 1.566)
                        #TRK
                        elif j.find('ScaleFactor_etracker_80x') != -1:
                            self.computeSF(self.branchBuffers['weight_SF_TRK'])
                        #TRIG
                        elif j.find('DiEleLeg1AfterIDISO_out') != -1:
                            eff1 = self.weight[0][0]
                            eff1Up = (self.weight[0][0]+self.weight[0][1])
                            eff1Down = (self.weight[0][0]-self.weight[0][1])
                        elif j.find('DiEleLeg2AfterIDISO_out') != -1:
                            eff2 = self.weight[1][0]
                            eff2Up = (self.weight[1][0]+self.weight[1][1])
                            eff2Down = (self.weight[1][0]-self.weight[1][1])
                #//// from 6ae102d
                if tree.Vtype == 0:
                    #print 'muTRK_BCDEF is', muTRK_BCDEF
                    #print 'muTRK_GH is', muTRK_GH
                    #print 'muID_BCDEF is', muID_BCDEF
                    #print 'muID_GH is', muID_GH
                    #print 'muISO_BCDEF is', muISO_BCDEF
                    #print 'muISO_GH is', muISO_GH

                    #Tracker
                    self.getLumiAvrgSF(muTRK_BCDEF,(20.1/36.4),muTRK_GH,(16.3/36.4),self.branchBuffers['weight_SF_TRK'])
                    #ID and ISO
                    self.getLumiAvrgSF(muID_BCDEF,(20.1/36.4),muID_GH,(16.3/36.4),self.branchBuffers['weight_SF_LooseID'])
                    self.getLumiAvrgSF(muISO_BCDEF,(20.1/36.4),muISO_GH,(16.3/36.4),self.branchBuffers['weight_SF_LooseISO'])

                    self.branchBuffers['weight_SF_LooseIDnISO'][0] = self.branchBuffers['weight_SF_LooseID'][0]*self.branchBuffers['weight_SF_LooseISO'][0]
                    self.branchBuffers['weight_SF_LooseIDnISO'][1] = self.branchBuffers['weight_SF_LooseID'][1]*self.branchBuffers['weight_SF_LooseISO'][1]
                    self.branchBuffers['weight_SF_LooseIDnISO'][2] = self.branchBuffers['weight_SF_LooseID'][2]*self.branchBuffers['weight_SF_LooseISO'][2]
                    #Trigger
                        #BCDEFG no DZ
                    EffData_BCDEFG = [1.0,0.]
                    EffMC_BCDEFG = [1.0,0.]
                    SF_BCDEFG = [1.0,0.,0.]
                    EffData_BCDEFG = self.computeEventSF_fromleg(effDataBCDEFG_leg8,effDataBCDEFG_leg17)
                    EffMC_BCDEFG = self.computeEventSF_fromleg(effMCBCDEFG_leg8,effMCBCDEFG_leg17)
                    SF_BCDEFG[0] =  (EffData_BCDEFG[0]/EffMC_BCDEFG[0])
                    SF_BCDEFG[1] = (1-math.sqrt(EffData_BCDEFG[1]**2+ EffMC_BCDEFG[1]**2))*SF_BCDEFG[0]
                    SF_BCDEFG[2] = (1+math.sqrt(EffData_BCDEFG[1]**2+ EffMC_BCDEFG[1]**2))*SF_BCDEFG[0]
                        #H no DZ
                    EffData_H = [1.0,0.]
                    EffMC_H = [1.0,0.]
                    SF_H = [1.0,0.,0.]
                    EffData_H = self.computeEventSF_fromleg(effDataH_leg8,effDataH_leg17)
                    EffMC_H = self.computeEventSF_fromleg(effMCH_leg8,effMCH_leg17)
                    SF_H[0] =  (EffData_H[0]/EffMC_H[0])
                    SF_H[1] = (1-math.sqrt(EffData_H[1]**2+ EffMC_H[1]**2))*SF_H[0]
                    SF_H[2] = (1+math.sqrt(EffData_H[1]**2+ EffMC_H[1]**2))*SF_H[0]
                        #H DZ SF
                    EffData_DZ = [1.0,0.]
                    EffMC_DZ = [1.0,0.]
                    SF_DZ = [1.0,0.,0.]
                    EffData_DZ = self.computeEvenSF_DZ(effDataH_DZ)
                    EffMC_DZ = self.computeEvenSF_DZ(effMCH_DZ)
                    SF_DZ[0] = (EffData_DZ[0]/EffMC_DZ[0])
                    SF_DZ[1] = (1-math.sqrt(EffData_DZ[1]**2+ EffMC_DZ[1]**2))*SF_DZ[0]
                    SF_DZ[2] = (1+math.sqrt(EffData_DZ[1]**2+ EffMC_DZ[1]**2))*SF_DZ[0]

                    #print 'List of all the double trigger SF + uncert'
                    #print 'SF_BCDEFG:', SF_BCDEFG[0], '+', SF_BCDEFG[1], '-', SF_BCDEFG[2]
                    #print 'SF_H:', SF_H[0], '+', SF_H[1], '-', SF_H[2]
                    #print 'SF_DZ:', SF_DZ[0], '+', SF_DZ[1], '-', SF_DZ[2]
                    #Final weight
                    self.branchBuffers['muTrigSFWeight_doublemu'][0] = (27.221/35.827)*SF_BCDEFG[0] + (8.606/35.827)*SF_H[0]*SF_DZ[0]
                    self.branchBuffers['muTrigSFWeight_doublemu'][1] = (27.221/35.827)*SF_BCDEFG[1] + (8.606/35.827)*SF_H[1]*SF_DZ[1]
                    self.branchBuffers['muTrigSFWeight_doublemu'][2] = (27.221/35.827)*SF_BCDEFG[2] + (8.606/35.827)*SF_H[2]*SF_DZ[2]

                if tree.Vtype == 1:
                    self.branchBuffers['eTrigSFWeight_doubleEle80x'][0] = eff1*(1-eff2)*eff1 + eff2*(1-eff1)*eff2 + eff1*eff1*eff2*eff2
                    self.branchBuffers['eTrigSFWeight_doubleEle80x'][1] = eff1Down*(1-eff2Down)*eff1Down + eff2Down*(1-eff1Down)*eff2Down + eff1Down*eff1Down*eff2Down*eff2Down
                    self.branchBuffers['eTrigSFWeight_doubleEle80x'][2] = eff1Up*(1-eff2Up)*eff1Up + eff2Up*(1-eff1Up)*eff2Up + eff1Up*eff1Up*eff2Up*eff2Up


                #////


                self.branchBuffers['weight_SF_Lepton'][0] = self.branchBuffers['weight_SF_TRK'][0]*self.branchBuffers['weight_SF_LooseIDnISO'][0]
                self.branchBuffers['weight_SF_Lepton'][1] = self.branchBuffers['weight_SF_TRK'][1]*self.branchBuffers['weight_SF_LooseIDnISO'][1]
                self.branchBuffers['weight_SF_Lepton'][2] = self.branchBuffers['weight_SF_TRK'][2]*self.branchBuffers['weight_SF_LooseIDnISO'][2]
                #print "::", tree.Vtype_new, self.branchBuffers['weight_SF_Lepton']
                #print self.branchBuffers
                #raw_input()

            if self.channel == 'Wlv' or self.channel == 'Zvv' or len(self.channel) < 1:
                for branchName in ['weight_SF_TightID', 'weight_SF_TightISO', 'weight_SF_TightIDnISO', 'weight_SF_TRK', 'weight_SF_Lepton', 'eTrigSFWeight_singleEle80', 'muTrigSFWeight_singlemu']:
                    self.branchBuffers[branchName][0] = 1.0
                    self.branchBuffers[branchName][1] = 0.0
                    self.branchBuffers[branchName][2] = 0.0

                if tree.Vtype != 4:
                    muID_BCDEF = [1.,0.,0.]
                    muID_GH = [1.,0.,0.]
                    muISO_BCDEF = [1.,0.,0.]
                    muISO_GH = [1.,0.,0.]
                    muTRK_BCDEF= [1.0,0.,0.]
                    muTRK_GH = [1.0,0.,0.]
                    muTrigg_BCDEF = [1.0,0.,0.]
                    muTrigg_GH = [1.0,0.,0.]
                    wdir = self.config.get('Directories', 'vhbbpath')

                    jsons = {
                        #
                        #Muon
                        #
                        #ID and ISO
                        wdir+'/python/json/V25/muon_ID_BCDEFv2.json' : ['MC_NUM_TightID_DEN_genTracks_PAR_pt_eta', 'abseta_pt_ratio'], #eta pt
                        wdir+'/python/json/V25/muon_ID_GHv2.json' : ['MC_NUM_TightID_DEN_genTracks_PAR_pt_eta', 'abseta_pt_ratio'],
                        ###
                        wdir+'/python/json/V25/muon_ISO_BCDEFv2.json' : ['TightISO_TightID_pt_eta', 'abseta_pt_ratio'],
                        wdir+'/python/json/V25/muon_ISO_GHv2.json' : ['TightISO_TightID_pt_eta', 'abseta_pt_ratio'],
                        #Tracker
                        wdir+'/python/json/V25/trk_SF_RunBCDEF.json' : ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                        wdir+'/python/json/V25/trk_SF_RunGH.json' : ['Graph', 'ratio_eff_eta3_dr030e030_corr'],
                        #Trigg
                        #BCDEF
                        wdir+'/python/json/V25/EfficienciesAndSF_RunBtoF.json' : ['IsoMu24_OR_IsoTkMu24_PtEtaBins', 'abseta_pt_ratio'],
                        #GH
                        wdir+'/python/json/V25/theJSONfile_Period4.json' : ['IsoMu24_OR_IsoTkMu24_PtEtaBins', 'abseta_pt_ratio'],
                        ##
                        ##Electron
                        ##
                        ##ID and ISO (grouped as MVAid for electron)
                        wdir+'/python/json/V25/EIDISO_WH_out.json' : ['EIDISO_WH', 'eta_pt_ratio'],
                        #Tracker
                        wdir+'/python/json/V25/ScaleFactor_etracker_80x.json' : ['ScaleFactor_tracker_80x', 'eta_pt_ratio'],
                        #Trigg
                        wdir+'/python/json/V25/Tight27AfterIDISO_out.json' : ['Tight27AfterIDISO', 'eta_pt_ratio']
                        }

                    for j, name in jsons.iteritems():

                        self.weight = []
                        lepCorrIdentifier = j + '_' + name[0] + '_' + name[1]
                        if lepCorrIdentifier not in self.leptonSF:
                            self.leptonSF[lepCorrIdentifier] = LeptonSF(j , name[0], name[1])
                        lepCorr = self.leptonSF[lepCorrIdentifier] 

                        #2-D binned SF
                        if not j.find('trk_SF_Run') != -1:
                            if 'abseta' in  name[1]:
                                self.weight.append(lepCorr.get_2D(abs(vLeptons[0].eta), vLeptons[0].pt))
                            else:
                                self.weight.append(lepCorr.get_2D(vLeptons[0].eta, vLeptons[0].pt))
                        #1-D binned SF
                        else:
                            self.weight.append(lepCorr.get_1D(vLeptons[0].eta))

                        if tree.Vtype == 2:
                            #Not filling the branches yet because need to separate run BCDEF and GH
                            #IDISO
                            if j.find('muon_ID_BCDEF') != -1:
                                self.computeSF_SingleLep(muID_BCDEF)
                            elif j.find('muon_ID_GH') != -1:
                                self.computeSF_SingleLep(muID_GH)
                            elif j.find('muon_ISO_BCDEF') != -1:
                                self.computeSF_SingleLep(muISO_BCDEF)
                            elif j.find('muon_ISO_GH') != -1:
                                self.computeSF_SingleLep(muISO_GH)
                            #TRK
                            elif j.find('trk_SF_RunBCDEF') != -1:
                                self.computeSF_SingleLep(muTRK_BCDEF)
                            elif j.find('trk_SF_RunGH') != -1:
                                self.computeSF_SingleLep(muTRK_GH)
                            #TRIG
                            elif j.find('EfficienciesAndSF_RunBtoF') != -1:
                                self.computeSF_SingleLep(muTrigg_BCDEF)
                            elif j.find('theJSONfile_Period4') != -1:
                                self.computeSF_SingleLep(muTrigg_GH)
                        elif tree.Vtype == 3:
                            #Here the branches are filled directly
                            #IDISO
                            if j.find('EIDISO_WH_out') != -1:
                                self.computeSF_SingleLep(self.branchBuffers['weight_SF_TightIDnISO'])
                            #TRK
                            elif j.find('ScaleFactor_etracker_80x') != -1:
                                self.computeSF_SingleLep(self.branchBuffers['weight_SF_TRK'])
                            #TRIG
                            elif j.find('Tight27AfterIDISO_out') != -1:
                                self.computeSF_SingleLep(self.branchBuffers['eTrigSFWeight_singleEle80'])

                    #Fill muon triggers
                    if tree.Vtype == 2:
                        #Fill branches for muon
                        #Tracker
                        self.getLumiAvrgSF(muTRK_BCDEF,(20.1/36.4),muTRK_GH,(16.3/36.4),self.branchBuffers['weight_SF_TRK'])
                        #ID and ISO
                        self.getLumiAvrgSF(muID_BCDEF,(20.1/36.4),muID_GH,(16.3/36.4),self.branchBuffers['weight_SF_TightID'])
                        self.getLumiAvrgSF(muISO_BCDEF,(20.1/36.4),muISO_GH,(16.3/36.4),self.branchBuffers['weight_SF_TightISO'])

                        self.branchBuffers['weight_SF_TightIDnISO'][0] = self.branchBuffers['weight_SF_TightID'][0]*self.branchBuffers['weight_SF_TightISO'][0]
                        self.branchBuffers['weight_SF_TightIDnISO'][1] = self.branchBuffers['weight_SF_TightID'][1]*self.branchBuffers['weight_SF_TightISO'][1]
                        self.branchBuffers['weight_SF_TightIDnISO'][2] = self.branchBuffers['weight_SF_TightID'][2]*self.branchBuffers['weight_SF_TightISO'][2]

                        #Trigger
                        self.getLumiAvrgSF(muTrigg_BCDEF,(20.1/36.4),muTrigg_GH,(16.3/36.4),self.branchBuffers['muTrigSFWeight_singlemu'])

                    self.branchBuffers['weight_SF_Lepton'][0] = self.branchBuffers['weight_SF_TRK'][0]*self.branchBuffers['weight_SF_TightIDnISO'][0]
                    self.branchBuffers['weight_SF_Lepton'][1] = self.branchBuffers['weight_SF_TRK'][1]*self.branchBuffers['weight_SF_TightIDnISO'][1]
                    self.branchBuffers['weight_SF_Lepton'][2] = self.branchBuffers['weight_SF_TRK'][2]*self.branchBuffers['weight_SF_TightIDnISO'][2]
        return isGoodEvent
コード例 #7
0
    def processEvent(self, tree):

        if not self.hasBeenProcessed(tree):
            self.markProcessed(tree)

            for n in ["isZmm", "isZee", "isWenu", "isWmunu", "isZnn"]:
                self._b(n)[0] = 0
            self._b("lepMetDPhi")[0] = -99.0
            self._b("V_mt")[0] = -99.0
            self._b("V_pt")[0] = -99.0
            self._b("V_eta")[0] = -99.0
            self._b("V_phi")[0] = -99.0
            self._b("V_mass")[0] = -99.0
            self._b("vLidx")[0] = -1
            self._b("vLidx")[1] = -1

            if not self.skipJetSelection:
                self._b("hJidx")[0] = -1
                self._b("hJidx")[1] = -1

            self.cutFlow[0] += 1

            debugEvent = [tree.run, tree.event] in self.debugEvents
            if debugEvent:
                print "DEBUG-EVENT:", tree.run, tree.event

            # TRIGGER
            triggerPassed = {
                k: any([getattr(tree, x) for x in v if hasattr(tree, x)])
                for k, v in self.HltPaths.items()
            }
            #print("------------------------------------")
            #for k,v in self.HltPaths.items():
            #    print(k,v)
            #    for x in v:
            #        print(x, hasattr(tree,x))
            #        if hasattr(tree,x):
            #            print(getattr(tree,x))

            #print(triggerPassed, "triggerPassed")
            #print(self.channels, "self.channels")
            #if not ((triggerPassed['0-lep'] and "Znn" in self.channels) or (triggerPassed['1-lep'] and "Wln" in self.channels) or (triggerPassed['2-lep'] and  "Zll" in self.channels)):

            if debugEvent:
                print "triggers:", triggerPassed

            Vtype = tree.Vtype
            if self.recomputeVtype:
                leptonSelector = vLeptonSelector(tree,
                                                 config=self.config,
                                                 isoZmm=self.isoZmm,
                                                 isoZee=self.isoZee,
                                                 isoWmn=self.isoWmn,
                                                 isoWen=self.isoWen)
                customVtype = leptonSelector.getVtype()
                if customVtype != Vtype:
                    self.count("recomputeVtype_mismatch")
                else:
                    self.count("recomputeVtype_match")
                self.count("recomputeVtype_Vtype%d" % customVtype)
                Vtype = customVtype

            isZnn = Vtype == 4 and triggerPassed['Znn']
            isWln = Vtype in [2, 3] and triggerPassed['Wln']
            isZll = Vtype in [0, 1] and triggerPassed['Zll']

            if not any([isZll, isWln, isZnn]):
                return False
            self.cutFlow[1] += 1

            # LEPTONS
            if self.sample.identifier not in self.leptonFlav or self.leptonFlav[
                    self.sample.identifier] == Vtype:
                if Vtype == 0:
                    good_muons_2lep = self.HighestPtGoodMuonsOppCharge(
                        tree,
                        min_pt=20.0,
                        max_rel_iso=self.isoZmm,
                        idcut=self.idZmmCut,
                        etacut=2.4,
                        isOneLepton=False,
                        muonID=self.idZmm)
                    if len(good_muons_2lep) > 1:
                        self._b("isZmm")[0] = 1
                        self._b("vLidx")[0] = good_muons_2lep[0]
                        self._b("vLidx")[1] = good_muons_2lep[1]
                    elif debugEvent:
                        print "DEBUG-EVENT: 2 mu event, but less than 2 good muons -> discard"
                elif Vtype == 1:
                    good_elecs_2lep = self.HighestPtGoodElectronsOppCharge(
                        tree,
                        min_pt=20.0,
                        max_rel_iso=self.isoZee,
                        idcut=self.idZeeCut,
                        etacut=2.5,
                        isOneLepton=False,
                        electronID=self.idZee)
                    if len(good_elecs_2lep) > 1:
                        self._b("isZee")[0] = 1
                        self._b("vLidx")[0] = good_elecs_2lep[0]
                        self._b("vLidx")[1] = good_elecs_2lep[1]
                    elif debugEvent:
                        print "DEBUG-EVENT: 2 e event, but less than 2 good electrons -> discard"
                elif Vtype == 2:
                    good_muons_1lep = self.HighestPtGoodMuonsOppCharge(
                        tree,
                        min_pt=25.0,
                        max_rel_iso=self.isoWmn,
                        idcut=self.idWmnCut,
                        etacut=2.4,
                        isOneLepton=True,
                        muonID=self.idWmn)
                    if len(good_muons_1lep) > 0:
                        self._b("isWmunu")[0] = 1
                        self._b("vLidx")[0] = good_muons_1lep[0]
                        self._b("vLidx")[1] = -1
                    elif debugEvent:
                        print "DEBUG-EVENT: 1 mu event, but no good muon found"
                elif Vtype == 3:
                    good_elecs_1lep = self.HighestPtGoodElectronsOppCharge(
                        tree,
                        min_pt=30.0,
                        max_rel_iso=self.isoWen,
                        idcut=self.idWenCut,
                        etacut=2.5,
                        isOneLepton=True,
                        electronID=self.idWen)
                    if len(good_elecs_1lep) > 0:
                        self._b("isWenu")[0] = 1
                        self._b("vLidx")[0] = good_elecs_1lep[0]
                        self._b("vLidx")[1] = -1
                    elif debugEvent:
                        print "DEBUG-EVENT: 1 e event, but no good electron found"
                elif Vtype == 4:
                    passMetFilters = all(
                        [getattr(tree, x) for x in self.metFilters])
                    if tree.MET_Pt > self.vpt0lep and passMetFilters:
                        self._b("isZnn")[0] = 1
                    else:
                        if debugEvent:
                            print "DEBUG-EVENT: 0 lep event, but MET criteria not passed!"
                        return False
                else:
                    return False
            else:
                return False
            self.cutFlow[2] += 1

            # CHANNEL
            if (self._b("isZmm")[0]
                    or self._b("isZee")[0]) and not ("Zll" in self.channels):
                return False
            #elif (self._b("isWmunu")[0] or self._b("isWenu")[0]) and not ("Wln" in self.channels or "Znn" in self.channels):
            # update: now 1-lepton events are only needed for 1-lepton channel (before they were also needed for 0-lepton channel for tt CR)
            elif (self._b("isWmunu")[0]
                  or self._b("isWenu")[0]) and not ("Wln" in self.channels):
                return False
            elif (self._b("isZnn")[0]) and not ("Znn" in self.channels):
                return False
            self.cutFlow[3] += 1

            # VECTOR BOSON
            Vphi_syst = {}
            any_v_sysvar_passes = False
            if self._b("isZee")[0] or self._b("isZmm")[0]:
                lep1 = ROOT.TLorentzVector()
                lep2 = ROOT.TLorentzVector()
                i1 = self._b("vLidx")[0]
                i2 = self._b("vLidx")[1]
                if self._b("isZee")[0]:
                    lep1.SetPtEtaPhiM(tree.Electron_pt[i1],
                                      tree.Electron_eta[i1],
                                      tree.Electron_phi[i1],
                                      tree.Electron_mass[i1])
                    lep2.SetPtEtaPhiM(tree.Electron_pt[i2],
                                      tree.Electron_eta[i2],
                                      tree.Electron_phi[i2],
                                      tree.Electron_mass[i2])
                elif self._b("isZmm")[0]:
                    lep1.SetPtEtaPhiM(tree.Muon_pt[i1], tree.Muon_eta[i1],
                                      tree.Muon_phi[i1], tree.Muon_mass[i1])
                    lep2.SetPtEtaPhiM(tree.Muon_pt[i2], tree.Muon_eta[i2],
                                      tree.Muon_phi[i2], tree.Muon_mass[i2])
                V = lep1 + lep2
            elif self._b("isWenu")[0] or self._b("isWmunu")[0]:
                i1 = self._b("vLidx")[0]
                if self._b("isWenu")[0]:
                    sel_lepton_pt = tree.Electron_pt[i1]
                    sel_lepton_eta = tree.Electron_eta[i1]
                    sel_lepton_phi = tree.Electron_phi[i1]
                    sel_lepton_mass = tree.Electron_mass[i1]
                elif self._b("isWmunu")[0]:
                    sel_lepton_pt = tree.Muon_pt[i1]
                    sel_lepton_eta = tree.Muon_eta[i1]
                    sel_lepton_phi = tree.Muon_phi[i1]
                    sel_lepton_mass = tree.Muon_mass[i1]
                self._b("lepMetDPhi")[0] = abs(
                    ROOT.TVector2.Phi_mpi_pi(sel_lepton_phi - tree.MET_Phi))
                #if self._b("lepMetDPhi")[0] > 2.0:
                #    return False

                MET = ROOT.TLorentzVector()
                Lep = ROOT.TLorentzVector()
                MET.SetPtEtaPhiM(tree.MET_Pt, 0.0, tree.MET_Phi, 0.0)
                Lep.SetPtEtaPhiM(sel_lepton_pt, sel_lepton_eta, sel_lepton_phi,
                                 sel_lepton_mass)
                cosPhi12 = (Lep.Px() * MET.Px() +
                            Lep.Py() * MET.Py()) / (Lep.Pt() * MET.Pt())
                self._b("V_mt")[0] = ROOT.TMath.Sqrt(2 * Lep.Pt() * MET.Pt() *
                                                     (1 - cosPhi12))

                V = MET + Lep

                if self.sample.isMC():
                    MET_syst = ROOT.TLorentzVector()
                    for syst in self.METsystematics:
                        for UD in self._variations(syst):
                            MET_syst.SetPtEtaPhiM(
                                self._r('MET_pt_' + syst + UD), 0.0,
                                self._r('MET_phi_' + syst + UD), 0.0)
                            V_syst = MET_syst + Lep
                            Vphi_syst[syst + UD] = V_syst.Phi()
                            if V_syst.Pt() > self.vpt1lep:
                                any_v_sysvar_passes = True

            elif self._b("isZnn")[0]:
                MET = ROOT.TLorentzVector()
                MET.SetPtEtaPhiM(tree.MET_Pt, 0.0, tree.MET_Phi, 0.0)
                if self.sample.isMC():
                    for syst in self.METsystematics:
                        for UD in self._variations(syst):
                            Vphi_syst[syst + UD] = self._r('MET_phi_' + syst +
                                                           UD)
                            if self._r('MET_pt_' + syst + UD) > self.vpt0lep:
                                any_v_sysvar_passes = True
                V = MET
            else:
                self.count("fail_lepton_selection")
                return False

            self.cutFlow[4] += 1

            self._b("V_pt")[0] = V.Pt()
            self._b("V_eta")[0] = V.Eta()
            self._b("V_phi")[0] = V.Phi()
            self._b("V_mass")[0] = V.M()

            if (self._b("isZee")[0] or
                    self._b("isZmm")[0]) and self._b("V_pt")[0] < self.vpt2lep:
                return False
            elif self._b("isZnn")[0] and self._b(
                    "V_pt")[0] < self.vpt0lep and not any_v_sysvar_passes:
                return False
            elif (self._b("isWenu")[0] or
                  self._b("isWmunu")[0]) and (self._b("V_pt")[0] < self.vpt1lep
                                              and not any_v_sysvar_passes):
                return False

            self.cutFlow[5] += 1

            if self.skipJetSelection:
                self.cutFlow[7] += 1
                return True

            # JETS
            if self._b("isZnn")[0]:
                j1ptCut = 35.0
                j2ptCut = 35.0
                maxJetPtCut = 60.0
                j1BtagName = 'loose'
            elif self._b("isWmunu")[0] or self._b("isWenu")[0]:
                j1ptCut = 25.0
                j2ptCut = 25.0
                maxJetPtCut = 0.0
                j1BtagName = 'loose'
            elif self._b("isZmm")[0] or self._b("isZee")[0]:
                j1ptCut = 20.0
                j2ptCut = 20.0
                maxJetPtCut = 0.0
                j1BtagName = 'none'
            else:
                return False
            j2BtagName = 'none'

            # btagMaxCut can overwrite the default b-tag max cut
            if self.btagMaxCut is not None and len(self.btagMaxCut) > 0:
                j1BtagName = self.btagMaxCut

            any_taggerPassed_syst = False
            for jetDefinition in self.jetDefinitions:

                indexName = jetDefinition[
                    'indexName'] if 'indexName' in jetDefinition else ''
                taggerName = jetDefinition['taggerName']
                j1Btag = self.btagWPs[self.year][taggerName][j1BtagName]
                j2Btag = self.btagWPs[self.year][taggerName][j2BtagName]

                jetTagger = getattr(tree, taggerName)
                taggerSelection = lambda x: (len(x) == 2 and jetTagger[x[
                    0]] >= j1Btag and jetTagger[x[1]] >= j2Btag)

                # -> nominal
                selectedJets = self.HighestTaggerValueBJets(
                    tree,
                    j1ptCut,
                    j2ptCut,
                    taggerName,
                    puIdCut=self.puIdCut,
                    jetIdCut=self.jetIdCut,
                    maxJetPtCut=maxJetPtCut,
                    systList=None)
                taggerPassed = taggerSelection(selectedJets)
                if taggerPassed:
                    self._b("hJidx" + indexName)[0] = selectedJets[0]
                    self._b("hJidx" + indexName)[1] = selectedJets[1]
                    any_taggerPassed_syst = True
                    self.count("pass_tagger_" + taggerName)
                else:
                    if debugEvent:
                        print("DEBUG-EVENT: did not pass jet-selection.")
                        print("DEBUG-EVENT: selected jets:", selectedJets)
                        print("DEBUG-EVENT: passed btag cuts:", taggerPassed)
                    self._b("hJidx" + indexName)[0] = -1
                    self._b("hJidx" + indexName)[1] = -1

                # -> systematic variations
                if self.sample.isMC():
                    systList = [
                        "".join(x) for x in itertools.product(
                            self.systematics, ["Up", "Down"])
                    ]
                    nSystematics = len(systList)

                    # this returns a list of lists of jet indices for all systematic variations
                    selectedJets = self.HighestTaggerValueBJets(
                        tree,
                        j1ptCut,
                        j2ptCut,
                        taggerName,
                        puIdCut=self.puIdCut,
                        jetIdCut=self.jetIdCut,
                        maxJetPtCut=maxJetPtCut,
                        systList=systList)

                    # apply pre-selection on tagger
                    for j in range(nSystematics):
                        hJidxName_syst = "hJidx{suffix}_{syst}".format(
                            suffix=indexName, syst=systList[j])
                        if taggerSelection(selectedJets[j]):
                            self._b(hJidxName_syst)[0] = selectedJets[j][0]
                            self._b(hJidxName_syst)[1] = selectedJets[j][1]
                            any_taggerPassed_syst = True
                        else:
                            self._b(hJidxName_syst)[0] = -1
                            self._b(hJidxName_syst)[1] = -1

            #print tree.Hbb_fjidx,tree.FatJet_pt[tree.Hbb_fjidx] if(tree.Hbb_fjidx>-1) else "outside",V.Pt()

            # BOOSTED JET selection
            any_boostedJet_syst = False

            # nominal
            Hbb_fjidx = self.HighestTaggerValueFatJet(
                tree,
                ptCut=250.0,
                msdCut=50.0,
                etaCut=2.5,
                taggerName='FatJet_deepTagMD_bbvsLight',
                systList=None,
                Vphi=V.Phi())
            self._b("Hbb_fjidx")[0] = Hbb_fjidx
            if Hbb_fjidx > -1:
                any_boostedJet_syst = True

            # systematics
            if self.sample.isMC():
                systList = [
                    "".join(x) for x in itertools.product(
                        self.systematicsBoosted, ["Up", "Down"])
                ]
                nSystematics = len(systList)

                # return list of jet indices for systematic variations
                Hbb_fjidx_syst = self.HighestTaggerValueFatJet(
                    tree,
                    ptCut=250.0,
                    msdCut=50.0,
                    etaCut=2.5,
                    taggerName='FatJet_deepTagMD_bbvsLight',
                    systList=systList,
                    Vphi=V.Phi(),
                    Vphi_syst=Vphi_syst)
                for j in range(nSystematics):
                    fJidxName_syst = "Hbb_fjidx_{syst}".format(
                        syst=systList[j])
                    self._b(fJidxName_syst)[0] = Hbb_fjidx_syst[j]
                    if Hbb_fjidx_syst[j] > -1:
                        any_boostedJet_syst = True

            #boostedPass = (tree.Hbb_fjidx>-1 and tree.FatJet_Pt[tree.Hbb_fjidx]>250 and V.Pt()>250)  #AC: selection for boosted analysis
            boostedPass = (any_boostedJet_syst and V.Pt() > 250)

            if boostedPass:
                self.count("pass_boosted")

            # discard event if none of the jet selections finds two Higgs candidate jets
            #if not (boostedPass or defaultTaggerPassed or any([jets['isSelected'] for jets in self.jetDefinitions])):
            if not (boostedPass or any_taggerPassed_syst):
                return False

            self.cutFlow[6] += 1

            # yield in the end
            self.cutFlow[7] += 1
            if debugEvent:
                print "DEBUG-EVENT: event passed!!!"

        return True