| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

TupleEx4.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # =============================================================================
00003 ## @file
00004 #  Simple exmaple to illustrate the usage ofsmart and friendly
00005 #  N-Tuples outside of algoruthm-scope in "script-like" environment
00006 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00007 #  @date 2007-07-04
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 ## get the application manager   (create if needed) 
00021 gaudi = GaudiPython.AppMgr() 
00022 
00023 
00024 gaudi.EvtSel               = 'NONE' ## no external event input
00025 #gaudi.HistogramPersistency = 'HBOOK' ## define the persistency type for N-tuples
00026 gaudi.HistogramPersistency = 'ROOT' ## define the persistency type for N-tuples
00027 
00028 toolSvc = gaudi.toolsvc()
00029 #print 'tool service: ', toolSvc
00030 
00031 ## configure N-Tuple Service 
00032 ## ntSvc = gaudi.service ( 'NTupleSvc' )
00033 ntSvc = GaudiPython.iService ( 'NTupleSvc' )
00034 ## define 3 output files in 'NEW' mode
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 ## configure & initiliallize 
00040 gaudi.config()
00041 gaudi.initialize()
00042 
00043 ## get some random numbers
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 ## get the first N-tuple
00054 tup1 = TupleUtils.nTuple( "path"             , ## the path 
00055                           "It is a title for my n-tuple" , ## the title 
00056                           LUN = 'MYLUN1'                 ) ## logical unit  
00057 ## fill it:
00058 for i in xrange(0,5000) :
00059     tup1.column ( 'i'  , i           )  ## int 
00060     tup1.column ( 'g1' , gauss()     )  ## double 
00061     tup1.column ( 'g2' , gauss()     )  ## double
00062     b = 0 < gauss() 
00063     tup1.column ( 'b1' , b           )  ## bool 
00064     tup1.write  ()
00065 
00066 
00067 # get some math-stuff
00068 Math = GaudiPython.gbl.ROOT.Math
00069 
00070 ## get the second N-tuple
00071 tup2 = TupleUtils.nTuple( "another/path"                  , ## the path
00072                           "MyTupleLV"                     , ## literal ID 
00073                           "N-tuple: Lorentz Vectors "     , ## the title
00074                           LUN = 'MYLUN1'                  ) ## logical unit  
00075 
00076 ## fill it:
00077 for i in xrange(0,1000) :
00078 
00079     ## Lorentz Vector
00080     lv1 = Math.PxPyPzEVector   ( gauss() , gauss() , gauss() , gauss() )
00081     tup2.column ( "lv1" , lv1 )                              ## Lorentz Vector
00082    
00083     ## Lorentz Vector
00084     lv2 = Math.PtEtaPhiEVector ( gauss() , gauss() , gauss() , gauss() )
00085     tup2.column ( "lv2" , lv2 )                              ## Lorentz Vector
00086 
00087     tup2.write  () 
00088 
00089 
00090 ## get the third N-tuple
00091 tup3 = TupleUtils.nTuple( "another/path"                  , ## the path
00092                           "MyTuple3DV"                    , ## literal ID 
00093                           "N-tuple: 3D-Vectors "          , ## the title
00094                           LUN = 'MYLUN2'                  ) ## logical unit  
00095 
00096 ## fill it:
00097 for i in xrange(0,1000) :
00098 
00099     ## 3D-Vector
00100     v1 = Math.XYZVector( gauss() , gauss() , gauss() )
00101     tup3.column ( "v1" , v1 )                                ## 3D-Vector
00102 
00103     ## 3D-Vector
00104     v2 = Math.Polar3DVector( gauss() , gauss() , gauss() )
00105     tup3.column ( "v2" , v2 )                                ## 3D-Vector
00106     
00107     ## 3D-Vector
00108     v3 = Math.RhoEtaPhiVector( gauss() , gauss() , gauss() )
00109     tup3.column ( "v3" , v3 )                                ## 3D-Vector
00110     
00111     ## 3D-Vector
00112     v4 = Math.RhoZPhiVector( gauss() , gauss() , gauss() )
00113     tup3.column ( "v4" , v4 )                                ## 3D-Vector
00114 
00115     tup3.write  () 
00116 
00117 
00118 ## get the fourth N-tuple
00119 tup4 = TupleUtils.nTuple( "another/path"                  , ## the path
00120                           "MyTuple3DP"                    , ## literal ID 
00121                           "N-tuple: 3D-Points"            , ## the title
00122                           LUN = 'MYLUN3'                  ) ## logical unit  
00123 
00124 ## fill it:
00125 for i in xrange(0,1000) :
00126     
00127     ## 3D-Point
00128     p1 = Math.XYZPoint( gauss() , gauss() , gauss() )
00129     tup4.column ( "p1" , p1 )                                ## 3D-Point
00130     
00131     ## 3D-Point
00132     p2 = Math.Polar3DPoint( gauss() , gauss() , gauss() )
00133     tup4.column ( "p2" , p2 )                                ## 3D-Point
00134 
00135     ## 3D-Point
00136     p3 = Math.RhoEtaPhiPoint( gauss() , gauss() , gauss() )
00137     tup4.column ( "p3" , p3 )                               ## 3D-Point
00138 
00139     ## 3D-Point
00140     p4 = Math.RhoZPhiPoint( gauss() , gauss() , gauss() )
00141     tup4.column ( "p4" , p4 )                               ## 3D-Point
00142     
00143     tup4.write  ()
00144 
00145 
00146 ## get the 5th N-tuple
00147 tup5 = TupleUtils.nTuple( "another/path"                  , ## the path
00148                           415                             , ## integer ID 
00149                           "N-tuple: VarArrays"            , ## the title
00150                           LUN = 'MYLUN1'                  ) ## logical unit
00151 
00152 vct1 = GaudiPython.gbl.vector('double')
00153 GaudiPython.loaddict('CLHEPRflx')
00154 vct2 = GaudiPython.gbl.CLHEP.HepVector
00155 
00156 ## fill it!
00157 for i in xrange ( 0 , 100 ) :
00158 
00159     ## variable size vector:
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 )  ## std::vector<double> 
00166 
00167     n2=min(50,max(5,long(50+25*gauss())))
00168     v2 = vct2(n2)
00169     
00170     tup5.farray( 'vct2' , v2 , 'len2' , 70 )   ## CLHEP::HepVector<double> 
00171 
00172     tup5.write ()
00173 
00174 
00175 
00176 ## get the 6th N-tuple
00177 tup6 = TupleUtils.nTuple( "another/path"                  , ## the path
00178                           "xTuple"                        , ## literal ID 
00179                           "N-tuple: FixArrays"            , ## the title
00180                           LUN = 'MYLUN2'                  ) ## logical unit
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 )                           ## std::vector<double>
00189 
00190     v2=vct2( 10 )
00191     tup6.array ( "v2" , v2 )                           ## CLHEP::HepVector<double>
00192 
00193     v3= Gaudi.Vector2()
00194     tup6.array ( "v3" , v3 )                           ## Gaudi::Vector2 
00195 
00196     v4= Gaudi.Vector3()
00197     tup6.array ( "v4" , v4 )                           ## Gaudi::Vector3 
00198 
00199     
00200     v5= Gaudi.Vector4()
00201     tup6.array ( "v5" , v5 )                           ## Gaudi::Vector4 
00202 
00203     v6= Gaudi.Vector5()
00204     tup6.array ( "v6" , v6 )                           ## Gaudi::Vector5 
00205 
00206     v7= Gaudi.Vector6()
00207     tup6.array ( "v7" , v7 )                           ## Gaudi::Vector6 
00208 
00209     v8= Gaudi.Vector7()
00210     tup6.array ( "v8" , v8 )                           ## Gaudi::Vector7 
00211 
00212     tup6.write ()
00213 
00214 ## get the 7th N-tuple
00215 tup7 = TupleUtils.nTuple( "another/path"                  , ## the path
00216                           "FixMatrices"                   , ## literal ID 
00217                           "N-tuple: FixMatrices"          , ## the title
00218                           LUN = 'MYLUN3'                  ) ## logical unit
00219 
00220 for i in xrange(0,100) :
00221 
00222     m2 = Gaudi.Matrix2x2()
00223     tup7.matrix ( "m2" , m2 )                            ## Gaudi::Matrix2x2
00224 
00225     m3 = Gaudi.Matrix3x3()
00226     tup7.matrix ( "m3" , m3 )                            ## Gaudi::Matrix3x3
00227     
00228     m4 = Gaudi.Matrix4x4()
00229     tup7.matrix ( "m4" , m4 )                            ## Gaudi::Matrix4x4
00230     
00231     m5 = Gaudi.Matrix5x5()
00232     tup7.matrix ( "m5" , m5 )                            ## Gaudi::Matrix5x5
00233 
00234     m6 = Gaudi.Matrix6x6()
00235     tup7.matrix ( "m6" , m6 )                            ## Gaudi::Matrix6x6
00236 
00237     m7 = Gaudi.Matrix7x7()
00238     tup7.matrix ( "m7" , m7 )                            ## Gaudi::Matrix7x7
00239     
00240     tup7.write () 
00241 
00242 ## get the 8th N-tuple
00243 tup8 = TupleUtils.nTuple( "another/path"                  , ## the path
00244                           "FixSymMatrices"                , ## literal ID 
00245                           "N-tuple: FixSymMatrices"       , ## the title
00246                           LUN = 'MYLUN2'                  ) ## logical unit
00247 
00248 for i in xrange(0,100) :
00249 
00250     m2 = Gaudi.SymMatrix2x2()
00251     tup8.matrix ( "m2" , m2 )                            ## Gaudi::SymMatrix2x2
00252 
00253     m3 = Gaudi.SymMatrix3x3()
00254     tup8.matrix ( "m3" , m3 )                            ## Gaudi::SymMatrix3x3
00255     
00256     m4 = Gaudi.SymMatrix4x4()
00257     tup8.matrix ( "m4" , m4 )                            ## Gaudi::SymMatrix4x4
00258     
00259     m5 = Gaudi.SymMatrix5x5()
00260     tup8.matrix ( "m5" , m5 )                            ## Gaudi::SymMatrix5x5
00261 
00262     m6 = Gaudi.SymMatrix6x6()
00263     tup8.matrix ( "m6" , m6 )                            ## Gaudi::SymMatrix6x6
00264 
00265     m7 = Gaudi.SymMatrix7x7()
00266     tup8.matrix ( "m7" , m7 )                            ## Gaudi::SymMatrix7x7
00267     
00268     tup8.write () 
00269 
00270 
00271 
00272 ## release all tuples at the end 
00273 TupleUtils.releaseTuples ()
00274 
00275 
00276 # =============================================================================
00277 # The END
00278 # =============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:59:39 2011 for GaudiExamples by doxygen 1.4.7