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