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