The Gaudi Framework  v36r11 (bdb84f5f)
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 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  gauss = Rndm.Numbers(self.randSvc(), Rndm.Gauss(0, 1))
50 
51  for i in range(0, 1000):
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 
74  gaudi = AppMgr()
75 
76  HistoEx1.configure(gaudi)
77 
78  hsvc = gaudi.service("HistogramPersistencySvc")
79  hsvc.OutputFile = "histoex2.root"
80 
81  alg = HistoEx2("HistoEx2")
82  gaudi.addAlgorithm(alg)
83 
84  alg.HistoPrint = True
85 
86  return SUCCESS
87 
88 
89 # =============================================================================
90 # The actual job execution
91 # =============================================================================
92 if "__main__" == __name__:
93  print(__doc__ + __author__)
94 
96  from GaudiPython.Bindings import AppMgr
97 
98  gaudi = AppMgr()
99  configure(gaudi)
100 
101  gaudi.run(20)
102 
103  # Skip the next part when running within QMTest
104  for alg in ("HistoEx", "HistoEx1", "HistoEx2"):
105  alg = gaudi.algorithm(alg)
106  histos = alg.Histos()
107  for key in sorted(histos):
108  histo = histos[key]
109  print(" Alg='%s', ID='%s' , Histo=%s " % (alg.name(), key, histo))
110  if hasattr(histo, "dump"):
111  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:872
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:66
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