27#include <TProfile2D.h>
33 template <
typename R,
typename A>
34 bool setAxisLabels_( A* aida,
const std::string& xAxis,
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() );
46 if ( !axis )
return false;
47 const unsigned nbins = axis->GetNbins();
48 for (
const auto& i : labels ) {
49 if ( 1 + i.first <= 0 || 1 + i.first > nbins )
return false;
51 axis->SetBinLabel( 1 + i.first, i.second.c_str() );
58 template <
typename R,
typename A>
60 if ( !aida )
return false;
62 if ( !root )
return false;
63 return setBinLabels_(
root->GetXaxis(), labels );
66 template <
typename Histogram>
69 l.reserve( labels.size() );
70 for (
unsigned i = 0; i < labels.size(); ++i )
l.emplace_back( i, labels[i] );
84 return setBinLabels_<TH1D>( hist, labels );
88 return setBinLabels_<TProfile>( hist, labels );
91 bool setBinLabels( AIDA::IHistogram1D* hist,
const Labels& labels ) {
return setBinLabels_( hist, labels ); }
93 bool setBinLabels( AIDA::IProfile1D* hist,
const Labels& labels ) {
return setBinLabels_( hist, labels ); }
96 if ( !hist )
return false;
98 if ( !h2d )
return false;
100 lx.reserve( xlabels.size() );
101 for (
unsigned int i = 0; i < xlabels.size(); ++i ) { lx.emplace_back( i, xlabels[i] ); }
103 ly.reserve( ylabels.size() );
104 for (
unsigned int i = 0; i < ylabels.size(); ++i ) { ly.emplace_back( i, ylabels[i] ); }
105 return ( setBinLabels_( h2d->GetXaxis(), lx ) && setBinLabels_( h2d->GetYaxis(), ly ) );
110 return ( h2d && setBinLabels_( h2d->GetXaxis(), xlabels ) && setBinLabels_( h2d->GetYaxis(), ylabels ) );
114 if ( !hist )
return false;
116 if ( !h2d )
return false;
118 lx.reserve( xlabels.size() );
119 for (
unsigned int i = 0; i < xlabels.size(); ++i ) { lx.emplace_back( i, xlabels[i] ); }
121 ly.reserve( ylabels.size() );
122 for (
unsigned int i = 0; i < ylabels.size(); ++i ) { ly.emplace_back( i, ylabels[i] ); }
123 return ( setBinLabels_( h2d->GetXaxis(), lx ) && setBinLabels_( h2d->GetYaxis(), ly ) );
128 return ( h2d && setBinLabels_( h2d->GetXaxis(), xlabels ) && setBinLabels_( h2d->GetYaxis(), ylabels ) );
133 bool setAxisLabels( AIDA::IHistogram1D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
134 return setAxisLabels_<TH1D>( hist, xAxis, yAxis );
137 bool setAxisLabels( AIDA::IProfile1D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
138 return setAxisLabels_<TProfile>( hist, xAxis, yAxis );
141 bool setAxisLabels( AIDA::IHistogram2D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
142 return setAxisLabels_<TH2D>( hist, xAxis, yAxis );
145 bool setAxisLabels( AIDA::IProfile2D* hist,
const std::string& xAxis,
const std::string& yAxis ) {
146 return setAxisLabels_<TProfile2D>( hist, xAxis, yAxis );
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Collection of useful utilities for manipulations with AIDA hisgograms.
std::vector< BinLabel > BinLabels
Typedef for a list of bin numbers and their associated label.
std::vector< std::string > Labels
Typedef for a list of labels.
GAUDI_API bool setBinLabels(AIDA::IHistogram1D *hist, const Labels &labels)
Set the Bin labels for a given 1D histogram.
GAUDI_API bool setAxisLabels(AIDA::IHistogram1D *hist, const std::string &xAxis, const std::string &yAxis)
Set the axis labels for the given 1D histogram.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...