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