CMS 3D CMS Logo

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

Functions

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

Function Documentation

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

Definition at line 27 of file vid_id_tools.py.

References if().

Referenced by setupVIDElectronSelection(), and setupVIDPhotonSelection().

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

Definition at line 49 of file vid_id_tools.py.

References DeadROC_duringRun.dir.

Referenced by miniAOD_tools.miniAOD_customizeCommon(), nano_cff.nanoAOD_activateVID(), PhotonPuppi_cff.setupPuppiPhoton(), and PhotonPuppi_cff.setupPuppiPhotonMiniAOD().

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

Definition at line 87 of file vid_id_tools.py.

References heepElectronID_tools.addHEEPProducersToSeq(), addVIDSelectionToPATProducer(), spr.find(), and setupVIDSelection().

87 
88 def setupVIDElectronSelection(process,cutflow,patProducer=None,addUserData=True,task=None):
89  if not hasattr(process,'egmGsfElectronIDs'):
90  raise Exception('VIDProducerNotAvailable','egmGsfElectronIDs producer not available in process!')
91  setupVIDSelection(process.egmGsfElectronIDs,cutflow)
92  #add to PAT electron producer if available or specified
93  if hasattr(process,'patElectrons') or patProducer is not None:
94  if patProducer is None:
95  patProducer = process.patElectrons
96  idName = cutflow.idName.value()
97  addVIDSelectionToPATProducer(patProducer,'egmGsfElectronIDs',idName,addUserData)
98 
99  #we know cutflow has a name otherwise an exception would have been thrown in setupVIDSelection
100  #run this for all heep IDs except V60 standard for which it is not needed
101  #it is needed for V61 and V70
102  if (cutflow.idName.value().find("HEEP")!=-1 and
103  cutflow.idName.value()!="heepElectronID-HEEPV60"):
104 
105  #not the ideal way but currently the easiest
106  useMiniAOD = process.egmGsfElectronIDs.physicsObjectSrc == cms.InputTag('slimmedElectrons')
107 
109  addHEEPProducersToSeq(process=process,seq=process.egmGsfElectronIDSequence,
110  useMiniAOD=useMiniAOD,task=task)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:27
def setupVIDElectronSelection
Definition: vid_id_tools.py:87
def setupVIDSelection
Definition: vid_id_tools.py:11
def vid_id_tools.setupVIDMuonSelection (   process,
  cutflow,
  patProducer = None 
)

Definition at line 138 of file vid_id_tools.py.

References setupVIDSelection().

139 def setupVIDMuonSelection(process,cutflow,patProducer=None):
140  moduleName = "muoMuonIDs"
141  if not hasattr(process, moduleName):
142  raise Exception("VIDProducerNotAvailable", "%s producer not available in process!" % moduleName)
143  module = getattr(process, moduleName)
144 
145  setupVIDSelection(module, cutflow)
146  #add to PAT electron producer if available or specified
147  #if hasattr(process,'patMuons') or patProducer is not None:
148  # if patProducer is None:
149  # patProducer = process.patMuons
150  # idName = cutflow.idName.value()
151  # 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,
  task = None 
)

Definition at line 181 of file vid_id_tools.py.

References addVIDSelectionToPATProducer(), and setupVIDSelection().

182 def setupVIDPhotonSelection(process,cutflow,patProducer=None,addUserData=True,task=None):
183  if not hasattr(process,'egmPhotonIDs'):
184  raise Exception('VIDProducerNotAvailable','egmPhotonIDs producer not available in process!\n')
185  setupVIDSelection(process.egmPhotonIDs,cutflow)
186  #add to PAT photon producer if available or specified
187  if hasattr(process,'patPhotons') or patProducer is not None:
188  if patProducer is None:
189  patProducer = process.patPhotons
190  idName = cutflow.idName.value()
191  addVIDSelectionToPATProducer(patProducer,'egmPhotonIDs',idName,addUserData)
192 
193 
def addVIDSelectionToPATProducer
Definition: vid_id_tools.py:27
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 = False
19  if hasattr(cutflow,'isPOGApproved'):
20  isPOGApproved = cutflow.isPOGApproved.value()
21  vidproducer.physicsObjectIDs.append(
22  cms.PSet( idDefinition = cutflow,
23  isPOGApproved = cms.untracked.bool(isPOGApproved),
24  idMD5 = cms.string(cutflow_md5) )
25  )
26 # 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,
  task = None 
)

