CMS 3D CMS Logo

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