|
Gaudi Framework, version v21r9 |
| Home | Generated: 3 May 2010 |
#include <cmath>#include <vector>#include <iostream>#include <utility>#include <sstream>#include "AIDA/IHistogram1D.h"#include "AIDA/IProfile1D.h"#include "AIDA/IAxis.h"#include "AIDA/IAnnotation.h"#include "GaudiKernel/StatusCode.h"#include "TH1.h"#include "TProfile.h"#include "TAxis.h"#include "boost/format.hpp"#include "GaudiUtils/HistoDump.h"#include "GaudiUtils/HistoTableFormat.h"#include "GaudiUtils/HistoStats.h"

Go to the source code of this file.
Functions | |
| StatusCode | _getHisto (const TH1 *root, Histo &hist) |
| "convert ROOT histogram into "local" histogram | |
| StatusCode | _getHisto (const TProfile *root, Histo &hist, const bool) |
| "convert ROOT 1D-profile into "local" histogram | |
| StatusCode | _getHisto (const AIDA::IHistogram1D *aida, Histo &hist) |
| "convert AIDA histogram into "local" histogram | |
| StatusCode | _getHisto (const AIDA::IProfile1D *aida, Histo &hist, const bool spread) |
| "convert AIDA 1D-profile into "local" histogram | |
| unsigned int | rebin (const unsigned int bins, const unsigned int imax) |
| find the approrpriate rebin factor (I suspect that there is some intelligent STD/STL routine for this purpose) | |
| std::pair< double, int > | decompose (double v) |
| decompose the double value into decimal significand (I suspect that there is some intelligent STD/STL routine for this purpose) | |
| double | _pow (double __x, unsigned long __n) |
| "efficient" pow-function | |
| double | rValMax (const double v) |
| find the proper "round" value | |
| double | rValMin (const double v) |
| find the proper "round" value | |
| double | rValMax (const double v) |
| find the proper "round" value | |
| double | rValMin (const double v) |
| find the proper "round" value | |
| std::string | yLabel (const double value) |
| make the label for y-axis | |
| std::string | xLabel (const double value) |
| make the label for x-axis | |
| char | symbBin (const Histo::Bin &bin, const double yLow, const double yHigh, const bool yNull, const bool errors) |
| get "correct" symbol | |
| std::ostream & | dumpText (const Histo &histo, const std::size_t width, const std::size_t height, const bool errors, std::ostream &stream) |
| dump the local histogram in text form | |
| GAUDI_API std::ostream & | Gaudi::Utils::Histos::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 | |
| GAUDI_API std::string | Gaudi::Utils::Histos::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 | |
| GAUDI_API std::ostream & | Gaudi::Utils::Histos::histoDump_ (const AIDA::IProfile1D *histo, std::ostream &stream, const std::size_t width=80, const std::size_t height=50, const bool spread=true) |
| dump the text representation of 1D-profile | |
| GAUDI_API std::string | Gaudi::Utils::Histos::histoDump (const AIDA::IProfile1D *histo, const std::size_t width=80, const std::size_t height=50, const bool spread=true) |
| dump the text representation of the 1D-profile | |
| GAUDI_API std::ostream & | Gaudi::Utils::Histos::histoDump_ (const TH1 *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 | |
| GAUDI_API std::ostream & | Gaudi::Utils::Histos::histoDump_ (const TProfile *histo, std::ostream &stream, const std::size_t width=80, const std::size_t height=50) |
| dump the text representation of the Profile | |
| GAUDI_API std::string | Gaudi::Utils::Histos::histoDump (const TH1 *histo, const std::size_t width=80, const std::size_t height=50, const bool errors=false) |
| dump the text representation of the histogram | |
| GAUDI_API std::string | Gaudi::Utils::Histos::histoDump (const TProfile *histo, const std::size_t width=80, const std::size_t height=50) |
| dump the text representation of the histogram | |
| StatusCode @707::_getHisto | ( | const AIDA::IProfile1D * | aida, | |
| Histo & | hist, | |||
| const bool | spread | |||
| ) | [static] |
"convert AIDA 1D-profile into "local" histogram
| aida | (INPUT) pointer to AIDA 1D-profile | |
| hist | (OUTPUT) local histogram |
Definition at line 246 of file HistoDump.cpp.
00249 { 00250 // clear the histogram 00251 hist.bins.clear() ; 00252 // 00253 if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN 00254 // 00255 const AIDA::IAxis& axis = aida -> axis () ; 00256 const int nbins = axis . bins () ; 00257 // 00258 // underflow bin 00259 hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) , 00260 spread ? 00261 aida -> binRms ( AIDA::IAxis::UNDERFLOW_BIN ) : 00262 aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) , 00263 axis . lowerEdge () ) ; 00264 // overflow bin 00265 hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) , 00266 spread ? 00267 aida -> binRms ( AIDA::IAxis::OVERFLOW_BIN ) : 00268 aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) , 00269 axis . upperEdge () ) ; 00270 // 00271 for ( int ibin = 0 ; ibin < nbins ; ++ibin ) 00272 { 00273 // add to the local histo 00274 Histo::Bin bin ( aida -> binHeight ( ibin ) , 00275 spread ? 00276 aida -> binRms ( ibin ) : 00277 aida -> binError ( ibin ) , 00278 axis . binLowerEdge ( ibin ) ) ; 00279 hist.bins.push_back ( bin ) ; 00280 } 00281 return StatusCode::SUCCESS ; 00282 }
| StatusCode @707::_getHisto | ( | const AIDA::IHistogram1D * | aida, | |
| Histo & | hist | |||
| ) | [static] |
"convert AIDA histogram into "local" histogram
| aida | (INPUT) pointer to AIDA histogram | |
| hist | (OUTPUT) local histogram |
Definition at line 208 of file HistoDump.cpp.
00209 { 00210 // clear the histogram 00211 hist.bins.clear() ; 00212 // 00213 if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN 00214 // 00215 const AIDA::IAxis& axis = aida -> axis () ; 00216 const int nbins = axis . bins () ; 00217 // 00218 // underflow bin 00219 hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) , 00220 aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) , 00221 axis . lowerEdge () ) ; 00222 // overflow bin 00223 hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) , 00224 aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) , 00225 axis . upperEdge () ) ; 00226 // 00227 for ( int ibin = 0 ; ibin < nbins ; ++ibin ) 00228 { 00229 // add to the local histo 00230 Histo::Bin bin ( aida -> binHeight ( ibin ) , 00231 aida -> binError ( ibin ) , 00232 axis . binLowerEdge ( ibin ) ) ; 00233 hist.bins.push_back ( bin ) ; 00234 } 00235 return StatusCode::SUCCESS ; 00236 }
| StatusCode @707::_getHisto | ( | const TProfile * | root, | |
| Histo & | hist, | |||
| const | bool | |||
| ) | [static] |
"convert ROOT 1D-profile into "local" histogram
| root | (INPUT) pointer to ROOT 1D-profile | |
| hist | (OUTPUT) local histogram |
Definition at line 192 of file HistoDump.cpp.
| StatusCode @707::_getHisto | ( | const TH1 * | root, | |
| Histo & | hist | |||
| ) | [static] |
"convert ROOT histogram into "local" histogram
| root | (INPUT) pointer to ROOT histogram | |
| hist | (OUTPUT) local histogram |
Definition at line 153 of file HistoDump.cpp.
00154 { 00155 // clear the histogram 00156 hist.bins.clear() ; 00157 // 00158 if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN 00159 const TAxis* axis = root->GetXaxis() ; 00160 if ( 0 == axis ) { return StatusCode::FAILURE ; } // RETURN 00161 const int nbins = axis->GetNbins () ; 00162 if ( 0 == nbins ) { return StatusCode::FAILURE ; } // RETURN 00163 00164 // underflow bin 00165 hist.under = Histo::Bin ( root -> GetBinContent ( 0 ) , 00166 root -> GetBinError ( 0 ) , 00167 axis -> GetXmin () ) ; 00168 // overflow bin 00169 hist.over = Histo::Bin ( root -> GetBinContent ( nbins + 1 ) , 00170 root -> GetBinError ( nbins + 1 ) , 00171 axis -> GetXmax () ) ; 00172 // 00173 // 00174 for ( int ibin = 1 ; ibin <= nbins ; ++ibin ) 00175 { 00176 // add to the local histo 00177 Histo::Bin bin ( root -> GetBinContent ( ibin ) , 00178 root -> GetBinError ( ibin ) , 00179 axis -> GetBinLowEdge ( ibin ) ) ; 00180 hist.bins.push_back ( bin ) ; 00181 } 00182 return StatusCode::SUCCESS ; 00183 }
| double @707::_pow | ( | double | __x, | |
| unsigned long | __n | |||
| ) | [inline, static] |
"efficient" pow-function
Definition at line 332 of file HistoDump.cpp.
00333 { 00334 double __y = __n % 2 ? __x : 1; 00335 while ( __n >>= 1 ) 00336 { 00337 __x = __x * __x; 00338 if ( __n % 2) { __y = __y * __x; } 00339 } 00340 return __y ; 00341 }
| std::pair<double,int> @707::decompose | ( | double | v | ) | [static] |
decompose the double value into decimal significand (I suspect that there is some intelligent STD/STL routine for this purpose)
Definition at line 304 of file HistoDump.cpp.
00305 { 00306 if ( 0 == v ) { return std::make_pair ( 0.0 , 0 ) ; } // RETURN 00307 else if ( 1 == v ) { return std::make_pair ( 1.0 , 0 ) ; } // RETURN 00308 else if ( 0 > v ) 00309 { 00310 std::pair<double,int> r = decompose ( -v ) ; 00311 return std::pair<double,int>( -r.first , r.second ) ; // RETURN 00312 } 00313 else if ( 0.1 > v ) 00314 { 00315 int i = 0 ; 00316 while ( 0.1 > v ) { ++i ; v *= 10 ; } // STUPID 00317 return std::make_pair ( v , -i ) ; 00318 } 00319 else if ( 1 < v ) 00320 { 00321 int i = 0 ; 00322 while ( 1 <= v ) { ++i ; v /= 10 ; } // STUPID 00323 return std::make_pair ( v , i ) ; 00324 } 00325 return std::make_pair ( v , 1 ) ; 00326 }
| std::ostream& @707::dumpText | ( | const Histo & | histo, | |
| const std::size_t | width, | |||
| const std::size_t | height, | |||
| const bool | errors, | |||
| std::ostream & | stream | |||
| ) | [static] |
dump the local histogram in text form
try to define the proper "Y-binning"
underflow bin:
overflow bin:
Definition at line 431 of file HistoDump.cpp.
00436 { 00437 if ( 40 > width ) { return dumpText ( histo , 40 , height , errors , stream ) ; } 00438 if ( 200 < width ) { return dumpText ( histo , 200 , height , errors , stream ) ; } 00439 if ( 150 < height ) { return dumpText ( histo , width , 150 , errors , stream ) ; } 00440 if ( 20 > height ) { return dumpText ( histo , width , 20 , errors , stream ) ; } 00441 if ( height > width ) { return dumpText ( histo , width , width , errors , stream ) ; } 00442 // 00443 const unsigned int nBins = histo.bins.size() ; 00444 if ( nBins > width ) 00445 { 00446 // rebin histogram 00447 Histo r = histo.rebin ( rebin ( nBins , width ) ) ; 00448 return dumpText ( r , width , height , errors , stream ) ; 00449 } 00450 // 00451 // get the Y-scale 00452 double yMax = std::max ( rValMax ( histo.maxY ( errors ) ) , 0.0 ) ; 00453 double yMin = std::min ( rValMin ( histo.minY ( errors ) ) , 0.0 ) ; 00454 00455 if ( yMin == yMax ) { yMax = yMin + 1 ; } 00457 std::pair<double,int> r = decompose ( yMax - yMin ) ; 00458 double _ny = std::ceil ( 10 * r.first ) ; // 1 <= ny < 10 00459 if ( 1 >= _ny ) { _ny = 10 ; } 00460 int yBins = (int) std::max ( 1. , std::ceil ( height / _ny ) ) ; 00461 00462 yBins *= (int) _ny ; 00463 if ( 20 > yBins ) { yBins = 20 ; } 00464 const double yScale = ( yMax - yMin ) / yBins ; 00465 00466 // 00467 const int ySkip = 00468 0 == yBins % 13 ? 13 : 00469 0 == yBins % 11 ? 11 : 00470 0 == yBins % 9 ? 9 : 00471 0 == yBins % 8 ? 8 : 00472 0 == yBins % 7 ? 7 : 00473 0 == yBins % 6 ? 6 : 00474 0 == yBins % 5 ? 5 : 00475 0 == yBins % 4 ? 4 : 10 ; 00476 00477 const int xSkip = 00478 // 0 == nBins % 8 ? 8 : 00479 0 == nBins % 7 ? 7 : 00480 0 == nBins % 6 ? 6 : 00481 0 == nBins % 5 ? 5 : 00482 0 == nBins % 4 ? 4 : 10 ; 00483 00484 int iNull = histo.nullBin() ; 00485 00486 if ( 0 <= iNull ) { iNull %= xSkip ; } 00487 else { iNull = 0 ; } 00488 00489 stream << std::endl ; 00490 00491 for ( int yLine = -1 ; yLine < yBins ; ++yLine ) 00492 { 00493 const double yHigh = yMax - yScale * yLine ; 00494 // const double yLow = yHigh - yScale ; 00495 const double yLow = yMax - yScale * ( yLine + 1 ) ; 00496 // 00497 std::string line1 = " " ; 00498 00499 const bool ynull = ( yLow <= 0 && 0 < yHigh ) ; 00500 const bool yfirst = -1 == yLine || yBins -1 == yLine ; 00501 const bool ylab = 00502 ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull ; 00503 00504 if ( ylab ) { line1 += yLabel ( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow ) ; } 00505 else { line1 += std::string( 10 , ' ' ) ; } 00506 // 00507 line1 += " " ; 00508 // 00510 line1 += symbBin ( histo.under , yLow , yHigh , ynull , errors ) ; 00511 // 00512 line1 += 00513 ynull ? "-+" : 00514 ylab ? " +" : " |" ; 00515 // 00516 std::string line2 ; 00517 // 00518 for ( Histo::Bins::const_iterator ibin = histo.bins.begin() ; 00519 histo.bins.end() != ibin ; ++ibin ) 00520 { 00521 //char symb = ' ' ; 00522 const int i = ibin - histo.bins.begin () ; 00523 // 00524 const bool xnull = 00525 ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.end() && 0 < (ibin+1)->lower ; 00526 const bool xlab = iNull == i % xSkip ; 00527 // 00528 char symb = symbBin ( *ibin, yLow , yHigh , ynull , errors ) ; 00529 // 00530 if ( ' ' == symb ) 00531 { 00532 if ( ( ynull || yfirst ) && xlab ) { symb = '+' ; } 00533 else if ( ynull || yfirst ) { symb = '-' ; } 00534 // 00535 else if ( ylab && xnull ) { symb = '+' ; } 00536 else if ( xnull ) { symb = '|' ; } 00537 // 00538 else if ( ylab || xlab ) { symb = '.' ; } 00539 // 00540 } 00541 line2 += symb ; 00542 // 00543 } 00544 // 00545 std::string line3 = 00546 ynull ? "->" : 00547 ylab ? "+ " : "| " ; 00548 // 00550 line3 += symbBin ( histo.over , yLow , yHigh , ynull , errors ) ; 00551 // 00552 stream << line1 << line2 << line3 << std::endl ; 00553 // 00554 } 00555 00556 // get x-labels 00557 std::vector<std::string> xlabels ; 00558 for ( Histo::Bins::const_iterator ib = histo.bins.begin() ; histo.bins.end() != ib ; ++ib ) 00559 { xlabels.push_back ( xLabel ( ib->lower ) ) ; } 00560 // overflow& underflow label 00561 const std::string oLabel = xLabel ( histo.over.lower ) ; 00562 const std::string uLabel = xLabel ( histo.under.lower ) ; 00563 // 00564 static const std::string s_UNDERFLOW ( "UNDERFLOW" ) ; 00565 static const std::string s_OVERFLOW ( " OVERFLOW" ) ; 00566 // 00567 // 00568 for ( unsigned int yLine = 0 ; yLine < 12 ; ++yLine ) 00569 { 00570 std::string line = std::string ( 12 , ' ' ) ; 00571 // 00572 if ( yLine < s_UNDERFLOW.size() ) { line += s_UNDERFLOW[yLine] ; } 00573 else { line += ' ' ; } 00574 // 00575 line += ' ' ; 00576 // 00577 if ( uLabel.size() > yLine ) { line += uLabel[yLine] ; } 00578 else { line += ' ' ; } 00579 // 00580 for ( Histo::Bins::const_iterator ibin = histo.bins.begin() ; histo.bins.end() != ibin ; ++ibin ) 00581 { 00582 int ib = ibin - histo.bins.begin() ; 00583 const bool xlab = ( iNull == ib % xSkip ) ; 00584 if ( xlab && yLine < xlabels[ib].size() ) { line += xlabels[ib][yLine] ; } 00585 else { line += ' ' ; } 00586 } 00587 // 00588 if ( oLabel.size() > yLine ) { line += oLabel[yLine] ; } 00589 else { line += ' ' ; } 00590 // 00591 line += ' ' ; 00592 // 00593 if ( yLine < s_OVERFLOW.size() ) { line += s_OVERFLOW[yLine] ; } 00594 else { line += ' ' ; } 00595 // 00596 stream << line << std::endl ; 00597 } 00598 // 00599 return stream ; // RETURN 00600 }
| unsigned int @707::rebin | ( | const unsigned int | bins, | |
| const unsigned int | imax | |||
| ) | [inline, static] |
find the approrpriate rebin factor (I suspect that there is some intelligent STD/STL routine for this purpose)
Definition at line 290 of file HistoDump.cpp.
00292 { 00293 if ( 0 == imax ) { return 1 ; } // RETURN 00294 unsigned int ibin = 1 ; 00295 while ( bins > imax * ibin ) { ++ibin ; } 00296 return ibin ; // RETURN 00297 }
| double @707::rValMax | ( | const double | v | ) | [inline, static] |
find the proper "round" value
Definition at line 359 of file HistoDump.cpp.
00360 { 00361 if ( 0 == v ) { return 0 ; } // RETURN 00362 else if ( 0 > v ) { return -1 * rValMin ( -v ) ; } // RETURN 00363 // decompose the double value into decimal significand and mantissa 00364 std::pair<double,int> r = decompose ( v ) ; 00365 // 00366 const double f = std::ceil ( 20 * r.first ) / 2 ; // + 1 ; 00367 const int l = r.second - 1 ; 00368 return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ; 00369 }
| double @707::rValMax | ( | const double | v | ) | [inline, static] |
find the proper "round" value
| double @707::rValMin | ( | const double | v | ) | [inline, static] |
find the proper "round" value
Definition at line 375 of file HistoDump.cpp.
00376 { 00377 if ( 0 == v ) { return 0 ; } // RETURN 00378 else if ( 0 > v ) { return -1 * rValMax ( -v ) ; } // RETURN 00379 // decompose the double value into decimal significand and mantissa 00380 std::pair<double,int> r = decompose ( v ) ; 00381 const double f = std::floor ( 20 * r.first ) / 2 ; // - 1 ; 00382 const int l = r.second - 1 ; 00383 return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ; 00384 }
| double @707::rValMin | ( | const double | v | ) | [inline, static] |
find the proper "round" value
| char @707::symbBin | ( | const Histo::Bin & | bin, | |
| const double | yLow, | |||
| const double | yHigh, | |||
| const bool | yNull, | |||
| const bool | errors | |||
| ) | [static] |
get "correct" symbol
Definition at line 409 of file HistoDump.cpp.
00414 { 00415 if ( errors && yLow <= bin.height && bin.height < yHigh ) { return '*' ; } // O 00416 else if ( errors && yHigh < bin.height - bin.error ) { return ' ' ; } 00417 else if ( errors && yLow >= bin.height + bin.error ) { return ' ' ; } 00418 else if ( errors ) { return 'I' ; } 00419 else if ( yLow <= bin.height && bin.height < yHigh ) { return '*' ; } 00420 else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) { return '*' ; } // + 00421 else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) { return '*' ; } // - 00422 // 00423 return ' ' ; 00424 }
| std::string @707::xLabel | ( | const double | value | ) | [inline, static] |
make the label for x-axis
Definition at line 401 of file HistoDump.cpp.
00402 { 00403 boost::format fmt ( "%9.3g" ) ; 00404 fmt % value ; 00405 return fmt.str () ; 00406 }
| std::string @707::yLabel | ( | const double | value | ) | [inline, static] |
make the label for y-axis
Definition at line 390 of file HistoDump.cpp.
00391 { 00392 boost::format fmt ( "%10.3g" ) ; 00393 fmt % value ; 00394 return fmt.str () ; 00395 }
| Bins bins |
| double error |
| double height |
| double lower |
| Bin over |
| Bin under |