All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HistoDump.cpp
Go to the documentation of this file.
1 // $Id: $
2 #ifdef __ICC
3 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
4 // TODO: To be removed, since it comes from ROOT TMathBase.h
5 #pragma warning(disable:2259)
6 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
7 // The comparison are meant
8 #pragma warning(disable:1572)
9 #endif
10 #ifdef WIN32
11 // Disable warning
12 // warning C4996: 'sprintf': This function or variable may be unsafe.
13 // coming from TString.h
14 #pragma warning(disable:4996)
15 #endif
16 // ============================================================================
17 // Include files
18 // ============================================================================
19 // STD & STL
20 // ============================================================================
21 #include <cmath>
22 #include <vector>
23 #include <iostream>
24 #include <utility>
25 #include <sstream>
26 // ============================================================================
27 // AIDA
28 // ============================================================================
29 #include "AIDA/IHistogram1D.h"
30 #include "AIDA/IProfile1D.h"
31 #include "AIDA/IAxis.h"
32 #include "AIDA/IAnnotation.h"
33 // ============================================================================
34 // GaudiKernel
35 // ============================================================================
36 #include "GaudiKernel/StatusCode.h"
37 // ============================================================================
38 // ROOT
39 // ============================================================================
40 #include "TH1.h"
41 #include "TProfile.h"
42 #include "TAxis.h"
43 // ============================================================================
44 // Boost
45 // ============================================================================
46 #include "boost/format.hpp"
47 // ============================================================================
48 // Local
49 // ============================================================================
50 #include "GaudiUtils/HistoDump.h"
52 #include "GaudiUtils/HistoStats.h"
53 // ============================================================================
54 namespace
55 {
56  // ==========================================================================
62  struct Histo
63  {
64  // ========================================================================
65  Histo() : bins() , under() , over() {}
66  // ========================================================================
72  struct Bin
73  {
74  // ======================================================================
75  Bin ( const double h = 0 ,
76  const double e = 0 ,
77  const double l = -1 )
78  : height ( h )
79  , error ( e )
80  , lower ( l ) {}
81  // ======================================================================
83  double height ; // bin height
85  double error ; // bin error
87  double lower ; // lower edge
88  // ======================================================================
89  Bin& operator+= ( const Bin& right )
90  {
91  height += right.height ;
92  const double e2 = error * error + right.error * right.error ;
93  error = std::sqrt ( e2 ) ;
94  return *this ;
95  }
96  // ======================================================================
97  } ;
98  // ========================================================================
100  double maxY ( const bool withErr ) const
101  {
102  double _m = std::max ( under.height , over.height ) ;
103  for ( Bins::const_iterator ib = bins.begin() ; bins.end() != ib ; ++ib )
104  { _m = std::max ( _m , withErr ? ib->height + ib->error : ib->height ) ; }
105  return _m ;
106  }
108  double minY ( const bool withErr ) const
109  {
110  double _m = std::min ( under.height , over.height ) ;
111  for ( Bins::const_iterator ib = bins.begin() ; bins.end() != ib ; ++ib )
112  { _m = std::min ( _m , withErr ? ib->height - ib->error : ib->height ) ; }
113  return _m ;
114  }
116  Histo rebin ( const unsigned int bin ) const
117  {
118  // create new histogram
119  Histo nh ;
120  // copy overflow & underflow bins
121  nh.under = under ;
122  nh.over = over ;
123  // rebin
124  for ( unsigned int ibin = 0 ; ibin < bins.size() ; ++ibin )
125  {
126  const Bin& current = bins[ibin] ;
127  if ( nh.bins.empty() ) { nh.bins.push_back ( current ) ; }
128  else if ( 0 == ibin % bin ) { nh.bins.push_back ( current ) ; }
129  else { nh.bins.back() += current ; }
130  }
131  return nh ;
132  }
133  // find "null-bin", if any
134  int nullBin () const
135  {
136  for ( Bins::const_iterator ib = bins.begin() ; bins.end() != ib + 1 ; ++ib )
137  { if ( ib->lower <= 0 && 0 < (ib+1)->lower ) { return ib - bins.begin() ; } }
138  return -1 ;
139  }
140  // ========================================================================
141  typedef std::vector<Bin> Bins ;
142  // ========================================================================
144  Bins bins ; // histogram bins
146  Bin under ; // underflow bin
148  Bin over ; // overflow bin
149  // ========================================================================
150  } ;
151  // ==========================================================================
159  StatusCode _getHisto ( const TH1* root , Histo& hist )
160  {
161  // clear the histogram
162  hist.bins.clear() ;
163  //
164  if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN
165  const TAxis* axis = root->GetXaxis() ;
166  if ( 0 == axis ) { return StatusCode::FAILURE ; } // RETURN
167  const int nbins = axis->GetNbins () ;
168  if ( 0 == nbins ) { return StatusCode::FAILURE ; } // RETURN
169 
170  // underflow bin
171  hist.under = Histo::Bin ( root -> GetBinContent ( 0 ) ,
172  root -> GetBinError ( 0 ) ,
173  axis -> GetXmin () ) ;
174  // overflow bin
175  hist.over = Histo::Bin ( root -> GetBinContent ( nbins + 1 ) ,
176  root -> GetBinError ( nbins + 1 ) ,
177  axis -> GetXmax () ) ;
178  //
179  //
180  for ( int ibin = 1 ; ibin <= nbins ; ++ibin )
181  {
182  // add to the local histo
183  Histo::Bin bin ( root -> GetBinContent ( ibin ) ,
184  root -> GetBinError ( ibin ) ,
185  axis -> GetBinLowEdge ( ibin ) ) ;
186  hist.bins.push_back ( bin ) ;
187  }
188  return StatusCode::SUCCESS ;
189  }
190  // ==========================================================================
198  StatusCode _getHisto ( const TProfile* root ,
199  Histo& hist ,
200  const bool /* spread */ )
201  {
202  const TH1* histo = root ;
203  return _getHisto ( histo , hist ) ;
204  }
205  // ==========================================================================
213  StatusCode _getHisto
214  ( const AIDA::IHistogram1D* aida , Histo& hist )
215  {
216  // clear the histogram
217  hist.bins.clear() ;
218  //
219  if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN
220  //
221  const AIDA::IAxis& axis = aida -> axis () ;
222  const int nbins = axis . bins () ;
223  //
224  // underflow bin
225  hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ,
226  aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) ,
227  axis . lowerEdge () ) ;
228  // overflow bin
229  hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) ,
230  aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) ,
231  axis . upperEdge () ) ;
232  //
233  for ( int ibin = 0 ; ibin < nbins ; ++ibin )
234  {
235  // add to the local histo
236  Histo::Bin bin ( aida -> binHeight ( ibin ) ,
237  aida -> binError ( ibin ) ,
238  axis . binLowerEdge ( ibin ) ) ;
239  hist.bins.push_back ( bin ) ;
240  }
241  return StatusCode::SUCCESS ;
242  }
243  // ==========================================================================
251  StatusCode _getHisto
252  ( const AIDA::IProfile1D* aida ,
253  Histo& hist ,
254  const bool spread )
255  {
256  // clear the histogram
257  hist.bins.clear() ;
258  //
259  if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN
260  //
261  const AIDA::IAxis& axis = aida -> axis () ;
262  const int nbins = axis . bins () ;
263  //
264  // underflow bin
265  hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ,
266  spread ?
267  aida -> binRms ( AIDA::IAxis::UNDERFLOW_BIN ) :
268  aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) ,
269  axis . lowerEdge () ) ;
270  // overflow bin
271  hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) ,
272  spread ?
273  aida -> binRms ( AIDA::IAxis::OVERFLOW_BIN ) :
274  aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) ,
275  axis . upperEdge () ) ;
276  //
277  for ( int ibin = 0 ; ibin < nbins ; ++ibin )
278  {
279  // add to the local histo
280  Histo::Bin bin ( aida -> binHeight ( ibin ) ,
281  spread ?
282  aida -> binRms ( ibin ) :
283  aida -> binError ( ibin ) ,
284  axis . binLowerEdge ( ibin ) ) ;
285  hist.bins.push_back ( bin ) ;
286  }
287  return StatusCode::SUCCESS ;
288  }
289  // ==========================================================================
295  inline unsigned int rebin
296  ( const unsigned int bins ,
297  const unsigned int imax )
298  {
299  if ( 0 == imax ) { return 1 ; } // RETURN
300  unsigned int ibin = 1 ;
301  while ( bins > imax * ibin ) { ++ibin ; }
302  return ibin ; // RETURN
303  }
304  // ==========================================================================
310  std::pair<double,int> decompose ( double v )
311  {
312  if ( 0 == v ) { return std::make_pair ( 0.0 , 0 ) ; } // RETURN
313  else if ( 1 == v ) { return std::make_pair ( 1.0 , 0 ) ; } // RETURN
314  else if ( 0 > v )
315  {
316  std::pair<double,int> r = decompose ( -v ) ;
317  return std::pair<double,int>( -r.first , r.second ) ; // RETURN
318  }
319  else if ( 0.1 > v )
320  {
321  int i = 0 ;
322  while ( 0.1 > v ) { ++i ; v *= 10 ; } // STUPID
323  return std::make_pair ( v , -i ) ;
324  }
325  else if ( 1 < v )
326  {
327  int i = 0 ;
328  while ( 1 <= v ) { ++i ; v /= 10 ; } // STUPID
329  return std::make_pair ( v , i ) ;
330  }
331  return std::make_pair ( v , 1 ) ;
332  }
333  // ==========================================================================
338  inline double _pow ( double __x , unsigned long __n )
339  {
340  double __y = __n % 2 ? __x : 1;
341  while ( __n >>= 1 )
342  {
343  __x = __x * __x;
344  if ( __n % 2) { __y = __y * __x; }
345  }
346  return __y ;
347  }
348  // ==========================================================================
353  inline double rValMax ( const double v ) ;
354  // ==========================================================================
359  inline double rValMin ( const double v ) ;
360  // ==========================================================================
365  inline double rValMax ( const double v )
366  {
367  if ( 0 == v ) { return 0 ; } // RETURN
368  else if ( 0 > v ) { return -1 * rValMin ( -v ) ; } // RETURN
369  // decompose the double value into decimal significand and mantissa
370  std::pair<double,int> r = decompose ( v ) ;
371  //
372  const double f = std::ceil ( 20 * r.first ) / 2 ; // + 1 ;
373  const int l = r.second - 1 ;
374  return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ;
375  }
376  // ==========================================================================
381  inline double rValMin ( const double v )
382  {
383  if ( 0 == v ) { return 0 ; } // RETURN
384  else if ( 0 > v ) { return -1 * rValMax ( -v ) ; } // RETURN
385  // decompose the double value into decimal significand and mantissa
386  std::pair<double,int> r = decompose ( v ) ;
387  const double f = std::floor ( 20 * r.first ) / 2 ; // - 1 ;
388  const int l = r.second - 1 ;
389  return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ;
390  }
391  // ==========================================================================
396  inline std::string yLabel ( const double value )
397  {
398  boost::format fmt ( "%10.3g" ) ;
399  fmt % value ;
400  return fmt.str () ;
401  }
402  // ==========================================================================
407  inline std::string xLabel ( const double value )
408  {
409  boost::format fmt ( "%9.3g" ) ;
410  fmt % value ;
411  return fmt.str () ;
412  }
413  // ==========================================================================
415  char symbBin ( const Histo::Bin& bin ,
416  const double yLow ,
417  const double yHigh ,
418  const bool yNull ,
419  const bool errors )
420  {
421  if ( errors && yLow <= bin.height && bin.height < yHigh ) { return '*' ; } // O
422  else if ( errors && yHigh < bin.height - bin.error ) { return ' ' ; }
423  else if ( errors && yLow >= bin.height + bin.error ) { return ' ' ; }
424  else if ( errors ) { return 'I' ; }
425  else if ( yLow <= bin.height && bin.height < yHigh ) { return '*' ; }
426  else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) { return '*' ; } // +
427  else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) { return '*' ; } // -
428  //
429  return ' ' ;
430  }
431  // ==========================================================================
436  std::ostream& dumpText
437  ( const Histo& histo ,
438  const std::size_t width ,
439  const std::size_t height ,
440  const bool errors ,
441  std::ostream& stream )
442  {
443  if ( 40 > width ) { return dumpText ( histo , 40 , height , errors , stream ) ; }
444  if ( 200 < width ) { return dumpText ( histo , 200 , height , errors , stream ) ; }
445  if ( 150 < height ) { return dumpText ( histo , width , 150 , errors , stream ) ; }
446  if ( 20 > height ) { return dumpText ( histo , width , 20 , errors , stream ) ; }
447  if ( height > width ) { return dumpText ( histo , width , width , errors , stream ) ; }
448  //
449  const unsigned int nBins = histo.bins.size() ;
450  if ( nBins > width )
451  {
452  // rebin histogram
453  Histo r = histo.rebin ( rebin ( nBins , width ) ) ;
454  return dumpText ( r , width , height , errors , stream ) ;
455  }
456  //
457  // get the Y-scale
458  double yMax = std::max ( rValMax ( histo.maxY ( errors ) ) , 0.0 ) ;
459  double yMin = std::min ( rValMin ( histo.minY ( errors ) ) , 0.0 ) ;
460 
461  if ( yMin == yMax ) { yMax = yMin + 1 ; }
463  std::pair<double,int> r = decompose ( yMax - yMin ) ;
464  double _ny = std::ceil ( 10 * r.first ) ; // 1 <= ny < 10
465  if ( 1 >= _ny ) { _ny = 10 ; }
466  int yBins = (int) std::max ( 1. , std::ceil ( height / _ny ) ) ;
467 
468  yBins *= (int) _ny ;
469  if ( 20 > yBins ) { yBins = 20 ; }
470  const double yScale = ( yMax - yMin ) / yBins ;
471 
472  //
473  const int ySkip =
474  0 == yBins % 13 ? 13 :
475  0 == yBins % 11 ? 11 :
476  0 == yBins % 9 ? 9 :
477  0 == yBins % 8 ? 8 :
478  0 == yBins % 7 ? 7 :
479  0 == yBins % 6 ? 6 :
480  0 == yBins % 5 ? 5 :
481  0 == yBins % 4 ? 4 : 10 ;
482 
483  const int xSkip =
484  // 0 == nBins % 8 ? 8 :
485  0 == nBins % 7 ? 7 :
486  0 == nBins % 6 ? 6 :
487  0 == nBins % 5 ? 5 :
488  0 == nBins % 4 ? 4 : 10 ;
489 
490  int iNull = histo.nullBin() ;
491 
492  if ( 0 <= iNull ) { iNull %= xSkip ; }
493  else { iNull = 0 ; }
494 
495  stream << std::endl ;
496 
497  for ( int yLine = -1 ; yLine < yBins ; ++yLine )
498  {
499  const double yHigh = yMax - yScale * yLine ;
500  // const double yLow = yHigh - yScale ;
501  const double yLow = yMax - yScale * ( yLine + 1 ) ;
502  //
503  std::string line1 = " " ;
504 
505  const bool ynull = ( yLow <= 0 && 0 < yHigh ) ;
506  const bool yfirst = -1 == yLine || yBins -1 == yLine ;
507  const bool ylab =
508  ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull ;
509 
510  if ( ylab ) { line1 += yLabel ( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow ) ; }
511  else { line1 += std::string( 10 , ' ' ) ; }
512  //
513  line1 += " " ;
514  //
516  line1 += symbBin ( histo.under , yLow , yHigh , ynull , errors ) ;
517  //
518  line1 +=
519  ynull ? "-+" :
520  ylab ? " +" : " |" ;
521  //
522  std::string line2 ;
523  //
524  for ( Histo::Bins::const_iterator ibin = histo.bins.begin() ;
525  histo.bins.end() != ibin ; ++ibin )
526  {
527  //char symb = ' ' ;
528  const int i = ibin - histo.bins.begin () ;
529  //
530  const bool xnull =
531  ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.end() && 0 < (ibin+1)->lower ;
532  const bool xlab = iNull == i % xSkip ;
533  //
534  char symb = symbBin ( *ibin, yLow , yHigh , ynull , errors ) ;
535  //
536  if ( ' ' == symb )
537  {
538  if ( ( ynull || yfirst ) && xlab ) { symb = '+' ; }
539  else if ( ynull || yfirst ) { symb = '-' ; }
540  //
541  else if ( ylab && xnull ) { symb = '+' ; }
542  else if ( xnull ) { symb = '|' ; }
543  //
544  else if ( ylab || xlab ) { symb = '.' ; }
545  //
546  }
547  line2 += symb ;
548  //
549  }
550  //
551  std::string line3 =
552  ynull ? "->" :
553  ylab ? "+ " : "| " ;
554  //
556  line3 += symbBin ( histo.over , yLow , yHigh , ynull , errors ) ;
557  //
558  stream << line1 << line2 << line3 << std::endl ;
559  //
560  }
561 
562  // get x-labels
563  std::vector<std::string> xlabels ;
564  for ( Histo::Bins::const_iterator ib = histo.bins.begin() ; histo.bins.end() != ib ; ++ib )
565  { xlabels.push_back ( xLabel ( ib->lower ) ) ; }
566  // overflow& underflow label
567  const std::string oLabel = xLabel ( histo.over.lower ) ;
568  const std::string uLabel = xLabel ( histo.under.lower ) ;
569  //
570  static const std::string s_UNDERFLOW ( "UNDERFLOW" ) ;
571  static const std::string s_OVERFLOW ( " OVERFLOW" ) ;
572  //
573  //
574  for ( unsigned int yLine = 0 ; yLine < 12 ; ++yLine )
575  {
576  std::string line = std::string ( 12 , ' ' ) ;
577  //
578  if ( yLine < s_UNDERFLOW.size() ) { line += s_UNDERFLOW[yLine] ; }
579  else { line += ' ' ; }
580  //
581  line += ' ' ;
582  //
583  if ( uLabel.size() > yLine ) { line += uLabel[yLine] ; }
584  else { line += ' ' ; }
585  //
586  for ( Histo::Bins::const_iterator ibin = histo.bins.begin() ; histo.bins.end() != ibin ; ++ibin )
587  {
588  int ib = ibin - histo.bins.begin() ;
589  const bool xlab = ( iNull == ib % xSkip ) ;
590  if ( xlab && yLine < xlabels[ib].size() ) { line += xlabels[ib][yLine] ; }
591  else { line += ' ' ; }
592  }
593  //
594  if ( oLabel.size() > yLine ) { line += oLabel[yLine] ; }
595  else { line += ' ' ; }
596  //
597  line += ' ' ;
598  //
599  if ( yLine < s_OVERFLOW.size() ) { line += s_OVERFLOW[yLine] ; }
600  else { line += ' ' ; }
601  //
602  stream << line << std::endl ;
603  }
604  //
605  return stream ; // RETURN
606  }
607 }
608 // ============================================================================
609 /* dump the text representation of the histogram
610  * @param histo (INPUT) the histogram
611  * @param stream (OUTUT) the stream
612  * @param width (INPUT) the maximal column width
613  * @param height (INPUT) the proposed coulmn height
614  * @param errors (INPUT) print/plot errors
615  * @return the stream
616  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
617  * @date 2009-09-19
618  */
619 // ============================================================================
621 ( const AIDA::IHistogram1D* histo ,
622  std::ostream& stream ,
623  const std::size_t width ,
624  const std::size_t height ,
625  const bool errors )
626 {
627  stream << std::endl ;
628  if ( 0 == histo ) { return stream ; } // RETURN
629  Histo hist ;
630  StatusCode sc = _getHisto ( histo , hist ) ;
631  if ( sc.isFailure() ) { return stream ; } // RETURN
632  //
633  stream
634  << boost::format ( " Histo TES : \"%s\"") % path ( histo )
635  << std::endl
636  << boost::format ( " Histo Title : \"%s\"") % histo->title()
637  << std::endl
638  << std::endl ;
639  //
640  stream
641  << boost::format ( " Mean : %11.5g +- %-10.4g ")
644  << std::endl
645  << boost::format ( " Rms : %11.5g +- %-10.4g ")
648  << std::endl
649  << boost::format ( " Skewness : %11.5g +- %-10.4g ")
652  << std::endl
653  << boost::format ( " Kurtosis : %11.5g +- %-10.4g ")
656  << std::endl
657  << std::endl ;
658  //
659  stream
660  << boost::format ( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s | %=11s |")
661  % "All"
662  % "In Range"
663  % "Underflow"
664  % "Overflow"
665  % "#Equivalent"
666  % "Integral"
667  % "Total"
668  << std::endl
669  << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g | %=11.5g |")
670  % histo -> allEntries ()
671  % histo -> entries ()
672  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
673  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
674  % histo -> equivalentBinEntries ()
675  % histo -> sumBinHeights ()
676  % histo -> sumAllBinHeights ()
677  << std::endl
678  << std::endl ;
679  //
680  const AIDA::IAnnotation& a = histo->annotation () ;
681  if ( 0 != a.size() )
682  {
683  stream << " Annotation" << std::endl ;
684  for ( int i = 0 ; i < a.size() ; ++i )
685  {
686  stream
687  << boost::format ( " | %-25.25s : %-45.45s | ")
688  % a.key ( i )
689  % a.value ( i )
690  << std::endl ;
691  }
692  stream << std::endl ;
693  }
694  //
695  return dumpText ( hist , width , height , errors , stream ) ;
696 }
697 // ============================================================================
698 /* dump the text representation of the histogram
699  * @param histo the histogram
700  * @param stream the stream
701  * @param width the maximal column width
702  * @param height (INPUT) the proposed coulmn height
703  * @param errors (INPUT) print/plot errors
704  * @param erorrs print/plot errors
705  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
706  * @date 2009-09-19
707  */
708 // ============================================================================
710 ( const AIDA::IHistogram1D* histo ,
711  const std::size_t width ,
712  const std::size_t height ,
713  const bool errors )
714 {
715  std::ostringstream stream ;
716  histoDump_ ( histo , stream , width , height , errors );
717  return stream.str() ;
718 }
719 // ============================================================================
720 /* dump the text representation of the 1D-profile
721  * @param histo (INPUT) the profile
722  * @param stream (OUTUT) the stream
723  * @param width (INPUT) the maximal column width
724  * @param height (INPUT) the proposed coulmn height
725  * @param spread (INPUT) plot spread/error?
726  * @return the stream
727  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
728  * @date 2009-09-19
729  */
730 // ============================================================================
732 ( const AIDA::IProfile1D* histo ,
733  std::ostream& stream ,
734  const std::size_t width ,
735  const std::size_t height ,
736  const bool spread )
737 {
738  stream << std::endl ;
739  if ( 0 == histo ) { return stream ; } // RETURN
740  Histo hist ;
741  StatusCode sc = _getHisto ( histo , hist , spread ) ;
742  if ( sc.isFailure() ) { return stream ; } // RETURN
743  //
744  stream
745  << boost::format ( " Histo TES : \"%s\"") % path ( histo )
746  << std::endl
747  << boost::format ( " Histo Title : \"%s\"") % histo->title()
748  << std::endl
749  << std::endl ;
750  //
751  stream
752  << boost::format ( " Mean : %11.5g ") % histo->mean()
753  << std::endl
754  << boost::format ( " Rms : %11.5g ") % histo->rms ()
755  << std::endl
756  << std::endl ;
757  //
758  stream
759  << boost::format ( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s |")
760  % "All"
761  % "In Range"
762  % "Underflow"
763  % "Overflow"
764  // % "#Equivalent"
765  % "Integral"
766  % "Total"
767  << std::endl
768  << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g |")
769  % histo -> allEntries ()
770  % histo -> entries ()
771  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
772  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
773  // % histo -> equivalentBinEntries ()
774  % histo -> sumBinHeights ()
775  % histo -> sumAllBinHeights ()
776  << std::endl
777  << std::endl ;
778  //
779  const AIDA::IAnnotation& a = histo->annotation () ;
780  if ( 0 != a.size() )
781  {
782  stream << " Annotation" << std::endl ;
783  for ( int i = 0 ; i < a.size() ; ++i )
784  {
785  stream
786  << boost::format ( " | %-25.25s : %-45.45s | ")
787  % a.key ( i )
788  % a.value ( i )
789  << std::endl ;
790  }
791  stream << std::endl ;
792  }
793  //
794  return dumpText ( hist , width , height , true , stream ) ;
795 }
796 // ============================================================================
797 /* dump the text representation of the 1D-profile
798  * @param histo the histogram
799  * @param stream the stream
800  * @param width the maximal column width
801  * @param height (INPUT) the proposed coulmn height
802  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
803  * @date 2009-09-19
804  */
805 // ============================================================================
807 ( const AIDA::IProfile1D* histo ,
808  const std::size_t width ,
809  const std::size_t height ,
810  const bool spread )
811 {
812  std::ostringstream stream ;
813  histoDump_ ( histo , stream , width , height , spread );
814  return stream.str() ;
815 }
816 // ============================================================================
817 /* dump the text representation of the histogram
818  * @param histo (INPUT) the histogram
819  * @param stream (OUTUT) the stream
820  * @param width (INPUT) the maximal column width
821  * @param errors (INPUT) print/plot errors
822  * @return the stream
823  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
824  * @date 2009-09-19
825  */
826 // ============================================================================
828 ( const TH1* histo ,
829  std::ostream& stream ,
830  const std::size_t width ,
831  const std::size_t height ,
832  const bool errors )
833 {
834  const TProfile* profile = dynamic_cast<const TProfile*> ( histo ) ;
835  if ( 0 != profile )
836  { return histoDump_ ( profile , stream , width , height ) ; }
837  //
838  stream << std::endl ;
839  if ( 0 == histo ) { return stream ; } // RETURN
840  Histo hist ;
841  StatusCode sc = _getHisto ( histo , hist ) ;
842  if ( sc.isFailure() ) { return stream ; } // RETURN
843  //
844  stream
845  << boost::format ( " Histo Name : \"%s\"")
846  % histo -> GetName ()
847  << std::endl
848  << boost::format ( " Histo Title : \"%s\"")
849  % histo -> GetTitle ()
850  << std::endl
851  << std::endl ;
852  //
853  stream
854  << boost::format ( " Mean : %11.5g +- %-10.4g ")
855  % histo -> GetMean ()
856  % histo -> GetMeanError ()
857  << std::endl
858  << boost::format ( " Rms : %11.5g +- %-10.4g ")
859  % histo -> GetRMS ()
860  % histo -> GetRMSError ()
861  << std::endl
862  << boost::format ( " Skewness : %11.5g ")
863  % histo -> GetSkewness ()
864  << std::endl
865  << boost::format ( " Kurtosis : %11.5g ")
866  % histo -> GetKurtosis ()
867  << std::endl
868  << std::endl ;
869  //
870  stream
871  << boost::format ( " Entries :\n | %=11s | %=11s | %=11s | %=11s | %=11s |")
872  % "All"
873  % "Underflow"
874  % "Overflow"
875  % "#Equivalent"
876  % "Integral"
877  << std::endl
878  << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g | %=11.5g |")
879  % histo -> GetEntries ()
880  % histo -> GetBinContent ( 0 )
881  % histo -> GetBinContent ( histo->GetNbinsX() + 1 )
882  % histo -> GetEffectiveEntries ()
883  % histo -> Integral ()
884  << std::endl
885  << std::endl ;
886  //
887  return dumpText ( hist , width , height , errors , stream ) ;
888 }
889 // ============================================================================
890 /* dump the text representation of the histogram
891  * @param histo (INPUT) the histogram
892  * @param stream (OUTUT) the stream
893  * @param width (INPUT) the maximal column width
894  * @param errors (INPUT) print/plot errors
895  * @return the stream
896  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
897  * @date 2009-09-19
898  */
899 // ============================================================================
901 ( const TProfile* histo ,
902  std::ostream& stream ,
903  const std::size_t width ,
904  const std::size_t height )
905 {
906  stream << std::endl ;
907  if ( 0 == histo ) { return stream ; } // RETURN
908  Histo hist ;
909  StatusCode sc = _getHisto ( histo , hist , true ) ;
910  if ( sc.isFailure() ) { return stream ; } // RETURN
911  //
912  stream
913  << boost::format ( " Profile Name : \"%s\"")
914  % histo -> GetName ()
915  << std::endl
916  << boost::format ( " Profile Title : \"%s\"")
917  % histo -> GetTitle ()
918  << std::endl
919  << std::endl ;
920  //
921  stream
922  << boost::format ( " Mean : %11.5g ") % histo -> GetMean ()
923  << std::endl
924  << boost::format ( " Rms : %11.5g ") % histo -> GetRMS ()
925  << std::endl
926  << std::endl ;
927  //
928  stream
929  << boost::format ( " Entries :\n | %=11s | %=11s | %=11s | %=11s |")
930  % "All"
931  % "Underflow"
932  % "Overflow"
933  % "Integral"
934  << std::endl
935  << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g |")
936  % histo -> GetEntries ()
937  % histo -> GetBinContent ( 0 )
938  % histo -> GetBinContent ( histo->GetNbinsX() + 1 )
939  % histo -> Integral ()
940  << std::endl
941  << std::endl ;
942  //
943  return dumpText ( hist , width , height , true , stream ) ;
944 }
945 // ============================================================================
946 /* dump the text representation of the histogram
947  * @param histo (INPUT) the histogram
948  * @param width (INPUT) the maximal column width
949  * @param errors (INPUT) print/plot errors
950  * @return string representation of the histogram
951  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
952  * @date 2009-09-19
953  */
954 // ============================================================================
956 ( const TH1* histo ,
957  const std::size_t width ,
958  const std::size_t height ,
959  const bool errors )
960 {
961  std::ostringstream stream ;
962  histoDump_ ( histo , stream , width , height , errors );
963  return stream.str() ;
964 }
965 // ============================================================================
966 /* dump the text representation of the histogram
967  * @param histo (INPUT) the histogram
968  * @param width (INPUT) the maximal column width
969  * @param errors (INPUT) print/plot errors
970  * @return string representation of the histogram
971  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
972  * @date 2009-09-19
973  */
974 // ============================================================================
976 ( const TProfile* histo ,
977  const std::size_t width ,
978  const std::size_t height )
979 {
980  std::ostringstream stream ;
981  histoDump_ ( histo , stream , width , height );
982  return stream.str() ;
983 }
984 // ============================================================================
985 
986 
987 
988 
989 // ============================================================================
990 // The END
991 // ============================================================================
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:255
GAUDI_API std::ostream & histoDump_(const AIDA::IHistogram1D *histo, std::ostream &stream, const std::size_t width=80, const std::size_t height=50, const bool errors=false)
dump the text representation of the histogram
Definition: HistoDump.cpp:621
GAUDI_API std::string histoDump(const AIDA::IHistogram1D *histo, const std::size_t width=80, const std::size_t height=50, const bool errors=false)
dump the text representation of the histogram
Definition: HistoDump.cpp:710
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:236
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
Definition: HistoStats.cpp:246
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
dictionary l
Definition: gaudirun.py:365
#define min(a, b)
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:203
GAUDI_API double Integral(const Genfun::AbsFunction &function, const double a, const double b, const GaudiMath::Integration::Type type=GaudiMath::Integration::Adaptive, const GaudiMath::Integration::KronrodRule rule=GaudiMath::Integration::Default, const double epsabs=1.e-10, const double epsrel=1.e-7, const size_t size=1000)
Definition: Integral.cpp:28
tuple root
Definition: IOTest.py:42
static double mean(const AIDA::IHistogram1D *histo)
get the mean value for the histogram (just for completeness)
Definition: HistoStats.cpp:227
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:178
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:192
list i
Definition: ana.py:128
int line
Definition: ana.py:50
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:167