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;
178 auto guard = std::scoped_lock{ m_fillSerialization };
179 m_rep->Fill( x, y, weight );
184 m_rep->SetEntries( m_sumEntries );
186 stat[0] = sumBinHeights();
189 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
195 meanX = m_sumwx / sumBinHeights();
196 meanY = m_sumwy / sumBinHeights();
198 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
199 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
201 m_rep->PutStats( &stat.
front() );
208 const char* title = titlestr.
c_str();
209 if (
h.xAxis().isFixedBinning() &&
h.yAxis().isFixedBinning() )
210 m_rep.reset(
new TH2D( title, title,
h.xAxis().bins(),
h.xAxis().lowerEdge(),
h.xAxis().upperEdge(),
211 h.yAxis().bins(),
h.yAxis().lowerEdge(),
h.yAxis().upperEdge() ) );
214 for (
int i = 0; i <
h.xAxis().bins(); ++i ) eX.
push_back(
h.xAxis().binLowerEdge( i ) );
216 eX.push_back(
h.xAxis().upperEdge() );
217 for (
int i = 0; i <
h.yAxis().bins(); ++i ) eY.push_back(
h.yAxis().binLowerEdge( i ) );
219 eY.push_back(
h.yAxis().upperEdge() );
220 m_rep.reset(
new TH2D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
222 m_xAxis.initialize( m_rep->GetXaxis(),
true );
223 m_yAxis.initialize( m_rep->GetYaxis(),
true );
229 double sumw =
h.sumBinHeights();
232 sumw2 = ( sumw * sumw ) /
h.equivalentBinEntries();
233 double sumwx =
h.meanX() *
h.sumBinHeights();
234 double sumwx2 = (
h.meanX() *
h.meanX() +
h.rmsX() *
h.rmsX() ) *
h.sumBinHeights();
235 double sumwy =
h.meanY() *
h.sumBinHeights();
236 double sumwy2 = (
h.meanY() *
h.meanY() +
h.rmsY() *
h.rmsY() ) *
h.sumBinHeights();
240 for (
int i = -2; i < xAxis().bins(); ++i ) {
241 for (
int j = -2;
j < yAxis().bins(); ++
j ) {
243 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ),
h.binHeight( i,
j ) );
244 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ),
h.binError( i,
j ) );
246 if ( i >= 0 &&
j >= 0 ) { sumwxy +=
h.binHeight( i,
j ) *
h.binMeanX( i,
j ) *
h.binMeanY( i,
j ); }
251 m_rep->SetEntries(
h.allEntries() );
254 m_rep->PutStats( stat.
data() );