| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# Generic1D.h

Go to the documentation of this file.

    00001 #ifndef GAUDISVC_GENERIC1D_H
    00002 #define GAUDISVC_GENERIC1D_H 1
    00003
    00004 #include <stdexcept>
    00005 #include "Axis.h"
    00006 #include "Annotation.h"
    00007 #include "GaudiKernel/HistogramBase.h"
    00008 #include "AIDA/IProfile1D.h"
    00009 #include "TFile.h"
    00010
    00011 /*
    00012  *    Gaudi namespace
    00013  */
    00014 namespace Gaudi {
    00015
    00026   template <class INTERFACE, class IMPLEMENTATION>
    00027   class Generic1D : virtual public INTERFACE, virtual public HistogramBase {
    00028   public:
    00029     typedef Generic1D<INTERFACE,IMPLEMENTATION> Base;
    00031     Generic1D() : m_rep(0) {}
    00033     virtual ~Generic1D()                                 { delete m_rep;                       }
    00035     virtual const std::string& userLevelClassType() const{ return m_classType;                 }
    00037     virtual void* cast(const std::string& cl) const;
    00039     TObject* representation() const                      { return m_rep;                       }
    00041     virtual void adoptRepresentation(TObject*rep);
    00043     virtual std::string title() const                    { return m_annotation.value("Title"); }
    00045     virtual bool setTitle(const std::string & title);
    00047     std::string name() const                             { return m_annotation.value("Name");  }
    00049     bool setName( const std::string& newName );
    00051     virtual AIDA::IAnnotation & annotation()             { return m_annotation;                }
    00053     virtual const AIDA::IAnnotation & annotation() const { return m_annotation;                }
    00055     Axis & axis ()                                       { return m_axis;                      }
    00057     const Axis & axis () const                           { return m_axis;                      }
    00058
    00060     virtual int entries() const                   { return (int)m_rep->GetEntries();           }
    00062     virtual int allEntries() const                { return int(m_rep->GetEntries());           }
    00064     virtual int extraEntries() const;
    00066     virtual int  binEntries ( int index ) const;
    00067     // spread
    00068     virtual double binRms(int index) const;
    00070     virtual double sumBinHeights() const         { return m_rep->GetSumOfWeights();            }
    00072     virtual double sumAllBinHeights() const      { return m_rep->GetSum();                     }
    00074     virtual double  sumExtraBinHeights () const  { return  sumAllBinHeights()-sumBinHeights(); }
    00076     virtual double minBinHeight() const          { return m_rep->GetMinimum();                 }
    00078     virtual double maxBinHeight() const          { return m_rep->GetMaximum();                 }
    00079
    00081     virtual double equivalentBinEntries (  ) const;
    00083     virtual bool scale( double scaleFactor );
    00085     virtual bool reset();
    00087     virtual bool add(const INTERFACE & profile);
    00089     virtual int rIndex(int index) const          { return m_axis.rIndex(index);}
    00091     virtual double  binMean(int index) const;
    00093     virtual double  binHeight(int index) const;
    00095     virtual double  binError(int index) const;
    00097     virtual double  mean() const                 { return m_rep->GetMean();                    }
    00099     virtual double  rms () const                 {  return m_rep->GetRMS();                    }
    00101     virtual int  coordToIndex ( double coord ) const { return axis().coordToIndex(coord);}
    00103     virtual int  dimension (  ) const  { return 1; }
    00105     virtual std::ostream& print( std::ostream& s ) const;
    00107     virtual std::ostream& write( std::ostream& s ) const;
    00109     virtual int write( const char* file_name ) const;
    00110
    00111   protected:
    00113     Axis                     m_axis;
    00115     mutable AIDA::Annotation m_annotation;
    00117     IMPLEMENTATION*          m_rep;
    00118     // class type
    00119     std::string              m_classType;
    00120     // cache sumEntries (allEntries)   when setting contents since Root can't compute by himself
    00121     int                      m_sumEntries;
    00122   }; // end class Generic1D
    00123
    00124   template <class INTERFACE, class IMPLEMENTATION>
    00125   bool Generic1D<INTERFACE,IMPLEMENTATION>::setTitle(const std::string & title)  {
    00126     m_rep->SetTitle(title.c_str());
    00127     if ( !annotation().addItem( "Title", title ) )
    00128       m_annotation.setValue( "Title" , title );
    00129     if ( !annotation().addItem( "title", title ) )
    00130       annotation().setValue( "title", title );
    00131     return true;
    00132   }
    00133
    00134   template <class INTERFACE, class IMPLEMENTATION>
    00135   bool Generic1D<INTERFACE,IMPLEMENTATION>::setName( const std::string& newName ) {
    00136     m_rep->SetName(newName.c_str());
    00137     m_annotation.setValue( "Name", newName );
    00138     return true;
    00139   }
    00140
    00141   template <class INTERFACE, class IMPLEMENTATION>
    00142   double Generic1D<INTERFACE,IMPLEMENTATION>::binRms(int index) const {
    00143     return m_rep->GetBinError ( rIndex(index) );
    00144   }
    00145
    00146   template <class INTERFACE, class IMPLEMENTATION>
    00147   double Generic1D<INTERFACE,IMPLEMENTATION>::binMean ( int index ) const  {
    00148     return m_rep->GetBinCenter ( rIndex(index) );
    00149   }
    00150
    00151   template <class INTERFACE, class IMPLEMENTATION>
    00152   double Generic1D<INTERFACE,IMPLEMENTATION>::binHeight ( int index ) const  {
    00153     return m_rep->GetBinContent ( rIndex(index) );
    00154   }
    00155
    00156   template <class INTERFACE, class IMPLEMENTATION>
    00157   double Generic1D<INTERFACE,IMPLEMENTATION>::binError ( int index ) const  {
    00158     return m_rep->GetBinError ( rIndex(index) );
    00159   }
    00160
    00161   template <class INTERFACE, class IMPLEMENTATION>
    00162   int Generic1D<INTERFACE,IMPLEMENTATION>::extraEntries() const {
    00163     return binEntries(AIDA::IAxis::UNDERFLOW_BIN) +
    00164           binEntries(AIDA::IAxis::OVERFLOW_BIN);
    00165   }
    00166   template <class INTERFACE, class IMPLEMENTATION>
    00167   bool Generic1D<INTERFACE,IMPLEMENTATION>::reset()   {
    00168     m_sumEntries = 0;
    00169     m_rep->Reset();
    00170     return true;
    00171   }
    00172
    00173   template <class INTERFACE, class IMPLEMENTATION>
    00174   double Generic1D<INTERFACE,IMPLEMENTATION>::equivalentBinEntries() const  {
    00175     if (sumBinHeights() <= 0) return 0;
    00176     Stat_t stats[11];   // cover up to 3D...
    00177     m_rep->GetStats(stats);
    00178     return stats[0]*stats[0]/stats[1];
    00179   }
    00180
    00181   template <class INTERFACE, class IMPLEMENTATION>
    00182   bool Generic1D<INTERFACE,IMPLEMENTATION>::scale(double scaleFactor)   {
    00183     m_rep->Scale ( scaleFactor );
    00184     return true;
    00185   }
    00186
    00187   template <class INTERFACE, class IMPLEMENTATION>
    00188   bool Generic1D<INTERFACE,IMPLEMENTATION>::add(const INTERFACE & h)  {
    00189     const Generic1D<INTERFACE,IMPLEMENTATION>* p =
    00190       dynamic_cast<const Generic1D<INTERFACE,IMPLEMENTATION>*>(&h);
    00191     if ( p )  {
    00192       m_rep->Add(p->m_rep);
    00193       return true;
    00194     }
    00195     throw std::runtime_error("Cannot add profile histograms of different implementations.");
    00196   }
    00197
    00198   template <class INTERFACE, class IMPLEMENTATION>
    00199   std::ostream& Generic1D<INTERFACE,IMPLEMENTATION>::print( std::ostream& s ) const    {
    00201     m_rep->Print("all");
    00202     return s;
    00203   }
    00204
    00206   template <class INTERFACE, class IMPLEMENTATION>
    00207   std::ostream& Generic1D<INTERFACE,IMPLEMENTATION>::write( std::ostream& s ) const  {
    00208     s << "\n1D Histogram Table: " << std::endl;
    00209     s << "Bin, Height, Error "  << std::endl;
    00210     for( int i = 0; i < axis().bins(); ++i )
    00211       s << binMean( i ) << ", "
    00212         << binHeight( i ) << ", "
    00213         << binError ( i ) << std::endl;
    00214     s << std::endl;
    00215     return s;
    00216   }
    00217
    00219   template <class INTERFACE, class IMPLEMENTATION>
    00220   int Generic1D<INTERFACE,IMPLEMENTATION>::write( const char* file_name ) const
    00221   {
    00222     TFile *f = TFile::Open(file_name,"RECREATE");
    00223     Int_t nbytes = m_rep->Write();
    00224     f->Close();
    00225     return nbytes;
    00226   }
    00227 } // end namespace AIDA
    00228
    00229 #endif // AIDAROOT_GENERIC1D_H