1 #ifndef GAUDISVC_GENERIC2D_H 2 #define GAUDISVC_GENERIC2D_H 1 4 #include "AIDA/IProfile2D.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 <
class INTERFACE,
class IMPLEMENTATION>
53 void adoptRepresentation( TObject* rep )
override;
63 AIDA::IAnnotation&
annotation()
override {
return m_annotation; }
65 const AIDA::IAnnotation&
annotation()
const override {
return m_annotation; }
68 const AIDA::IAxis&
xAxis()
const override {
return m_xAxis; }
70 const AIDA::IAxis&
yAxis()
const override {
return m_yAxis; }
72 virtual int rIndexX(
int index )
const {
return m_xAxis.rIndex( index ); }
74 virtual int rIndexY(
int index )
const {
return m_yAxis.rIndex( index ); }
77 int entries()
const override;
79 int allEntries()
const override;
81 int extraEntries()
const override;
83 double sumBinHeights()
const override;
85 double sumAllBinHeights()
const override;
89 double minBinHeight()
const override;
91 double maxBinHeight()
const override;
94 double binMeanX(
int indexX,
int indexY )
const override;
96 double binMeanY(
int indexX,
int indexY )
const override;
98 int binEntries(
int indexX,
int indexY )
const override;
100 int binEntriesX(
int indexX )
const override;
102 int binEntriesY(
int indexY )
const override;
104 double binHeight(
int indexX,
int indexY )
const override;
106 double binHeightX(
int indexX )
const override;
108 double binHeightY(
int indexY )
const override;
110 double binError(
int indexX,
int indexY )
const override;
112 virtual double binRms(
int indexX,
int indexY )
const;
114 double meanX()
const override;
116 double meanY()
const override;
118 double rmsX()
const override;
120 double rmsY()
const override;
122 int coordToIndexX(
double coordX )
const override;
124 int coordToIndexY(
double coordY )
const override;
126 virtual double equivalentBinEntries()
const;
129 virtual bool scale(
double scaleFactor );
131 bool add(
const INTERFACE&
h )
override;
133 bool reset()
override;
135 void* cast(
const std::string& className )
const override;
145 int write(
const char* file_name )
const override;
159 int m_sumEntries = 0;
162 template <
class INTERFACE,
class IMPLEMENTATION>
165 m_rep->SetTitle( title.
c_str() );
166 if ( !annotation().addItem(
"Title", title ) ) m_annotation.setValue(
"Title", title );
167 if ( !annotation().addItem(
"title", title ) ) annotation().setValue(
"title", title );
171 template <
class INTERFACE,
class IMPLEMENTATION>
174 m_rep->SetName( newName.
c_str() );
175 m_annotation.setValue(
"Name", newName );
179 template <
class INTERFACE,
class IMPLEMENTATION>
182 return m_rep->GetEntries();
185 template <
class INTERFACE,
class IMPLEMENTATION>
188 return m_rep->GetEntries();
191 template <
class INTERFACE,
class IMPLEMENTATION>
194 return m_rep->GetMinimum();
197 template <
class INTERFACE,
class IMPLEMENTATION>
200 return m_rep->GetMaximum();
203 template <
class INTERFACE,
class IMPLEMENTATION>
206 return m_rep->GetSumOfWeights();
209 template <
class INTERFACE,
class IMPLEMENTATION>
212 return m_rep->GetSum();
215 template <
class INTERFACE,
class IMPLEMENTATION>
218 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ) );
221 template <
class INTERFACE,
class IMPLEMENTATION>
224 return m_rep->GetXaxis()->GetBinCenter( rIndexX( indexX ) );
227 template <
class INTERFACE,
class IMPLEMENTATION>
230 return m_rep->GetYaxis()->GetBinCenter( rIndexY( indexY ) );
233 template <
class INTERFACE,
class IMPLEMENTATION>
237 for (
int iY = -2; iY < yAxis().bins(); ++iY ) n += binEntries( index, iY );
241 template <
class INTERFACE,
class IMPLEMENTATION>
245 for (
int iX = -2; iX < xAxis().bins(); ++iX ) n += binEntries( iX, index );
249 template <
class INTERFACE,
class IMPLEMENTATION>
252 return m_rep->GetBinContent( rIndexX( indexX ), rIndexY( indexY ) );
255 template <
class INTERFACE,
class IMPLEMENTATION>
259 for (
int iY = -2; iY < yAxis().bins(); ++iY ) {
260 s += binHeight( index, iY );
265 template <
class INTERFACE,
class IMPLEMENTATION>
269 for (
int iX = -2; iX < xAxis().bins(); ++iX ) s += binHeight( iX, index );
273 template <
class INTERFACE,
class IMPLEMENTATION>
276 return m_rep->GetBinError( rIndexX( indexX ), rIndexY( indexY ) );
279 template <
class INTERFACE,
class IMPLEMENTATION>
282 return m_rep->GetMean( 1 );
285 template <
class INTERFACE,
class IMPLEMENTATION>
288 return m_rep->GetMean( 2 );
291 template <
class INTERFACE,
class IMPLEMENTATION>
294 return m_rep->GetRMS( 1 );
297 template <
class INTERFACE,
class IMPLEMENTATION>
300 return m_rep->GetRMS( 2 );
303 template <
class INTERFACE,
class IMPLEMENTATION>
306 return xAxis().coordToIndex( coord );
309 template <
class INTERFACE,
class IMPLEMENTATION>
312 return yAxis().coordToIndex( coord );
315 template <
class INTERFACE,
class IMPLEMENTATION>
318 const Base* p =
dynamic_cast<const Base*
>( &hist );
319 if ( !p )
throw std::runtime_error(
"Cannot add profile histograms of different implementations." );
324 template <
class INTERFACE,
class IMPLEMENTATION>
327 return binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
328 binEntries( AIDA::IAxis::UNDERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN ) +
329 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::UNDERFLOW_BIN ) +
330 binEntries( AIDA::IAxis::OVERFLOW_BIN, AIDA::IAxis::OVERFLOW_BIN );
333 template <
class INTERFACE,
class IMPLEMENTATION>
336 if ( sumBinHeights() <= 0 )
return 0;
338 m_rep->GetStats( stats );
339 return stats[0] * stats[0] / stats[1];
342 template <
class INTERFACE,
class IMPLEMENTATION>
345 m_rep->Scale( scaleFactor );
349 template <
class INTERFACE,
class IMPLEMENTATION>
357 template <
class INTERFACE,
class IMPLEMENTATION>
361 m_rep->Print(
"all" );
366 template <
class INTERFACE,
class IMPLEMENTATION>
370 s <<
"BinX, BinY, Height, Error " <<
std::endl;
371 for (
int i = 0; i < xAxis().bins(); ++i ) {
372 for (
int j = 0; j < yAxis().bins(); ++j ) {
373 s << binMeanX( i, j ) <<
", " << binMeanY( i, j ) <<
", " << binHeight( i, j ) <<
", " << binError( i, j )
382 template <
class INTERFACE,
class IMPLEMENTATION>
385 TFile* f = TFile::Open( file_name,
"RECREATE" );
386 Int_t nbytes = m_rep->Write();
393 #pragma clang diagnostic pop 394 #elif defined( __GNUC__ ) && __GNUC__ >= 5 395 #pragma GCC diagnostic pop 398 #endif // GAUDIPI_GENERIC2D_H int coordToIndexX(double coordX) const override
Convenience method, equivalent to xAxis().coordToIndex(coord).
virtual double equivalentBinEntries() const
Number of equivalent entries, i.e. SUM[ weight ] ^ 2 / SUM[ weight^2 ]
double rmsX() const override
Returns the rms of the profile as calculated on filling-time projected on the X axis.
int extraEntries() const override
Get the number of entries in the underflow and overflow bins.
int dimension() const override
Get the Histogram's dimension.
Generic2D(IMPLEMENTATION *p)
constructor
double binMeanY(int indexX, int indexY) const override
The weighted mean along y of a given bin.
virtual bool scale(double scaleFactor)
Scale the weights and the errors of all the IHistogram's bins (in-range and out-of-range ones) by a g...
double rmsY() const override
Returns the rms of the profile as calculated on filling-time projected on the Y axis.
double maxBinHeight() const override
Get the maximum height of the in-range bins.
std::string name() const
object name
bool setName(const std::string &newName)
Set the name of the object.
virtual int rIndexX(int index) const
operator methods
int binEntriesX(int indexX) const override
Equivalent to projectionX().binEntries(indexX).
double sumBinHeights() const override
Get the sum of in range bin heights in the IProfile.
double binHeightY(int indexY) const override
Equivalent to projectionY().binHeight(indexY).
double binHeightX(int indexX) const override
Equivalent to projectionX().binHeight(indexX).
std::string m_classType
class type
Axis m_xAxis
X axis member.
Generic2D< INTERFACE, IMPLEMENTATION > Base
int allEntries() const override
Get the number or all the entries, both in range and underflow/overflow bins of the IProfile...
Implementation of the AIDA IAnnotation interface class.
int coordToIndexY(double coordY) const override
Convenience method, equivalent to yAxis().coordToIndex(coord).
double sumExtraBinHeights() const override
Get the sum of the underflow and overflow bin height.
std::ostream & print(std::ostream &s) const override
Print (ASCII) the histogram into the output stream.
const AIDA::IAnnotation & annotation() const override
Access annotation object (cons)
const std::string & userLevelClassType() const
The AIDA user-level unterface leaf class type.
AIDA::IAnnotation & annotation() override
Access annotation object.
double binError(int indexX, int indexY) const override
The error on this bin.
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
AIDA::Annotation m_annotation
Object annotations.
bool setTitle(const std::string &title) override
Set the title of the object.
TObject * representation() const override
ROOT object implementation.
double meanX() const override
Returns the mean of the profile, as calculated on filling-time projected on the X axis...
Axis m_yAxis
Y axis member.
std::ostream & write(std::ostream &s) const override
Write (ASCII) the histogram table into the output stream.
double binMeanX(int indexX, int indexY) const override
The weighted mean along x of a given bin.
double sumAllBinHeights() const override
Get the sum of all the bins heights (including underflow and overflow bin).
virtual double binRms(int indexX, int indexY) const
The spread (RMS) of this bin.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
int binEntriesY(int indexY) const override
Equivalent to projectionY().binEntries(indexY).
int entries() const override
Get the number or all the entries.
virtual int rIndexY(int index) const
operator methods
double meanY() const override
Returns the mean of the profile, as calculated on filling-time projected on the Y axis...
std::string title() const override
Get the title of the object.
Helper functions to set/get the application return code.
An IAxis represents a binned histogram axis.
bool add(const INTERFACE &h) override
Modifies this profile by adding the contents of profile to it.
const AIDA::IAxis & yAxis() const override
Return the Y axis.
double minBinHeight() const override
Get the minimum height of the in-range bins.
const AIDA::IAxis & xAxis() const override
Return the X axis.
double binHeight(int indexX, int indexY) const override
Total height of the corresponding bin (ie the sum of the weights in this bin).
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.