The Gaudi Framework  v36r9p1 (5c15b2bb)
HistoEx.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 * *
19 *******************************************************************************
20 """
21 from __future__ import print_function
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 implicitely book&fill three histograms"""
36 
37  def __init__(self, name):
38  """Constructor"""
39  HistoAlgo.__init__(self, name)
40 
41  def execute(self):
42  """The major method 'execute', it is invoked for each event"""
43  for i in range(0, 10):
44  self.plot1D(i, " 1D histo ", 0, 20, 20)
45  for j in range(0, 10):
46  self.plot2D(i, j, " 2D histo ", 0, 20, 0, 20, 20, 20)
47  for k in range(0, 10):
48  self.plot3D(i, j, k, " 3D histo ", 0, 20, 0, 20, 0, 20, 20, 20, 20)
49 
50  return SUCCESS
51 
52 
53 # =============================================================================
54 # job configuration
55 # =============================================================================
56 def configure(gaudi=None):
57  """Configuration of the job"""
58 
59  if not gaudi:
60  from GaudiPython.Bindings import AppMgr
61 
62  gaudi = AppMgr()
63 
64  gaudi.JobOptionsType = "NONE"
65  gaudi.EvtSel = "NONE"
66  gaudi.HistogramPersistency = "ROOT"
67 
68  gaudi.config()
69 
70  gaudi.DLLs = [
71  "GaudiAlg",
72  "RootHistCnv",
73  ]
74 
75  alg = HistoEx("HistoEx")
76  gaudi.setAlgorithms([alg])
77  alg.HistoPrint = True
78 
79  hsvc = gaudi.service("HistogramPersistencySvc")
80  hsvc.OutputFile = "histoex.root"
81 
82  # This does not harm and tests bug #50389
83  getMyalgBack = gaudi.algorithm("HistoEx")
84 
85  return SUCCESS
86 
87 
88 # =============================================================================
89 # The actual job excution
90 # =============================================================================
91 if "__main__" == __name__:
92  print(__doc__ + __author__)
93 
94  from GaudiPython.Bindings import AppMgr
95 
96  gaudi = AppMgr()
97  configure(gaudi)
98  gaudi.run(20)
99 
101 
102  alg = gaudi.algorithm("HistoEx")
103  histos = alg.Histos()
104  for key in sorted(histos):
105  histo = histos[key]
106  if hasattr(histo, "dump"):
107  print(histo.dump(80, 20, True))
108 
109 # =============================================================================
110 # The END
111 # =============================================================================
GaudiPython.HistoUtils
Definition: HistoUtils.py:1
GaudiPython.GaudiAlgs.HistoAlgo
Definition: GaudiAlgs.py:768
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:873
GaudiPython.Bindings
Definition: Bindings.py:1
HistoEx.configure
def configure(gaudi=None)
Definition: HistoEx.py:56
HistoEx.HistoEx.__init__
def __init__(self, name)
Definition: HistoEx.py:37
HistoEx.HistoEx.execute
def execute(self)
Definition: HistoEx.py:41
GaudiPython.GaudiAlgs
Definition: GaudiAlgs.py:1
HistoEx.HistoEx
Definition: HistoEx.py:34
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:102