Example #1
0
    def ToEvent(self, iEv):
        '''Navigate to a given event and process it.'''

        # output event structure
        self.event = Event()

        # navigating to the correct FWLite event
        self.iEvent = iEv
        self.events.to(iEv)
        self.LoadCollections(self.events)

        # reading CMG objects from the handle
        #COLIN this kind of stuff could be automatized
        cmgDiTaus = self.handles['cmgTauMuCorFullSelSVFit'].product()
        cmgLeptons = self.handles['leptons'].product()
        self.event.triggerObject = self.handles['cmgTriggerObjectSel'].product(
        )[0]
        self.event.vertices = self.handles['vertices'].product()
        cmgJets = self.handles['jets'].product()

        # converting them into my own python objects
        self.event.diTaus = [DiTau(diTau) for diTau in cmgDiTaus]
        self.event.leptons = [Lepton(lepton) for lepton in cmgLeptons]
        self.event.jets = [
            Jet(jet) for jet in cmgJets if testJet(jet, self.cfg.cuts)
        ]
        self.event.jets = []
        for cmgJet in cmgJets:
            if not testJet(jet, self.cfg.cuts):
                continue
            jet = Jet(cmgJet)
            # print jet.energy()
            jet.scaleEnergy(1)
            # print jet.energy()
            self.event.jets.append(jet)

        self.counters.counter('triggerPassed').inc('a: All events')
        if not self.triggerList.triggerPassed(self.event.triggerObject):
            return False
        self.counters.counter('triggerPassed').inc('b: Trig OK ')

        self.counters.counter('exactlyOneDiTau').inc('a: any # of di-taus ')
        if len(self.event.diTaus) == 0:
            print 'Event %d : No tau mu.' % i
            return False
        if len(self.event.diTaus) > 1:
            # print 'Event %d : Too many tau-mus: n = %d' % (iEv, len(self.event.diTaus))
            #COLIN could be nice to have a counter class
            # which knows why events are rejected. make histograms with that.
            self.logger.warning('Ev %d: more than 1 di-tau : n = %d' %
                                (iEv, len(self.event.diTaus)))

        self.counters.counter('exactlyOneDiTau').inc('b: at least 1 di-tau ')

        if not leptonAccept(self.event.leptons):
            return False
        self.counters.counter('exactlyOneDiTau').inc('c: exactly one lepton ')

        self.event.diTau = self.event.diTaus[0]
        if len(self.event.diTaus) > 1:
            self.event.diTau = bestDiTau(self.event.diTaus)
        elif len(self.event.diTaus) == 1:
            self.counters.counter('exactlyOneDiTau').inc(
                'd: exactly 1 di-tau ')
        else:
            raise ValueError('should not happen!')

        cuts = self.cfg.cuts

        self.counters.counter('singleDiTau').inc('a:  best di-tau')
        self.event.tau = Tau(self.event.diTau.leg1())
        if self.event.tau.calcEOverP() > 0.2:
            self.counters.counter('singleDiTau').inc('b:   E/p > 0.2 ')
        else:
            return False

        if self.event.tau.pt() > cuts.tauPt:
            self.counters.counter('singleDiTau').inc(
                'c:  tau pt > {ptCut:3.1f}'.format(ptCut=cuts.tauPt))
        else:
            return False

        self.event.lepton = Lepton(self.event.diTau.leg2())
        if self.event.lepton.pt() > cuts.lepPt:
            self.counters.counter('singleDiTau').inc(
                'd:  lep pt > {ptCut:3.1f}'.format(ptCut=cuts.lepPt))
        else:
            return False

        if abs(self.event.lepton.eta()) < cuts.lepEta:
            self.counters.counter('singleDiTau').inc(
                'e:  lep |eta| <{etaCut:3.1f}'.format(etaCut=cuts.lepEta))
        else:
            return False

        self.counters.counter('VBF').inc('a: all events ')
        if len(self.event.jets) > 1:
            self.counters.counter('VBF').inc('b: at least 2 jets ')
            self.event.vbf = VBF(self.event.jets)
            if self.event.vbf.mjj > cuts.VBF_Mjj:
                self.counters.counter('VBF').inc(
                    'c: Mjj > {mjj:3.1f}'.format(mjj=cuts.VBF_Mjj))
                if abs(self.event.vbf.deta) > cuts.VBF_Deta:
                    self.counters.counter('VBF').inc(
                        'd: deta > {deta:3.1f}'.format(deta=cuts.VBF_Deta))
                    if len(self.event.vbf.centralJets) == 0:
                        self.counters.counter('VBF').inc('e: no central jet ')

            # print self.event.vbf

        self.event.eventWeight = 1
        # self.event.triggerWeight = 1
        self.event.vertexWeight = 1
        self.event.tauEffWeight = 1
        self.event.lepEffWeight = 1
        if self.cmp.isMC:
            self.event.vertexWeight = self.handles['vertexWeight'].product()[0]
            self.event.eventWeight *= self.event.vertexWeight
            if self.trigEff.tauEff is not None:
                self.event.tauEffWeight = self.trigEff.tauEff(
                    self.event.tau.pt())
            if self.trigEff.lepEff is not None:
                self.event.lepEffWeight = self.trigEff.lepEff(
                    self.event.lepton.pt(), self.event.lepton.eta())
            self.event.eventWeight = self.event.vertexWeight * \
                                     self.event.tauEffWeight * \
                                     self.event.lepEffWeight

            # if self.cmp.turnOnCurve is not None:
            #    self.event.triggerWeight = self.cmp.turnOnCurve.weight(
            #        self.event.tau.pt() )
            #    self.event.eventWeight *= self.event.triggerWeight

        # self.averages['triggerWeight'].add( self.event.triggerWeight )
        self.averages['tauEffWeight'].add(self.event.tauEffWeight)
        self.averages['lepEffWeight'].add(self.event.lepEffWeight)
        self.averages['vertexWeight'].add(self.event.vertexWeight)
        self.averages['eventWeight'].add(self.event.eventWeight)

        # exclusive analysis
        regionName = self.regions.test(self.event)
        histoList = self.histoLists[regionName]
        histoList.Fill(self.event, self.event.eventWeight)

        # inclusive analysis
        incRegionName = inclusiveRegionName(regionName)
        histoList = self.histoLists[incRegionName]
        histoList.Fill(self.event, self.event.eventWeight)

        return True
