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