Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HistoEx2.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 * *
19 * This example illustrates the usage of 1D and 2D profile histograms *
20 * *
21 *******************************************************************************
22 """
23 # =============================================================================
24 __author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
25 # =============================================================================
26 
27 from GaudiPython.Bindings import gbl as cpp
28 from GaudiPython.GaudiAlgs import SUCCESS, HistoAlgo
29 
30 Rndm = cpp.Rndm
31 
32 # =============================================================================
33 # Simple algorithm which book&fill two profile histograms
34 # =============================================================================
35 
36 
38  """Simple algorithm which explicitly book&fill profile histograms"""
39 
40  def __init__(self, name="HistoEx2"):
41  """Constructor"""
42  HistoAlgo.__init__(self, name)
43 
44  def execute(self):
45  """The major method 'execute', it is invoked for each event"""
46  gauss = Rndm.Numbers(self.randSvc(), Rndm.Gauss(0, 1))
47 
48  for i in range(0, 1000):
49  x = gauss()
50  y = gauss()
51  self.plot2D(x, y, " x vs y ", -2, 2, -4, 4)
52  self.plot2D(x, y + 3 * x, " x vs y+3x ", -2, 2, -4, 4)
53  self.plot2D(x, y - 3 * x, " x vs y-3x ", -2, 2, -4, 4)
54  self.profile1D(x, y, " x vs y (profile)", -2, 2)
55  self.profile1D(x, y + 3 * x, " x vs y+3x (profile)", -2, 2)
56  self.profile1D(x, y - 3 * x, " x vs y-3x (profile)", -2, 2)
57  return SUCCESS
58 
59 
60 # =============================================================================
61 # job configuration
62 # =============================================================================
63 def configure(gaudi=None):
64  """Configuration of the job"""
65 
66  import HistoEx1
67 
68  if not gaudi:
69  from GaudiPython.Bindings import AppMgr
70 
71  gaudi = AppMgr()
72 
73  HistoEx1.configure(gaudi)
74 
75  hsvc = gaudi.service("HistogramPersistencySvc")
76  hsvc.OutputFile = "histoex2.root"
77 
78  alg = HistoEx2("HistoEx2")
79  gaudi.addAlgorithm(alg)
80 
81  alg.HistoPrint = True
82 
83  return SUCCESS
84 
85 
86 # =============================================================================
87 # The actual job execution
88 # =============================================================================
89 if "__main__" == __name__:
90  print(__doc__ + __author__)
91 
92  import GaudiPython.HistoUtils # noqa: F401 (adds dump method)
93  from GaudiPython.Bindings import AppMgr
94 
95  gaudi = AppMgr()
96  configure(gaudi)
97 
98  gaudi.run(20)
99 
100  # Skip the next part when running within QMTest
101  for alg in ("HistoEx", "HistoEx1", "HistoEx2"):
102  alg = gaudi.algorithm(alg)
103  histos = alg.Histos()
104  for key in sorted(histos):
105  histo = histos[key]
106  print(" Alg='%s', ID='%s' , Histo=%s " % (alg.name(), key, histo))
107  if hasattr(histo, "dump"):
108  print(histo.dump(60, 20, True))
GaudiPython.HistoUtils
Definition: HistoUtils.py:1
GaudiPython.GaudiAlgs.HistoAlgo
Definition: GaudiAlgs.py:768
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:869
HistoEx2.HistoEx2.__init__
def __init__(self, name="HistoEx2")
Definition: HistoEx2.py:40
HistoEx2.HistoEx2.execute
def execute(self)
Definition: HistoEx2.py:44
GaudiPython.Bindings
Definition: Bindings.py:1
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
HistoEx2.HistoEx2
Definition: HistoEx2.py:37
HistoEx2.configure
def configure(gaudi=None)
Definition: HistoEx2.py:63
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
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