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 if().

Referenced by setupVIDElectronSelection(), setupVIDMuonSelection(), 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(conf.exists("allCellsPositionCalc"))
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().

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,
  addUserData = True 
)

Definition at line 112 of file vid_id_tools.py.

References addVIDSelectionToPATProducer(), and setupVIDSelection().

113 def setupVIDMuonSelection(process,cutflow,patProducer=None,addUserData=True):
114  if not hasattr(process,'muoMuonIDs'):
115  raise Exception('VIDProducerNotAvailable','muoMuonIDs producer not available in process!')
116  setupVIDSelection(process.muoMuonIDs,cutflow)
117  #add to PAT electron producer if available or specified
118  if hasattr(process,'patMuons') or patProducer is not None:
119  if patProducer is None:
120  patProducer = process.patMuons
121  idName = cutflow.idName.value()
122  addVIDSelectionToPATProducer(patProducer,'muoMuonIDs',idName,addUserData)
def setupVIDMuonSelection
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:28
def setupVIDSelection
Definition: vid_id_tools.py:11
def vid_id_tools.setupVIDPhotonSelection (   process,
  cutflow,
  patProducer = None,
  addUserData = True 
)

Definition at line 148 of file vid_id_tools.py.

References addVIDSelectionToPATProducer(), and setupVIDSelection().

149 def setupVIDPhotonSelection(process,cutflow,patProducer=None,addUserData=True):
150  if not hasattr(process,'egmPhotonIDs'):
151  raise Exception('VIDProducerNotAvailable','egmPhotonIDs producer not available in process!\n')
152  setupVIDSelection(process.egmPhotonIDs,cutflow)
153  #add to PAT photon producer if available or specified
154  if hasattr(process,'patPhotons') or patProducer is not None:
155  if patProducer is None:
156  patProducer = process.patPhotons
157  idName = cutflow.idName.value()
158  addVIDSelectionToPATProducer(patProducer,'egmPhotonIDs',idName,addUserData)
159 
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 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(conf.exists("allCellsPositionCalc"))
def vid_id_tools.switchOnVIDMuonIdProducer (   process)

Muons.

Definition at line 105 of file vid_id_tools.py.

References if().

106 def switchOnVIDMuonIdProducer(process):
107  process.load('RecoMuon.MuonIdentification.muoMuonIDs_cff')
108  #*always* reset to an empty configuration
109  if( len(process.muonMuonIDs.physicsObjectIDs) > 0 ):
110  process.muoMuonIDs.physicsObjectIDs = cms.VPSet()
111  sys.stderr.write('Added \'muoMuonIDs\' to process definition!\n')
def switchOnVIDMuonIdProducer
Muons.
if(conf.exists("allCellsPositionCalc"))
def vid_id_tools.switchOnVIDPhotonIdProducer (   process,
  dataFormat 
)

Photons.

Definition at line 129 of file vid_id_tools.py.

References if().

130 def switchOnVIDPhotonIdProducer(process, dataFormat):
131  process.load('RecoEgamma.PhotonIdentification.egmPhotonIDs_cff')
132  #*always* reset to an empty configuration
133  if( len(process.egmPhotonIDs.physicsObjectIDs) > 0 ):
134  process.egmPhotonIDs.physicsObjectIDs = cms.VPSet()
135  dataFormatString = "Undefined"
136  if dataFormat == DataFormat.AOD:
137  # No reconfiguration is required, default settings are for AOD
138  dataFormatString = "AOD"
139  elif dataFormat == DataFormat.MiniAOD:
140  # If we are dealing with MiniAOD, we overwrite the electron collection
141  # name appropriately, for the fragment we just loaded above.
142  process.egmPhotonIDs.physicsObjectSrc = cms.InputTag('slimmedPhotons')
143  dataFormatString = "MiniAOD"
144  else:
145  raise Exception('InvalidVIDDataFormat', 'The requested data format is different from AOD or MiniAOD')
146  #
147  sys.stderr.write('Added \'egmPhotonIDs\' to process definition (%s format)!\n' % dataFormatString)
def switchOnVIDPhotonIdProducer
Photons.
if(conf.exists("allCellsPositionCalc"))