Example #2
0
    def ToEvent( self, iEv ):
        '''Navigate to a given event and process it.'''

        # output event structure
        self.event = Event()

        # navigating to the correct FWLite event
        self.iEvent = iEv
        self.events.to(iEv)
        self.LoadCollections(self.events)

        # reading CMG objects from the handle
        #COLIN this kind of stuff could be automatized
        cmgDiTaus = self.handles['cmgTauMuCorFullSelSVFit'].product()
        cmgLeptons = self.handles['leptons'].product()
        self.event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]
        self.event.vertices = self.handles['vertices'].product()
        cmgJets = self.handles['jets'].product()
        
        # converting them into my own python objects
        self.event.diTaus = [ DiTau(diTau) for diTau in cmgDiTaus ]
        self.event.leptons = [ Lepton(lepton) for lepton in cmgLeptons ]
        self.event.jets = [ Jet(jet) for jet in cmgJets if testJet(jet, self.cfg.cuts) ]
        self.event.jets = []
        for cmgJet in cmgJets:
            if not testJet( jet, self.cfg.cuts):
                continue
            jet = Jet( cmgJet )
            # print jet.energy()
            jet.scaleEnergy( 1 )
            # print jet.energy()
            self.event.jets.append(jet)

        self.counters.counter('triggerPassed').inc('a: All events')
        if not self.triggerList.triggerPassed(self.event.triggerObject):
            return False
        self.counters.counter('triggerPassed').inc('b: Trig OK ')
        
        self.counters.counter('exactlyOneDiTau').inc('a: any # of di-taus ')
        if len(self.event.diTaus)==0:
            print 'Event %d : No tau mu.' % i
            return False
        if len(self.event.diTaus)>1:
            # print 'Event %d : Too many tau-mus: n = %d' % (iEv, len(self.event.diTaus)) 
            #COLIN could be nice to have a counter class
            # which knows why events are rejected. make histograms with that.
            self.logger.warning('Ev %d: more than 1 di-tau : n = %d' % (iEv,
                                                                        len(self.event.diTaus)))

        self.counters.counter('exactlyOneDiTau').inc('b: at least 1 di-tau ')
        
        if not leptonAccept(self.event.leptons):
            return False 
        self.counters.counter('exactlyOneDiTau').inc('c: exactly one lepton ')        

        self.event.diTau = self.event.diTaus[0]
        if len(self.event.diTaus)>1:
            self.event.diTau = bestDiTau( self.event.diTaus )
        elif len(self.event.diTaus)==1:
            self.counters.counter('exactlyOneDiTau').inc('d: exactly 1 di-tau ')
        else:
            raise ValueError('should not happen!')

        cuts = self.cfg.cuts
        
        self.counters.counter('singleDiTau').inc('a:  best di-tau')
        self.event.tau = Tau( self.event.diTau.leg1() )
        if self.event.tau.calcEOverP() > 0.2:
            self.counters.counter('singleDiTau').inc('b:   E/p > 0.2 ')
        else:
            return False

        if self.event.tau.pt()>cuts.tauPt:
            self.counters.counter('singleDiTau').inc('c:  tau pt > {ptCut:3.1f}'.format(ptCut = cuts.tauPt))
        else:
            return False

        self.event.lepton = Lepton( self.event.diTau.leg2() )
        if self.event.lepton.pt()>cuts.lepPt:
            self.counters.counter('singleDiTau').inc('d:  lep pt > {ptCut:3.1f}'.format(ptCut = cuts.lepPt))
        else:
            return False

        if abs( self.event.lepton.eta() ) < cuts.lepEta:
            self.counters.counter('singleDiTau').inc('e:  lep |eta| <{etaCut:3.1f}'.format(etaCut = cuts.lepEta))
        else:
            return False

        self.counters.counter('VBF').inc('a: all events ') 
        if len(self.event.jets)>1:
            self.counters.counter('VBF').inc('b: at least 2 jets ') 
            self.event.vbf = VBF( self.event.jets )
            if self.event.vbf.mjj > cuts.VBF_Mjj:
                self.counters.counter('VBF').inc('c: Mjj > {mjj:3.1f}'.format(mjj = cuts.VBF_Mjj))
                if abs(self.event.vbf.deta) > cuts.VBF_Deta:
                    self.counters.counter('VBF').inc('d: deta > {deta:3.1f}'.format(deta = cuts.VBF_Deta))
                    if len(self.event.vbf.centralJets)==0:
                        self.counters.counter('VBF').inc('e: no central jet ')
                        
                
            # print self.event.vbf


        self.event.eventWeight = 1
        # self.event.triggerWeight = 1
        self.event.vertexWeight = 1
        self.event.tauEffWeight = 1
        self.event.lepEffWeight = 1
        if self.cmp.isMC:
            self.event.vertexWeight = self.handles['vertexWeight'].product()[0]
            self.event.eventWeight *= self.event.vertexWeight
            if self.trigEff.tauEff is not None:
                self.event.tauEffWeight = self.trigEff.tauEff(self.event.tau.pt())
            if self.trigEff.lepEff is not None:
                self.event.lepEffWeight = self.trigEff.lepEff(
                    self.event.lepton.pt(),
                    self.event.lepton.eta() )
            self.event.eventWeight = self.event.vertexWeight * \
                                     self.event.tauEffWeight * \
                                     self.event.lepEffWeight
            
            # if self.cmp.turnOnCurve is not None:
            #    self.event.triggerWeight = self.cmp.turnOnCurve.weight(
            #        self.event.tau.pt() )
            #    self.event.eventWeight *= self.event.triggerWeight

        # self.averages['triggerWeight'].add( self.event.triggerWeight )
        self.averages['tauEffWeight'].add( self.event.tauEffWeight )
        self.averages['lepEffWeight'].add( self.event.lepEffWeight )
        self.averages['vertexWeight'].add( self.event.vertexWeight )
        self.averages['eventWeight'].add( self.event.eventWeight ) 

        # exclusive analysis 
        regionName = self.regions.test( self.event )
        histoList = self.histoLists[regionName]
        histoList.Fill( self.event, self.event.eventWeight )

        # inclusive analysis
        incRegionName = inclusiveRegionName( regionName )
        histoList = self.histoLists[incRegionName]
        histoList.Fill( self.event, self.event.eventWeight )
        
        return True
