File indexing completed on 2024-04-06 12:23:26
0001 from __future__ import print_function
0002 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
0003
0004
0005 class EventSelector( Analyzer ):
0006 """Skips events that are not in the toSelect list.
0007
0008 Example:
0009
0010 eventSelector = cfg.Analyzer(
0011 'EventSelector',
0012 toSelect = [
0013 1239742,
0014 38001,
0015 159832
0016 ]
0017 )
0018
0019 it can also be used with (run,lumi,event) tuples:
0020
0021 eventSelector = cfg.Analyzer(
0022 'EventSelector',
0023 toSelect = [
0024 (1,40,1239742),
0025 (1,38,38001),
0026 ]
0027 )
0028
0029
0030 The process function of this analyzer returns False if the event number
0031 is not in the toSelect list.
0032 In this list, put actual CMS event numbers obtained by doing:
0033 event.input.eventAuxiliary().id().event()
0034
0035 not event processing number
0036 in this python framework.
0037
0038 This analyzer is typically inserted at the beginning of the analyzer
0039 sequence to skip events you don't want.
0040 We use it in conjonction with an
0041 import pdb; pdb.set_trace()
0042 statement in a subsequent analyzer, to debug a given event in the
0043 toSelect list.
0044
0045 This kind of procedure if you want to synchronize your selection
0046 with an other person at the event level.
0047 """
0048
0049 def process(self, event):
0050 run = event.input.eventAuxiliary().id().run()
0051 lumi = event.input.eventAuxiliary().id().luminosityBlock()
0052 eId = event.input.eventAuxiliary().id().event()
0053 if eId in self.cfg_ana.toSelect or (run, lumi, eId) in self.cfg_ana.toSelect:
0054
0055 print('Selecting', run, lumi, eId)
0056 return True
0057 else:
0058 return False