PhysicsTools
HeppyCore
python
framework
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
import
six
7
for
key, value
in
six.iteritems(weights):
8
print
(key)
9
print
(value)
10
11
class
Weight
(
object
):
12
'''make names uniform wrt Component.
13
14
COLIN: messy... should I have several types of weight (base, data, mc)?
15
COLIN: need to add other weighting factors'''
16
17
FBINV = 1000.
18
19
def
__init__
(self, genNEvents, xSection, genEff,
20
intLumi = FBINV, addWeight=1):
21
self.
genNEvents
=
int
(genNEvents)
22
if
xSection
is
not
None
:
23
self.
xSection
=
float
(xSection)
24
else
:
25
self.
xSection
=
None
26
self.
genEff
=
float
(genEff)
27
if
intLumi
is
not
None
:
28
self.
intLumi
=
float
(intLumi)
29
else
:
30
self.
intLumi
= Weight.FBINV
31
self.
addWeight
=
float
(addWeight)
32
33
def
GetWeight
(self):
34
'''Return the weight'''
35
if
self.
xSection
is
None
:
36
# data
37
return
1
38
else
:
39
# MC
40
return
self.
addWeight
* self.
xSection
* self.
intLumi
/ ( self.
genNEvents
* self.
genEff
)
41
42
def
SetIntLumi
(self, lumi):
43
'''Set integrated luminosity.'''
44
self.dict[
'intLumi'
] = lumi
45
46
def
__str__
(self):
47
if
self.
xSection
is
None
:
48
return
' intLumi = %5.2f, addWeight = %3.2f'
\
49
% ( self.
intLumi
,
50
self.
addWeight
)
51
else
:
52
return
' genN = %d, xsec = %5.5f pb, genEff = %2.2f, intLumi = %5.2f, addWeight = %3.2f -> weight = %3.5f'
\
53
% ( self.
genNEvents
,
54
self.
xSection
,
55
self.
genEff
,
56
self.
intLumi
,
57
self.
addWeight
,
58
self.
GetWeight
() )
59
60
weight.Weight.GetWeight
def GetWeight(self)
Definition:
weight.py:33
resolutioncreator_cfi.object
object
Definition:
resolutioncreator_cfi.py:4
weight.Weight.genEff
genEff
Definition:
weight.py:25
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:19
weight.Weight.__str__
def __str__(self)
Definition:
weight.py:46
weight.Weight.intLumi
intLumi
Definition:
weight.py:27
weight.Weight.xSection
xSection
Definition:
weight.py:22
createfilelist.int
int
Definition:
createfilelist.py:10
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition:
JobReport.cc:66
weight.Weight.genNEvents
genNEvents
Definition:
weight.py:20
weight.Weight.SetIntLumi
def SetIntLumi(self, lumi)
Definition:
weight.py:42
weight.Weight
Definition:
weight.py:11
weight.Weight.addWeight
addWeight
Definition:
weight.py:30
Generated for CMSSW Reference Manual by
1.8.16