Gaudi Framework, version v21r4

Home   Generated: 7 Sep 2009

HistoUtils.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # =============================================================================
00003 ##  This module contains set of simple and useful utilities for booking and  
00004 #   manipulations with Gaudi-AIDA histograms, inspired by Thomas' request
00005 #   @author Vanya BELYAEV ibelyaev@physics.syr.edu
00006 #   @date 2007-08-03
00007 # =============================================================================
00008 """
00009 This module contains set of simple and useful utilities for booking and
00010 manipulations with Gaudi-AIDA histograms, inspired by Thomas' request
00011 
00012 The module contains following public symbols:
00013 
00014   - book       for booking of various 1D,2D&3D-histograms 
00015   - bookProf   for booking of various 1D&2D-profiles 
00016   - getAsAIDA  for retrieval of histograms/profiles from HTS in AIDA format
00017   - getAsROOT  for retrieval of histograms/profiles from HTS in ROOT format 
00018   - fill       for smart filling of 1D-histogram (AIDA or ROOT)
00019   - aida2root  for conversion of AIDA histogram to ROOT
00020   - HistoStats for many statistical information
00021   - HistoFile  class for storing histograms to a file
00022 
00023 """
00024 # =============================================================================
00025 __author__ = "Vanya BELYAEV ibelyaev@physics.syr.edu"
00026 # =============================================================================
00027 __all__    = (
00028     'book'      , ##                book AIDA histogram using Histogram Service
00029     'bookProf'  , ##        book AIDA profile histogram using Histogram Service
00030     'getAsAIDA' , ## get the histogram form Histogram Service as AIDA histogram
00031     'getAsROOT' , ## get the histogram form Histogram Service as AIDA histogram
00032     'fill'      , ##              "power-fill" method for filling of histograms
00033     'aida2root' , ##                                     AIDA -> ROOT converter
00034     'HistoStats'  ##                  statistical information for 1D-histograms
00035     'HistoFile'   ##                     class for storing histograms to a file
00036     )
00037 # =============================================================================
00038 ## import core of Gaudi
00039 from GaudiPython.Bindings import AppMgr
00040 from GaudiPython.Bindings import iHistogramSvc
00041 from GaudiPython.Bindings import gbl as cpp
00042 HID = cpp.GaudiAlg.ID
00043 
00044 # =============================================================================
00045 ## Helper private auxiliary function to get Application Manager 
00046 def _getAppMgr   ( **kwargs  ) :
00047     """
00048     Helper private auxiliary function to get Application Manager
00049     """
00050     gaudi = kwargs.get ( 'gaudi' , None )
00051     if not gaudi : gaudi = AppMgr() 
00052     if not gaudi : raise RuntimeError, 'Unable to get valid ApplicationMgr'
00053     return gaudi                                               ## RETURN
00054 
00055 # =============================================================================    
00056 ## Helper private auxiliary function to get iHistogramSvs 
00057 def _getHistoSvc ( **kwargs ) :
00058     """
00059     Helper private auxiliary function to get iHistogramSvs
00060     """ 
00061     svc = kwargs.get ( 'service' , None )
00062     if not svc : svc = kwargs.get ( 'svc' , None )
00063     else       : return svc                                    ## RETURN 
00064     gaudi = _getAppMgr ( **kwargs ) 
00065     return gaudi.histsvc ()                                    ## RETURN
00066 
00067 # =============================================================================
00068 ## Helper private auxiliary function to get iDataSvs 
00069 def _getEvtSvc ( **kwargs ) :
00070     """
00071     Helper private auxiliary function to get iDataSvs
00072     """ 
00073     svc = kwargs.get ( 'service' , None )
00074     if not svc : svc = kwargs.get ( 'svc' , None )
00075     else       : return svc                                    ## RETURN 
00076     gaudi = _getAppMgr ( **kwargs ) 
00077     return gaudi.evtsvc()                                      ## RETURN
00078     
00079 # =============================================================================
00080 ## The trivial function to book the various 1D,2D&3D-histograms
00081 def book ( *args , **kwargs ) :
00082     """
00083     The trivial function to book the various 1D,2D&3D-histograms
00084 
00085     (1) book the trivial 1D histogram with full path
00086     
00087     >>> h1D = book ( 'path/to/my/histo'       , ## path in Histogram Transient Store
00088                      'cosine of decay angle ' , ## histogram title 
00089                       100                     , ## number of bins 
00090                       -1                      , ## low edge
00091                       100                     ) ## high edge
00092                       
00093     (2) book the trivial 1D histogram with directory path and string ID :
00094     
00095     >>> h1D = book ( 'path/to/directory'      , ## the path to directory in HTS
00096                      'H1'                     , ## string histogram identifier
00097                      'cosine of decay angle ' , ## histogram title 
00098                       100                     , ## number of bins 
00099                       -1                      , ## low edge
00100                       100                     ) ## high edge                     
00101                           
00102     (3) book the trivial 1D histogram with directory path and integer ID :
00103     
00104     >>> h1D = book ( 'path/to/directory'      , ## the path to directory in HTS
00105                      124                      , ## integer histogram identifier
00106                      'cosine of decay angle ' , ## histogram title 
00107                       100                     , ## number of bins 
00108                       -1                      , ## low edge
00109                       100                     ) ## high edge
00110 
00111     (4) book the trivial 2D histogram with full path
00112     
00113     >>> h1D = book ( 'path/to/my/histo'       , ## path in Histogram Transient Store
00114                      'm12**2 versus m13**2'   , ## histogram title 
00115                       50                      , ## number of X-bins 
00116                       1.0                     , ## low X-edge
00117                       4.0                     , ## high X-edge
00118                       50                      , ## number of Y-bins 
00119                       1                       , ## low Y-edge
00120                       2                       ) ## high Y-edge                      
00121 
00122     (5) book the trivial 2D histogram with directory path and literal ID 
00123     
00124     >>> h1D = book ( 'path/to/directory'      , ## path in Histogram Transient Store
00125                      'Dalitz1'                , ## literal histogram identifier 
00126                      'm12**2 versus m13**2'   , ## histogram title 
00127                       50                      , ## number of X-bins 
00128                       1.0                     , ## low X-edge
00129                       4.0                     , ## high X-edge
00130                       50                      , ## number of Y-bins 
00131                       1                       , ## low Y-edge
00132                       2                       ) ## high Y-edge
00133                       
00134     (6) book the trivial 2D histogram with directory path and integer ID 
00135     
00136     >>> h1D = book ( 'path/to/directory'      , ## path in Histogram Transient Store
00137                      854                      , ## integer histogram identifier 
00138                      'm12**2 versus m13**2'   , ## histogram title 
00139                       50                      , ## number of X-bins 
00140                       1.0                     , ## low X-edge
00141                       4.0                     , ## high X-edge
00142                       50                      , ## number of Y-bins 
00143                       1.0                     , ## low Y-edge
00144                       4.0                     ) ## high Y-edge
00145                       
00146     (7) book the trivial 3D histogram with full path
00147     
00148     >>> h1D = book ( 'path/to/my/histo'       , ## path in Histogram Transient Store
00149                      'x vs y vs z '           , ## histogram title 
00150                       10                      , ## number of X-bins 
00151                       -1.0                    , ## low X-edge
00152                       1.0                     , ## high X-edge
00153                       10                      , ## number of Y-bins 
00154                       -1.0                    , ## low Y-edge
00155                       1.0                     , ## high Y-edge
00156                       10                      , ## number of Z-bins 
00157                       -1.0                    , ## low Z-edge
00158                       1.0                     ) ## high Z-edge                  
00159 
00160     (8) book the trivial 3D histogram with directory path and literal ID 
00161     
00162     >>> h1D = book ( 'path/to/directory'      , ## path in Histogram Transient Store
00163                      'xyz'                    , ## literal histogram identifier 
00164                      'x vs y vs z'            , ## histogram title 
00165                       10                      , ## number of X-bins 
00166                       -1.0                    , ## low X-edge
00167                       1.0                     , ## high X-edge
00168                       10                      , ## number of Y-bins 
00169                       -1.0                    , ## low Y-edge
00170                       1.0                     , ## high Y-edge
00171                       10                      , ## number of Z-bins 
00172                       -1.0                    , ## low Z-edge
00173                       1.0                     ) ## high Z-edge
00174 
00175     (9) book the trivial 3D histogram with directory path and integer ID 
00176     
00177     >>> h1D = book ( 'path/to/directory'      , ## path in Histogram Transient Store
00178                      888                      , ## integer histogram identifier 
00179                      'x vs y vs z'            , ## histogram title 
00180                       10                      , ## number of X-bins 
00181                       -1.0                    , ## low X-edge
00182                       1.0                     , ## high X-edge
00183                       10                      , ## number of Y-bins 
00184                       -1.0                    , ## low Y-edge
00185                       1.0                     , ## high Y-edge
00186                       10                      , ## number of Z-bins 
00187                       -1.0                    , ## low Z-edge
00188                       1.0                     ) ## high Z-edge
00189 
00190     Many other booking methods are available,
00191     e.g. for the histograms with non-equidistant bins, see IHistogamSvc::book
00192     
00193     """
00194     svc = _getHistoSvc ( **kwargs )
00195     if not svc : raise RuntimeError, 'Unable to get valid HistogramService '
00196     ## book the histogram using the service 
00197     return svc.book(*args)                                          ## RETURN
00198 
00199 book.__doc__ += '\n\n' + '\thelp(iHistogramSvc.book) : \n\n' \
00200                 + iHistogramSvc.book       . __doc__ 
00201 book.__doc__ += '\n\n' + '\thelp(IHistogramSvc::book) : \n\n'            \
00202                 + cpp.IHistogramSvc.book . __doc__
00203 
00204 # =============================================================================
00205 ## The trivial function to book 1D&2D profile histograms:
00206 def bookProf ( *args , **kwargs ) :
00207     """
00208     
00209     The trivial function to book 1D&2D profile histograms:
00210 
00211     (1) book 1D-profile histogram with full path in Histogram Transient Store:
00212     >>> histo = bookProf ( 'path/to/my/profile'  , ## path in Histogram Transient Store
00213                            'Energy Correction'   , ## the histogram title
00214                            100                   , ## number of X-bins
00215                            0.0                   , ## low X-edge
00216                            100                   ) ## high X-edge
00217     
00218     (2) book 1D-profile histogram with directory path and literal ID 
00219     >>> histo = bookProf ( 'path/to/my/profile'  , ## path in Histogram Transient Store
00220                            'Calibration'         , ## the histogram literal identifier
00221                            'Energy Correction'   , ## the histogram title
00222                            100                   , ## number of X-bins
00223                            0.0                   , ## low X-edge
00224                            100                   ) ## high X-edge
00225     
00226     (3) book 1D-profile histogram with directory path and integer  ID 
00227     >>> histo = bookProf ( 'path/to/my/profile'  , ## path in Histogram Transient Store
00228                            418                   , ## the histogram integer identifier 
00229                            'Energy Correction'   , ## the histogram title
00230                            100                   , ## number of X-bins
00231                            0.0                   , ## low X-edge
00232                            100                   ) ## high X-edge
00233 
00234     (4) book 2D-profile histogram with full path in Histogram Transient Store:
00235     >>> histo = bookProf ( 'path/to/my/profile'  , ## path in Histogram Transient Store
00236                            'Energy Correction'   , ## the histogram title
00237                            50                    , ## number of X-bins
00238                            0.0                   , ## low X-edge
00239                            100                   , ## high X-edge
00240                            50                    , ## number of Y-bins
00241                            0.0                   , ## low Y-edge
00242                            100                   ) ## high Y-edge
00243     
00244     (5) book 2D-profile histogram with directory path and literal ID 
00245     >>> histo = bookProf ( 'path/to/my/profile'  , ## path in Histogram Transient Store
00246                            'Calibration'         , ## the histogram literal identifier
00247                            'Energy Correction'   , ## the histogram title
00248                            50                    , ## number of X-bins
00249                            0.0                   , ## low X-edge
00250                            100                   , ## high X-edge
00251                            50                    , ## number of Y-bins
00252                            0.0                   , ## low Y-edge
00253                            100                   ) ## high Y-edge
00254     
00255     (6) book 2D-profile histogram with directory path and integer  ID 
00256     >>> histo = bookProf ( 'path/to/my/profile'  , ## path in Histogram Transient Store
00257                            418                   , ## the histogram integer identifier 
00258                            'Energy Correction'   , ## the histogram title
00259                            50                    , ## number of X-bins
00260                            0.0                   , ## low X-edge
00261                            100                   , ## high X-edge
00262                            50                    , ## number of Y-bins
00263                            0.0                   , ## low Y-edge
00264                            100                   ) ## high Y-edge
00265     
00266     Many other booking methods are available,
00267     e.g. for the histograms with non-equidistant bins, see IHistogamSvc::book
00268     
00269     """
00270     svc = _getHistoSvc ( **kwargs )
00271     if not svc : raise RuntimeError, 'Unable to get valid HistogramService '
00272     ## book the histogram using the service 
00273     return svc.bookProf(*args)                                      ## RETURN
00274 
00275 
00276 bookProf.__doc__ += '\n\n' + '\thelp(iHistogramSvc.bookProf) : \n\n' \
00277                     + iHistogramSvc.bookProf . __doc__ 
00278 bookProf.__doc__ += '\n\n' + '\thelp(IHistogramSvc::bookProf) : \n\n'             \
00279                     + cpp.IHistogramSvc.bookProf . __doc__
00280 
00281 # =============================================================================
00282 ## The most trivial function to retrieve the histogram from Histogram Transient Store
00283 def getAsAIDA ( path , **kwargs ) :
00284     """
00285     
00286     The most trivial function to retrieve the histogram from Histogram Transient Store
00287     The histogram is returned by reference to its AIDA-representation (if possible)
00288 
00289     >>> h = getAsAIDA ( 'some/path/to/my/histogram' )
00290     
00291     """
00292     svc = _getHistoSvc ( **kwargs )
00293     if not svc : raise RuntimeError, 'Unable to get valid HistogramService '
00294     ## return the histogram 
00295     return svc.getAsAIDA( path )                                   ## RETURN
00296 
00297 getAsAIDA.__doc__ += '\n\n' + '\thelp(iHistogramSvc.getAsAIDA) : \n\n' \
00298                      + iHistogramSvc.getAsAIDA . __doc__ 
00299 getAsAIDA.__doc__ += '\n\n' + '\thelp(iHistogramSvc.retrieve)  : \n\n' \
00300                      + iHistogramSvc.retrieve  . __doc__ 
00301 
00302 # =============================================================================
00303 ## The most trivial function to retrieve the histogram from Histogram Transient Store
00304 def getAsROOT ( path , **kwargs ) :
00305     """
00306     
00307     The most trivial function to retrieve the histogram from Histogram Transient Store
00308     The histogram is returned by reference to its underlying native ROOT-representation (if possible)
00309     
00310     >>> h = getAsROOT ( 'some/path/to/my/histogram' )
00311     
00312     """
00313     svc = _getHistoSvc ( **kwargs )
00314     if not svc : raise RuntimeError, 'Unable to get valid HistogramService '
00315     ## return the histogram 
00316     return svc.getAsROOT( path )                                   ## RETURN
00317 
00318 getAsROOT.__doc__ += '\n\n' + '\thelp(iHistogramSvc.getAsROOT) : \n\n' \
00319                      + iHistogramSvc.getAsROOT . __doc__ 
00320 
00321 
00322 # =============================================================================
00323 ## The function which allows 'the smart fill' of 1D-histogram
00324 def fill ( histo                   ,   ## histogram 
00325            data                    ,   ## input data 
00326            fun   = lambda x : x    ,   ## function to be used  
00327            cut   = lambda x : True ,   ## cut to be applied
00328            **kwargs                ) : ## optional extra arguments 
00329     """
00330     
00331     The function which allows 'the smart fill' of 1D-histogram
00332 
00333     >>> histo = ...
00334 
00335     The most trivial case, fill with the value 
00336     >>> fill ( histo , 1.0 ) 
00337 
00338     Fill from any iterable object (sequence)
00339     >>> fill ( histo , [1,,2,3,4,5,10] )
00340 
00341     Fill from iterable object and apply the function:
00342     >>> fill ( histo , [1,2,3,4,5] , math.sin )
00343     
00344     Use lambda form:
00345     >>> fill ( histo , [1,2,3,4,5] , lambda x : x*x )
00346 
00347     The same 
00348     >>> fill ( histo , [1,2,3,4,5] , fun = lambda x : x*x )
00349 
00350     Use internal attributes:
00351     >>> tracks = evtSvc['Rec/Track/Best']    ## iterable container of tracks
00352     >>> fill ( histo , tracks , lambda t : t.pt() )
00353 
00354     Apply the predicate: fill only even numbers: 
00355     >>> fill ( histo , [1,2,3,4,5,6,7] , lambda x : x , lambda y : y%2 )
00356 
00357     The same (omit the trivial function) : 
00358     >>> fill ( histo , [1,2,3,4,5,6,7] , cut = lambda y : y%2 )
00359 
00360     Apply the predicate: fill only pt for positively charged tracks:
00361     >>> tracks = evtSvc['Rec/Track/Best']
00362     >>> fill ( histo , tracks , lambda t : t.pt() , lambda t : 0<t.charge() )
00363 
00364     The same: 
00365     >>> fill ( histo , tracks ,
00366                fun = lambda t : t.pt()       ,
00367                cut = lambda t : 0<t.charge() )
00368 
00369     Ordinary functions are also fine:
00370     >>> def myfun ( track ) : return sin( track.pt() + track.p() )
00371     >>> def mycut ( track ) : return track.p() > 100 * GeV 
00372     >>> fill ( histo , tracks , myfun , mycut )
00373         
00374     The 'data' could be the address in TES, in this case the object
00375     is retrieved from TES and the method is applied to the objects,
00376     retrieved from TES:
00377     >>> fill (  histo             , ## the reference to the histogram 
00378                'Rec/Track/Best'   , ## the location of objects in TES
00379                 lambda t : t.pt() ) ## function to be used for histogram fill
00380     >>> fill (  histo             , ## the reference to the histogram
00381                'Rec/Track/Best'   , ## the address of objects in TES
00382                 lambda t : t.pt() , ## the function to be used for histogram fill
00383                 lambda t : t.charge()>0 ) ## the criteria to select tracks 
00384     
00385     The arguments 'fun' and 'cut' could be strings, in this case
00386     they are evaluated by python before usage.
00387     This option could be often very useful.
00388     
00389     """
00390     
00391     # if value is a string, try to get the objects from TES
00392     if type ( data ) == str :
00393         svc  = _getEvtSvc ( **kwargs ) 
00394         data = svc[data]
00395         return fill ( histo , data , fun , cut , **kwargs )
00396     
00397     # if the function  is a string: evaluate it!
00398     if type ( fun  ) == str : fun  = eval ( fun  , globals() )
00399     
00400     # if the criterion is a string: evaluate it!
00401     if type ( cut  ) == str : cut  = eval ( cut  , globals() )
00402 
00403     if not hasattr ( data , '__iter__' ) : data = [ data ]
00404 
00405     if not hasattr ( histo , 'fill' ) and hasattr ( histo , 'Fill' ) :
00406         setattr ( histo , 'fill' , getattr ( histo , 'Fill' ) )
00407     
00408     for item in data :
00409         if not cut ( item )         : continue             ## CONTINUE
00410         histo.fill ( fun ( item ) )
00411         
00412     return histo                                           ## RETURN
00413 
00414 # =============================================================================
00415 ## AIDA -> ROOT converter 
00416 aida2root = cpp.Gaudi.Utils.Aida2ROOT.aida2root
00417 # =============================================================================
00418 ## Convert AIDA to ROOT
00419 def _to_root_ ( self ) :
00420     """
00421     Convert AIDA to ROOT
00422     
00423     >>> aida = ...            ## get AIDA histogram
00424     >>> root = aida.toROOT()  ## convert it to ROOT
00425     
00426     """
00427     return aida2root ( self )
00428 
00429 _to_root_ . __doc__  += aida2root . __doc__
00430 
00431 for t in ( cpp.AIDA.IHistogram3D , cpp.AIDA.IHistogram2D , cpp.AIDA.IHistogram1D ,
00432            cpp.AIDA.IProfile2D   , cpp.AIDA.IProfile1D   ) :
00433     if not hasattr ( t , 'Fill' ) and hasattr ( t , 'fill' ) :
00434         setattr ( t , 'Fill' , getattr ( t , 'fill' ) ) 
00435     for attr in ( 'toROOT' , 'toRoot' ,
00436                   'asROOT' , 'asRoot' , 
00437                   'AsROOT' , 'AsRoot' ) :
00438         if not hasattr ( t , attr ) : setattr ( t , attr , _to_root_ )
00439 
00440 cpp.AIDA.IHistogram3D. __repr__ =  lambda s : cpp.GaudiAlg.Print3D.toString( s , HID( s.title() ) ) 
00441 cpp.AIDA.IHistogram3D. __str__  = cpp.AIDA.IHistogram3D. __repr__  
00442     
00443 
00444 HistoStats = cpp.Gaudi.Utils.HistoStats
00445 
00446 # =============================================================================
00447 ## Evaluate 'bin-by-bin' momentum of certain order around the value
00448 def _moment_ ( self , order , value = 0 ) :
00449     """
00450     Evaluate 'bin-by-bin' momentum of order 'order' around the value 'value'
00451     for 1D histogram 
00452     
00453     >>> h1 = ...
00454     >>> print h1.moment ( 5 )
00455     
00456     """
00457     return HistoStats.moment ( self , order , value ) 
00458 
00459 # =============================================================================
00460 ## Evaluate error in 'bin-by-bin' momentum of certain order around the value
00461 def _momentErr_ ( self , order ) :
00462     """
00463     Evaluate error for 'bin-by-bin' momentum of order 'order' around the value 'value'
00464     for 1D histogram 
00465     
00466     >>> h1 = ...
00467     >>> print h1.momentErr ( 5 )
00468     
00469     """
00470     return HistoStats.momentErr ( self , order ) 
00471 # =============================================================================
00472 ## Evaluate 'bin-by-bin' central momentum (around mean value)
00473 def _centralMoment_ ( self , order ) :
00474     """
00475     Evaluate 'bin-by-bin' central momentum (around mean value) 
00476     for 1D histogram 
00477     
00478     >>> h1 = ...
00479     >>> print h1.centralMoment ( 5 )
00480     
00481     """
00482     return HistoStats.centralMoment ( self , order ) 
00483 
00484 # =============================================================================
00485 ## Evaluate error in 'bin-by-bin' momentum of certain order around the value
00486 def _centralMomentErr_ ( self , order ) :
00487     """
00488     Evaluate error for 'bin-by-bin' central momentum (around mean value)
00489     for 1D histogram 
00490     
00491     >>> h1 = ...
00492     >>> print h1.centralMomentErr ( 5 )
00493     
00494     """
00495     return HistoStats.centralMomentErr ( self , order )
00496 
00497 # =============================================================================
00498 ## Evaluate 'bin-by-bin' skewness for 1D histogram 
00499 def _skewness_ ( self ) :
00500     """
00501     Evaluate 'bin-by-bin' skewness for 1D histogram
00502 
00503     >>> h1 = ...
00504     >>> print h1.skewness()
00505     
00506     """
00507     return HistoStats.skewness ( self )
00508 
00509 # =============================================================================
00510 ## Evaluate error for 'bin-by-bin' skewness for 1D histogram 
00511 def _skewnessErr_ ( self ) :
00512     """
00513     Evaluate error for 'bin-by-bin' skewness for 1D histogram
00514 
00515     >>> h1 = ...
00516     >>> print h1.skewnessErr()
00517     
00518     """
00519     return HistoStats.skewnessErr ( self )
00520 
00521 # =============================================================================
00522 ## Evaluate 'bin-by-bin' kurtosis for 1D histogram 
00523 def _kurtosis_ ( self ) :
00524     """
00525     Evaluate 'bin-by-bin' kurtosis for 1D histogram
00526 
00527     >>> h1 = ...
00528     >>> print h1.kurtosis ()
00529     
00530     """
00531     return HistoStats.kurtosis ( self )
00532 
00533 # =============================================================================
00534 ## Evaluate error for 'bin-by-bin' kurtosis for 1D histogram 
00535 def _kurtosisErr_ ( self ) :
00536     """
00537     Evaluate error for 'bin-by-bin' kurtotis for 1D histogram
00538 
00539     >>> h1 = ...
00540     >>> print h1.kurtotisErr()
00541     
00542     """
00543     return HistoStats.kurtosisErr ( self )
00544 
00545 # =============================================================================
00546 def _nEff_    ( self ) :
00547     """
00548     Number of equivalent entries
00549     """
00550     return HistoStats.nEff ( self )
00551 # =============================================================================
00552 def _mean_    ( self ) :
00553     """
00554     Evaluate the MEAN value
00555     """
00556     return HistoStats.mean ( self )
00557 # =============================================================================
00558 def _meanErr_ ( self ) :
00559     """
00560     Evaluate the error for MEAN estimate
00561     """
00562     return HistoStats.meanErr ( self )
00563 
00564 # =============================================================================
00565 def _rms_    ( self ) :
00566     """
00567     Evaluate the RMS
00568     """
00569     return HistoStats.rms ( self )
00570 # =============================================================================
00571 def _rmsErr_ ( self ) :
00572     """
00573     Evaluate the error for RMS estimate
00574     """
00575     return HistoStats.rmsErr ( self )
00576 
00577 # =============================================================================
00578 def _sumBinHeightErr_    ( self ) :
00579     """
00580     Get an error in the sum bin height ('in-range integral')
00581     """
00582     return HistoStats.sumBinHeightErr ( self )
00583 
00584 # =============================================================================
00585 def _sumAllBinHeightErr_ ( self ) :
00586     """ Get an error in the sum bin height ('in-range integral') """
00587     return HistoStats.sumAllBinHeightErr ( self ) 
00588 
00589 # =============================================================================
00590 def _overflowEntriesFrac_     ( self ) :
00591     """
00592     The fraction of overflow entries  (useful for shape comparison)
00593     """
00594     return HistoStats.overflowEntriesFrac     ( self ) 
00595 # =============================================================================
00596 def _overflowEntriesFracErr_  ( self ) :
00597     """
00598     The error for fraction of overflow entries  (useful for shape comparison)
00599     """
00600     return HistoStats.overflowEntriesFracErr  ( self ) 
00601 # =============================================================================
00602 def _underflowEntriesFrac_    ( self ) :
00603     """
00604     The fraction of underflow entries  (useful for shape comparison)
00605     """
00606     return HistoStats.underflowEntriesFrac    ( self ) 
00607 # =============================================================================
00608 def _underflowEntriesFracErr_ ( self ) :
00609     """
00610     The error for fraction of underflow entries  (useful for shape comparison)
00611     """
00612     return HistoStats.underflowEntriesFracErr ( self ) 
00613 
00614 # =============================================================================
00615 def _overflowIntegralFrac_     ( self ) :
00616     """
00617     The fraction of overflow integral  (useful for shape comparison)
00618     """
00619     return HistoStats.overflowIntegralFrac     ( self ) 
00620 # =============================================================================
00621 def _overflowIntegralFracErr_  ( self ) :
00622     """
00623     The error for fraction of overflow integral  (useful for shape comparison)
00624     """
00625     return HistoStats.overflowIntegralFracErr  ( self ) 
00626 # =============================================================================
00627 def _underflowIntegralFrac_    ( self ) :
00628     """
00629     The fraction of underflow integral  (useful for shape comparison)
00630     """
00631     return HistoStats.underflowIntegralFrac    ( self ) 
00632 # =============================================================================
00633 def _underflowIntegralFracErr_ ( self ) :
00634     """
00635     The error for fraction of underflow integral (useful for shape comparison)
00636     """
00637     return HistoStats.underflowIntegralFracErr ( self ) 
00638 
00639 # =============================================================================
00640 ## get number of entries in histogram up to  the certain bin (not-included)
00641 #  get number of entries in histogram form the certain 
00642 #  minimal bin up to the certain maximal bin (not-included)
00643 def _nEntries_ ( self , i1 , i2 = -10000000 ) :
00644     """
00645     Get number of entries in histogram up to  the certain bin (not-included)
00646     
00647     attention: underflow bin is included!
00648     
00649     >>> h1
00650     >>> print h1.nEntries ( 10 )
00651 
00652     Get number of entries in histogram form the certain 
00653     minimal bin up to the certain maximal bin (not-included)
00654     
00655     >>> h1
00656     >>> print h1.nEntries ( 10 , 15 )
00657     
00658     """
00659     if  i2 < i1 or i2 < 0 : return HistoStats.nEntries ( self , i1 )
00660     return HistoStats.nEntries ( self , i1 , i2 )
00661 # =============================================================================
00662 def _nEntriesFrac_ ( self , i1 , i2 = -10000000 ) :
00663     """
00664     Get the fraction of entries in histogram up to  the certain bin (not-included)
00665     
00666     attention: underflow bin is included!
00667     
00668     >>> h1
00669     >>> print h1.nEntriesFrac ( 10 )
00670     
00671     Get the fraction of entries in histogram form the certain 
00672     minimal bin up to the certain maximal bin (not-included)
00673     
00674     >>> h1
00675     >>> print h1.nEntriesFrac ( 10 , 15 )
00676     
00677     """
00678     if  i2 < i1 or i2 < 0 : return HistoStats.nEntriesFrac ( self , i1 )
00679     return HistoStats.nEntriesFrac ( self , i1 , i2 )
00680 # =============================================================================
00681 def _nEntriesFracErr_ ( self , i1 , i2 = -10000000 ) :
00682     """
00683     Get error for  fraction of entries in histogram up to  the certain bin (not-included)
00684     
00685     attention: underflow bin is included!
00686     
00687     >>> h1
00688     >>> print h1.nEntriesFracErr( 10 )
00689 
00690     Get error  fraction of entries in histogram form the certain
00691     minimal bin up to the certain maximal bin (not-included)
00692     
00693     >>> h1
00694     >>> print h1.nEntriesFracErr ( 10 , 15 )
00695     
00696     """
00697     if  i2 < i1 or i2 < 0 : return HistoStats.nEntriesFracErr ( self , i1 )
00698     return HistoStats.nEntriesFracErr ( self , i1 , i2 )
00699 
00700 # =============================================================================
00701 i1DH = cpp.AIDA.IHistogram1D 
00702 
00703 if not hasattr ( i1DH , 'moment'          ) : i1DH.moment           = _moment_ 
00704 if not hasattr ( i1DH , 'momentErr'       ) : i1DH.momentErr        = _momentErr_ 
00705 if not hasattr ( i1DH , 'centralMoment'   ) : i1DH.centralMoment    = _centralMoment_ 
00706 if not hasattr ( i1DH , 'momentMomentErr' ) : i1DH.centralMomentErr = _centralMomentErr_ 
00707 if not hasattr ( i1DH , 'nEff'            ) : i1DH.nEff             = _nEff_ 
00708 if not hasattr ( i1DH , 'mean'            ) : i1DH.mean             = _mean_ 
00709 if not hasattr ( i1DH , 'meanErr'         ) : i1DH.meanErr          = _meanErr_ 
00710 if not hasattr ( i1DH , 'rms'             ) : i1DH.rms              = _rms_ 
00711 if not hasattr ( i1DH , 'rmsErr'          ) : i1DH.rmsErr           = _rmsErr_ 
00712 if not hasattr ( i1DH , 'skewness'        ) : i1DH.skewness         = _skewness_ 
00713 if not hasattr ( i1DH , 'skewnessErr'     ) : i1DH.skewnessErr      = _skewnessErr_ 
00714 if not hasattr ( i1DH , 'kurtosis'        ) : i1DH.kurtosis         = _kurtosis_ 
00715 if not hasattr ( i1DH , 'kurtosisErr'     ) : i1DH.kurtosisErr      = _kurtosisErr_ 
00716 
00717 if not hasattr ( i1DH , 'overflowEntriesFrac'     ) : i1DH.overflowEntriesFrac     = _overflowEntriesFrac_ 
00718 if not hasattr ( i1DH , 'overflowEntriesFracErr'  ) : i1DH.overflowEntriesFracErr  = _overflowEntriesFracErr_ 
00719 if not hasattr ( i1DH , 'underflowEntriesFrac'    ) : i1DH.underflowEntriesFrac    = _underflowEntriesFrac_ 
00720 if not hasattr ( i1DH , 'underflowEntriesFracErr' ) : i1DH.underflowEntriesFracErr = _underflowEntriesFracErr_ 
00721 
00722 if not hasattr ( i1DH , 'overflowIntegralFrac'     ) : i1DH.overflowIntegralFrac     = _overflowIntegralFrac_ 
00723 if not hasattr ( i1DH , 'overflowIntegralFracErr'  ) : i1DH.overflowIntegralFracErr  = _overflowIntegralFracErr_ 
00724 if not hasattr ( i1DH , 'underflowIntegralFrac'    ) : i1DH.underflowIntegralFrac    = _underflowIntegralFrac_ 
00725 if not hasattr ( i1DH , 'underflowIntegralFracErr' ) : i1DH.underflowIntegralFracErr = _underflowIntegralFracErr_ 
00726 
00727 if not hasattr ( i1DH , 'nEntries'        ) : i1DH.nEntries        = _nEntries_ 
00728 if not hasattr ( i1DH , 'nEntriesFrac'    ) : i1DH.nEntriesFrac    = _nEntriesFrac_ 
00729 if not hasattr ( i1DH , 'nEntriesFracErr' ) : i1DH.nEntriesFracErr = _nEntriesFracErr_ 
00730 
00731 ## ============================================================================
00732 def _path_ ( self ) :
00733     """
00734     Get the path in THS for the given AIDA object:
00735 
00736     >>> aida = 
00737     >>> print aida.path()
00738 
00739     """
00740     return cpp.Gaudi.Utils.Histos.path ( self )
00741 
00742 iBH = cpp.AIDA.IBaseHistogram
00743 if not hasattr ( iBH , 'path'     ) : iBH.path     = _path_
00744 if not hasattr ( iBH , 'TESpath'  ) : iBH.TESpath  = _path_
00745 if not hasattr ( iBH , 'location' ) : iBH.location = _path_
00746 
00747 
00748 # ==============================================================================
00749 class HistoFile :
00750     """
00751     Class to write histograms to a ROOT file.
00752     hFile = HistoFile("myFile.root")
00753     myHisto = ...
00754     hFile.save(myHisto)
00755     myHisto0 = ...
00756     myHisto1 = ...
00757     myHisto2 = ...
00758     hFile.save(myHisto0, myHisto1, myHisto2)
00759     histoList = [h0, h1, h2, h3]
00760     hFile.save(histoList)
00761     ...
00762     hWriter.close()
00763     """
00764     __author__ = "Juan Palacios juan.palacios@nikhef.nl"
00765     
00766     def __init__(self, fileName) :
00767         self.file = TFile(fileName, "RECREATE")
00768         self.aida2root = gbl.Gaudi.Utils.Aida2ROOT.aida2root
00769         self.aidaTypes = [gbl.AIDA.IHistogram1D,
00770                           gbl.AIDA.IHistogram2D,
00771                           gbl.AIDA.IHistogram3D,
00772                           gbl.AIDA.IProfile1D,
00773                           gbl.AIDA.IProfile2D,
00774                           gbl.AIDA.IHistogram    ]
00775 
00776     def __convertibleType(self, histo) :
00777         histoType = type(histo)
00778         for t in self.aidaTypes :
00779             if histoType == t : return True
00780         return False
00781     
00782     def save(self, *args) :
00783         """
00784         This function stores histograms on the file for future saving.
00785         It takes an arbitrary number of AIDA or ROOT histograms or
00786         a list of them.
00787         """
00788         if args :
00789             if type(args[0])==list :
00790                 histoList = args[0]
00791             else :
00792                 histoList = args
00793             for h in histoList :
00794                 if self.__convertibleType(h) : h = self.aida2root(h)
00795                 h.Write()
00796             
00797     def close(self) :
00798         self.file.Write()
00799         self.file.Close()
00800 
00801 # =============================================================================
00802 if '__main__' == __name__ :
00803     import sys 
00804     print __doc__
00805     for o in __all__ :
00806         print o
00807         print sys.modules[__name__].__dict__[o].__doc__
00808         
00809     
00810 # =============================================================================
00811 # The END 
00812 # =============================================================================

Generated at Mon Sep 7 18:05:46 2009 for Gaudi Framework, version v21r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004