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

In This Package:

TupleEx1.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # =============================================================================
00003 # $Id: TupleEx1.py,v 1.12 2007/10/29 14:29:47 mato Exp $
00004 # =============================================================================
00005 # CVS tag $Name: GAUDI_v20r4-pre $ , version $Revision: 1.12 $
00006 # =============================================================================
00007 ## @file
00008 #
00009 #  Simple example which illustrate the usage of useful                         
00010 #  algorithm  base class for N-Tuple manipulations                             
00011 #
00012 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00013 #  @date 2006-11-26
00014 # =============================================================================
00015 """
00016 *******************************************************************************
00017 *                                                                             *
00018 * Simple example which illustrate the usage of useful                         *
00019 * algorithm  base class for N-Tuple manipulations                             *
00020 *                                                                             *
00021 *******************************************************************************
00022 """
00023 # =============================================================================
00024 __author__ = 'Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr'
00025 # =============================================================================
00026 
00027 import GaudiPython, math 
00028 
00029 SUCCESS = GaudiPython.SUCCESS 
00030 
00031 # random numbewrs 
00032 Rndm    = GaudiPython.gbl.Rndm
00033 Numbers = Rndm.Numbers
00034 
00035 from   GaudiPython.GaudiAlgs   import TupleAlgo, mapvct
00036 
00037 # =============================================================================
00038 ## Primitive function which transform arbitrary sequence  into
00039 #  GaudiPython.Vector ( std::vector<double> )
00040 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00041 #  @date 2006-11-26
00042 def vct( sequence ) :
00043     """
00044     Primitive function which transform arbitrary sequence  into
00045     GaudiPython.Vector ( std::vector<double> )
00046     """
00047     result = GaudiPython.gbl.GaudiPython.Vector()
00048     if   hasattr( sequence , '__len__' ) : result.reserve ( len(sequence)   )
00049     elif hasattr( sequence , 'size'    ) : result.reserve ( sequence.size() )
00050         
00051     for item in sequence : result.push_back( item )
00052     return result 
00053     
00054 # =============================================================================
00055 ## @class TupleEx1
00056 #  Simple algorithm which book&fill 3 histograms
00057 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00058 #  @date 2006-11-26
00059 class TupleEx1(TupleAlgo) :
00060     """
00061     Simple algorithm which implicitely book&fill N-Tuples
00062     """
00063     ## the main executiomethod 
00064     def execute( self ) :
00065         """
00066         The major method 'execute', it is invoked for each event
00067         """
00068         
00069         rSvc    = self.randSvc() 
00070         gauss   = Numbers ( rSvc , Rndm.Gauss        (   0.0 ,   1.0  ) )
00071         flat    = Numbers ( rSvc , Rndm.Flat         ( -10   ,  10    ) )
00072         expo    = Numbers ( rSvc , Rndm.Exponential  (   1.0          ) )
00073         breit   = Numbers ( rSvc , Rndm.BreitWigner  (   0.0 ,   1.0  ) )
00074         poisson = Numbers ( rSvc , Rndm.Poisson      (   2.0          ) )
00075         binom   = Numbers ( rSvc , Rndm.Binomial     (   8   ,   0.25 ) )
00076 
00077         # =====================================================================
00078         # primitive row-wise n-tuple 
00079         # =====================================================================
00080         tuple1  = self.nTuple ( 1 , "Trivial Row-Wise Tuple" , 42 )
00081 
00082         # fill N-Tuple with double/float numbers:
00083         tuple1 . column ( 'gauss' , gauss () )
00084         tuple1 . column ( 'flat'  , flat  () )
00085         tuple1 . column ( 'expo'  , expo  () )
00086         tuple1 . column ( 'breit' , breit () )
00087         
00088         # fill N-Tuple with integer numbers:
00089         tuple1 . column ( 'poiss' , int( poisson () ) )
00090         tuple1 . column ( 'binom' , int( binom   () ) )
00091 
00092         # fill N-Tuple with "reduced" integer numbers:
00093         tuple1 . column ( 'poiss' , int( poisson () ) , 0 , 14 )
00094         tuple1 . column ( 'binom' , int( binom   () ) , 0 , 14 )
00095         
00096         # fill N-Tuple with "boolean" numbers:
00097         tuple1 . column ( "poisb" ,  poisson () > 1.0 ) 
00098 
00099         # commit the row 
00100         tuple1 . write() 
00101 
00102         # =====================================================================
00103         # the same n-tuple but column-wise  
00104         # =====================================================================
00105         tuple2  = self.nTuple ( 2 , "Trivial Column-Wise Tuple" )
00106 
00107         # fill N-Tuple with double/float numbers:
00108         tuple2 . column ( 'gauss' , gauss () )
00109         tuple2 . column ( 'flat'  , flat  () )
00110         tuple2 . column ( 'expo'  , expo  () )
00111         tuple2 . column ( 'breit' , breit () )
00112         
00113         # fill N-Tuple with integer numbers:
00114         tuple2 . column ( 'poiss' , int( poisson () ) )
00115         tuple2 . column ( 'binom' , int( binom   () ) )
00116         # fill N-Tuple with "reduced" integer numbers:
00117         tuple2 . column ( 'poiss' , int( poisson () ) , 0 , 14 )
00118         tuple2 . column ( 'binom' , int( binom   () ) , 0 , 14 )
00119 
00120         # fill N-Tuple with "boolean" numbers:
00121         tuple2 . column ( "poisb" ,  poisson () > 1.0 ) 
00122 
00123         # commit the row 
00124         tuple2 . write() 
00125 
00126         # =====================================================================
00127         # book and fill Column-wise NTuple with "fixed"-size arrays/vectors
00128         # =====================================================================
00129         tuple3 = self.nTuple ( 3 , "Fixed-size arrays/vectors" ) 
00130 
00131         tuple3.array ( 'arflat' , vct( [ flat () for i in xrange(0,50) ] ) )
00132         tuple3.array ( 'arexpo' , vct( [ expo () for i in xrange(0,62) ] ) )
00133         tuple3.array ( 'argau'  , vct( [ gauss() for i in xrange(0,42) ] ) )
00134         t=tuple([ gauss() for i in xrange(0,42) ])
00135         tuple3.array ( 'argau2' , vct( t ) )
00136         
00137         tuple3.write()
00138         
00139         return SUCCESS
00140                 
00141                 
00142 # =============================================================================
00143 ## job configuration 
00144 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00145 #  @date 2006-11-26
00146 def configure( gaudi = None  ) :
00147     """ Configuration of the job """
00148     
00149     if not gaudi : gaudi = GaudiPython.AppMgr()
00150     
00151     gaudi.JobOptionsType       = 'NONE'
00152     gaudi.EvtSel               = 'NONE'
00153     gaudi.HistogramPersistency = 'ROOT'
00154 
00155     gaudi.ExtSvc += ["NTupleSvc" ]
00156 
00157     ntSvc = gaudi.service('NTupleSvc')
00158     ntSvc.Output = [ "MYLUN DATAFILE='TupleEx1.root' OPT='NEW' TYP='ROOT'" ] 
00159 
00160     gaudi.config()
00161     
00162     gaudi.DLLs = [ 'GaudiAlg', 'RootHistCnv', ]
00163 
00164     alg = TupleEx1('TupleEx1')
00165     gaudi.setAlgorithms( [alg] )
00166 
00167     ## configure the properties 
00168     alg.NTupleLUN = 'MYLUN'
00169     
00170     return SUCCESS
00171 
00172 
00173 # =============================================================================
00174 ## The actual job excution 
00175 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00176 #  @date 2006-11-26
00177 if '__main__' == __name__ :
00178     print __doc__
00179     gaudi = GaudiPython.AppMgr()
00180     configure( gaudi )
00181     gaudi.run(20)
00182     
00183 # =============================================================================
00184 # The END 
00185 # =============================================================================
00186 
| 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