1 #ifndef GAUDISVC_GENERIC3D_H
2 #define GAUDISVC_GENERIC3D_H 1
10 #include "AIDA/IHistogram3D.h"
28 template<
typename INTERFACE,
typename IMPLEMENTATION>
39 virtual void adoptRepresentation(TObject* rep);
44 virtual std::string
title()
const {
return m_annotation.value(
"Title");}
46 virtual bool setTitle(
const std::string & title);
48 virtual std::string
name()
const {
return m_annotation.value(
"Name"); }
50 bool setName(
const std::string& newName);
52 virtual AIDA::IAnnotation &
annotation() {
return m_annotation; }
54 virtual const AIDA::IAnnotation &
annotation()
const {
return m_annotation; }
57 virtual int entries()
const;
59 virtual int allEntries()
const;
61 virtual double sumBinHeights()
const;
63 virtual double sumAllBinHeights()
const;
67 virtual double minBinHeight()
const;
69 virtual double maxBinHeight()
const;
71 int rIndexX(
int index)
const {
return m_xAxis.rIndex(index);}
72 int rIndexY(
int index)
const {
return m_yAxis.rIndex(index);}
73 int rIndexZ(
int index)
const {
return m_zAxis.rIndex(index);}
76 double binMeanX(
int indexX,
int ,
int )
const
77 {
return (m_rep->GetXaxis())->GetBinCenter( rIndexX(indexX) ); }
79 double binMeanY(
int,
int indexY,
int )
const
80 {
return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexY) ); }
82 double binMeanZ(
int ,
int ,
int indexZ)
const
83 {
return (m_rep->GetYaxis())->GetBinCenter( rIndexY(indexZ) ); }
86 if (binHeight(indexX, indexY, indexZ)<=0)
return 0;
87 double xx = binHeight(indexX, indexY, indexZ)/binError(indexX, indexY, indexZ);
88 return int(xx*xx+0.5);
93 for (
int i = -2;
i < yAxis().bins(); ++
i)
94 for (
int j = -2; j < zAxis().bins(); ++j)
95 n += binEntries(index,
i,j);
102 for (
int i = -2;
i < xAxis().bins(); ++
i)
103 for (
int j = -2; j < zAxis().bins(); ++j)
104 n += binEntries(
i,index,j);
111 for (
int i = -2;
i < xAxis().bins(); ++
i)
112 for (
int j = -2; j < yAxis().bins(); ++j)
113 n += binEntries(
i,j,index);
118 double binHeight (
int indexX,
int indexY,
int indexZ )
const
119 {
return m_rep->GetBinContent ( rIndexX(indexX), rIndexY(indexY), rIndexZ(indexZ) ); }
124 for (
int i = -2;
i < yAxis().bins(); ++
i)
125 for (
int j = -2; j < zAxis().bins(); ++j)
126 s += binHeight(index,
i,j);
132 for (
int i = -2;
i < xAxis().bins(); ++
i)
133 for (
int j = -2; j < zAxis().bins(); ++j)
134 s += binHeight(
i,index,j);
140 for (
int i = -2;
i < xAxis().bins(); ++
i)
141 for (
int j = -2; j < yAxis().bins(); ++j)
142 s += binHeight(
i,j,index);
146 virtual double binError (
int indexX,
int indexY,
int indexZ )
const
147 {
return m_rep->GetBinError ( rIndexX(indexX), rIndexY(indexY ), rIndexZ(indexZ ) ); }
149 virtual double meanX ( )
const {
return m_rep->GetMean ( 1); }
152 virtual double meanY ( )
const {
return m_rep->GetMean ( 2 ); }
154 virtual double meanZ ( )
const {
return m_rep->GetMean ( 3 ); }
156 virtual double rmsX ( )
const {
return m_rep->GetRMS( 1 ); }
158 virtual double rmsY ( )
const {
return m_rep->GetRMS( 2 ); }
160 virtual double rmsZ ( )
const {
return m_rep->GetRMS( 3 ); }
162 virtual const AIDA::IAxis &
xAxis ( )
const {
return m_xAxis; }
164 virtual const AIDA::IAxis &
yAxis ( )
const {
return m_yAxis; }
166 virtual const AIDA::IAxis &
zAxis ( )
const {
return m_zAxis; }
168 virtual int coordToIndexX (
double coord )
const {
return xAxis().coordToIndex(coord);}
170 virtual int coordToIndexY (
double coord )
const {
return yAxis().coordToIndex(coord);}
172 virtual int coordToIndexZ (
double coord )
const {
return zAxis().coordToIndex(coord);}
175 virtual double equivalentBinEntries ( )
const;
177 virtual bool scale(
double scaleFactor );
179 virtual bool add (
const INTERFACE & hist ) {
180 const Base* p =
dynamic_cast<const Base*
>(&hist);
182 m_rep->Add(p->
m_rep);
185 throw std::runtime_error(
"Cannot add profile histograms of different implementations.");
191 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
192 binEntries(AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
193 binEntries(AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
194 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
195 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN) +
196 binEntries(AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::UNDERFLOW_BIN) +
197 binEntries(AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN,AIDA::IAxis::OVERFLOW_BIN);
200 virtual std::ostream& print( std::ostream&
s )
const;
202 virtual std::ostream& write( std::ostream&
s )
const;
204 virtual int write(
const char* file_name )
const;
220 template <
class INTERFACE,
class IMPLEMENTATION>
222 m_rep->SetTitle(title.c_str());
223 if ( !annotation().addItem(
"Title", title ) )
224 m_annotation.setValue(
"Title" , title );
225 if ( !annotation().addItem(
"title", title ) )
226 annotation().setValue(
"title", title );
230 template <
class INTERFACE,
class IMPLEMENTATION>
232 m_rep->SetName(newName.c_str());
233 m_annotation.setValue(
"Name", newName );
236 template <
class INTERFACE,
class IMPLEMENTATION>
238 return (
int)m_rep->GetEntries();
241 template <
class INTERFACE,
class IMPLEMENTATION>
243 return int(m_rep->GetEntries());
246 template <
class INTERFACE,
class IMPLEMENTATION>
248 return m_rep->GetMinimum();
251 template <
class INTERFACE,
class IMPLEMENTATION>
253 return m_rep->GetMaximum();
256 template <
class INTERFACE,
class IMPLEMENTATION>
258 return m_rep->GetSumOfWeights();
261 template <
class INTERFACE,
class IMPLEMENTATION>
263 return m_rep->GetSum();
266 template <
class INTERFACE,
class IMPLEMENTATION>
268 if (sumBinHeights() <= 0)
return 0;
270 m_rep->GetStats(stats);
271 return stats[0]*stats[0]/stats[1];
274 template <
class INTERFACE,
class IMPLEMENTATION>
276 m_rep->Scale ( scaleFactor );
280 template <
class INTERFACE,
class IMPLEMENTATION>
290 template <
class INTERFACE,
class IMPLEMENTATION>
293 s <<
"\n3D Histogram Table: " << std::endl;
294 s <<
"BinX, BinY, BinZ, Height, Error " << std::endl;
295 for (
int i = 0;
i < xAxis().bins(); ++
i )
296 for (
int j = 0; j < yAxis().bins(); ++j )
297 for (
int k = 0; k < zAxis().bins(); ++k )
298 s << binMeanX(
i, j, k ) <<
", "
299 << binMeanY(
i, j, k ) <<
", "
300 << binMeanZ(
i, j, k ) <<
", "
301 << binHeight(
i, j, k ) <<
", "
302 << binError (
i, j, k ) << std::endl;
308 template <
class INTERFACE,
class IMPLEMENTATION>
311 TFile *f = TFile::Open(file_name,
"RECREATE");
312 Int_t nbytes = m_rep->Write();
317 #endif // GAUDIPI_GENERIC3D_H