13 #include "AIDA/IHistogram1D.h"
14 #include "AIDA/IHistogram2D.h"
18 #include "GaudiKernel/ToStream.h"
22 #include "GaudiUtils/Aida2ROOT.h"
23 #include "GaudiUtils/Histo2String.h"
24 #include "GaudiUtils/HistoXML.h"
35 template <
class HISTO>
36 std::ostream& _toStream_1D_
37 (
const HISTO& histo ,
38 std::ostream& stream ,
45 stream <<
"'name' : " ;
47 stream <<
"'title' : " ;
50 const TAxis* axis = histo.GetXaxis() ;
51 const unsigned int nBins = axis->GetNbins() ;
53 stream << std::endl <<
"'X' : { " ;
54 if ( axis->IsVariableBinSize() )
56 const TArrayD* xbins = axis->GetXbins() ;
57 const unsigned int xsize = xbins->GetSize() ;
58 std::vector<double> edges ;
59 for (
unsigned int iBin = 0 ; iBin < xsize ; ++iBin )
60 { edges.push_back ( xbins->At( iBin ) ) ; }
61 stream <<
"'edges' : " ;
66 stream <<
"'nbins' : " ;
68 stream <<
"'low' : " ;
70 stream <<
"'high' : " ;
74 std::vector<std::pair<double,double> > bins ;
75 for (
unsigned int iBin = 0 ; iBin <= nBins + 1 ; ++iBin )
77 bins.emplace_back( histo.GetBinContent( iBin ) ,
78 histo.GetBinError ( iBin ) ) ;
80 stream <<
"'bins' : " ;
88 template <
class HISTO>
89 std::ostream& _toStream_2D_
90 (
const HISTO& histo ,
91 std::ostream& stream ,
98 stream <<
"'name' : " ;
100 stream <<
"'title' : " ;
103 const TAxis* xaxis = histo.GetXaxis() ;
104 const int xBins = xaxis->GetNbins() ;
106 stream << std::endl <<
"'X' : { " ;
107 if ( xaxis->IsVariableBinSize() )
109 const TArrayD* xbins = xaxis->GetXbins() ;
110 const unsigned int xsize = xbins->GetSize() ;
111 std::vector<double> edges ;
112 for (
unsigned int iBin = 0 ; iBin < xsize ; ++iBin )
113 { edges.push_back ( xbins->At( iBin ) ) ; }
115 stream <<
"'edges' : " ;
120 stream <<
"'nbins' : " ;
122 stream <<
"'low' : " ;
124 stream <<
"'high' : " ;
128 const TAxis* yaxis = histo.GetYaxis() ;
129 const int yBins = yaxis->GetNbins() ;
131 stream << std::endl <<
"'Y' : { " ;
132 if ( yaxis->IsVariableBinSize() )
134 const TArrayD* ybins = yaxis->GetXbins() ;
135 const unsigned int ysize = ybins->GetSize() ;
136 std::vector<double> edges ;
137 for (
unsigned int iBin = 0 ; iBin < ysize ; ++iBin )
138 { edges.push_back ( ybins->At( iBin ) ) ; }
140 stream <<
" 'edges' : " ;
145 stream <<
"'nbins' : " ;
147 stream <<
"'low' : " ;
149 stream <<
"'high' : " ;
154 stream <<
"'bins' : " << std::endl <<
" [ " ;
155 for (
int jBin = yBins + 1 ; jBin >= 0 ; --jBin )
157 if ( yBins + 1 != jBin ) { stream << std::endl ; }
158 for (
int iBin = 0 ; iBin <= xBins + 1 ; ++iBin )
162 ( histo.GetBinContent( iBin , jBin ) ,
163 histo.GetBinError ( iBin , jBin ) ) , stream ) ;
165 if ( xBins + 1 != iBin || 0 != jBin ) { stream <<
" , " ; }
184 (
const TH1D& histo ,
185 std::ostream& stream ,
186 const bool asXML ) {
return _toStream_1D_ ( histo , stream , asXML ) ; }
195 (
const TH1F& histo ,
196 std::ostream& stream ,
197 const bool asXML ) {
return _toStream_1D_ ( histo , stream , asXML ) ; }
206 (
const TH2D& histo ,
207 std::ostream& stream ,
208 const bool asXML ) {
return _toStream_2D_ ( histo , stream , asXML ) ; }
217 (
const TH2F& histo ,
218 std::ostream& stream ,
219 const bool asXML ) {
return _toStream_2D_ ( histo , stream , asXML ) ; }
228 (
const AIDA::IHistogram1D& histo ,
229 std::ostream& stream ,
243 (
const AIDA::IHistogram2D& histo ,
244 std::ostream& stream ,
261 (
const TH1D& histo ,
264 std::ostringstream o ;
278 (
const TH1F& histo ,
281 std::ostringstream o ;
295 (
const TH2D& histo ,
298 std::ostringstream o ;
312 (
const TH2F& histo ,
315 std::ostringstream o ;
329 (
const AIDA::IHistogram1D& histo ,
332 std::ostringstream o ;
346 (
const AIDA::IHistogram2D& histo ,
349 std::ostringstream o ;
364 return histo ?
toString ( *histo ) :
"{}";
377 return histo ?
toString ( *histo ) :
"{}";
390 return histo ?
toString ( *histo ) :
"{}";
403 return histo ?
toString ( *histo ) :
"{}";
416 return histo ?
toString ( *histo ) :
"{}";
429 return histo ?
toString ( *histo ) :
"{}";
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
GAUDI_API std::ostream & toXml(const TH1D &histo, std::ostream &stream)
stream the ROOT histogram into output stream as XML