Electrons.

Definition at line 66 of file vid_id_tools.py.

References if().

Referenced by miniAOD_tools.miniAOD_customizeCommon(), and nano_cff.nanoAOD_activateVID().

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

Muons.

Definition at line 117 of file vid_id_tools.py.

References if().

118 def switchOnVIDMuonIdProducer(process, dataFormat, task=None):
119  process.load('RecoMuon.MuonIdentification.muoMuonIDs_cff')
120  if task is not None:
121  task.add(process.muoMuonIDTask)
122  #*always* reset to an empty configuration
123  if( len(process.muoMuonIDs.physicsObjectIDs) > 0 ):
124  process.muoMuonIDs.physicsObjectIDs = cms.VPSet()
125  dataFormatString = "Undefined"
126  if dataFormat == DataFormat.AOD:
127  # No reconfiguration is required, default settings are for AOD
128  dataFormatString = "AOD"
129  elif dataFormat == DataFormat.MiniAOD:
130  # If we are dealing with MiniAOD, we overwrite the muon collection
131  # name appropriately, for the fragment we just loaded above.
132  process.muoMuonIDs.physicsObjectSrc = cms.InputTag('slimmedMuons')
133  dataFormatString = "MiniAOD"
134  else:
135  raise Exception('InvalidVIDDataFormat', 'The requested data format is different from AOD or MiniAOD')
136  #
137 # sys.stderr.write('Added \'muoMuonIDs\' to process definition (%s format)!\n' % dataFormatString)
def switchOnVIDMuonIdProducer
Muons.
if(conf_.getParameter< bool >("UseStripCablingDB"))
def vid_id_tools.switchOnVIDPhotonIdProducer (   process,
  dataFormat,
  task = None 
)

Photons.

Definition at line 158 of file vid_id_tools.py.

References if(), and egmPhotonIDs_cff.loadEgmIdSequence().

Referenced by miniAOD_tools.miniAOD_customizeCommon(), nano_cff.nanoAOD_activateVID(), PhotonPuppi_cff.setupPuppiPhoton(), and PhotonPuppi_cff.setupPuppiPhotonMiniAOD().

159 def switchOnVIDPhotonIdProducer(process, dataFormat, task=None):
160  from RecoEgamma.PhotonIdentification.egmPhotonIDs_cff import loadEgmIdSequence
161  # Set up the ID task and sequence appropriate for this data format
162  loadEgmIdSequence(process,dataFormat)
163  if task is not None:
164  task.add(process.egmPhotonIDTask)
165  #*always* reset to an empty configuration
166  if( len(process.egmPhotonIDs.physicsObjectIDs) > 0 ):
167  process.egmPhotonIDs.physicsObjectIDs = cms.VPSet()
168  dataFormatString = "Undefined"
169  if dataFormat == DataFormat.AOD:
170  # No reconfiguration is required, default settings are for AOD
171  dataFormatString = "AOD"
172  elif dataFormat == DataFormat.MiniAOD:
173  # If we are dealing with MiniAOD, we overwrite the electron collection
174  # name appropriately, for the fragment we just loaded above.
175  process.egmPhotonIDs.physicsObjectSrc = cms.InputTag('slimmedPhotons')
176  dataFormatString = "MiniAOD"
177  else:
178  raise Exception('InvalidVIDDataFormat', 'The requested data format is different from AOD or MiniAOD')
179  #
180 # sys.stderr.write('Added \'egmPhotonIDs\' to process definition (%s format)!\n' % dataFormatString)
if(conf_.getParameter< bool >("UseStripCablingDB"))
def switchOnVIDPhotonIdProducer
Photons.