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

Public Member Functions

def __init__ (self, name="", axis_title="", bins=-1, bmin=0., bmax=-1.e9, bin_width=-1, bdir=None, log_binning=False)
 
def has_log_binnnig (self)
 
def name (self)
 
def TH1 (self)
 
def fill (self, value, weight=1.)
 
def write (self)
 
def max (self)
 
def min (self)
 
def setMinimum (self, minimum)
 
def setMaximum (self, maximum)
 
def fixHisto (self)
 

Private Member Functions

def __getInterval (self, value)
 

Private Attributes

 __name
 
 __xTitle
 
 __min
 
 __width
 
 __entries
 
 __content
 
 __error
 
 __TH1
 
 __TDir
 
 __log_binning
 
 __max
 

Detailed Description

Definition at line 18 of file PlotUtils.py.

Constructor & Destructor Documentation

◆ __init__()

def PlotUtils.DiagnosticHisto.__init__ (   self,
  name = "",
  axis_title = "",
  bins = -1,
  bmin = 0.,
  bmax = -1.e9,
  bin_width = -1,
  bdir = None,
  log_binning = False 
)

Definition at line 19 of file PlotUtils.py.

19  def __init__(self, name = "",
20  axis_title = "",
21  bins = -1,
22  bmin = 0.,
23  bmax = -1.e9,
24  bin_width = -1,
25  bdir = None,
26  log_binning = False):
27  self.__name = name
28  self.__xTitle = axis_title
29  self.__min = bmin
30  self.__width = bin_width
31  self.__entries = 0
32  self.__content = {}
33  self.__error = {}
34  self.__TH1 = None
35  self.__TDir = bdir
36 
37  self.__log_binning = log_binning
38  if bins > 0 and not log_binning:
39  self.__width = (bmax-bmin)/ bins
40  self.__TH1 = ROOT.TH1D(name, "Diagnostic histogram", bins, bmin, bmax)
41  self.__TH1.SetDirectory(bdir)
42  elif bins > 0:
43  log_start = math.log(bmin)
44  log_end = math.log(bmax)
45  log_step = (log_end -log_start) / bins
46  binning = array("f", [math.exp(log_start +n*log_step) for n in range(bins+1)])
47  self.__TH1 = ROOT.TH1D(name, "Diagnostic histogram", bins, binning)
48  self.__TH1.SetDirectory(bdir)
49 

Member Function Documentation

◆ __getInterval()

def PlotUtils.DiagnosticHisto.__getInterval (   self,
  value 
)
private

Definition at line 62 of file PlotUtils.py.

62  def __getInterval(self,value):
63  i = math.ceil( (value - self.__min) / self.__width)
64  return (self.__min +self.__width*(i-1), self.__min+ self.__width*i)

◆ fill()

def PlotUtils.DiagnosticHisto.fill (   self,
  value,
  weight = 1. 
)

Definition at line 53 of file PlotUtils.py.

53  def fill(self, value, weight=1.):
54  self.__entries +=1
55  if self.__TH1: self.__TH1.Fill(value, weight)
56  else:
57  rng = self.__getInterval(value)
58  try: self.__content[rng] += weight
59  except: self.__content[rng] = weight
60  try: self.__error[rng] += weight**2
61  except: self.__error[rng] = weight**2

◆ fixHisto()

def PlotUtils.DiagnosticHisto.fixHisto (   self)

Definition at line 86 of file PlotUtils.py.

86  def fixHisto(self):
87  if self.__TH1: return
88  bins = min (int((self.__max - self.__min) / self.__width), 10000)
89  self.__TH1 = ROOT.TH1D(self.name(), "Diagnostic histogram", bins, self.__min, self.__max)
90  self.__TH1.SetDirectory(self.__TDir)
91 
92  for rng in self.__content.iterkeys():
93  bin = self.__TH1.FindBin((rng[1] + rng[0])/2.)
94  self.__TH1.SetBinContent(bin, self.__content[rng])
95  self.__TH1.SetBinError(bin, math.sqrt(self.__error[rng]))
96 

◆ has_log_binnnig()

def PlotUtils.DiagnosticHisto.has_log_binnnig (   self)

Definition at line 50 of file PlotUtils.py.

50  def has_log_binnnig(self): return self.__log_binning

◆ max()

def PlotUtils.DiagnosticHisto.max (   self)

Definition at line 78 of file PlotUtils.py.

