File indexing completed on 2024-04-06 12:23:30
0001
0002
0003
0004 class Histograms(object):
0005 '''Base class to handle writing and formatting of a set of histograms.
0006
0007 Subclass it, and simply add your histograms to the subclass.
0008 No need to put them in a list, they will be kept track of automatically
0009 by this base class.
0010 Then, fill them. Finally, you can call FormatHistos and Write.'''
0011 def __init__(self, name):
0012 self.name = name
0013 self.hists = []
0014 self.named = []
0015
0016
0017
0018
0019 for var in vars( self ).values():
0020 try:
0021 if var.InheritsFrom('TNamed'):
0022 self.named.append(var)
0023 if var.InheritsFrom('TH1'):
0024 var.StatOverflows(True)
0025 self.hists.append(var)
0026 except:
0027 pass
0028
0029
0030
0031 def FormatHistos(self, style ):
0032 '''Apply a style to all histograms.'''
0033 for hist in self.hists:
0034 style.FormatHisto( hist )
0035
0036 def Write(self, dir ):
0037 '''Writes all histograms to a subdirectory of dir called self.name.'''
0038 self.dir = dir.mkdir( self.name )
0039 self.dir.cd()
0040 for hist in self.hists:
0041 hist.Write()
0042 dir.cd()
0043
0044