| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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