CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
vid_id_tools Namespace Reference

Classes

class  DataFormat
 

Functions

def addVIDSelectionToPATProducer
 
def setupAllVIDIdsInModule
 
def setupVIDElectronSelection
 
def setupVIDMuonSelection
 
def setupVIDPhotonSelection
 
def setupVIDSelection
 
def switchOnVIDElectronIdProducer
 
def switchOnVIDMuonIdProducer
 Muons. More...
 
def switchOnVIDPhotonIdProducer
 Photons. More...
 

Function Documentation

def vid_id_tools.addVIDSelectionToPATProducer (   patProducer,
  idProducer,
  idName,
  addUserData = True 
)

Definition at line 28 of file vid_id_tools.py.

References citk.if().

Referenced by setupVIDElectronSelection(), and setupVIDPhotonSelection().

28 
29 def addVIDSelectionToPATProducer(patProducer,idProducer,idName,addUserData=True):
30  patProducerIDs = None
31  userDatas = None
32  for key in patProducer.__dict__.keys():
33  if 'IDSources' in key:
34  patProducerIDs = getattr(patProducer,key)
35  if 'userData' in key:
36  userDatas = getattr(patProducer,key)
37  if patProducerIDs is None:
38  raise Exception('StrangePatModule','%s does not have ID sources!'%patProducer.label())
39  if userDatas is None:
40  raise Exception('StrangePatModule','%s does not have UserData sources!'%patProducer.label())
41  setattr(patProducerIDs,idName,cms.InputTag('%s:%s'%(idProducer,idName)))
42  if( addUserData ):
43  if( len(userDatas.userClasses.src) == 1 and
44  type(userDatas.userClasses.src[0]) is str and
45  userDatas.userClasses.src[0] == '' ):
46  userDatas.userClasses.src = cms.VInputTag(cms.InputTag('%s:%s'%(idProducer,idName)))
47  else:
48  userDatas.userClasses.src.append(cms.InputTag('%s:%s'%(idProducer,idName)))
49  sys.stderr.write('\t--- %s:%s added to %s\n'%(idProducer,idName,patProducer.label()))
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:28
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
def vid_id_tools.setupAllVIDIdsInModule (   process,
  id_module_name,
  setupFunction,
  patProducer = None,
  addUserData = True 
)

Definition at line 50 of file vid_id_tools.py.

References dir.

Referenced by miniAOD_tools.miniAOD_customizeCommon(), and PhotonPuppi_cff.setupPuppiPhoton().

50 
51 def setupAllVIDIdsInModule(process,id_module_name,setupFunction,patProducer=None,addUserData=True):
52 # idmod = importlib.import_module(id_module_name)
53  idmod= __import__(id_module_name, globals(), locals(), ['idName','cutFlow'])
54  for name in dir(idmod):
55  item = getattr(idmod,name)
56  if hasattr(item,'idName') and hasattr(item,'cutFlow'):
57  setupFunction(process,item,patProducer,addUserData)
58 
# Supported data formats defined via "enum"
def setupAllVIDIdsInModule
Definition: vid_id_tools.py:50
dbl *** dir
Definition: mlp_gen.cc:35
def vid_id_tools.setupVIDElectronSelection (   process,
  cutflow,
  patProducer = None,
  addUserData = True 
)

Definition at line 88 of file vid_id_tools.py.

References addVIDSelectionToPATProducer(), and setupVIDSelection().

88 
89 def setupVIDElectronSelection(process,cutflow,patProducer=None,addUserData=True):
90  if not hasattr(process,'egmGsfElectronIDs'):
91  raise Exception('VIDProducerNotAvailable','egmGsfElectronIDs producer not available in process!')
92  setupVIDSelection(process.egmGsfElectronIDs,cutflow)
93  #add to PAT electron producer if available or specified
94  if hasattr(process,'patElectrons') or patProducer is not None:
95  if patProducer is None:
96  patProducer = process.patElectrons
97  idName = cutflow.idName.value()
98  addVIDSelectionToPATProducer(patProducer,'egmGsfElectronIDs',idName,addUserData)
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:28
def setupVIDElectronSelection
Definition: vid_id_tools.py:88
def setupVIDSelection
Definition: vid_id_tools.py:11
def vid_id_tools.setupVIDMuonSelection (   process,
  cutflow,
  patProducer = None 
)

