The Gaudi Framework  v36r7 (7f57a304)
HistoEx1.py
Go to the documentation of this file.
1 #!/usr/bin/env python
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 from __future__ import print_function
24 
25 # =============================================================================
26 __author__ = "Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr"
27 # =============================================================================
28 
29 from GaudiPython.GaudiAlgs import SUCCESS, HistoAlgo
30 
31 # =============================================================================
32 # Simple algorithm which book&fill 3 histograms
33 # =============================================================================
34 
35 
37  """Simple algorithm which explicitely book&fill three histograms"""
38 
39  def __init__(self, name):
40  """Constructor"""
41  HistoAlgo.__init__(self, name)
42 
43  def initialize(self):
44  """Initialization, initialize the base class and book histograms"""
45  status = HistoAlgo.initialize(self)
46  if status.isFailure():
47  return status
48 
49  self.h1 = self.book1D(" 1D histo ", 0, 20, 20)
50  self.h2 = self.book2D(" 2D histo ", 0, 20, 20, 0, 20, 20)
51  self.h3 = self.book3D(" 3D histo ", 0, 20, 20, 0, 20, 20, 0, 20, 20)
52 
53  return SUCCESS
54 
55  def execute(self):
56  """The major method 'execute', it is invoked for each event"""
57 
58  for i in range(0, 10):
59  self.h1.fill(i, 0.166)
60  for j in range(0, 10):
61  self.h2.fill(i, j)
62  for k in range(0, 10):
63  self.h3.fill(i, j, k)
64 
65  return SUCCESS
66 
67 
68 # =============================================================================
69 # job configuration
70 # =============================================================================
71 def configure(gaudi=None):
72  """Configuration of the job"""
73 
74  import HistoEx
75 
76  if not gaudi:
77  from GaudiPython.Bindings import AppMgr
78 
79  gaudi = AppMgr()
80 
81  HistoEx.configure(gaudi)
82 
83  alg = HistoEx1("HistoEx1")
84  gaudi.addAlgorithm(alg)
85 
86  alg.HistoPrint = True
87 
88  return SUCCESS
89 
90 
91 # =============================================================================
92 # The actual job excution
93 # =============================================================================
94 if "__main__" == __name__:
95  print(__doc__ + __author__)
96 
97  from GaudiPython.Bindings import AppMgr
98 
99  gaudi = AppMgr()
100 
101  configure(gaudi)
102 
103  gaudi.run(20)
105 
106  alg = gaudi.algorithm("HistoEx1")
107  histos = alg.Histos()
108  for key in sorted(histos):
109  histo = histos[key]
110  if hasattr(histo, "dump"):
111  print(histo.dump(80, 20, True))
112 
113 # =============================================================================
HistoEx1.HistoEx1.h3
h3
Definition: HistoEx1.py:51
GaudiPython.HistoUtils
Definition: HistoUtils.py:1
GaudiPython.GaudiAlgs.HistoAlgo
Definition: GaudiAlgs.py:768
HistoEx1.HistoEx1.initialize
def initialize(self)
Definition: HistoEx1.py:43
HistoEx1.HistoEx1.h2
h2
Definition: HistoEx1.py:50
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:873
HistoEx1.HistoEx1
Definition: HistoEx1.py:36
HistoEx1.HistoEx1.execute
def execute(self)
Definition: HistoEx1.py:55
GaudiPython.Bindings
Definition: Bindings.py:1
HistoEx1.HistoEx1.h1
h1
Definition: HistoEx1.py:49
HistoEx.configure
def configure(gaudi=None)
Definition: HistoEx.py:56
HistoEx1.HistoEx1.__init__
def __init__(self, name)
Definition: HistoEx1.py:39
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:71
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:102