Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011

P1D.cpp

Go to the documentation of this file.
00001 #ifdef __ICC
00002 // disable icc remark #2259: non-pointer conversion from "X" to "Y" may lose significant bits
00003 //   TODO: To be removed, since it comes from ROOT TMathBase.h
00004 #pragma warning(disable:2259)
00005 #endif
00006 #ifdef WIN32
00007 // Disable warning
00008 //   warning C4996: 'sprintf': This function or variable may be unsafe.
00009 // coming from TString.h
00010 #pragma warning(disable:4996)
00011 #endif
00012 
00013 #include <cmath>
00014 #include "P1D.h"
00015 #include "GaudiKernel/ObjectFactory.h"
00016 
00017 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D
00018 ( const std::string& title ,
00019   int nBins  , double xlow, double xup,
00020   double ylow, double yup, const std::string& opt )
00021 {
00022   TProfile* _p = new TProfile(title.c_str(),title.c_str(),nBins,xlow,xup,ylow,yup,opt.c_str() ) ;
00023   Profile1D* p = new Profile1D(_p);
00024   return std::pair<DataObject*,AIDA::IProfile1D*>(p,p);
00025 }
00026 
00027 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D
00028 ( const std::string& title,
00029   const Edges& e, double ylow, double yup ,
00030   const std::string& opt )
00031 {
00032   Profile1D* p = new Profile1D(new TProfile(title.c_str(),title.c_str(),e.size()-1,&e.front(),ylow,yup,opt.c_str()));
00033   return std::pair<DataObject*,AIDA::IProfile1D*>(p,p);
00034 }
00035 
00036 std::pair<DataObject*,AIDA::IProfile1D*> Gaudi::createProf1D(const AIDA::IProfile1D& hist)  {
00037   TProfile *h = getRepresentation<AIDA::IProfile1D,TProfile>(hist);
00038   Profile1D *n = h ? new Profile1D(new TProfile(*h)) : 0;
00039   return std::pair<DataObject*,AIDA::IProfile1D*>(n,n);
00040 }
00041 
00042 namespace Gaudi {
00043   template <>
00044   int Generic1D<AIDA::IProfile1D,TProfile>::binEntries (int index) const  {
00045     return int(m_rep->GetBinEntries( rIndex(index) )+0.5);
00046   }
00047 
00048   template <> void* Generic1D<AIDA::IProfile1D,TProfile>::cast(const std::string& className) const {
00049     if (className == "AIDA::IProfile1D")
00050       return const_cast<AIDA::IProfile1D*>((AIDA::IProfile1D*)this);
00051     else if (className == "AIDA::IProfile")
00052       return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
00053     else if (className == "AIDA::IBaseHistogram")
00054       return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
00055     return 0;
00056   }
00057 
00058   template <>
00059   void Generic1D<AIDA::IProfile1D,TProfile>::adoptRepresentation(TObject* rep)  {
00060     TProfile* imp = dynamic_cast<TProfile*>(rep);
00061     if ( imp )  {
00062     if ( m_rep ) delete m_rep;
00063       m_rep = imp;
00064       m_axis.initialize(m_rep->GetXaxis(),true);
00065       const TArrayD* a = m_rep->GetSumw2();
00066       if ( 0 == a || (a && a->GetSize()==0) ) m_rep->Sumw2();
00067       setTitle(m_rep->GetTitle());
00068       return;
00069     }
00070     throw std::runtime_error("Cannot adopt native histogram representation.");
00071   }
00072 }
00073 
00074 Gaudi::Profile1D::Profile1D() {
00075   m_rep = new TProfile();
00076   init("",false);
00077 }
00078 
00079 Gaudi::Profile1D::Profile1D(TProfile* rep)  {
00080   m_rep = rep;
00081   init(m_rep->GetTitle());
00082 }
00083 
00084 void Gaudi::Profile1D::init(const std::string& title, bool initialize_axis) {
00085   m_classType = "IProfile1D";
00086   setTitle(title);
00087   setName(title);
00088   if ( initialize_axis )  {
00089     axis().initialize(m_rep->GetXaxis(),false);
00090   }
00091   //m_rep->SetErrorOption("s");
00092   m_rep->SetDirectory(0);
00093   m_sumEntries = 0;
00094 }
00095 
00096 bool Gaudi::Profile1D::setBinContents(int i, int entries,double height,double /*error*/, double spread, double /* centre */ ) {
00097   m_rep->SetBinEntries(rIndex(i), entries );
00098   // set content takes in root height * entries
00099   m_rep->SetBinContent(rIndex(i), height*entries );
00100   // set error takes sqrt of bin sum(w*y**2)
00101   double sumwy2Bin = ( spread*spread + height*height )*entries;
00102   m_rep->SetBinError(rIndex(i), sqrt(sumwy2Bin) );
00103   m_sumEntries += entries;
00104   // not very efficient (but do evey bin since root cannot figure out by himself)
00105   m_rep->SetEntries(m_sumEntries);
00106   return true;
00107 }
00108 
00109 #ifdef __ICC
00110 // disable icc remark #1572: floating-point equality and inequality comparisons are unreliable
00111 //   The comparison is correct
00112 #pragma warning(disable:1572)
00113 #endif
00114 bool Gaudi::Profile1D::fill ( double x, double y, double weight )  {
00115   (weight == 1.) ? m_rep->Fill(x,y) : m_rep->Fill(x,y,weight);
00116   return true;
00117 }
00118 
00119 typedef Gaudi::Profile1D P1D;
00120 DECLARE_DATAOBJECT_FACTORY(P1D)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Tue May 10 2011 18:53:59 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004