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