CMS 3D CMS Logo

List of all members | Public Member Functions
gen.LHEWeightAnalyzer.LHEWeightAnalyzer Class Reference
Inheritance diagram for gen.LHEWeightAnalyzer.LHEWeightAnalyzer:

Public Member Functions

def __init__ (self, cfg_ana, cfg_comp, looperName)
 
def beginLoop (self, setup)
 
def declareHandles (self)
 
def process (self, event)
 

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

◆ __init__()

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

Definition at line 19 of file LHEWeightAnalyzer.py.

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

Member Function Documentation

◆ beginLoop()

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

Definition at line 30 of file LHEWeightAnalyzer.py.

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

◆ declareHandles()

def gen.LHEWeightAnalyzer.LHEWeightAnalyzer.declareHandles (   self)

Definition at line 22 of file LHEWeightAnalyzer.py.

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

References core.Analyzer.Analyzer.mchandles.

◆ process()

def gen.LHEWeightAnalyzer.LHEWeightAnalyzer.process (   self,
  event 
)

Definition at line 33 of file LHEWeightAnalyzer.py.

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

References analyzer.Analyzer.cfg_comp, looper.Looper.cfg_comp, createfilelist.int, sistrip::SpyUtilities.isValid(), core.Analyzer.Analyzer.mchandles, core.Analyzer.Analyzer.readCollections(), str, and HLT_FULL_cff.weights.

HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99166
str
#define str(s)
Definition: TestProcessor.cc:52
sistrip::SpyUtilities::isValid
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Definition: SiStripSpyUtilities.cc:124
LaserDQM_cfg.process
process
Definition: LaserDQM_cfg.py:3
createfilelist.int
int
Definition: createfilelist.py:10