HistoTableFormat.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <string>
7 #include <cmath>
8 // ============================================================================
9 // AIDA
10 // ============================================================================
12 #include <vector>
13 #include "GaudiKernel/Kernel.h"
14 #ifdef __clang__
15 #pragma clang diagnostic push
16 #pragma clang diagnostic ignored "-Wkeyword-macro"
17 #endif
18 #define class class GAUDI_API
19 #ifdef __clang__
20 #pragma clang diagnostic pop
21 #endif
22 #include "AIDA/IHistogram1D.h"
23 #include "AIDA/IAxis.h"
24 #undef class
25 // ============================================================================
26 // GaudiKernel
27 // ============================================================================
28 #include "GaudiKernel/DataObject.h"
29 #include "GaudiKernel/IRegistry.h"
30 // ============================================================================
31 // Local
32 // ============================================================================
33 #include "GaudiUtils/HistoStats.h"
35 // ============================================================================
36 // Boost
37 // ============================================================================
38 #include "boost/format.hpp"
39 // ============================================================================
45 // ============================================================================
46 namespace
47 {
48  // ==========================================================================
49  // Examples of formats
50  // ==========================================================================
52  const std::string s_histoFormatStat =
53  "| %2$-45.45s | %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
54  // ==========================================================================
56  const std::string s_histoFormatStatOnly =
57  "| %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
58  // ==========================================================================
60  const std::string s_histoFormatStat1 =
61  "| %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|" ;
62  // ==========================================================================
66  const std::string s_histoFormatShapeOnly =
67  "|%8$11.5g |%10$11.5g |%12$11.5g |%14$11.5g |%19$11.5g/%21$-11.5g|" ;
68  // ==========================================================================
73  const std::string s_histoFormatShape =
74  "|%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|" ;
75  // ==========================================================================
77  const std::string s_histoFormatLineTitle =
78  " %2$-45.45s mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
79  // ==========================================================================
81  const std::string s_histoFormatLineOnly =
82  " mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
83  // ==========================================================================
85  const std::string s_histoFormatOld =
86  " %2$-45.45s Ents/All=%7$5s/%3$5s<X>/sX=%8$.5g/%10$-.5g" ;
87  // ==========================================================================
89  const std::string s_histoFormatPathTitle = "| %1$-45.45s | %2$-45.45s | " ;
90  // ==========================================================================
92  const std::string s_histoFormatFull =
93  "| %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|" ;
95  const std::string s_histoFormatFullStat =
96  "| %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|" ;
97  // ==========================================================================
98  // headers:
99  // ==========================================================================
101  const std::string s_histoFormatStatHeader =
102  "| Title | # | Mean | RMS | Skewness | Kurtosis |" ;
103  // ==========================================================================
105  const std::string s_histoFormatStatOnlyHeader =
106  "| # | Mean | RMS | Skewness | Kurtosis |" ;
107  // ==========================================================================
109  const std::string s_histoFormatStat1Header =
110  "| # | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
111  // ==========================================================================
113  const std::string s_histoFormatShapeOnlyHeader =
114  "| Mean | RMS | Skewness | Kurtosis | Underflow%/Overflow% |" ;
115  // ==========================================================================
117  const std::string s_histoFormatShapeHeader =
118  "| Mean | RMS | Skewness | Kurtosis | Underflow [%] | Overflow [%] |" ;
119  // ==========================================================================
121  const std::string s_histoFormatLineTitleHeader = " Title " ;
122  // ==========================================================================
124  const std::string s_histoFormatLineOnlyHeader = "" ;
125  // ==========================================================================
127  const std::string s_histoFormatOldHeader = "" ;
128  // ==========================================================================
130  const std::string s_histoFormatPathTitleHeader =
131  "| Path in Histogram Data Store | Title | ";
132  // ==========================================================================
134  const std::string s_histoFormatFullHeader =
135  "| Path in Histogram Data Store | Title | # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
136  // ==========================================================================
138  const std::string s_histoFormatFullStatHeader =
139  "| # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
140  // ==========================================================================
141 }
142 // ============================================================================
143 // get the format by enum
144 // ============================================================================
146 {
147  switch ( ID )
148  {
149  case Old : return s_histoFormatOld ;
150  case Full : return s_histoFormatFull ;
151  case FullStat : return s_histoFormatFullStat ;
152  case Stat : return s_histoFormatStat ;
153  case StatOnly : return s_histoFormatStatOnly ;
154  case Stat1 : return s_histoFormatStat1 ;
155  case ShapeOnly : return s_histoFormatShapeOnly ;
156  case Shape : return s_histoFormatShape ;
157  case LineTitle : return s_histoFormatLineTitle ;
158  case LineOnly : return s_histoFormatLineOnly ;
159  case PathTitle : return s_histoFormatPathTitle ;
160  default : break ;
161  }
163  return s_histoFormatStat ;
164 }
165 // ============================================================================
166 // get the recommended header by enum
167 // ============================================================================
169 {
170  switch ( ID )
171  {
172  case Old : return s_histoFormatOldHeader ;
173  case Full : return s_histoFormatFullHeader ;
174  case FullStat : return s_histoFormatFullStatHeader ;
175  case Stat : return s_histoFormatStatHeader ;
176  case Stat1 : return s_histoFormatStat1Header ;
177  case StatOnly : return s_histoFormatStatOnlyHeader ;
178  case ShapeOnly : return s_histoFormatShapeOnlyHeader ;
179  case Shape : return s_histoFormatShapeHeader ;
180  case LineTitle : return s_histoFormatLineTitleHeader ;
181  case LineOnly : return s_histoFormatLineOnlyHeader ;
182  case PathTitle : return s_histoFormatPathTitleHeader ;
183  default : ;
184  }
186  return s_histoFormatStatHeader ;
187 }
188 // ============================================================================
189 // get the path in TES for AIDA histogram
190 // ============================================================================
191 std::string Gaudi::Utils::Histos::path ( const AIDA::IBaseHistogram* aida )
192 {
193  if ( 0 == aida ) { return "" ; } // RETURN
194  const DataObject* object = dynamic_cast<const DataObject*>( aida ) ;
195  if ( 0 == object ) { return "" ; } // RETURN
196  IRegistry* registry = object->registry() ;
197  if ( 0 == registry ) { return "" ; } // RETURN
198  std::string _path = registry->identifier() ;
199  std::string::size_type n = _path.find("/stat/") ;
200  if ( 0 == n ) { return std::string(_path,6) ; } // RETURN
201  return _path ; // RETURN
202 }
203 // ============================================================================
204 /* Make the string representation of the historgam
205  * according to the specified format.
206  */
207 // ============================================================================
209 ( const AIDA::IHistogram1D* histo ,
210  const std::string& fmt )
211 {
212  if ( 0 == histo ) { return "<NULL>" ; }
213  using namespace Gaudi::Utils ;
214  using namespace boost::io ;
215  boost::format _fmt ( fmt ) ;
216  // allow various number of arguments
217  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
218 
219  _fmt
220  % ( "\"" + path ( histo ) + "\"" ) // 1) histogram path
221  % ( "\"" + histo -> title () + "\"" ) // 2) title
222  % histo -> allEntries () // 3) # entries
223  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) // 4) # underflow
224  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN ) // 5) # overflow
225  % histo -> equivalentBinEntries () // 6) equivalent entries
226  % histo -> sumBinHeights () // 7) integral
227  % histo -> mean () // 8) mean value
228  % HistoStats:: meanErr ( histo ) // 9) error in mean
229  % histo -> rms () // 10) rms
230  % HistoStats::rmsErr ( histo ) // 11) error in rms
231  % HistoStats::skewness ( histo ) // 12) skewness
232  % HistoStats::skewnessErr ( histo ) // 13) error in skewness
233  % HistoStats::kurtosis ( histo ) // 14) kurtosis
234  % HistoStats::kurtosisErr ( histo ) // 15) error in kurtosis
235  //
236  % histo -> sumAllBinHeights () // 16) full integral (in and out range)
237  % HistoStats::sumAllBinHeightErr ( histo ) // 17) error on 16
238  % HistoStats::sumBinHeightErr ( histo ) // 18) error on 7
239  //
240  % ( 100 * HistoStats::underflowEntriesFrac ( histo ) ) // 19) fraction of underflow entries
241  % ( 100 * HistoStats::underflowEntriesFracErr ( histo ) ) // 20) error on 19
242  % ( 100 * HistoStats::overflowEntriesFrac ( histo ) ) // 21) fraction of overflow entries
243  % ( 100 * HistoStats::overflowEntriesFracErr ( histo ) ) // 22) error on 21
244  //
245  % HistoStats::underflowIntegralFrac ( histo ) // 23) fraction of underflow integral
246  % HistoStats::underflowIntegralFracErr ( histo ) // 24) error on 23
247  % HistoStats::overflowIntegralFrac ( histo ) // 25) fraction of overflow intergal
248  % HistoStats::overflowIntegralFracErr ( histo ) ; // 26) error on 25
249  //
250  return _fmt.str() ;
251 }
252 // ============================================================================
253 /* format a full row in table, including ID, label, path or any other
254  * "extra" identifier in string form
255  */
256 // ============================================================================
258 ( const AIDA::IHistogram1D* histo ,
259  const std::string& ID ,
260  const std::string& fmt1 ,
261  const std::string& fmt2 )
262 {
263  using namespace boost::io ;
264  boost::format _fmt ( fmt1 ) ;
265  // allow various number of arguments
266  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
267  //
268  _fmt
269  % ID // format ID
270  % format ( histo , fmt2 ) ; // format the histogram
271  //
272  return _fmt.str() ;
273 }
274 // ============================================================================
275 // helper method to merge the headers for short format table
276 // ============================================================================
278 ( const std::string& val1 ,
279  const std::string& val2 ,
280  const std::string& fmt )
281 {
282  using namespace boost::io ;
283  boost::format _fmt ( fmt ) ;
284  // allow various number of arguments
285  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
286  //
287  _fmt
288  % val1 // format ID
289  % val2 ; // format the histogram
290  //
291  return _fmt.str() ;
292 }
293 // ============================================================================
294 // default constructor
295 // ============================================================================
297  : m_header ( Gaudi::Utils::Histos::Formats::header ( ID ) )
298  , m_footer ()
299  , m_format ( Gaudi::Utils::Histos::Formats::format ( ID ) )
300 {}
301 // ============================================================================
303 ( const std::string& format ,
304  const std::string& header ,
305  const std::string& footer )
306  : m_header ( header )
307  , m_footer ( footer )
308  , m_format ( format )
309 {}
310 // ============================================================================
311 // format the table row using the default format
312 // ============================================================================
314 ( const AIDA::IHistogram1D* histo ) const
315 { return Gaudi::Utils::Histos::format ( histo , format() ) ; }
316 // ============================================================================
320 // ============================================================================
322 ( const AIDA::IHistogram1D* histo ,
323  const std::string& ID ,
324  const std::string& fmt ) const
325 { return Gaudi::Utils::Histos::format ( histo , ID , fmt , format() ) ; }
326 // ============================================================================
327 
328 // ============================================================================
329 // The END
330 // ============================================================================
helper namespace to collect useful definitions, types, constants and functions, related to manipulati...
static double underflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow integral
Definition: HistoStats.cpp:411
static double overflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of overflow intergal
Definition: HistoStats.cpp:388
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
static double underflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow entries (useful for shape comparison)
Definition: HistoStats.cpp:307
std::string m_header
the table header
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:241
Table(const int ID=0)
constructor from enum
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:46
static double underflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow integral (useful for shape comparison)
Definition: HistoStats.cpp:336
GAUDI_API std::string format(const AIDA::IHistogram1D *histo, const std::string &fmt)
Make the string representation of the historgam according to the specified format.
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:223
static double overflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow intergal (useful for shape comparison)
Definition: HistoStats.cpp:322
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
const std::string & header() const
the table header
STL class.
virtual const id_type & identifier() const =0
Full identifier (or key)
GAUDI_API std::string format(const int ID=Default)
get the format by enum
const std::string & format() const
the format
static double overflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow entries (useful for shape comparison)
Definition: HistoStats.cpp:292
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
std::string m_footer
the table footer
static double sumBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum bin height ("in-range integral")
Definition: HistoStats.cpp:255
static double overflowEntriesFracErr(const AIDA::IHistogram1D *histo)
error on fraction of overflow entries (useful for shape comparison)
Definition: HistoStats.cpp:350
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
static double sumAllBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum of all bin height ("integral")
Definition: HistoStats.cpp:276
T find(T...args)
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:192
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:169
static double underflowEntriesFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow entries (useful for shape comparison)
Definition: HistoStats.cpp:369
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:181
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::string m_format
the defautl format
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:158
std::string toString(const AIDA::IHistogram1D *histo) const
make the string representation according to the default format
const std::string & footer() const
the table footer