def _loadTriggerPeriod(cls, period, reparse): if not period & TriggerPeriod.future: cls.init() if (period, cls.customGRL) not in cls.dbQueries: if TriggerPeriod.isRunNumber(period) or (isinstance( period, TriggerPeriod) and period.isBasePeriod()): cls.dbQueries[(period, cls.customGRL)] = TriggerInfo( period, cls.customGRL, cls.release) cls.privatedbQueries[(period, cls.customGRL)] = cls.dbQueries[( period, cls.customGRL)] if not period & TriggerPeriod.future or TriggerPeriod.isRunNumber( period): #Don't pickle TM information since it can change, very cheap to retrieve anyway with open(cls.privatePickleFile, 'wb') as f: pickle.dump(cls.privatedbQueries, f) else: basePeriods = [ tp for tp in TriggerPeriod.basePeriods() if tp & period ] for bp in basePeriods: cls._loadTriggerPeriod(bp, reparse) cls.dbQueries[(period, cls.customGRL)] = TriggerInfo.merge( [cls.dbQueries[(bp, cls.customGRL)] for bp in basePeriods]) cls.privatedbQueries[(period, cls.customGRL)] = cls.dbQueries[( period, cls.customGRL)] if reparse: cls.dbQueries[(period, cls.customGRL)].reparse()
def isLowerThan(self, other, period=TriggerPeriod.future): ''' Returns -1 if none of them is lower than the other (e.g. asymmetric dilepton). Returns 0 if other is lower than self. Returns 1 if self is lower than other. ''' is2015 = period & TriggerPeriod.y2015 and not TriggerPeriod.isRunNumber( period) is2015 |= period <= 284484 and TriggerPeriod.isRunNumber(period) if self.triggerType != other.triggerType: return -1 if len(self.legs) != len(other.legs): return -1 comp = -1 debug = False #if re.search("HLT_j55_gsc75_bmv2c1040_split_3j55_gsc75_boffperf_split", self.name): debug = True if debug: print("DEBUG:", self.name, other.name) for selfleg, otherleg in zip(self.legs, other.legs): legcomp = selfleg.isLegLowerThan(otherleg, is2015, debug) if debug: print("DEBUG LEG return:", legcomp) if legcomp == -9: return -1 elif legcomp == -1: continue elif legcomp == 0 and comp == 1: return -1 elif legcomp == 1 and comp == 0: return -1 elif legcomp == 0: comp = 0 elif legcomp == 1: comp = 1 if debug: print("DEBUG FINAL:", comp) return comp
def dumpFullPickle(cls): for period, grl in cls.dbQueries.keys(): if TriggerPeriod.isRunNumber(period) or (isinstance( period, TriggerPeriod) and period.isBasePeriod()): continue del cls.dbQueries[(period, grl)] with open(cls.privatePickleFile, 'wb') as f: pickle.dump(cls.dbQueries, f) print(sorted(cls.dbQueries.keys()))
def skimPeriod(self, period): if TriggerPeriod.isRunNumber(period): if period in self.grl: blocks = self.grl[period] self.grl = {} self.grl[period] = blocks else: self.grl = {} self.grl[period] = [(0, 9999)] else: ranges = [] if period & TriggerPeriod.y2015: ranges.append(self.periodMap2015['All']) if period & TriggerPeriod.y2016periodA: ranges.append(self.periodMap2016['A']) if period & TriggerPeriod.y2016periodBD3: ranges.append(self.periodMap2016['BD3']) if period & TriggerPeriod.y2016periodD4plus: ranges.append(self.periodMap2016['D4plus']) if period & TriggerPeriod.y2017periodB1: ranges.append(self.periodMap2017['B1']) if period & TriggerPeriod.y2017periodB2B4: for i in range(2, 4 + 1): ranges.append(self.periodMap2017['B%d' % i]) if period & TriggerPeriod.y2017periodB5B7: for i in range(5, 7 + 1): ranges.append(self.periodMap2017['B%d' % i]) if period & TriggerPeriod.y2017periodB8: ranges.append(self.periodMap2017['B8']) if period & TriggerPeriod.y2017periodC: for i in range(1, 8 + 1): ranges.append(self.periodMap2017['C%d' % i]) if period & TriggerPeriod.y2017periodD1D5: for i in range(1, 5 + 1): ranges.append(self.periodMap2017['D%d' % i]) if period & TriggerPeriod.y2017periodD6: ranges.append(self.periodMap2017['D6']) if period & TriggerPeriod.y2017periodEF: ranges.append(self.periodMap2017['E']) ranges.append(self.periodMap2017['F']) if period & TriggerPeriod.y2017periodGHIK: ranges.append(self.periodMap2017['G']) ranges.append(self.periodMap2017['H']) ranges.append(self.periodMap2017['I']) ranges.append(self.periodMap2017['K']) if period & TriggerPeriod.y2017periodN: ranges.append(self.periodMap2017['N']) if period & TriggerPeriod.y2018periodBF: ranges.append(self.periodMap2018['B']) ranges.append(self.periodMap2018['C']) ranges.append(self.periodMap2018['D']) ranges.append(self.periodMap2018['E']) ranges.append(self.periodMap2018['F']) for run in self.grl.keys()[:]: if not any([run >= x[0] and run <= x[1] for x in ranges]): self.grl.pop(run)
def getHLTlist(period, customGRL, release): ''' For a given period it returns: [HLT chain, L1 seed, average livefraction, active LB, is-rerun], total LB The average livefraction is an approximation weighting the PS by number of lumiblocks. *** Don't use this number in analysis!!! *** For "future" periods, the average livefraction is 1 for items flagged as primary in TM and 0 for non-primaries ''' if not period & TriggerPeriod.future or TriggerPeriod.isRunNumber(period): hltmap, totalLB = getHLTmap_fromDB(period, customGRL) else: hltmap, totalLB = getHLTmap_fromTM(period, release) hltlist = cleanHLTmap(hltmap, totalLB) return (hltlist, totalLB)
def __init__(self, period, customGRL=None): if customGRL: self.loadGRL(customGRL) elif TriggerPeriod.isRunNumber(period): #run number assume 2018 self.loadGRL(self.y2018grlpath) elif period & TriggerPeriod.y2015: self.loadGRL(self.y2015grlpath) elif period & TriggerPeriod.y2016: self.loadGRL(self.y2016grlpath) elif period & TriggerPeriod.y2017: self.loadGRL(self.y2017grlpath) elif period & TriggerPeriod.y2018: self.loadGRL(self.y2018grlpath) self.skimPeriod(period)
def getHLTlist(period, customGRL): ''' For a given period it returns: [HLT chain, L1 seed, average livefraction, active LB], total LB The average prescale is an approximation weighting the PS by number of lumiblocks. *** Don't use this number in analysis!!! *** For "future" periods, the average prescale is 1 for items flagged as primary in TM and 0 for non-primaries ''' if not period & TriggerPeriod.future or TriggerPeriod.isRunNumber(period): hltlist, totalLB = getHLTlist_fromDB(period, customGRL) else: hltlist, totalLB = getHLTlist_fromTM(period) vetoes = ['calib','noise','noalg','satmon','peb'] hltlist = [(name, l1seed, livefraction, activeLB, hasRerun) for name, l1seed, livefraction, activeLB, hasRerun in hltlist if not any(v in name for v in vetoes)] return (hltlist, totalLB)