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