1 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
2 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
3 import PhysicsTools.HeppyCore.framework.config
as cfg
4 from DataFormats.FWLite
import Handle
5 from ROOT.gen
import WeightsInfo
8 """Read the WeightsInfo objects of the LHE branch and store them 9 in event.LHE_weights list. 11 If the WeightsInfo.id is a string, replace it with an integer. 13 So far the only allowed string format is "mg_reweight_X", 14 which gets stored as str(10000+int(X)) 16 If w.id is an unknown string or anything but a string or int, 17 a RuntimeError is raised. 19 def __init__(self, cfg_ana, cfg_comp, looperName ):
20 super(LHEWeightAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
24 self.mchandles[
'LHEweights'] = AutoHandle(
'externalLHEProducer',
27 fallbackLabel=
'source',
31 super(LHEWeightAnalyzer,self).
beginLoop(setup)
34 self.readCollections( event.input )
37 if not self.cfg_comp.isMC:
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()
46 for w
in self.mchandles[
'LHEweights'].product().
weights():
50 event.LHE_weights.append(w)
52 if not isinstance(w.id, str):
53 raise RuntimeError(
'Non int or string type for LHE weight id')
55 newweight = WeightsInfo()
57 if w.id.startswith(
'mg_reweight'):
58 newid =
str(10000 +
int(w.id.rsplit(
'_',1)[1]))
61 else:
raise RuntimeError(
'Unknown string id in LHE weights')
62 event.LHE_weights.append(newweight)
66 setattr(LHEWeightAnalyzer,
"defaultConfig",
67 cfg.Analyzer(LHEWeightAnalyzer,
def beginLoop(self, setup)
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
def __init__(self, cfg_ana, cfg_comp, looperName)