Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:02

0001 from PhysicsTools.PatAlgos.tools.ConfigToolBase import *
0002 
0003 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
0004 
0005 class AddMETCollection(ConfigToolBase):
0006     """
0007     Tool to add alternative MET collection(s) to your PAT Tuple
0008     """
0009     _label='addMETCollection'
0010     _defaultParameters=dicttypes.SortedKeysDict()
0011 
0012     def __init__(self):
0013         """
0014         Initialize elements of the class. Note that the tool needs to be derived from ConfigToolBase
0015         to be usable in the configEditor.
0016         """
0017         ## initialization of the base class
0018         ConfigToolBase.__init__(self)
0019         ## add all parameters that should be known to the class
0020         self.addParameter(self._defaultParameters,'labelName',self._defaultValue, "Label name of the new patMET collection.", str)
0021         self.addParameter(self._defaultParameters,'metSource',self._defaultValue, "Label of the input collection from which the new patMet collection should be created.", str)
0022         ## set defaults
0023         self._parameters=copy.deepcopy(self._defaultParameters)
0024         ## add comments
0025         self._comment = "Add alternative MET collections as PAT object to your PAT Tuple"
0026 
0027     def getDefaultParameters(self):
0028         """
0029         Return default parameters of the class
0030         """
0031         return self._defaultParameters
0032 
0033     def __call__(self,process,labelName=None,metSource=None):
0034         """
0035         Function call wrapper. This will check the parameters and call the actual implementation that
0036         can be found in toolCode via the base class function apply.
0037         """
0038         if labelName is None:
0039             labelName=self._defaultParameters['labelName'].value
0040         self.setParameter('labelName', labelName)
0041         if metSource is None:
0042             metSource=self._defaultParameters['metSource'].value
0043         self.setParameter('metSource', metSource)
0044         self.apply(process)
0045 
0046     def toolCode(self, process):
0047         """
0048         Tool code implementation
0049         """
0050         ## initialize parameters
0051         labelName=self._parameters['labelName'].value
0052         metSource=self._parameters['metSource'].value
0053         ## do necessary imports
0054         from PhysicsTools.PatAlgos.producersLayer1.metProducer_cfi import patMETs
0055         ## add module to the process
0056         task = getPatAlgosToolsTask(process)
0057         addToProcessAndTask(labelName, patMETs.clone(metSource = metSource, addMuonCorrections=False), process, task)
0058 
0059         ## add module to output
0060         if hasattr(process, "out"):
0061             process.out.outputCommands+=["keep *_{LABEL_NAME}_*_*".format(LABEL_NAME=labelName)]
0062 
0063 addMETCollection=AddMETCollection()