Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Counter.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
13 """
14 *******************************************************************************
15 * *
16 * Simple example which illustrates the usage of the useful base class *
17 * GaudiAlgo (python version of C++ GaudiAlgorithm) for "easy" manipulations *
18 * with 'counters' *
19 * *
20 * The example is equivalent to C++ example 'CounterEx', see *
21 * GaudiExamples/src/CounterEx/*.cpp and *
22 * GaudiExamples/options/CounterEx.opts *
23 * *
24 *******************************************************************************
25 """
26 from __future__ import print_function
27 
28 import six
29 
30 # =============================================================================
31 __author__ = "Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr"
32 # =============================================================================
33 
34 from GaudiPython.GaudiAlgs import GaudiAlgo
35 
36 import GaudiPython
37 
38 Rndm = GaudiPython.gbl.Rndm
39 Numbers = Rndm.Numbers
40 SUCCESS = GaudiPython.SUCCESS
41 
42 Numbers.__call__ = Numbers.shoot
43 
44 # =============================================================================
45 # Simple algorithm which manipulates with counters
46 # =============================================================================
47 
48 
50  """Simple algorithm which manipulates with counters"""
51 
52  def __init__(self, name="Counter"):
53  """Constructor"""
54  GaudiAlgo.__init__(self, name)
55 
56  def execute(self):
57  """The major method 'execute', it is invoked for each event"""
58 
59  executed = self.counter("executed")
60  executed += 1.0
61 
62  gauss = Numbers(self.randSvc(), Rndm.Gauss(0.0, 1.0))
63  poisson = Numbers(self.randSvc(), Rndm.Poisson(5.0))
64 
65  # 'accuulate gauss'
66  value = gauss.shoot()
67 
68  g1 = self.counter("gauss")
69  g2 = self.counter("g2")
70 
71  g1 += value
72  g2 += value * value
73 
74  if 0 < value:
75  gp = self.counter("Gpos")
76  gp += 1.0
77  else:
78  gn = self.counter("Gneg")
79  gn += 1.0
80 
81  stat1 = self.counter("NG")
82  stat2 = self.counter("G")
83  for i in range(0, int(poisson())):
84  stat1 += 1.0
85  stat2 += gauss()
86 
87  stat3 = self.counter("eff")
88  stat3 += value > 0
89 
90  # print statistics every 1000 events
91  executed = self.counter("executed")
92  prnt = int(executed.flag())
93  if 0 == prnt % 1000:
94  six.print_(" Event number %s " % prnt, flush=True)
95  bc = self.counter("eff")
96  line = "(%.12g += %.12g)%s" % (bc.eff() * 100, bc.effErr() * 100, "%")
97  six.print_(' Efficiency (binomial counter "eff"): %s' % line, flush=True)
98 
99  return SUCCESS
100 
101 
102 # =============================================================================
103 # job configuration
104 # =============================================================================
105 def configure(gaudi=None):
106  """Configuration of the job"""
107 
108  if not gaudi:
109  gaudi = GaudiPython.AppMgr()
110 
111  gaudi.JobOptionsType = "NONE"
112  gaudi.EvtSel = "NONE"
113 
114  gaudi.config()
115 
116  alg = Counter()
117  gaudi.setAlgorithms([alg])
118  gaudi.ExtSvc += ["Gaudi::Monitoring::MessageSvcSink"]
119 
120  return SUCCESS
121 
122 
123 # =============================================================================
124 # The actual job excution
125 # =============================================================================
126 if "__main__" == __name__:
127  print(__doc__ + __author__)
129  configure(gaudi)
130  gaudi.run(5400)
131 
132 # =============================================================================
133 # The END
134 # =============================================================================
Counter.configure
def configure(gaudi=None)
Definition: Counter.py:105
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:869
GaudiPython.GaudiAlgs.GaudiAlgo
Definition: GaudiAlgs.py:638
Counter.Numbers
Numbers
Definition: Counter.py:39
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
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
Counter.Counter.execute
def execute(self)
Definition: Counter.py:56
Counter.Counter.__init__
def __init__(self, name="Counter")
Definition: Counter.py:52
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
GaudiPython.GaudiAlgs
Definition: GaudiAlgs.py:1
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:102
Counter.Counter
Definition: Counter.py:49