20 # pragma warning( disable : 4996 )
33 #include <TProfile2D.h>
39 template <
typename R,
typename A>
40 bool setAxisLabels_( A* aida,
const std::string& xAxis,
const std::string& yAxis ) {
41 if ( !aida )
return false;
43 if ( !
root )
return false;
44 root->SetXTitle( xAxis.c_str() );
45 root->SetYTitle( yAxis.c_str() );
52 if ( !axis )
return false;
53 const unsigned nbins = axis->GetNbins();
54 for (
const auto& i : labels ) {
55 if ( 1 + i.first <= 0 || 1 + i.first > nbins )
return false;
57 axis->SetBinLabel( 1 + i.first, i.second.c_str() );
64 template <
typename R,
typename A>
66 if ( !aida )
return false;
68 if ( !
root )
return false;
69 return setBinLabels_(
root->GetXaxis(), labels );
72 template <
typename Histogram>
75 l.reserve( labels.size() );
76 for (
unsigned i = 0; i < labels.size(); ++i )
l.emplace_back( i, labels[i] );
90 return setBinLabels_<TH1D>( hist, labels );
94 return setBinLabels_<TProfile>( hist, labels );
97 bool setBinLabels( AIDA::IHistogram1D* hist,
const Labels& labels ) {
return setBinLabels_( hist, labels ); }
99 bool setBinLabels( AIDA::IProfile1D* hist,
const Labels& labels ) {
return setBinLabels_( hist, labels ); }
102 if ( !hist )
return false;
104 if ( !h2d )
return false;
106 lx.reserve( xlabels.size() );
107 for (
unsigned int i = 0; i < xlabels.size(); ++i ) { lx.emplace_back( i, xlabels[i] ); }
109 ly.reserve( ylabels.size() );
110 for (
unsigned int i = 0; i < ylabels.size(); ++i ) { ly.emplace_back( i, ylabels[i] ); }
111 return ( setBinLabels_( h2d->GetXaxis(), lx ) && setBinLabels_( h2d->GetYaxis(), ly ) );
116 return ( h2d && setBinLabels_( h2d->GetXaxis(), xlabels ) && setBinLabels_( h2d->GetYaxis(), ylabels ) );
120 if ( !hist )
return false;
122 if ( !h2d )
return false;
124 lx.reserve( xlabels.size() );
125 for (
unsigned int i = 0; i < xlabels.size(); ++i ) { lx.emplace_back( i, xlabels[i] ); }
127 ly.reserve( ylabels.size() );
128 for (
unsigned int i = 0; i < ylabels.size(); ++i ) { ly.emplace_back( i, ylabels[i] ); }
129 return ( setBinLabels_( h2d->GetXaxis(), lx ) && setBinLabels_( h2d->GetYaxis(), ly ) );
134 return ( h2d && setBinLabels_( h2d->GetXaxis(), xlabels ) && setBinLabels_( h2d->GetYaxis(), ylabels ) );
139 bool setAxisLabels( AIDA::IHistogram1D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
140 return setAxisLabels_<TH1D>( hist, xAxis, yAxis );
143 bool setAxisLabels( AIDA::IProfile1D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
144 return setAxisLabels_<TProfile>( hist, xAxis, yAxis );
147 bool setAxisLabels( AIDA::IHistogram2D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
148 return setAxisLabels_<TH2D>( hist, xAxis, yAxis );
151 bool setAxisLabels( AIDA::IProfile2D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
152 return setAxisLabels_<TProfile2D>( hist, xAxis, yAxis );