Definition at line 124 of file vid_id_tools.py.

References setupVIDSelection().

125 def setupVIDMuonSelection(process,cutflow,patProducer=None):
126  moduleName = "muoMuonIDs"
127  if not hasattr(process, moduleName):
128  raise Exception("VIDProducerNotAvailable", "%s producer not available in process!" % moduleName)
129  module = getattr(process, moduleName)
130 
131  setupVIDSelection(module, cutflow)
132  #add to PAT electron producer if available or specified
133  #if hasattr(process,'patMuons') or patProducer is not None:
134  # if patProducer is None:
135  # patProducer = process.patMuons
136  # idName = cutflow.idName.value()
137  # addVIDSelectionToPATProducer(patProducer, moduleName, idName)
def setupVIDMuonSelection
def setupVIDSelection
Definition: vid_id_tools.py:11
def vid_id_tools.setupVIDPhotonSelection (   process,
  cutflow,
  patProducer = None,
  addUserData = True 
)

Definition at line 163 of file vid_id_tools.py.

References addVIDSelectionToPATProducer(), and setupVIDSelection().

164 def setupVIDPhotonSelection(process,cutflow,patProducer=None,addUserData=True):
165  if not hasattr(process,'egmPhotonIDs'):
166  raise Exception('VIDProducerNotAvailable','egmPhotonIDs producer not available in process!\n')
167  setupVIDSelection(process.egmPhotonIDs,cutflow)
168  #add to PAT photon producer if available or specified
169  if hasattr(process,'patPhotons') or patProducer is not None:
170  if patProducer is None:
171  patProducer = process.patPhotons
172  idName = cutflow.idName.value()
173  addVIDSelectionToPATProducer(patProducer,'egmPhotonIDs',idName,addUserData)
174 
175 
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:28
def setupVIDPhotonSelection
def setupVIDSelection
Definition: vid_id_tools.py:11
def vid_id_tools.setupVIDSelection (   vidproducer,
  cutflow 
)

Definition at line 11 of file vid_id_tools.py.

Referenced by setupVIDElectronSelection(), setupVIDMuonSelection(), and setupVIDPhotonSelection().

11 
12 def setupVIDSelection(vidproducer,cutflow):
13  if not hasattr(cutflow,'idName'):
14  raise Exception('InvalidVIDCutFlow', 'The cutflow configuation provided is malformed and does not have a specified name!')
15  if not hasattr(cutflow,'cutFlow'):
16  raise Exception('InvalidVIDCutFlow', 'The cutflow configuration provided is malformed and does not have a specific cutflow!')
17  cutflow_md5 = central_id_registry.getMD5FromName(cutflow.idName)
18  isPOGApproved = cms.untracked.bool(False)
19  if hasattr(cutflow,'isPOGApproved'):
20  isPOGApproved = cutflow.isPOGApproved
21  del cutflow.isPOGApproved
22  vidproducer.physicsObjectIDs.append(
23  cms.PSet( idDefinition = cutflow,
24  isPOGApproved = isPOGApproved,
25  idMD5 = cms.string(cutflow_md5) )
26  )
27 # sys.stderr.write('Added ID \'%s\' to %s\n'%(cutflow.idName.value(),vidproducer.label()))
def setupVIDSelection
Definition: vid_id_tools.py:11
def vid_id_tools.switchOnVIDElectronIdProducer (   process,
  dataFormat 
)

Definition at line 69 of file vid_id_tools.py.

References citk.if().

Referenced by miniAOD_tools.miniAOD_customizeCommon().

