CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions
gen.LHEWeightAnalyzer.LHEWeightAnalyzer Class Reference
Inheritance diagram for gen.LHEWeightAnalyzer.LHEWeightAnalyzer:

Public Member Functions

def __init__
 
def beginLoop
 
def declareHandles
 
def process
 

Detailed Description

Read the WeightsInfo objects of the LHE branch and store them
   in event.LHE_weights list.

   If the WeightsInfo.id is a string, replace it with an integer.

   So far the only allowed string format is "mg_reweight_X",
   which gets stored as str(10000+int(X))

   If w.id is an unknown string or anything but a string or int,
   a RuntimeError is raised.

Definition at line 7 of file LHEWeightAnalyzer.py.

Constructor & Destructor Documentation

def gen.LHEWeightAnalyzer.LHEWeightAnalyzer.__init__ (   self,
  cfg_ana,
  cfg_comp,
  looperName 
)

Definition at line 19 of file LHEWeightAnalyzer.py.

19 
20  def __init__(self, cfg_ana, cfg_comp, looperName ):
21  super(LHEWeightAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)

Member Function Documentation

def gen.LHEWeightAnalyzer.LHEWeightAnalyzer.beginLoop (   self,
  setup 
)

Definition at line 30 of file LHEWeightAnalyzer.py.

30 
31  def beginLoop(self, setup):
32  super(LHEWeightAnalyzer,self).beginLoop(setup)
def gen.LHEWeightAnalyzer.LHEWeightAnalyzer.declareHandles (   self)

Definition at line 22 of file LHEWeightAnalyzer.py.

References core.Analyzer.Analyzer.mchandles.

22 
23  def declareHandles(self):
24  super(LHEWeightAnalyzer, self).declareHandles()
25  self.mchandles['LHEweights'] = AutoHandle('externalLHEProducer',
26  'LHEEventProduct',
27  mayFail=True,
28  fallbackLabel='source',
29  lazy=False )
def gen.LHEWeightAnalyzer.LHEWeightAnalyzer.process (   self,
  event 
)

Definition at line 33 of file LHEWeightAnalyzer.py.

References core.Analyzer.Analyzer.mchandles, core.Analyzer.Analyzer.readCollections(), and create_public_pileup_plots.weights.

Referenced by ConfigBuilder.ConfigBuilder.addExtraStream(), ConfigBuilder.ConfigBuilder.completeInputCommand(), ConfigBuilder.ConfigBuilder.doNotInlineEventContent(), ConfigBuilder.ConfigBuilder.PrintAllModules.leave(), ConfigBuilder.ConfigBuilder.prepare_HLT(), ConfigBuilder.ConfigBuilder.prepare_LHE(), ConfigBuilder.ConfigBuilder.prepare_PATFILTER(), ConfigBuilder.ConfigBuilder.prepare_VALIDATION(), ConfigBuilder.ConfigBuilder.renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), and ConfigBuilder.ConfigBuilder.scheduleSequence().

33 
34  def process(self, event):
35  self.readCollections( event.input )
36 
37  # if not MC, nothing to do
38  if not self.cfg_comp.isMC:
39  return True
40 
41  # Add LHE weight info
42  event.LHE_weights = []
43  event.LHE_originalWeight = 1.0
44  if self.mchandles['LHEweights'].isValid():
45  event.LHE_originalWeight = self.mchandles['LHEweights'].product().originalXWGTUP()
46 
47  for w in self.mchandles['LHEweights'].product().weights():
48  # Check if id is string or int and convert to int if it's a string
49  try:
50  int(w.id)
51  event.LHE_weights.append(w)
52  except ValueError:
53  if not type(w.id) == str:
54  raise RuntimeError('Non int or string type for LHE weight id')
55 
56  newweight = WeightsInfo()
57  newweight.wgt = w.wgt
58  if w.id.startswith('mg_reweight'):
59  newid = str(10000 + int(w.id.rsplit('_',1)[1]))
60  newweight.id = newid
61 
62  else: raise RuntimeError('Unknown string id in LHE weights')
63  event.LHE_weights.append(newweight)
64 
65  return True
66 
setattr(LHEWeightAnalyzer,"defaultConfig",