test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
weight.py
Go to the documentation of this file.
1 # Copyright (C) 2014 Colin Bernet
2 # https://github.com/cbernet/heppy/blob/master/LICENSE
3 
4 def printWeights( weights ):
5  for key, value in weights.iteritems():
6  print key
7  print value
8 
9 class Weight( object ):
10  '''make names uniform wrt Component.
11 
12  COLIN: messy... should I have several types of weight (base, data, mc)?
13  COLIN: need to add other weighting factors'''
14 
15  FBINV = 1000.
16 
17  def __init__(self, genNEvents, xSection, genEff,
18  intLumi = FBINV, addWeight=1):
19  self.genNEvents = int(genNEvents)
20  if xSection is not None:
21  self.xSection = float(xSection)
22  else:
23  self.xSection = None
24  self.genEff = float(genEff)
25  if intLumi is not None:
26  self.intLumi = float(intLumi)
27  else:
28  self.intLumi = Weight.FBINV
29  self.addWeight = float(addWeight)
30 
31  def GetWeight(self):
32  '''Return the weight'''
33  if self.xSection is None:
34  # data
35  return 1
36  else:
37  # MC
38  return self.addWeight * self.xSection * self.intLumi / ( self.genNEvents * self.genEff)
39 
40  def SetIntLumi(self, lumi):
41  '''Set integrated luminosity.'''
42  self.dict['intLumi'] = lumi
43 
44  def __str__(self):
45  if self.xSection is None:
46  return ' intLumi = %5.2f, addWeight = %3.2f' \
47  % ( self.intLumi,
48  self.addWeight )
49  else:
50  return ' genN = %d, xsec = %5.5f pb, genEff = %2.2f, intLumi = %5.2f, addWeight = %3.2f -> weight = %3.5f' \
51  % ( self.genNEvents,
52  self.xSection,
53  self.genEff,
54  self.intLumi,
55  self.addWeight,
56  self.GetWeight() )
57 
def __str__
Definition: weight.py:44
def printWeights
Definition: weight.py:4
def SetIntLumi
Definition: weight.py:40
def __init__
Definition: weight.py:18
def GetWeight
Definition: weight.py:31