| # Gaudi Framework, version v21r7p1 |

Home |  | Generated: 15 Feb 2010

# Generic1D.h

Go to the documentation of this file.

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