CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/PhysicsTools/PatAlgos/python/tools/metTools.py

Go to the documentation of this file.
00001 from FWCore.GuiBrowsers.ConfigToolBase import *
00002 
00003 
00004 class AddTcMET(ConfigToolBase):
00005 
00006     """ Add track corrected MET collection to patEventContent
00007     """
00008     _label='addTcMET'    
00009     _defaultParameters=dicttypes.SortedKeysDict()
00010     
00011     def __init__(self):
00012         ConfigToolBase.__init__(self)
00013         self.addParameter(self._defaultParameters,'postfixLabel','TC', '')
00014         self._parameters=copy.deepcopy(self._defaultParameters)
00015         self._comment = ''
00016 
00017     def getDefaultParameters(self):
00018         return self._defaultParameters
00019 
00020     def __call__(self,process,postfixLabel=None) :
00021         if  postfixLabel is None:
00022             postfixLabel=self._defaultParameters['postfixLabel'].value 
00023         self.setParameter('postfixLabel',postfixLabel)
00024         self.apply(process) 
00025         
00026     def toolCode(self, process):                
00027         postfixLabel=self._parameters['postfixLabel'].value
00028 
00029 
00030         ## add module as process to the default sequence
00031         def addAlso (label,value):
00032             existing = getattr(process, label)
00033             setattr( process, label+postfixLabel, value)
00034             process.patDefaultSequence.replace( existing, existing*value )        
00035 
00036         ## clone and add a module as process to the
00037         ## default sequence
00038         def addClone(label,**replaceStatements):
00039             new = getattr(process, label).clone(**replaceStatements)
00040             addAlso(label, new)
00041 
00042         ## addClone('corMetType1Icone5Muons', uncorMETInputTag = cms.InputTag("tcMet"))
00043         addClone('patMETs', metSource = cms.InputTag("tcMet"))
00044 
00045         ## add new met collections output to the pat summary
00046         process.patCandidateSummary.candidates += [ cms.InputTag('patMETs'+postfixLabel) ]
00047        
00048 
00049 addTcMET=AddTcMET()
00050 
00051 class AddPfMET(ConfigToolBase):
00052     
00053     """ Add pflow MET collection to patEventContent
00054     """
00055     _label='addPfMET'    
00056     _defaultParameters=dicttypes.SortedKeysDict()
00057     
00058     def __init__(self):
00059         ConfigToolBase.__init__(self)
00060         self.addParameter(self._defaultParameters,'postfixLabel','PF', '')
00061         self._parameters=copy.deepcopy(self._defaultParameters)
00062         self._comment = ''
00063         
00064     def getDefaultParameters(self):
00065         return self._defaultParameters
00066         
00067     def __call__(self,process,postfixLabel=None):
00068         if  postfixLabel is None:
00069             postfixLabel=self._defaultParameters['postfixLabel'].value 
00070         self.setParameter('postfixLabel',postfixLabel)
00071         self.apply(process) 
00072 
00073     def toolCode(self, process): 
00074         postfixLabel=self._parameters['postfixLabel'].value
00075 
00076 
00077         ## add module as process to the default sequence
00078         def addAlso (label,value):
00079             existing = getattr(process, label)
00080             setattr( process, label+postfixLabel, value)
00081             process.patDefaultSequence.replace( existing, existing*value )        
00082             
00083         ## clone and add a module as process to the
00084         ## default sequence
00085         def addClone(label,**replaceStatements):
00086             new = getattr(process, label).clone(**replaceStatements)
00087             addAlso(label, new)
00088 
00089         ## addClone('corMetType1Icone5Muons', uncorMETInputTag = cms.InputTag("tcMet"))
00090         addClone('patMETs', metSource = cms.InputTag("pfType1CorrectedMet"), addMuonCorrections = False)
00091 
00092         ## add new met collections output to the pat summary
00093         process.patCandidateSummary.candidates += [ cms.InputTag('patMETs'+postfixLabel) ]
00094 
00095        
00096 addPfMET=AddPfMET()