00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00032 Rndm = GaudiPython.gbl.Rndm
00033 Numbers = Rndm.Numbers
00034
00035 from GaudiPython.GaudiAlgs import TupleAlgo, mapvct
00036
00037
00038
00039
00040
00041
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
00056
00057
00058
00059 class TupleEx1(TupleAlgo) :
00060 """
00061 Simple algorithm which implicitely book&fill N-Tuples
00062 """
00063
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
00079
00080 tuple1 = self.nTuple ( 1 , "Trivial Row-Wise Tuple" , 42 )
00081
00082
00083 tuple1 . column ( 'gauss' , gauss () )
00084 tuple1 . column ( 'flat' , flat () )
00085 tuple1 . column ( 'expo' , expo () )
00086 tuple1 . column ( 'breit' , breit () )
00087
00088
00089 tuple1 . column ( 'poiss' , int( poisson () ) )
00090 tuple1 . column ( 'binom' , int( binom () ) )
00091
00092
00093 tuple1 . column ( 'poiss' , int( poisson () ) , 0 , 14 )
00094 tuple1 . column ( 'binom' , int( binom () ) , 0 , 14 )
00095
00096
00097 tuple1 . column ( "poisb" , poisson () > 1.0 )
00098
00099
00100 tuple1 . write()
00101
00102
00103
00104
00105 tuple2 = self.nTuple ( 2 , "Trivial Column-Wise Tuple" )
00106
00107
00108 tuple2 . column ( 'gauss' , gauss () )
00109 tuple2 . column ( 'flat' , flat () )
00110 tuple2 . column ( 'expo' , expo () )
00111 tuple2 . column ( 'breit' , breit () )
00112
00113
00114 tuple2 . column ( 'poiss' , int( poisson () ) )
00115 tuple2 . column ( 'binom' , int( binom () ) )
00116
00117 tuple2 . column ( 'poiss' , int( poisson () ) , 0 , 14 )
00118 tuple2 . column ( 'binom' , int( binom () ) , 0 , 14 )
00119
00120
00121 tuple2 . column ( "poisb" , poisson () > 1.0 )
00122
00123
00124 tuple2 . write()
00125
00126
00127
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
00144
00145
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
00168 alg.NTupleLUN = 'MYLUN'
00169
00170 return SUCCESS
00171
00172
00173
00174
00175
00176
00177 if '__main__' == __name__ :
00178 print __doc__
00179 gaudi = GaudiPython.AppMgr()
00180 configure( gaudi )
00181 gaudi.run(20)
00182
00183
00184
00185
00186