Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:52

0001 from __future__ import print_function
0002 # Copyright (C) 2014 Colin Bernet
0003 # https://github.com/cbernet/heppy/blob/master/LICENSE
0004 
0005 def printWeights( weights ):
0006     for key, value in weights.items():
0007         print(key)
0008         print(value) 
0009 
0010 class Weight( object ):
0011     '''make names uniform wrt Component.
0012 
0013     COLIN: messy... should I have several types of weight (base, data, mc)?
0014     COLIN: need to add other weighting factors'''
0015 
0016     FBINV = 1000.
0017      
0018     def __init__(self, genNEvents, xSection, genEff,
0019                  intLumi = FBINV, addWeight=1):
0020         self.genNEvents = int(genNEvents)
0021         if xSection is not None:
0022             self.xSection = float(xSection)
0023         else:
0024             self.xSection = None
0025         self.genEff = float(genEff)
0026         if intLumi is not None:
0027             self.intLumi = float(intLumi)
0028         else:
0029             self.intLumi = Weight.FBINV
0030         self.addWeight = float(addWeight)
0031         
0032     def GetWeight(self):
0033         '''Return the weight'''
0034         if self.xSection is None:
0035             # data
0036             return 1 
0037         else:
0038             # MC
0039             return self.addWeight * self.xSection * self.intLumi / ( self.genNEvents * self.genEff) 
0040 
0041     def SetIntLumi(self, lumi):
0042         '''Set integrated luminosity.'''
0043         self.dict['intLumi'] = lumi
0044 
0045     def __str__(self):
0046         if self.xSection is None:          
0047             return ' intLumi = %5.2f, addWeight = %3.2f' \
0048                % ( self.intLumi,
0049                    self.addWeight )
0050         else:
0051             return ' genN = %d, xsec = %5.5f pb, genEff = %2.2f, intLumi = %5.2f, addWeight = %3.2f -> weight = %3.5f' \
0052                    % ( self.genNEvents,
0053                        self.xSection,
0054                        self.genEff,
0055                        self.intLumi,
0056                        self.addWeight,
0057                        self.GetWeight() )
0058         
0059