ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
HistControl.HistControl Class Reference
Inheritance diagram for HistControl.HistControl:
Collaboration diagram for HistControl.HistControl:

Public Member Functions

def __init__ (self, name="HistControl", title="Controls the histograms", doOutputFile=False)
 
def BookTProfile (self, name, title, numbinx, xmin, xmax)
 
def BookHist1D (self, name, title, numbinx, xmin, xmax)
 
def BookHist2D (self, name, title, numbinx, xmin, xmax, numbiny, ymin, ymax)
 
def GetRandomString (self, N)
 
def SaveTH1FToImage (self, histname, imagename, drawoptions='HIST', colors=[ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta], linewidth=2)
 
def SaveTH2FToImage (self, histname, imagename, doth2f2graph=False, minY=1., maxY=-1.)
 
def getRMSs (self, hist)
 
def TwoDHist2Graph (self, name, doErros=False)
 
def FillHist1D (self, name, value)
 
def FillHist2D (self, name, valuex, valuey)
 
def FillTProfile (self, name, valuex, valuey)
 
def SaveAllToFile (self)
 

Private Attributes

 __OneDHists
 
 __TwoDHists
 
 __Graphs
 
 __TProfiles
 
 __OutputROOTFile
 
 __doOutputFile
 

Detailed Description

Definition at line 9 of file HistControl.py.

Constructor & Destructor Documentation

◆ __init__()

def HistControl.HistControl.__init__ (   self,
  name = "HistControl",
  title = "Controls the histograms",
  doOutputFile = False 
)

Definition at line 11 of file HistControl.py.

11  def __init__( self, name = "HistControl", title = "Controls the histograms", doOutputFile=False):
12 
13  # Initialise the base class:
14  ROOT.TNamed.__init__( self, name, title )
15  self.SetName( name )
16  self.SetTitle( title )
17 
18  self.__OneDHists = {}
19  self.__TwoDHists = {}
20  self.__Graphs = {}
21  self.__TProfiles = {}
22  self.__OutputROOTFile = None
23 
24  self.__doOutputFile = doOutputFile
25 
26  return
27 

Member Function Documentation

◆ BookHist1D()

def HistControl.HistControl.BookHist1D (   self,
  name,
  title,
  numbinx,
  xmin,
  xmax 
)

Definition at line 36 of file HistControl.py.

36  def BookHist1D(self, name, title, numbinx, xmin, xmax):
37 
38  if name in self.__OneDHists.keys():
39  print 'already stored a th1f object with name', name
40  return False
41  hist1d = ROOT.TH1F(name, title, numbinx, xmin, xmax)
42  self.__OneDHists[ name ] = hist1d
43  return True
44 
45 

◆ BookHist2D()

def HistControl.HistControl.BookHist2D (   self,
  name,
  title,
  numbinx,
  xmin,
  xmax,
  numbiny,
  ymin,
  ymax 
)

Definition at line 46 of file HistControl.py.

46  def BookHist2D(self, name, title, numbinx, xmin, xmax, numbiny, ymin, ymax):
47  if name in self.__TwoDHists.keys():
48  print 'already stored a th2f object with name', name
49  return False
50  hist2d = ROOT.TH2F(name, title, numbinx, xmin, xmax, numbiny, ymin, ymax)
51  self.__TwoDHists[ name ] = hist2d
52  return True
53 
54 

◆ BookTProfile()

def HistControl.HistControl.BookTProfile (   self,
  name,
  title,
  numbinx,
  xmin,
  xmax 
)

Definition at line 28 of file HistControl.py.

28  def BookTProfile(self, name, title, numbinx, xmin, xmax):
29  if name in self.__TProfiles.keys():
30  print 'already stored a tprofile object with name', name
31  return False
32  tprof = ROOT.TProfile(name, title, numbinx, xmin, xmax)
33  self.__TProfiles[ name ] = tprof
34  return True
35 

◆ FillHist1D()

def HistControl.HistControl.FillHist1D (   self,
  name,
  value 
)

Definition at line 214 of file HistControl.py.

214  def FillHist1D(self, name, value):
215  if name in self.__OneDHists:
216  self.__OneDHists[ name ].Fill(value)
217  else:
218  print 'No such th1f with name', name
219  pass
220  return
221 

◆ FillHist2D()

def HistControl.HistControl.FillHist2D (   self,
  name,
  valuex,
  valuey 
)

Definition at line 222 of file HistControl.py.

222  def FillHist2D(self, name, valuex, valuey):
223  if name in self.__TwoDHists:
224  self.__TwoDHists[ name ].Fill(valuex, valuey)
225  else:
226  print 'No such th2f with name', name
227  pass
228  return
229 

◆ FillTProfile()

