CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
vid_id_tools.py
Go to the documentation of this file.
2 
3 from PhysicsTools.SelectorUtils.centralIDRegistry import central_id_registry
4 
5 #keep python2.6 compatibility for computing
6 #import importlib
7 
8 #general simple tools for various object types
9 def setupVIDSelection(vidproducer,cutflow):
10  if not hasattr(cutflow,'idName'):
11  raise Exception('InvalidVIDCutFlow', 'The cutflow configuation provided is malformed and does not have a specified name!')
12  if not hasattr(cutflow,'cutFlow'):
13  raise Exception('InvalidVIDCutFlow', 'The cutflow configuration provided is malformed and does not have a specific cutflow!')
14  cutflow_md5 = central_id_registry.getMD5FromName(cutflow.idName)
15  vidproducer.physicsObjectIDs.append(
16  cms.PSet( idDefinition = cutflow,
17  idMD5 = cms.string(cutflow_md5) )
18  )
19  print 'Added ID \'%s\' to %s'%(cutflow.idName.value(),vidproducer.label())
20 
21 def addVIDSelectionToPATProducer(patProducer,idProducer,idName):
22  patProducerIDs = None
23  for key in patProducer.__dict__.keys():
24  if 'IDSources' in key:
25  patProducerIDs = getattr(patProducer,key)
26  if patProducerIDs is None:
27  raise Exception('StrangePatModule','%s does not have ID sources!'%patProducer.label())
28  setattr(patProducerIDs,idName,cms.InputTag('%s:%s'%(idProducer,idName)))
29  print '\t--- %s:%s added to %s'%(idProducer,idName,patProducer.label())
30 
31 def setupAllVIDIdsInModule(process,id_module_name,setupFunction,patProducer=None):
32 # idmod = importlib.import_module(id_module_name)
33  idmod= __import__(id_module_name, globals(), locals(), ['idName','cutFlow'])
34  for name in dir(idmod):
35  item = getattr(idmod,name)
36  if hasattr(item,'idName') and hasattr(item,'cutFlow'):
37  setupFunction(process,item,patProducer)
38 
39 ####
40 # Electrons
41 ####
42 
43 #turns on the VID electron ID producer, possibly with extra options
44 # for PAT and/or MINIAOD
46  process.load('RecoEgamma.ElectronIdentification.egmGsfElectronIDs_cff')
47  print 'Added \'egmGsfElectronIDs\' to process definition!'
48 
49 def setupVIDElectronSelection(process,cutflow,patProducer=None):
50  if not hasattr(process,'egmGsfElectronIDs'):
51  raise Exception('VIDProducerNotAvailable','egmGsfElectronIDs producer not available in process!')
52  setupVIDSelection(process.egmGsfElectronIDs,cutflow)
53  #add to PAT electron producer if available or specified
54  if hasattr(process,'patElectrons') or patProducer is not None:
55  if patProducer is None:
56  patProducer = process.patElectrons
57  idName = cutflow.idName.value()
58  addVIDSelectionToPATProducer(patProducer,'egmGsfElectronIDs',idName)
59 
def setupAllVIDIdsInModule
Definition: vid_id_tools.py:31
def switchOnVIDElectronIdProducer
Electrons.
Definition: vid_id_tools.py:45
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:21
dbl *** dir
Definition: mlp_gen.cc:35
def setupVIDElectronSelection
Definition: vid_id_tools.py:49
def setupVIDSelection
Definition: vid_id_tools.py:9