The Gaudi Framework  v36r1 (3e2fb5a8)
TupleEx1.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
21 """
22 *******************************************************************************
23 * *
24 * Simple example which illustrate the usage of useful *
25 * algorithm base class for N-Tuple manipulations *
26 * *
27 *******************************************************************************
28 """
29 from __future__ import print_function
30 # =============================================================================
31 __author__ = 'Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr'
32 # =============================================================================
33 
34 import GaudiPython
35 import math
36 
37 SUCCESS = GaudiPython.SUCCESS
38 
39 # random numbewrs
40 Rndm = GaudiPython.gbl.Rndm
41 Numbers = Rndm.Numbers
42 
43 from GaudiPython.GaudiAlgs import TupleAlgo, mapvct
44 
45 # =============================================================================
46 # Primitive function which transform arbitrary sequence into
47 # GaudiPython.Vector ( std::vector<double> )
48 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
49 # @date 2006-11-26
50 
51 
52 def vct(sequence):
53  """
54  Primitive function which transform arbitrary sequence into
55  GaudiPython.Vector ( std::vector<double> )
56  """
57  result = GaudiPython.gbl.GaudiPython.Vector()
58  if hasattr(sequence, '__len__'):
59  result.reserve(len(sequence))
60  elif hasattr(sequence, 'size'):
61  result.reserve(sequence.size())
62 
63  for item in sequence:
64  result.push_back(item)
65  return result
66 
67 
68 # =============================================================================
69 # @class TupleEx1
70 # Simple algorithm which book&fill 3 histograms
71 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
72 # @date 2006-11-26
73 
74 
76  """
77  Simple algorithm which implicitely book&fill N-Tuples
78  """
79 
80  # the main executiomethod
81 
82  def execute(self):
83  """
84  The major method 'execute', it is invoked for each event
85  """
86 
87  rSvc = self.randSvc()
88  gauss = Numbers(rSvc, Rndm.Gauss(0.0, 1.0))
89  flat = Numbers(rSvc, Rndm.Flat(-10, 10))
90  expo = Numbers(rSvc, Rndm.Exponential(1.0))
91  breit = Numbers(rSvc, Rndm.BreitWigner(0.0, 1.0))
92  poisson = Numbers(rSvc, Rndm.Poisson(2.0))
93  binom = Numbers(rSvc, Rndm.Binomial(8, 0.25))
94 
95  # =====================================================================
96  # primitive row-wise n-tuple
97  # =====================================================================
98  tuple1 = self.nTuple(1, "Trivial Row-Wise Tuple", 42)
99 
100  # fill N-Tuple with double/float numbers:
101  tuple1.column('gauss', gauss())
102  tuple1.column('flat', flat())
103  tuple1.column('expo', expo())
104  tuple1.column('breit', breit())
105 
106  # fill N-Tuple with integer numbers:
107  tuple1.column('poiss1', int(poisson()))
108  tuple1.column('binom1', int(binom()))
109 
110  # fill N-Tuple with long long numbers:
111  tuple1.column_ll('poiss2', int(poisson()))
112  tuple1.column_ll('binom2', int(binom()))
113 
114  # fill N-Tuple with unsigned long long numbers:
115  tuple1.column_ull('poiss3', int(poisson()))
116  tuple1.column_ull('binom3', int(binom()))
117 
118  # fill N-Tuple with "reduced" integer numbers:
119  tuple1.column('poiss4', int(poisson()), 0, 14)
120  tuple1.column('binom4', int(binom()), 0, 14)
121 
122  # fill N-Tuple with "boolean" numbers:
123  tuple1.column("poisb", poisson() > 1.0)
124 
125  # commit the row
126  tuple1.write()
127 
128  # =====================================================================
129  # the same n-tuple but column-wise
130  # =====================================================================
131  tuple2 = self.nTuple(2, "Trivial Column-Wise Tuple")
132 
133  # fill N-Tuple with double/float numbers:
134  tuple2.column('gauss', gauss())
135  tuple2.column('flat', flat())
136  tuple2.column('expo', expo())
137  tuple2.column('breit', breit())
138 
139  # fill N-Tuple with integer numbers:
140  tuple2.column('poiss', int(poisson()))
141  tuple2.column('binom', int(binom()))
142  # fill N-Tuple with "reduced" integer numbers:
143  tuple2.column('poiss', int(poisson()), 0, 14)
144  tuple2.column('binom', int(binom()), 0, 14)
145 
146  # fill N-Tuple with "boolean" numbers:
147  tuple2.column("poisb", poisson() > 1.0)
148 
149  # commit the row
150  tuple2.write()
151 
152  # =====================================================================
153  # book and fill Column-wise NTuple with "fixed"-size arrays/vectors
154  # =====================================================================
155  tuple3 = self.nTuple(3, "Fixed-size arrays/vectors")
156 
157  tuple3.array('arflat', vct([flat() for i in range(0, 50)]))
158  tuple3.array('arexpo', vct([expo() for i in range(0, 62)]))
159  tuple3.array('argau', vct([gauss() for i in range(0, 42)]))
160  t = tuple([gauss() for i in range(0, 42)])
161  tuple3.array('argau2', vct(t))
162 
163  tuple3.write()
164 
165  return SUCCESS
166 
167 
168 # =============================================================================
169 # job configuration
170 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
171 # @date 2006-11-26
172 def configure(gaudi=None):
173  """ Configuration of the job """
174 
175  if not gaudi:
176  gaudi = GaudiPython.AppMgr()
177 
178  gaudi.JobOptionsType = 'NONE'
179  gaudi.EvtSel = 'NONE'
180  gaudi.HistogramPersistency = 'ROOT'
181 
182  gaudi.ExtSvc += ["NTupleSvc"]
183 
184  ntSvc = gaudi.service('NTupleSvc')
185  ntSvc.Output = ["MYLUN DATAFILE='TupleEx1.root' OPT='NEW' TYP='ROOT'"]
186 
187  gaudi.config()
188 
189  gaudi.DLLs = [
190  'GaudiAlg',
191  'RootHistCnv',
192  ]
193 
194  alg = TupleEx1('TupleEx1')
195  gaudi.setAlgorithms([alg])
196 
197  # configure the properties
198  alg.NTupleLUN = 'MYLUN'
199 
200  return SUCCESS
201 
202 
203 # =============================================================================
204 # The actual job excution
205 # @author Vanya BELYAEV ibelyaev@physics.syr.edu
206 # @date 2006-11-26
207 if '__main__' == __name__:
208  print(__doc__)
210  configure(gaudi)
211  gaudi.run(20)
212 
213 # =============================================================================
214 # The END
215 # =============================================================================
GaudiPython.GaudiAlgs.TupleAlgo
Definition: GaudiAlgs.py:881
TupleEx1.TupleEx1
Definition: TupleEx1.py:75
TupleEx1.configure
def configure(gaudi=None)
Definition: TupleEx1.py:172
GaudiPython.Bindings.AppMgr
Definition: Bindings.py:842
Rndm::Flat
Parameters for the flat random number generation within boundaries [minimum, maximum].
Definition: RndmGenerators.h:253
TupleEx1.vct
def vct(sequence)
Definition: TupleEx1.py:52
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
Rndm::BreitWigner
Parameters for the BreitWigner distributed random number generation.
Definition: RndmGenerators.h:94
HistoUtilsEx.gauss
gauss
Definition: HistoUtilsEx.py:66
TupleEx1.TupleEx1.execute
def execute(self)
Definition: TupleEx1.py:82
Rndm::Exponential
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:56
Rndm::Poisson
Parameters for the Poisson distributed random number generation with a given mean.
Definition: RndmGenerators.h:209
GaudiPython.GaudiAlgs
Definition: GaudiAlgs.py:1
TupleEx1.Numbers
Numbers
Definition: TupleEx1.py:41
Rndm::Binomial
Parameters for the Binomial distributed random number generation.
Definition: RndmGenerators.h:230
Gaudi::Functional::details::zip::range
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
Definition: FunctionalDetails.h:97