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 // ============================================================================
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 { 0.0 , 0 } ; } // RETURN
311  else if ( 1 == v ) { return { 1.0 , 0 } ; } // RETURN
312  else if ( 0 > v )
313  {
314  auto r = decompose ( -v ) ;
315  return { -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 { v , -i } ;
322  }
323  else if ( 1 < v )
324  {
325  int i = 0 ;
326  while ( 1 <= v ) { ++i ; v /= 10 ; } // STUPID
327  return { v , i } ;
328  }
329  return { 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  // forward declaration to break cyclic dependency between rValMin and rValMax
347  inline double rValMin ( double v );
348  // ==========================================================================
353  inline double rValMax ( double v )
354  {
355  if ( 0 == v ) { return 0 ; } // RETURN
356  else if ( 0 > v ) { return -1 * rValMin ( -v ) ; } // RETURN
357  // decompose the double value into decimal significand and mantissa
358  std::pair<double,int> r = decompose ( v ) ;
359  //
360  const double f = std::ceil ( 20 * r.first ) / 2 ; // + 1 ;
361  const int l = r.second - 1 ;
362  return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ;
363  }
364  // ==========================================================================
369  inline double rValMin ( double v )
370  {
371  if ( 0 == v ) { return 0 ; } // RETURN
372  else if ( 0 > v ) { return -1 * rValMax ( -v ) ; } // RETURN
373  // decompose the double value into decimal significand and mantissa
374  std::pair<double,int> r = decompose ( v ) ;
375  const double f = std::floor ( 20 * r.first ) / 2 ; // - 1 ;
376  const int l = r.second - 1 ;
377  return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ;
378  }
379  // ==========================================================================
384  inline std::string yLabel ( double value )
385  {
386  boost::format fmt ( "%10.3g" ) ;
387  fmt % value ;
388  return fmt.str () ;
389  }
390  // ==========================================================================
395  inline std::string xLabel ( const double value )
396  {
397  boost::format fmt ( "%9.3g" ) ;
398  fmt % value ;
399  return fmt.str () ;
400  }
401  // ==========================================================================
403  char symbBin ( const Histo::Bin& bin ,
404  const double yLow ,
405  const double yHigh ,
406  const bool yNull ,
407  const bool errors )
408  {
409  if ( errors && yLow <= bin.height && bin.height < yHigh ) { return '*' ; } // O
410  else if ( errors && yHigh < bin.height - bin.error ) { return ' ' ; }
411  else if ( errors && yLow >= bin.height + bin.error ) { return ' ' ; }
412  else if ( errors ) { return 'I' ; }
413  else if ( yLow <= bin.height && bin.height < yHigh ) { return '*' ; }
414  else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) { return '*' ; } // +
415  else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) { return '*' ; } // -
416  //
417  return ' ' ;
418  }
419  // ==========================================================================
424  std::ostream& dumpText
425  ( const Histo& histo ,
426  const std::size_t width ,
427  const std::size_t height ,
428  const bool errors ,
429  std::ostream& stream )
430  {
431  if ( 40 > width ) { return dumpText ( histo , 40 , height , errors , stream ) ; }
432  if ( 200 < width ) { return dumpText ( histo , 200 , height , errors , stream ) ; }
433  if ( 150 < height ) { return dumpText ( histo , width , 150 , errors , stream ) ; }
434  if ( 20 > height ) { return dumpText ( histo , width , 20 , errors , stream ) ; }
435  if ( height > width ) { return dumpText ( histo , width , width , errors , stream ) ; }
436  //
437  const unsigned int nBins = histo.bins.size() ;
438  if ( nBins > width )
439  {
440  // rebin histogram
441  Histo r = histo.rebin ( rebin ( nBins , width ) ) ;
442  return dumpText ( r , width , height , errors , stream ) ;
443  }
444  //
445  // get the Y-scale
446  double yMax = std::max ( rValMax ( histo.maxY ( errors ) ) , 0.0 ) ;
447  double yMin = std::min ( rValMin ( histo.minY ( errors ) ) , 0.0 ) ;
448 
449  if ( yMin == yMax ) { yMax = yMin + 1 ; }
451  std::pair<double,int> r = decompose ( yMax - yMin ) ;
452  double _ny = std::ceil ( 10 * r.first ) ; // 1 <= ny < 10
453  if ( 1 >= _ny ) { _ny = 10 ; }
454  int yBins = (int) std::max ( 1. , std::ceil ( height / _ny ) ) ;
455 
456  yBins *= (int) _ny ;
457  if ( 20 > yBins ) { yBins = 20 ; }
458  const double yScale = ( yMax - yMin ) / yBins ;
459 
460  //
461  const int ySkip =
462  0 == yBins % 13 ? 13 :
463  0 == yBins % 11 ? 11 :
464  0 == yBins % 9 ? 9 :
465  0 == yBins % 8 ? 8 :
466  0 == yBins % 7 ? 7 :
467  0 == yBins % 6 ? 6 :
468  0 == yBins % 5 ? 5 :
469  0 == yBins % 4 ? 4 : 10 ;
470 
471  const int xSkip =
472  // 0 == nBins % 8 ? 8 :
473  0 == nBins % 7 ? 7 :
474  0 == nBins % 6 ? 6 :
475  0 == nBins % 5 ? 5 :
476  0 == nBins % 4 ? 4 : 10 ;
477 
478  int iNull = histo.nullBin() ;
479 
480  if ( 0 <= iNull ) { iNull %= xSkip ; }
481  else { iNull = 0 ; }
482 
483  stream << std::endl ;
484 
485  for ( int yLine = -1 ; yLine < yBins ; ++yLine )
486  {
487  const double yHigh = yMax - yScale * yLine ;
488  // const double yLow = yHigh - yScale ;
489  const double yLow = yMax - yScale * ( yLine + 1 ) ;
490  //
491  std::string line1 = " " ;
492 
493  const bool ynull = ( yLow <= 0 && 0 < yHigh ) ;
494  const bool yfirst = -1 == yLine || yBins -1 == yLine ;
495  const bool ylab =
496  ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull ;
497 
498  if ( ylab ) { line1 += yLabel ( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow ) ; }
499  else { line1 += std::string( 10 , ' ' ) ; }
500  //
501  line1 += " " ;
502  //
504  line1 += symbBin ( histo.under , yLow , yHigh , ynull , errors ) ;
505  //
506  line1 +=
507  ynull ? "-+" :
508  ylab ? " +" : " |" ;
509  //
510  std::string line2 ;
511  //
512  for ( auto ibin = histo.bins.cbegin() ;
513  histo.bins.cend() != ibin ; ++ibin )
514  {
515  //char symb = ' ' ;
516  const int i = ibin - histo.bins.cbegin () ;
517  //
518  const bool xnull =
519  ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.cend() && 0 < (ibin+1)->lower ;
520  const bool xlab = iNull == i % xSkip ;
521  //
522  char symb = symbBin ( *ibin, yLow , yHigh , ynull , errors ) ;
523  //
524  if ( ' ' == symb )
525  {
526  if ( ( ynull || yfirst ) && xlab ) { symb = '+' ; }
527  else if ( ynull || yfirst ) { symb = '-' ; }
528  //
529  else if ( ylab && xnull ) { symb = '+' ; }
530  else if ( xnull ) { symb = '|' ; }
531  //
532  else if ( ylab || xlab ) { symb = '.' ; }
533  //
534  }
535  line2 += symb ;
536  //
537  }
538  //
539  std::string line3 =
540  ynull ? "->" :
541  ylab ? "+ " : "| " ;
542  //
544  line3 += symbBin ( histo.over , yLow , yHigh , ynull , errors ) ;
545  //
546  stream << line1 << line2 << line3 << std::endl ;
547  //
548  }
549 
550  // get x-labels
551  std::vector<std::string> xlabels ;
552  for ( auto ib = histo.bins.cbegin() ; histo.bins.cend() != ib ; ++ib )
553  { xlabels.push_back ( xLabel ( ib->lower ) ) ; }
554  // overflow& underflow label
555  const std::string oLabel = xLabel ( histo.over.lower ) ;
556  const std::string uLabel = xLabel ( histo.under.lower ) ;
557  //
558  static const std::string s_UNDERFLOW ( "UNDERFLOW" ) ;
559  static const std::string s_OVERFLOW ( " OVERFLOW" ) ;
560  //
561  //
562  for ( unsigned int yLine = 0 ; yLine < 12 ; ++yLine )
563  {
564  std::string line = std::string ( 12 , ' ' ) ;
565  //
566  if ( yLine < s_UNDERFLOW.size() ) { line += s_UNDERFLOW[yLine] ; }
567  else { line += ' ' ; }
568  //
569  line += ' ' ;
570  //
571  if ( uLabel.size() > yLine ) { line += uLabel[yLine] ; }
572  else { line += ' ' ; }
573  //
574  for ( auto ibin = histo.bins.cbegin() ; histo.bins.cend() != ibin ; ++ibin )
575  {
576  int ib = ibin - histo.bins.cbegin() ;
577  const bool xlab = ( iNull == ib % xSkip ) ;
578  if ( xlab && yLine < xlabels[ib].size() ) { line += xlabels[ib][yLine] ; }
579  else { line += ' ' ; }
580  }
581  //
582  if ( oLabel.size() > yLine ) { line += oLabel[yLine] ; }
583  else { line += ' ' ; }
584  //
585  line += ' ' ;
586  //
587  if ( yLine < s_OVERFLOW.size() ) { line += s_OVERFLOW[yLine] ; }
588  else { line += ' ' ; }
589  //
590  stream << line << std::endl ;
591  }
592  //
593  return stream ; // RETURN
594  }
595 }
596 // ============================================================================
597 /* dump the text representation of the histogram
598  * @param histo (INPUT) the histogram
599  * @param stream (OUTUT) the stream
600  * @param width (INPUT) the maximal column width
601  * @param height (INPUT) the proposed coulmn height
602  * @param errors (INPUT) print/plot errors
603  * @return the stream
604  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
605  * @date 2009-09-19
606  */
607 // ============================================================================
609 ( const AIDA::IHistogram1D* histo ,
610  std::ostream& stream ,
611  const std::size_t width ,
612  const std::size_t height ,
613  const bool errors )
614 {
615  stream << std::endl ;
616  if ( !histo ) { return stream ; } // RETURN
617  Histo hist ;
618  StatusCode sc = _getHisto ( histo , hist ) ;
619  if ( sc.isFailure() ) { return stream ; } // RETURN
620  //
621  stream
622  << boost::format ( " Histo TES : \"%s\"") % path ( histo )
623  << std::endl
624  << boost::format ( " Histo Title : \"%s\"") % histo->title()
625  << std::endl
626  << std::endl ;
627  //
628  stream
629  << boost::format ( " Mean : %11.5g +- %-10.4g ")
632  << std::endl
633  << boost::format ( " Rms : %11.5g +- %-10.4g ")
636  << std::endl
637  << boost::format ( " Skewness : %11.5g +- %-10.4g ")
640  << std::endl
641  << boost::format ( " Kurtosis : %11.5g +- %-10.4g ")
644  << std::endl
645  << std::endl ;
646  //
647  stream
648  << boost::format ( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s | %=11s |")
649  % "All"
650  % "In Range"
651  % "Underflow"
652  % "Overflow"
653  % "#Equivalent"
654  % "Integral"
655  % "Total"
656  << std::endl
657  << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g | %=11.5g |")
658  % histo -> allEntries ()
659  % histo -> entries ()
660  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
661  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
662  % histo -> equivalentBinEntries ()
663  % histo -> sumBinHeights ()
664  % histo -> sumAllBinHeights ()
665  << std::endl
666  << std::endl ;
667  //
668  const AIDA::IAnnotation& a = histo->annotation () ;
669  if ( 0 != a.size() )
670  {
671  stream << " Annotation" << std::endl ;
672  for ( int i = 0 ; i < a.size() ; ++i )
673  {
674  stream
675  << boost::format ( " | %-25.25s : %-45.45s | ")
676  % a.key ( i )
677  % a.value ( i )
678  << std::endl ;
679  }
680  stream << std::endl ;
681  }
682  //
683  return dumpText ( hist , width , height , errors , stream ) ;
684 }
685 // ============================================================================
686 /* dump the text representation of the histogram
687  * @param histo the histogram
688  * @param stream the stream
689  * @param width the maximal column width
690  * @param height (INPUT) the proposed coulmn height
691  * @param errors (INPUT) print/plot errors
692  * @param erorrs print/plot errors
693  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
694  * @date 2009-09-19
695  */
696 // ============================================================================
698 ( const AIDA::IHistogram1D* histo ,
699  const std::size_t width ,
700  const std::size_t height ,
701  const bool errors )
702 {
703  std::ostringstream stream ;
704  histoDump_ ( histo , stream , width , height , errors );
705  return stream.str() ;
706 }
707 // ============================================================================
708 /* dump the text representation of the 1D-profile
709  * @param histo (INPUT) the profile
710  * @param stream (OUTUT) the stream
711  * @param width (INPUT) the maximal column width
712  * @param height (INPUT) the proposed coulmn height
713  * @param spread (INPUT) plot spread/error?
714  * @return the stream
715  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
716  * @date 2009-09-19
717  */
718 // ============================================================================
720 ( const AIDA::IProfile1D* histo ,
721  std::ostream& stream ,
722  const std::size_t width ,
723  const std::size_t height ,
724  const bool spread )
725 {
726  stream << std::endl ;
727  if ( !histo ) { return stream ; } // RETURN
728  Histo hist ;
729  StatusCode sc = _getHisto ( histo , hist , spread ) ;
730  if ( sc.isFailure() ) { return stream ; } // RETURN
731  //
732  stream
733  << boost::format ( " Histo TES : \"%s\"") % path ( histo )
734  << std::endl
735  << boost::format ( " Histo Title : \"%s\"") % histo->title()
736  << std::endl
737  << std::endl ;
738  //
739  stream
740  << boost::format ( " Mean : %11.5g ") % histo->mean()
741  << std::endl
742  << boost::format ( " Rms : %11.5g ") % histo->rms ()
743  << std::endl
744  << std::endl ;
745  //
746  stream
747  << boost::format ( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s |")
748  % "All"
749  % "In Range"
750  % "Underflow"
751  % "Overflow"
752  // % "#Equivalent"
753  % "Integral"
754  % "Total"
755  << std::endl
756  << boost::format ( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g |")
757  % histo -> allEntries ()
758  % histo -> entries ()
759  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
760  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
761  // % histo -> equivalentBinEntries ()
762  % histo -> sumBinHeights ()
763  % histo -> sumAllBinHeights ()
764  << std::endl
765  << std::endl ;
766  //
767  const AIDA::IAnnotation& a = histo->annotation () ;
768  if ( 0 != a.size() )
769  {
770  stream << " Annotation" << std::endl ;
771  for ( int i = 0 ; i < a.size() ; ++i )
772  {
773  stream
774  << boost::format ( " | %-25.25s : %-45.45s | ")
775  % a.key ( i )
776  % a.value ( i )
777  << std::endl ;
778  }
779  stream << std::endl ;
780  }
781  //
782  return dumpText ( hist , width , height , true , stream ) ;
783 }
784 // ============================================================================
785 /* dump the text representation of the 1D-profile
786  * @param histo the histogram
787  * @param stream the stream
788  * @param width the maximal column width
789  * @param height (INPUT) the proposed coulmn height
790  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
791  * @date 2009-09-19
792  */
793 // ============================================================================
795 ( const AIDA::IProfile1D* histo ,
796  const std::size_t width ,
797  const std::size_t height ,
798  const bool spread )
799 {
800  std::ostringstream stream ;
801  histoDump_ ( histo , stream , width , height , spread );
802  return stream.str() ;
803 }
804 // ============================================================================
805 /* dump the text representation of the histogram
806  * @param histo (INPUT) the histogram
807  * @param stream (OUTUT) the stream
808  * @param width (INPUT) the maximal column width
809  * @param errors (INPUT) print/plot errors
810  * @return the stream
811  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
812  * @date 2009-09-19
813  */
814 // ============================================================================
816 ( const TH1* histo ,
817  std::ostream& stream ,
818  const std::size_t width ,
819  const std::size_t height ,
820  const bool errors )
821 {
822  const TProfile* profile = dynamic_cast<const TProfile*> ( histo ) ;
823  if ( profile )
824  { return histoDump_ ( profile , stream , width , height ) ; }
825  //
826  stream << std::endl ;
827  if ( !histo ) { return stream ; } // RETURN
828  Histo hist ;
829  StatusCode sc = _getHisto ( histo , hist ) ;
830  if ( sc.isFailure() ) { return stream ; } // RETURN
831  //
832  stream
833  << boost::format ( " Histo Name : \"%s\"")
834  % histo -> GetName ()
835  << std::endl
836  << boost::format ( " Histo Title : \"%s\"")
837  % histo -> GetTitle ()
838  << std::endl
839  << std::endl ;
840  //
841  stream
842  << boost::format ( " Mean : %11.5g +- %-10.4g ")
843  % histo -> GetMean ()
844  % histo -> GetMeanError ()
845  << std::endl
846  << boost::format ( " Rms : %11.5g +- %-10.4g ")
847  % histo -> GetRMS ()
848  % histo -> GetRMSError ()
849  << std::endl
850  << boost::format ( " Skewness : %11.5g ")
851  % histo -> GetSkewness ()
852  << std::endl
853  << boost::format ( " Kurtosis : %11.5g ")
854  % histo -> GetKurtosis ()
855  << std::endl
856  << std::endl ;
857  //
858  stream
859  << boost::format ( " Entries :\n | %=11s | %=11s | %=11s | %=11s | %=11s |")
860  % "All"
861  % "Underflow"
862  % "Overflow"
863  % "#Equivalent"
864  % "Integral"
865  << std::endl
866  << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g | %=11.5g |")
867  % histo -> GetEntries ()
868  % histo -> GetBinContent ( 0 )
869  % histo -> GetBinContent ( histo->GetNbinsX() + 1 )
870  % histo -> GetEffectiveEntries ()
871  % histo -> Integral ()
872  << std::endl
873  << std::endl ;
874  //
875  return dumpText ( hist , width , height , errors , stream ) ;
876 }
877 // ============================================================================
878 /* dump the text representation of the histogram
879  * @param histo (INPUT) the histogram
880  * @param stream (OUTUT) the stream
881  * @param width (INPUT) the maximal column width
882  * @param errors (INPUT) print/plot errors
883  * @return the stream
884  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
885  * @date 2009-09-19
886  */
887 // ============================================================================
889 ( const TProfile* histo ,
890  std::ostream& stream ,
891  const std::size_t width ,
892  const std::size_t height )
893 {
894  stream << std::endl ;
895  if ( ! histo ) { return stream ; } // RETURN
896  Histo hist ;
897  StatusCode sc = _getHisto ( histo , hist , true ) ;
898  if ( sc.isFailure() ) { return stream ; } // RETURN
899  //
900  stream
901  << boost::format ( " Profile Name : \"%s\"")
902  % histo -> GetName ()
903  << std::endl
904  << boost::format ( " Profile Title : \"%s\"")
905  % histo -> GetTitle ()
906  << std::endl
907  << std::endl ;
908  //
909  stream
910  << boost::format ( " Mean : %11.5g ") % histo -> GetMean ()
911  << std::endl
912  << boost::format ( " Rms : %11.5g ") % histo -> GetRMS ()
913  << std::endl
914  << std::endl ;
915  //
916  stream
917  << boost::format ( " Entries :\n | %=11s | %=11s | %=11s | %=11s |")
918  % "All"
919  % "Underflow"
920  % "Overflow"
921  % "Integral"
922  << std::endl
923  << boost::format ( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g |")
924  % histo -> GetEntries ()
925  % histo -> GetBinContent ( 0 )
926  % histo -> GetBinContent ( histo->GetNbinsX() + 1 )
927  % histo -> Integral ()
928  << std::endl
929  << std::endl ;
930  //
931  return dumpText ( hist , width , height , true , stream ) ;
932 }
933 // ============================================================================
934 /* dump the text representation of the histogram
935  * @param histo (INPUT) the histogram
936  * @param width (INPUT) the maximal column width
937  * @param errors (INPUT) print/plot errors
938  * @return string representation of the histogram
939  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
940  * @date 2009-09-19
941  */
942 // ============================================================================
944 ( const TH1* histo ,
945  const std::size_t width ,
946  const std::size_t height ,
947  const bool errors )
948 {
949  std::ostringstream stream ;
950  histoDump_ ( histo , stream , width , height , errors );
951  return stream.str() ;
952 }
953 // ============================================================================
954 /* dump the text representation of the histogram
955  * @param histo (INPUT) the histogram
956  * @param width (INPUT) the maximal column width
957  * @param errors (INPUT) print/plot errors
958  * @return string representation of the histogram
959  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
960  * @date 2009-09-19
961  */
962 // ============================================================================
964 ( const TProfile* histo ,
965  const std::size_t width ,
966  const std::size_t height )
967 {
968  std::ostringstream stream ;
969  histoDump_ ( histo , stream , width , height );
970  return stream.str() ;
971 }
972 // ============================================================================
973 
974 // ============================================================================
975 // The END
976 // ============================================================================
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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
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:421
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:609
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:698
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
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:166