78  def max(self):
79  try: return sorted(self.__content.iterkeys(), key=lambda Rng: Rng[1])[-1][1]
80  except: return float('nan')

◆ min()

def PlotUtils.DiagnosticHisto.min (   self)

Definition at line 81 of file PlotUtils.py.

81  def min(self):
82  try: return sorted(self.__content.iterkeys(), key=lambda Rng: Rng[0])[0][1]
83  except: return float('nan')

◆ name()

def PlotUtils.DiagnosticHisto.name (   self)

Definition at line 51 of file PlotUtils.py.

51  def name(self): return self.__name

◆ setMaximum()

def PlotUtils.DiagnosticHisto.setMaximum (   self,
  maximum 
)

Definition at line 85 of file PlotUtils.py.

85  def setMaximum(self, maximum): self.__max = maximum

◆ setMinimum()

def PlotUtils.DiagnosticHisto.setMinimum (   self,
  minimum 
)

Definition at line 84 of file PlotUtils.py.

84  def setMinimum(self, minimum): self.__min = minimum

◆ TH1()

def PlotUtils.DiagnosticHisto.TH1 (   self)

Definition at line 52 of file PlotUtils.py.

52  def TH1(self): return self.__TH1

◆ write()

def PlotUtils.DiagnosticHisto.write (   self)

Definition at line 65 of file PlotUtils.py.

65  def write(self):
66  self.fixHisto()
67  if not self.__TH1: return
68  self.__TH1.GetXaxis().SetTitle(self.__xTitle)
69 
70  self.TH1().SetBinContent(self.TH1().GetNbinsX(),self.TH1().GetBinContent(self.TH1().GetNbinsX()+1) + self.TH1().GetBinContent(self.TH1().GetNbinsX()))
71  self.TH1().SetBinError(self.TH1().GetNbinsX(), math.sqrt( (self.TH1().GetBinError(self.TH1().GetNbinsX()+1) + self.TH1().GetBinError(self.TH1().GetNbinsX()))**2))
72 
73  self.TH1().SetBinContent(1,self.TH1().GetBinContent(0) + self.TH1().GetBinContent(1))
74  self.TH1().SetBinError(1, math.sqrt( (self.TH1().GetBinError(0) + self.TH1().GetBinError(1))**2))
75 
76  self.__TH1.SetEntries(self.__entries)
77  if self.__TDir: self.__TDir.WriteObject(self.__TH1, self.__name)

Member Data Documentation

◆ __content

PlotUtils.DiagnosticHisto.__content
private

Definition at line 25 of file PlotUtils.py.

◆ __entries

PlotUtils.DiagnosticHisto.__entries
private

Definition at line 24 of file PlotUtils.py.

◆ __error

PlotUtils.DiagnosticHisto.__error
private

Definition at line 26 of file PlotUtils.py.

◆ __log_binning

PlotUtils.DiagnosticHisto.__log_binning
private

Definition at line 30 of file PlotUtils.py.

◆ __max

PlotUtils.DiagnosticHisto.__max
private

Definition at line 85 of file PlotUtils.py.

◆ __min

PlotUtils.DiagnosticHisto.__min
private

Definition at line 22 of file PlotUtils.py.

◆ __name

PlotUtils.DiagnosticHisto.__name
private

Definition at line 20 of file PlotUtils.py.

◆ __TDir

PlotUtils.DiagnosticHisto.__TDir
private

Definition at line 28 of file PlotUtils.py.

◆ __TH1

PlotUtils.DiagnosticHisto.__TH1
private

Definition at line 27 of file PlotUtils.py.

◆ __width

PlotUtils.DiagnosticHisto.__width
private

Definition at line 23 of file PlotUtils.py.

◆ __xTitle

PlotUtils.DiagnosticHisto.__xTitle
private

Definition at line 21 of file PlotUtils.py.


The documentation for this class was generated from the following file:
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
RootHelpers::FindBin
Int_t FindBin(const TAxis *axis, const double x)
Definition: RootHelpers.cxx:14
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
python.Bindings.iterkeys
iterkeys
Definition: Control/AthenaPython/python/Bindings.py:810
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:247
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
array
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RCU::SetDirectory
bool SetDirectory(TObject *object, TDirectory *directory)
effects: set the directory this object is associated with returns: whether the object type actively k...
Definition: RootUtils.cxx:28
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
readCCLHist.float
float
Definition: readCCLHist.py:83