11 #ifndef GAUDISVC_GENERIC3D_H 12 #define GAUDISVC_GENERIC3D_H 1 14 #include "AIDA/IHistogram3D.h" 25 # pragma clang diagnostic push 26 # pragma clang diagnostic ignored "-Winconsistent-missing-override" 27 #elif defined( __GNUC__ ) && __GNUC__ >= 5 28 # pragma GCC diagnostic push 29 # pragma GCC diagnostic ignored "-Wsuggest-override" 44 template <
typename INTERFACE,
typename IMPLEMENTATION>
59 void adoptRepresentation( TObject* rep )
override;
72 AIDA::IAnnotation&
annotation()
override {
return m_annotation; }
74 const AIDA::IAnnotation&
annotation()
const override {
return m_annotation; }
77 int entries()
const override;
79 int allEntries()
const override;
81 double sumBinHeights()
const override;
83 double sumAllBinHeights()
const override;
87 double minBinHeight()
const override;
89 double maxBinHeight()
const override;
91 int rIndexX(
int index )
const {
return m_xAxis.rIndex( index ); }
92 int rIndexY(
int index )
const {
return m_yAxis.rIndex( index ); }
93 int rIndexZ(
int index )
const {
return m_zAxis.rIndex( index ); }
96 double binMeanX(
int indexX,
int,
int )
const override {
97 return m_rep->GetXaxis()->GetBinCenter( rIndexX( indexX ) );
100 double binMeanY(
int,
int indexY,
int )
const override {
101 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexY ) );
104 double binMeanZ(
int,
int,
int indexZ )
const override {
105 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexZ ) );
108 int binEntries(
int indexX,
int indexY,
int indexZ )
const override {
109 if ( binHeight( indexX, indexY, indexZ ) <= 0 )
return 0;
110 double xx = binHeight( indexX, indexY, indexZ ) / binError( indexX, indexY, indexZ );
111 return int( xx * xx + 0.5 );
116 for (
int i = -2; i < yAxis().bins(); ++i )
117 for (
int j = -2; j < zAxis().bins(); ++j )
n += binEntries( index, i, j );
123 for (
int i = -2; i < xAxis().bins(); ++i )
124 for (
int j = -2; j < zAxis().bins(); ++j )
n += binEntries( i, index, j );
131 for (
int i = -2; i < xAxis().bins(); ++i )
132 for (
int j = -2; j < yAxis().bins(); ++j )
n += binEntries( i, j, index );
137 double binHeight(
int indexX,
int indexY,
int indexZ )
const {
138 return m_rep->GetBinContent( rIndexX( indexX ), rIndexY( indexY ), rIndexZ( indexZ ) );
144 for (
int i = -2; i < yAxis().bins(); ++i )
145 for (
int j = -2; j < zAxis().bins(); ++j )
s += binHeight( index, i, j );
151 for (
int i = -2; i < xAxis().bins(); ++i )
152 for (
int j = -2; j < zAxis().bins(); ++j )
s += binHeight( i, index, j );
158 for (
int i = -2; i < xAxis().bins(); ++i )
159 for (
int j = -2; j < yAxis().bins(); ++j )
s += binHeight( i, j, index );
163 double binError(
int indexX,
int indexY,
int indexZ )
const override {
164 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ), rIndexZ( indexZ ) );
167 double meanX()
const override {
return m_rep->GetMean( 1 ); }
170 double meanY()
const override {
return m_rep->GetMean( 2 ); }
172 double meanZ()
const override {
return m_rep->GetMean( 3 ); }
174 double rmsX()
const override {
return m_rep->GetRMS( 1 ); }
176 double rmsY()
const override {
return m_rep->GetRMS( 2 ); }
178 double rmsZ()
const override {
return m_rep->GetRMS( 3 ); }
180 const AIDA::IAxis&
xAxis()
const override {
return m_xAxis; }
182 const AIDA::IAxis&
yAxis()
const override {
return m_yAxis; }
184 const AIDA::IAxis&
zAxis()
const override {
return m_zAxis; }
186 int coordToIndexX(
double coord )
const override {
return xAxis().coordToIndex( coord ); }
188 int coordToIndexY(
double coord )
const override {
return yAxis().coordToIndex( coord ); }
190 int coordToIndexZ(
double coord )
const override {
return zAxis().coordToIndex( coord ); }
193 double equivalentBinEntries()
const override;
196 bool scale(
double scaleFactor )
override;
198 bool add(
const INTERFACE& hist )
override {
199 const Base* p = dynamic_cast<const Base*>( &hist );
200 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations." );
207 return binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
208 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
209 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
210 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
211 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
212 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
213 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN );
220 int write(
const char* file_name )
const override;
233 int m_sumEntries = 0;
236 template <
class INTERFACE,
class IMPLEMENTATION>
238 m_rep->SetTitle( title.
c_str() );
239 if ( !annotation().addItem(
"Title", title ) ) m_annotation.setValue(
"Title", title );
240 if ( !annotation().addItem(
"title", title ) ) annotation().setValue(
"title", title );
244 template <
class INTERFACE,
class IMPLEMENTATION>
246 m_rep->SetName( newName.
c_str() );
247 m_annotation.setValue(
"Name", newName );
250 template <
class INTERFACE,
class IMPLEMENTATION>
252 return m_rep->GetEntries();
255 template <
class INTERFACE,
class IMPLEMENTATION>
257 return int( m_rep->GetEntries() );
260 template <
class INTERFACE,
class IMPLEMENTATION>
262 return m_rep->GetMinimum();
265 template <
class INTERFACE,
class IMPLEMENTATION>
267 return m_rep->GetMaximum();
270 template <
class INTERFACE,
class IMPLEMENTATION>
272 return m_rep->GetSumOfWeights();
275 template <
class INTERFACE,
class IMPLEMENTATION>
277 return m_rep->GetSum();
280 template <
class INTERFACE,
class IMPLEMENTATION>
282 if ( sumBinHeights() <= 0 )
return 0;
284 m_rep->GetStats( stats );
285 return stats[0] * stats[0] / stats[1];
288 template <
class INTERFACE,
class IMPLEMENTATION>
290 m_rep->Scale( scaleFactor );
294 template <
class INTERFACE,
class IMPLEMENTATION>
297 m_rep->Print(
"all" );
302 template <
class INTERFACE,
class IMPLEMENTATION>
305 s <<
"BinX, BinY, BinZ, Height, Error " <<
std::endl;
306 for (
int i = 0; i < xAxis().bins(); ++i )
307 for (
int j = 0; j < yAxis().bins(); ++j )
308 for (
int k = 0; k < zAxis().bins(); ++k )
309 s << binMeanX( i, j, k ) <<
", " << binMeanY( i, j, k ) <<
", " << binMeanZ( i, j, k ) <<
", " 310 << binHeight( i, j, k ) <<
", " << binError( i, j, k ) <<
std::endl;
316 template <
class INTERFACE,
class IMPLEMENTATION>
318 TFile* f = TFile::Open( file_name,
"RECREATE" );
319 Int_t nbytes = m_rep->Write();
326 # pragma clang diagnostic pop 327 #elif defined( __GNUC__ ) && __GNUC__ >= 5 328 # pragma GCC diagnostic pop 331 #endif // GAUDIPI_GENERIC3D_H AIDA::IAnnotation & annotation() override
Access annotation object.
int rIndexX(int index) const
int rIndexZ(int index) const
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
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.
int binEntriesZ(int index) const override
Sum of all the entries of the bins along a given z bin.
std::string name() const
object name
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
TObject * representation() const override
ROOT object implementation.
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
std::string title() const override
Get the title of the object.
bool add(const INTERFACE &hist) override
Add to this Histogram3D the contents of another IHistogram3D.
int rIndexY(int index) const
Generic3D< INTERFACE, IMPLEMENTATION > Base
int entries() const override
Get the number or all the entries.
double binMeanY(int, int indexY, int) const override
The weighted mean along the y axis of a given bin.
const AIDA::IAxis & zAxis() const override
Get the z axis of the IHistogram3D.
double maxBinHeight() const override
Get the maximum height of the in-range bins.
double meanX() const override
The mean of the IHistogram3D along the x axis.
int binEntriesY(int index) const override
Sum of all the entries of the bins along a given y bin.
double binMeanX(int indexX, int, int) const override
The weighted mean along the x axis of a given bin.
double binMeanZ(int, int, int indexZ) const override
The weighted mean along the z axis of a given bin.
Implementation of the AIDA IAnnotation interface class.
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).
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.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
int dimension() const override
Get the Histogram's dimension.
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile.
double binHeightZ(int index) const override
Sum of all the heights of the bins along a given z bin.
double rmsY() const override
The RMS of the IHistogram3D along the y axis.
double binHeightY(int index) const override
Sum of all the heights of the bins along a given y bin.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
int coordToIndexX(double coord) const override
Get the bin number corresponding to a given coordinate along the x axis.
AIDA::Annotation m_annotation
Object annotations.
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
double minBinHeight() const override
Get the minimum height of the in-range bins.
int coordToIndexZ(double coord) const override
Get the bin number corresponding to a given coordinate along the z axis.
int binEntriesX(int index) const override
Sum of all the entries of the bins along a given x bin.
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
double rmsZ() const override
The RMS of the IHistogram3D along the z axis.
double binError(int indexX, int indexY, int indexZ) const override
The error of a given bin.
int extraEntries() const override
double meanY() const override
The mean of the IHistogram3D along the y axis.
double binHeightX(int index) const override
Sum of all the heights of the bins along a given x bin.
Generic3D(IMPLEMENTATION *p)
constructor
Header file for std:chrono::duration-based Counters.
An IAxis represents a binned histogram axis.
double rmsX() const override
The RMS of the IHistogram3D along the x axis.
double meanZ() const override
The mean of the IHistogram3D along the z axis.
double equivalentBinEntries() const override
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.
double binHeight(int indexX, int indexY, int indexZ) const
Total height of the corresponding bin (ie the sum of the weights in this bin).
const AIDA::IAxis & yAxis() const override
Get the y axis of the IHistogram3D.