10 #pragma warning(disable:4996)
14 #include "GaudiUtils/HistoLabels.h"
15 #include "GaudiUtils/Aida2ROOT.h"
23 #include "TProfile2D.h"
30 template <
typename R,
typename A>
31 bool setAxisLabels_( A* aida,
32 const std::string& xAxis,
33 const std::string& yAxis )
35 if (!aida)
return false;
37 if (!root)
return false;
38 root->SetXTitle(xAxis.c_str());
39 root->SetYTitle(yAxis.c_str());
45 bool setBinLabels_( TAxis* axis,
48 if (!axis)
return false;
49 const unsigned nbins = axis->GetNbins();
50 for (
const auto&
i : labels )
52 if ( 1+
i.first <= 0 || 1+
i.first > nbins )
return false;
54 axis -> SetBinLabel( 1 +
i.first,
i.second.c_str() );
61 template <
typename R,
typename A>
62 bool setBinLabels_( A* aida,
65 if (!aida)
return false;
67 if (!root)
return false;
68 return setBinLabels_( root->GetXaxis(), labels );
71 template <
typename Histogram>
72 bool setBinLabels_( Histogram* hist,
76 l.reserve(labels.size());
77 for (
unsigned i = 0;
i<labels.size(); ++
i ) l.emplace_back(
i,labels[
i] );
97 return setBinLabels_<TH1D>(hist,labels);
103 return setBinLabels_<TProfile>(hist,labels);
109 return setBinLabels_(hist,labels);
115 return setBinLabels_(hist,labels);
122 if (!hist)
return false;
124 if (!h2d)
return false;
126 lx.reserve(xlabels.size());
127 for (
unsigned int i = 0;
i < xlabels.size(); ++
i )
129 lx.emplace_back(
i , xlabels[
i] );
132 ly.reserve(ylabels.size());
133 for (
unsigned int i = 0;
i < ylabels.size(); ++
i )
135 ly.emplace_back(
i , ylabels[
i] );
137 return ( setBinLabels_( h2d->GetXaxis(), lx ) &&
138 setBinLabels_( h2d->GetYaxis(), ly ) );
147 setBinLabels_( h2d->GetXaxis(), xlabels ) &&
148 setBinLabels_( h2d->GetYaxis(), ylabels ) );
155 if (!hist)
return false;
157 if (!h2d)
return false;
159 lx.reserve(xlabels.size());
160 for (
unsigned int i = 0;
i < xlabels.size(); ++
i )
162 lx.emplace_back(
i , xlabels[
i] );
165 ly.reserve(ylabels.size());
166 for (
unsigned int i = 0;
i < ylabels.size(); ++
i )
168 ly.emplace_back(
i , ylabels[
i] );
170 return ( setBinLabels_( h2d->GetXaxis(), lx ) &&
171 setBinLabels_( h2d->GetYaxis(), ly ) );
180 setBinLabels_( h2d->GetXaxis(), xlabels ) &&
181 setBinLabels_( h2d->GetYaxis(), ylabels ) );
187 const std::string & xAxis,
188 const std::string & yAxis )
190 return setAxisLabels_<TH1D>( hist, xAxis, yAxis );
194 const std::string & xAxis,
195 const std::string & yAxis )
197 return setAxisLabels_<TProfile>( hist, xAxis, yAxis );
201 const std::string & xAxis,
202 const std::string & yAxis )
204 return setAxisLabels_<TH2D>( hist, xAxis, yAxis );
208 const std::string & xAxis,
209 const std::string & yAxis )
211 return setAxisLabels_<TProfile2D>( hist, xAxis, yAxis );
helper namespace to collect useful definitions, types, constants and functions, related to manipulati...
GAUDI_API bool setAxisLabels(AIDA::IHistogram1D *hist, const std::string &xAxis, const std::string &yAxis)
Set the axis labels for the given 1D histogram.
std::vector< BinLabel > BinLabels
Typedef for a list of bin numbers and their associated label.
GAUDI_API bool setBinLabels(AIDA::IHistogram1D *hist, const Labels &labels)
Set the Bin labels for a given 1D histogram.
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Helper functions to set/get the application return code.
std::vector< std::string > Labels
Typedef for a list of labels.