Example #3
0
    def process( self, iEv ):
        '''Navigate to a given event and process it.'''

        # output event structure
        self.event = Event()

        # navigating to the correct FWLite event
        self.iEvent = iEv
        self.events.to(iEv)
        self.LoadCollections(self.events)

        # reading CMG objects from the handle
        #COLIN this kind of stuff could be automatized
        cmgDiTaus = self.handles['diTau'].product()
        cmgLeptons = self.handles['leptons'].product()
        self.event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]
        self.event.vertices = self.handles['vertices'].product()
        cmgJets = self.handles['jets'].product()
        if self.cmp.isMC: 
            genParticles = self.mchandles['genParticles'].product()
            self.event.genParticles = map( GenParticle, genParticles)
        # converting them into my own python objects
        self.event.diTaus = [ DiTau(diTau) for diTau in cmgDiTaus ]
        self.event.leptons = [ Lepton(lepton) for lepton in cmgLeptons ]

        # self.event.dirtyJets = [ Jet(jet) for jet in cmgJets if testJet(jet, self.cfg.cuts) ] 
        self.event.dirtyJets = []
        for cmgJet in cmgJets:
            jet = Jet( cmgJet )
            if self.cmp.isMC:
                scale = random.gauss( self.cmp.jetScale, self.cmp.jetSmear)
                jet.scaleEnergy( scale )
            if not testJet( cmgJet, self.cfg.cuts):
                continue
            self.event.dirtyJets.append(jet)

        
        self.counters.counter('triggerPassed').inc('a: All events')
        if not self.triggerList.triggerPassed(self.event.triggerObject):
            return False
        self.counters.counter('triggerPassed').inc('b: Trig OK ')
        
        self.counters.counter('exactlyOneDiTau').inc('a: any # of di-taus ')
        if len(self.event.diTaus)==0:
            print 'Event %d : No di-tau.' % i
            return False
        if len(self.event.diTaus)>1:
            # print 'Event %d : Too many tau-mus: n = %d' % (iEv, len(self.event.diTaus)) 
            #COLIN could be nice to have a counter class
            # which knows why events are rejected. make histograms with that.
            self.logger.warning('Ev %d: more than 1 di-tau : n = %d' % (iEv,
                                                                        len(self.event.diTaus)))

        self.counters.counter('exactlyOneDiTau').inc('b: at least 1 di-tau ')

        #MUONS
        if not self.leptonAccept(self.event.leptons):
            return False 
        self.counters.counter('exactlyOneDiTau').inc('c: exactly one lepton ')        

        self.event.diTau = self.event.diTaus[0]
        if len(self.event.diTaus)>1:
            self.event.diTau = bestDiTau( self.event.diTaus )
        elif len(self.event.diTaus)==1:
            self.counters.counter('exactlyOneDiTau').inc('d: exactly 1 di-tau ')
        else:
            raise ValueError('should not happen!')

        cuts = self.cfg.cuts
        
        self.counters.counter('singleDiTau').inc('a:  best di-tau')
        self.event.tau = Tau( self.event.diTau.leg1() )
        if self.event.tau.decayMode() == 0 and \
               self.event.tau.calcEOverP() < 0.2: #MUONS
            return False
        else:
            self.counters.counter('singleDiTau').inc('b:   E/p > 0.2 ')

        if self.event.tau.pt()>cuts.tauPt:
            self.counters.counter('singleDiTau').inc('c:  tau pt > {ptCut:3.1f}'.format(ptCut = cuts.tauPt))
        else:
            return False

        self.event.lepton = Lepton( self.event.diTau.leg2() )
        if self.event.lepton.pt()>cuts.lepPt:
            self.counters.counter('singleDiTau').inc('d:  lep pt > {ptCut:3.1f}'.format(ptCut = cuts.lepPt))
        else:
            return False

        if abs( self.event.lepton.eta() ) < cuts.lepEta:
            self.counters.counter('singleDiTau').inc('e:  lep |eta| <{etaCut:3.1f}'.format(etaCut = cuts.lepEta))
        else:
            return False

        ##################  Starting from here, we have the di-tau ###############


        # clean up jet collection

        self.event.jets = cleanObjectCollection( self.event.dirtyJets,
                                                 masks = [self.event.diTau.leg1(),
                                                          self.event.diTau.leg2() ],
                                                 deltaRMin = 0.5 )
