Exemplo n.º 1
0
def analyze(self, E, PARAMS=None):
    if self.TRIGGER and self.SP is not None:
        if not Selections.passedTrigger(E): return
    DSAmuons = E.getPrimitives('DSAMUON')
    PATmuons = E.getPrimitives('PATMUON')
    Dimuons3 = E.getPrimitives('DIMUON')
    Event = E.getPrimitives('EVENT')

    eventWeight = 1.
    try:
        eventWeight = 1. if Event.weight > 0. else -1.
    except:
        pass

    selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjectsReordered(
        E,
        self.CUTS,
        Dimuons3,
        DSAmuons,
        PATmuons,
        keepHybrids=ARGS.HYBRIDS,
        option=ARGS.PCOPTION)
    if selectedDimuons is None: return

    self.COUNTS['events'] += 1
    self.COUNTS['selected'] += len(selectedDimuons)

    if self.SP is not None:
        if '4Mu' in self.NAME:
            mu11, mu12, mu21, mu22, X1, X2, H, P, extramu = E.getPrimitives(
                'GEN')
            genMuons = (mu11, mu12, mu21, mu22)
            genMuonPairs = ((mu11, mu12), (mu21, mu22))
        elif '2Mu2J' in self.NAME:
            mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN')
            genMuons = (mu1, mu2)
            genMuonPairs = ((mu1, mu2), )

        # do the signal matching
        if len(genMuonPairs) == 1:
            genMuonPair = genMuonPairs[0]
            dimuonMatches, muonMatches, exitcode = matchedDimuons(
                genMuonPair, selectedDimuons)
            if len(dimuonMatches) > 0:
                realMatches = {0: dimuonMatches[0]}
            else:
                realMatches = {}
        else:
            realMatches, dimuonMatches, muon0Matches, muon1Matches = matchedDimuonPairs(
                genMuonPairs, selectedDimuons)

        if len(realMatches) > 0: self.COUNTS['matchEvents'] += 1

        for pairIndex in realMatches:
            self.COUNTS['matches'] += 1
Exemplo n.º 2
0
def analyze(self, E, PARAMS=None):
    if self.TRIGGER and self.SP is not None:
        if not Selections.passedTrigger(E): return
    DSAmuons = E.getPrimitives('DSAMUON')
    PATmuons = E.getPrimitives('PATMUON')
    Dimuons3 = E.getPrimitives('DIMUON')
    Event = E.getPrimitives('EVENT')

    eventWeight = 1.
    try:
        eventWeight = 1. if Event.weight > 0. else -1.
    except:
        pass

    if self.SP is not None:
        if '4Mu' in self.NAME:
            mu11, mu12, mu21, mu22, X1, X2, H, P, extramu = E.getPrimitives(
                'GEN')
            genMuons = (mu11, mu12, mu21, mu22)
            genMuonPairs = ((mu11, mu12), (mu21, mu22))
        elif '2Mu2J' in self.NAME:
            mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN')
            genMuons = (mu1, mu2)
            genMuonPairs = ((mu1, mu2), )

        for pTCut in xrange(31):

            selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjectsReordered(
                E,
                self.CUTS,
                Dimuons3,
                DSAmuons,
                PATmuons,
                keepHybrids=True,
                option=3,
                pTCut=float(pTCut))
            if selectedDimuons is None: continue

            # do the signal matching
            if len(genMuonPairs) == 1:
                genMuonPair = genMuonPairs[0]
                dimuonMatches, muonMatches, exitcode = matchedDimuons(
                    genMuonPair, selectedDimuons)
                if len(dimuonMatches) > 0:
                    realMatches = {0: dimuonMatches[0]}
                else:
                    realMatches = {}
            else:
                realMatches, dimuonMatches, muon0Matches, muon1Matches = matchedDimuonPairs(
                    genMuonPairs, selectedDimuons)

            if len(realMatches) > 0:
                self.HISTS['nMatches'].Fill(float(pTCut), eventWeight)
