The Gaudi Framework  v36r11 (bdb84f5f)
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 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  hsvc = gaudi.service("HistogramPersistencySvc")
84  hsvc.OutputFile = "histoex1.root"
85 
86  alg = HistoEx1("HistoEx1")
87  gaudi.addAlgorithm(alg)
88 
89  alg.HistoPrint = True
90 
91  return SUCCESS
92 
93 
94 # =============================================================================
95 # The actual job excution
96 # =============================================================================
97 if "__main__" == __name__:
98  print(__doc__ + __author__)
99 
100  from GaudiPython.Bindings import AppMgr
101 
102  gaudi = AppMgr()
103 
104  configure(gaudi)
105 
106  gaudi.run(20)
108 
109  alg = gaudi.algorithm("HistoEx1")
110  histos = alg.Histos()
111  for key in sorted(histos):
112  histo = histos[key]
113  if hasattr(histo, "dump"):
114  print(histo.dump(80, 20, True))
115 
116 # =============================================================================
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:872
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