#         print '-----------'
#        if len(self.event.dirtyJets)>0:
#            print 'Dirty:'
#            print '\n\t'.join( map(str, self.event.dirtyJets) )
#            print self.event.diTau
#            print 'Clean:'
#            print '\n\t'.join( map(str, self.event.jets) )
        

        self.counters.counter('VBF').inc('a: all events ') 
        if len(self.event.jets)>1:
            self.counters.counter('VBF').inc('b: at least 2 jets ') 
            self.event.vbf = VBF( self.event.jets )
            if self.event.vbf.mjj > cuts.VBF_Mjj:
                self.counters.counter('VBF').inc('c: Mjj > {mjj:3.1f}'.format(mjj = cuts.VBF_Mjj))
                if abs(self.event.vbf.deta) > cuts.VBF_Deta:
                    self.counters.counter('VBF').inc('d: deta > {deta:3.1f}'.format(deta = cuts.VBF_Deta))
                    if len(self.event.vbf.centralJets)==0:
                        self.counters.counter('VBF').inc('e: no central jet ')
                        
                
        matched = None
        if self.cmp.name == 'DYJets':
            leg1DeltaR, leg2DeltaR = self.event.diTau.match( self.event.genParticles ) 
            if leg1DeltaR>-1 and leg1DeltaR < 0.1 and \
               leg2DeltaR>-1 and leg2DeltaR < 0.1:
                matched = True
            else:
                matched = False

        self.event.eventWeight = 1
        # self.event.triggerWeight = 1
        self.event.vertexWeight = 1
        self.event.tauEffWeight = 1
        self.event.lepEffWeight = 1
        self.event.generatorWeight = 1 
        if self.cmp.isMC:
            self.event.vertexWeight = self.handles['vertexWeight'].product()[0]
        if self.cmp.isEmbed:
            self.event.generatorWeight = self.embhandles['generatorWeight'].product()[0]
        if self.cmp.isMC or self.cmp.isEmbed:
            if self.trigEff.tauEff is not None:
                self.event.tauEffWeight = self.trigEff.tauEff(self.event.tau.pt())
            #MUONS
            if self.trigEff.lepEff is not None:
                self.event.lepEffWeight = self.trigEff.lepEff( self.event.lepton.pt(),
                                                               self.event.lepton.eta() )

        self.event.eventWeight = self.event.vertexWeight * \
                                 self.event.tauEffWeight * \
                                 self.event.lepEffWeight * \
                                 self.event.generatorWeight

        # self.averages['triggerWeight'].add( self.event.triggerWeight )
        self.averages['tauEffWeight'].add( self.event.tauEffWeight )
        self.averages['lepEffWeight'].add( self.event.lepEffWeight )
        self.averages['vertexWeight'].add( self.event.vertexWeight )
        self.averages['generatorWeight'].add( self.event.generatorWeight )
        self.averages['eventWeight'].add( self.event.eventWeight ) 

        regionName = self.regions.test( self.event )
        if matched is None or matched is True:
            self.output.Fill( self.event, regionName )
        elif matched is False: 
            self.outputFakes.Fill( self.event, regionName )
        else:
            raise ValueError('should not happen!')
        return True