def analyze(self, E, PARAMS=None):
    if self.TRIGGER and self.SP is not None:
        if not Selections.passedTrigger(E): return
    DSAmuons = E.getPrimitives('DSAMUON')
    PATmuons = E.getPrimitives('PATMUON')
    Dimuons3 = E.getPrimitives('DIMUON')
    Event = E.getPrimitives('EVENT')

    if self.SP is not None:
        if '4Mu' in self.NAME:
            mu11, mu12, mu21, mu22, X1, X2, H, P, extramu = E.getPrimitives(
                'GEN')
            genMuons = (mu11, mu12, mu21, mu22)
            genMuonPairs = ((mu11, mu12), (mu21, mu22))
        elif '2Mu2J' in self.NAME:
            mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN')
            genMuons = (mu1, mu2)
            genMuonPairs = ((mu1, mu2), )

    eventWeight = 1.
    try:
        eventWeight = 1. if Event.weight > 0. else -1.
    except:
        pass

    selectedDimuons, selectedDSAmuons, selectedPATmuons, debug_PC = Selector.SelectObjectsReordered(
        E, self.CUTS, Dimuons3, DSAmuons, PATmuons)
    if selectedDimuons is None: return

    # this script is for dumping Drell Yan events with Lxy Sig > 100
    # the output of this is used in badChi2.py

    for dim in selectedDimuons:
        if dim.composition == 'PAT' and dim.LxySig() > 100.:
            print '{:d} {:7d} {:10d} ::: {} ::: {:9.4f} ::: {:8.4f} ::: {:10.2f}'.format(
                Event.run,
                Event.lumi,
                Event.event,
                dim.ID,
                dim.LxySig(),
                dim.Lxy(),
                dim.normChi2,
            )
