|
Gaudi Framework, version v21r7p1 |
| Home | Generated: 15 Feb 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 @699::_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 238 of file HistoDump.cpp.
00241 { 00242 // clear the histogram 00243 hist.bins.clear() ; 00244 // 00245 if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN 00246 // 00247 const AIDA::IAxis& axis = aida -> axis () ; 00248 const int nbins = axis . bins () ; 00249 // 00250 // underflow bin 00251 hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) , 00252 spread ? 00253 aida -> binRms ( AIDA::IAxis::UNDERFLOW_BIN ) : 00254 aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) , 00255 axis . lowerEdge () ) ; 00256 // overflow bin 00257 hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) , 00258 spread ? 00259 aida -> binRms ( AIDA::IAxis::OVERFLOW_BIN ) : 00260 aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) , 00261 axis . upperEdge () ) ; 00262 // 00263 for ( int ibin = 0 ; ibin < nbins ; ++ibin ) 00264 { 00265 // add to the local histo 00266 Histo::Bin bin ( aida -> binHeight ( ibin ) , 00267 spread ? 00268 aida -> binRms ( ibin ) : 00269 aida -> binError ( ibin ) , 00270 axis . binLowerEdge ( ibin ) ) ; 00271 hist.bins.push_back ( bin ) ; 00272 } 00273 return StatusCode::SUCCESS ; 00274 }
| StatusCode @699::_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 200 of file HistoDump.cpp.
00201 { 00202 // clear the histogram 00203 hist.bins.clear() ; 00204 // 00205 if ( 0 == aida ) { return StatusCode::FAILURE ; } // RETURN 00206 // 00207 const AIDA::IAxis& axis = aida -> axis () ; 00208 const int nbins = axis . bins () ; 00209 // 00210 // underflow bin 00211 hist.under = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::UNDERFLOW_BIN ) , 00212 aida -> binError ( AIDA::IAxis::UNDERFLOW_BIN ) , 00213 axis . lowerEdge () ) ; 00214 // overflow bin 00215 hist.over = Histo::Bin ( aida -> binHeight ( AIDA::IAxis::OVERFLOW_BIN ) , 00216 aida -> binError ( AIDA::IAxis::OVERFLOW_BIN ) , 00217 axis . upperEdge () ) ; 00218 // 00219 for ( int ibin = 0 ; ibin < nbins ; ++ibin ) 00220 { 00221 // add to the local histo 00222 Histo::Bin bin ( aida -> binHeight ( ibin ) , 00223 aida -> binError ( ibin ) , 00224 axis . binLowerEdge ( ibin ) ) ; 00225 hist.bins.push_back ( bin ) ; 00226 } 00227 return StatusCode::SUCCESS ; 00228 }
| StatusCode @699::_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 184 of file HistoDump.cpp.
| StatusCode @699::_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 145 of file HistoDump.cpp.
00146 { 00147 // clear the histogram 00148 hist.bins.clear() ; 00149 // 00150 if ( 0 == root ) { return StatusCode::FAILURE ; } // RETURN 00151 const TAxis* axis = root->GetXaxis() ; 00152 if ( 0 == axis ) { return StatusCode::FAILURE ; } // RETURN 00153 const int nbins = axis->GetNbins () ; 00154 if ( 0 == nbins ) { return StatusCode::FAILURE ; } // RETURN 00155 00156 // underflow bin 00157 hist.under = Histo::Bin ( root -> GetBinContent ( 0 ) , 00158 root -> GetBinError ( 0 ) , 00159 axis -> GetXmin () ) ; 00160 // overflow bin 00161 hist.over = Histo::Bin ( root -> GetBinContent ( nbins + 1 ) , 00162 root -> GetBinError ( nbins + 1 ) , 00163 axis -> GetXmax () ) ; 00164 // 00165 // 00166 for ( int ibin = 1 ; ibin <= nbins ; ++ibin ) 00167 { 00168 // add to the local histo 00169 Histo::Bin bin ( root -> GetBinContent ( ibin ) , 00170 root -> GetBinError ( ibin ) , 00171 axis -> GetBinLowEdge ( ibin ) ) ; 00172 hist.bins.push_back ( bin ) ; 00173 } 00174 return StatusCode::SUCCESS ; 00175 }
| double @699::_pow | ( | double | __x, | |
| unsigned long | __n | |||
| ) | [inline, static] |
"efficient" pow-function
Definition at line 324 of file HistoDump.cpp.
00325 { 00326 double __y = __n % 2 ? __x : 1; 00327 while ( __n >>= 1 ) 00328 { 00329 __x = __x * __x; 00330 if ( __n % 2) { __y = __y * __x; } 00331 } 00332 return __y ; 00333 }
| std::pair<double,int> @699::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 296 of file HistoDump.cpp.
00297 { 00298 if ( 0 == v ) { return std::make_pair ( 0.0 , 0 ) ; } // RETURN 00299 else if ( 1 == v ) { return std::make_pair ( 1.0 , 0 ) ; } // RETURN 00300 else if ( 0 > v ) 00301 { 00302 std::pair<double,int> r = decompose ( -v ) ; 00303 return std::pair<double,int>( -r.first , r.second ) ; // RETURN 00304 } 00305 else if ( 0.1 > v ) 00306 { 00307 int i = 0 ; 00308 while ( 0.1 > v ) { ++i ; v *= 10 ; } // STUPID 00309 return std::make_pair ( v , -i ) ; 00310 } 00311 else if ( 1 < v ) 00312 { 00313 int i = 0 ; 00314 while ( 1 <= v ) { ++i ; v /= 10 ; } // STUPID 00315 return std::make_pair ( v , i ) ; 00316 } 00317 return std::make_pair ( v , 1 ) ; 00318 }
| std::ostream& @699::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 423 of file HistoDump.cpp.
00428 { 00429 if ( 40 > width ) { return dumpText ( histo , 40 , height , errors , stream ) ; } 00430 if ( 200 < width ) { return dumpText ( histo , 200 , height , errors , stream ) ; } 00431 if ( 150 < height ) { return dumpText ( histo , width , 150 , errors , stream ) ; } 00432 if ( 20 > height ) { return dumpText ( histo , width , 20 , errors , stream ) ; } 00433 if ( height > width ) { return dumpText ( histo , width , width , errors , stream ) ; } 00434 // 00435 const unsigned int nBins = histo.bins.size() ; 00436 if ( nBins > width ) 00437 { 00438 // rebin histogram 00439 Histo r = histo.rebin ( rebin ( nBins , width ) ) ; 00440 return dumpText ( r , width , height , errors , stream ) ; 00441 } 00442 // 00443 // get the Y-scale 00444 double yMax = std::max ( rValMax ( histo.maxY ( errors ) ) , 0.0 ) ; 00445 double yMin = std::min ( rValMin ( histo.minY ( errors ) ) , 0.0 ) ; 00446 00447 if ( yMin == yMax ) { yMax = yMin + 1 ; } 00449 std::pair<double,int> r = decompose ( yMax - yMin ) ; 00450 double _ny = std::ceil ( 10 * r.first ) ; // 1 <= ny < 10 00451 if ( 1 >= _ny ) { _ny = 10 ; } 00452 int yBins = (int) std::max ( 1. , std::ceil ( height / _ny ) ) ; 00453 00454 yBins *= (int) _ny ; 00455 if ( 20 > yBins ) { yBins = 20 ; } 00456 const double yScale = ( yMax - yMin ) / yBins ; 00457 00458 // 00459 const int ySkip = 00460 0 == yBins % 13 ? 13 : 00461 0 == yBins % 11 ? 11 : 00462 0 == yBins % 9 ? 9 : 00463 0 == yBins % 8 ? 8 : 00464 0 == yBins % 7 ? 7 : 00465 0 == yBins % 6 ? 6 : 00466 0 == yBins % 5 ? 5 : 00467 0 == yBins % 4 ? 4 : 10 ; 00468 00469 const int xSkip = 00470 // 0 == nBins % 8 ? 8 : 00471 0 == nBins % 7 ? 7 : 00472 0 == nBins % 6 ? 6 : 00473 0 == nBins % 5 ? 5 : 00474 0 == nBins % 4 ? 4 : 10 ; 00475 00476 int iNull = histo.nullBin() ; 00477 00478 if ( 0 <= iNull ) { iNull %= xSkip ; } 00479 else { iNull = 0 ; } 00480 00481 stream << std::endl ; 00482 00483 for ( int yLine = -1 ; yLine < yBins ; ++yLine ) 00484 { 00485 const double yHigh = yMax - yScale * yLine ; 00486 // const double yLow = yHigh - yScale ; 00487 const double yLow = yMax - yScale * ( yLine + 1 ) ; 00488 // 00489 std::string line1 = " " ; 00490 00491 const bool ynull = ( yLow <= 0 && 0 < yHigh ) ; 00492 const bool yfirst = -1 == yLine || yBins -1 == yLine ; 00493 const bool ylab = 00494 ( 0 == ( yLine + 1 ) % ySkip ) || yfirst || ynull ; 00495 00496 if ( ylab ) { line1 += yLabel ( ( yLow <= 0 && 0 < yHigh ) ? 0.0 : yLow ) ; } 00497 else { line1 += std::string( 10 , ' ' ) ; } 00498 // 00499 line1 += " " ; 00500 // 00502 line1 += symbBin ( histo.under , yLow , yHigh , ynull , errors ) ; 00503 // 00504 line1 += 00505 ynull ? "-+" : 00506 ylab ? " +" : " |" ; 00507 // 00508 std::string line2 ; 00509 // 00510 for ( Histo::Bins::const_iterator ibin = histo.bins.begin() ; 00511 histo.bins.end() != ibin ; ++ibin ) 00512 { 00513 //char symb = ' ' ; 00514 const int i = ibin - histo.bins.begin () ; 00515 // 00516 const bool xnull = 00517 ibin->lower <= 0 && ( ibin + 1 ) != histo.bins.end() && 0 < (ibin+1)->lower ; 00518 const bool xlab = iNull == i % xSkip ; 00519 // 00520 char symb = symbBin ( *ibin, yLow , yHigh , ynull , errors ) ; 00521 // 00522 if ( ' ' == symb ) 00523 { 00524 if ( ( ynull || yfirst ) && xlab ) { symb = '+' ; } 00525 else if ( ynull || yfirst ) { symb = '-' ; } 00526 // 00527 else if ( ylab && xnull ) { symb = '+' ; } 00528 else if ( xnull ) { symb = '|' ; } 00529 // 00530 else if ( ylab || xlab ) { symb = '.' ; } 00531 // 00532 } 00533 line2 += symb ; 00534 // 00535 } 00536 // 00537 std::string line3 = 00538 ynull ? "->" : 00539 ylab ? "+ " : "| " ; 00540 // 00542 line3 += symbBin ( histo.over , yLow , yHigh , ynull , errors ) ; 00543 // 00544 stream << line1 << line2 << line3 << std::endl ; 00545 // 00546 } 00547 00548 // get x-labels 00549 std::vector<std::string> xlabels ; 00550 for ( Histo::Bins::const_iterator ib = histo.bins.begin() ; histo.bins.end() != ib ; ++ib ) 00551 { xlabels.push_back ( xLabel ( ib->lower ) ) ; } 00552 // overflow& underflow label 00553 const std::string oLabel = xLabel ( histo.over.lower ) ; 00554 const std::string uLabel = xLabel ( histo.under.lower ) ; 00555 // 00556 static const std::string s_UNDERFLOW ( "UNDERFLOW" ) ; 00557 static const std::string s_OVERFLOW ( " OVERFLOW" ) ; 00558 // 00559 // 00560 for ( unsigned int yLine = 0 ; yLine < 12 ; ++yLine ) 00561 { 00562 std::string line = std::string ( 12 , ' ' ) ; 00563 // 00564 if ( yLine < s_UNDERFLOW.size() ) { line += s_UNDERFLOW[yLine] ; } 00565 else { line += ' ' ; } 00566 // 00567 line += ' ' ; 00568 // 00569 if ( uLabel.size() > yLine ) { line += uLabel[yLine] ; } 00570 else { line += ' ' ; } 00571 // 00572 for ( Histo::Bins::const_iterator ibin = histo.bins.begin() ; histo.bins.end() != ibin ; ++ibin ) 00573 { 00574 int ib = ibin - histo.bins.begin() ; 00575 const bool xlab = ( iNull == ib % xSkip ) ; 00576 if ( xlab && yLine < xlabels[ib].size() ) { line += xlabels[ib][yLine] ; } 00577 else { line += ' ' ; } 00578 } 00579 // 00580 if ( oLabel.size() > yLine ) { line += oLabel[yLine] ; } 00581 else { line += ' ' ; } 00582 // 00583 line += ' ' ; 00584 // 00585 if ( yLine < s_OVERFLOW.size() ) { line += s_OVERFLOW[yLine] ; } 00586 else { line += ' ' ; } 00587 // 00588 stream << line << std::endl ; 00589 } 00590 // 00591 return stream ; // RETURN 00592 }
| unsigned int @699::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 282 of file HistoDump.cpp.
00284 { 00285 if ( 0 == imax ) { return 1 ; } // RETURN 00286 unsigned int ibin = 1 ; 00287 while ( bins > imax * ibin ) { ++ibin ; } 00288 return ibin ; // RETURN 00289 }
| double @699::rValMax | ( | const double | v | ) | [inline, static] |
find the proper "round" value
Definition at line 351 of file HistoDump.cpp.
00352 { 00353 if ( 0 == v ) { return 0 ; } // REUTRN 00354 else if ( 0 > v ) { return -1 * rValMin ( -v ) ; } // RETURN 00355 // decompose the double value into decimal significand and mantissa 00356 std::pair<double,int> r = decompose ( v ) ; 00357 // 00358 const double f = std::ceil ( 20 * r.first ) / 2 ; // + 1 ; 00359 const int l = r.second - 1 ; 00360 return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ; 00361 }
| double @699::rValMax | ( | const double | v | ) | [inline, static] |
find the proper "round" value
| double @699::rValMin | ( | const double | v | ) | [inline, static] |
find the proper "round" value
Definition at line 367 of file HistoDump.cpp.
00368 { 00369 if ( 0 == v ) { return 0 ; } // REUTRN 00370 else if ( 0 > v ) { return -1 * rValMax ( -v ) ; } // RETURN 00371 // decompose the double value into decimal significand and mantissa 00372 std::pair<double,int> r = decompose ( v ) ; 00373 const double f = std::floor ( 20 * r.first ) / 2 ; // - 1 ; 00374 const int l = r.second - 1 ; 00375 return 0 < l ? f * _pow ( 10 , l ) : f / _pow ( 10 , -l ) ; 00376 }
| double @699::rValMin | ( | const double | v | ) | [inline, static] |
find the proper "round" value
| char @699::symbBin | ( | const Histo::Bin & | bin, | |
| const double | yLow, | |||
| const double | yHigh, | |||
| const bool | yNull, | |||
| const bool | errors | |||
| ) | [static] |
get "correct" symbol
Definition at line 401 of file HistoDump.cpp.
00406 { 00407 if ( errors && yLow <= bin.height && bin.height < yHigh ) { return '*' ; } // O 00408 else if ( errors && yHigh < bin.height - bin.error ) { return ' ' ; } 00409 else if ( errors && yLow >= bin.height + bin.error ) { return ' ' ; } 00410 else if ( errors ) { return 'I' ; } 00411 else if ( yLow <= bin.height && bin.height < yHigh ) { return '*' ; } 00412 else if ( 0 <= bin.height && yLow <= bin.height && 0 < yHigh && !yNull ) { return '*' ; } // + 00413 else if ( 0 > bin.height && yHigh > bin.height && 0 >= yLow && !yNull ) { return '*' ; } // - 00414 // 00415 return ' ' ; 00416 }
| std::string @699::xLabel | ( | const double | value | ) | [inline, static] |
make the label for x-axis
Definition at line 393 of file HistoDump.cpp.
00394 { 00395 boost::format fmt ( "%9.3g" ) ; 00396 fmt % value ; 00397 return fmt.str () ; 00398 }
| std::string @699::yLabel | ( | const double | value | ) | [inline, static] |
make the label for y-axis
Definition at line 382 of file HistoDump.cpp.
00383 { 00384 boost::format fmt ( "%10.3g" ) ; 00385 fmt % value ; 00386 return fmt.str () ; 00387 }
| Bins bins |
| double error |
| double height |
| double lower |
| Bin over |
| Bin under |