def analyze(self, E, PARAMS=None): DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON') DSASelections = [Selections.MuonSelection(muon) for muon in DSAmuons] # loop over DSAmuons and select for muon, muonSelection in zip(DSAmuons, DSASelections): self.COUNTERS['MUON']['TOTAL'] += 1 muonSelection.IndividualIncrement(self.COUNTERS['MUON']['IND']) muonSelection.SequentialIncrement(self.COUNTERS['MUON']['SEQ']) muonSelection.NMinusOneIncrement(self.COUNTERS['MUON']['NM1']) # loop over dimuons and select for dimuon in Dimuons: muon1Selection = DSASelections[dimuon.idx1] muon2Selection = DSASelections[dimuon.idx2] if muon1Selection and muon2Selection: self.COUNTERS['DIMUON']['TOTAL'] += 1 dimuonSelection = Selections.DimuonSelection(dimuon) dimuonSelection.IndividualIncrement(self.COUNTERS['DIMUON']['IND']) dimuonSelection.SequentialIncrement(self.COUNTERS['DIMUON']['SEQ']) dimuonSelection.NMinusOneIncrement(self.COUNTERS['DIMUON']['NM1'])
def analyze(self, E, PARAMS=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), ) DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') #selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects(E, '_Combined_NS_NH_FPTE_PT_DCA_TRK_NDT_PV', Dimuons3, DSAmuons, PATmuons) #if selectedDimuons is None: selectedDimuons = [] selectedDimuons = [dim for dim in Dimuons3 if dim.composition == 'DSA'] selectedDSAmuons = [ mu for mu in DSAmuons if Selections.MuonSelection(mu, cutList=CUTLIST) ] for genMuonPair in genMuonPairs: genMuonSelection = Selections.AcceptanceSelection(genMuonPair) if not genMuonSelection: continue dimuonMatches, muonMatches, exitcode = AT.matchedDimuons( genMuonPair, selectedDimuons, selectedDSAmuons, vertex='BS') fillDen = exitcode.both and ((not exitcode.same) or (exitcode.same and exitcode.nextBest)) fillNum = exitcode.matched if fillDen: KEY = 'Lxy' F = lambda genMuon: genMuon.Lxy() if True: self.HISTS[KEY + 'Den'].Fill(F(genMuonPair[0])) if fillNum: self.HISTS[KEY + 'Eff'].Fill(F(genMuonPair[0])) if fillDen and fillNum: region = 'Less' if genMuonPair[0].Lxy() < 320. else 'More' genMuonMatches = exitcode.getBestGenMuonMatches(muonMatches) selDim = None for dim in selectedDimuons: if (genMuonMatches[0]['muon'].idx, genMuonMatches[1]['muon'].idx) == dim.ID: selDim = dim break if (genMuonMatches[1]['muon'].idx, genMuonMatches[0]['muon'].idx) == dim.ID: selDim = dim break for which, genMuon in enumerate(genMuonPair): RM = genMuonMatches[which]['muon'] GM = genMuon.BS pTRes = (RM.pt - GM.pt) / GM.pt self.HISTS['pTRes-' + region].Fill(pTRes) self.HISTS['LxyErr-' + region].Fill(selDim.LxyErr())
def analyze(self, E, PARAMS=None): Event = E.getPrimitives('EVENT') pileupWeight = PileupWeight(Event.nTruePV) if self.SP is not None: if '2Mu2J' in self.NAME: mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN') genMuons = (mu1, mu2) genMuonPairs = ((mu1, mu2), ) for op in self.COUNTS: for factor in self.COUNTS[op]: signalWeight = AT.SignalWeight( self.SP.cTau, OP[op](self.SP.cTau, float(factor)), mu1, X) self.COUNTS[op][factor]['nEvents'] += 1 self.COUNTS[op][factor]['sumWeights'] += pileupWeight # We don't add up the signal weights because with infinite statistics, # lifetime reweighting should result in the same number of events #self.COUNTS[op][factor]['sumWeights'] += signalWeight*pileupWeight if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return # take 10% of data: event numbers ending in 7 if 'DoubleMuon' in self.NAME and not self.ARGS.IDPHI: if Event.event % 10 != 7: return DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') cutstring = CUTSTRING if ('DoubleMuon' in self.NAME or ('DoubleMuon' not in self.NAME and self.SP is None)) and self.ARGS.IDPHI: cutstring = CUTSTRING.replace('DPHI', 'IDPHI') selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, cutstring, Dimuons3, DSAmuons, PATmuons) if selectedDimuons is not None: for dim in selectedDimuons: if dim.composition != 'DSA': continue if not Selections.modelDependentMassCut(self.SP.mX, dim.mass): continue if self.SP is not None: for op in self.COUNTS: for factor in self.COUNTS[op]: signalWeight = AT.SignalWeight( self.SP.cTau, OP[op](self.SP.cTau, float(factor)), mu1, X) self.COUNTS[op][factor][ 'passingWeights'] += signalWeight * pileupWeight self.COUNTS[op][factor]['passingWeightsSquared'] += ( signalWeight * pileupWeight)**2.
def analyze(self, E, PARAMS=None): if self.SP is None: raise Exception('[ANALYZER ERROR]: This script runs on signal only.') if self.TRIGGER: if not Selections.passedTrigger(E): return 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), ) DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON') ALL = True if 'All' in self.CUTS else False # require dimuons to pass all selections, and require DSA muons to pass all selections if ALL: DSASelections = [Selections.MuonSelection(muon) for muon in DSAmuons] selectedDSAmuons = [ mu for idx, mu in enumerate(DSAmuons) if DSASelections[idx] ] selectedDimuons = [ dim for idx, dim in enumerate(Dimuons) if DSASelections[dim.idx1] and DSASelections[dim.idx2] ] # don't require dimuons to pass all selections, and don't require DSA muons to pass all selections, either else: selectedDSAmuons = DSAmuons selectedDimuons = Dimuons for genMuonPair in genMuonPairs: # require genMuonPair to be within acceptance genMuonSelection = Selections.AcceptanceSelection(genMuonPair) if not genMuonSelection: continue dimuonMatches, muonMatches, exitcode = matchedDimuons(genMuonPair, selectedDimuons, selectedDSAmuons, vertex='BS') # fill denominator if both gen muons matched, either to different reco muons or, if the same, that there is a next best fillDen = exitcode.both and ((not exitcode.same) or (exitcode.same and exitcode.nextBest)) fillNum = exitcode.matched if fillDen: for KEY in CONFIG: F = CONFIG[KEY]['LAMBDA'] if True: self.HISTS[KEY + 'Den'].Fill(F(genMuonPair[0])) if fillNum: self.HISTS[KEY + 'Eff'].Fill(F(genMuonPair[0]))
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return 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), ) ACCEPT = False for genMuonPair in genMuonPairs: genAcceptance = Selections.AcceptanceSelection(genMuonPair) #genAcceptances = [Selections.AcceptanceSelection(genMuonPair[0]), Selections.AcceptanceSelection(genMuonPair[1])] if genAcceptance: ACCEPT = True # I ran this 4 times: # - selectedMuons = DSAmuons # - selectedMuons = DSAmuons passing Q.C. # - selectedMuons = DSAmuons passing Q.C. + pT > 10 # - selectedMuons = DSAmuons passing Q.C. + pT > 10 + eta < 2 DSAmuons = E.getPrimitives('DSAMUON') selectedMuons = { 'DSA': [ mu for mu in DSAmuons if Selections.MuonSelection(mu, cutList=CUTLIST) and mu.pt > 10. and abs(mu.eta) < 2. ] } if len(selectedMuons['DSA']) < 2: return HLTRECO = True HLTPaths, HLTMuons, L1TMuons = E.getPrimitives('TRIGGER') HLTMuonMatches = AT.matchedTrigger(HLTMuons, selectedMuons['DSA']) if not any([HLTMuonMatches[ij]['matchFound'] for ij in HLTMuonMatches]): HLTRECO = False vals = {'subPT': min([mu.pt for mu in genMuons]), 'Lxy': genMuons[0].Lxy()} for val in vals: if True: if True: self.HISTS['{}-Den-Nom'.format(val)].Fill(vals[val]) if HLTRECO: self.HISTS['{}-Eff-Nom'.format(val)].Fill(vals[val]) if ACCEPT: if True: self.HISTS['{}-Den-Acc'.format(val)].Fill(vals[val]) if HLTRECO: self.HISTS['{}-Eff-Acc'.format(val)].Fill(vals[val])
def analyze(self, E, PARAMS=None): if self.SP is None: raise Exception('[ANALYZER ERROR]: This script runs on signal only.') 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), ) Event = E.getPrimitives('EVENT') DSAmuons = E.getPrimitives('DSAMUON') SelectMuons = False # require muons to pass all selections if SelectMuons: DSASelections = [Selections.MuonSelection(muon) for muon in DSAmuons] selectedDSAmuons = [ mu for idx, mu in enumerate(DSAmuons) if DSASelections[idx] ] # don't require muons to pass all selections else: selectedDSAmuons = DSAmuons # loop over genMuons and count various matching criteria for genMuon in genMuons: self.COUNTERS['nGenMuons'] += 1 if Selections.AcceptanceSelection(genMuon): self.COUNTERS['nGenAcc'] += 1 matches = matchedMuons(genMuon, selectedDSAmuons) if len(matches) != 0: self.COUNTERS['nMatches'] += 1 if len(matches) > 1: self.COUNTERS['nMultiple'] += 1 if PARAMS.DUMP: dumpInfo(Event, genMuon, selectedDSAmuons, len(matches), extramu, PARAMS) if len(matches) not in self.COUNTERS['multiDict']: self.COUNTERS['multiDict'][len(matches)] = 0 self.COUNTERS['multiDict'][len(matches)] += 1
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None and not Selections.passedTrigger( E): return Event = E.getPrimitives('EVENT') DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON') eventWeight = 1. try: eventWeight = 1. if Event.weight > 0. else -1. except: pass DSASelections = [Selections.MuonSelection(muon) for muon in DSAmuons] DimuonSelections = [ Selections.DimuonSelection(dimuon) for dimuon in Dimuons ] for dimSel, dimuon in zip(DimuonSelections, Dimuons): DeltaPhiRegion = 'Less' if dimSel['deltaPhi'] else 'More' mu1, mu2 = DSAmuons[dimuon.idx1], DSAmuons[dimuon.idx2] mu1Sel, mu2Sel = DSASelections[dimuon.idx1], DSASelections[dimuon.idx2] for KEY in DIMUONCUTKEYS: # require muons to pass their full selection # require dimuons to pass their full selection except KEY # (and deltaPhi of course) if all((dimSel.allExcept('deltaPhi', KEY), mu1Sel, mu2Sel)): # reminder: expr is the lambda performed on object to get the value on which the cut is applied # e.g. Selections.CUTS['nStations'].expr(mu) == mu.nDTStations + mu.nCSCStations thisCut = Selections.CUTS[KEY] fillValue = thisCut.expr(dimuon) self.HISTS[NAME(KEY, DeltaPhiRegion)].Fill(fillValue, eventWeight) for KEY in MUONCUTKEYS: # require dimuons to pass their full selection # require muons to pass their full selection except KEY # (and deltaPhi of course) if all((dimSel.allExcept('deltaPhi'), mu1Sel.allExcept(KEY), mu2Sel.allExcept(KEY))): # reminder: expr is the lambda performed on object to get the value on which the cut is applied # e.g. Selections.CUTS['nStations'].expr(mu) == mu.nDTStations + mu.nCSCStations # mfunc is max if cut is < or <=; mfunc is min if cut is > or >= thisCut = Selections.CUTS[KEY] fillValue = thisCut.mfunc(thisCut.expr(mu1), thisCut.expr(mu2)) self.HISTS[NAME(KEY, DeltaPhiRegion)].Fill(fillValue, eventWeight)
def analyze(self, E, PARAMS=None): if self.SP is None: raise Exception('[ANALYZER ERROR]: This script runs on signal only.') 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),) Event = E.getPrimitives('EVENT' ) DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON' ) for genMuonPair in genMuonPairs: # require genMuonPair to be within acceptance genMuonSelection = Selections.AcceptanceSelection(genMuonPair) if not genMuonSelection: continue # check if any DSA muons match a genMuon dimuonMatches, muonMatches, exitcode = matchedDimuons(genMuonPair, Dimuons, DSAmuons, vertex='BS') # print if exitcode 1, 2, 3: gen muons matched (or exists next best), but no dimuon found, and Lxy>340 if exitcode in (1, 2, 3) and genMuonPair[0].Lxy() > 340.: dumpInfo(Event, genMuonPair, muonMatches, exitcode, DSAmuons, Dimuons, extramu, PARAMS)
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') # take 10% of data: event numbers ending in 7 if 'DoubleMuon' in self.NAME and not self.ARGS.IDPHI: if Event.event % 10 != 7: return DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') BASECUTS = '_Combined_REP_PC' eventWeight = 1. try: eventWeight = 1. if Event.weight > 0. else -1. except: pass def nDSA(selDims): return len([d for d in selDims if d.composition == 'DSA']) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects(E, BASECUTS, Dimuons3, DSAmuons, PATmuons, bumpFPTE=self.ARGS.BUMPFPTE) if selectedDimuons is not None: self.seqCounts['none'] += 1 self.HISTS['SEQ'].Fill(0., eventWeight) self.DSAseqCounts['none'] += nDSA(selectedDimuons) self.HISTS['DSA-SEQ'].Fill(0., eventWeight*nDSA(selectedDimuons)) for idx, omit in enumerate(CUTS): CUTSTRING = BASECUTS + '_' + '_'.join([c for c in CUTS if c != omit]) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects(E, CUTSTRING, Dimuons3, DSAmuons, PATmuons, bumpFPTE=self.ARGS.BUMPFPTE) if selectedDimuons is not None: self.omitCounts[omit] += 1 self.HISTS['NM1'].Fill(idx+1., eventWeight) self.DSAomitCounts[omit] += nDSA(selectedDimuons) self.HISTS['DSA-NM1'].Fill(idx+1., eventWeight*nDSA(selectedDimuons)) for idx in range(len(CUTS)): CUTSTRING = BASECUTS + '_' + '_'.join(CUTS[:idx+1]) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects(E, CUTSTRING, Dimuons3, DSAmuons, PATmuons, bumpFPTE=self.ARGS.BUMPFPTE) if selectedDimuons is not None: self.seqCounts[CUTS[idx]] += 1 self.HISTS['SEQ'].Fill(idx+1., eventWeight) self.DSAseqCounts[CUTS[idx]] += nDSA(selectedDimuons) self.HISTS['DSA-SEQ'].Fill(idx+1., eventWeight*nDSA(selectedDimuons)) if idx == len(CUTS)-1: self.omitCounts['none'] += 1 self.HISTS['NM1'].Fill(0., eventWeight) self.DSAomitCounts['none'] += nDSA(selectedDimuons) self.HISTS['DSA-NM1'].Fill(0., eventWeight*nDSA(selectedDimuons))
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') # take 10% of data: event numbers ending in 7 if 'DoubleMuon' in self.NAME and '_IDPHI' not in self.CUTS: if Event.event % 10 != 7: return DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') eventWeight = 1. try: eventWeight = 1. if Event.weight > 0. else -1. except: pass selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_PT', Dimuons3, DSAmuons, PATmuons) if selectedDimuons is not None: for dim in selectedDimuons: if dim.composition != 'DSA': continue self.HISTS['Lxy-before'].Fill(dim.Lxy(), eventWeight) self.HISTS['LxySig-before'].Fill(dim.LxySig(), eventWeight) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_REP_PT', Dimuons3, DSAmuons, PATmuons) if selectedDimuons is not None: for dim in selectedDimuons: if dim.composition != 'DSA': continue self.HISTS['Lxy-after'].Fill(dim.Lxy(), eventWeight) self.HISTS['LxySig-after'].Fill(dim.LxySig(), eventWeight)
def analyze(self, E, PARAMS=None): #selections if self.TRIGGER: if not Selections.passedTrigger(E): return dsaMuons = E.getPrimitives('DSAMUON') diMuons = E.getPrimitives('DIMUON') Primitives.CopyExtraRecoMuonInfo(diMuons, dsaMuons) 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), ) else: print "Haven't implemented these samples" return selectedDimuons = [dim for dim in diMuons if dim.Lxy() < 330] for genMuonPair in genMuonPairs: dimuonMatches, muonMatches, exitcode = AT.matchedDimuons( genMuonPair, selectedDimuons) if len(muonMatches[0]): fillStats(self, genMuonPair[0], muonMatches[0][0]['muon']) if len(muonMatches[1]): fillStats(self, genMuonPair[1], muonMatches[1][0]['muon']) return
def analyze(self, E, PARAMS=None): if self.TRIGGER: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') self.HISTS['pileup'].Fill(Event.nTruePV)
def analyze(self, E, PARAMS=None): if self.SP is None: raise Exception('[ANALYZER ERROR]: This script runs on signal only.') muons = E.getPrimitives('DSAMUON') # apply trigger if --trigger # skip events without at least 2 muons with pT > 30 if self.TRIGGER: if not Selections.passedTrigger(E): return numPT = 0 for mu in muons: if mu.pt > 30: numPT += 1 if numPT == 2: break if numPT < 2: return Event = E.getPrimitives('EVENT') dimuons = E.getPrimitives('DIMUON') 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), ) # loop over genMuonPairs, find dimuon, and do something based on result for genMuonPair in genMuonPairs: if len(dimuons) > 0: dimuonMatches, muonMatches, exitcode = matchedDimuons( genMuonPair, dimuons, muons) savedDimuon = dimuonMatches[0]['dim'] if len( dimuonMatches) > 0 else None if savedDimuon is not None: for dimuon in dimuons: if dimuon.idx1 == savedDimuon.idx1 and dimuon.idx2 == savedDimuon.idx2: print '1,' + ','.join([ '{:.4f}'.format(i) for i in (dimuon.deltaR, dimuon.normChi2, dimuon.Lxy() / dimuon.LxySig()) ]) else: print '0,' + ','.join([ '{:.4f}'.format(i) for i in (dimuon.deltaR, dimuon.normChi2, dimuon.Lxy() / dimuon.LxySig()) ]) else: for dimuon in dimuons: print '0,' + ','.join([ '{:.4f}'.format(i) for i in (dimuon.deltaR, dimuon.normChi2, dimuon.Lxy() / dimuon.LxySig()) ])
def analyze(self, E, PARAMS=None): if '2Mu2J' in self.NAME: mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN') genMuons = (mu1, mu2) genMuonPairs = ((mu1, mu2), ) for factor in self.WEIGHTS: weight = AT.SignalWeight(self.SP.cTau, self.SP.cTau / float(factor), mu1, X) self.WEIGHTS[factor] += weight self.HISTS['genLxy_{}'.format(factor)].Fill(mu1.Lxy(), weight) self.HISTS['genTime_{}'.format(factor)].Fill(mu1.Lxy() * X.mass / X.pt, weight) if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_REP_PT_DCA_PC_LXYE_MASS_CHI2_VTX_COSA_NPP_LXYSIG_TRK_OS_NDT_DPHI', Dimuons3, DSAmuons, PATmuons) if selectedDimuons is None: return for factor in self.WEIGHTS: weight = AT.SignalWeight(self.SP.cTau, self.SP.cTau / float(factor), mu1, X) for dim in selectedDimuons: self.HISTS['Lxy_{}_{}'.format(dim.composition[:3], factor)].Fill(dim.Lxy(), weight)
def analyze(self, E, PARAMS=None): #selections if self.TRIGGER: if not Selections.passedTrigger(E): return DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') Event = E.getPrimitives('EVENT') #selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects(E, '_Combined_NS_NH_FPTE_HLT_REP_PT_DCA_PC_LXYE_CHI2_VTX_COSA_NPP_TRK_NDT_DPHI', Dimuons3, DSAmuons, PATmuons) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects(E, '_Combined_NS_NH_FPTE_HLT_DCA_PC_LXYE_CHI2', Dimuons3, DSAmuons, PATmuons) if selectedDimuons is None: return foundDSADimuon = False for dimuon in selectedDimuons: if dimuon.LxySig() < 10.: continue #print dimuon self.HISTS[dimuon.composition+'-Lxy-Isolation'].Fill(dimuon.isoLxy) self.HISTS[dimuon.composition+'-Pmumu-Isolation'].Fill(dimuon.isoPmumu) self.HISTS[dimuon.composition+'-DimuonMax-Isolation'].Fill(max(dimuon.isoPmumu,dimuon.isoLxy)) self.HISTS[dimuon.composition+'-Mu1-Isolation'].Fill(dimuon.mu1.iso) self.HISTS[dimuon.composition+'-Mu2-Isolation'].Fill(dimuon.mu2.iso) self.HISTS[dimuon.composition+'-SingleMuonMax-Isolation'].Fill(max(dimuon.mu1.iso,dimuon.mu2.iso)) if dimuon.composition == 'DSA': global counter print "Event: " + str(counter) counter = counter +1 print dimuon foundDSADimuon = True self.HISTS['DSA p_{T} Spectrum'].Fill(min(dimuon.mu1.pt,dimuon.mu2.pt))
def analyze(self, E, PARAMS=None): # get dimuons Dimuons = E.getPrimitives('DIMUON') # loop over dimuons and fill if they pass their selection for dimuon in Dimuons: if Selections.DimuonSelection(dimuon): self.HISTS['pT'].Fill(dimuon.pt)
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') # take 10% of data: event numbers ending in 7 if 'DoubleMuon' in self.NAME and '_IDPHI' not in self.CUTS: if Event.event % 10 != 7: return DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') mu1, mu2, j1, j2, X, XP, H, P, extramu = E.getPrimitives('GEN') genMuons = (mu1, mu2) genMuonPairs = ((mu1, mu2), ) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_PT', Dimuons3, DSAmuons, PATmuons) if selectedDimuons is not None: genMuonPair = genMuonPairs[0] selectedDimuons = [ dim for dim in selectedDimuons if dim.composition == 'DSA' ] dimuonMatches, muonMatches, exitcode = AT.matchedDimuons( genMuonPair, selectedDimuons) if len(dimuonMatches) > 0: realMatches = {0: dimuonMatches[0]} else: realMatches = {} for pairIndex in realMatches: genMuon = genMuonPairs[pairIndex][0] self.HISTS['Lxy-before'].Fill(genMuon.Lxy()) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_REP_PT', Dimuons3, DSAmuons, PATmuons) if selectedDimuons is not None: genMuonPair = genMuonPairs[0] selectedDimuons = [ dim for dim in selectedDimuons if dim.composition == 'DSA' ] dimuonMatches, muonMatches, exitcode = AT.matchedDimuons( genMuonPair, selectedDimuons) if len(dimuonMatches) > 0: realMatches = {0: dimuonMatches[0]} else: realMatches = {} for pairIndex in realMatches: genMuon = genMuonPairs[pairIndex][0] self.HISTS['Lxy-after'].Fill(genMuon.Lxy())
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.SelectObjects(E, self.CUTS, Dimuons3, DSAmuons, PATmuons) if selectedDimuons is None: return for dim in selectedDimuons: if dim.composition == 'DSA': continue idxList = (dim.idx2,) if dim.composition == 'HYBRID' else dim.ID for idx in idxList: mu = PATmuons[idx] self.HISTS['pT'].Fill(mu.pt) if mu.highPurity: self.HISTS['pT-HP'].Fill(mu.pt) 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) for pairIndex in realMatches: genMuon = genMuonPairs[pairIndex][0] dim = realMatches[pairIndex]['dim'] if dim.composition == 'DSA': continue idxList = (dim.idx2,) if dim.composition == 'HYBRID' else dim.ID for idx in idxList: mu = PATmuons[idx] self.HISTS['GM-pT'].Fill(mu.pt) if mu.highPurity: self.HISTS['GM-pT-HP'].Fill(mu.pt)
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return 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), ) DSAmuons = E.getPrimitives('DSAMUON') RSAmuons = E.getPrimitives('RSAMUON') selectedMuons = {'DSA': DSAmuons, 'RSA': RSAmuons} for genMuonPair in genMuonPairs: genAcceptances = [ Selections.AcceptanceSelection(genMuonPair[0]), Selections.AcceptanceSelection(genMuonPair[1]) ] for MUON in ('DSA', 'RSA'): dimuonMatches, muonMatches, exitcode = AT.matchedDimuons( genMuonPair, [], selectedMuons[MUON], vertex='BS', doDimuons=False) genMuonMatches = exitcode.getBestGenMuonMatches(muonMatches) for which, genMuon in enumerate(genMuonPair): if genAcceptances[which].allExcept('a_Lxy'): self.HISTS['nGen' + MUON].Fill(genMuon.Lxy()) if genMuonMatches[which] is not None: self.HISTS['nRec' + MUON].Fill(genMuon.Lxy()) RM = genMuonMatches[which]['muon'] GM = genMuon.BS pTRes = (RM.pt - GM.pt) / GM.pt self.HISTS['pTRes-' + MUON].Fill(pTRes)
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None and not Selections.passedTrigger( E): return Event = E.getPrimitives('EVENT') DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON') eventWeight = 1. try: eventWeight = 1. if Event.weight > 0. else -1. except: pass DSASelections = [Selections.MuonSelection(muon) for muon in DSAmuons] # loop over DSAmuons and select for muon, muonSelection in zip(DSAmuons, DSASelections): for CUT in Selections.CutLists['MuonCutList']: for Q in ('pT', 'eta', 'd0'): F = CONFIG[Q]['LAMBDA'] if muonSelection.allExcept(CUT): self.HISTS[CUT + 'DenVS' + Q].Fill(F(muon), eventWeight) if muonSelection: self.HISTS[CUT + 'EffVS' + Q].Fill(F(muon), eventWeight) # loop over dimuons and select for dimuon in Dimuons: muon1Selection = DSASelections[dimuon.idx1] muon2Selection = DSASelections[dimuon.idx2] if muon1Selection and muon2Selection: dimuonSelection = Selections.DimuonSelection(dimuon) for CUT in Selections.CutLists['DimuonCutList']: for Q in ('Lxy', ): F = CONFIG[Q]['LAMBDA'] if dimuonSelection.allExcept(CUT): self.HISTS[CUT + 'DenVS' + Q].Fill( F(dimuon), eventWeight) if dimuonSelection: self.HISTS[CUT + 'EffVS' + Q].Fill( F(dimuon), 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') eventWeight = 1. try: eventWeight = 1. if Event.weight > 0. else -1. except: pass CutStrings = { '': '_Combined_NS_NH_FPTE_HLT_REP_PT_PC_LXYE_MASS', 'G': '_Combined_NS_NH_FPTE_HLT_GLB_REP_PT_PC_LXYE_MASS', 'GN': '_Combined_NS_NH_FPTE_HLT_GLB_NTL_REP_PT_PC_LXYE_MASS', 'M': '_Combined_NS_NH_FPTE_HLT_MED_REP_PT_PC_LXYE_MASS', 'MN': '_Combined_NS_NH_FPTE_HLT_MED_NTL_REP_PT_PC_LXYE_MASS', } CutStringKeys = ('', 'G', 'GN', 'M', 'MN') selectedDimuons, selectedDSAmuons, selectedPATmuons = {}, {}, {} for key in CutStringKeys: selectedDimuons[key], selectedDSAmuons[key], selectedPATmuons[ key] = Selector.SelectObjects(E, CutStrings[key], Dimuons3, DSAmuons, PATmuons) selectedIDs = {key: set() for key in CutStringKeys} for key in CutStringKeys: if selectedDimuons[key] is None: continue for dim in selectedDimuons[key]: selectedIDs[key].add((dim.composition[:3], dim.idx1, dim.idx2)) maxLen = max([len(selectedIDs[key]) for key in selectedIDs]) if not selectedIDs[''] == selectedIDs['G'] == selectedIDs[ 'M'] == selectedIDs['GN'] == selectedIDs['MN']: print '::: {:13s} {:d} {:7d} {:10d} :::'.format( self.NAME, Event.run, Event.lumi, Event.event) for key in CutStringKeys: strings = [] if selectedDimuons[key] is not None: for dim in selectedDimuons[key]: strings.append( '{:3s} {:2d} {:2d} ::: {:9.4f} {:8.4f} {:10.2f} {:6.2f}' .format(dim.composition[:3], dim.idx1, dim.idx2, dim.LxySig(), dim.Lxy(), dim.normChi2, min(dim.mu1.d0Sig(), dim.mu2.d0Sig()))) while len(strings) < maxLen: strings.append('-') for s in strings: print ' {:2s} ::: {:s}'.format(key if key != '' else 'X', s)
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') # take 10% of data: event numbers ending in 7 if 'DoubleMuon' in self.NAME and '_IDPHI' not in self.CUTS: if Event.event % 10 != 7: return DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') 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), ) prePCDimuons, prePCDSAmuons, prePCPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_REP_PT_TRK_NDT_DCA', Dimuons3, DSAmuons, PATmuons) selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, '_Combined_NS_NH_FPTE_HLT_REP_PT_TRK_NDT_DCA_PC', Dimuons3, DSAmuons, PATmuons) if prePCDimuons is not None: if len(genMuonPairs) == 1: genMuonPair = genMuonPairs[0] dimuonMatches, muonMatches, exitcode = AT.matchedDimuons( genMuonPair, [dim for dim in prePCDimuons if dim.composition == 'DSA']) if len(dimuonMatches) > 0: realMatches = {0: dimuonMatches[0]} else: realMatches = {} else: realMatches, dimuonMatches, muon0Matches, muon1Matches = AT.matchedDimuonPairs( genMuonPairs, [dim for dim in prePCDimuons if dim.composition == 'DSA']) selectedIDs = [ dim.ID for dim in selectedDimuons if dim.composition == 'DSA' ] if selectedDimuons is not None else [] for pairIndex in realMatches: self.HISTS['Lxy-Den'].Fill(genMuonPairs[pairIndex][0].Lxy()) if realMatches[pairIndex]['dim'].ID in selectedIDs: self.HISTS['Lxy-Num'].Fill(genMuonPairs[pairIndex][0].Lxy())
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
def analyze(self, E, PARAMS=None): if self.SP is None: raise Exception('[ANALYZER ERROR]: This script runs on signal only.') if self.TRIGGER: if not Selections.passedTrigger(E): return 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), ) DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON') for genMuonPair in genMuonPairs: genMuonPairSelection = Selections.AcceptanceSelection(genMuonPair) if not genMuonPairSelection: continue if genMuonPair[0].Lxy() < 100.: self.COUNTS['Den'] += 1 DSAdimuonMatches, DSAmuonMatches, DSAexitcode = matchedDimuons( genMuonPair, ('DUMMY', ), DSAmuons, vertex='BS') REFdimuonMatches, REFmuonMatches, REFexitcode = matchedDimuons( genMuonPair, Dimuons) if DSAexitcode in (1, 2, 3): self.COUNTS['DSATotal'] += 2 elif DSAexitcode in (4, 5, 6, 7): self.COUNTS['DSATotal'] += 1 if len(REFdimuonMatches) > 0: self.COUNTS['REFTotal'] += 2 if len(REFdimuonMatches) == 0: if DSAexitcode == 8: self.COUNTS['None'] += 1 elif DSAexitcode in (4, 5, 6, 7): self.COUNTS['One'] += 1 elif DSAexitcode in (1, 2, 3): self.COUNTS['Both'] += 1
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 Event = E.getPrimitives('EVENT') DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') CUTSTRING = '_Combined_NS_NH_FPTE_HLT_REP_PT_TRK_NDT_DCA_PC_LXYE_MASS_CHI2_VTX_COSA_NPP_LXYSIG_OS' selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, CUTSTRING, Dimuons3, DSAmuons, PATmuons) if selectedDimuons is None: return for dim in selectedDimuons: if dim.composition != 'DSA': continue if not Selections.modelDependentMassCut(self.SP.mX, dim.mass): continue if dim.deltaPhi < R.TMath.Pi() / 2.: self.COUNTS['before'] += 1 if dim.deltaPhi < R.TMath.Pi() / 4.: self.COUNTS['after'] += 1
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') CUTSTRING = '_Combined_NS_NH_FPTE_HLT_REP_PT_TRK_NDT_DCA_PC_LXYE_MASS_CHI2_VTX_COSA_NPP_LXYSIG_OS_DPHI' DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') # gen stuff 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 selection for key in ('before', 'after'): selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, CUTSTRING, Dimuons3, DSAmuons, PATmuons, applyDeltaR=key) if selectedDimuons is None: continue DSADimuons = [ dim for dim in selectedDimuons if dim.composition == 'DSA' ] if self.SP is not None: if len(genMuonPairs) == 1: genMuonPair = genMuonPairs[0] dimuonMatches, muonMatches, exitcode = matchedDimuons( genMuonPair, DSADimuons) if len(dimuonMatches) > 0: realMatches = {0: dimuonMatches[0]} else: realMatches = {} else: realMatches, dimuonMatches, muon0Matches, muon1Matches = matchedDimuonPairs( genMuonPairs, DSADimuons) for pairIndex in realMatches: genMuon = genMuonPairs[pairIndex][0] self.HISTS['Lxy_{}'.format(key)].Fill(genMuon.Lxy())
def analyze(self, E, PARAMS=None): if self.TRIGGER and self.SP is not None: if not Selections.passedTrigger(E): return Event = E.getPrimitives('EVENT') # no LxySig, no Dphi, and no blinding # LxySig < 5 applied below; iDphi and Dphi applied separately and histogrammed separately CUTSTRING = '_Combined_NS_NH_FPTE_HLT_REP_PT_TRK_NDT_DCA_PC_LXYE_MASS_CHI2_VTX_COSA_NPP_OS' DSAmuons = E.getPrimitives('DSAMUON') PATmuons = E.getPrimitives('PATMUON') Dimuons3 = E.getPrimitives('DIMUON') eventWeight = 1. try: eventWeight = 1. if Event.weight > 0. else -1. except: pass def getOriginalMuons(dim, DSAmuons): if dim.composition == 'PAT': return PATmuons[dim.idx1], PATmuons[dim.idx2] elif dim.composition == 'DSA': return DSAmuons[dim.idx1], DSAmuons[dim.idx2] else: return DSAmuons[dim.idx1], PATmuons[dim.idx2] def modifiedName(name): if 'DoubleMuon' in name: return 'Data' + name[17] if 'QCD' in name: return 'QCD' if 'HTo2X' in name: return '{:4d} {:3d} {:4d}'.format(*self.SP.SP) return name for DPHI in ('_IDPHI', '_DPHI'): selectedDimuons, selectedDSAmuons, selectedPATmuons = Selector.SelectObjects( E, CUTSTRING + DPHI, Dimuons3, DSAmuons, PATmuons) if selectedDimuons is None: continue DSADimuons = [ dim for dim in selectedDimuons if dim.composition == 'DSA' and dim.LxySig() < 6. ] for dim in DSADimuons: self.HISTS['LxySig' + DPHI].Fill(dim.LxySig())
def analyze(self, E, PARAMS=None): if self.SP is None: raise Exception('[ANALYZER ERROR]: This script runs on signal only.') if self.TRIGGER: if not Selections.passedTrigger(E): return 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), ) DSAmuons = E.getPrimitives('DSAMUON') Dimuons = E.getPrimitives('DIMUON') for genMuon in genMuons: #print '{:9.4f} {:7.4f} {:7.4f} : {:9.4f} {:7.4f} {:7.4f}'.format(genMuon.pt, genMuon.eta, genMuon.phi, genMuon.BS.pt, genMuon.BS.eta, genMuon.BS.phi) matchesRG = matchedMuons(genMuon, DSAmuons, vertex=None) matchesBS = matchedMuons(genMuon, DSAmuons, vertex='BS') if len(matchesRG) > 0: recoMuon = DSAmuons[matchesRG[0]['idx']] for QUANTITY in ('pT', 'd0'): PRETTY, AXES, RFUNC, GFUNC, RESFUNC = CONFIG[QUANTITY] self.HISTS[QUANTITY + 'ResRG'].Fill( RESFUNC(RFUNC(recoMuon), GFUNC(genMuon, 'LIN'))) self.HISTS['deltaRRG'].Fill(matchesRG[0]['deltaR']) self.HISTS['deltaphiRG'].Fill(recoMuon.p4.DeltaPhi(genMuon.p4)) self.HISTS['deltaEtaRG'].Fill(recoMuon.eta - genMuon.eta) if len(matchesBS) > 0: recoMuon = DSAmuons[matchesBS[0]['idx']] for QUANTITY in ('pT', 'd0'): PRETTY, AXES, RFUNC, GFUNC, RESFUNC = CONFIG[QUANTITY] self.HISTS[QUANTITY + 'ResBS'].Fill( RESFUNC(RFUNC(recoMuon), GFUNC(genMuon, 'FULL'))) self.HISTS['deltaRBS'].Fill(matchesBS[0]['deltaR']) self.HISTS['deltaphiBS'].Fill(recoMuon.p4.DeltaPhi(genMuon.BS.p4)) self.HISTS['deltaEtaBS'].Fill(recoMuon.eta - genMuon.BS.eta) if len(matchesRG) > 0 and len(matchesBS) > 0: dRRG = matchesRG[0]['deltaR'] dRBS = matchesBS[0]['deltaR'] self.HISTS['deltaDeltaR'].Fill(dRRG - dRBS) elif len(matchesRG) > 0: self.HISTS['deltaDeltaR'].Fill(.4) elif len(matchesBS) > 0: self.HISTS['deltaDeltaR'].Fill(-.4)
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, )