Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

HistoDump.cpp

Go to the documentation of this file.
00001 // $Id: $
00002 #ifdef __ICC
00003 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
00004 //   TODO: To be removed, since it comes from ROOT TMathBase.h
00005 #pragma warning(disable:2259)
00006 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
00007 //   The comparison are meant
00008 #pragma warning(disable:1572)
00009 #endif
00010 // ============================================================================
00011 // Include files 
00012 // ============================================================================
00013 // STD & STL 
00014 // ============================================================================
00015 #include <cmath>
00016 #include <vector>
00017 #include <iostream>
00018 #include <utility>
00019 #include <sstream>
00020 // ============================================================================
00021 // AIDA
00022 // ============================================================================
00023 #include "AIDA/IHistogram1D.h"
00024 #include "AIDA/IProfile1D.h"
00025 #include "AIDA/IAxis.h"
00026 #include "AIDA/IAnnotation.h"
00027 // ============================================================================
00028 // GaudiKernel
00029 // ============================================================================
00030 #include "GaudiKernel/StatusCode.h"
00031 // ============================================================================
00032 // ROOT 
00033 // ============================================================================
00034 #include "TH1.h"
00035 #include "TProfile.h"
00036 #include "TAxis.h"
00037 // ============================================================================
00038 // Boost 
00039 // ============================================================================
00040 #include "boost/format.hpp"
00041 // ============================================================================
00042 // Local 
00043 // ============================================================================
00044 #include "GaudiUtils/HistoDump.h"
00045 #include "GaudiUtils/HistoTableFormat.h"
00046 #include "GaudiUtils/HistoStats.h"
00047 // ============================================================================
00048 namespace 
00049 {
00050   // ==========================================================================
00056   struct Histo
00057   {
00058     // ========================================================================
00059     Histo() : bins() , under() , over() {}
00060     // ========================================================================
00066     struct Bin 
00067     {
00068       // ======================================================================
00069       Bin ( const double h = 0  , 
00070             const double e = 0  ,
00071             const double l = -1 ) 
00072         : height ( h  ) 
00073         , error  ( e  ) 
00074         , lower ( l ) {}
00075       // ======================================================================
00077       double height ;                                            //  bin height 
00079       double error  ;                                            //   bin error
00081       double lower  ;                                            //  lower edge 
00082       // ======================================================================
00083       Bin& operator+= ( const Bin& right ) 
00084       {
00085         height          += right.height     ;
00086         const double e2  = error * error + right.error * right.error ;
00087         error            = std::sqrt ( e2 ) ;
00088         return *this ;
00089       }
00090       // ======================================================================
00091     } ;
00092     // ========================================================================
00094     double maxY ( const bool withErr ) const 
00095     {
00096       double _m  = std::max ( under.height , over.height  ) ;
00097       for ( Bins::const_iterator ib = bins.begin() ; bins.end() != ib ; ++ib ) 
00098       { _m = std::max ( _m  , withErr ?  ib->height +  ib->error :  ib->height ) ; }
00099       return _m ;
00100     }
00102     double minY ( const bool withErr ) const 
00103     {
00104       double _m  = std::min ( under.height , over.height  ) ;
00105       for ( Bins::const_iterator ib = bins.begin() ; bins.end() != ib ; ++ib ) 
00106       { _m = std::min ( _m  , withErr ?  ib->height - ib->error :  ib->height ) ; }
00107       return _m ;
00108     }
00110     Histo rebin ( const unsigned int bin ) const 
00111     {
00112       // create new histogram 
00113       Histo nh ;
00114       // copy overflow & underflow bins 
00115       nh.under = under ;
00116       nh.over  = over  ;
00117       // rebin
00118       for ( unsigned int ibin = 0 ; ibin < bins.size() ; ++ibin ) 
00119       {
00120         const Bin& current = bins[ibin] ;
00121         if      ( nh.bins.empty() ) { nh.bins.push_back ( current ) ; }
00122         else if ( 0 == ibin % bin ) { nh.bins.push_back ( current ) ; }
00123         else                        { nh.bins.back()   += current   ; }    
00124       }
00125       return nh ;
00126     }
00127     // find "null-bin", if any 
00128     int nullBin () const
00129     {
00130       for ( Bins::const_iterator ib = bins.begin() ; bins.end() != ib + 1 ; ++ib ) 
00131       { if ( ib->lower <= 0 && 0 < (ib+1)->lower ) { return ib - bins.begin() ; } } 
00132       return -1 ;
00133     }
00134     // ========================================================================
00135     typedef std::vector<Bin> Bins ;
00136     // ========================================================================
00138     Bins bins  ;                                              // histogram bins
00140     Bin  under ;                                              //  underflow bin 
00142     Bin  over  ;                                              //   overflow bin 
00143     // ========================================================================
00144   } ;
00145   // ==========================================================================
00153   StatusCode _getHisto ( const TH1* root , Histo& hist ) 
00154   {
00155     // clear the histogram 
00156     hist.bins.clear() ;
00157     //
00158     if ( 0 == root  ) { return StatusCode::FAILURE ; } // RETURN
00159     const TAxis* axis  = root->GetXaxis() ;
00160     if ( 0 == axis  ) { return StatusCode::FAILURE ; } // RETURN
00161     const int    nbins = axis->GetNbins () ;
00162     if ( 0 == nbins ) { return StatusCode::FAILURE ; } // RETURN
00163     
00164     // underflow bin 
00165     hist.under = Histo::Bin ( root -> GetBinContent ( 0         ) ,
00166                               root -> GetBinError   ( 0         ) , 
00167                               axis -> GetXmin       ()            ) ;
00168     // overflow bin
00169     hist.over  = Histo::Bin ( root -> GetBinContent ( nbins + 1 ) ,
00170                               root -> GetBinError   ( nbins + 1 ) ,
00171                               axis -> GetXmax       ()            ) ;
00172     //
00173     //
00174     for ( int ibin = 1 ; ibin <= nbins ; ++ibin ) 
00175     {
00176       // add to the local histo 
00177       Histo::Bin bin ( root -> GetBinContent   ( ibin ) ,
00178                        root -> GetBinError     ( ibin ) ,
00179                        axis -> GetBinLowEdge   ( ibin ) ) ;
00180       hist.bins.push_back ( bin ) ;
00181     }
00182     return StatusCode::SUCCESS ;
00183   }
00184   // ==========================================================================
00192   StatusCode _getHisto ( const TProfile* root      , 
00193                          Histo&          hist      , 
00194                          const bool   /* spread */ ) 
00195   {
00196     const TH1* histo = root ;
00197     return _getHisto ( histo , hist ) ;
00198   }
00199   // ==========================================================================
00207   StatusCode _getHisto 
00208   ( const AIDA::IHistogram1D* aida , Histo& hist ) 
00209   {
00210     // clear the histogram 
00211     hist.bins.clear() ;
00212     //
00213     if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN
00214     //
00215     const AIDA::IAxis& axis  = aida -> axis () ;
00216     const int          nbins = axis .  bins () ;
00217     //
00218    // underflow bin 
00219     hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ,
00220                               aida -> binError  ( AIDA::IAxis::UNDERFLOW_BIN ) , 
00221                               axis .  lowerEdge ()  ) ;
00222     // overflow bin
00223     hist.over  = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN  ) ,
00224                               aida -> binError  ( AIDA::IAxis::OVERFLOW_BIN  ) ,
00225                               axis .  upperEdge ()  ) ;
00226     //
00227     for ( int ibin = 0 ; ibin < nbins ; ++ibin ) 
00228     {
00229       // add to the local histo 
00230       Histo::Bin bin ( aida -> binHeight    ( ibin ) ,
00231                        aida -> binError     ( ibin ) ,
00232                        axis .  binLowerEdge ( ibin ) ) ;
00233       hist.bins.push_back ( bin ) ;
00234     }
00235     return StatusCode::SUCCESS ;
00236   }
00237   // ==========================================================================
00245   StatusCode _getHisto 
00246   ( const AIDA::IProfile1D* aida   , 
00247     Histo&                  hist   , 
00248     const bool              spread ) 
00249   {
00250     // clear the histogram 
00251     hist.bins.clear() ;
00252     //
00253     if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN
00254     //
00255     const AIDA::IAxis& axis  = aida -> axis () ;
00256     const int          nbins = axis .  bins () ;
00257     //
00258     // underflow bin 
00259     hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ,
00260                               spread ? 
00261                               aida -> binRms    ( AIDA::IAxis::UNDERFLOW_BIN ) :
00262                               aida -> binError  ( AIDA::IAxis::UNDERFLOW_BIN ) , 
00263                               axis .  lowerEdge ()  ) ;
00264     // overflow bin
00265     hist.over  = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN  ) ,
00266                               spread ?                              
00267                               aida -> binRms    ( AIDA::IAxis::OVERFLOW_BIN  ) :
00268                               aida -> binError  ( AIDA::IAxis::OVERFLOW_BIN  ) ,
00269                               axis .  upperEdge ()  ) ;
00270     //
00271     for ( int ibin = 0 ; ibin < nbins ; ++ibin ) 
00272     {
00273       // add to the local histo 
00274       Histo::Bin bin ( aida -> binHeight    ( ibin ) ,
00275                        spread ?                              
00276                        aida -> binRms       ( ibin ) :
00277                        aida -> binError     ( ibin ) ,
00278                        axis .  binLowerEdge ( ibin ) ) ;
00279       hist.bins.push_back ( bin ) ;
00280     }
00281     return StatusCode::SUCCESS ;
00282   }
00283   // ==========================================================================
00289   inline unsigned int rebin 
00290   ( const unsigned int bins , 
00291     const unsigned int imax ) 
00292   {
00293     if ( 0 == imax  ) { return 1 ; }                                  // RETURN 
00294     unsigned int ibin = 1 ;
00295     while ( bins > imax * ibin ) { ++ibin ; }
00296     return ibin ;                                                     // RETURN 
00297   }
00298   // ==========================================================================
00304   std::pair<double,int> decompose ( double v ) 
00305   {
00306     if      ( 0 == v ) { return std::make_pair ( 0.0 , 0 ) ;  }       // RETURN 
00307     else if ( 1 == v ) { return std::make_pair ( 1.0 , 0 ) ;  }       // RETURN 
00308     else if ( 0 >  v ) 
00309     {
00310       std::pair<double,int> r = decompose ( -v ) ;
00311       return std::pair<double,int>( -r.first , r.second ) ;          // RETURN 
00312     }
00313     else if ( 0.1 > v  ) 
00314     {
00315       int i       = 0 ;
00316       while ( 0.1 > v   ) { ++i ; v *= 10 ; }       // STUPID
00317       return std::make_pair ( v , -i ) ;
00318     }
00319     else if ( 1  < v  ) 
00320     {
00321       int i       = 0 ;
00322       while ( 1  <= v  ) { ++i ; v /= 10 ; }       // STUPID
00323       return std::make_pair ( v , i ) ;
00324     }
00325     return std::make_pair ( v , 1 ) ;
00326   }
00327   // ==========================================================================
00332   inline double _pow ( double __x , unsigned long __n )
00333   {
00334     double __y = __n % 2 ? __x : 1; 
00335     while ( __n >>= 1 )
00336     {
00337       __x = __x * __x;
00338       if ( __n % 2) { __y = __y * __x; }
00339     }  
00340     return __y ;
00341   }
00342   // ==========================================================================
00347   inline double rValMax ( const double v ) ;
00348   // ==========================================================================
00353   inline double rValMin ( const double v ) ;
00354   // ==========================================================================
00359   inline double rValMax ( const double v ) 
00360   {
00361     if      ( 0 == v  ) { return 0                   ; }             // RETURN    
00362     else if ( 0 >  v  ) { return -1 * rValMin ( -v ) ; }             // RETURN 
00363     // decompose the double value into decimal significand and mantissa  
00364     std::pair<double,int> r = decompose ( v ) ;
00365     // 
00366     const double f = std::ceil ( 20 * r.first ) / 2 ; // + 1 ;
00367     const int    l = r.second                   - 1 ;
00368     return 0 < l ? f * _pow ( 10 ,  l ) : f / _pow ( 10 , -l ) ;
00369   }
00370   // ==========================================================================
00375   inline double rValMin ( const double v ) 
00376   {
00377     if      ( 0 == v  ) { return 0                   ; }             // RETURN    
00378     else if ( 0 >  v  ) { return -1 * rValMax ( -v ) ; }             // RETURN 
00379     // decompose the double value into decimal significand and mantissa  
00380     std::pair<double,int> r = decompose ( v ) ;
00381     const double f = std::floor ( 20 * r.first ) / 2 ; // - 1 ;
00382     const int    l = r.second - 1   ;
00383     return 0 < l ? f * _pow ( 10 ,  l ) : f / _pow ( 10 , -l ) ;
00384   }
00385   // ==========================================================================
00390   inline std::string yLabel  ( const double value ) 
00391   {
00392     boost::format fmt ( "%10.3g" ) ;
00393     fmt % value ;
00394     return fmt.str () ;
00395   }
00396   // ==========================================================================
00401   inline std::string xLabel  ( const double value ) 
00402   {
00403     boost::format fmt ( "%9.3g" ) ;
00404     fmt % value ;
00405     return fmt.str () ;
00406   }
00407   // ==========================================================================
00409   char symbBin ( const Histo::Bin& bin    , 
00410                  const double      yLow   , 
00411                  const double      yHigh  , 
00412                  const bool        yNull  ,
00413                  const bool        errors ) 
00414   {
00415     if      ( errors && yLow  <= bin.height && bin.height < yHigh             ) { return '*' ; } // O 
00416     else if ( errors && yHigh <  bin.height -  bin.error                      ) { return ' ' ; }
00417     else if ( errors && yLow  >= bin.height +  bin.error                      ) { return ' ' ; }
00418     else if ( errors                                                          ) { return 'I' ; }
00419     else if ( yLow  <= bin.height  && bin.height < yHigh                      ) { return '*' ; }
00420     else if ( 0 <= bin.height && yLow  <= bin.height  && 0 <  yHigh && !yNull ) { return '*' ; } // + 
00421     else if ( 0 >  bin.height && yHigh >  bin.height  && 0 >= yLow  && !yNull ) { return '*' ; } // -
00422     //
00423     return ' ' ;
00424   }
00425   // ==========================================================================
00430   std::ostream& dumpText 
00431   ( const Histo&              histo  , 
00432     const std::size_t         width  , 
00433     const std::size_t         height , 
00434     const bool                errors ,
00435     std::ostream&             stream ) 
00436   {
00437     if (  40    > width  ) { return dumpText ( histo ,  40   , height , errors , stream ) ; } 
00438     if ( 200    < width  ) { return dumpText ( histo , 200   , height , errors , stream ) ; } 
00439     if ( 150    < height ) { return dumpText ( histo , width , 150    , errors , stream ) ; } 
00440     if (  20    > height ) { return dumpText ( histo , width , 20     , errors , stream ) ; } 
00441     if ( height > width  ) { return dumpText ( histo , width , width  , errors , stream ) ; }
00442     //
00443     const unsigned int nBins = histo.bins.size() ;
00444     if ( nBins > width  )
00445     {
00446       // rebin histogram 
00447       Histo r = histo.rebin ( rebin ( nBins , width ) ) ;
00448       return dumpText ( r , width , height , errors , stream ) ;
00449     }
00450     // 
00451     // get the Y-scale 
00452     double yMax = std::max ( rValMax ( histo.maxY ( errors ) ) , 0.0 ) ;
00453     double yMin = std::min ( rValMin ( histo.minY ( errors ) ) , 0.0 ) ;
00454     
00455     if ( yMin == yMax ) { yMax = yMin + 1 ; }
00457     std::pair<double,int> r = decompose ( yMax - yMin ) ;
00458     double _ny = std::ceil ( 10 * r.first ) ; //   1 <= ny < 10 
00459     if ( 1 >=  _ny  ) { _ny = 10 ; }
00460     int yBins  = (int) std::max ( 1. , std::ceil ( height / _ny ) ) ;
00461     
00462     yBins     *= (int) _ny ;
00463     if ( 20     > yBins ) { yBins = 20    ; }
00464     const double yScale = ( yMax - yMin ) / yBins ;    
00465     
00466     //
00467     const int ySkip = 
00468       0 == yBins % 13 ? 13 :
00469       0 == yBins % 11 ? 11 :
00470       0 == yBins %  9 ?  9 :
00471       0 == yBins %  8 ?  8 :
00472       0 == yBins %  7 ?  7 :
00473       0 == yBins %  6 ?  6 :
00474       0 == yBins %  5 ?  5 : 
00475       0 == yBins %  4 ?  4 : 10 ;
00476     
00477     const int xSkip =
00478       // 0 == nBins % 8 ? 8 : 
00479       0 == nBins % 7 ? 7 : 
00480       0 == nBins % 6 ? 6 :
00481       0 == nBins % 5 ? 5 : 
00482       0 == nBins % 4 ? 4 : 10 ;
00483     
00484     int iNull = histo.nullBin() ;
00485 
00486     if ( 0 <= iNull ) { iNull %= xSkip ; }
00487     else              { iNull  = 0     ; }
00488     
00489     stream << std::endl ;
00490     
00491     for ( int yLine = -1  ; yLine < yBins ; ++yLine ) 
00492     {
00493       const double yHigh = yMax - yScale *   yLine       ;
00494       // const double yLow  = yHigh - yScale         ;
00495       const double yLow  = yMax - yScale * ( yLine + 1 ) ;
00496       //
00497       std::string line1 = " " ;
00498       
00499       const bool ynull  = ( yLow <= 0 && 0 < yHigh )    ;
00500       const bool yfirst = -1 == yLine || yBins -1  == yLine ;
00501       const bool ylab   = 
00502         ( 0  == ( yLine + 1 ) % ySkip ) || yfirst || ynull ;
00503       
00504       if ( ylab ) { line1 += yLabel ( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow )  ; }
00505       else        { line1 += std::string( 10 , ' ' )                             ; }  
00506       //
00507       line1 += " " ;
00508       //
00510       line1 += symbBin ( histo.under , yLow , yHigh , ynull , errors ) ;
00511       //
00512       line1 += 
00513         ynull ? "-+" :
00514         ylab  ? " +" : " |" ;
00515       //
00516       std::string line2 ;
00517       //
00518       for  ( Histo::Bins::const_iterator ibin = histo.bins.begin() ;
00519              histo.bins.end() != ibin ; ++ibin ) 
00520       {
00521         //char symb = ' ' ;
00522         const int i = ibin - histo.bins.begin () ;
00523         //
00524         const bool xnull = 
00525           ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.end() && 0 < (ibin+1)->lower ;
00526         const bool xlab  =  iNull == i % xSkip ;
00527         //
00528         char symb = symbBin ( *ibin, yLow , yHigh , ynull , errors ) ;
00529         //
00530         if ( ' ' == symb ) 
00531         {
00532           if      ( ( ynull || yfirst ) && xlab ) { symb = '+' ; }
00533           else if (   ynull || yfirst           ) { symb = '-' ; }
00534           //
00535           else if ( ylab && xnull               ) { symb = '+' ; }
00536           else if (         xnull               ) { symb = '|' ; }
00537           //
00538           else if ( ylab || xlab                ) { symb = '.' ; }
00539           //
00540         }
00541         line2 += symb ;
00542         //
00543       }
00544       //
00545       std::string line3 = 
00546         ynull ? "->" : 
00547         ylab  ? "+ " : "| " ;
00548       //
00550       line3 += symbBin ( histo.over , yLow , yHigh , ynull , errors ) ;
00551       //
00552       stream << line1 << line2 << line3  << std::endl ;
00553       //
00554     }
00555     
00556     // get x-labels 
00557     std::vector<std::string> xlabels ;
00558     for ( Histo::Bins::const_iterator ib = histo.bins.begin() ; histo.bins.end() != ib ; ++ib ) 
00559     { xlabels.push_back ( xLabel ( ib->lower )  ) ; }
00560     // overflow& underflow  label
00561     const std::string oLabel = xLabel ( histo.over.lower  ) ;
00562     const std::string uLabel = xLabel ( histo.under.lower ) ;
00563     //
00564     static const std::string s_UNDERFLOW ( "UNDERFLOW" ) ;
00565     static const std::string s_OVERFLOW  ( " OVERFLOW" ) ;
00566     //
00567     //
00568     for ( unsigned int yLine = 0 ; yLine < 12 ; ++yLine ) 
00569     {
00570       std::string line = std::string ( 12 , ' ' ) ;
00571       //
00572       if ( yLine < s_UNDERFLOW.size() ) { line += s_UNDERFLOW[yLine] ; }
00573       else                              { line += ' '                ; }      
00574       //
00575       line += ' ' ;
00576       //
00577       if ( uLabel.size() > yLine ) { line += uLabel[yLine] ; }
00578       else                         { line += ' '           ; }
00579       //
00580       for  ( Histo::Bins::const_iterator ibin = histo.bins.begin() ; histo.bins.end() != ibin ; ++ibin ) 
00581       {
00582         int ib  = ibin - histo.bins.begin() ;
00583         const bool xlab  =  ( iNull == ib % xSkip ) ;
00584         if ( xlab && yLine < xlabels[ib].size() ) { line += xlabels[ib][yLine] ; }
00585         else { line += ' ' ; }
00586       }
00587       //
00588       if ( oLabel.size() > yLine ) { line += oLabel[yLine] ; }
00589       else                         { line += ' '           ; }
00590       //
00591       line += ' ' ;
00592       //
00593       if ( yLine < s_OVERFLOW.size() ) { line += s_OVERFLOW[yLine] ; }
00594       else                             { line += ' '               ; }
00595       //
00596       stream << line << std::endl ;
00597     }
00598     //
00599     return stream ; // RETURN 
00600   }
00601 }
00602 // ============================================================================
00603 /*  dump the text representation of the histogram 
00604  *  @param histo  (INPUT) the histogram 
00605  *  @param stream (OUTUT) the stream  
00606  *  @param width  (INPUT) the maximal column width 
00607  *  @param height (INPUT) the proposed coulmn height 
00608  *  @param errors (INPUT) print/plot errors
00609  *  @return the stream 
00610  *  @author Vanya BELYAEV  Ivan.BElyaev@nikhef.nl
00611  *  @date 2009-09-19
00612  */ 
00613 // ============================================================================
00614 std::ostream& Gaudi::Utils::Histos::histoDump_
00615 ( const AIDA::IHistogram1D* histo   , 
00616   std::ostream&             stream  , 
00617   const std::size_t         width   ,  
00618   const std::size_t         height  , 
00619   const bool                errors  ) 
00620 {
00621   stream << std::endl ;
00622   if ( 0 == histo     ) { return stream ; }  // RETURN 
00623   Histo hist ;
00624   StatusCode sc = _getHisto ( histo , hist ) ;
00625   if ( sc.isFailure() ) { return stream ; }  // RETURN 
00626   //
00627   stream 
00628     << boost::format ( " Histo TES   : \"%s\"") % path ( histo )  
00629     << std::endl 
00630     << boost::format ( " Histo Title : \"%s\"") % histo->title() 
00631     << std::endl 
00632     << std::endl ;
00633   //
00634   stream 
00635     << boost::format ( " Mean        : %11.5g +- %-10.4g ")
00636     % Gaudi::Utils::HistoStats::mean        ( histo ) 
00637     % Gaudi::Utils::HistoStats::meanErr     ( histo ) 
00638     << std::endl 
00639     << boost::format ( " Rms         : %11.5g +- %-10.4g ")
00640     % Gaudi::Utils::HistoStats::rms         ( histo ) 
00641     % Gaudi::Utils::HistoStats::rmsErr      ( histo ) 
00642     << std::endl 
00643     << boost::format ( " Skewness    : %11.5g +- %-10.4g ")
00644     % Gaudi::Utils::HistoStats::skewness    ( histo ) 
00645     % Gaudi::Utils::HistoStats::skewnessErr ( histo ) 
00646     << std::endl 
00647     << boost::format ( " Kurtosis    : %11.5g +- %-10.4g ")
00648     % Gaudi::Utils::HistoStats::kurtosis    ( histo ) 
00649     % Gaudi::Utils::HistoStats::kurtosisErr ( histo ) 
00650     << std::endl 
00651     << std::endl ;
00652   //
00653   stream 
00654     << boost::format ( " Entries     :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s | %=11s |") 
00655     % "All" 
00656     % "In Range"
00657     % "Underflow" 
00658     % "Overflow" 
00659     % "#Equivalent" 
00660     % "Integral" 
00661     % "Total" 
00662     << std::endl 
00663     << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g | %=11.5g |") 
00664     % histo -> allEntries () 
00665     % histo -> entries    () 
00666     % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) 
00667     % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN  )  
00668     % histo -> equivalentBinEntries ()
00669     % histo -> sumBinHeights        () 
00670     % histo -> sumAllBinHeights     () 
00671     << std::endl 
00672     << std::endl ;  
00673   //
00674   const AIDA::IAnnotation& a = histo->annotation () ;
00675   if ( 0 != a.size() ) 
00676   {
00677     stream << " Annotation" << std::endl ;
00678     for ( int i = 0 ; i < a.size() ; ++i ) 
00679     {
00680       stream 
00681         << boost::format ( " | %-25.25s : %-45.45s | ")
00682         % a.key   ( i ) 
00683         % a.value ( i ) 
00684         << std::endl ;
00685     }
00686     stream << std::endl ; 
00687   }
00688   //
00689   return dumpText ( hist , width , height , errors , stream ) ;
00690 }
00691 // ============================================================================
00692 /*  dump the text representation of the histogram 
00693  *  @param histo the histogram 
00694  *  @param stream the stream  
00695  *  @param width  the maximal column width 
00696  *  @param height (INPUT) the proposed coulmn height 
00697  *  @param errors (INPUT) print/plot errors
00698  *  @param erorrs print/plot errors
00699  *  @author Vanya BELYAEV  Ivan.BElyaev@nikhef.nl
00700  *  @date 2009-09-19
00701  */ 
00702 // ============================================================================
00703 std::string Gaudi::Utils::Histos::histoDump 
00704 ( const AIDA::IHistogram1D* histo  , 
00705   const std::size_t         width  , 
00706   const std::size_t         height  , 
00707   const bool                errors ) 
00708 {
00709   std::ostringstream stream ;
00710   histoDump_ ( histo , stream , width , height , errors );
00711   return stream.str() ;
00712 }
00713 // ============================================================================
00714 /*  dump the text representation of the 1D-profile 
00715  *  @param histo  (INPUT) the profile  
00716  *  @param stream (OUTUT) the stream  
00717  *  @param width  (INPUT) the maximal column width 
00718  *  @param height (INPUT) the proposed coulmn height 
00719  *  @param spread (INPUT) plot spread/error? 
00720  *  @return the stream 
00721  *  @author Vanya BELYAEV  Ivan.BElyaev@nikhef.nl
00722  *  @date 2009-09-19
00723  */ 
00724 // ============================================================================
00725 std::ostream& Gaudi::Utils::Histos::histoDump_ 
00726 ( const AIDA::IProfile1D*   histo   , 
00727   std::ostream&             stream  , 
00728   const std::size_t         width   ,  
00729   const std::size_t         height  , 
00730   const bool                spread  ) 
00731 {
00732   stream << std::endl ;
00733   if ( 0 == histo     ) { return stream ; }  // RETURN 
00734   Histo hist ;
00735   StatusCode sc = _getHisto ( histo , hist , spread ) ;
00736   if ( sc.isFailure() ) { return stream ; }  // RETURN 
00737   //
00738   stream 
00739     << boost::format ( " Histo TES   : \"%s\"") % path ( histo )  
00740     << std::endl 
00741     << boost::format ( " Histo Title : \"%s\"") % histo->title() 
00742     << std::endl 
00743     << std::endl ;
00744   //
00745   stream 
00746     << boost::format ( " Mean        : %11.5g ") % histo->mean() 
00747     << std::endl 
00748     << boost::format ( " Rms         : %11.5g ") % histo->rms () 
00749     << std::endl 
00750     << std::endl ;
00751   //
00752   stream 
00753     << boost::format ( " Entries     :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s |") 
00754     % "All" 
00755     % "In Range"
00756     % "Underflow" 
00757     % "Overflow" 
00758     // % "#Equivalent" 
00759     % "Integral" 
00760     % "Total" 
00761     << std::endl 
00762     << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g |") 
00763     % histo -> allEntries () 
00764     % histo -> entries    () 
00765     % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) 
00766     % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN  )  
00767     // % histo -> equivalentBinEntries ()
00768     % histo -> sumBinHeights        () 
00769     % histo -> sumAllBinHeights     () 
00770     << std::endl 
00771     << std::endl ;  
00772   //
00773   const AIDA::IAnnotation& a = histo->annotation () ;
00774   if ( 0 != a.size() ) 
00775   {
00776     stream << " Annotation" << std::endl ;
00777     for ( int i = 0 ; i < a.size() ; ++i ) 
00778     {
00779       stream 
00780         << boost::format ( " | %-25.25s : %-45.45s | ")
00781         % a.key   ( i ) 
00782         % a.value ( i ) 
00783         << std::endl ;
00784     }
00785     stream << std::endl ; 
00786   }
00787   //
00788   return dumpText ( hist , width , height , true , stream ) ;
00789 }
00790 // ============================================================================
00791 /*  dump the text representation of the 1D-profile 
00792  *  @param histo the histogram 
00793  *  @param stream the stream  
00794  *  @param width  the maximal column width 
00795  *  @param height (INPUT) the proposed coulmn height 
00796  *  @author Vanya BELYAEV  Ivan.BElyaev@nikhef.nl
00797  *  @date 2009-09-19
00798  */ 
00799 // ============================================================================
00800 std::string Gaudi::Utils::Histos::histoDump 
00801 ( const AIDA::IProfile1D*   histo  , 
00802   const std::size_t         width  , 
00803   const std::size_t         height , 
00804   const bool                spread ) 
00805 {
00806   std::ostringstream stream ;
00807   histoDump_ ( histo , stream , width , height , spread );
00808   return stream.str() ;
00809 }
00810 // ============================================================================
00811 /*  dump the text representation of the histogram 
00812  *  @param histo  (INPUT) the histogram 
00813  *  @param stream (OUTUT) the stream  
00814  *  @param width  (INPUT) the maximal column width 
00815  *  @param errors (INPUT) print/plot errors
00816  *  @return the stream 
00817  *  @author Vanya BELYAEV  Ivan.Belyaev@nikhef.nl
00818  *  @date 2009-09-19
00819  */ 
00820 // ============================================================================
00821 std::ostream& Gaudi::Utils::Histos::histoDump_ 
00822 ( const TH1*                histo  , 
00823   std::ostream&             stream ,
00824   const std::size_t         width  , 
00825   const std::size_t         height , 
00826   const bool                errors ) 
00827 {
00828   const TProfile* profile = dynamic_cast<const TProfile*> ( histo ) ;
00829   if ( 0 != profile ) 
00830   { return histoDump_ ( profile , stream , width , height ) ; }
00831   //
00832   stream << std::endl ;
00833   if ( 0 == histo     ) { return stream ; }  // RETURN 
00834   Histo hist ;
00835   StatusCode sc = _getHisto ( histo , hist ) ;
00836   if ( sc.isFailure() ) { return stream ; }  // RETURN 
00837   //
00838   stream 
00839     << boost::format ( " Histo Name  : \"%s\"") 
00840     % histo -> GetName () 
00841     << std::endl 
00842     << boost::format ( " Histo Title : \"%s\"") 
00843     % histo -> GetTitle () 
00844     << std::endl 
00845     << std::endl ;
00846   //
00847   stream 
00848     << boost::format ( " Mean        : %11.5g +- %-10.4g ")
00849     % histo -> GetMean      ()
00850     % histo -> GetMeanError ()
00851     << std::endl 
00852     << boost::format ( " Rms         : %11.5g +- %-10.4g ")
00853     % histo -> GetRMS      ()
00854     % histo -> GetRMSError ()
00855     << std::endl 
00856     << boost::format ( " Skewness    : %11.5g            ")
00857     % histo -> GetSkewness ()
00858     << std::endl 
00859     << boost::format ( " Kurtosis    : %11.5g            ")
00860     % histo -> GetKurtosis ()
00861     << std::endl 
00862     << std::endl ;
00863   //
00864   stream 
00865     << boost::format ( " Entries     :\n | %=11s | %=11s | %=11s | %=11s | %=11s |") 
00866     % "All" 
00867     % "Underflow" 
00868     % "Overflow" 
00869     % "#Equivalent" 
00870     % "Integral" 
00871     << std::endl 
00872     << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g | %=11.5g |") 
00873     % histo -> GetEntries () 
00874     % histo -> GetBinContent ( 0                       ) 
00875     % histo -> GetBinContent ( histo->GetNbinsX() + 1  ) 
00876     % histo -> GetEffectiveEntries  ()
00877     % histo -> Integral             ()
00878     << std::endl 
00879     << std::endl ;  
00880   //
00881   return dumpText ( hist , width , height , errors , stream ) ;
00882 }
00883 // ============================================================================
00884 /*  dump the text representation of the histogram 
00885  *  @param histo  (INPUT) the histogram 
00886  *  @param stream (OUTUT) the stream  
00887  *  @param width  (INPUT) the maximal column width 
00888  *  @param errors (INPUT) print/plot errors
00889  *  @return the stream 
00890  *  @author Vanya BELYAEV  Ivan.Belyaev@nikhef.nl
00891  *  @date 2009-09-19
00892  */ 
00893 // ============================================================================
00894 std::ostream& Gaudi::Utils::Histos::histoDump_ 
00895 ( const TProfile*           histo  , 
00896   std::ostream&             stream ,
00897   const std::size_t         width  , 
00898   const std::size_t         height )  
00899 {
00900   stream << std::endl ;
00901   if ( 0 == histo     ) { return stream ; }  // RETURN 
00902   Histo hist ;
00903   StatusCode sc = _getHisto ( histo , hist , true ) ;
00904   if ( sc.isFailure() ) { return stream ; }  // RETURN 
00905   //
00906   stream 
00907     << boost::format ( " Profile Name  : \"%s\"") 
00908     % histo -> GetName () 
00909     << std::endl 
00910     << boost::format ( " Profile Title : \"%s\"") 
00911     % histo -> GetTitle () 
00912     << std::endl 
00913     << std::endl ;
00914   //
00915   stream 
00916     << boost::format ( " Mean          : %11.5g ") % histo -> GetMean      ()
00917     << std::endl 
00918     << boost::format ( " Rms           : %11.5g ") % histo -> GetRMS      ()
00919     << std::endl 
00920     << std::endl ;
00921   //
00922   stream 
00923     << boost::format ( " Entries       :\n | %=11s | %=11s | %=11s | %=11s |") 
00924     % "All" 
00925     % "Underflow" 
00926     % "Overflow" 
00927     % "Integral" 
00928     << std::endl 
00929     << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g |") 
00930     % histo -> GetEntries () 
00931     % histo -> GetBinContent ( 0                       ) 
00932     % histo -> GetBinContent ( histo->GetNbinsX() + 1  ) 
00933     % histo -> Integral             ()
00934     << std::endl 
00935     << std::endl ;  
00936   //
00937   return dumpText ( hist , width , height , true , stream ) ;
00938 }
00939 // ============================================================================
00940 /*  dump the text representation of the histogram 
00941  *  @param histo  (INPUT) the histogram 
00942  *  @param width  (INPUT) the maximal column width 
00943  *  @param errors (INPUT) print/plot errors
00944  *  @return string representation of the histogram       
00945  *  @author Vanya BELYAEV  Ivan.Belyaev@nikhef.nl
00946  *  @date 2009-09-19
00947  */ 
00948 // ============================================================================
00949 std::string Gaudi::Utils::Histos::histoDump 
00950 ( const TH1*                histo  , 
00951   const std::size_t         width  , 
00952   const std::size_t         height , 
00953   const bool                errors ) 
00954 {
00955   std::ostringstream stream ;
00956   histoDump_ ( histo , stream , width , height , errors );
00957   return stream.str() ;
00958 }
00959 // ============================================================================
00960 /*  dump the text representation of the histogram 
00961  *  @param histo  (INPUT) the histogram 
00962  *  @param width  (INPUT) the maximal column width 
00963  *  @param errors (INPUT) print/plot errors
00964  *  @return string representation of the histogram       
00965  *  @author Vanya BELYAEV  Ivan.Belyaev@nikhef.nl
00966  *  @date 2009-09-19
00967  */ 
00968 // ============================================================================
00969 std::string Gaudi::Utils::Histos::histoDump 
00970 ( const TProfile*           histo  , 
00971   const std::size_t         width  , 
00972   const std::size_t         height ) 
00973 {
00974   std::ostringstream stream ;
00975   histoDump_ ( histo , stream , width , height );
00976   return stream.str() ;
00977 }
00978 // ============================================================================
00979 
00980 
00981 
00982 
00983 // ============================================================================
00984 // The END  
00985 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:25:05 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004