| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# P1D.cpp

Go to the documentation of this file.

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