14# pragma warning( disable : 2259 )
30 using AIDA::IHistogram1D;
31 using AIDA::IHistogram2D;
32 using AIDA::IProfile1D;
36 const std::string& title,
int binsX,
double iminX,
double imaxX,
37 int binsY,
double iminY,
double imaxY ) {
38 auto p =
new Histogram2D(
new TH2D( title.c_str(), title.c_str(), binsX, iminX, imaxX, binsY, iminY, imaxY ) );
39 svcLocator->monitoringHub().registerEntity(
"", path,
"histogram:Histogram:double", *p );
44 const std::string& title,
const Edges& eX,
const Edges& eY ) {
46 new TH2D( title.c_str(), title.c_str(), eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
47 svcLocator->monitoringHub().registerEntity(
"", path,
"histogram:Histogram:double", *p );
53 svcLocator->monitoringHub().registerEntity(
"", path,
"histogram:Histogram:double", *p );
61 if ( n ) {
svcLocator->monitoringHub().registerEntity( path,
h->GetName(),
"histogram:Histogram:double", *n ); }
68 TH1D*
t = r ? r->ProjectionX(
"_px", first, last,
"e" ) :
nullptr;
69 if ( t )
t->SetName( nam.c_str() );
77 TH1D*
t = r ? r->ProjectionY(
"_py", first, last,
"e" ) :
nullptr;
78 if ( t )
t->SetName( nam.c_str() );
86 TH1D*
t = r ? r->ProjectionY(
"_px", first, last,
"e" ) :
nullptr;
87 if ( t )
t->SetName( nam.c_str() );
95 TProfile*
t = r ? r->ProfileX(
"_pfx", first, last,
"e" ) :
nullptr;
96 if ( t )
t->SetName( nam.c_str() );
104 TProfile*
t = r ? r->ProfileY(
"_pfx", first, last,
"e" ) :
nullptr;
105 if ( t )
t->SetName( nam.c_str() );
113 if ( className ==
"AIDA::IHistogram2D" )
115 else if ( className ==
"AIDA::IHistogram" )
116 return (IHistogram*)
this;
122 if (
binHeight( indexX, indexY ) <= 0 )
return 0;
124 return int( xx * xx + 0.5 );
129 TH2D* imp =
dynamic_cast<TH2D*
>( rep );
130 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
134 const TArrayD* a =
m_rep->GetSumw2();
135 if ( !a || ( a && a->GetSize() == 0 ) )
m_rep->Sumw2();
144 m_rep->SetDirectory(
nullptr );
150 m_rep->SetDirectory(
nullptr );
158 if ( i >= 0 && j >= 0 ) {
175 m_rep->Fill( x, y, weight );
181 std::vector<double> stat( 11 );
197 m_rep->PutStats( &stat.front() );
203 std::string titlestr = h.title();
204 const char*
title = titlestr.c_str();
205 if ( h.xAxis().isFixedBinning() && h.yAxis().isFixedBinning() )
206 m_rep.reset(
new TH2D(
title,
title, h.xAxis().bins(), h.xAxis().lowerEdge(), h.xAxis().upperEdge(),
207 h.yAxis().bins(), h.yAxis().lowerEdge(), h.yAxis().upperEdge() ) );
210 for (
int i = 0; i < h.xAxis().bins(); ++i ) eX.push_back( h.xAxis().binLowerEdge( i ) );
212 eX.push_back( h.xAxis().upperEdge() );
213 for (
int i = 0; i < h.yAxis().bins(); ++i ) eY.push_back( h.yAxis().binLowerEdge( i ) );
215 eY.push_back( h.yAxis().upperEdge() );
216 m_rep.reset(
new TH2D(
title,
title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
225 double sumw = h.sumBinHeights();
227 if (
std::abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
228 sumw2 = ( sumw * sumw ) / h.equivalentBinEntries();
229 double sumwx = h.meanX() * h.sumBinHeights();
230 double sumwx2 = ( h.meanX() * h.meanX() + h.rmsX() * h.rmsX() ) * h.sumBinHeights();
231 double sumwy = h.meanY() * h.sumBinHeights();
232 double sumwy2 = ( h.meanY() * h.meanY() + h.rmsY() * h.rmsY() ) * h.sumBinHeights();
236 for (
int i = -2; i <
xAxis().bins(); ++i ) {
237 for (
int j = -2; j <
yAxis().bins(); ++j ) {
242 if ( i >= 0 && j >= 0 ) { sumwxy += h.binHeight( i, j ) * h.binMeanX( i, j ) * h.binMeanY( i, j ); }
247 m_rep->SetEntries( h.allEntries() );
249 std::array<double, 11> stat = { { sumw, sumw2, sumwx, sumwx2, sumwy, sumwy2, sumwxy } };
250 m_rep->PutStats( stat.data() );
virtual int rIndexX(int index) const
int entries() const override
double binError(int indexX, int indexY) const override
const AIDA::IAxis & xAxis() const override
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
double rmsY() const override
void adoptRepresentation(TObject *rep)
const AIDA::IAxis & yAxis() const override
std::unique_ptr< TH2D > m_rep
double meanY() const override
double meanX() const override
int binEntries(int indexX, int indexY) const override
The number of entries (ie the number of times fill was called for this bin).
double sumBinHeights() const override
double rmsX() const override
double binHeight(int indexX, int indexY) const override
Generic2D< AIDA::IHistogram2D, TH2D > Base
virtual int rIndexY(int index) const
void * cast(const std::string &className) const override
Introspection method.
virtual double equivalentBinEntries() const
bool setTitle(const std::string &title) override
std::string title() const override
AIDA implementation for 1 D histograms using ROOT THD1.
AIDA implementation for 2 D histograms using ROOT THD2.
void copyFromAida(const AIDA::IHistogram2D &h)
Create new histogram from any AIDA based histogram.
bool fill(double x, double y, double weight=1.) override
Fill the Histogram2D with a value and the.
Histogram2D()
Standard Constructor.
std::mutex m_fillSerialization
bool setRms(double rmsX, double rmsY)
Sets the rms of the histogram.
virtual bool setBinContents(int binIndexX, int binIndexY, int entries, double height, double error, double centreX, double centreY)
Fast filling method for a given bin. It can be also the over/underflow bin.
AIDA implementation for 1 D profiles using ROOT TProfile.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
GAUDI_API ISvcLocator * svcLocator()
std::pair< DataObject *, AIDA::IHistogram2D * > createH2D(ISvcLocator *svcLocator, const std::string &path, const AIDA::IHistogram2D &hist)
Copy constructor.
std::pair< DataObject *, AIDA::IHistogram1D * > slice1DX(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D slice from 2D histogram.
std::pair< DataObject *, AIDA::IHistogram1D * > slice1DY(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D slice from 2D histogram.
std::pair< DataObject *, AIDA::IHistogram1D * > project1DY(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D projection in Y from 2D histogram.
T * getRepresentation(const Q &hist)
std::pair< DataObject *, AIDA::IProfile1D * > profile1DX(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D profile in X from 2D histogram.
std::pair< DataObject *, AIDA::IProfile1D * > profile1DY(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D profile in Y from 2D histogram.
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.