14 # pragma warning( disable : 2259 )
20 # pragma warning( disable : 4996 )
34 using AIDA::IHistogram1D;
35 using AIDA::IHistogram2D;
36 using AIDA::IProfile1D;
40 const std::string& title,
int binsX,
double iminX,
double imaxX,
41 int binsY,
double iminY,
double imaxY ) {
42 auto p =
new Histogram2D(
new TH2D( title.
c_str(), title.
c_str(), binsX, iminX, imaxX, binsY, iminY, imaxY ) );
48 const std::string& title,
const Edges& eX,
const Edges& eY ) {
49 auto p =
new Histogram2D(
50 new TH2D( title.
c_str(), title.
c_str(), eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
56 auto p =
new Histogram2D( rep );
62 const IHistogram2D& hist ) {
63 TH2D*
h = getRepresentation<AIDA::IHistogram2D, TH2D>( hist );
64 Histogram2D*
n =
h ?
new Histogram2D(
new TH2D( *
h ) ) :
nullptr;
71 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
72 TH1D*
t = r ? r->ProjectionX(
"_px", first, last,
"e" ) :
nullptr;
73 if (
t )
t->SetName( nam.
c_str() );
74 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
80 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
81 TH1D*
t = r ? r->ProjectionY(
"_py", first, last,
"e" ) :
nullptr;
82 if (
t )
t->SetName( nam.
c_str() );
83 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
89 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
90 TH1D*
t = r ? r->ProjectionY(
"_px", first, last,
"e" ) :
nullptr;
91 if (
t )
t->SetName( nam.
c_str() );
92 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
98 TH2* r = Gaudi::getRepresentation<IHistogram2D, TH2>( hist );
99 TProfile*
t = r ? r->ProfileX(
"_pfx", first, last,
"e" ) :
nullptr;
100 if (
t )
t->SetName( nam.
c_str() );
101 Profile1D* p = (
t ?
new Profile1D(
t ) :
nullptr );
107 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
108 TProfile*
t = r ? r->ProfileY(
"_pfx", first, last,
"e" ) :
nullptr;
109 if (
t )
t->SetName( nam.
c_str() );
110 Profile1D* p = (
t ?
new Profile1D(
t ) :
nullptr );
117 if ( className ==
"AIDA::IHistogram2D" )
118 return (IHistogram2D*)
this;
119 else if ( className ==
"AIDA::IHistogram" )
120 return (IHistogram*)
this;
126 if ( binHeight( indexX, indexY ) <= 0 )
return 0;
127 double xx = binHeight( indexX, indexY ) / binError( indexX, indexY );
128 return int( xx * xx + 0.5 );
133 TH2D* imp =
dynamic_cast<TH2D*
>( rep );
134 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
136 m_xAxis.initialize( m_rep->GetXaxis(),
true );
137 m_yAxis.initialize( m_rep->GetYaxis(),
true );
138 const TArrayD* a = m_rep->GetSumw2();
139 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
140 setTitle( m_rep->GetTitle() );
148 m_rep->SetDirectory(
nullptr );
152 adoptRepresentation( rep );
153 m_sumwx = m_sumwy = 0;
154 m_rep->SetDirectory(
nullptr );
159 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ), height );
160 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ), error );
162 if ( i >= 0 &&
j >= 0 ) {
163 m_sumwx += centreX * height;
164 m_sumwy += centreY * height;
166 m_sumEntries += entries;
179 # pragma warning( push )
180 # pragma warning( disable : 1572 )
184 auto guard = std::scoped_lock{ m_fillSerialization };
185 ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight );
190 m_rep->SetEntries( m_sumEntries );
192 stat[0] = sumBinHeights();
194 if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
197 if ( sumBinHeights() != 0 ) meanX = m_sumwx / sumBinHeights();
198 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
201 if ( sumBinHeights() != 0 ) meanY = m_sumwy / sumBinHeights();
202 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
204 m_rep->PutStats( &stat.
front() );
211 const char* title = titlestr.
c_str();
212 if (
h.xAxis().isFixedBinning() &&
h.yAxis().isFixedBinning() )
213 m_rep.reset(
new TH2D( title, title,
h.xAxis().bins(),
h.xAxis().lowerEdge(),
h.xAxis().upperEdge(),
214 h.yAxis().bins(),
h.yAxis().lowerEdge(),
h.yAxis().upperEdge() ) );
217 for (
int i = 0; i <
h.xAxis().bins(); ++i ) eX.
push_back(
h.xAxis().binLowerEdge( i ) );
219 eX.push_back(
h.xAxis().upperEdge() );
220 for (
int i = 0; i <
h.yAxis().bins(); ++i ) eY.push_back(
h.yAxis().binLowerEdge( i ) );
222 eY.push_back(
h.yAxis().upperEdge() );
223 m_rep.reset(
new TH2D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
225 m_xAxis.initialize( m_rep->GetXaxis(),
true );
226 m_yAxis.initialize( m_rep->GetYaxis(),
true );
232 double sumw =
h.sumBinHeights();
234 if (
h.equivalentBinEntries() != 0 ) sumw2 = ( sumw * sumw ) /
h.equivalentBinEntries();
235 double sumwx =
h.meanX() *
h.sumBinHeights();
236 double sumwx2 = (
h.meanX() *
h.meanX() +
h.rmsX() *
h.rmsX() ) *
h.sumBinHeights();
237 double sumwy =
h.meanY() *
h.sumBinHeights();
238 double sumwy2 = (
h.meanY() *
h.meanY() +
h.rmsY() *
h.rmsY() ) *
h.sumBinHeights();
242 for (
int i = -2; i < xAxis().bins(); ++i ) {
243 for (
int j = -2;
j < yAxis().bins(); ++
j ) {
245 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ),
h.binHeight( i,
j ) );
246 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ),
h.binError( i,
j ) );
248 if ( i >= 0 &&
j >= 0 ) { sumwxy +=
h.binHeight( i,
j ) *
h.binMeanX( i,
j ) *
h.binMeanY( i,
j ); }
253 m_rep->SetEntries(
h.allEntries() );
256 m_rep->PutStats( stat.
data() );
261 # pragma warning( pop )