00001
00002
00003
00004
00005 """
00006 *******************************************************************************
00007 * *
00008 * Simple example which illustrates the usage of the useful base class *
00009 * GaudiAlgo (python version of C++ GaudiAlgorithm) for "easy" manipulations *
00010 * with 'counters' *
00011 * *
00012 * The example is equivalent to C++ example 'CounterEx', see *
00013 * $GAUDIEXAMPLESROOT/src/CounterEx/*.cpp and *
00014 * $GAUDIEXAMPLESROOT/options/CounterEx.opts *
00015 * *
00016 *******************************************************************************
00017 """
00018
00019 __author__ = 'Vanya BELYAEV Ivan.Belyaev@lapp.in2p3.fr'
00020
00021
00022 import GaudiPython
00023
00024 from GaudiPython.GaudiAlgs import GaudiAlgo
00025
00026 Rndm = GaudiPython.gbl.Rndm
00027 Numbers = Rndm.Numbers
00028 SUCCESS = GaudiPython.SUCCESS
00029
00030 Numbers.__call__ = Numbers.shoot
00031
00032
00033
00034
00035 class Counter(GaudiAlgo) :
00036 """ Simple algorithm which manipulates with counters """
00037 def __init__ ( self , name = 'Counter' ) :
00038 """ Constructor """
00039 GaudiAlgo.__init__( self , name )
00040
00041 def execute( self ) :
00042 """ The major method 'execute', it is invoked for each event """
00043
00044 executed = self.counter('executed')
00045 executed += 1.
00046
00047 gauss = Numbers( self.randSvc() , Rndm.Gauss ( 0.0 ,1.0 ) )
00048 poisson = Numbers( self.randSvc() , Rndm.Poisson ( 5.0 ) )
00049
00050
00051 value = gauss.shoot()
00052
00053 g1 = self.counter('gauss')
00054 g2 = self.counter('g2')
00055
00056 g1 += value
00057 g2 += value * value
00058
00059 if 0 < value :
00060 gp = self.counter('Gpos')
00061 gp += 1.
00062 else :
00063 gn = self.counter('Gneg')
00064 gn += 1.
00065
00066 stat1 = self.counter('NG')
00067 stat2 = self.counter('G')
00068 for i in range ( 0, int( poisson() ) ) :
00069 stat1 += 1.
00070 stat2 += gauss()
00071
00072 stat3 = self.counter('eff')
00073 stat3 += value>0
00074
00075
00076 executed = self.counter('executed')
00077 prnt = int( executed.flag() )
00078 if 0 == prnt%1000 :
00079 print " Event number %s " % prnt
00080 self.printStat()
00081 bc = self.counter('eff')
00082 line = "(%s += %s)%s"%(bc.eff()*100,bc.effErr()*100,'%')
00083 print ' Efficiency (binomial counter "eff"): %s'%line
00084
00085 return SUCCESS
00086
00087
00088
00089
00090
00091 def configure( gaudi = None ) :
00092 """ Configuration of the job """
00093
00094 if not gaudi : gaudi = GaudiPython.AppMgr()
00095
00096 gaudi.JobOptionsType = 'NONE'
00097 gaudi.EvtSel = 'NONE'
00098
00099 gaudi.config()
00100
00101 alg = Counter()
00102 gaudi.setAlgorithms( [alg] )
00103
00104
00105 alg.StatPrint = True
00106
00107 return SUCCESS
00108
00109
00110
00111
00112 if '__main__' == __name__ :
00113 print __doc__ , __author__
00114 gaudi = GaudiPython.AppMgr()
00115 configure( gaudi )
00116 gaudi.run(5400)
00117
00118
00119
00120