| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# P2D.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 #include "GaudiKernel/DataObject.h"
    00007 #include "GaudiKernel/ObjectFactory.h"
    00008 #include "GaudiPI.h"
    00009 #include "Generic2D.h"
    00010 #include "TProfile2D.h"
    00011 #include "TH2D.h"
    00012
    00013 namespace Gaudi {
    00014
    00021   class GAUDI_API Profile2D : public DataObject, public Generic2D<AIDA::IProfile2D,TProfile2D>   {
    00022   public:
    00024     Profile2D() {
    00025       m_classType = "IProfile2D";
    00026       m_rep = new TProfile2D();
    00027       m_rep->SetErrorOption("s");
    00028       m_rep->SetDirectory(0);
    00029       m_sumEntries = 0;
    00030     }
    00032     Profile2D(TProfile2D* rep);
    00034     virtual ~Profile2D()  {}
    00036     bool fill(double x,double y,double z,double weight)  {
    00037       m_rep->Fill(x,y,z,weight);
    00038       return true;
    00039     }
    00041     virtual const CLID& clID() const { return Gaudi::Profile2D::classID(); }
    00042     static const CLID& classID()     { return CLID_ProfileH2; }
    00043   };
    00044 }
    00045 typedef Gaudi::Profile2D P2D;
    00046 DECLARE_DATAOBJECT_FACTORY(P2D)
    00047
    00048 namespace Gaudi {
    00049   template <>
    00050   void* Generic2D<AIDA::IProfile2D,TProfile2D>::cast(const std::string& className) const  {
    00051     if (className == "AIDA::IProfile2D")
    00052       return const_cast<AIDA::IProfile2D*>((AIDA::IProfile2D*)this);
    00053     else if (className == "AIDA::IProfile")
    00054       return const_cast<AIDA::IProfile*>((AIDA::IProfile*)this);
    00055     else if (className == "AIDA::IBaseHistogram")
    00056       return const_cast<AIDA::IBaseHistogram*>((AIDA::IBaseHistogram*)this);
    00057     return 0;
    00058   }
    00059
    00060   template <>
    00061   int  Generic2D<AIDA::IProfile2D,TProfile2D>::binEntries(int idX, int idY) const  {
    00062     int rBin = m_rep->GetBin(rIndexX(idX),rIndexY(idY));
    00063     return int(m_rep->GetBinEntries(rBin)+0.5);
    00064   }
    00065
    00066   template <>
    00067   void Generic2D<AIDA::IProfile2D,TProfile2D>::adoptRepresentation(TObject* rep) {
    00068     TProfile2D* imp = dynamic_cast<TProfile2D*>(rep);
    00069     if ( imp )  {
    00070       if ( m_rep ) delete m_rep;
    00071       m_rep = imp;
    00072       m_xAxis.initialize(m_rep->GetXaxis(),true);
    00073       m_yAxis.initialize(m_rep->GetYaxis(),true);
    00074       setTitle(m_rep->GetTitle());
    00075       return;
    00076     }
    00077     throw std::runtime_error("Cannot adopt native histogram representation.");
    00078   }
    00079 }
    00080
    00081 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const std::string& title, const Edges& eX, const Edges& eY, double /* zlow */ , double /* zup */) {
    00082   // Not implemented in ROOT! Can only use TProfile2D with no z-limits
    00083   Profile2D* p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),eX.size()-1,&eX.front(), eY.size()-1,&eY.front()/*,zlow,zup */));
    00084   return std::pair<DataObject*,AIDA::IProfile2D*>(p,p);
    00085 }
    00086
    00087 std::pair<DataObject*,AIDA::IProfile2D*>
    00088 Gaudi::createProf2D(const std::string& title,int binsX,double xlow,double xup,int binsY,double ylow,double yup,double zlow,double zup) {
    00089   Profile2D* p = new Profile2D(new TProfile2D(title.c_str(),title.c_str(),binsX,xlow,xup,binsY,ylow,yup,zlow,zup));
    00090   return std::pair<DataObject*,AIDA::IProfile2D*>(p,p);
    00091 }
    00092
    00093 std::pair<DataObject*,AIDA::IProfile2D*> Gaudi::createProf2D(const AIDA::IProfile2D& hist)  {
    00094   TProfile2D *h = getRepresentation<AIDA::IProfile2D,TProfile2D>(hist);
    00095   Profile2D *n = h ? new Profile2D(new TProfile2D(*h)) : 0;
    00096   return std::pair<DataObject*,AIDA::IProfile2D*>(n,n);
    00097 }
    00098
    00099 Gaudi::Profile2D::Profile2D(TProfile2D* rep)    {
    00100   m_rep = 0;
    00101   m_classType = "IProfile2D";
    00102   rep->SetDirectory(0);
    00103   adoptRepresentation(rep);
    00104   m_sumEntries = 0;
    00105 }