69 
70 def switchOnVIDElectronIdProducer(process, dataFormat):
71  process.load('RecoEgamma.ElectronIdentification.egmGsfElectronIDs_cff')
72  #*always* reset to an empty configuration
73  if( len(process.egmGsfElectronIDs.physicsObjectIDs) > 0 ):
74  process.egmGsfElectronIDs.physicsObjectIDs = cms.VPSet()
75  dataFormatString = "Undefined"
76  if dataFormat == DataFormat.AOD:
77  # No reconfiguration is required, default settings are for AOD
78  dataFormatString = "AOD"
79  elif dataFormat == DataFormat.MiniAOD:
80  # If we are dealing with MiniAOD, we overwrite the electron collection
81  # name appropriately, for the fragment we just loaded above.
82  process.egmGsfElectronIDs.physicsObjectSrc = cms.InputTag('slimmedElectrons')
83  dataFormatString = "MiniAOD"
84  else:
85  raise Exception('InvalidVIDDataFormat', 'The requested data format is different from AOD or MiniAOD')
86  #
87 # sys.stderr.write('Added \'egmGsfElectronIDs\' to process definition (%s format)!\n' % dataFormatString)
def switchOnVIDElectronIdProducer
Definition: vid_id_tools.py:69
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
def vid_id_tools.switchOnVIDMuonIdProducer (   process,
  dataFormat 
)

Muons.

Definition at line 105 of file vid_id_tools.py.

References citk.if().

106 def switchOnVIDMuonIdProducer(process, dataFormat):
107  process.load('RecoMuon.MuonIdentification.muoMuonIDs_cff')
108  #*always* reset to an empty configuration
109  if( len(process.muoMuonIDs.physicsObjectIDs) > 0 ):
110  process.muoMuonIDs.physicsObjectIDs = cms.VPSet()
111  dataFormatString = "Undefined"
112  if dataFormat == DataFormat.AOD:
113  # No reconfiguration is required, default settings are for AOD
114  dataFormatString = "AOD"
115  elif dataFormat == DataFormat.MiniAOD:
116  # If we are dealing with MiniAOD, we overwrite the muon collection
117  # name appropriately, for the fragment we just loaded above.
118  process.muoMuonIDs.physicsObjectSrc = cms.InputTag('slimmedMuons')
119  dataFormatString = "MiniAOD"
120  else:
121  raise Exception('InvalidVIDDataFormat', 'The requested data format is different from AOD or MiniAOD')
122  #
123 # sys.stderr.write('Added \'muoMuonIDs\' to process definition (%s format)!\n' % dataFormatString)
def switchOnVIDMuonIdProducer
Muons.
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
def vid_id_tools.switchOnVIDPhotonIdProducer (   process,
  dataFormat 
)

Photons.

Definition at line 144 of file vid_id_tools.py.

References citk.if().

Referenced by miniAOD_tools.miniAOD_customizeCommon(), and PhotonPuppi_cff.setupPuppiPhoton().

145 def switchOnVIDPhotonIdProducer(process, dataFormat):
146  process.load('RecoEgamma.PhotonIdentification.egmPhotonIDs_cff')
147  #*always* reset to an empty configuration
148  if( len(process.egmPhotonIDs.physicsObjectIDs) > 0 ):
149  process.egmPhotonIDs.physicsObjectIDs = cms.VPSet()
150  dataFormatString = "Undefined"
151  if dataFormat == DataFormat.AOD:
152  # No reconfiguration is required, default settings are for AOD
153  dataFormatString = "AOD"
154  elif dataFormat == DataFormat.MiniAOD:
155  # If we are dealing with MiniAOD, we overwrite the electron collection
156  # name appropriately, for the fragment we just loaded above.
157  process.egmPhotonIDs.physicsObjectSrc = cms.InputTag('slimmedPhotons')
158  dataFormatString = "MiniAOD"
159  else:
160  raise Exception('InvalidVIDDataFormat', 'The requested data format is different from AOD or MiniAOD')
161  #
162  sys.stderr.write('Added \'egmPhotonIDs\' to process definition (%s format)!\n' % dataFormatString)
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
def switchOnVIDPhotonIdProducer
Photons.