The Gaudi Framework  v36r7 (7f57a304)
HistoEx2.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 * This example illustrates the usage of 1D and 2D profile histograms *
20 * *
21 *******************************************************************************
22 """
23 from __future__ import print_function
24 
25 # =============================================================================
26 __author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
27 # =============================================================================
28 import os
29 
30 from GaudiPython.Bindings import gbl as cpp
31 from GaudiPython.GaudiAlgs import SUCCESS, HistoAlgo
32 
33 Rndm = cpp.Rndm
34 
35 # =============================================================================
36 # Simple algorithm which book&fill two profile histograms
37 # =============================================================================
38 
39 
41  """Simple algorithm which explicitly book&fill profile histograms"""
42 
43  def __init__(self, name="HistoEx2"):
44  """Constructor"""
45  HistoAlgo.__init__(self, name)
46 
47  def execute(self):
48  """The major method 'execute', it is invoked for each event"""
49 
50  gauss = Rndm.Numbers(self.randSvc(), Rndm.Gauss(0, 1))
51 
52  for i in range(0, 10000):
53  x = gauss()
54  y = gauss()
55  self.plot2D(x, y, " x vs y ", -2, 2, -4, 4)
56  self.plot2D(x, y + 3 * x, " x vs y+3x ", -2, 2, -4, 4)
57  self.plot2D(x, y - 3 * x, " x vs y-3x ", -2, 2, -4, 4)
58  self.profile1D(x, y, " x vs y (profile)", -2, 2)
59  self.profile1D(x, y + 3 * x, " x vs y+3x (profile)", -2, 2)
60  self.profile1D(x, y - 3 * x, " x vs y-3x (profile)", -2, 2)
61  return SUCCESS
62 
63 
64 # =============================================================================
65 # job configuration
66 # =============================================================================
67 def configure(gaudi=None):
68  """Configuration of the job"""
69 
70  import HistoEx1
71 
72  if not gaudi:
73  from GaudiPython.Bindings import AppMgr
74 
75  gaudi = AppMgr()
76 
77  HistoEx1.configure(gaudi)
78 
79  alg = HistoEx2("HistoEx2")
80  gaudi.addAlgorithm(alg)
81 
82  alg.HistoPrint = True
83 
84  return SUCCESS
85 
86 
87 # =============================================================================
88 # The actual job execution
89 # =============================================================================
90 if "__main__" == __name__:
91  print(__doc__ + __author__)
92 
94  from GaudiPython.Bindings import AppMgr
95 
96  gaudi = AppMgr()
97  configure(gaudi)
98 
99  gaudi.run(20)
100 
101  # Skip the next part when running within QMTest
102  for alg in ("HistoEx", "HistoEx1", "HistoEx2"):
103  alg = gaudi.algorithm(alg)
104  histos = alg.Histos()
105  for key in sorted(histos):
106  histo = histos[key]
107  print(" Alg='%s', ID='%s' , Histo=%s " % (alg.name(), key, histo))
108  if hasattr(histo, "dump"):
109  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:873
HistoEx2.HistoEx2.__init__
def __init__(self, name="HistoEx2")
Definition: HistoEx2.py:43
HistoEx2.HistoEx2.execute
def execute(self)
Definition: HistoEx2.py:47
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:40
HistoEx2.configure
def configure(gaudi=None)
Definition: HistoEx2.py:67
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
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