Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HistoEx1.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
13 """
14 *******************************************************************************
15 * *
16 * Simple example which illustrate the usage of useful algorithm base class *
17 * HistoAlgo (python version of C++ GaudiHistoAlg) for "easy" histogramming. *
18 * It is an extension of HistoEx module, it provides similar algorithm, but *
19 * with explicit histogram manipulation trhrough explicit book and fill *
20 * *
21 *******************************************************************************
22 """
23 # =============================================================================
24 __author__ = "Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr"
25 # =============================================================================
26 
27 from GaudiPython.GaudiAlgs import SUCCESS, HistoAlgo
28 
29 # =============================================================================
30 # Simple algorithm which book&fill 3 histograms
31 # =============================================================================
32 
33 
35  """Simple algorithm which explicitely book&fill three histograms"""
36 
37  def __init__(self, name):
38  """Constructor"""
39  HistoAlgo.__init__(self, name)
40 
41  def initialize(self):
42  """Initialization, initialize the base class and book histograms"""
43  status = HistoAlgo.initialize(self)
44  if status.isFailure():
45  return status
46 
47  self.h1 = self.book1D(" 1D histo ", 0, 20, 20)
48  self.h2 = self.book2D(" 2D histo ", 0, 20, 20, 0, 20, 20)
49  self.h3 = self.book3D(" 3D histo ", 0, 20, 20, 0, 20, 20, 0, 20, 20)
50 
51  return SUCCESS
52 
53  def execute(self):
54  """The major method 'execute', it is invoked for each event"""
55 
56  for i in range(0, 10):
57  self.h1.fill(i, 0.166)
58  for j in range(0, 10):
59  self.h2.fill(i, j)
60  for k in range(0, 10):
61  self.h3.fill(i, j, k)
62 
63  return SUCCESS
64 
65 
66 # =============================================================================
67 # job configuration
68 # =============================================================================
69 def configure(gaudi=None):
70  """Configuration of the job"""
71 
72  import HistoEx
73 
74  if not gaudi:
75  from GaudiPython.Bindings import AppMgr
76 
77  gaudi = AppMgr()
78 
79  HistoEx.configure(gaudi)
80 
81  hsvc = gaudi.service("HistogramPersistencySvc")
82  hsvc.OutputFile = "histoex1.root"
83 
84  alg = HistoEx1("HistoEx1")
85  gaudi.addAlgorithm(alg)
86 
87  alg.HistoPrint = True
88 
89  return SUCCESS
90 
91 
92 # =============================================================================
93 # The actual job excution
94 # =============================================================================
95 if "__main__" == __name__:
96  print(__doc__ + __author__)
97 
98  from GaudiPython.Bindings import AppMgr
99 
100  gaudi = AppMgr()
101 
102  configure(gaudi)
103 
104  gaudi.run(20)
105  import GaudiPython.HistoUtils # noqa: F401 (adds dump method)
106 
107  alg = gaudi.algorithm("HistoEx1")
108  histos = alg.Histos()
109  for key in sorted(histos):
110  histo = histos[key]
111  if hasattr(histo, "dump"):
112  print(histo.dump(80, 20, True))
113 
114 # =============================================================================
HistoEx1.HistoEx1.h3
h3
Definition: HistoEx1.py:49
GaudiPython.HistoUtils
Definition: HistoUtils.py:1
GaudiPython.GaudiAlgs.HistoAlgo
Definition: GaudiAlgs.py:768
HistoEx1.HistoEx1.initialize
def initialize(self)
Definition: HistoEx1.py:41
HistoEx1.HistoEx1.h2
h2
Definition: HistoEx1.py:48
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:869
HistoEx1.HistoEx1
Definition: HistoEx1.py:34
HistoEx1.HistoEx1.execute
def execute(self)
Definition: HistoEx1.py:53
GaudiPython.Bindings
Definition: Bindings.py:1
HistoEx1.HistoEx1.h1
h1
Definition: HistoEx1.py:47
HistoEx.configure
def configure(gaudi=None)
Definition: HistoEx.py:54
HistoEx1.HistoEx1.__init__
def __init__(self, name)
Definition: HistoEx1.py:37
Gaudi::Utils::Histos::fill
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
Definition: Fill.cpp:45
GaudiPython.GaudiAlgs
Definition: GaudiAlgs.py:1
HistoEx1.configure
def configure(gaudi=None)
Definition: HistoEx1.py:69
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:102