14 # pragma warning( disable : 2259 ) 20 # pragma warning( disable : 4996 ) 33 using AIDA::IHistogram1D;
34 using AIDA::IHistogram2D;
35 using AIDA::IProfile1D;
39 int binsY,
double iminY,
double imaxY ) {
40 auto p =
new Histogram2D(
new TH2D( title.
c_str(), title.
c_str(), binsX, iminX, imaxX, binsY, iminY, imaxY ) );
45 auto p =
new Histogram2D(
46 new TH2D( title.
c_str(), title.
c_str(), eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
51 auto p =
new Histogram2D( rep );
56 TH2D* h = getRepresentation<AIDA::IHistogram2D, TH2D>( hist );
57 Histogram2D*
n = h ?
new Histogram2D(
new TH2D( *h ) ) : nullptr;
63 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
64 TH1D* t = r ? r->ProjectionX(
"_px", first, last,
"e" ) :
nullptr;
65 if ( t ) t->SetName( nam.
c_str() );
66 Histogram1D* p = ( t ?
new Histogram1D( t ) : nullptr );
72 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
73 TH1D* t = r ? r->ProjectionY(
"_py", first, last,
"e" ) :
nullptr;
74 if ( t ) t->SetName( nam.
c_str() );
75 Histogram1D* p = ( t ?
new Histogram1D( t ) : nullptr );
81 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
82 TH1D* t = r ? r->ProjectionY(
"_px", first, last,
"e" ) :
nullptr;
83 if ( t ) t->SetName( nam.
c_str() );
84 Histogram1D* p = ( t ?
new Histogram1D( t ) : nullptr );
90 TH2* r = Gaudi::getRepresentation<IHistogram2D, TH2>( hist );
91 TProfile* t = r ? r->ProfileX(
"_pfx", first, last,
"e" ) :
nullptr;
92 if ( t ) t->SetName( nam.
c_str() );
93 Profile1D* p = ( t ?
new Profile1D( t ) : nullptr );
99 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
100 TProfile* t = r ? r->ProfileY(
"_pfx", first, last,
"e" ) :
nullptr;
101 if ( t ) t->SetName( nam.
c_str() );
102 Profile1D* p = ( t ?
new Profile1D( t ) : nullptr );
109 if ( className ==
"AIDA::IHistogram2D" )
110 return (IHistogram2D*)
this;
111 else if ( className ==
"AIDA::IHistogram" )
112 return (IHistogram*)
this;
118 if ( binHeight( indexX, indexY ) <= 0 )
return 0;
119 double xx = binHeight( indexX, indexY ) / binError( indexX, indexY );
120 return int( xx * xx + 0.5 );
125 TH2D* imp = dynamic_cast<TH2D*>( rep );
126 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
128 m_xAxis.initialize( m_rep->GetXaxis(), true );
129 m_yAxis.initialize( m_rep->GetYaxis(), true );
130 const TArrayD* a = m_rep->GetSumw2();
131 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
132 setTitle( m_rep->GetTitle() );
140 m_rep->SetDirectory(
nullptr );
144 adoptRepresentation( rep );
145 m_sumwx = m_sumwy = 0;
146 m_rep->SetDirectory(
nullptr );
151 m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), height );
152 m_rep->SetBinError( rIndexX( i ), rIndexY( j ), error );
154 if ( i >= 0 && j >= 0 ) {
155 m_sumwx += centreX * height;
156 m_sumwy += centreY * height;
158 m_sumEntries += entries;
165 return Base::reset();
171 # pragma warning( push ) 172 # pragma warning( disable : 1572 ) 177 ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight );
182 m_rep->SetEntries( m_sumEntries );
184 stat[0] = sumBinHeights();
186 if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
189 if ( sumBinHeights() != 0 ) meanX = m_sumwx / sumBinHeights();
190 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
193 if ( sumBinHeights() != 0 ) meanY = m_sumwy / sumBinHeights();
194 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
196 m_rep->PutStats( &stat.
front() );
203 const char* title = titlestr.
c_str();
204 if ( h.xAxis().isFixedBinning() && h.yAxis().isFixedBinning() )
205 m_rep.reset(
new TH2D( title, title, h.xAxis().bins(), h.xAxis().lowerEdge(), h.xAxis().upperEdge(),
206 h.yAxis().bins(), h.yAxis().lowerEdge(), h.yAxis().upperEdge() ) );
209 for (
int i = 0; i < h.xAxis().bins(); ++i ) eX.
push_back( h.xAxis().binLowerEdge( i ) );
211 eX.push_back( h.xAxis().upperEdge() );
212 for (
int i = 0; i < h.yAxis().bins(); ++i ) eY.push_back( h.yAxis().binLowerEdge( i ) );
214 eY.push_back( h.yAxis().upperEdge() );
215 m_rep.reset(
new TH2D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
217 m_xAxis.initialize( m_rep->GetXaxis(), true );
218 m_yAxis.initialize( m_rep->GetYaxis(), true );
224 double sumw = h.sumBinHeights();
226 if ( h.equivalentBinEntries() != 0 ) sumw2 = ( sumw * sumw ) / h.equivalentBinEntries();
227 double sumwx = h.meanX() * h.sumBinHeights();
228 double sumwx2 = ( h.meanX() * h.meanX() + h.rmsX() * h.rmsX() ) * h.sumBinHeights();
229 double sumwy = h.meanY() * h.sumBinHeights();
230 double sumwy2 = ( h.meanY() * h.meanY() + h.rmsY() * h.rmsY() ) * h.sumBinHeights();
234 for (
int i = -2; i < xAxis().bins(); ++i ) {
235 for (
int j = -2; j < yAxis().bins(); ++j ) {
237 m_rep->SetBinContent( rIndexX( i ), rIndexY( j ), h.binHeight( i, j ) );
238 m_rep->SetBinError( rIndexX( i ), rIndexY( j ), h.binError( i, j ) );
240 if ( i >= 0 && j >= 0 ) { sumwxy += h.binHeight( i, j ) * h.binMeanX( i, j ) * h.binMeanY( i, j ); }
245 m_rep->SetEntries( h.allEntries() );
248 m_rep->PutStats( stat.
data() );
253 # pragma warning( pop ) bool setRms(double rmsX, double rmsY)
Sets the rms of the histogram.
std::pair< DataObject *, AIDA::IHistogram2D * > createH2D(const AIDA::IHistogram2D &hist)
Copy constructor.
std::pair< DataObject *, AIDA::IHistogram1D * > slice1DY(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D slice from 2D histogram.
void * cast(const std::string &className) const override
Introspection method.
bool fill(double x, double y, double weight=1.) override
Fill the Histogram2D with a value and the.
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.
std::vector< double > Edges
int binEntries(int indexX, int indexY) const override
The number of entries (ie the number of times fill was called for this bin).
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
Histogram2D()
Standard 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.
bool setTitle(const std::string &title) override
Set the title of the object.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
void copyFromAida(const AIDA::IHistogram2D &h)
Create new histogram from any AIDA based 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.
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.
Header file for std:chrono::duration-based Counters.
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.
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.