| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

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