All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HistoTableFormat.cpp
Go to the documentation of this file.
1 // $Id: HistoTableFormat.cpp,v 1.2 2008/04/03 22:12:27 marcocle Exp $
2 // ============================================================================
3 // Include files
4 // ============================================================================
5 // STD & STL
6 // ============================================================================
7 #include <string>
8 #include <cmath>
9 // ============================================================================
10 // AIDA
11 // ============================================================================
13 #include <vector>
14 #include "GaudiKernel/Kernel.h"
15 #define class class GAUDI_API
16 #include "AIDA/IHistogram1D.h"
17 #include "AIDA/IAxis.h"
18 #undef class
19 // ============================================================================
20 // GaudiKernel
21 // ============================================================================
22 #include "GaudiKernel/DataObject.h"
23 #include "GaudiKernel/IRegistry.h"
24 // ============================================================================
25 // Local
26 // ============================================================================
27 #include "GaudiUtils/HistoStats.h"
29 // ============================================================================
30 // Boost
31 // ============================================================================
32 #include "boost/format.hpp"
33 // ============================================================================
39 // ============================================================================
40 namespace
41 {
42  // ==========================================================================
43  // Examples of formats
44  // ==========================================================================
46  const std::string s_histoFormatStat =
47  "| %2$-45.45s | %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
48  // ==========================================================================
50  const std::string s_histoFormatStatOnly =
51  "| %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
52  // ==========================================================================
54  const std::string s_histoFormatStat1 =
55  "| %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|" ;
56  // ==========================================================================
60  const std::string s_histoFormatShapeOnly =
61  "|%8$11.5g |%10$11.5g |%12$11.5g |%14$11.5g |%19$11.5g/%21$-11.5g|" ;
62  // ==========================================================================
67  const std::string s_histoFormatShape =
68  "|%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|" ;
69  // ==========================================================================
71  const std::string s_histoFormatLineTitle =
72  " %2$-45.45s mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
73  // ==========================================================================
75  const std::string s_histoFormatLineOnly =
76  " mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
77  // ==========================================================================
79  const std::string s_histoFormatOld =
80  " %2$-45.45s Ents/All=%7$5s/%3$5s<X>/sX=%8$.5g/%10$-.5g" ;
81  // ==========================================================================
83  const std::string s_histoFormatPathTitle = "| %1$-45.45s | %2$-45.45s | " ;
84  // ==========================================================================
86  const std::string s_histoFormatFull =
87  "| %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|" ;
89  const std::string s_histoFormatFullStat =
90  "| %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|" ;
91  // ==========================================================================
92  // headers:
93  // ==========================================================================
95  const std::string s_histoFormatStatHeader =
96  "| Title | # | Mean | RMS | Skewness | Kurtosis |" ;
97  // ==========================================================================
99  const std::string s_histoFormatStatOnlyHeader =
100  "| # | Mean | RMS | Skewness | Kurtosis |" ;
101  // ==========================================================================
103  const std::string s_histoFormatStat1Header =
104  "| # | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
105  // ==========================================================================
107  const std::string s_histoFormatShapeOnlyHeader =
108  "| Mean | RMS | Skewness | Kurtosis | Underflow%/Overflow% |" ;
109  // ==========================================================================
111  const std::string s_histoFormatShapeHeader =
112  "| Mean | RMS | Skewness | Kurtosis | Underflow [%] | Overflow [%] |" ;
113  // ==========================================================================
115  const std::string s_histoFormatLineTitleHeader = " Title " ;
116  // ==========================================================================
118  const std::string s_histoFormatLineOnlyHeader = "" ;
119  // ==========================================================================
121  const std::string s_histoFormatOldHeader = "" ;
122  // ==========================================================================
124  const std::string s_histoFormatPathTitleHeader =
125  "| Path in Histogram Data Store | Title | ";
126  // ==========================================================================
128  const std::string s_histoFormatFullHeader =
129  "| Path in Histogram Data Store | Title | # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
130  // ==========================================================================
132  const std::string s_histoFormatFullStatHeader =
133  "| # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
134  // ==========================================================================
135 }
136 // ============================================================================
137 // get the format by enum
138 // ============================================================================
139 std::string Gaudi::Utils::Histos::Formats::format ( const int ID )
140 {
141  switch ( ID )
142  {
143  case Old : return s_histoFormatOld ;
144  case Full : return s_histoFormatFull ;
145  case FullStat : return s_histoFormatFullStat ;
146  case Stat : return s_histoFormatStat ;
147  case StatOnly : return s_histoFormatStatOnly ;
148  case Stat1 : return s_histoFormatStat1 ;
149  case ShapeOnly : return s_histoFormatShapeOnly ;
150  case Shape : return s_histoFormatShape ;
151  case LineTitle : return s_histoFormatLineTitle ;
152  case LineOnly : return s_histoFormatLineOnly ;
153  case PathTitle : return s_histoFormatPathTitle ;
154  default : break ;
155  }
157  return s_histoFormatStat ;
158 }
159 // ============================================================================
160 // get the recommended header by enum
161 // ============================================================================
162 std::string Gaudi::Utils::Histos::Formats::header ( const int ID )
163 {
164  switch ( ID )
165  {
166  case Old : return s_histoFormatOldHeader ;
167  case Full : return s_histoFormatFullHeader ;
168  case FullStat : return s_histoFormatFullStatHeader ;
169  case Stat : return s_histoFormatStatHeader ;
170  case Stat1 : return s_histoFormatStat1Header ;
171  case StatOnly : return s_histoFormatStatOnlyHeader ;
172  case ShapeOnly : return s_histoFormatShapeOnlyHeader ;
173  case Shape : return s_histoFormatShapeHeader ;
174  case LineTitle : return s_histoFormatLineTitleHeader ;
175  case LineOnly : return s_histoFormatLineOnlyHeader ;
176  case PathTitle : return s_histoFormatPathTitleHeader ;
177  default : ;
178  }
180  return s_histoFormatStatHeader ;
181 }
182 // ============================================================================
183 // get the path in TES for AIDA histogram
184 // ============================================================================
185 std::string Gaudi::Utils::Histos::path ( const AIDA::IBaseHistogram* aida )
186 {
187  if ( 0 == aida ) { return "" ; } // RETURN
188  const DataObject* object = dynamic_cast<const DataObject*>( aida ) ;
189  if ( 0 == object ) { return "" ; } // RETURN
190  IRegistry* registry = object->registry() ;
191  if ( 0 == registry ) { return "" ; } // RETURN
192  std::string _path = registry->identifier() ;
193  std::string::size_type n = _path.find("/stat/") ;
194  if ( 0 == n ) { return std::string(_path,6) ; } // RETURN
195  return _path ; // RETURN
196 }
197 // ============================================================================
198 /* Make the string representation of the historgam
199  * according to the specified format.
200  */
201 // ============================================================================
203 ( const AIDA::IHistogram1D* histo ,
204  const std::string& fmt )
205 {
206  if ( 0 == histo ) { return "<NULL>" ; }
207  using namespace Gaudi::Utils ;
208  using namespace boost::io ;
209  boost::format _fmt ( fmt ) ;
210  // allow various number of arguments
211  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
212 
213  _fmt
214  % ( "\"" + path ( histo ) + "\"" ) // 1) histogram path
215  % ( "\"" + histo -> title () + "\"" ) // 2) title
216  % histo -> allEntries () // 3) # entries
217  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) // 4) # underflow
218  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN ) // 5) # overflow
219  % histo -> equivalentBinEntries () // 6) equivalent entries
220  % histo -> sumBinHeights () // 7) integral
221  % histo -> mean () // 8) mean value
222  % HistoStats:: meanErr ( histo ) // 9) error in mean
223  % histo -> rms () // 10) rms
224  % HistoStats::rmsErr ( histo ) // 11) error in rms
225  % HistoStats::skewness ( histo ) // 12) skewness
226  % HistoStats::skewnessErr ( histo ) // 13) error in skewness
227  % HistoStats::kurtosis ( histo ) // 14) kurtosis
228  % HistoStats::kurtosisErr ( histo ) // 15) error in kurtosis
229  //
230  % histo -> sumAllBinHeights () // 16) full integral (in and out range)
231  % HistoStats::sumAllBinHeightErr ( histo ) // 17) error on 16
232  % HistoStats::sumBinHeightErr ( histo ) // 18) error on 7
233  //
234  % ( 100 * HistoStats::underflowEntriesFrac ( histo ) ) // 19) fraction of underflow entries
235  % ( 100 * HistoStats::underflowEntriesFracErr ( histo ) ) // 20) error on 19
236  % ( 100 * HistoStats::overflowEntriesFrac ( histo ) ) // 21) fraction of overflow entries
237  % ( 100 * HistoStats::overflowEntriesFracErr ( histo ) ) // 22) error on 21
238  //
239  % HistoStats::underflowIntegralFrac ( histo ) // 23) fraction of underflow integral
240  % HistoStats::underflowIntegralFracErr ( histo ) // 24) error on 23
241  % HistoStats::overflowIntegralFrac ( histo ) // 25) fraction of overflow intergal
242  % HistoStats::overflowIntegralFracErr ( histo ) ; // 26) error on 25
243  //
244  return _fmt.str() ;
245 }
246 // ============================================================================
247 /* format a full row in table, including ID, label, path or any other
248  * "extra" identifier in string form
249  */
250 // ============================================================================
252 ( const AIDA::IHistogram1D* histo ,
253  const std::string& ID ,
254  const std::string& fmt1 ,
255  const std::string& fmt2 )
256 {
257  using namespace boost::io ;
258  boost::format _fmt ( fmt1 ) ;
259  // allow various number of arguments
260  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
261  //
262  _fmt
263  % ID // format ID
264  % format ( histo , fmt2 ) ; // format the histogram
265  //
266  return _fmt.str() ;
267 }
268 // ============================================================================
269 // helper method to merge the headers for short format table
270 // ============================================================================
272 ( const std::string& val1 ,
273  const std::string& val2 ,
274  const std::string& fmt )
275 {
276  using namespace boost::io ;
277  boost::format _fmt ( fmt ) ;
278  // allow various number of arguments
279  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
280  //
281  _fmt
282  % val1 // format ID
283  % val2 ; // format the histogram
284  //
285  return _fmt.str() ;
286 }
287 // ============================================================================
288 // default constructor
289 // ============================================================================
291  : m_header ( Gaudi::Utils::Histos::Formats::header ( ID ) )
292  , m_footer ()
293  , m_format ( Gaudi::Utils::Histos::Formats::format ( ID ) )
294 {}
295 // ============================================================================
297 ( const std::string& format ,
298  const std::string& header ,
299  const std::string& footer )
300  : m_header ( header )
301  , m_footer ( footer )
302  , m_format ( format )
303 {}
304 // ============================================================================
305 // format the table row using the default format
306 // ============================================================================
308 ( const AIDA::IHistogram1D* histo ) const
309 { return Gaudi::Utils::Histos::format ( histo , format() ) ; }
310 // ============================================================================
314 // ============================================================================
316 ( const AIDA::IHistogram1D* histo ,
317  const std::string& ID ,
318  const std::string& fmt ) const
319 { return Gaudi::Utils::Histos::format ( histo , ID , fmt , format() ) ; }
320 // ============================================================================
321 
322 // ============================================================================
323 // The END
324 // ============================================================================
static double underflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow integral
Definition: HistoStats.cpp:433
static double overflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of overflow intergal
Definition: HistoStats.cpp:411
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
static double underflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow entries (useful for shape comparison)
Definition: HistoStats.cpp:327
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:255
Table(const int ID=0)
constructor from enum
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:50
static double underflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow integral (useful for shape comparison)
Definition: HistoStats.cpp:359
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:236
static double overflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow intergal (useful for shape comparison)
Definition: HistoStats.cpp:345
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
GAUDI_API std::string format(const int ID=Default)
get the format by enum
static double overflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow entries (useful for shape comparison)
Definition: HistoStats.cpp:309
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
static double sumBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum bin height ("in-range integral")
Definition: HistoStats.cpp:270
static double overflowEntriesFracErr(const AIDA::IHistogram1D *histo)
error on fraction of overflow entries (useful for shape comparison)
Definition: HistoStats.cpp:373
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:293
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:203
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:178
virtual const id_type & identifier() const =0
Full identifier (or key)
static double underflowEntriesFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow entries (useful for shape comparison)
Definition: HistoStats.cpp:392
list header
Definition: Test.py:33
This is a number of static methods for bootstrapping the Gaudi framework.
Definition: Bootstrap.h:14
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:192
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:167
std::string toString(const AIDA::IHistogram1D *histo) const
make the string representation according to the default format