CMS 3D CMS Logo

metTools.py
Go to the documentation of this file.
2 
3 from PhysicsTools.PatAlgos.tools.helpers import getPatAlgosToolsTask, addToProcessAndTask
4 
6  """
7  Tool to add alternative MET collection(s) to your PAT Tuple
8  """
9  _label='addMETCollection'
10  _defaultParameters=dicttypes.SortedKeysDict()
11 
12  def __init__(self):
13  """
14  Initialize elements of the class. Note that the tool needs to be derived from ConfigToolBase
15  to be usable in the configEditor.
16  """
17  ## initialization of the base class
18  ConfigToolBase.__init__(self)
19  ## add all parameters that should be known to the class
20  self.addParameter(self._defaultParameters,'labelName',self._defaultValue, "Label name of the new patMET collection.", str)
21  self.addParameter(self._defaultParameters,'metSource',self._defaultValue, "Label of the input collection from which the new patMet collection should be created.", str)
22  ## set defaults
23  self._parameters=copy.deepcopy(self._defaultParameters)
24  ## add comments
25  self._comment = "Add alternative MET collections as PAT object to your PAT Tuple"
26 
28  """
29  Return default parameters of the class
30  """
31  return self._defaultParameters
32 
33  def __call__(self,process,labelName=None,metSource=None):
34  """
35  Function call wrapper. This will check the parameters and call the actual implementation that
36  can be found in toolCode via the base class function apply.
37  """
38  if labelName is None:
39  labelName=self._defaultParameters['labelName'].value
40  self.setParameter('labelName', labelName)
41  if metSource is None:
42  metSource=self._defaultParameters['metSource'].value
43  self.setParameter('metSource', metSource)
44  self.apply(process)
45 
46  def toolCode(self, process):
47  """
48  Tool code implementation
49  """
50  ## initialize parameters
51  labelName=self._parameters['labelName'].value
52  metSource=self._parameters['metSource'].value
53  ## do necessary imports
55  ## add module to the process
56  task = getPatAlgosToolsTask(process)
57  addToProcessAndTask(labelName, patMETs.clone(metSource = metSource, addMuonCorrections=False), process, task)
58 
59  ## add module to output
60  if hasattr(process, "out"):
61  process.out.outputCommands+=["keep *_{LABEL_NAME}_*_*".format(LABEL_NAME=labelName)]
62 
63 addMETCollection=AddMETCollection()
def addToProcessAndTask(label, module, process, task)
Definition: helpers.py:27
def toolCode(self, process)
Definition: metTools.py:46
def __call__(self, process, labelName=None, metSource=None)
Definition: metTools.py:33
def getDefaultParameters(self)
Definition: metTools.py:27
_comment
add comments
Definition: metTools.py:25
_parameters
initialization of the base class
Definition: metTools.py:23
def getPatAlgosToolsTask(process)
Definition: helpers.py:12