00001
00002
00003
00004
00005
00006
00007
00008
00009 """
00010 Simple exmaple to illustrate the usage ofsmart and friendly
00011 N-Tuples outside of algoruthm-scope in 'script-like' environment
00012 """
00013
00014 __author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
00015
00016
00017 import GaudiPython
00018 import GaudiPython.TupleUtils as TupleUtils
00019
00020
00021 gaudi = GaudiPython.AppMgr()
00022
00023
00024 gaudi.EvtSel = 'NONE'
00025
00026 gaudi.HistogramPersistency = 'ROOT'
00027
00028 toolSvc = gaudi.toolsvc()
00029
00030
00031
00032
00033 ntSvc = GaudiPython.iService ( 'NTupleSvc' )
00034
00035 ntSvc.Output = [ "MYLUN1 DATAFILE='TupleEx4_1.root' OPT='NEW'" ,
00036 "MYLUN2 DATAFILE='TupleEx4_2.root' OPT='NEW'" ,
00037 "MYLUN3 DATAFILE='TupleEx4_3.root' OPT='NEW'" ]
00038
00039
00040 gaudi.config()
00041 gaudi.initialize()
00042
00043
00044 Rndm = GaudiPython.gbl.Rndm
00045 IRndmGenSvc = GaudiPython.gbl.IRndmGenSvc
00046 rndmSvc = gaudi.service('RndmGenSvc',IRndmGenSvc)
00047 if not rndmSvc : gaudi.createSvc('RndmGenSvc')
00048 rndmSvc = gaudi.service('RndmGenSvc',IRndmGenSvc)
00049
00050 gauss = Rndm.Numbers ( rndmSvc , Rndm.Gauss ( 0.0 , 1.0 ) )
00051
00052
00053
00054 tup1 = TupleUtils.nTuple( "path" ,
00055 "It is a title for my n-tuple" ,
00056 LUN = 'MYLUN1' )
00057
00058 for i in xrange(0,5000) :
00059 tup1.column ( 'i' , i )
00060 tup1.column ( 'g1' , gauss() )
00061 tup1.column ( 'g2' , gauss() )
00062 b = 0 < gauss()
00063 tup1.column ( 'b1' , b )
00064 tup1.write ()
00065
00066
00067
00068 Math = GaudiPython.gbl.ROOT.Math
00069
00070
00071 tup2 = TupleUtils.nTuple( "another/path" ,
00072 "MyTupleLV" ,
00073 "N-tuple: Lorentz Vectors " ,
00074 LUN = 'MYLUN1' )
00075
00076
00077 for i in xrange(0,1000) :
00078
00079
00080 lv1 = Math.PxPyPzEVector ( gauss() , gauss() , gauss() , gauss() )
00081 tup2.column ( "lv1" , lv1 )
00082
00083
00084 lv2 = Math.PtEtaPhiEVector ( gauss() , gauss() , gauss() , gauss() )
00085 tup2.column ( "lv2" , lv2 )
00086
00087 tup2.write ()
00088
00089
00090
00091 tup3 = TupleUtils.nTuple( "another/path" ,
00092 "MyTuple3DV" ,
00093 "N-tuple: 3D-Vectors " ,
00094 LUN = 'MYLUN2' )
00095
00096
00097 for i in xrange(0,1000) :
00098
00099
00100 v1 = Math.XYZVector( gauss() , gauss() , gauss() )
00101 tup3.column ( "v1" , v1 )
00102
00103
00104 v2 = Math.Polar3DVector( gauss() , gauss() , gauss() )
00105 tup3.column ( "v2" , v2 )
00106
00107
00108 v3 = Math.RhoEtaPhiVector( gauss() , gauss() , gauss() )
00109 tup3.column ( "v3" , v3 )
00110
00111
00112 v4 = Math.RhoZPhiVector( gauss() , gauss() , gauss() )
00113 tup3.column ( "v4" , v4 )
00114
00115 tup3.write ()
00116
00117
00118
00119 tup4 = TupleUtils.nTuple( "another/path" ,
00120 "MyTuple3DP" ,
00121 "N-tuple: 3D-Points" ,
00122 LUN = 'MYLUN3' )
00123
00124
00125 for i in xrange(0,1000) :
00126
00127
00128 p1 = Math.XYZPoint( gauss() , gauss() , gauss() )
00129 tup4.column ( "p1" , p1 )
00130
00131
00132 p2 = Math.Polar3DPoint( gauss() , gauss() , gauss() )
00133 tup4.column ( "p2" , p2 )
00134
00135
00136 p3 = Math.RhoEtaPhiPoint( gauss() , gauss() , gauss() )
00137 tup4.column ( "p3" , p3 )
00138
00139
00140 p4 = Math.RhoZPhiPoint( gauss() , gauss() , gauss() )
00141 tup4.column ( "p4" , p4 )
00142
00143 tup4.write ()
00144
00145
00146
00147 tup5 = TupleUtils.nTuple( "another/path" ,
00148 415 ,
00149 "N-tuple: VarArrays" ,
00150 LUN = 'MYLUN1' )
00151
00152 vct1 = GaudiPython.gbl.vector('double')
00153 GaudiPython.loaddict('CLHEPRflx')
00154 vct2 = GaudiPython.gbl.CLHEP.HepVector
00155
00156
00157 for i in xrange ( 0 , 100 ) :
00158
00159
00160 v1=vct1()
00161 n=max(10,long(50+25*gauss()))
00162 n=min(n,100)
00163 while n > v1.size() : v1.push_back ( gauss() )
00164
00165 tup5.farray ( 'vct1' , v1 , 'len1' , 100 )
00166
00167 n2=min(50,max(5,long(50+25*gauss())))
00168 v2 = vct2(n2)
00169
00170 tup5.farray( 'vct2' , v2 , 'len2' , 70 )
00171
00172 tup5.write ()
00173
00174
00175
00176
00177 tup6 = TupleUtils.nTuple( "another/path" ,
00178 "xTuple" ,
00179 "N-tuple: FixArrays" ,
00180 LUN = 'MYLUN2' )
00181
00182 Gaudi = GaudiPython.gbl.Gaudi
00183
00184 for i in xrange(0,10) :
00185
00186 v1=vct1()
00187 for j in range(0,5) : v1.push_back( gauss() )
00188 tup6.array ( "v1" , v1 )
00189
00190 v2=vct2( 10 )
00191 tup6.array ( "v2" , v2 )
00192
00193 v3= Gaudi.Vector2()
00194 tup6.array ( "v3" , v3 )
00195
00196 v4= Gaudi.Vector3()
00197 tup6.array ( "v4" , v4 )
00198
00199
00200 v5= Gaudi.Vector4()
00201 tup6.array ( "v5" , v5 )
00202
00203 v6= Gaudi.Vector5()
00204 tup6.array ( "v6" , v6 )
00205
00206 v7= Gaudi.Vector6()
00207 tup6.array ( "v7" , v7 )
00208
00209 v8= Gaudi.Vector7()
00210 tup6.array ( "v8" , v8 )
00211
00212 tup6.write ()
00213
00214
00215 tup7 = TupleUtils.nTuple( "another/path" ,
00216 "FixMatrices" ,
00217 "N-tuple: FixMatrices" ,
00218 LUN = 'MYLUN3' )
00219
00220 for i in xrange(0,100) :
00221
00222 m2 = Gaudi.Matrix2x2()
00223 tup7.matrix ( "m2" , m2 )
00224
00225 m3 = Gaudi.Matrix3x3()
00226 tup7.matrix ( "m3" , m3 )
00227
00228 m4 = Gaudi.Matrix4x4()
00229 tup7.matrix ( "m4" , m4 )
00230
00231 m5 = Gaudi.Matrix5x5()
00232 tup7.matrix ( "m5" , m5 )
00233
00234 m6 = Gaudi.Matrix6x6()
00235 tup7.matrix ( "m6" , m6 )
00236
00237 m7 = Gaudi.Matrix7x7()
00238 tup7.matrix ( "m7" , m7 )
00239
00240 tup7.write ()
00241
00242
00243 tup8 = TupleUtils.nTuple( "another/path" ,
00244 "FixSymMatrices" ,
00245 "N-tuple: FixSymMatrices" ,
00246 LUN = 'MYLUN2' )
00247
00248 for i in xrange(0,100) :
00249
00250 m2 = Gaudi.SymMatrix2x2()
00251 tup8.matrix ( "m2" , m2 )
00252
00253 m3 = Gaudi.SymMatrix3x3()
00254 tup8.matrix ( "m3" , m3 )
00255
00256 m4 = Gaudi.SymMatrix4x4()
00257 tup8.matrix ( "m4" , m4 )
00258
00259 m5 = Gaudi.SymMatrix5x5()
00260 tup8.matrix ( "m5" , m5 )
00261
00262 m6 = Gaudi.SymMatrix6x6()
00263 tup8.matrix ( "m6" , m6 )
00264
00265 m7 = Gaudi.SymMatrix7x7()
00266 tup8.matrix ( "m7" , m7 )
00267
00268 tup8.write ()
00269
00270
00271
00272
00273 TupleUtils.releaseTuples ()
00274
00275
00276
00277
00278