src
PhysicsTools
HeppyCore
python
statistics
histograms.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
class
Histograms
(
object
):
5
'''Base class to handle writing and formatting of a set of histograms.
6
7
Subclass it, and simply add your histograms to the subclass.
8
No need to put them in a list, they will be kept track of automatically
9
by this base class.
10
Then, fill them. Finally, you can call FormatHistos and Write.'''
11
def
__init__
(self, name):
12
self.
name
= name
13
self.
hists
= []
14
self.
named
= []
15
# attributes inheriting from TH1 and TNamed
16
# are kept track of automagically, even if they are in
17
# child classes
18
# setting StatOverflows True for all histograms
19
for
var
in
vars( self ).
values
():
20
try
:
21
if
var.InheritsFrom(
'TNamed'
):
22
self.
named
.
append
(var)
23
if
var.InheritsFrom(
'TH1'
):
24
var.StatOverflows(
True
)
25
self.
hists
.
append
(var)
26
except
:
27
pass
28
# print 'TH1 list:', self.hists
29
# print 'TNamed list:', self.named
30
31
def
FormatHistos
(self, style ):
32
'''Apply a style to all histograms.'''
33
for
hist
in
self.
hists
:
34
style.FormatHisto( hist )
35
36
def
Write
(self, dir ):
37
'''Writes all histograms to a subdirectory of dir called self.name.'''
38
self.
dir
= dir.mkdir( self.
name
)
39
self.
dir
.
cd
()
40
for
hist
in
self.
hists
:
41
hist.Write()
42
dir.cd()
43
44
histograms.Histograms
Definition:
histograms.py:4
histograms.Histograms.__init__
def __init__(self, name)
Definition:
histograms.py:11
hippyaddtobaddatafiles.cd
def cd(newdir)
Definition:
hippyaddtobaddatafiles.py:40
histograms.Histograms.name
name
Definition:
histograms.py:12
histograms.Histograms.dir
dir
Definition:
histograms.py:38
histograms.Histograms.named
named
Definition:
histograms.py:14
contentValuesCheck.values
values
Definition:
contentValuesCheck.py:38
histograms.Histograms.Write
def Write(self, dir)
Definition:
histograms.py:36
histograms.Histograms.FormatHistos
def FormatHistos(self, style)
Definition:
histograms.py:31
mps_setup.append
append
Definition:
mps_setup.py:85
histograms.Histograms.hists
hists
Definition:
histograms.py:13
resolutioncreator_cfi.object
object
Definition:
resolutioncreator_cfi.py:4
Generated for CMSSW Reference Manual by
1.8.14