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