00001
00002 #ifndef HISTOGRAMSVC_GENHISTO1D_H
00003 #define HISTOGRAMSVC_GENHISTO1D_H 1
00004
00005
00006
00007 #include <string>
00008 #include "GaudiKernel/xtoa.h"
00009 #include "GaudiKernel/Kernel.h"
00010 #include "GaudiKernel/StatusCode.h"
00011 #include "GaudiKernel/DataObject.h"
00012 #include "GaudiKernel/IHistogram1D.h"
00013 #include "Axis.h"
00014
00015 #include "HTL/Histograms.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 template <class TYPE>
00049 class GenHisto1D : virtual public IHistogram1D, public DataObject {
00050
00051 protected:
00052
00056
00057 GenHisto1D(
00058 const std::string& title,
00059 const std::string& histoID,
00060 int nBinsX,
00061 double lowX,
00062 double highX,
00063 End_Point_Convention )
00064
00065 {
00066 std::string temp = histoID;
00067 temp += '|';
00068 temp += title;
00069 m_histogram = new TYPE( temp.c_str(), nBinsX, lowX, highX );
00070
00071 m_xAxis = new Axis( m_histogram, 0, nBinsX, lowX, highX );
00072 }
00073
00074 GenHisto1D(
00075 const std::string& title,
00076 int histoID,
00077 int nBinsX,
00078 double lowX,
00079 double highX,
00080 End_Point_Convention )
00081
00082 {
00083
00084 char buffer[32];
00085 _itoa(histoID,buffer,10);
00086 std::string temp = buffer;
00087 temp += '|';
00088 temp += title;
00089 m_histogram = new TYPE( temp.c_str(), nBinsX, lowX, highX );
00090
00091 m_xAxis = new Axis( m_histogram, 0, nBinsX, lowX, highX );
00092 }
00093
00097
00098 GenHisto1D(
00099 const std::string& title,
00100 const std::string& histoID,
00101 std::vector<double> edges,
00102 End_Point_Convention )
00103 {
00104 std::string temp = histoID;
00105 temp += '|';
00106 temp += title;
00107 m_histogram = new TYPE( temp.c_str(), edges );
00108
00109 m_xAxis = new Axis( m_histogram, 0, edges );
00110 }
00111
00112 GenHisto1D(
00113 const std::string& title,
00114 int histoID,
00115 std::vector<double> edges,
00116 End_Point_Convention )
00117 {
00118
00119 char buffer[32];
00120 _itoa(histoID,buffer,10);
00121 std::string temp = buffer;
00122 temp += '|';
00123 temp += title;
00124 m_histogram = new TYPE( temp.c_str(), edges );
00125
00126 m_xAxis = new Axis( m_histogram, 0, edges );
00127 }
00128
00132
00133 GenHisto1D(
00134 const std::string& title,
00135 Histo1D& h,
00136 int nBinsX,
00137 double lowX,
00138 double highX,
00139 End_Point_Convention )
00140 : m_histogram(&h)
00141 {
00142
00143 m_xAxis = new Axis( m_histogram, 0, nBinsX, lowX, highX );
00144
00145 setTitle( title );
00146 }
00147
00148 GenHisto1D(
00149 const std::string& title,
00150 Histo1DVar& h,
00151 std::vector<double>& edges,
00152 End_Point_Convention )
00153 : m_histogram(&h)
00154 {
00155
00156 m_xAxis = new Axis( m_histogram, 0, edges );
00157
00158 setTitle( title );
00159 }
00160
00164
00165 virtual ~GenHisto1D() {
00166 delete m_histogram;
00167 delete m_xAxis;
00168 }
00169
00170
00171 public:
00172
00173
00177
00178
00182
00186 virtual std::string title() const {
00187 return m_histogram->name();
00188 }
00189 virtual void setTitle( std::string value ) {
00190 m_histogram->set_name( value.c_str() );
00191 }
00192
00194
00195
00197 virtual int dimensions() const {
00198 return m_histogram->dim();
00199 }
00200
00202 virtual void reset() {
00203 m_histogram->reset();
00204 }
00205
00206
00210
00212 virtual int entries() const {
00213 return (int) HStat::in_range_entries_count( *m_histogram );
00214 }
00215
00218 virtual int allEntries() const {
00219 return (int) HStat::entries_count( *m_histogram );
00220 }
00221
00223 virtual int extraEntries() const {
00224 return (int) HStat::extra_entries_count( *m_histogram );
00225 }
00226
00229 virtual double equivalentBinEntries() const {
00230 return HStat::nequival( *m_histogram );
00231 }
00232
00233
00237
00239 virtual double sumBinHeights() const {
00240 return HInfo::in_range_value( *m_histogram );
00241 }
00242
00244 virtual double sumAllBinHeights() const {
00245 return sumBinHeights() + sumExtraBinHeights();
00246 }
00247
00249 virtual double sumExtraBinHeights() const {
00250 return binHeight( UNDERFLOW_BIN ) + binHeight( OVERFLOW_BIN );
00251 }
00252
00253
00257
00258
00262
00264 virtual void fill( double x, double weight = 1 ) {
00265 m_histogram->fill( x, weight );
00266 }
00267
00268
00273
00275 virtual int binEntries( int index ) const {
00276 int i = checkIndex( index );
00277 if( UNDERFLOW_BIN == i ) {
00278 return m_histogram->extra_bin( H_UNDERFLOW ).count();
00279 }
00280 else if( OVERFLOW_BIN == i ) {
00281 return m_histogram->extra_bin( H_OVERFLOW ).count();
00282 }
00283
00284 return m_histogram->i_bin( i ).count();
00285 }
00286
00288 virtual double binHeight( int index ) const {
00289 int i = checkIndex( index );
00290 if( UNDERFLOW_BIN == i ) {
00291 return m_histogram->extra_bin( H_UNDERFLOW ).value();
00292 }
00293 else if( OVERFLOW_BIN == i ) {
00294 return m_histogram->extra_bin( H_OVERFLOW ).value();
00295 }
00296
00297 return m_histogram->i_bin( i ).value();
00298 }
00299
00301 virtual double binError( int index ) const {
00302 int i = checkIndex( index );
00303 if( UNDERFLOW_BIN == i ) {
00304 return m_histogram->extra_bin( H_UNDERFLOW ).error();
00305 }
00306 else if( OVERFLOW_BIN == i ) {
00307 return m_histogram->extra_bin( H_OVERFLOW ).error();
00308 }
00309
00310 return m_histogram->i_bin( i ).error();
00311 }
00312
00313
00317
00320 virtual double mean() const {
00321 return HStat::mean( *m_histogram );
00322 }
00323
00326 virtual double rms() const {
00327 return HStat::rms( *m_histogram );
00328 }
00329
00330
00334
00336 virtual double minBinHeight() const {
00337 return HInfo::in_range_min_value( *m_histogram );
00338 }
00340 virtual int minBin() const {
00341 int index = 0;
00342 double val = m_histogram->i_bin( index ).value();
00343 for( int i=1; i<m_histogram->bin_count(); i++ ) {
00344 if( m_histogram->i_bin( i ).value() < val ) {
00345 index = i;
00346 }
00347 }
00348 return index;
00349 }
00350
00352 virtual double maxBinHeight() const {
00353 return HInfo::in_range_max_value( *m_histogram );
00354 }
00356 virtual int maxBin() const {
00357 int index = 0;
00358 double val = m_histogram->i_bin( index ).value();
00359 for( int i=1; i<m_histogram->bin_count(); i++ ) {
00360 if( m_histogram->i_bin( i ).value() > val ) {
00361 index = i;
00362 }
00363 }
00364 return index;
00365 }
00366
00367
00371
00373 virtual IAxis* xAxis() const {
00374 return m_xAxis;
00375 }
00376
00377
00381
00383 virtual int coordToIndex( double coord ) const {
00384 return xAxis()->coordToIndex( coord );
00385 }
00386
00387
00391
00394
00396 virtual std::ostream& print( std::ostream& s ) const {
00397 HPrinter hp( s );
00398 hp.print( *m_histogram );
00399 return s;
00400 }
00401
00404
00406 virtual std::ostream& write( std::ostream& s ) const {
00407 s << "1-dimensional histogram" << std::endl;
00408 for( int i = 0; i < m_xAxis->bins(); i++ ) {
00409 s << m_xAxis->binCentre(i) << " "
00410 << binHeight(i) << " "
00411 << binError(i) << std::endl;
00412 }
00413 s << std::endl;
00414 return s;
00415 }
00416
00418 virtual int write( const char* file_name ) const {
00419 HistoTable1D ht( file_name );
00420 int status = ht.write( *m_histogram );
00421 return status;
00422 }
00423
00424
00425 protected:
00426
00430
00433 virtual int checkIndex( int index ) const {
00434 return m_xAxis->checkIndex( index );
00435 }
00436
00437
00441
00443 TYPE* m_histogram;
00444
00446 Axis* m_xAxis;
00447
00448 };
00449
00450
00451 #endif // HISTOGRAMSVC_GENHISTO1D_H