CMS 3D CMS Logo

PDFWeightsAnalyzer.py
Go to the documentation of this file.
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 
5 
7  """ """
8  def __init__(self, cfg_ana, cfg_comp, looperName ):
9  super(PDFWeightsAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
10  self.doPDFWeights = hasattr(self.cfg_ana, "PDFWeights") and len(self.cfg_ana.PDFWeights) > 0
11  self.doPDFVars = hasattr(self.cfg_ana, "doPDFVars") and self.cfg_ana.doPDFVars == True
12  if self.doPDFWeights:
13  self.pdfWeightInit = False
14  #---------------------------------------------
15  # DECLARATION OF HANDLES OF GEN LEVEL OBJECTS
16  #---------------------------------------------
17 
18 
19  def declareHandles(self):
20  super(PDFWeightsAnalyzer, self).declareHandles()
21 
22  if self.doPDFVars or self.doPDFWeights:
23  self.mchandles['pdfstuff'] = AutoHandle( 'generator', 'GenEventInfoProduct' )
24 
25  def beginLoop(self, setup):
26  super(PDFWeightsAnalyzer,self).beginLoop(setup)
27 
28  def initPDFWeights(self):
29  from ROOT import PdfWeightProducerTool
30  self.pdfWeightInit = True
31  self.pdfWeightTool = PdfWeightProducerTool()
32  for pdf in self.cfg_ana.PDFWeights:
33  self.pdfWeightTool.addPdfSet(pdf+".LHgrid")
34  self.pdfWeightTool.beginJob()
35 
36  def makePDFWeights(self, event):
37  if not self.pdfWeightInit: self.initPDFWeights()
39  event.pdfWeights = {}
40  for pdf in self.cfg_ana.PDFWeights:
41  ws = self.pdfWeightTool.getWeights(pdf+".LHgrid")
42  event.pdfWeights[pdf] = [w for w in ws]
43 
44  def process(self, event):
45  self.readCollections( event.input )
46 
47  # if not MC, nothing to do
48  if not self.cfg_comp.isMC:
49  return True
50 
51  if self.doPDFVars or self.doPDFWeights:
52  self.genInfo = self.mchandles['pdfstuff'].product()
53  if self.doPDFWeights:
54  self.makePDFWeights(event)
55  if self.doPDFVars:
56  event.pdf_x1 = self.genInfo.pdf().x.first
57  event.pdf_x2 = self.genInfo.pdf().x.second
58  event.pdf_id1 = self.genInfo.pdf().id.first
59  event.pdf_id2 = self.genInfo.pdf().id.second
60  event.pdf_scale = self.genInfo.pdf().scalePDF
61 
62  return True
63 
64 setattr(PDFWeightsAnalyzer,"defaultConfig",
65  cfg.Analyzer(PDFWeightsAnalyzer,
66  PDFWeights = []
67  )
68 )
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.__init__
def __init__(self, cfg_ana, cfg_comp, looperName)
Definition: PDFWeightsAnalyzer.py:8
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.initPDFWeights
def initPDFWeights(self)
Definition: PDFWeightsAnalyzer.py:28
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.doPDFVars
doPDFVars
Definition: PDFWeightsAnalyzer.py:11
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.beginLoop
def beginLoop(self, setup)
Definition: PDFWeightsAnalyzer.py:25
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.declareHandles
def declareHandles(self)
Definition: PDFWeightsAnalyzer.py:19
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer
Definition: PDFWeightsAnalyzer.py:6
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.process
def process(self, event)
Definition: PDFWeightsAnalyzer.py:44
processEvent
dispatcher processEvent(e, inputTag, standby)
remoteMonitoring_LED_IterMethod_cfg.Analyzer
Analyzer
Definition: remoteMonitoring_LED_IterMethod_cfg.py:32
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.genInfo
genInfo
Definition: PDFWeightsAnalyzer.py:52
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.doPDFWeights
doPDFWeights
Definition: PDFWeightsAnalyzer.py:10
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.makePDFWeights
def makePDFWeights(self, event)
Definition: PDFWeightsAnalyzer.py:36
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.pdfWeightTool
pdfWeightTool
Definition: PDFWeightsAnalyzer.py:31
gen.PDFWeightsAnalyzer.PDFWeightsAnalyzer.pdfWeightInit
pdfWeightInit
Definition: PDFWeightsAnalyzer.py:13