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