Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:27

0001 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0002 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0003 import PhysicsTools.HeppyCore.framework.config as cfg
0004 
0005         
0006 class PDFWeightsAnalyzer( Analyzer ):
0007     """    """
0008     def __init__(self, cfg_ana, cfg_comp, looperName ):
0009         super(PDFWeightsAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
0010         self.doPDFWeights = hasattr(self.cfg_ana, "PDFWeights") and len(self.cfg_ana.PDFWeights) > 0
0011         self.doPDFVars = hasattr(self.cfg_ana, "doPDFVars") and self.cfg_ana.doPDFVars == True
0012         if self.doPDFWeights:
0013             self.pdfWeightInit = False
0014     #---------------------------------------------
0015     # DECLARATION OF HANDLES OF GEN LEVEL OBJECTS 
0016     #---------------------------------------------
0017         
0018 
0019     def declareHandles(self):
0020         super(PDFWeightsAnalyzer, self).declareHandles()
0021 
0022         if self.doPDFVars or self.doPDFWeights:
0023             self.mchandles['pdfstuff'] = AutoHandle( 'generator', 'GenEventInfoProduct' )
0024 
0025     def beginLoop(self, setup):
0026         super(PDFWeightsAnalyzer,self).beginLoop(setup)
0027 
0028     def initPDFWeights(self):
0029         from ROOT import PdfWeightProducerTool
0030         self.pdfWeightInit = True
0031         self.pdfWeightTool = PdfWeightProducerTool()
0032         for pdf in self.cfg_ana.PDFWeights:
0033             self.pdfWeightTool.addPdfSet(pdf+".LHgrid")
0034         self.pdfWeightTool.beginJob()
0035 
0036     def makePDFWeights(self, event):
0037         if not self.pdfWeightInit: self.initPDFWeights()
0038         self.pdfWeightTool.processEvent(self.genInfo)
0039         event.pdfWeights = {}
0040         for pdf in self.cfg_ana.PDFWeights:
0041             ws = self.pdfWeightTool.getWeights(pdf+".LHgrid")
0042             event.pdfWeights[pdf] = [w for w in ws]
0043 
0044     def process(self, event):
0045         self.readCollections( event.input )
0046 
0047         # if not MC, nothing to do
0048         if not self.cfg_comp.isMC: 
0049             return True
0050 
0051         if self.doPDFVars or self.doPDFWeights:
0052             self.genInfo = self.mchandles['pdfstuff'].product()
0053         if self.doPDFWeights:
0054             self.makePDFWeights(event)
0055         if self.doPDFVars:
0056             event.pdf_x1 = self.genInfo.pdf().x.first
0057             event.pdf_x2 = self.genInfo.pdf().x.second
0058             event.pdf_id1 = self.genInfo.pdf().id.first
0059             event.pdf_id2 = self.genInfo.pdf().id.second
0060             event.pdf_scale = self.genInfo.pdf().scalePDF
0061 
0062         return True
0063 
0064 setattr(PDFWeightsAnalyzer,"defaultConfig",
0065     cfg.Analyzer(PDFWeightsAnalyzer,
0066         PDFWeights = []
0067     )
0068 )