| The Gaudi Framework v32r1 (f65d50dc)

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 <iostream>
22 #include <numeric>
23 #include <sstream>
24 #include <utility>
25 #include <vector>
26 // ============================================================================
27 // AIDA
28 // ============================================================================
29 #include "AIDA/IAnnotation.h"
30 #include "AIDA/IAxis.h"
31 #include "AIDA/IHistogram1D.h"
32 #include "AIDA/IProfile1D.h"
33 // ============================================================================
34 // GaudiKernel
35 // ============================================================================
36 #include "GaudiKernel/StatusCode.h"
37 // ============================================================================
38 // ROOT
39 // ============================================================================
40 #include "TAxis.h"
41 #include "TH1.h"
42 #include "TProfile.h"
43 // ============================================================================
44 // Boost
45 // ============================================================================
46 #include "boost/format.hpp"
47 // ============================================================================
48 // Local
49 // ============================================================================
50 #include "GaudiUtils/HistoDump.h"
51 #include "GaudiUtils/HistoStats.h"
52 #include "GaudiUtils/HistoTableFormat.h"
53 // ============================================================================
54 namespace {
55 // ==========================================================================
61 struct Histo {
62 // ========================================================================
63 Histo() = default;
64 // ========================================================================
70 struct Bin {
71 // ======================================================================
72 Bin( const double h = 0, const double e = 0, const double l = -1 ) : height( h ), error( e ), lower( l ) {}
73 // ======================================================================
75 double height; // bin height
77 double error; // bin error
79 double lower; // lower edge
80 // ======================================================================
81 Bin& operator+=( const Bin& right ) {
82 height += right.height;
83 const double e2 = error * error + right.error * right.error;
84 error = std::sqrt( e2 );
85 return *this;
86 }
87 // ======================================================================
88 };
89 // ========================================================================
91 double maxY( const bool withErr ) const {
92 return std::accumulate(
93 std::begin( bins ), std::end( bins ), std::max( under.height, over.height ),
94 [&]( double m, const Bin& b ) { return std::max( m, withErr ? b.height + b.error : b.height ); } );
95 }
97 double minY( const bool withErr ) const {
98 return std::accumulate(
99 std::begin( bins ), std::end( bins ), std::min( under.height, over.height ),
100 [&]( double m, const Bin& b ) { return std::min( m, withErr ? b.height - b.error : b.height ); } );
101 }
103 Histo rebin( const unsigned int bin ) const {
104 // create new histogram
105 Histo nh;
106 // copy overflow & underflow bins
107 nh.under = under;
108 nh.over = over;
109 // rebin
110 for ( unsigned int ibin = 0; ibin < bins.size(); ++ibin ) {
111 const Bin& current = bins[ibin];
112 if ( nh.bins.empty() ) {
113 nh.bins.push_back( current );
114 } else if ( 0 == ibin % bin ) {
115 nh.bins.push_back( current );
116 } else {
117 nh.bins.back() += current;
118 }
119 }
120 return nh;
121 }
122 // find "null-bin", if any
123 int nullBin() const {
124 for ( auto ib = bins.cbegin(); bins.cend() != ib + 1; ++ib ) {
125 if ( ib->lower <= 0 && 0 < ( ib + 1 )->lower ) { return ib - bins.cbegin(); }
126 }
127 return -1;
128 }
129 // ========================================================================
130 typedef std::vector<Bin> Bins;
131 // ========================================================================
133 Bins bins; // histogram bins
135 Bin under; // underflow bin
137 Bin over; // overflow bin
138 // ========================================================================
139 };
140 // ==========================================================================
148 StatusCode _getHisto( const TH1* root, Histo& hist ) {
149 // clear the histogram
150 hist.bins.clear();
151 //
152 if ( !root ) { return StatusCode::FAILURE; } // RETURN
153 const TAxis* axis = root->GetXaxis();
154 if ( !axis ) { return StatusCode::FAILURE; } // RETURN
155 const int nbins = axis->GetNbins();
156 if ( 0 == nbins ) { return StatusCode::FAILURE; } // RETURN
157
158 // underflow bin
159 hist.under = Histo::Bin( root->GetBinContent( 0 ), root->GetBinError( 0 ), axis->GetXmin() );
160 // overflow bin
161 hist.over = Histo::Bin( root->GetBinContent( nbins + 1 ), root->GetBinError( nbins + 1 ), axis->GetXmax() );
162 //
163 //
164 for ( int ibin = 1; ibin <= nbins; ++ibin ) {
165 // add to the local histo
166 hist.bins.emplace_back( root->GetBinContent( ibin ), root->GetBinError( ibin ), axis->GetBinLowEdge( ibin ) );
167 }
168 return StatusCode::SUCCESS;
169 }
170 // ==========================================================================
178 StatusCode _getHisto( const TProfile* root, Histo& hist, const bool /* spread */ ) {
179 const TH1* histo = root;
180 return _getHisto( histo, hist );
181 }
182 // ==========================================================================
190 StatusCode _getHisto( const AIDA::IHistogram1D* aida, Histo& hist ) {
191 // clear the histogram
192 hist.bins.clear();
193 //
194 if ( !aida ) { return StatusCode::FAILURE; } // RETURN
195 //
196 const AIDA::IAxis& axis = aida->axis();
197 const int nbins = axis.bins();
198 //
199 // underflow bin
200 hist.under = Histo::Bin( aida->binHeight( AIDA::IAxis::UNDERFLOW_BIN ),
201 aida->binError( AIDA::IAxis::UNDERFLOW_BIN ), axis.lowerEdge() );
202 // overflow bin
203 hist.over = Histo::Bin( aida->binHeight( AIDA::IAxis::OVERFLOW_BIN ), aida->binError( AIDA::IAxis::OVERFLOW_BIN ),
204 axis.upperEdge() );
205 //
206 for ( int ibin = 0; ibin < nbins; ++ibin ) {
207 // add to the local histo
208 hist.bins.emplace_back( aida->binHeight( ibin ), aida->binError( ibin ), axis.binLowerEdge( ibin ) );
209 }
210 return StatusCode::SUCCESS;
211 }
212 // ==========================================================================
220 StatusCode _getHisto( const AIDA::IProfile1D* aida, Histo& hist, const bool spread ) {
221 // clear the histogram
222 hist.bins.clear();
223 //
224 if ( !aida ) { return StatusCode::FAILURE; } // RETURN
225 //
226 const AIDA::IAxis& axis = aida->axis();
227 const int nbins = axis.bins();
228 //
229 // underflow bin
230 hist.under =
231 Histo::Bin( aida->binHeight( AIDA::IAxis::UNDERFLOW_BIN ),
232 spread ? aida->binRms( AIDA::IAxis::UNDERFLOW_BIN ) : aida->binError( AIDA::IAxis::UNDERFLOW_BIN ),
233 axis.lowerEdge() );
234 // overflow bin
235 hist.over =
236 Histo::Bin( aida->binHeight( AIDA::IAxis::OVERFLOW_BIN ),
237 spread ? aida->binRms( AIDA::IAxis::OVERFLOW_BIN ) : aida->binError( AIDA::IAxis::OVERFLOW_BIN ),
238 axis.upperEdge() );
239 //
240 for ( int ibin = 0; ibin < nbins; ++ibin ) {
241 // add to the local histo
242 hist.bins.emplace_back( aida->binHeight( ibin ), spread ? aida->binRms( ibin ) : aida->binError( ibin ),
243 axis.binLowerEdge( ibin ) );
244 }
245 return StatusCode::SUCCESS;
246 }
247 // ==========================================================================
253 inline unsigned int rebin( const unsigned int bins, const unsigned int imax ) {
254 if ( 0 == imax ) { return 1; } // RETURN
255 unsigned int ibin = 1;
256 while ( bins > imax * ibin ) { ++ibin; }
257 return ibin; // RETURN
258 }
259 // ==========================================================================
265 std::pair<double, int> decompose( double v ) {
266 if ( 0 == v ) {
267 return {0.0, 0};
268 } // RETURN
269 else if ( 1 == v ) {
270 return {1.0, 0};
271 } // RETURN
272 else if ( 0 > v ) {
273 auto r = decompose( -v );
274 return {-r.first, r.second}; // RETURN
275 } else if ( 0.1 > v ) {
276 int i = 0;
277 while ( 0.1 > v ) {
278 ++i;
279 v *= 10;
280 } // STUPID
281 return {v, -i};
282 } else if ( 1 < v ) {
283 int i = 0;
284 while ( 1 <= v ) {
285 ++i;
286 v /= 10;
287 } // STUPID
288 return {v, i};
289 }
290 return {v, 1};
291 }
292 // ==========================================================================
297 inline double _pow( double x, unsigned long n ) {
298 double y = n % 2 ? x : 1;
299 while ( n >>= 1 ) {
300 x = x * x;
301 if ( n % 2 ) { y *= x; }
302 }
303 return y;
304 }
305 // forward declaration to break cyclic dependency between rValMin and rValMax
306 inline double rValMin( double v );
307 // ==========================================================================
312 inline double rValMax( double v ) {
313 if ( 0 == v ) {
314 return 0;
315 } // RETURN
316 else if ( 0 > v ) {
317 return -1 * rValMin( -v );
318 } // RETURN
319 // decompose the double value into decimal significand and mantissa
320 std::pair<double, int> r = decompose( v );
321 //
322 const double f = std::ceil( 20 * r.first ) / 2; // + 1 ;
323 const int l = r.second - 1;
324 return 0 < l ? f * _pow( 10, l ) : f / _pow( 10, -l );
325 }
326 // ==========================================================================
331 inline double rValMin( double v ) {
332 if ( 0 == v ) {
333 return 0;
334 } // RETURN
335 else if ( 0 > v ) {
336 return -1 * rValMax( -v );
337 } // RETURN
338 // decompose the double value into decimal significand and mantissa
339 std::pair<double, int> r = decompose( v );
340 const double f = std::floor( 20 * r.first ) / 2; // - 1 ;
341 const int l = r.second - 1;
342 return 0 < l ? f * _pow( 10, l ) : f / _pow( 10, -l );
343 }
344 // ==========================================================================
349 inline std::string yLabel( double value ) {
350 boost::format fmt( "%10.3g" );
351 fmt % value;
352 return fmt.str();
353 }
354 // ==========================================================================
359 inline std::string xLabel( const double value ) {
360 boost::format fmt( "%9.3g" );
361 fmt % value;
362 return fmt.str();
363 }
364 // ==========================================================================
366 char symbBin( const Histo::Bin& bin, const double yLow, const double yHigh, const bool yNull, const bool errors ) {
367 if ( errors && yLow <= bin.height && bin.height < yHigh ) {
368 return '*';
369 } // O
370 else if ( errors && yHigh < bin.height - bin.error ) {
371 return ' ';
372 } else if ( errors && yLow >= bin.height + bin.error ) {
373 return ' ';
374 } else if ( errors ) {
375 return 'I';
376 } else if ( yLow <= bin.height && bin.height < yHigh ) {
377 return '*';
378 } else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) {
379 return '*';
380 } // +
381 else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) {
382 return '*';
383 } // -
384 //
385 return ' ';
386 }
387 // ==========================================================================
392 std::ostream& dumpText( const Histo& histo, const std::size_t width, const std::size_t height, const bool errors,
393 std::ostream& stream ) {
394 if ( 40 > width ) { return dumpText( histo, 40, height, errors, stream ); }
395 if ( 200 < width ) { return dumpText( histo, 200, height, errors, stream ); }
396 if ( 150 < height ) { return dumpText( histo, width, 150, errors, stream ); }
397 if ( 20 > height ) { return dumpText( histo, width, 20, errors, stream ); }
398 if ( height > width ) { return dumpText( histo, width, width, errors, stream ); }
399 //
400 const unsigned int nBins = histo.bins.size();
401 if ( nBins > width ) {
402 // rebin histogram
403 Histo r = histo.rebin( rebin( nBins, width ) );
404 return dumpText( r, width, height, errors, stream );
405 }
406 //
407 // get the Y-scale
408 double yMax = std::max( rValMax( histo.maxY( errors ) ), 0.0 );
409 double yMin = std::min( rValMin( histo.minY( errors ) ), 0.0 );
410
411 if ( yMin == yMax ) { yMax = yMin + 1; }
413 std::pair<double, int> r = decompose( yMax - yMin );
414 double _ny = std::ceil( 10 * r.first ); // 1 <= ny < 10
415 if ( 1 >= _ny ) { _ny = 10; }
416 int yBins = (int)std::max( 1., std::ceil( height / _ny ) );
417
418 yBins *= (int)_ny;
419 if ( 20 > yBins ) { yBins = 20; }
420 const double yScale = ( yMax - yMin ) / yBins;
421
422 //
423 const int ySkip =
424 0 == yBins % 13
425 ? 13
426 : 0 == yBins % 11
427 ? 11
428 : 0 == yBins % 9
429 ? 9
430 : 0 == yBins % 8
431 ? 8
432 : 0 == yBins % 7 ? 7 : 0 == yBins % 6 ? 6 : 0 == yBins % 5 ? 5 : 0 == yBins % 4 ? 4 : 10;
433
434 const int xSkip =
435 // 0 == nBins % 8 ? 8 :
436 0 == nBins % 7 ? 7 : 0 == nBins % 6 ? 6 : 0 == nBins % 5 ? 5 : 0 == nBins % 4 ? 4 : 10;
437
438 int iNull = histo.nullBin();
439
440 if ( 0 <= iNull ) {
441 iNull %= xSkip;
442 } else {
443 iNull = 0;
444 }
445
446 stream << std::endl;
447
448 for ( int yLine = -1; yLine < yBins; ++yLine ) {
449 const double yHigh = yMax - yScale * yLine;
450 // const double yLow = yHigh - yScale ;
451 const double yLow = yMax - yScale * ( yLine + 1 );
452 //
453 std::string line1 = " ";
454
455 const bool ynull = ( yLow <= 0 && 0 < yHigh );
456 const bool yfirst = -1 == yLine || yBins - 1 == yLine;
457 const bool ylab = ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull;
458
459 if ( ylab ) {
460 line1 += yLabel( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow );
461 } else {
462 line1 += std::string( 10, ' ' );
463 }
464 //
465 line1 += " ";
466 //
468 line1 += symbBin( histo.under, yLow, yHigh, ynull, errors );
469 //
470 line1 += ynull ? "-+" : ylab ? " +" : " |";
471 //
472 std::string line2;
473 //
474 for ( auto ibin = histo.bins.cbegin(); histo.bins.cend() != ibin; ++ibin ) {
475 // char symb = ' ' ;
476 const int i = ibin - histo.bins.cbegin();
477 //
478 const bool xnull = ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.cend() && 0 < ( ibin + 1 )->lower;
479 const bool xlab = iNull == i % xSkip;
480 //
481 char symb = symbBin( *ibin, yLow, yHigh, ynull, errors );
482 //
483 if ( ' ' == symb ) {
484 if ( ( ynull || yfirst ) && xlab ) {
485 symb = '+';
486 } else if ( ynull || yfirst ) {
487 symb = '-';
488 }
489 //
490 else if ( ylab && xnull ) {
491 symb = '+';
492 } else if ( xnull ) {
493 symb = '|';
494 }
495 //
496 else if ( ylab || xlab ) {
497 symb = '.';
498 }
499 //
500 }
501 line2 += symb;
502 //
503 }
504 //
505 std::string line3 = ynull ? "->" : ylab ? "+ " : "| ";
506 //
508 line3 += symbBin( histo.over, yLow, yHigh, ynull, errors );
509 //
510 stream << line1 << line2 << line3 << std::endl;
511 //
512 }
513
514 // get x-labels
515 std::vector<std::string> xlabels;
516 for ( auto ib = histo.bins.cbegin(); histo.bins.cend() != ib; ++ib ) { xlabels.push_back( xLabel( ib->lower ) ); }
517 // overflow& underflow label
518 const std::string oLabel = xLabel( histo.over.lower );
519 const std::string uLabel = xLabel( histo.under.lower );
520 //
521 static const std::string s_UNDERFLOW( "UNDERFLOW" );
522 static const std::string s_OVERFLOW( " OVERFLOW" );
523 //
524 //
525 for ( unsigned int yLine = 0; yLine < 12; ++yLine ) {
526 std::string line = std::string( 12, ' ' );
527 //
528 if ( yLine < s_UNDERFLOW.size() ) {
529 line += s_UNDERFLOW[yLine];
530 } else {
531 line += ' ';
532 }
533 //
534 line += ' ';
535 //
536 if ( uLabel.size() > yLine ) {
537 line += uLabel[yLine];
538 } else {
539 line += ' ';
540 }
541 //
542 for ( auto ibin = histo.bins.cbegin(); histo.bins.cend() != ibin; ++ibin ) {
543 int ib = ibin - histo.bins.cbegin();
544 const bool xlab = ( iNull == ib % xSkip );
545 if ( xlab && yLine < xlabels[ib].size() ) {
546 line += xlabels[ib][yLine];
547 } else {
548 line += ' ';
549 }
550 }
551 //
552 if ( oLabel.size() > yLine ) {
553 line += oLabel[yLine];
554 } else {
555 line += ' ';
556 }
557 //
558 line += ' ';
559 //
560 if ( yLine < s_OVERFLOW.size() ) {
561 line += s_OVERFLOW[yLine];
562 } else {
563 line += ' ';
564 }
565 //
566 stream << line << std::endl;
567 }
568 //
569 return stream; // RETURN
570 }
571 } // namespace
572 // ============================================================================
573 /* dump the text representation of the histogram
574 * @param histo (INPUT) the histogram
575 * @param stream (OUTUT) the stream
576 * @param width (INPUT) the maximal column width
577 * @param height (INPUT) the proposed coulmn height
578 * @param errors (INPUT) print/plot errors
579 * @return the stream
580 * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
581 * @date 2009-09-19
582 */
583 // ============================================================================
584 std::ostream& Gaudi::Utils::Histos::histoDump_( const AIDA::IHistogram1D* histo, std::ostream& stream,
585 const std::size_t width, const std::size_t height, const bool errors ) {
586 stream << std::endl;
587 if ( !histo ) { return stream; } // RETURN
588 Histo hist;
589 StatusCode sc = _getHisto( histo, hist );
590 if ( sc.isFailure() ) { return stream; } // RETURN
591 //
592 stream << boost::format( " Histo TES : \"%s\"" ) % path( histo ) << std::endl
593 << boost::format( " Histo Title : \"%s\"" ) % histo->title() << std::endl
594 << std::endl;
595 //
596 stream << boost::format( " Mean : %11.5g +- %-10.4g " ) % Gaudi::Utils::HistoStats::mean( histo ) %
597 Gaudi::Utils::HistoStats::meanErr( histo )
598 << std::endl
599 << boost::format( " Rms : %11.5g +- %-10.4g " ) % Gaudi::Utils::HistoStats::rms( histo ) %
600 Gaudi::Utils::HistoStats::rmsErr( histo )
601 << std::endl
602 << boost::format( " Skewness : %11.5g +- %-10.4g " ) % Gaudi::Utils::HistoStats::skewness( histo ) %
603 Gaudi::Utils::HistoStats::skewnessErr( histo )
604 << std::endl
605 << boost::format( " Kurtosis : %11.5g +- %-10.4g " ) % Gaudi::Utils::HistoStats::kurtosis( histo ) %
606 Gaudi::Utils::HistoStats::kurtosisErr( histo )
607 << std::endl
608 << std::endl;
609 //
610 stream << boost::format( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s | %=11s |" ) % "All" %
611 "In Range" % "Underflow" % "Overflow" % "#Equivalent" % "Integral" % "Total"
612 << std::endl
613 << boost::format( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g | %=11.5g |" ) % histo->allEntries() %
614 histo->entries() % histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ) %
615 histo->binEntries( AIDA::IAxis::OVERFLOW_BIN ) % histo->equivalentBinEntries() %
616 histo->sumBinHeights() % histo->sumAllBinHeights()
617 << std::endl
618 << std::endl;
619 //
620 const AIDA::IAnnotation& a = histo->annotation();
621 if ( 0 != a.size() ) {
622 stream << " Annotation" << std::endl;
623 for ( int i = 0; i < a.size(); ++i ) {
624 stream << boost::format( " | %-25.25s : %-45.45s | " ) % a.key( i ) % a.value( i ) << std::endl;
625 }
626 stream << std::endl;
627 }
628 //
629 return dumpText( hist, width, height, errors, stream );
630 }
631 // ============================================================================
632 /* dump the text representation of the histogram
633 * @param histo the histogram
634 * @param stream the stream
635 * @param width the maximal column width
636 * @param height (INPUT) the proposed coulmn height
637 * @param errors (INPUT) print/plot errors
638 * @param erorrs print/plot errors
639 * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
640 * @date 2009-09-19
641 */
642 // ============================================================================
643 std::string Gaudi::Utils::Histos::histoDump( const AIDA::IHistogram1D* histo, const std::size_t width,
644 const std::size_t height, const bool errors ) {
645 std::ostringstream stream;
646 histoDump_( histo, stream, width, height, errors );
647 return stream.str();
648 }
649 // ============================================================================
650 /* dump the text representation of the 1D-profile
651 * @param histo (INPUT) the profile
652 * @param stream (OUTUT) the stream
653 * @param width (INPUT) the maximal column width
654 * @param height (INPUT) the proposed coulmn height
655 * @param spread (INPUT) plot spread/error?
656 * @return the stream
657 * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
658 * @date 2009-09-19
659 */
660 // ============================================================================
661 std::ostream& Gaudi::Utils::Histos::histoDump_( const AIDA::IProfile1D* histo, std::ostream& stream,
662 const std::size_t width, const std::size_t height, const bool spread ) {
663 stream << std::endl;
664 if ( !histo ) { return stream; } // RETURN
665 Histo hist;
666 StatusCode sc = _getHisto( histo, hist, spread );
667 if ( sc.isFailure() ) { return stream; } // RETURN
668 //
669 stream << boost::format( " Histo TES : \"%s\"" ) % path( histo ) << std::endl
670 << boost::format( " Histo Title : \"%s\"" ) % histo->title() << std::endl
671 << std::endl;
672 //
673 stream << boost::format( " Mean : %11.5g " ) % histo->mean() << std::endl
674 << boost::format( " Rms : %11.5g " ) % histo->rms() << std::endl
675 << std::endl;
676 //
677 stream << boost::format( " Entries :\n | %=9s | %=9s | %=9s | %9s | %=11s | %=11s |" ) % "All" % "In Range" %
678 "Underflow" %
679 "Overflow"
680 // % "#Equivalent"
681 % "Integral" % "Total"
682 << std::endl
683 << boost::format( " | %=9d | %=9d | %=9d | %=9d | %=11.5g | %=11.5g |" ) % histo->allEntries() %
684 histo->entries() % histo->binEntries( AIDA::IAxis::UNDERFLOW_BIN ) %
685 histo->binEntries( AIDA::IAxis::OVERFLOW_BIN )
686 // % histo -> equivalentBinEntries ()
687 % histo->sumBinHeights() % histo->sumAllBinHeights()
688 << std::endl
689 << std::endl;
690 //
691 const AIDA::IAnnotation& a = histo->annotation();
692 if ( 0 != a.size() ) {
693 stream << " Annotation" << std::endl;
694 for ( int i = 0; i < a.size(); ++i ) {
695 stream << boost::format( " | %-25.25s : %-45.45s | " ) % a.key( i ) % a.value( i ) << std::endl;
696 }
697 stream << std::endl;
698 }
699 //
700 return dumpText( hist, width, height, true, stream );
701 }
702 // ============================================================================
703 /* dump the text representation of the 1D-profile
704 * @param histo the histogram
705 * @param stream the stream
706 * @param width the maximal column width
707 * @param height (INPUT) the proposed coulmn height
708 * @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
709 * @date 2009-09-19
710 */
711 // ============================================================================
712 std::string Gaudi::Utils::Histos::histoDump( const AIDA::IProfile1D* histo, const std::size_t width,
713 const std::size_t height, const bool spread ) {
714 std::ostringstream stream;
715 histoDump_( histo, stream, width, height, spread );
716 return stream.str();
717 }
718 // ============================================================================
719 /* dump the text representation of the histogram
720 * @param histo (INPUT) the histogram
721 * @param stream (OUTUT) the stream
722 * @param width (INPUT) the maximal column width
723 * @param errors (INPUT) print/plot errors
724 * @return the stream
725 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
726 * @date 2009-09-19
727 */
728 // ============================================================================
729 std::ostream& Gaudi::Utils::Histos::histoDump_( const TH1* histo, std::ostream& stream, const std::size_t width,
730 const std::size_t height, const bool errors ) {
731 const TProfile* profile = dynamic_cast<const TProfile*>( histo );
732 if ( profile ) { return histoDump_( profile, stream, width, height ); }
733 //
734 stream << std::endl;
735 if ( !histo ) { return stream; } // RETURN
736 Histo hist;
737 StatusCode sc = _getHisto( histo, hist );
738 if ( sc.isFailure() ) { return stream; } // RETURN
739 //
740 stream << boost::format( " Histo Name : \"%s\"" ) % histo->GetName() << std::endl
741 << boost::format( " Histo Title : \"%s\"" ) % histo->GetTitle() << std::endl
742 << std::endl;
743 //
744 stream << boost::format( " Mean : %11.5g +- %-10.4g " ) % histo->GetMean() % histo->GetMeanError() << std::endl
745 << boost::format( " Rms : %11.5g +- %-10.4g " ) % histo->GetRMS() % histo->GetRMSError() << std::endl
746 << boost::format( " Skewness : %11.5g " ) % histo->GetSkewness() << std::endl
747 << boost::format( " Kurtosis : %11.5g " ) % histo->GetKurtosis() << std::endl
748 << std::endl;
749 //
750 stream << boost::format( " Entries :\n | %=11s | %=11s | %=11s | %=11s | %=11s |" ) % "All" % "Underflow" %
751 "Overflow" % "#Equivalent" % "Integral"
752 << std::endl
753 << boost::format( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g | %=11.5g |" ) % histo->GetEntries() %
754 histo->GetBinContent( 0 ) % histo->GetBinContent( histo->GetNbinsX() + 1 ) %
755 histo->GetEffectiveEntries() % histo->Integral()
756 << std::endl
757 << std::endl;
758 //
759 return dumpText( hist, width, height, errors, stream );
760 }
761 // ============================================================================
762 /* dump the text representation of the histogram
763 * @param histo (INPUT) the histogram
764 * @param stream (OUTUT) the stream
765 * @param width (INPUT) the maximal column width
766 * @param errors (INPUT) print/plot errors
767 * @return the stream
768 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
769 * @date 2009-09-19
770 */
771 // ============================================================================
772 std::ostream& Gaudi::Utils::Histos::histoDump_( const TProfile* histo, std::ostream& stream, const std::size_t width,
773 const std::size_t height ) {
774 stream << std::endl;
775 if ( !histo ) { return stream; } // RETURN
776 Histo hist;
777 StatusCode sc = _getHisto( histo, hist, true );
778 if ( sc.isFailure() ) { return stream; } // RETURN
779 //
780 stream << boost::format( " Profile Name : \"%s\"" ) % histo->GetName() << std::endl
781 << boost::format( " Profile Title : \"%s\"" ) % histo->GetTitle() << std::endl
782 << std::endl;
783 //
784 stream << boost::format( " Mean : %11.5g " ) % histo->GetMean() << std::endl
785 << boost::format( " Rms : %11.5g " ) % histo->GetRMS() << std::endl
786 << std::endl;
787 //
788 stream << boost::format( " Entries :\n | %=11s | %=11s | %=11s | %=11s |" ) % "All" % "Underflow" % "Overflow" %
789 "Integral"
790 << std::endl
791 << boost::format( " | %=11.5g | %=11.5g | %=11.5g | %=11.5g |" ) % histo->GetEntries() %
792 histo->GetBinContent( 0 ) % histo->GetBinContent( histo->GetNbinsX() + 1 ) % histo->Integral()
793 << std::endl
794 << std::endl;
795 //
796 return dumpText( hist, width, height, true, stream );
797 }
798 // ============================================================================
799 /* dump the text representation of the histogram
800 * @param histo (INPUT) the histogram
801 * @param width (INPUT) the maximal column width
802 * @param errors (INPUT) print/plot errors
803 * @return string representation of the histogram
804 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
805 * @date 2009-09-19
806 */
807 // ============================================================================
808 std::string Gaudi::Utils::Histos::histoDump( const TH1* histo, const std::size_t width, const std::size_t height,
809 const bool errors ) {
810 std::ostringstream stream;
811 histoDump_( histo, stream, width, height, errors );
812 return stream.str();
813 }
814 // ============================================================================
815 /* dump the text representation of the histogram
816 * @param histo (INPUT) the histogram
817 * @param width (INPUT) the maximal column width
818 * @param errors (INPUT) print/plot errors
819 * @return string representation of the histogram
820 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
821 * @date 2009-09-19
822 */
823 // ============================================================================
824 std::string Gaudi::Utils::Histos::histoDump( const TProfile* histo, const std::size_t width,
825 const std::size_t height ) {
826 std::ostringstream stream;
827 histoDump_( histo, stream, width, height );
828 return stream.str();
829 }
830 // ============================================================================
831
832 // ============================================================================
833 // The END
834 // ============================================================================
HistoDump.h
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:14
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:932
std::ceil
T ceil(T... args)
Gaudi::Utils::HistoStats::rmsErr
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:651
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:584
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:643
std::endl
T endl(T... args)
std::right
T right(T... args)
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
HistoTableFormat.h
std::end
T end(T... args)
std::floor
T floor(T... args)
std::size_t
Gaudi::Utils::HistoStats::meanErr
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:635
plotBacklogPyRoot.maxY
int maxY
Definition: plotBacklogPyRoot.py:22
std::string
STL class.
std::min
T min(T... args)
HepRndm::Engine
Definition: HepRndmEngine.h:25
GaudiPluginService.cpluginsvc.n
n
Definition: cpluginsvc.py:210
std::vector::push_back
T push_back(T... args)
Gaudi::Utils::HistoStats::rms
static double rms(const AIDA::IHistogram1D *histo)
get the rms value for the histogram (just for completeness)
Definition: HistoStats.cpp:643
HistoStats.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:92
std::ostringstream
STL class.
std::ostringstream::str
T str(T... args)
std::max
T max(T... args)
gaudirun.l
dictionary l
Definition: gaudirun.py:521
std::pair
std::string::size
T size(T... args)
std::vector
STL class.
std::begin
T begin(T... args)
Gaudi::Utils::HistoStats::kurtosisErr
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:611
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
gaudiComponentHelp.root
root
Definition: gaudiComponentHelp.py:27
Gaudi::Utils::HistoStats::mean
static double mean(const AIDA::IHistogram1D *histo)
get the mean value for the histogram (just for completeness)
Definition: HistoStats.cpp:627
Gaudi::Utils::HistoStats::skewnessErr
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:595
std::sqrt
T sqrt(T... args)
StatusCode.h
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
std::accumulate
T accumulate(T... args)
Gaudi::Utils::HistoStats::kurtosis
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:603
std::ostream
STL class.
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:170
Gaudi::Utils::HistoStats::skewness
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:587