1 #ifndef GAUDISVC_GENERIC3D_H 2 #define GAUDISVC_GENERIC3D_H 1 4 #include "AIDA/IHistogram3D.h" 15 #pragma clang diagnostic push 16 #pragma clang diagnostic ignored "-Winconsistent-missing-override" 17 #elif defined( __GNUC__ ) && __GNUC__ >= 5 18 #pragma GCC diagnostic push 19 #pragma GCC diagnostic ignored "-Wsuggest-override" 35 template <
typename INTERFACE,
typename IMPLEMENTATION>
51 void adoptRepresentation( TObject* rep )
override;
64 AIDA::IAnnotation&
annotation()
override {
return m_annotation; }
66 const AIDA::IAnnotation&
annotation()
const override {
return m_annotation; }
69 int entries()
const override;
71 int allEntries()
const override;
73 double sumBinHeights()
const override;
75 double sumAllBinHeights()
const override;
79 double minBinHeight()
const override;
81 double maxBinHeight()
const override;
83 int rIndexX(
int index )
const {
return m_xAxis.rIndex( index ); }
84 int rIndexY(
int index )
const {
return m_yAxis.rIndex( index ); }
85 int rIndexZ(
int index )
const {
return m_zAxis.rIndex( index ); }
88 double binMeanX(
int indexX,
int,
int )
const override 90 return m_rep->GetXaxis()->GetBinCenter( rIndexX( indexX ) );
93 double binMeanY(
int,
int indexY,
int )
const override 95 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexY ) );
98 double binMeanZ(
int,
int,
int indexZ )
const override 100 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexZ ) );
103 int binEntries(
int indexX,
int indexY,
int indexZ )
const override 105 if ( binHeight( indexX, indexY, indexZ ) <= 0 )
return 0;
106 double xx = binHeight( indexX, indexY, indexZ ) / binError( indexX, indexY, indexZ );
107 return int( xx * xx + 0.5 );
113 for (
int i = -2; i < yAxis().bins(); ++i )
114 for (
int j = -2; j < zAxis().bins(); ++j ) n += binEntries( index, i, j );
121 for (
int i = -2; i < xAxis().bins(); ++i )
122 for (
int j = -2; j < zAxis().bins(); ++j ) n += binEntries( i, index, j );
130 for (
int i = -2; i < xAxis().bins(); ++i )
131 for (
int j = -2; j < yAxis().bins(); ++j ) n += binEntries( i, j, index );
136 double binHeight(
int indexX,
int indexY,
int indexZ )
const 138 return m_rep->GetBinContent( rIndexX( indexX ), rIndexY( indexY ), rIndexZ( indexZ ) );
145 for (
int i = -2; i < yAxis().bins(); ++i )
146 for (
int j = -2; j < zAxis().bins(); ++j ) s += binHeight( index, i, j );
153 for (
int i = -2; i < xAxis().bins(); ++i )
154 for (
int j = -2; j < zAxis().bins(); ++j ) s += binHeight( i, index, j );
161 for (
int i = -2; i < xAxis().bins(); ++i )
162 for (
int j = -2; j < yAxis().bins(); ++j ) s += binHeight( i, j, index );
166 double binError(
int indexX,
int indexY,
int indexZ )
const override 168 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ), rIndexZ( indexZ ) );
171 double meanX()
const override {
return m_rep->GetMean( 1 ); }
174 double meanY()
const override {
return m_rep->GetMean( 2 ); }
176 double meanZ()
const override {
return m_rep->GetMean( 3 ); }
178 double rmsX()
const override {
return m_rep->GetRMS( 1 ); }
180 double rmsY()
const override {
return m_rep->GetRMS( 2 ); }
182 double rmsZ()
const override {
return m_rep->GetRMS( 3 ); }
184 const AIDA::IAxis&
xAxis()
const override {
return m_xAxis; }
186 const AIDA::IAxis&
yAxis()
const override {
return m_yAxis; }
188 const AIDA::IAxis&
zAxis()
const override {
return m_zAxis; }
190 int coordToIndexX(
double coord )
const override {
return xAxis().coordToIndex( coord ); }
192 int coordToIndexY(
double coord )
const override {
return yAxis().coordToIndex( coord ); }
194 int coordToIndexZ(
double coord )
const override {
return zAxis().coordToIndex( coord ); }
197 double equivalentBinEntries()
const override;
200 bool scale(
double scaleFactor )
override;
202 bool add(
const INTERFACE& hist )
override 204 const Base* p =
dynamic_cast<const Base*
>( &hist );
205 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations." );
213 return binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
214 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
215 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
216 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
217 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
218 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
219 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN );
226 int write(
const char* file_name )
const override;
239 int m_sumEntries = 0;
242 template <
class INTERFACE,
class IMPLEMENTATION>
245 m_rep->SetTitle( title.
c_str() );
246 if ( !annotation().addItem(
"Title", title ) ) m_annotation.setValue(
"Title", title );
247 if ( !annotation().addItem(
"title", title ) ) annotation().setValue(
"title", title );
251 template <
class INTERFACE,
class IMPLEMENTATION>
254 m_rep->SetName( newName.
c_str() );
255 m_annotation.setValue(
"Name", newName );
258 template <
class INTERFACE,
class IMPLEMENTATION>
261 return m_rep->GetEntries();
264 template <
class INTERFACE,
class IMPLEMENTATION>
267 return int( m_rep->GetEntries() );
270 template <
class INTERFACE,
class IMPLEMENTATION>
273 return m_rep->GetMinimum();
276 template <
class INTERFACE,
class IMPLEMENTATION>
279 return m_rep->GetMaximum();
282 template <
class INTERFACE,
class IMPLEMENTATION>
285 return m_rep->GetSumOfWeights();
288 template <
class INTERFACE,
class IMPLEMENTATION>
291 return m_rep->GetSum();
294 template <
class INTERFACE,
class IMPLEMENTATION>
297 if ( sumBinHeights() <= 0 )
return 0;
299 m_rep->GetStats( stats );
300 return stats[0] * stats[0] / stats[1];
303 template <
class INTERFACE,
class IMPLEMENTATION>
306 m_rep->Scale( scaleFactor );
310 template <
class INTERFACE,
class IMPLEMENTATION>
314 m_rep->Print(
"all" );
319 template <
class INTERFACE,
class IMPLEMENTATION>
322 s <<
"\n3D Histogram Table: " <<
std::endl;
323 s <<
"BinX, BinY, BinZ, Height, Error " <<
std::endl;
324 for (
int i = 0; i < xAxis().bins(); ++i )
325 for (
int j = 0; j < yAxis().bins(); ++j )
326 for (
int k = 0; k < zAxis().bins(); ++k )
327 s << binMeanX( i, j, k ) <<
", " << binMeanY( i, j, k ) <<
", " << binMeanZ( i, j, k ) <<
", " 328 << binHeight( i, j, k ) <<
", " << binError( i, j, k ) <<
std::endl;
334 template <
class INTERFACE,
class IMPLEMENTATION>
337 TFile* f = TFile::Open( file_name,
"RECREATE" );
338 Int_t nbytes = m_rep->Write();
345 #pragma clang diagnostic pop 346 #elif defined( __GNUC__ ) && __GNUC__ >= 5 347 #pragma GCC diagnostic pop 350 #endif // GAUDIPI_GENERIC3D_H int rIndexZ(int index) const
int rIndexX(int index) const
AIDA::IAnnotation & annotation() override
Access annotation object.
double meanZ() const override
The mean of the IHistogram3D along the z axis.
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
int binEntriesY(int index) const override
Sum of all the entries of the bins along a given y bin.
double maxBinHeight() const override
Get the maximum height of the in-range bins.
int entries() const override
Get the number or all the entries.
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
double binMeanY(int, int indexY, int) const override
The weighted mean along the y axis of a given bin.
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
std::string name() const
object name
bool add(const INTERFACE &hist) override
Add to this Histogram3D the contents of another IHistogram3D.
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
Generic3D< INTERFACE, IMPLEMENTATION > Base
int binEntries(int indexX, int indexY, int indexZ) const override
Number of entries in the corresponding bin (ie the number of times fill was calle d for this bin)...
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
double binHeightY(int index) const override
Sum of all the heights of the bins along a given y bin.
double binHeightZ(int index) const override
Sum of all the heights of the bins along a given z bin.
Implementation of the AIDA IAnnotation interface class.
bool scale(double scaleFactor) override
Scale the weights and the errors of all the IHistogram's bins (in-range and out-of-range ones) by a g...
bool setName(const std::string &newName)
Sets the name of the object.
bool setTitle(const std::string &title) override
Set the title of the object.
int rIndexY(int index) const
TObject * representation() const override
ROOT object implementation.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
double binHeight(int indexX, int indexY, int indexZ) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
std::string title() const override
Get the title of the object.
double minBinHeight() const override
Get the minimum height of the in-range bins.
int binEntriesX(int index) const override
Sum of all the entries of the bins along a given x bin.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
AIDA::Annotation m_annotation
Object annotations.
int coordToIndexY(double coord) const override
Get the bin number corresponding to a given coordinate along the y axis.
const AIDA::IAxis & xAxis() const override
Get the x axis of the IHistogram3D.
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
double binMeanZ(int, int, int indexZ) const override
The weighted mean along the z axis of a given bin.
int coordToIndexZ(double coord) const override
Get the bin number corresponding to a given coordinate along the z axis.
int dimension() const override
Get the Histogram's dimension.
double meanY() const override
The mean of the IHistogram3D along the y axis.
double binMeanX(int indexX, int, int) const override
The weighted mean along the x axis of a given bin.
int coordToIndexX(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
int extraEntries() const override
double equivalentBinEntries() const override
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
double binHeightX(int index) const override
Sum of all the heights of the bins along a given x bin.
double binError(int indexX, int indexY, int indexZ) const override
The error of a given bin.
Generic3D(IMPLEMENTATION *p)
constructor
Helper functions to set/get the application return code.
An IAxis represents a binned histogram axis.
double meanX() const override
The mean of the IHistogram3D along the x axis.
int binEntriesZ(int index) const override
Sum of all the entries of the bins along a given z bin.
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.