def HistControl.HistControl.FillTProfile (   self,
  name,
  valuex,
  valuey 
)

Definition at line 230 of file HistControl.py.

230  def FillTProfile(self, name, valuex, valuey):
231  if name in self.__TProfiles:
232  self.__TProfiles[ name ].Fill(valuex, valuey)
233  else:
234  print 'No such tprofile with name', name
235  pass
236  return
237 
238 

◆ GetRandomString()

def HistControl.HistControl.GetRandomString (   self,
  N 
)

Definition at line 57 of file HistControl.py.

57  def GetRandomString(self, N):
58  str = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
59  print 'randomstring', str
60  return str
61 

◆ getRMSs()

def HistControl.HistControl.getRMSs (   self,
  hist 
)

Definition at line 134 of file HistControl.py.

134  def getRMSs(self, hist):
135 
136  mean = hist.GetMean()
137  nentries = hist.GetEntries()
138  rmsDown = 0.
139  rmsUp = 0.
140  nDown = 0
141  nUp = 0
142  print 'mean', mean
143  for bin in range(1, hist.GetNbinsX()+1):
144  if hist.GetBinCenter(bin) < mean:
145  print 'low', hist.GetBinContent(bin)
146  nDown = nDown + hist.GetBinContent(bin)
147  rmsDown += float(hist.GetBinContent(bin))*(mean - float(hist.GetBinCenter(bin)))**2
148  else:
149  nUp = nUp + hist.GetBinContent(bin)
150  rmsUp += float(hist.GetBinContent(bin))*(mean - float(hist.GetBinCenter(bin)))**2
151  pass
152  pass
153  if nDown > 0:
154  rmsDown = ROOT.TMath.Sqrt(rmsDown/float(nentries))
155  else:
156  rmsDown = 0.
157  pass
158  if nUp > 0:
159  rmsUp = ROOT.TMath.Sqrt(rmsUp/float(nentries))
160  else:
161  rmsUp = 0.
162 
163  return (rmsDown,rmsUp)
164 
165 

◆ SaveAllToFile()

def HistControl.HistControl.SaveAllToFile (   self)

Definition at line 239 of file HistControl.py.

239  def SaveAllToFile(self):
240  if not self.__doOutputFile:
241  print 'Cannot save hists to file. No output file set.'
242  return
243 
244  outputFile = ROOT.TFile(self.GetName()+'.root', 'RECREATE')
245  for name1D, hist1D in self.__OneDHists.iteritems():
246  if hist1D.GetEntries() != 0:
247  hist1D.Write()
248  for name2D, hist2D in self.__TwoDHists.iteritems():
249  if hist2D.GetEntries() != 0:
250  hist2D.Write()
251  for nametprof, histtprof in self.__TProfiles.iteritems():
252  histtprof.Write()
253  #for graph in self.__Graphs:
254  # graph.Write()
255  return

◆ SaveTH1FToImage()

def HistControl.HistControl.SaveTH1FToImage (   self,
  histname,
  imagename,
  drawoptions = 'HIST',
  colors = [ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta],
  linewidth = 2 
)

Definition at line 62 of file HistControl.py.

62  def SaveTH1FToImage(self, histname, imagename, drawoptions = 'HIST',
63  colors = [ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta],
64  linewidth = 2):
65  canvas = ROOT.TCanvas('canvas'+self.GetRandomString(6))
66  canvas.cd(0)
67  if isinstance(histname, list):
68  maxy = -999.
69  for (index,hname) in enumerate(histname):
70  if self.__OneDHists[ hname ].GetMaximum() > maxy:
71  maxy = self.__OneDHists[ hname ].GetMaximum()
72  pass
73  pass
74  for (index,hname) in enumerate(histname):
75  self.__OneDHists[ hname ].SetMaximum(maxy*1.2)
76  pass
77  for (index,hname) in enumerate(histname):
78  self.__OneDHists[ hname ].SetLineWidth(linewidth)
79  if index >= len(colors):
80  print 'add more colors'
81  assert false
82  pass
83  self.__OneDHists[ hname ].SetLineColor(colors[index])
84  if index == 0:
85  self.__OneDHists[ hname ].Draw(drawoptions)
86  else:
87  self.__OneDHists[ hname ].Draw(drawoptions+'SAME')
88  pass
89  pass
90  pass
91  else:
92  self.__OneDHists[ hname ].SetLineWidth(linewidth)
93  self.__OneDHists[ hname ].SetLineColor(colors[0])
94  self.__OneDHists[ hname ].Draw(drawoptions)
95  pass
96  canvas.SaveAs('output/'+imagename+'.png')
97  pass
98 

◆ SaveTH2FToImage()

def HistControl.HistControl.SaveTH2FToImage (   self,
  histname,
  imagename,
  doth2f2graph = False,
  minY = 1.,
  maxY = -1. 
)

