14 # pragma warning( disable : 2259 )
20 # pragma warning( disable : 4996 )
35 using AIDA::IHistogram1D;
36 using AIDA::IHistogram2D;
37 using AIDA::IProfile1D;
41 const std::string& title,
int binsX,
double iminX,
double imaxX,
42 int binsY,
double iminY,
double imaxY ) {
43 auto p =
new Histogram2D(
new TH2D( title.
c_str(), title.
c_str(), binsX, iminX, imaxX, binsY, iminY, imaxY ) );
49 const std::string& title,
const Edges& eX,
const Edges& eY ) {
50 auto p =
new Histogram2D(
51 new TH2D( title.
c_str(), title.
c_str(), eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
57 auto p =
new Histogram2D( rep );
63 const IHistogram2D& hist ) {
64 TH2D*
h = getRepresentation<AIDA::IHistogram2D, TH2D>( hist );
65 Histogram2D*
n =
h ?
new Histogram2D(
new TH2D( *
h ) ) :
nullptr;
72 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
73 TH1D*
t = r ? r->ProjectionX(
"_px", 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(
"_py", first, last,
"e" ) :
nullptr;
83 if (
t )
t->SetName( nam.
c_str() );
84 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
90 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
91 TH1D*
t = r ? r->ProjectionY(
"_px", first, last,
"e" ) :
nullptr;
92 if (
t )
t->SetName( nam.
c_str() );
93 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
99 TH2* r = Gaudi::getRepresentation<IHistogram2D, TH2>( hist );
100 TProfile*
t = r ? r->ProfileX(
"_pfx", first, last,
"e" ) :
nullptr;
101 if (
t )
t->SetName( nam.
c_str() );
102 Profile1D* p = (
t ?
new Profile1D(
t ) :
nullptr );
108 TH2* r = getRepresentation<IHistogram2D, TH2>( hist );
109 TProfile*
t = r ? r->ProfileY(
"_pfx", first, last,
"e" ) :
nullptr;
110 if (
t )
t->SetName( nam.
c_str() );
111 Profile1D* p = (
t ?
new Profile1D(
t ) :
nullptr );
118 if ( className ==
"AIDA::IHistogram2D" )
119 return (IHistogram2D*)
this;
120 else if ( className ==
"AIDA::IHistogram" )
121 return (IHistogram*)
this;
127 if ( binHeight( indexX, indexY ) <= 0 )
return 0;
128 double xx = binHeight( indexX, indexY ) / binError( indexX, indexY );
129 return int( xx * xx + 0.5 );
134 TH2D* imp =
dynamic_cast<TH2D*
>( rep );
135 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
137 m_xAxis.initialize( m_rep->GetXaxis(),
true );
138 m_yAxis.initialize( m_rep->GetYaxis(),
true );
139 const TArrayD* a = m_rep->GetSumw2();
140 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
141 setTitle( m_rep->GetTitle() );
149 m_rep->SetDirectory(
nullptr );
153 adoptRepresentation( rep );
154 m_sumwx = m_sumwy = 0;
155 m_rep->SetDirectory(
nullptr );
160 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ), height );
161 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ), error );
163 if ( i >= 0 &&
j >= 0 ) {
164 m_sumwx += centreX * height;
165 m_sumwy += centreY * height;
167 m_sumEntries += entries;
174 return Base::reset();
179 auto guard = std::scoped_lock{ m_fillSerialization };
180 m_rep->Fill( x, y, weight );
185 m_rep->SetEntries( m_sumEntries );
187 stat[0] = sumBinHeights();
190 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
196 meanX = m_sumwx / sumBinHeights();
197 meanY = m_sumwy / sumBinHeights();
199 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
200 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
202 m_rep->PutStats( &stat.
front() );
209 const char* title = titlestr.
c_str();
210 if (
h.xAxis().isFixedBinning() &&
h.yAxis().isFixedBinning() )
211 m_rep.reset(
new TH2D( title, title,
h.xAxis().bins(),
h.xAxis().lowerEdge(),
h.xAxis().upperEdge(),
212 h.yAxis().bins(),
h.yAxis().lowerEdge(),
h.yAxis().upperEdge() ) );
215 for (
int i = 0; i <
h.xAxis().bins(); ++i ) eX.
push_back(
h.xAxis().binLowerEdge( i ) );
217 eX.push_back(
h.xAxis().upperEdge() );
218 for (
int i = 0; i <
h.yAxis().bins(); ++i ) eY.push_back(
h.yAxis().binLowerEdge( i ) );
220 eY.push_back(
h.yAxis().upperEdge() );
221 m_rep.reset(
new TH2D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
223 m_xAxis.initialize( m_rep->GetXaxis(),
true );
224 m_yAxis.initialize( m_rep->GetYaxis(),
true );
230 double sumw =
h.sumBinHeights();
233 sumw2 = ( sumw * sumw ) /
h.equivalentBinEntries();
234 double sumwx =
h.meanX() *
h.sumBinHeights();
235 double sumwx2 = (
h.meanX() *
h.meanX() +
h.rmsX() *
h.rmsX() ) *
h.sumBinHeights();
236 double sumwy =
h.meanY() *
h.sumBinHeights();
237 double sumwy2 = (
h.meanY() *
h.meanY() +
h.rmsY() *
h.rmsY() ) *
h.sumBinHeights();
241 for (
int i = -2; i < xAxis().bins(); ++i ) {
242 for (
int j = -2;
j < yAxis().bins(); ++
j ) {
244 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ),
h.binHeight( i,
j ) );
245 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ),
h.binError( i,
j ) );
247 if ( i >= 0 &&
j >= 0 ) { sumwxy +=
h.binHeight( i,
j ) *
h.binMeanX( i,
j ) *
h.binMeanY( i,
j ); }
252 m_rep->SetEntries(
h.allEntries() );
255 m_rep->PutStats( stat.
data() );