The Gaudi Framework  v36r1 (3e2fb5a8)
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 =
408  0 == yBins % 13
409  ? 13
410  : 0 == yBins % 11
411  ? 11
412  : 0 == yBins % 9
413  ? 9
414  : 0 == yBins % 8
415  ? 8
416  : 0 == yBins % 7 ? 7 : 0 == yBins % 6 ? 6 : 0 == yBins % 5 ? 5 : 0 == yBins % 4 ? 4 : 10;
417 
418  const int xSkip =
419  // 0 == nBins % 8 ? 8 :
420  0 == nBins % 7 ? 7 : 0 == nBins % 6 ? 6 : 0 == nBins % 5 ? 5 : 0 == nBins % 4 ? 4 : 10;
421 
422  int iNull = histo.nullBin();
423 
424  if ( 0 <= iNull ) {
425  iNull %= xSkip;
426  } else {
427  iNull = 0;
428  }
429 
430  stream << std::endl;
431 
432  for ( int yLine = -1; yLine < yBins; ++yLine ) {
433  const double yHigh = yMax - yScale * yLine;
434  // const double yLow = yHigh - yScale ;
435  const double yLow = yMax - yScale * ( yLine + 1 );
436  //
437  std::string line1 = " ";
438 
439  const bool ynull = ( yLow <= 0 && 0 < yHigh );
440  const bool yfirst = -1 == yLine || yBins - 1 == yLine;
441  const bool ylab = ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull;
442 
443  if ( ylab ) {
444  line1 += yLabel( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow );
445  } else {
446  line1 += std::string( 10, ' ' );
447  }
448  //
449  line1 += " ";
450  //
452  line1 += symbBin( histo.under, yLow, yHigh, ynull, errors );
453  //
454  line1 += ynull ? "-+" : ylab ? " +" : " |";
455  //
456  std::string line2;
457  //
458  for ( auto ibin = histo.bins.cbegin(); histo.bins.cend() != ibin; ++ibin ) {
459  // char symb = ' ' ;
460  const int i = ibin - histo.bins.cbegin();
461  //
462  const bool xnull = ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.cend() && 0 < ( ibin + 1 )->lower;
463  const bool xlab = iNull == i % xSkip;
464  //
465  char symb = symbBin( *ibin, yLow, yHigh, ynull, errors );
466  //
467  if ( ' ' == symb ) {
468  if ( ( ynull || yfirst ) && xlab ) {
469  symb = '+';
470  } else if ( ynull || yfirst ) {
471  symb = '-';
472  }
473  //
474  else if ( ylab && xnull ) {
475  symb = '+';
476  } else if ( xnull ) {
477  symb = '|';
478  }
479  //
480  else if ( ylab || xlab ) {
481  symb = '.';
482  }
483  //
484  }
485  line2 += symb;
486  //
487  }
488  //
489  std::string line3 = ynull ? "->" : ylab ? "+ " : "| ";
490  //
492  line3 += symbBin( histo.over, yLow, yHigh, ynull, errors );
493  //
494  stream << line1 << line2 << line3 << std::endl;
495  //
496  }
497 
498  // get x-labels
499  std::vector<std::string> xlabels;
500  for ( auto ib = histo.bins.cbegin(); histo.bins.cend() != ib; ++ib ) { xlabels.push_back( xLabel( ib->lower ) ); }
501  // overflow& underflow label
502  const std::string oLabel = xLabel( histo.over.lower );
503  const std::string uLabel = xLabel( histo.under.lower );
504  //
505  static const std::string s_UNDERFLOW( "UNDERFLOW" );
506  static const std::string s_OVERFLOW( " OVERFLOW" );
507  //
508  //
509  for ( unsigned int yLine = 0; yLine < 12; ++yLine ) {
510  std::string line = std::string( 12, ' ' );
511  //
512  if ( yLine < s_UNDERFLOW.size() ) {
513  line += s_UNDERFLOW[yLine];
514  } else {
515  line += ' ';
516  }
517  //
518  line += ' ';
519  //
520  if ( uLabel.size() > yLine ) {
521  line += uLabel[yLine];
522  } else {
523  line += ' ';
524  }
525  //
526  for ( auto ibin = histo.bins.cbegin(); histo.bins.cend() != ibin; ++ibin ) {
527  int ib = ibin - histo.bins.cbegin();
528  const bool xlab = ( iNull == ib % xSkip );
529  if ( xlab && yLine < xlabels[ib].size() ) {
530  line += xlabels[ib][yLine];
531  } else {
532  line += ' ';
533  }
534  }
535  //
536  if ( oLabel.size() > yLine ) {
537  line += oLabel[yLine];
538  } else {
539  line += ' ';
540  }
541  //
542  line += ' ';
543  //
544  if ( yLine < s_OVERFLOW.size() ) {
545  line += s_OVERFLOW[yLine];
546  } else {
547  line += ' ';
548  }
549  //
550  stream << line << std::endl;
551  }
552  //
553  return stream; // RETURN
554  }
555 } // namespace
556 // ============================================================================
557 /* dump the text representation of the histogram
558  * @param histo (INPUT) the histogram
559  * @param stream (OUTUT) the stream
560  * @param width (INPUT) the maximal column width
561  * @param height (INPUT) the proposed coulmn height
562  * @param errors (INPUT) print/plot errors
563  * @return the stream
564  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
565  * @date 2009-09-19
566  */
567 // ============================================================================
569  const std::size_t width, const std::size_t height, const bool errors ) {
570  stream << std::endl;
571  if ( !histo ) { return stream; } // RETURN
572  Histo hist;
573  StatusCode sc = _getHisto( histo, hist );
574  if ( sc.isFailure() ) { return stream; } // RETURN
575 
576  stream << fmt::format( R"( Histo TES : "{}"
577  Histo Title : "{}"
578 
579  Mean : {:11.5g} +- {:<10.4g}
580  Rms : {:11.5g} +- {:<10.4g}
581  Skewness : {:11.5g} +- {:<10.4g}
582  Kurtosis : {:11.5g} +- {:<10.4g}
583 
584  Entries :
585  | All | In Range | Underflow | Overflow | #Equivalent | Integral | Total |
586  | {:^9} | {:^9} | {:^9} | {:^9} | {:^11.5g} | {:^11.5g} | {:^11.5g} |
587 
588 )",
589  path( histo ), histo->title(), //
594  histo->allEntries(), histo->entries(), histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ),
595  histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ), histo->equivalentBinEntries(),
596  histo->sumBinHeights(), histo->sumAllBinHeights() );
597 
598  const AIDA::IAnnotation& a = histo->annotation();
599  if ( a.size() ) {
600  stream << " Annotation\n";
601  for ( int i = 0; i < a.size(); ++i ) {
602  stream << fmt::format( " | {:<25.25s} : {:<45.45s} |\n", a.key( i ), a.value( i ) );
603  }
604  stream << '\n';
605  }
606 
607  return dumpText( hist, width, height, errors, stream );
608 }
609 // ============================================================================
610 /* dump the text representation of the histogram
611  * @param histo the histogram
612  * @param stream the stream
613  * @param width the maximal column width
614  * @param height (INPUT) the proposed coulmn height
615  * @param errors (INPUT) print/plot errors
616  * @param erorrs print/plot errors
617  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
618  * @date 2009-09-19
619  */
620 // ============================================================================
621 std::string Gaudi::Utils::Histos::histoDump( const AIDA::IHistogram1D* histo, const std::size_t width,
622  const std::size_t height, const bool errors ) {
624  histoDump_( histo, stream, width, height, errors );
625  return stream.str();
626 }
627 // ============================================================================
628 /* dump the text representation of the 1D-profile
629  * @param histo (INPUT) the profile
630  * @param stream (OUTUT) the stream
631  * @param width (INPUT) the maximal column width
632  * @param height (INPUT) the proposed coulmn height
633  * @param spread (INPUT) plot spread/error?
634  * @return the stream
635  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
636  * @date 2009-09-19
637  */
638 // ============================================================================
640  const std::size_t width, const std::size_t height, const bool spread ) {
641  stream << std::endl;
642  if ( !histo ) { return stream; } // RETURN
643  Histo hist;
644  StatusCode sc = _getHisto( histo, hist, spread );
645  if ( sc.isFailure() ) { return stream; } // RETURN
646 
647  stream << fmt::format( R"( Histo TES : "{}"
648  Histo Title : "{}"
649 
650  Mean : {:11.5g}
651  Rms : {:11.5g}
652 
653  Entries :
654  | All | In Range | Underflow | Overflow | Integral | Total |
655  | {:^9} | {:^9} | {:^9} | {:^9} | {:^11.5g} | {:^11.5g} |
656 
657 )",
658  path( histo ), histo->title(), //
659  histo->mean(), histo->rms(), histo->allEntries(), histo->entries(),
660  histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ),
661  histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ), histo->sumBinHeights(),
662  histo->sumAllBinHeights() );
663 
664  const AIDA::IAnnotation& a = histo->annotation();
665  if ( a.size() ) {
666  stream << " Annotation\n";
667  for ( int i = 0; i < a.size(); ++i ) {
668  stream << fmt::format( " | {:<25.25s} : {:<45.45s} |\n", a.key( i ), a.value( i ) );
669  }
670  stream << std::endl;
671  }
672 
673  return dumpText( hist, width, height, true, stream );
674 }
675 // ============================================================================
676 /* dump the text representation of the 1D-profile
677  * @param histo the histogram
678  * @param stream the stream
679  * @param width the maximal column width
680  * @param height (INPUT) the proposed coulmn height
681  * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
682  * @date 2009-09-19
683  */
684 // ============================================================================
685 std::string Gaudi::Utils::Histos::histoDump( const AIDA::IProfile1D* histo, const std::size_t width,
686  const std::size_t height, const bool spread ) {
688  histoDump_( histo, stream, width, height, spread );
689  return stream.str();
690 }
691 // ============================================================================
692 /* dump the text representation of the histogram
693  * @param histo (INPUT) the histogram
694  * @param stream (OUTUT) the stream
695  * @param width (INPUT) the maximal column width
696  * @param errors (INPUT) print/plot errors
697  * @return the stream
698  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
699  * @date 2009-09-19
700  */
701 // ============================================================================
703  const std::size_t height, const bool errors ) {
704  const TProfile* profile = dynamic_cast<const TProfile*>( histo );
705  if ( profile ) { return histoDump_( profile, stream, width, height ); }
706  //
707  stream << std::endl;
708  if ( !histo ) { return stream; } // RETURN
709  Histo hist;
710  StatusCode sc = _getHisto( histo, hist );
711  if ( sc.isFailure() ) { return stream; } // RETURN
712 
713  stream << fmt::format( R"( Histo Name : "{}"
714  Histo Title : "{}"
715 
716  Mean : {:11.5g} +- {:<10.4g}
717  Rms : {:11.5g} +- {:<10.4g}
718  Skewness : {:11.5g}
719  Kurtosis : {:11.5g}
720 
721  Entries :
722  | All | Underflow | Overflow | #Equivalent | Integral |
723  | {:^11.5g} | {:^11.5g} | {:^11.5g} | {:^11.5g} | {:^11.5g} |
724 
725 )",
726  histo->GetName(), histo->GetTitle(), //
727  histo->GetMean(), histo->GetMeanError(), histo->GetRMS(), histo->GetRMSError(),
728  histo->GetSkewness(), histo->GetKurtosis(), histo->GetEntries(), histo->GetBinContent( 0 ),
729  histo->GetBinContent( histo->GetNbinsX() + 1 ), histo->GetEffectiveEntries(),
730  histo->Integral() );
731 
732  return dumpText( hist, width, height, errors, stream );
733 }
734 // ============================================================================
735 /* dump the text representation of the histogram
736  * @param histo (INPUT) the histogram
737  * @param stream (OUTUT) the stream
738  * @param width (INPUT) the maximal column width
739  * @param errors (INPUT) print/plot errors
740  * @return the stream
741  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
742  * @date 2009-09-19
743  */
744 // ============================================================================
746  const std::size_t height ) {
747  stream << std::endl;
748  if ( !histo ) { return stream; } // RETURN
749  Histo hist;
750  StatusCode sc = _getHisto( histo, hist, true );
751  if ( sc.isFailure() ) { return stream; } // RETURN
752 
753  stream << fmt::format( R"( Profile Name : "{}"
754  Profile Title : "{}"
755 
756  Mean : {:11.5g}
757  Rms : {:11.5g}
758 
759  Entries :
760  | All | Underflow | Overflow | Integral |
761  | {:^11.5g} | {:^11.5g} | {:^11.5g} | {:^11.5g} |
762 
763 )",
764  histo->GetName(), histo->GetTitle(), //
765  histo->GetMean(), histo->GetRMS(), histo->GetSkewness(), histo->GetKurtosis(),
766  histo->GetEntries(), histo->GetBinContent( 0 ), histo->GetBinContent( histo->GetNbinsX() + 1 ),
767  histo->Integral() );
768 
769  return dumpText( hist, width, height, true, stream );
770 }
771 // ============================================================================
772 /* dump the text representation of the histogram
773  * @param histo (INPUT) the histogram
774  * @param width (INPUT) the maximal column width
775  * @param errors (INPUT) print/plot errors
776  * @return string representation of the histogram
777  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
778  * @date 2009-09-19
779  */
780 // ============================================================================
782  const bool errors ) {
784  histoDump_( histo, stream, width, height, errors );
785  return stream.str();
786 }
787 // ============================================================================
788 /* dump the text representation of the histogram
789  * @param histo (INPUT) the histogram
790  * @param width (INPUT) the maximal column width
791  * @param errors (INPUT) print/plot errors
792  * @return string representation of the histogram
793  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
794  * @date 2009-09-19
795  */
796 // ============================================================================
798  const std::size_t height ) {
800  histoDump_( histo, stream, width, height );
801  return stream.str();
802 }
803 // ============================================================================
804 
805 // ============================================================================
806 // The END
807 // ============================================================================
HistoStats.h
std::floor
T floor(T... args)
Write.stream
stream
Definition: Write.py:31
std::string
STL class.
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:22
HistoEx.histo
histo
Definition: HistoEx.py:103
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:38
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:621
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:568
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:26
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:943
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:221
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:142
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:553
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:181
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:33
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