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