Exemplo n.º 4
0
def analyze(self, E, PARAMS=None):
    if self.TRIGGER and self.SP is not None:
        if not Selections.passedTrigger(E): return
    DSAmuons = E.getPrimitives('DSAMUON')
    PATmuons = E.getPrimitives('PATMUON')
    Dimuons3 = E.getPrimitives('DIMUON')
    Event = E.getPrimitives('EVENT')

    eventWeight = 1.
    try:
        eventWeight = 1. if Event.weight > 0. else -1.
    except:
        pass

    selectedDimuonsOld, selectedDSAmuonsOld = Selector.SelectObjects(
        E, self.CUTS, [dim for dim in Dimuons3 if dim.composition == 'DSA'],
        DSAmuons)
    if selectedDimuonsOld is None: return

    selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjectsReordered(
        E, self.CUTS, Dimuons3, DSAmuons, PATmuons)

    selectedDimuonsHyb, selectedDSAmuonsHyb, selectedPATmuonsHyb = Selector.SelectObjectsReordered(
        E,
        self.CUTS,
        Dimuons3,
        DSAmuons,
        PATmuons,
        keepHybrids=True,
        option=ARGS.PCOPTION)

    if self.SP is not None:
        if '4Mu' in self.NAME:
            mu11, mu12, mu21, mu22, X1, X2, H, P, extramu = E.getPrimitives(
                'GEN')
            genMuons = (mu11, mu12, mu21, mu22)
            genMuonPairs = ((mu11, mu12), (mu21, mu22))
        elif '2Mu2J' in self.NAME:
            mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN')
            genMuons = (mu1, mu2)
            genMuonPairs = ((mu1, mu2), )

        realMatches = {}
        if selectedDimuons is not None:
            # do the signal matching
            if len(genMuonPairs) == 1:
                genMuonPair = genMuonPairs[0]
                dimuonMatches, muonMatches, exitcode = matchedDimuons(
                    genMuonPair, selectedDimuons)
                if len(dimuonMatches) > 0:
                    realMatches = {0: dimuonMatches[0]}
                else:
                    realMatches = {}
            else:
                realMatches, dimuonMatches, muon0Matches, muon1Matches = matchedDimuonPairs(
                    genMuonPairs, selectedDimuons)

        if len(realMatches) == 0:
            if len(genMuonPairs) == 1:
                genMuonPair = genMuonPairs[0]
                dimuonMatches, muonMatches, exitcode = matchedDimuons(
                    genMuonPair, selectedDimuonsOld)
                if len(dimuonMatches) > 0:
                    realMatchesOld = {0: dimuonMatches[0]}
                else:
                    realMatchesOld = {}
            else:
                realMatchesOld, dimuonMatches, muon0Matches, muon1Matches = matchedDimuonPairs(
                    genMuonPairs, selectedDimuonsOld)

            if len(realMatchesOld) > 0:
                # huzzah!
                self.COUNTS['huzzah'] += 1
                HybridDimuons = [
                    dim for dim in Dimuons3 if dim.composition == 'HYBRID'
                ]
                HybridIDs = [dim.ID for dim in HybridDimuons]

                # defines a SegMatch, returns a pair of indices (called candidate)
                def lookForSegMatch(DSAmuon):
                    candidate = None
                    if DSAmuon.idx_SegMatch is None:
                        pass
                    elif len(DSAmuon.idx_SegMatch) > 1:
                        if DSAmuon.idx_ProxMatch in DSAmuon.idx_SegMatch:
                            candidate = DSAmuon.idx_ProxMatch
                        else:
                            # take first entry
                            # which is the smallest index = largest pT
                            candidate = DSAmuon.idx_SegMatch[0]
                    else:
                        candidate = DSAmuon.idx_SegMatch[0]
                    return candidate

                # check whether the DSA dimuons have hybrid replacements
                for dim in selectedDimuonsOld:
                    candidates = map(lookForSegMatch,
                                     (DSAmuons[dim.idx1], DSAmuons[dim.idx2]))

                    if candidates.count(None) == 1:
                        PATIndex = candidates[0] if candidates[
                            0] is not None else candidates[1]
                        DSAIndex = dim.idx2 if candidates[
                            1] is None else dim.idx1
                        testID = (DSAIndex, PATIndex)
                        if testID in HybridIDs:
                            self.COUNTS['hybfound'] += 1
                        else:
                            self.COUNTS['hybnot'] += 1
                    elif candidates.count(None) == 2:
                        self.COUNTS['nomatch'] += 1
                    elif candidates.count(None) == 0:
                        self.COUNTS['bothmatch'] += 1
                        PATDim = None
                        for pd in Dimuons3:
                            if pd.composition == 'PAT' and set(
                                    candidates).issubset(pd.ID):
                                PATDim = pd
                                break
                        if PATDim is None:
                            self.COUNTS['failedDim'] += 1
                            continue
                        elif PATmuons[PATDim.idx1].pt < 10. or PATmuons[
                                PATDim.idx2].pt < 10.:
                            self.COUNTS['failedPT'] += 1
                            continue
                        elif PATDim.LxyErr() > 99.:
                            self.COUNTS['failedLxyE'] += 1
                            continue
                        elif PATDim.mass < 5.:
                            self.COUNTS['failedM'] += 1
                            continue
                        else:
                            self.COUNTS['failedMatch'] += 1
                    else:
                        print 'What?'

                # see if gen muons matched with hybrid selection
                if selectedDimuonsHyb is not None:
                    if len(genMuonPairs) == 1:
                        genMuonPair = genMuonPairs[0]
                        dimuonMatches, muonMatches, exitcode = matchedDimuons(
                            genMuonPair, selectedDimuonsHyb)
                        if len(dimuonMatches) > 0:
                            realMatchesHyb = {0: dimuonMatches[0]}
                        else:
                            realMatchesHyb = {}
                    else:
                        realMatchesHyb, dimuonMatches, muon0Matches, muon1Matches = matchedDimuonPairs(
                            genMuonPairs, selectedDimuonsHyb)

                    if len(realMatchesHyb) > 0:
                        self.COUNTS['recovered'] += 1