The Gaudi Framework  v36r9p1 (5c15b2bb)
HistoDump.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifdef __ICC
12 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
13 // TODO: To be removed, since it comes from ROOT TMathBase.h
14 # pragma warning( disable : 2259 )
15 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
16 // The comparison are meant
17 # pragma warning( disable : 1572 )
18 #endif
19 #ifdef WIN32
20 // Disable warning
21 // warning C4996: 'sprintf': This function or variable may be unsafe.
22 // coming from TString.h
23 # pragma warning( disable : 4996 )
24 #endif
25 
26 #include "GaudiUtils/HistoDump.h"
27 #include "AIDA/IAnnotation.h"
28 #include "AIDA/IAxis.h"
29 #include "AIDA/IHistogram1D.h"
30 #include "AIDA/IProfile1D.h"
31 #include "GaudiKernel/StatusCode.h"
32 #include "GaudiUtils/HistoStats.h"
34 #include "TAxis.h"
35 #include "TH1.h"
36 #include "TProfile.h"
37 #include <cmath>
38 #include <fmt/format.h>
39 #include <iostream>
40 #include <numeric>
41 #include <sstream>
42 #include <utility>
43 #include <vector>
44 
45 // ============================================================================
46 namespace {
47  // ==========================================================================
53  struct Histo {
54  // ========================================================================
55  Histo() = default;
56  // ========================================================================
62  struct Bin {
63  // ======================================================================
64  Bin( const double h = 0, const double e = 0, const double l = -1 ) : height( h ), error( e ), lower( l ) {}
65  // ======================================================================
67  double height; // bin height
69  double error; // bin error
71  double lower; // lower edge
72  // ======================================================================
73  Bin& operator+=( const Bin& right ) {
74  height += right.height;
75  const double e2 = error * error + right.error * right.error;
76  error = std::sqrt( e2 );
77  return *this;
78  }
79  // ======================================================================
80  };
81  // ========================================================================
83  double maxY( const bool withErr ) const {
84  return std::accumulate(
85  std::begin( bins ), std::end( bins ), std::max( under.height, over.height ),
86  [&]( double m, const Bin& b ) { return std::max( m, withErr ? b.height + b.error : b.height ); } );
87  }
89  double minY( const bool withErr ) const {
90  return std::accumulate(
91  std::begin( bins ), std::end( bins ), std::min( under.height, over.height ),
92  [&]( double m, const Bin& b ) { return std::min( m, withErr ? b.height - b.error : b.height ); } );
93  }
95  Histo rebin( const unsigned int bin ) const {
96  // create new histogram
97  Histo nh;
98  // copy overflow & underflow bins
99  nh.under = under;
100  nh.over = over;
101  // rebin
102  for ( unsigned int ibin = 0; ibin < bins.size(); ++ibin ) {
103  const Bin& current = bins[ibin];
104  if ( nh.bins.empty() ) {
105  nh.bins.push_back( current );
106  } else if ( 0 == ibin % bin ) {
107  nh.bins.push_back( current );
108  } else {
109  nh.bins.back() += current;
110  }
111  }
112  return nh;
113  }
114  // find "null-bin", if any
115  int nullBin() const {
116  for ( auto ib = bins.cbegin(); bins.cend() != ib + 1; ++ib ) {
117  if ( ib->lower <= 0 && 0 < ( ib + 1 )->lower ) { return ib - bins.cbegin(); }
118  }
119  return -1;
120  }
121  // ========================================================================
122  typedef std::vector<Bin> Bins;
123  // ========================================================================
125  Bins bins; // histogram bins
127  Bin under; // underflow bin
129  Bin over; // overflow bin
130  // ========================================================================
131  };
132  // ==========================================================================
140  StatusCode _getHisto( const TH1* root, Histo& hist ) {
141  // clear the histogram
142  hist.bins.clear();
143  //
144  if ( !root ) { return StatusCode::FAILURE; } // RETURN
145  const TAxis* axis = root->GetXaxis();
146  if ( !axis ) { return StatusCode::FAILURE; } // RETURN
147  const int nbins = axis->GetNbins();
148  if ( 0 == nbins ) { return StatusCode::FAILURE; } // RETURN
149 
150  // underflow bin
151  hist.under = Histo::Bin( root->GetBinContent( 0 ), root->GetBinError( 0 ), axis->GetXmin() );
152  // overflow bin
153  hist.over = Histo::Bin( root->GetBinContent( nbins + 1 ), root->GetBinError( nbins + 1 ), axis->GetXmax() );
154  //
155  //
156  for ( int ibin = 1; ibin <= nbins; ++ibin ) {
157  // add to the local histo
158  hist.bins.emplace_back( root->GetBinContent( ibin ), root->GetBinError( ibin ), axis->GetBinLowEdge( ibin ) );
159  }
160  return StatusCode::SUCCESS;
161  }
162  // ==========================================================================
170  StatusCode _getHisto( const TProfile* root, Histo& hist, const bool /* spread */ ) {
171  const TH1* histo = root;
172  return _getHisto( histo, hist );
173  }
174  // ==========================================================================
182  StatusCode _getHisto( const AIDA::IHistogram1D* aida, Histo& hist ) {
183  // clear the histogram
184  hist.bins.clear();
185  //
186  if ( !aida ) { return StatusCode::FAILURE; } // RETURN
187  //
188  const AIDA::IAxis& axis = aida->axis();
189  const int nbins = axis.bins();
190  //
191  // underflow bin
192  hist.under = Histo::Bin( aida->binHeight( AIDA::IAxis::UNDERFLOW_BIN ),
193  aida->binError( AIDA::IAxis::UNDERFLOW_BIN ), axis.lowerEdge() );
194  // overflow bin
195  hist.over = Histo::Bin( aida->binHeight( AIDA::IAxis::OVERFLOW_BIN ), aida->binError( AIDA::IAxis::OVERFLOW_BIN ),
196  axis.upperEdge() );
197  //
198  for ( int ibin = 0; ibin < nbins; ++ibin ) {
199  // add to the local histo
200  hist.bins.emplace_back( aida->binHeight( ibin ), aida->binError( ibin ), axis.binLowerEdge( ibin ) );
201  }
202  return StatusCode::SUCCESS;
203  }
204  // ==========================================================================
212  StatusCode _getHisto( const AIDA::IProfile1D* aida, Histo& hist, const bool spread ) {
213  // clear the histogram
214  hist.bins.clear();
215  //
216  if ( !aida ) { return StatusCode::FAILURE; } // RETURN
217  //
218  const AIDA::IAxis& axis = aida->axis();
219  const int nbins = axis.bins();
220  //
221  // underflow bin
222  hist.under =
223  Histo::Bin( aida->binHeight( AIDA::IAxis::UNDERFLOW_BIN ),
224  spread ? aida->binRms( AIDA::IAxis::UNDERFLOW_BIN ) : aida->binError( AIDA::IAxis::UNDERFLOW_BIN ),
225  axis.lowerEdge() );
226  // overflow bin
227  hist.over =
228  Histo::Bin( aida->binHeight( AIDA::IAxis::OVERFLOW_BIN ),
229  spread ? aida->binRms( AIDA::IAxis::OVERFLOW_BIN ) : aida->binError( AIDA::IAxis::OVERFLOW_BIN ),
230  axis.upperEdge() );
231  //
232  for ( int ibin = 0; ibin < nbins; ++ibin ) {
233  // add to the local histo
234  hist.bins.emplace_back( aida->binHeight( ibin ), spread ? aida->binRms( ibin ) : aida->binError( ibin ),
235  axis.binLowerEdge( ibin ) );
236  }
237  return StatusCode::SUCCESS;
238  }
239  // ==========================================================================
245  inline unsigned int rebin( const unsigned int bins, const unsigned int imax ) {
246  if ( 0 == imax ) { return 1; } // RETURN
247  unsigned int ibin = 1;
248  while ( bins > imax * ibin ) { ++ibin; }
249  return ibin; // RETURN
250  }
251  // ==========================================================================
257  std::pair<double, int> decompose( double v ) {
258  if ( 0 == v ) {
259  return { 0.0, 0 };
260  } // RETURN
261  else if ( 1 == v ) {
262  return { 1.0, 0 };
263  } // RETURN
264  else if ( 0 > v ) {
265  auto r = decompose( -v );
266  return { -r.first, r.second }; // RETURN
267  } else if ( 0.1 > v ) {
268  int i = 0;
269  while ( 0.1 > v ) {
270  ++i;
271  v *= 10;
272  } // STUPID
273  return { v, -i };
274  } else if ( 1 < v ) {
275  int i = 0;
276  while ( 1 <= v ) {
277  ++i;
278  v /= 10;
279  } // STUPID
280  return { v, i };
281  }
282  return { v, 1 };
283  }
284  // ==========================================================================
289  inline double _pow( double x, unsigned long n ) {
290  double y = n % 2 ? x : 1;
291  while ( n >>= 1 ) {
292  x = x * x;
293  if ( n % 2 ) { y *= x; }
294  }
295  return y;
296  }
297  // forward declaration to break cyclic dependency between rValMin and rValMax
298  inline double rValMin( double v );
299  // ==========================================================================
304  inline double rValMax( double v ) {
305  if ( 0 == v ) {
306  return 0;
307  } // RETURN
308  else if ( 0 > v ) {
309  return -1 * rValMin( -v );
310  } // RETURN
311  // decompose the double value into decimal significand and mantissa
312  std::pair<double, int> r = decompose( v );
313  //
314  const double f = std::ceil( 20 * r.first ) / 2; // + 1 ;
315  const int l = r.second - 1;
316  return 0 < l ? f * _pow( 10, l ) : f / _pow( 10, -l );
317  }
318  // ==========================================================================
323  inline double rValMin( double v ) {
324  if ( 0 == v ) {
325  return 0;
326  } // RETURN
327  else if ( 0 > v ) {
328  return -1 * rValMax( -v );
329  } // RETURN
330  // decompose the double value into decimal significand and mantissa
331  std::pair<double, int> r = decompose( v );
332  const double f = std::floor( 20 * r.first ) / 2; // - 1 ;
333  const int l = r.second - 1;
334  return 0 < l ? f * _pow( 10, l ) : f / _pow( 10, -l );
335  }
336  // ==========================================================================
341  inline std::string yLabel( double value ) { return fmt::format( "{:10.3g}", value ); }
342  // ==========================================================================
347  inline std::string xLabel( const double value ) { return fmt::format( "{:9.3g}", value ); }
348  // ==========================================================================
350  char symbBin( const Histo::Bin& bin, const double yLow, const double yHigh, const bool yNull, const bool errors ) {
351  if ( errors && yLow <= bin.height && bin.height < yHigh ) {
352  return '*';
353  } // O
354  else if ( errors && yHigh < bin.height - bin.error ) {
355  return ' ';
356  } else if ( errors && yLow >= bin.height + bin.error ) {
357  return ' ';
358  } else if ( errors ) {
359  return 'I';
360  } else if ( yLow <= bin.height && bin.height < yHigh ) {
361  return '*';
362  } else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) {
363  return '*';
364  } // +
365  else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) {
366  return '*';
367  } // -
368  //
369  return ' ';
370  }
371  // ==========================================================================
376  std::ostream& dumpText( const Histo& histo, const std::size_t width, const std::size_t height, const bool errors,
377  std::ostream& stream ) {
378  if ( 40 > width ) { return dumpText( histo, 40, height, errors, stream ); }
379  if ( 200 < width ) { return dumpText( histo, 200, height, errors, stream ); }
380  if ( 150 < height ) { return dumpText( histo, width, 150, errors, stream ); }
381  if ( 20 > height ) { return dumpText( histo, width, 20, errors, stream ); }
382  if ( height > width ) { return dumpText( histo, width, width, errors, stream ); }
383  //
384  const unsigned int nBins = histo.bins.size();
385  if ( nBins > width ) {
386  // rebin histogram
387  Histo r = histo.rebin( rebin( nBins, width ) );
388  return dumpText( r, width, height, errors, stream );
389  }
390  //
391  // get the Y-scale
392  double yMax = std::max( rValMax( histo.maxY( errors ) ), 0.0 );
393  double yMin = std::min( rValMin( histo.minY( errors ) ), 0.0 );
394 
395  if ( yMin == yMax ) { yMax = yMin + 1; }
397  std::pair<double, int> r = decompose( yMax - yMin );
398  double _ny = std::ceil( 10 * r.first ); // 1 <= ny < 10
399  if ( 1 >= _ny ) { _ny = 10; }
400  int yBins = (int)std::max( 1., std::ceil( height / _ny ) );
401 
402  yBins *= (int)_ny;
403  if ( 20 > yBins ) { yBins = 20; }
404  const double yScale = ( yMax - yMin ) / yBins;
405 
406  //
407  const int ySkip = 0 == yBins % 13 ? 13
408  : 0 == yBins % 11 ? 11
409  : 0 == yBins % 9 ? 9
410  : 0 == yBins % 8 ? 8
411  : 0 == yBins % 7 ? 7
412  : 0 == yBins % 6 ? 6
413  : 0 == yBins % 5 ? 5
414  : 0 == yBins % 4 ? 4
415  : 10;
416 
417  const int xSkip =
418  // 0 == nBins % 8 ? 8 :
419  0 == nBins % 7 ? 7
420  : 0 == nBins % 6 ? 6
421  : 0 == nBins % 5 ? 5
422  : 0 == nBins % 4 ? 4
423  : 10;
424 
425  int iNull = histo.nullBin();
426 
427  if ( 0 <= iNull ) {
428  iNull %= xSkip;
429  } else {
430  iNull = 0;
431  }
432 
433  stream << std::endl;
434 
435  for ( int yLine = -1; yLine < yBins; ++yLine ) {
436  const double yHigh = yMax - yScale * yLine;
437  // const double yLow = yHigh - yScale ;
438  const double yLow = yMax - yScale * ( yLine + 1 );
439  //
440  std::string line1 = " ";
441 
442  const bool ynull = ( yLow <= 0 && 0 < yHigh );
443  const bool yfirst = -1 == yLine || yBins - 1 == yLine;
444  const bool ylab = ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull;
445 
446  if ( ylab ) {
447  line1 += yLabel( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow );
448  } else {
449  line1 += std::string( 10, ' ' );
450  }
451  //
452  line1 += " ";
453  //
455  line1 += symbBin( histo.under, yLow, yHigh, ynull, errors );
456  //
457  line1 += ynull ? "-+" : ylab ? " +" : " |";
458  //
459  std::string line2;
460  //
461  for ( auto ibin = histo.bins.cbegin(); histo.bins.cend() != ibin; ++ibin ) {
462  // char symb = ' ' ;
463  const int i = ibin - histo.bins.cbegin();
464  //
465  const bool xnull = ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.cend() && 0 < ( ibin + 1 )->lower;
466  const bool xlab = iNull == i % xSkip;
467  //
468  char symb = symbBin( *ibin, yLow, yHigh, ynull, errors );
469  //
470  if ( ' ' == symb ) {
471  if ( ( ynull || yfirst ) && xlab ) {
472  symb = '+';
473  } else if ( ynull || yfirst ) {
474  symb = '-';
475  }
476  //
477  else if ( ylab && xnull ) {
478  symb = '+';
479  } else if ( xnull ) {
480  symb = '|';
481  }
482  //
483  else if ( ylab || xlab ) {
484  symb = '.';
485  }
486  //
487  }
488  line2 += symb;
489  //
490  }
491  //
492  std::string line3 = ynull ? "->" : ylab ? "+ " : "| ";
493  //
495  line3 += symbBin( histo.over, yLow, yHigh, ynull, errors );
496  //
497  stream << line1 << line2 << line3 << std::endl;
498  //
499  }
500 
501  // get x-labels
502  std::vector<std::string> xlabels;
503  for ( auto ib = histo.bins.cbegin(); histo.bins.cend() != ib; ++ib ) { xlabels.push_back( xLabel( ib->lower ) ); }
504  // overflow& underflow label
505  const std::string oLabel = xLabel( histo.over.lower );
506  const std::string uLabel = xLabel( histo.under.lower );
507  //
508  static const std::string s_UNDERFLOW( "UNDERFLOW" );
509  static const std::string s_OVERFLOW( " OVERFLOW" );
510  //
511  //
512  for ( unsigned int yLine = 0; yLine < 12; ++yLine ) {
513  std::string line = std::string( 12, ' ' );
514  //
515  if ( yLine < s_UNDERFLOW.size() ) {
516  line += s_UNDERFLOW[yLine];
517  } else {
518  line += ' ';
519  }
520  //
521  line += ' ';
522  //
523  if ( uLabel.size() > yLine ) {
524  line += uLabel[yLine];
525  } else {
526  line += ' ';
527  }
528  //
529  for ( auto ibin = histo.bins.cbegin(); histo.bins.cend() != ibin; ++ibin ) {
530  int ib = ibin - histo.bins.cbegin();
531  const bool xlab = ( iNull == ib % xSkip );
532  if ( xlab && yLine < xlabels[ib].size() ) {
533  line += xlabels[ib][yLine];
534  } else {
535  line += ' ';
536  }
537  }
538  //
539  if ( oLabel.size() > yLine ) {
540  line += oLabel[yLine];
541  } else {
542  line += ' ';
543  }
544  //
545  line += ' ';
546  //
547  if ( yLine < s_OVERFLOW.size() ) {
548  line += s_OVERFLOW[yLine];
549  } else {
550  line += ' ';
551  }
552  //
553  stream << line << std::endl;
554  }
555  //
556  return stream; // RETURN
557  }
558 } // namespace
559 // ============================================================================
560 /* dump the text representation of the histogram
561  * @param histo (INPUT) the histogram
562  * @param stream (OUTUT) the stream
563  * @param width (INPUT) the maximal column width
564  * @param height (INPUT) the proposed coulmn height
565  * @param errors (INPUT) print/plot errors
566  * @return the stream
567  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
568  * @date 2009-09-19
569  */
570 // ============================================================================
572  const std::size_t width, const std::size_t height, const bool errors ) {
573  stream << std::endl;
574  if ( !histo ) { return stream; } // RETURN
575  Histo hist;
576  StatusCode sc = _getHisto( histo, hist );
577  if ( sc.isFailure() ) { return stream; } // RETURN
578 
579  stream << fmt::format( R"( Histo TES : "{}"
580  Histo Title : "{}"
581 
582  Mean : {:11.5g} +- {:<10.4g}
583  Rms : {:11.5g} +- {:<10.4g}
584  Skewness : {:11.5g} +- {:<10.4g}
585  Kurtosis : {:11.5g} +- {:<10.4g}
586 
587  Entries :
588  | All | In Range | Underflow | Overflow | #Equivalent | Integral | Total |
589  | {:^9} | {:^9} | {:^9} | {:^9} | {:^11.5g} | {:^11.5g} | {:^11.5g} |
590 
591 )",
592  path( histo ), histo->title(), //
597  histo->allEntries(), histo->entries(), histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ),
598  histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ), histo->equivalentBinEntries(),
599  histo->sumBinHeights(), histo->sumAllBinHeights() );
600 
601  const AIDA::IAnnotation& a = histo->annotation();
602  if ( a.size() ) {
603  stream << " Annotation\n";
604  for ( int i = 0; i < a.size(); ++i ) {
605  stream << fmt::format( " | {:<25.25s} : {:<45.45s} |\n", a.key( i ), a.value( i ) );
606  }
607  stream << '\n';
608  }
609 
610  return dumpText( hist, width, height, errors, stream );
611 }
612 // ============================================================================
613 /* dump the text representation of the histogram
614  * @param histo the histogram
615  * @param stream the stream
616  * @param width the maximal column width
617  * @param height (INPUT) the proposed coulmn height
618  * @param errors (INPUT) print/plot errors
619  * @param erorrs print/plot errors
620  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
621  * @date 2009-09-19
622  */
623 // ============================================================================
624 std::string Gaudi::Utils::Histos::histoDump( const AIDA::IHistogram1D* histo, const std::size_t width,
625  const std::size_t height, const bool errors ) {
627  histoDump_( histo, stream, width, height, errors );
628  return stream.str();
629 }
630 // ============================================================================
631 /* dump the text representation of the 1D-profile
632  * @param histo (INPUT) the profile
633  * @param stream (OUTUT) the stream
634  * @param width (INPUT) the maximal column width
635  * @param height (INPUT) the proposed coulmn height
636  * @param spread (INPUT) plot spread/error?
637  * @return the stream
638  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
639  * @date 2009-09-19
640  */
641 // ============================================================================
643  const std::size_t width, const std::size_t height, const bool spread ) {
644  stream << std::endl;
645  if ( !histo ) { return stream; } // RETURN
646  Histo hist;
647  StatusCode sc = _getHisto( histo, hist, spread );
648  if ( sc.isFailure() ) { return stream; } // RETURN
649 
650  stream << fmt::format( R"( Histo TES : "{}"
651  Histo Title : "{}"
652 
653  Mean : {:11.5g}
654  Rms : {:11.5g}
655 
656  Entries :
657  | All | In Range | Underflow | Overflow | Integral | Total |
658  | {:^9} | {:^9} | {:^9} | {:^9} | {:^11.5g} | {:^11.5g} |
659 
660 )",
661  path( histo ), histo->title(), //
662  histo->mean(), histo->rms(), histo->allEntries(), histo->entries(),
663  histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ),
664  histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ), histo->sumBinHeights(),
665  histo->sumAllBinHeights() );
666 
667  const AIDA::IAnnotation& a = histo->annotation();
668  if ( a.size() ) {
669  stream << " Annotation\n";
670  for ( int i = 0; i < a.size(); ++i ) {
671  stream << fmt::format( " | {:<25.25s} : {:<45.45s} |\n", a.key( i ), a.value( i ) );
672  }
673  stream << std::endl;
674  }
675 
676  return dumpText( hist, width, height, true, stream );
677 }
678 // ============================================================================
679 /* dump the text representation of the 1D-profile
680  * @param histo the histogram
681  * @param stream the stream
682  * @param width the maximal column width
683  * @param height (INPUT) the proposed coulmn height
684  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
685  * @date 2009-09-19
686  */
687 // ============================================================================
688 std::string Gaudi::Utils::Histos::histoDump( const AIDA::IProfile1D* histo, const std::size_t width,
689  const std::size_t height, const bool spread ) {
691  histoDump_( histo, stream, width, height, spread );
692  return stream.str();
693 }
694 // ============================================================================
695 /* dump the text representation of the histogram
696  * @param histo (INPUT) the histogram
697  * @param stream (OUTUT) the stream
698  * @param width (INPUT) the maximal column width
699  * @param errors (INPUT) print/plot errors
700  * @return the stream
701  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
702  * @date 2009-09-19
703  */
704 // ============================================================================
706  const std::size_t height, const bool errors ) {
707  const TProfile* profile = dynamic_cast<const TProfile*>( histo );
708  if ( profile ) { return histoDump_( profile, stream, width, height ); }
709  //
710  stream << std::endl;
711  if ( !histo ) { return stream; } // RETURN
712  Histo hist;
713  StatusCode sc = _getHisto( histo, hist );
714  if ( sc.isFailure() ) { return stream; } // RETURN
715 
716  stream << fmt::format( R"( Histo Name : "{}"
717  Histo Title : "{}"
718 
719  Mean : {:11.5g} +- {:<10.4g}
720  Rms : {:11.5g} +- {:<10.4g}
721  Skewness : {:11.5g}
722  Kurtosis : {:11.5g}
723 
724  Entries :
725  | All | Underflow | Overflow | #Equivalent | Integral |
726  | {:^11.5g} | {:^11.5g} | {:^11.5g} | {:^11.5g} | {:^11.5g} |
727 
728 )",
729  histo->GetName(), histo->GetTitle(), //
730  histo->GetMean(), histo->GetMeanError(), histo->GetRMS(), histo->GetRMSError(),
731  histo->GetSkewness(), histo->GetKurtosis(), histo->GetEntries(), histo->GetBinContent( 0 ),
732  histo->GetBinContent( histo->GetNbinsX() + 1 ), histo->GetEffectiveEntries(),
733  histo->Integral() );
734 
735  return dumpText( hist, width, height, errors, stream );
736 }
737 // ============================================================================
738 /* dump the text representation of the histogram
739  * @param histo (INPUT) the histogram
740  * @param stream (OUTUT) the stream
741  * @param width (INPUT) the maximal column width
742  * @param errors (INPUT) print/plot errors
743  * @return the stream
744  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
745  * @date 2009-09-19
746  */
747 // ============================================================================
749  const std::size_t height ) {
750  stream << std::endl;
751  if ( !histo ) { return stream; } // RETURN
752  Histo hist;
753  StatusCode sc = _getHisto( histo, hist, true );
754  if ( sc.isFailure() ) { return stream; } // RETURN
755 
756  stream << fmt::format( R"( Profile Name : "{}"
757  Profile Title : "{}"
758 
759  Mean : {:11.5g}
760  Rms : {:11.5g}
761 
762  Entries :
763  | All | Underflow | Overflow | Integral |
764  | {:^11.5g} | {:^11.5g} | {:^11.5g} | {:^11.5g} |
765 
766 )",
767  histo->GetName(), histo->GetTitle(), //
768  histo->GetMean(), histo->GetRMS(), histo->GetSkewness(), histo->GetKurtosis(),
769  histo->GetEntries(), histo->GetBinContent( 0 ), histo->GetBinContent( histo->GetNbinsX() + 1 ),
770  histo->Integral() );
771 
772  return dumpText( hist, width, height, true, stream );
773 }
774 // ============================================================================
775 /* dump the text representation of the histogram
776  * @param histo (INPUT) the histogram
777  * @param width (INPUT) the maximal column width
778  * @param errors (INPUT) print/plot errors
779  * @return string representation of the histogram
780  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
781  * @date 2009-09-19
782  */
783 // ============================================================================
785  const bool errors ) {
787  histoDump_( histo, stream, width, height, errors );
788  return stream.str();
789 }
790 // ============================================================================
791 /* dump the text representation of the histogram
792  * @param histo (INPUT) the histogram
793  * @param width (INPUT) the maximal column width
794  * @param errors (INPUT) print/plot errors
795  * @return string representation of the histogram
796  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
797  * @date 2009-09-19
798  */
799 // ============================================================================
801  const std::size_t height ) {
803  histoDump_( histo, stream, width, height );
804  return stream.str();
805 }
806 // ============================================================================
807 
808 // ============================================================================
809 // The END
810 // ============================================================================
HistoStats.h
std::floor
T floor(T... args)
Write.stream
stream
Definition: Write.py:32
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:22
HistoEx.histo
histo
Definition: HistoEx.py:105
std::pair
std::vector
STL class.
std::string::size
T size(T... args)
Gaudi::Utils::HistoStats::rmsErr
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:661
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:43
Gaudi::Utils::Histos::histoDump
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:624
StatusCode.h
Gaudi::Utils::HistoStats::kurtosisErr
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:621
std::sqrt
T sqrt(T... args)
Gaudi::Utils::Histos::histoDump_
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:571
std::vector::push_back
T push_back(T... args)
Gaudi::Utils::HistoStats::meanErr
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:645
StatusCode
Definition: StatusCode.h:65
HistoDumpEx.r
r
Definition: HistoDumpEx.py:20
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:108
std::ostream
STL class.
AlgSequencer.h
h
Definition: AlgSequencer.py:32
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:961
std::accumulate
T accumulate(T... args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::ceil
T ceil(T... args)
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:235
std::min
T min(T... args)
HistoDumpEx.v
v
Definition: HistoDumpEx.py:27
std::ostringstream
STL class.
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
std::endl
T endl(T... args)
std::right
T right(T... args)
gaudirun.l
dictionary l
Definition: gaudirun.py:580
std::begin
T begin(T... args)
Gaudi::Utils::HistoStats::mean
static double mean(const AIDA::IHistogram1D *histo)
get the mean value for the histogram (just for completeness)
Definition: HistoStats.cpp:637
Gaudi::Utils::HistoStats::rms
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
Definition: HistoStats.cpp:653
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:193
Gaudi::Utils::HistoStats::kurtosis
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:613
HepRndm::Engine
Definition: HepRndmEngine.h:35
std::size_t
std::end
T end(T... args)
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
plotBacklogPyRoot.maxY
int maxY
Definition: plotBacklogPyRoot.py:36
std::max
T max(T... args)
Gaudi::Utils::HistoStats::skewnessErr
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:605
HistoTableFormat.h
Gaudi::Utils::HistoStats::skewness
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:597
HistoDump.h