Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <string>
00008 #include <cmath>
00009
00010
00011
00013 #include <vector>
00014 #include "GaudiKernel/Kernel.h"
00015 #define class class GAUDI_API
00016 #include "AIDA/IHistogram1D.h"
00017 #include "AIDA/IAxis.h"
00018 #undef class
00019
00020
00021
00022 #include "GaudiKernel/DataObject.h"
00023 #include "GaudiKernel/IRegistry.h"
00024
00025
00026
00027 #include "GaudiUtils/HistoStats.h"
00028 #include "GaudiUtils/HistoTableFormat.h"
00029
00030
00031
00032 #include "boost/format.hpp"
00033
00039
00040 namespace
00041 {
00042
00043
00044
00046 const std::string s_histoFormatStat =
00047 "| %2$-45.45s | %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
00048
00050 const std::string s_histoFormatStatOnly =
00051 "| %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
00052
00054 const std::string s_histoFormatStat1 =
00055 "| %3$=7d |%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|" ;
00056
00060 const std::string s_histoFormatShapeOnly =
00061 "|%8$11.5g |%10$11.5g |%12$11.5g |%14$11.5g |%19$11.5g/%21$-11.5g|" ;
00062
00067 const std::string s_histoFormatShape =
00068 "|%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|%19$9.3g+-%20$-9.3g|%21$9.3g+-%22$-9.3g|" ;
00069
00071 const std::string s_histoFormatLineTitle =
00072 " %2$-45.45s mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
00073
00075 const std::string s_histoFormatLineOnly =
00076 " mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
00077
00079 const std::string s_histoFormatOld =
00080 " %2$-45.45s Ents/All=%7$5s/%3$5s<X>/sX=%8$.5g/%10$-.5g" ;
00081
00083 const std::string s_histoFormatPathTitle = "| %1$-45.45s | %2$-45.45s | " ;
00084
00086 const std::string s_histoFormatFull =
00087 "| %1$-45.45s | %2$-45.45s | %3$=7d |%4$5d/%5$-5d|%6$9.3g | %7$-9.3g|%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|" ;
00089 const std::string s_histoFormatFullStat =
00090 "| %3$=7d |%4$5d/%5$-5d|%6$9.3g | %7$-9.3g|%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|" ;
00091
00092
00093
00095 const std::string s_histoFormatStatHeader =
00096 "| Title | # | Mean | RMS | Skewness | Kurtosis |" ;
00097
00099 const std::string s_histoFormatStatOnlyHeader =
00100 "| # | Mean | RMS | Skewness | Kurtosis |" ;
00101
00103 const std::string s_histoFormatStat1Header =
00104 "| # | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
00105
00107 const std::string s_histoFormatShapeOnlyHeader =
00108 "| Mean | RMS | Skewness | Kurtosis | Underflow%/Overflow% |" ;
00109
00111 const std::string s_histoFormatShapeHeader =
00112 "| Mean | RMS | Skewness | Kurtosis | Underflow [%] | Overflow [%] |" ;
00113
00115 const std::string s_histoFormatLineTitleHeader = " Title " ;
00116
00118 const std::string s_histoFormatLineOnlyHeader = "" ;
00119
00121 const std::string s_histoFormatOldHeader = "" ;
00122
00124 const std::string s_histoFormatPathTitleHeader =
00125 "| Path in Histogram Data Store | Title | ";
00126
00128 const std::string s_histoFormatFullHeader =
00129 "| Path in Histogram Data Store | Title | # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
00130
00132 const std::string s_histoFormatFullStatHeader =
00133 "| # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
00134
00135 }
00136
00137
00138
00139 std::string Gaudi::Utils::Histos::Formats::format ( const int ID )
00140 {
00141 switch ( ID )
00142 {
00143 case Old : return s_histoFormatOld ;
00144 case Full : return s_histoFormatFull ;
00145 case FullStat : return s_histoFormatFullStat ;
00146 case Stat : return s_histoFormatStat ;
00147 case StatOnly : return s_histoFormatStatOnly ;
00148 case Stat1 : return s_histoFormatStat1 ;
00149 case ShapeOnly : return s_histoFormatShapeOnly ;
00150 case Shape : return s_histoFormatShape ;
00151 case LineTitle : return s_histoFormatLineTitle ;
00152 case LineOnly : return s_histoFormatLineOnly ;
00153 case PathTitle : return s_histoFormatPathTitle ;
00154 default : ;
00155 }
00157 return s_histoFormatStat ;
00158 }
00159
00160
00161
00162 std::string Gaudi::Utils::Histos::Formats::header ( const int ID )
00163 {
00164 switch ( ID )
00165 {
00166 case Old : return s_histoFormatOldHeader ;
00167 case Full : return s_histoFormatFullHeader ;
00168 case FullStat : return s_histoFormatFullStatHeader ;
00169 case Stat : return s_histoFormatStatHeader ;
00170 case Stat1 : return s_histoFormatStat1Header ;
00171 case StatOnly : return s_histoFormatStatOnlyHeader ;
00172 case ShapeOnly : return s_histoFormatShapeOnlyHeader ;
00173 case Shape : return s_histoFormatShapeHeader ;
00174 case LineTitle : return s_histoFormatLineTitleHeader ;
00175 case LineOnly : return s_histoFormatLineOnlyHeader ;
00176 case PathTitle : return s_histoFormatPathTitleHeader ;
00177 default : ;
00178 }
00180 return s_histoFormatStatHeader ;
00181 }
00182
00183
00184
00185 std::string Gaudi::Utils::Histos::path ( const AIDA::IBaseHistogram* aida )
00186 {
00187 if ( 0 == aida ) { return "" ; }
00188 const DataObject* object = dynamic_cast<const DataObject*>( aida ) ;
00189 if ( 0 == object ) { return "" ; }
00190 IRegistry* registry = object->registry() ;
00191 if ( 0 == registry ) { return "" ; }
00192 std::string _path = registry->identifier() ;
00193 std::string::size_type n = _path.find("/stat/") ;
00194 if ( 0 == n ) { return std::string(_path,6) ; }
00195 return _path ;
00196 }
00197
00198
00199
00200
00201
00202 std::string Gaudi::Utils::Histos::format
00203 ( const AIDA::IHistogram1D* histo ,
00204 const std::string& fmt )
00205 {
00206 if ( 0 == histo ) { return "<NULL>" ; }
00207 using namespace Gaudi::Utils ;
00208 using namespace boost::io ;
00209 boost::format _fmt ( fmt ) ;
00210
00211 _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00212
00213 _fmt
00214 % ( "\"" + path ( histo ) + "\"" )
00215 % ( "\"" + histo -> title () + "\"" )
00216 % histo -> allEntries ()
00217 % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN )
00218 % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN )
00219 % histo -> equivalentBinEntries ()
00220 % histo -> sumBinHeights ()
00221 % histo -> mean ()
00222 % HistoStats:: meanErr ( histo )
00223 % histo -> rms ()
00224 % HistoStats::rmsErr ( histo )
00225 % HistoStats::skewness ( histo )
00226 % HistoStats::skewnessErr ( histo )
00227 % HistoStats::kurtosis ( histo )
00228 % HistoStats::kurtosisErr ( histo )
00229
00230 % histo -> sumAllBinHeights ()
00231 % HistoStats::sumAllBinHeightErr ( histo )
00232 % HistoStats::sumBinHeightErr ( histo )
00233
00234 % ( 100 * HistoStats::underflowEntriesFrac ( histo ) )
00235 % ( 100 * HistoStats::underflowEntriesFracErr ( histo ) )
00236 % ( 100 * HistoStats::overflowEntriesFrac ( histo ) )
00237 % ( 100 * HistoStats::overflowEntriesFracErr ( histo ) )
00238
00239 % HistoStats::underflowIntegralFrac ( histo )
00240 % HistoStats::underflowIntegralFracErr ( histo )
00241 % HistoStats::overflowIntegralFrac ( histo )
00242 % HistoStats::overflowIntegralFracErr ( histo ) ;
00243
00244 return _fmt.str() ;
00245 }
00246
00247
00248
00249
00250
00251 std::string Gaudi::Utils::Histos::format
00252 ( const AIDA::IHistogram1D* histo ,
00253 const std::string& ID ,
00254 const std::string& fmt1 ,
00255 const std::string& fmt2 )
00256 {
00257 using namespace boost::io ;
00258 boost::format _fmt ( fmt1 ) ;
00259
00260 _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00261
00262 _fmt
00263 % ID
00264 % format ( histo , fmt2 ) ;
00265
00266 return _fmt.str() ;
00267 }
00268
00269
00270
00271 std::string Gaudi::Utils::Histos::format
00272 ( const std::string& val1 ,
00273 const std::string& val2 ,
00274 const std::string& fmt )
00275 {
00276 using namespace boost::io ;
00277 boost::format _fmt ( fmt ) ;
00278
00279 _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00280
00281 _fmt
00282 % val1
00283 % val2 ;
00284
00285 return _fmt.str() ;
00286 }
00287
00288
00289
00290 Gaudi::Utils::Histos::Table::Table ( const int ID )
00291 : m_header ( Gaudi::Utils::Histos::Formats::header ( ID ) )
00292 , m_footer ()
00293 , m_format ( Gaudi::Utils::Histos::Formats::format ( ID ) )
00294 {}
00295
00296 Gaudi::Utils::Histos::Table::Table
00297 ( const std::string& format ,
00298 const std::string& header ,
00299 const std::string& footer )
00300 : m_header ( header )
00301 , m_footer ( footer )
00302 , m_format ( format )
00303 {}
00304
00305
00306
00307 std::string Gaudi::Utils::Histos::Table::toString
00308 ( const AIDA::IHistogram1D* histo ) const
00309 { return Gaudi::Utils::Histos::format ( histo , format() ) ; }
00310
00314
00315 std::string Gaudi::Utils::Histos::Table::toString
00316 ( const AIDA::IHistogram1D* histo ,
00317 const std::string& ID ,
00318 const std::string& fmt ) const
00319 { return Gaudi::Utils::Histos::format ( histo , ID , fmt , format() ) ; }
00320
00321
00322
00323
00324