All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 #include <numeric>
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() = default;
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  return std::accumulate( std::begin(bins), std::end(bins),
103  std::max ( under.height, over.height ),
104  [&](double m, const Bin& b) {
105  return std::max ( m, withErr ? b.height + b.error : b.height ) ;
106  });
107  }
109  double minY ( const bool withErr ) const
110  {
111  return std::accumulate( std::begin(bins), std::end(bins),
112  std::min ( under.height, over.height ),
113  [&](double m, const Bin& b) {
114  return std::min ( m, withErr ? b.height - b.error : b.height ) ;
115  });
116  }
118  Histo rebin ( const unsigned int bin ) const
119  {
120  // create new histogram
121  Histo nh ;
122  // copy overflow & underflow bins
123  nh.under = under ;
124  nh.over = over ;
125  // rebin
126  for ( unsigned int ibin = 0 ; ibin < bins.size() ; ++ibin )
127  {
128  const Bin& current = bins[ibin] ;
129  if ( nh.bins.empty() ) { nh.bins.push_back ( current ) ; }
130  else if ( 0 == ibin % bin ) { nh.bins.push_back ( current ) ; }
131  else { nh.bins.back() += current ; }
132  }
133  return nh ;
134  }
135  // find "null-bin", if any
136  int nullBin () const
137  {
138  for ( auto ib = bins.cbegin() ; bins.cend() != ib + 1 ; ++ib )
139  { if ( ib->lower <= 0 && 0 < (ib+1)->lower ) { return ib - bins.cbegin() ; } }
140  return -1 ;
141  }
142  // ========================================================================
143  typedef std::vector<Bin> Bins ;
144  // ========================================================================
146  Bins bins ; // histogram bins
148  Bin under ; // underflow bin
150  Bin over ; // overflow bin
151  // ========================================================================
152  } ;
153  // ==========================================================================
161  StatusCode _getHisto ( const TH1* root , Histo& hist )
162  {
163  // clear the histogram
164  hist.bins.clear() ;
165  //
166  if ( !root ) { return StatusCode::FAILURE ; } // RETURN
167  const TAxis* axis = root->GetXaxis() ;
168  if ( !axis ) { return StatusCode::FAILURE ; } // RETURN
169  const int nbins = axis->GetNbins () ;
170  if ( 0 == nbins ) { return StatusCode::FAILURE ; } // RETURN
171 
172  // underflow bin
173  hist.under = Histo::Bin ( root -> GetBinContent ( 0 ) ,
174  root -> GetBinError ( 0 ) ,
175  axis -> GetXmin () ) ;
176  // overflow bin
177  hist.over = Histo::Bin ( root -> GetBinContent ( nbins + 1 ) ,
178  root -> GetBinError ( nbins + 1 ) ,
179  axis -> GetXmax () ) ;
180  //
181  //
182  for ( int ibin = 1 ; ibin <= nbins ; ++ibin )
183  {
184  // add to the local histo
185  hist.bins.emplace_back( root -> GetBinContent ( ibin ) ,
186  root -> GetBinError ( ibin ) ,
187  axis -> GetBinLowEdge ( ibin ) ) ;
188  }
189  return StatusCode::SUCCESS ;
190  }
191  // ==========================================================================
199  StatusCode _getHisto ( const TProfile* root ,
200  Histo& hist ,
201  const bool /* spread */ )
202  {
203  const TH1* histo = root ;
204  return _getHisto ( histo , hist ) ;
205  }
206  // ==========================================================================
214  StatusCode _getHisto
215  ( const AIDA::IHistogram1D* aida , Histo& hist )
216  {
217  // clear the histogram
218  hist.bins.clear() ;
219  //
220  if ( !aida ) { return StatusCode::FAILURE ; } // RETURN
221  //
222  const AIDA::IAxis& axis = aida -> axis () ;
223  const int nbins = axis . bins () ;
224  //
225  // underflow bin
226  hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) ,
227  aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) ,
228  axis . lowerEdge () ) ;
229  // overflow bin
230  hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) ,
231  aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) ,
232  axis . upperEdge () ) ;
233  //
234  for ( int ibin = 0 ; ibin < nbins ; ++ibin )
235  {
236  // add to the local histo
237  hist.bins.emplace_back ( aida -> binHeight ( ibin ) ,
238  aida -> binError ( ibin ) ,
239  axis . binLowerEdge ( ibin ) ) ;
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 ( !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  hist.bins.emplace_back( aida -> binHeight ( ibin ) ,
281  spread ?
282  aida -> binRms ( ibin ) :
283  aida -> binError ( ibin ) ,
284  axis . binLowerEdge ( ibin ) ) ;
285  }
286  return StatusCode::SUCCESS ;
287  }
288  // ==========================================================================
294  inline unsigned int rebin
295  ( const unsigned int bins ,
296  const unsigned int imax )
297  {
298  if ( 0 == imax ) { return 1 ; } // RETURN
299  unsigned int ibin = 1 ;
300  while ( bins > imax * ibin ) { ++ibin ; }
301  return ibin ; // RETURN
302  }
303  // ==========================================================================
309  std::pair<double,int> decompose ( double v )
310  {
311  if ( 0 == v ) { return { 0.0 , 0 } ; } // RETURN
312  else if ( 1 == v ) { return { 1.0 , 0 } ; } // RETURN
313  else if ( 0 > v )
314  {
315  auto r = decompose ( -v ) ;
316  return { -r.first , r.second } ; // RETURN
317  }
318  else if ( 0.1 > v )
319  {
320  int i = 0 ;
321  while ( 0.1 > v ) { ++i ; v *= 10 ; } // STUPID
322  return { v , -i } ;
323  }
324  else if ( 1 < v )
325  {
326  int i = 0 ;
327  while ( 1 <= v ) { ++i ; v /= 10 ; } // STUPID
328  return { v , i } ;
329  }
330  return { v , 1 } ;
331  }
332  // ==========================================================================
337  inline double _pow ( double x , unsigned long n )
338  {
339  double y = n % 2 ? x : 1;
340  while ( n >>= 1 )
341  {
342  x = x * x;
343  if ( n % 2) { y *= x; }
344  }
345  return y ;
346  }
347  // forward declaration to break cyclic dependency between rValMin and rValMax
348  inline double rValMin ( double v );
349  // ==========================================================================
354  inline double rValMax ( double v )
355  {
356  if ( 0 == v ) { return 0 ; } // RETURN
357  else if ( 0 > v ) { return -1 * rValMin ( -v ) ; } // RETURN
358  // decompose the double value into decimal significand and mantissa
359  std::pair<double,int> r = decompose ( v ) ;
360  //
361  const double f = std::ceil ( 20 * r.first ) / 2 ; // + 1 ;
362  const int l = r.second - 1 ;
363  return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ;
364  }
365  // ==========================================================================
370  inline double rValMin ( double v )
371  {
372  if ( 0 == v ) { return 0 ; } // RETURN
373  else if ( 0 > v ) { return -1 * rValMax ( -v ) ; } // RETURN
374  // decompose the double value into decimal significand and mantissa
375  std::pair<double,int> r = decompose ( v ) ;
376  const double f = std::floor ( 20 * r.first ) / 2 ; // - 1 ;
377  const int l = r.second - 1 ;
378  return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ;
379  }
380  // ==========================================================================
385  inline std::string yLabel ( double value )
386  {
387  boost::format fmt ( "%10.3g" ) ;
388  fmt % value ;
389  return fmt.str () ;
390  }
391  // ==========================================================================
396  inline std::string xLabel ( const double value )
397  {
398  boost::format fmt ( "%9.3g" ) ;
399  fmt % value ;
400  return fmt.str () ;
401  }
402  // ==========================================================================
404  char symbBin ( const Histo::Bin& bin ,
405  const double yLow ,
406  const double yHigh ,
407  const bool yNull ,
408  const bool errors )
409  {
410  if ( errors && yLow <= bin.height && bin.height < yHigh ) { return '*' ; } // O
411  else if ( errors && yHigh < bin.height - bin.error ) { return ' ' ; }
412  else if ( errors && yLow >= bin.height + bin.error ) { return ' ' ; }
413  else if ( errors ) { return 'I' ; }
414  else if ( yLow <= bin.height && bin.height < yHigh ) { return '*' ; }
415  else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) { return '*' ; } // +
416  else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) { return '*' ; } // -
417  //
418  return ' ' ;
419  }
420  // ==========================================================================
425  std::ostream& dumpText
426  ( const Histo& histo ,
427  const std::size_t width ,
428  const std::size_t height ,
429  const bool errors ,
430  std::ostream& stream )
431  {
432  if ( 40 > width ) { return dumpText ( histo , 40 , height , errors , stream ) ; }
433  if ( 200 < width ) { return dumpText ( histo , 200 , height , errors , stream ) ; }
434  if ( 150 < height ) { return dumpText ( histo , width , 150 , errors , stream ) ; }
435  if ( 20 > height ) { return dumpText ( histo , width , 20 , errors , stream ) ; }
436  if ( height > width ) { return dumpText ( histo , width , width , errors , stream ) ; }
437  //
438  const unsigned int nBins = histo.bins.size() ;
439  if ( nBins > width )
440  {
441  // rebin histogram
442  Histo r = histo.rebin ( rebin ( nBins , width ) ) ;
443  return dumpText ( r , width , height , errors , stream ) ;
444  }
445  //
446  // get the Y-scale
447  double yMax = std::max ( rValMax ( histo.maxY ( errors ) ) , 0.0 ) ;
448  double yMin = std::min ( rValMin ( histo.minY ( errors ) ) , 0.0 ) ;
449 
450  if ( yMin == yMax ) { yMax = yMin + 1 ; }
452  std::pair<double,int> r = decompose ( yMax - yMin ) ;
453  double _ny = std::ceil ( 10 * r.first ) ; // 1 <= ny < 10
454  if ( 1 >= _ny ) { _ny = 10 ; }
455  int yBins = (int) std::max ( 1. , std::ceil ( height / _ny ) ) ;
456 
457  yBins *= (int) _ny ;
458  if ( 20 > yBins ) { yBins = 20 ; }
459  const double yScale = ( yMax - yMin ) / yBins ;
460 
461  //
462  const int ySkip =
463  0 == yBins % 13 ? 13 :
464  0 == yBins % 11 ? 11 :
465  0 == yBins % 9 ? 9 :
466  0 == yBins % 8 ? 8 :
467  0 == yBins % 7 ? 7 :
468  0 == yBins % 6 ? 6 :
469  0 == yBins % 5 ? 5 :
470  0 == yBins % 4 ? 4 : 10 ;
471 
472  const int xSkip =
473  // 0 == nBins % 8 ? 8 :
474  0 == nBins % 7 ? 7 :
475  0 == nBins % 6 ? 6 :
476  0 == nBins % 5 ? 5 :
477  0 == nBins % 4 ? 4 : 10 ;
478 
479  int iNull = histo.nullBin() ;
480 
481  if ( 0 <= iNull ) { iNull %= xSkip ; }
482  else { iNull = 0 ; }
483 
484  stream << std::endl ;
485 
486  for ( int yLine = -1 ; yLine < yBins ; ++yLine )
487  {
488  const double yHigh = yMax - yScale * yLine ;
489  // const double yLow = yHigh - yScale ;
490  const double yLow = yMax - yScale * ( yLine + 1 ) ;
491  //
492  std::string line1 = " " ;
493 
494  const bool ynull = ( yLow <= 0 && 0 < yHigh ) ;
495  const bool yfirst = -1 == yLine || yBins -1 == yLine ;
496  const bool ylab =
497  ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull ;
498 
499  if ( ylab ) { line1 += yLabel ( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow ) ; }
500  else { line1 += std::string( 10 , ' ' ) ; }
501  //
502  line1 += " " ;
503  //
505  line1 += symbBin ( histo.under , yLow , yHigh , ynull , errors ) ;
506  //
507  line1 +=
508  ynull ? "-+" :
509  ylab ? " +" : " |" ;
510  //
511  std::string line2 ;
512  //
513  for ( auto ibin = histo.bins.cbegin() ;
514  histo.bins.cend() != ibin ; ++ibin )
515  {
516  //char symb = ' ' ;
517  const int i = ibin - histo.bins.cbegin () ;
518  //
519  const bool xnull =
520  ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.cend() && 0 < (ibin+1)->lower ;
521  const bool xlab = iNull == i % xSkip ;
522  //
523  char symb = symbBin ( *ibin, yLow , yHigh , ynull , errors ) ;
524  //
525  if ( ' ' == symb )
526  {
527  if ( ( ynull || yfirst ) && xlab ) { symb = '+' ; }
528  else if ( ynull || yfirst ) { symb = '-' ; }
529  //
530  else if ( ylab && xnull ) { symb = '+' ; }
531  else if ( xnull ) { symb = '|' ; }
532  //
533  else if ( ylab || xlab ) { symb = '.' ; }
534  //
535  }
536  line2 += symb ;
537  //
538  }
539  //
540  std::string line3 =
541  ynull ? "->" :
542  ylab ? "+ " : "| " ;
543  //
545  line3 += symbBin ( histo.over , yLow , yHigh , ynull , errors ) ;
546  //
547  stream << line1 << line2 << line3 << std::endl ;
548  //
549  }
550 
551  // get x-labels
552  std::vector<std::string> xlabels ;
553  for ( auto ib = histo.bins.cbegin() ; histo.bins.cend() != ib ; ++ib )
554  { xlabels.push_back ( xLabel ( ib->lower ) ) ; }
555  // overflow& underflow label
556  const std::string oLabel = xLabel ( histo.over.lower ) ;
557  const std::string uLabel = xLabel ( histo.under.lower ) ;
558  //
559  static const std::string s_UNDERFLOW ( "UNDERFLOW" ) ;
560  static const std::string s_OVERFLOW ( " OVERFLOW" ) ;
561  //
562  //
563  for ( unsigned int yLine = 0 ; yLine < 12 ; ++yLine )
564  {
565  std::string line = std::string ( 12 , ' ' ) ;
566  //
567  if ( yLine < s_UNDERFLOW.size() ) { line += s_UNDERFLOW[yLine] ; }
568  else { line += ' ' ; }
569  //
570  line += ' ' ;
571  //
572  if ( uLabel.size() > yLine ) { line += uLabel[yLine] ; }
573  else { line += ' ' ; }
574  //
575  for ( auto ibin = histo.bins.cbegin() ; histo.bins.cend() != ibin ; ++ibin )
576  {
577  int ib = ibin - histo.bins.cbegin() ;
578  const bool xlab = ( iNull == ib % xSkip ) ;
579  if ( xlab && yLine < xlabels[ib].size() ) { line += xlabels[ib][yLine] ; }
580  else { line += ' ' ; }
581  }
582  //
583  if ( oLabel.size() > yLine ) { line += oLabel[yLine] ; }
584  else { line += ' ' ; }
585  //
586  line += ' ' ;
587  //
588  if ( yLine < s_OVERFLOW.size() ) { line += s_OVERFLOW[yLine] ; }
589  else { line += ' ' ; }
590  //
591  stream << line << std::endl ;
592  }
593  //
594  return stream ; // RETURN
595  }
596 }
597 // ============================================================================
598 /* dump the text representation of the histogram
599  * @param histo (INPUT) the histogram
600  * @param stream (OUTUT) the stream
601  * @param width (INPUT) the maximal column width
602  * @param height (INPUT) the proposed coulmn height
603  * @param errors (INPUT) print/plot errors
604  * @return the stream
605  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
606  * @date 2009-09-19
607  */
608 // ============================================================================
610 ( const AIDA::IHistogram1D* histo ,
611  std::ostream& stream ,
612  const std::size_t width ,
613  const std::size_t height ,
614  const bool errors )
615 {
616  stream << std::endl ;
617  if ( !histo ) { return stream ; } // RETURN
618  Histo hist ;
619  StatusCode sc = _getHisto ( histo , hist ) ;
620  if ( sc.isFailure() ) { return stream ; } // RETURN
621  //
622  stream
623  << boost::format ( " Histo TES : \"%s\"") % path ( histo )
624  << std::endl
625  << boost::format ( " Histo Title : \"%s\"") % histo->title()
626  << std::endl
627  << std::endl ;
628  //
629  stream
630  << boost::format ( " Mean : %11.5g +- %-10.4g ")
633  << std::endl
634  << boost::format ( " Rms : %11.5g +- %-10.4g ")
637  << std::endl
638  << boost::format ( " Skewness : %11.5g +- %-10.4g ")
641  << std::endl
642  << boost::format ( " Kurtosis : %11.5g +- %-10.4g ")
645  << std::endl
646  << std::endl ;
647  //
648  stream
649  << boost::format ( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s | %=11s |")
650  % "All"
651  % "In Range"
652  % "Underflow"
653  % "Overflow"
654  % "#Equivalent"
655  % "Integral"
656  % "Total"
657  << std::endl
658  << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g | %=11.5g |")
659  % histo -> allEntries ()
660  % histo -> entries ()
661  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
662  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
663  % histo -> equivalentBinEntries ()
664  % histo -> sumBinHeights ()
665  % histo -> sumAllBinHeights ()
666  << std::endl
667  << std::endl ;
668  //
669  const AIDA::IAnnotation& a = histo->annotation () ;
670  if ( 0 != a.size() )
671  {
672  stream << " Annotation" << std::endl ;
673  for ( int i = 0 ; i < a.size() ; ++i )
674  {
675  stream
676  << boost::format ( " | %-25.25s : %-45.45s | ")
677  % a.key ( i )
678  % a.value ( i )
679  << std::endl ;
680  }
681  stream << std::endl ;
682  }
683  //
684  return dumpText ( hist , width , height , errors , stream ) ;
685 }
686 // ============================================================================
687 /* dump the text representation of the histogram
688  * @param histo the histogram
689  * @param stream the stream
690  * @param width the maximal column width
691  * @param height (INPUT) the proposed coulmn height
692  * @param errors (INPUT) print/plot errors
693  * @param erorrs print/plot errors
694  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
695  * @date 2009-09-19
696  */
697 // ============================================================================
699 ( const AIDA::IHistogram1D* histo ,
700  const std::size_t width ,
701  const std::size_t height ,
702  const bool errors )
703 {
704  std::ostringstream stream ;
705  histoDump_ ( histo , stream , width , height , errors );
706  return stream.str() ;
707 }
708 // ============================================================================
709 /* dump the text representation of the 1D-profile
710  * @param histo (INPUT) the profile
711  * @param stream (OUTUT) the stream
712  * @param width (INPUT) the maximal column width
713  * @param height (INPUT) the proposed coulmn height
714  * @param spread (INPUT) plot spread/error?
715  * @return the stream
716  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
717  * @date 2009-09-19
718  */
719 // ============================================================================
721 ( const AIDA::IProfile1D* histo ,
722  std::ostream& stream ,
723  const std::size_t width ,
724  const std::size_t height ,
725  const bool spread )
726 {
727  stream << std::endl ;
728  if ( !histo ) { return stream ; } // RETURN
729  Histo hist ;
730  StatusCode sc = _getHisto ( histo , hist , spread ) ;
731  if ( sc.isFailure() ) { return stream ; } // RETURN
732  //
733  stream
734  << boost::format ( " Histo TES : \"%s\"") % path ( histo )
735  << std::endl
736  << boost::format ( " Histo Title : \"%s\"") % histo->title()
737  << std::endl
738  << std::endl ;
739  //
740  stream
741  << boost::format ( " Mean : %11.5g ") % histo->mean()
742  << std::endl
743  << boost::format ( " Rms : %11.5g ") % histo->rms ()
744  << std::endl
745  << std::endl ;
746  //
747  stream
748  << boost::format ( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s |")
749  % "All"
750  % "In Range"
751  % "Underflow"
752  % "Overflow"
753  // % "#Equivalent"
754  % "Integral"
755  % "Total"
756  << std::endl
757  << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g |")
758  % histo -> allEntries ()
759  % histo -> entries ()
760  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
761  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
762  // % histo -> equivalentBinEntries ()
763  % histo -> sumBinHeights ()
764  % histo -> sumAllBinHeights ()
765  << std::endl
766  << std::endl ;
767  //
768  const AIDA::IAnnotation& a = histo->annotation () ;
769  if ( 0 != a.size() )
770  {
771  stream << " Annotation" << std::endl ;
772  for ( int i = 0 ; i < a.size() ; ++i )
773  {
774  stream
775  << boost::format ( " | %-25.25s : %-45.45s | ")
776  % a.key ( i )
777  % a.value ( i )
778  << std::endl ;
779  }
780  stream << std::endl ;
781  }
782  //
783  return dumpText ( hist , width , height , true , stream ) ;
784 }
785 // ============================================================================
786 /* dump the text representation of the 1D-profile
787  * @param histo the histogram
788  * @param stream the stream
789  * @param width the maximal column width
790  * @param height (INPUT) the proposed coulmn height
791  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
792  * @date 2009-09-19
793  */
794 // ============================================================================
796 ( const AIDA::IProfile1D* histo ,
797  const std::size_t width ,
798  const std::size_t height ,
799  const bool spread )
800 {
801  std::ostringstream stream ;
802  histoDump_ ( histo , stream , width , height , spread );
803  return stream.str() ;
804 }
805 // ============================================================================
806 /* dump the text representation of the histogram
807  * @param histo (INPUT) the histogram
808  * @param stream (OUTUT) the stream
809  * @param width (INPUT) the maximal column width
810  * @param errors (INPUT) print/plot errors
811  * @return the stream
812  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
813  * @date 2009-09-19
814  */
815 // ============================================================================
817 ( const TH1* histo ,
818  std::ostream& stream ,
819  const std::size_t width ,
820  const std::size_t height ,
821  const bool errors )
822 {
823  const TProfile* profile = dynamic_cast<const TProfile*> ( histo ) ;
824  if ( profile )
825  { return histoDump_ ( profile , stream , width , height ) ; }
826  //
827  stream << std::endl ;
828  if ( !histo ) { return stream ; } // RETURN
829  Histo hist ;
830  StatusCode sc = _getHisto ( histo , hist ) ;
831  if ( sc.isFailure() ) { return stream ; } // RETURN
832  //
833  stream
834  << boost::format ( " Histo Name : \"%s\"")
835  % histo -> GetName ()
836  << std::endl
837  << boost::format ( " Histo Title : \"%s\"")
838  % histo -> GetTitle ()
839  << std::endl
840  << std::endl ;
841  //
842  stream
843  << boost::format ( " Mean : %11.5g +- %-10.4g ")
844  % histo -> GetMean ()
845  % histo -> GetMeanError ()
846  << std::endl
847  << boost::format ( " Rms : %11.5g +- %-10.4g ")
848  % histo -> GetRMS ()
849  % histo -> GetRMSError ()
850  << std::endl
851  << boost::format ( " Skewness : %11.5g ")
852  % histo -> GetSkewness ()
853  << std::endl
854  << boost::format ( " Kurtosis : %11.5g ")
855  % histo -> GetKurtosis ()
856  << std::endl
857  << std::endl ;
858  //
859  stream
860  << boost::format ( " Entries :\n | %=11s | %=11s | %=11s | %=11s | %=11s |")
861  % "All"
862  % "Underflow"
863  % "Overflow"
864  % "#Equivalent"
865  % "Integral"
866  << std::endl
867  << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g | %=11.5g |")
868  % histo -> GetEntries ()
869  % histo -> GetBinContent ( 0 )
870  % histo -> GetBinContent ( histo->GetNbinsX() + 1 )
871  % histo -> GetEffectiveEntries ()
872  % histo -> Integral ()
873  << std::endl
874  << std::endl ;
875  //
876  return dumpText ( hist , width , height , errors , stream ) ;
877 }
878 // ============================================================================
879 /* dump the text representation of the histogram
880  * @param histo (INPUT) the histogram
881  * @param stream (OUTUT) the stream
882  * @param width (INPUT) the maximal column width
883  * @param errors (INPUT) print/plot errors
884  * @return the stream
885  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
886  * @date 2009-09-19
887  */
888 // ============================================================================
890 ( const TProfile* histo ,
891  std::ostream& stream ,
892  const std::size_t width ,
893  const std::size_t height )
894 {
895  stream << std::endl ;
896  if ( ! histo ) { return stream ; } // RETURN
897  Histo hist ;
898  StatusCode sc = _getHisto ( histo , hist , true ) ;
899  if ( sc.isFailure() ) { return stream ; } // RETURN
900  //
901  stream
902  << boost::format ( " Profile Name : \"%s\"")
903  % histo -> GetName ()
904  << std::endl
905  << boost::format ( " Profile Title : \"%s\"")
906  % histo -> GetTitle ()
907  << std::endl
908  << std::endl ;
909  //
910  stream
911  << boost::format ( " Mean : %11.5g ") % histo -> GetMean ()
912  << std::endl
913  << boost::format ( " Rms : %11.5g ") % histo -> GetRMS ()
914  << std::endl
915  << std::endl ;
916  //
917  stream
918  << boost::format ( " Entries :\n | %=11s | %=11s | %=11s | %=11s |")
919  % "All"
920  % "Underflow"
921  % "Overflow"
922  % "Integral"
923  << std::endl
924  << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g |")
925  % histo -> GetEntries ()
926  % histo -> GetBinContent ( 0 )
927  % histo -> GetBinContent ( histo->GetNbinsX() + 1 )
928  % histo -> Integral ()
929  << std::endl
930  << std::endl ;
931  //
932  return dumpText ( hist , width , height , true , stream ) ;
933 }
934 // ============================================================================
935 /* dump the text representation of the histogram
936  * @param histo (INPUT) the histogram
937  * @param width (INPUT) the maximal column width
938  * @param errors (INPUT) print/plot errors
939  * @return string representation of the histogram
940  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
941  * @date 2009-09-19
942  */
943 // ============================================================================
945 ( const TH1* histo ,
946  const std::size_t width ,
947  const std::size_t height ,
948  const bool errors )
949 {
950  std::ostringstream stream ;
951  histoDump_ ( histo , stream , width , height , errors );
952  return stream.str() ;
953 }
954 // ============================================================================
955 /* dump the text representation of the histogram
956  * @param histo (INPUT) the histogram
957  * @param width (INPUT) the maximal column width
958  * @param errors (INPUT) print/plot errors
959  * @return string representation of the histogram
960  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
961  * @date 2009-09-19
962  */
963 // ============================================================================
965 ( const TProfile* histo ,
966  const std::size_t width ,
967  const std::size_t height )
968 {
969  std::ostringstream stream ;
970  histoDump_ ( histo , stream , width , height );
971  return stream.str() ;
972 }
973 // ============================================================================
974 
975 // ============================================================================
976 // The END
977 // ============================================================================
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
T ceil(T...args)
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:241
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:610
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:699
T endl(T...args)
T end(T...args)
T floor(T...args)
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:223
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
STL class.
T min(T...args)
T push_back(T...args)
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
Definition: HistoStats.cpp:233
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
constexpr double m
Definition: SystemOfUnits.h:93
T max(T...args)
dictionary l
Definition: gaudirun.py:421
T size(T...args)
STL class.
T begin(T...args)
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:192
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
static double mean(const AIDA::IHistogram1D *histo)
get the mean value for the histogram (just for completeness)
Definition: HistoStats.cpp:215
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:169
T sqrt(T...args)
T accumulate(T...args)
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:181
STL class.
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:158