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 #define class class GAUDI_API
15 #include "AIDA/IHistogram1D.h"
16 #include "AIDA/IAxis.h"
17 #undef class
18 // ============================================================================
19 // GaudiKernel
20 // ============================================================================
21 #include "GaudiKernel/DataObject.h"
22 #include "GaudiKernel/IRegistry.h"
23 // ============================================================================
24 // Local
25 // ============================================================================
26 #include "GaudiUtils/HistoStats.h"
27 #include "GaudiUtils/HistoTableFormat.h"
28 // ============================================================================
29 // Boost
30 // ============================================================================
31 #include "boost/format.hpp"
32 // ============================================================================
38 // ============================================================================
39 namespace
40 {
41  // ==========================================================================
42  // Examples of formats
43  // ==========================================================================
45  const std::string s_histoFormatStat =
46  "| %2$-45.45s | %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
47  // ==========================================================================
49  const std::string s_histoFormatStatOnly =
50  "| %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
51  // ==========================================================================
53  const std::string s_histoFormatStat1 =
54  "| %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|" ;
55  // ==========================================================================
59  const std::string s_histoFormatShapeOnly =
60  "|%8$11.5g |%10$11.5g |%12$11.5g |%14$11.5g |%19$11.5g/%21$-11.5g|" ;
61  // ==========================================================================
66  const std::string s_histoFormatShape =
67  "|%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|" ;
68  // ==========================================================================
70  const std::string s_histoFormatLineTitle =
71  " %2$-45.45s mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
72  // ==========================================================================
74  const std::string s_histoFormatLineOnly =
75  " mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
76  // ==========================================================================
78  const std::string s_histoFormatOld =
79  " %2$-45.45s Ents/All=%7$5s/%3$5s<X>/sX=%8$.5g/%10$-.5g" ;
80  // ==========================================================================
82  const std::string s_histoFormatPathTitle = "| %1$-45.45s | %2$-45.45s | " ;
83  // ==========================================================================
85  const std::string s_histoFormatFull =
86  "| %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|" ;
88  const std::string s_histoFormatFullStat =
89  "| %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|" ;
90  // ==========================================================================
91  // headers:
92  // ==========================================================================
94  const std::string s_histoFormatStatHeader =
95  "| Title | # | Mean | RMS | Skewness | Kurtosis |" ;
96  // ==========================================================================
98  const std::string s_histoFormatStatOnlyHeader =
99  "| # | Mean | RMS | Skewness | Kurtosis |" ;
100  // ==========================================================================
102  const std::string s_histoFormatStat1Header =
103  "| # | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
104  // ==========================================================================
106  const std::string s_histoFormatShapeOnlyHeader =
107  "| Mean | RMS | Skewness | Kurtosis | Underflow%/Overflow% |" ;
108  // ==========================================================================
110  const std::string s_histoFormatShapeHeader =
111  "| Mean | RMS | Skewness | Kurtosis | Underflow [%] | Overflow [%] |" ;
112  // ==========================================================================
114  const std::string s_histoFormatLineTitleHeader = " Title " ;
115  // ==========================================================================
117  const std::string s_histoFormatLineOnlyHeader = "" ;
118  // ==========================================================================
120  const std::string s_histoFormatOldHeader = "" ;
121  // ==========================================================================
123  const std::string s_histoFormatPathTitleHeader =
124  "| Path in Histogram Data Store | Title | ";
125  // ==========================================================================
127  const std::string s_histoFormatFullHeader =
128  "| Path in Histogram Data Store | Title | # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
129  // ==========================================================================
131  const std::string s_histoFormatFullStatHeader =
132  "| # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ;
133  // ==========================================================================
134 }
135 // ============================================================================
136 // get the format by enum
137 // ============================================================================
138 std::string Gaudi::Utils::Histos::Formats::format ( const int ID )
139 {
140  switch ( ID )
141  {
142  case Old : return s_histoFormatOld ;
143  case Full : return s_histoFormatFull ;
144  case FullStat : return s_histoFormatFullStat ;
145  case Stat : return s_histoFormatStat ;
146  case StatOnly : return s_histoFormatStatOnly ;
147  case Stat1 : return s_histoFormatStat1 ;
148  case ShapeOnly : return s_histoFormatShapeOnly ;
149  case Shape : return s_histoFormatShape ;
150  case LineTitle : return s_histoFormatLineTitle ;
151  case LineOnly : return s_histoFormatLineOnly ;
152  case PathTitle : return s_histoFormatPathTitle ;
153  default : break ;
154  }
156  return s_histoFormatStat ;
157 }
158 // ============================================================================
159 // get the recommended header by enum
160 // ============================================================================
161 std::string Gaudi::Utils::Histos::Formats::header ( const int ID )
162 {
163  switch ( ID )
164  {
165  case Old : return s_histoFormatOldHeader ;
166  case Full : return s_histoFormatFullHeader ;
167  case FullStat : return s_histoFormatFullStatHeader ;
168  case Stat : return s_histoFormatStatHeader ;
169  case Stat1 : return s_histoFormatStat1Header ;
170  case StatOnly : return s_histoFormatStatOnlyHeader ;
171  case ShapeOnly : return s_histoFormatShapeOnlyHeader ;
172  case Shape : return s_histoFormatShapeHeader ;
173  case LineTitle : return s_histoFormatLineTitleHeader ;
174  case LineOnly : return s_histoFormatLineOnlyHeader ;
175  case PathTitle : return s_histoFormatPathTitleHeader ;
176  default : ;
177  }
179  return s_histoFormatStatHeader ;
180 }
181 // ============================================================================
182 // get the path in TES for AIDA histogram
183 // ============================================================================
184 std::string Gaudi::Utils::Histos::path ( const AIDA::IBaseHistogram* aida )
185 {
186  if ( 0 == aida ) { return "" ; } // RETURN
187  const DataObject* object = dynamic_cast<const DataObject*>( aida ) ;
188  if ( 0 == object ) { return "" ; } // RETURN
189  IRegistry* registry = object->registry() ;
190  if ( 0 == registry ) { return "" ; } // RETURN
191  std::string _path = registry->identifier() ;
192  std::string::size_type n = _path.find("/stat/") ;
193  if ( 0 == n ) { return std::string(_path,6) ; } // RETURN
194  return _path ; // RETURN
195 }
196 // ============================================================================
197 /* Make the string representation of the historgam
198  * according to the specified format.
199  */
200 // ============================================================================
202 ( const AIDA::IHistogram1D* histo ,
203  const std::string& fmt )
204 {
205  if ( 0 == histo ) { return "<NULL>" ; }
206  using namespace Gaudi::Utils ;
207  using namespace boost::io ;
208  boost::format _fmt ( fmt ) ;
209  // allow various number of arguments
210  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
211 
212  _fmt
213  % ( "\"" + path ( histo ) + "\"" ) // 1) histogram path
214  % ( "\"" + histo -> title () + "\"" ) // 2) title
215  % histo -> allEntries () // 3) # entries
216  % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) // 4) # underflow
217  % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN ) // 5) # overflow
218  % histo -> equivalentBinEntries () // 6) equivalent entries
219  % histo -> sumBinHeights () // 7) integral
220  % histo -> mean () // 8) mean value
221  % HistoStats:: meanErr ( histo ) // 9) error in mean
222  % histo -> rms () // 10) rms
223  % HistoStats::rmsErr ( histo ) // 11) error in rms
224  % HistoStats::skewness ( histo ) // 12) skewness
225  % HistoStats::skewnessErr ( histo ) // 13) error in skewness
226  % HistoStats::kurtosis ( histo ) // 14) kurtosis
227  % HistoStats::kurtosisErr ( histo ) // 15) error in kurtosis
228  //
229  % histo -> sumAllBinHeights () // 16) full integral (in and out range)
230  % HistoStats::sumAllBinHeightErr ( histo ) // 17) error on 16
231  % HistoStats::sumBinHeightErr ( histo ) // 18) error on 7
232  //
233  % ( 100 * HistoStats::underflowEntriesFrac ( histo ) ) // 19) fraction of underflow entries
234  % ( 100 * HistoStats::underflowEntriesFracErr ( histo ) ) // 20) error on 19
235  % ( 100 * HistoStats::overflowEntriesFrac ( histo ) ) // 21) fraction of overflow entries
236  % ( 100 * HistoStats::overflowEntriesFracErr ( histo ) ) // 22) error on 21
237  //
238  % HistoStats::underflowIntegralFrac ( histo ) // 23) fraction of underflow integral
239  % HistoStats::underflowIntegralFracErr ( histo ) // 24) error on 23
240  % HistoStats::overflowIntegralFrac ( histo ) // 25) fraction of overflow intergal
241  % HistoStats::overflowIntegralFracErr ( histo ) ; // 26) error on 25
242  //
243  return _fmt.str() ;
244 }
245 // ============================================================================
246 /* format a full row in table, including ID, label, path or any other
247  * "extra" identifier in string form
248  */
249 // ============================================================================
251 ( const AIDA::IHistogram1D* histo ,
252  const std::string& ID ,
253  const std::string& fmt1 ,
254  const std::string& fmt2 )
255 {
256  using namespace boost::io ;
257  boost::format _fmt ( fmt1 ) ;
258  // allow various number of arguments
259  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
260  //
261  _fmt
262  % ID // format ID
263  % format ( histo , fmt2 ) ; // format the histogram
264  //
265  return _fmt.str() ;
266 }
267 // ============================================================================
268 // helper method to merge the headers for short format table
269 // ============================================================================
271 ( const std::string& val1 ,
272  const std::string& val2 ,
273  const std::string& fmt )
274 {
275  using namespace boost::io ;
276  boost::format _fmt ( fmt ) ;
277  // allow various number of arguments
278  _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
279  //
280  _fmt
281  % val1 // format ID
282  % val2 ; // format the histogram
283  //
284  return _fmt.str() ;
285 }
286 // ============================================================================
287 // default constructor
288 // ============================================================================
290  : m_header ( Gaudi::Utils::Histos::Formats::header ( ID ) )
291  , m_footer ()
292  , m_format ( Gaudi::Utils::Histos::Formats::format ( ID ) )
293 {}
294 // ============================================================================
296 ( const std::string& format ,
297  const std::string& header ,
298  const std::string& footer )
299  : m_header ( header )
300  , m_footer ( footer )
301  , m_format ( format )
302 {}
303 // ============================================================================
304 // format the table row using the default format
305 // ============================================================================
307 ( const AIDA::IHistogram1D* histo ) const
308 { return Gaudi::Utils::Histos::format ( histo , format() ) ; }
309 // ============================================================================
313 // ============================================================================
315 ( const AIDA::IHistogram1D* histo ,
316  const std::string& ID ,
317  const std::string& fmt ) const
318 { return Gaudi::Utils::Histos::format ( histo , ID , fmt , format() ) ; }
319 // ============================================================================
320 
321 // ============================================================================
322 // The END
323 // ============================================================================
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:432
static double overflowIntegralFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of overflow intergal
Definition: HistoStats.cpp:410
static double underflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of underflow entries (useful for shape comparison)
Definition: HistoStats.cpp:326
static double rmsErr(const AIDA::IHistogram1D *histo)
get an error in the rms value
Definition: HistoStats.cpp:254
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:358
list path
Definition: __init__.py:15
static double meanErr(const AIDA::IHistogram1D *histo)
get an error in the mean value
Definition: HistoStats.cpp:235
static double overflowIntegralFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow intergal (useful for shape comparison)
Definition: HistoStats.cpp:344
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 overflowEntriesFrac(const AIDA::IHistogram1D *histo)
the fraction of overflow entries (useful for shape comparison)
Definition: HistoStats.cpp:308
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
GAUDI_API std::string format(const int ID=Default)
get the format by enum
static double sumBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum bin height ("in-range integral")
Definition: HistoStats.cpp:269
static double overflowEntriesFracErr(const AIDA::IHistogram1D *histo)
error on fraction of overflow entries (useful for shape comparison)
Definition: HistoStats.cpp:372
static double sumAllBinHeightErr(const AIDA::IHistogram1D *histo)
get an error in the sum of all bin height ("integral")
Definition: HistoStats.cpp:292
static double kurtosisErr(const AIDA::IHistogram1D *histo)
get the error in kurtosis for the histogram
Definition: HistoStats.cpp:202
static double skewnessErr(const AIDA::IHistogram1D *histo)
get the error in skewness for the histogram
Definition: HistoStats.cpp:177
virtual const id_type & identifier() const =0
Full identifier (or key)
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
static double underflowEntriesFracErr(const AIDA::IHistogram1D *histo)
the error on fraction of underflow entries (useful for shape comparison)
Definition: HistoStats.cpp:391
list header
Definition: Test.py:33
static double kurtosis(const AIDA::IHistogram1D *histo)
get the kurtosis for the histogram
Definition: HistoStats.cpp:191
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
static double skewness(const AIDA::IHistogram1D *histo)
get the skewness for the histogram
Definition: HistoStats.cpp:166
std::string toString(const AIDA::IHistogram1D *histo) const
make the string representation according to the default format