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 )
dispatcher processEvent(e, inputTag, standby)
void beginJob()
Definition: Breakpoints.cc:14
def __init__(self, cfg_ana, cfg_comp, looperName)