Definition at line 99 of file HistControl.py.

99  def SaveTH2FToImage(self, histname, imagename, doth2f2graph=False, minY=1., maxY=-1.):
100  canvas = ROOT.TCanvas('canvas'+self.GetRandomString(6))
101  canvas.cd(0)
102  hist_frame = None
103  if (minY<maxY) and doth2f2graph:
104  hist_frame = ROOT.TH1F('hist_frame', self.__TwoDHists[ histname ].GetTitle(),
105  100, self.__TwoDHists[ histname ].GetXaxis().GetXmin(), self.__TwoDHists[ histname ].GetXaxis().GetXmax())
106  hist_frame.SetXTitle( self.__TwoDHists[ histname ].GetXaxis().GetTitle() )
107  hist_frame.SetYTitle( self.__TwoDHists[ histname ].GetYaxis().GetTitle() )
108  hist_frame.SetMinimum(minY)
109  hist_frame.SetMaximum(maxY)
110  if isinstance(histname, list):
111  print 'still need to figure this out'
112  pass
113  else:
114  if doth2f2graph:
115  graph_err = self.TwoDHist2Graph(histname, doErros=True)
116  graph = self.TwoDHist2Graph(histname, doErros=False)
117  if hist_frame is not None:
118  hist_frame.Draw()
119  graph.SetLineWidth(3)
120  graph_err.Draw('3SAME')
121  #graph.SetMarkerSize(0)
122  graph.Draw('CSAME')
123  else:
124  graph.Draw('ALP')
125  pass
126  else:
127  self.__TwoDHists[ histname ].Draw()
128  pass
129  pass
130  canvas.SaveAs('output/'+imagename+'.png')
131  pass
132 
133 

◆ TwoDHist2Graph()

def HistControl.HistControl.TwoDHist2Graph (   self,
  name,
  doErros = False 
)

Definition at line 166 of file HistControl.py.

166  def TwoDHist2Graph(self, name, doErros=False):
167  if not name in self.__TwoDHists.keys():
168  print 'No such TH2F as', name
169  return None
170 
171  hist = self.__TwoDHists[ name ]
172 
173  list_mean = []
174  list_x = []
175  list_xel = []
176  list_yel = []
177  list_xeh = []
178  list_yeh = []
179 
180  for bin in range(1, hist.GetNbinsX()+1 ):
181  hist_projY = hist.ProjectionY('pY'+str(bin), bin, bin)
182  if hist_projY.GetEntries() != 0:
183  mean = hist_projY.GetMean()
184  list_mean.append( mean )
185  list_x.append( hist.GetXaxis().GetBinCenter(bin) )
186  list_xel.append(0.)
187  list_xeh.append(0.)
188  if doErros:
189  (yel,yeh) = self.getRMSs(hist_projY)
190  else:
191  (yel,yeh) = (0., 0.)
192  pass
193  list_yel.append(yel)
194  list_yeh.append(yeh)
195  pass
196  hist_projY.Delete()
197  pass
198 
199  array_mean = array.array('d', list_mean)
200  array_x = array.array('d', list_x)
201  array_xel = array.array('d', list_xel)
202  array_yel = array.array('d', list_yel)
203  array_xeh = array.array('d', list_xeh)
204  array_yeh = array.array('d', list_yeh)
205 
206  if doErros:
207  graph_mean = ROOT.TGraphAsymmErrors(len(list_mean), array_x, array_mean, array_xel,array_xeh,array_yel,array_yeh)
208  graph_mean.SetFillColor(ROOT.kRed)
209  else:
210  graph_mean = ROOT.TGraph(len(list_mean), array_x, array_mean)
211  return graph_mean
212 
213 

Member Data Documentation

◆ __doOutputFile

HistControl.HistControl.__doOutputFile
private

Definition at line 24 of file HistControl.py.

◆ __Graphs

HistControl.HistControl.__Graphs
private

Definition at line 20 of file HistControl.py.

◆ __OneDHists

HistControl.HistControl.__OneDHists
private

Definition at line 18 of file HistControl.py.

◆ __OutputROOTFile

HistControl.HistControl.__OutputROOTFile
private

Definition at line 22 of file HistControl.py.

◆ __TProfiles

HistControl.HistControl.__TProfiles
private

Definition at line 21 of file HistControl.py.

◆ __TwoDHists

HistControl.HistControl.__TwoDHists
private

Definition at line 19 of file HistControl.py.


The documentation for this class was generated from the following file:
python.Bindings.iteritems
iteritems
Definition: Control/AthenaPython/python/Bindings.py:820
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
str
Definition: BTagTrackIpAccessor.cxx:11
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
readCCLHist.float
float
Definition: readCCLHist.py:83