00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "GaudiUtils/HistoLabels.h"
00010 #include "GaudiUtils/Aida2ROOT.h"
00011
00012
00013
00014
00015 #include "TH1D.h"
00016 #include "TH2D.h"
00017 #include "TProfile.h"
00018 #include "TProfile2D.h"
00019
00020
00021 namespace
00022 {
00023
00024
00025 template <typename R, typename A>
00026 bool setAxisLabels_( A* aida,
00027 const std::string& xAxis,
00028 const std::string& yAxis )
00029 {
00030 if (!aida) return false;
00031 R * root = Gaudi::Utils::Aida2ROOT::aida2root( aida );
00032 if (!root) return false;
00033 root->SetXTitle(xAxis.c_str());
00034 root->SetYTitle(yAxis.c_str());
00035 return true;
00036 }
00037
00038
00039
00040 bool setBinLabels_( TAxis* axis,
00041 const Gaudi::Utils::Histos::BinLabels & labels )
00042 {
00043 if (!axis) return false;
00044 const unsigned nbins = axis->GetNbins();
00045 for ( Gaudi::Utils::Histos::BinLabels::const_iterator i = labels.begin();
00046 i != labels.end(); ++i )
00047 {
00048 if ( 1+i->first <= 0 || 1+i->first > nbins ) return false;
00049
00050 axis -> SetBinLabel( 1 + i->first, i->second.c_str() );
00051 }
00052 return true;
00053 }
00054
00055
00056
00057 template <typename R, typename A>
00058 bool setBinLabels_( A* aida,
00059 const Gaudi::Utils::Histos::BinLabels& labels )
00060 {
00061 if (!aida) return false;
00062 R * root = Gaudi::Utils::Aida2ROOT::aida2root( aida );
00063 if (!root) return false;
00064 return setBinLabels_( root->GetXaxis(), labels );
00065 }
00066
00067 template <typename Histogram>
00068 bool setBinLabels_( Histogram* hist,
00069 const Gaudi::Utils::Histos::Labels& labels )
00070 {
00071 Gaudi::Utils::Histos::BinLabels l;
00072 l.reserve(labels.size());
00073 for ( unsigned i = 0; i<labels.size(); ++i )
00074 {
00075 l.push_back( Gaudi::Utils::Histos::BinLabel(i,labels[i]) );
00076 }
00077 return Gaudi::Utils::Histos::setBinLabels(hist,l);
00078 }
00079
00080
00081
00082 }
00083
00084 namespace Gaudi
00085 {
00086 namespace Utils
00087 {
00088 namespace Histos
00089 {
00090
00091
00092
00093 bool setBinLabels( AIDA::IHistogram1D* hist,
00094 const BinLabels& labels )
00095 {
00096 return setBinLabels_<TH1D>(hist,labels);
00097 }
00098
00099 bool setBinLabels( AIDA::IProfile1D* hist,
00100 const BinLabels& labels )
00101 {
00102 return setBinLabels_<TProfile>(hist,labels);
00103 }
00104
00105 bool setBinLabels( AIDA::IHistogram1D* hist,
00106 const Labels& labels )
00107 {
00108 return setBinLabels_(hist,labels);
00109 }
00110
00111 bool setBinLabels( AIDA::IProfile1D* hist,
00112 const Labels& labels )
00113 {
00114 return setBinLabels_(hist,labels);
00115 }
00116
00117 bool setBinLabels( AIDA::IHistogram2D* hist,
00118 const Labels& xlabels,
00119 const Labels& ylabels )
00120 {
00121 if (!hist) return false;
00122 TH2D * h2d = Gaudi::Utils::Aida2ROOT::aida2root( hist );
00123 if (!h2d) return false;
00124 BinLabels lx;
00125 lx.reserve(xlabels.size());
00126 for ( unsigned int i = 0; i < xlabels.size(); ++i )
00127 {
00128 lx.push_back( Gaudi::Utils::Histos::BinLabel( i , xlabels[i] ) );
00129 }
00130 BinLabels ly;
00131 ly.reserve(ylabels.size());
00132 for ( unsigned int i = 0; i < ylabels.size(); ++i )
00133 {
00134 ly.push_back(Gaudi::Utils::Histos::BinLabel( i , ylabels[i] ) );
00135 }
00136 return ( setBinLabels_( h2d->GetXaxis(), lx ) &&
00137 setBinLabels_( h2d->GetYaxis(), ly ) );
00138 }
00139
00140 bool setBinLabels( AIDA::IHistogram2D* hist,
00141 const BinLabels& xlabels,
00142 const BinLabels& ylabels)
00143 {
00144 TH2D * h2d = Gaudi::Utils::Aida2ROOT::aida2root( hist );
00145 return ( h2d &&
00146 setBinLabels_( h2d->GetXaxis(), xlabels ) &&
00147 setBinLabels_( h2d->GetYaxis(), ylabels ) );
00148 }
00149
00150 bool setBinLabels( AIDA::IProfile2D* hist,
00151 const Labels& xlabels,
00152 const Labels& ylabels )
00153 {
00154 if (!hist) return false;
00155 TProfile2D * h2d = Gaudi::Utils::Aida2ROOT::aida2root( hist );
00156 if (!h2d) return false;
00157 BinLabels lx;
00158 lx.reserve(xlabels.size());
00159 for ( unsigned int i = 0; i < xlabels.size(); ++i )
00160 {
00161 lx.push_back(Gaudi::Utils::Histos::BinLabel( i , xlabels[i] ) );
00162 }
00163 BinLabels ly;
00164 ly.reserve(ylabels.size());
00165 for ( unsigned int i = 0; i < ylabels.size(); ++i )
00166 {
00167 ly.push_back(Gaudi::Utils::Histos::BinLabel( i , ylabels[i] ) );
00168 }
00169 return ( setBinLabels_( h2d->GetXaxis(), lx ) &&
00170 setBinLabels_( h2d->GetYaxis(), ly ) );
00171 }
00172
00173 bool setBinLabels( AIDA::IProfile2D* hist,
00174 const BinLabels& xlabels,
00175 const BinLabels& ylabels )
00176 {
00177 TProfile2D * h2d = Gaudi::Utils::Aida2ROOT::aida2root( hist );
00178 return ( h2d &&
00179 setBinLabels_( h2d->GetXaxis(), xlabels ) &&
00180 setBinLabels_( h2d->GetYaxis(), ylabels ) );
00181 }
00182
00183
00184
00185 bool setAxisLabels( AIDA::IHistogram1D* hist,
00186 const std::string & xAxis,
00187 const std::string & yAxis )
00188 {
00189 return setAxisLabels_<TH1D>( hist, xAxis, yAxis );
00190 }
00191
00192 bool setAxisLabels( AIDA::IProfile1D* hist,
00193 const std::string & xAxis,
00194 const std::string & yAxis )
00195 {
00196 return setAxisLabels_<TProfile>( hist, xAxis, yAxis );
00197 }
00198
00199 bool setAxisLabels( AIDA::IHistogram2D* hist,
00200 const std::string & xAxis,
00201 const std::string & yAxis )
00202 {
00203 return setAxisLabels_<TH2D>( hist, xAxis, yAxis );
00204 }
00205
00206 bool setAxisLabels( AIDA::IProfile2D* hist,
00207 const std::string & xAxis,
00208 const std::string & yAxis )
00209 {
00210 return setAxisLabels_<TProfile2D>( hist, xAxis, yAxis );
00211 }
00212
00213
00214
00215 }
00216 }
00217 }