14 # pragma warning( disable : 2259 )
20 # pragma warning( disable : 4996 )
36 using AIDA::IHistogram1D;
37 using AIDA::IHistogram2D;
38 using AIDA::IProfile1D;
42 const std::string& title,
int binsX,
double iminX,
double imaxX,
43 int binsY,
double iminY,
double imaxY ) {
44 auto p =
new Histogram2D(
new TH2D( title.
c_str(), title.
c_str(), binsX, iminX, imaxX, binsY, iminY, imaxY ) );
50 const std::string& title,
const Edges& eX,
const Edges& eY ) {
51 auto p =
new Histogram2D(
52 new TH2D( title.
c_str(), title.
c_str(), eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
58 auto p =
new Histogram2D( rep );
64 const IHistogram2D& hist ) {
65 TH2D*
h = getRepresentation<AIDA::IHistogram2D, TH2D>( hist );
66 Histogram2D*
n =
h ?
new Histogram2D(
new TH2D( *
h ) ) :
nullptr;
73 TH2*
r = getRepresentation<IHistogram2D, TH2>( hist );
74 TH1D*
t =
r ?
r->ProjectionX(
"_px", first, last,
"e" ) :
nullptr;
75 if (
t )
t->SetName( nam.
c_str() );
76 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
82 TH2*
r = getRepresentation<IHistogram2D, TH2>( hist );
83 TH1D*
t =
r ?
r->ProjectionY(
"_py", first, last,
"e" ) :
nullptr;
84 if (
t )
t->SetName( nam.
c_str() );
85 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
91 TH2*
r = getRepresentation<IHistogram2D, TH2>( hist );
92 TH1D*
t =
r ?
r->ProjectionY(
"_px", first, last,
"e" ) :
nullptr;
93 if (
t )
t->SetName( nam.
c_str() );
94 Histogram1D* p = (
t ?
new Histogram1D(
t ) :
nullptr );
100 TH2*
r = Gaudi::getRepresentation<IHistogram2D, TH2>( hist );
101 TProfile*
t =
r ?
r->ProfileX(
"_pfx", first, last,
"e" ) :
nullptr;
102 if (
t )
t->SetName( nam.
c_str() );
103 Profile1D* p = (
t ?
new Profile1D(
t ) :
nullptr );
109 TH2*
r = getRepresentation<IHistogram2D, TH2>( hist );
110 TProfile*
t =
r ?
r->ProfileY(
"_pfx", first, last,
"e" ) :
nullptr;
111 if (
t )
t->SetName( nam.
c_str() );
112 Profile1D* p = (
t ?
new Profile1D(
t ) :
nullptr );
119 if ( className ==
"AIDA::IHistogram2D" )
120 return (IHistogram2D*)
this;
121 else if ( className ==
"AIDA::IHistogram" )
122 return (IHistogram*)
this;
128 if ( binHeight( indexX, indexY ) <= 0 )
return 0;
129 double xx = binHeight( indexX, indexY ) / binError( indexX, indexY );
130 return int( xx * xx + 0.5 );
135 TH2D* imp =
dynamic_cast<TH2D*
>( rep );
136 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
138 m_xAxis.initialize( m_rep->GetXaxis(),
true );
139 m_yAxis.initialize( m_rep->GetYaxis(),
true );
140 const TArrayD* a = m_rep->GetSumw2();
141 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
142 setTitle( m_rep->GetTitle() );
150 m_rep->SetDirectory(
nullptr );
154 adoptRepresentation( rep );
155 m_sumwx = m_sumwy = 0;
156 m_rep->SetDirectory(
nullptr );
161 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ), height );
162 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ), error );
164 if ( i >= 0 &&
j >= 0 ) {
165 m_sumwx += centreX * height;
166 m_sumwy += centreY * height;
168 m_sumEntries += entries;
175 return Base::reset();
183 # pragma warning( push )
184 # pragma warning( disable : 1572 )
188 auto guard = std::scoped_lock{ m_fillSerialization };
189 ( weight == 1. ) ? m_rep->Fill( x, y ) : m_rep->Fill( x, y, weight );
194 m_rep->SetEntries( m_sumEntries );
196 stat[0] = sumBinHeights();
198 if ( equivalentBinEntries() != 0 ) stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
201 if ( sumBinHeights() != 0 ) meanX = m_sumwx / sumBinHeights();
202 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
205 if ( sumBinHeights() != 0 ) meanY = m_sumwy / sumBinHeights();
206 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
208 m_rep->PutStats( &stat.
front() );
215 const char* title = titlestr.
c_str();
216 if (
h.xAxis().isFixedBinning() &&
h.yAxis().isFixedBinning() )
217 m_rep.reset(
new TH2D( title, title,
h.xAxis().bins(),
h.xAxis().lowerEdge(),
h.xAxis().upperEdge(),
218 h.yAxis().bins(),
h.yAxis().lowerEdge(),
h.yAxis().upperEdge() ) );
221 for (
int i = 0; i <
h.xAxis().bins(); ++i ) eX.
push_back(
h.xAxis().binLowerEdge( i ) );
223 eX.push_back(
h.xAxis().upperEdge() );
224 for (
int i = 0; i <
h.yAxis().bins(); ++i ) eY.push_back(
h.yAxis().binLowerEdge( i ) );
226 eY.push_back(
h.yAxis().upperEdge() );
227 m_rep.reset(
new TH2D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front() ) );
229 m_xAxis.initialize( m_rep->GetXaxis(),
true );
230 m_yAxis.initialize( m_rep->GetYaxis(),
true );
236 double sumw =
h.sumBinHeights();
238 if (
h.equivalentBinEntries() != 0 ) sumw2 = ( sumw * sumw ) /
h.equivalentBinEntries();
239 double sumwx =
h.meanX() *
h.sumBinHeights();
240 double sumwx2 = (
h.meanX() *
h.meanX() +
h.rmsX() *
h.rmsX() ) *
h.sumBinHeights();
241 double sumwy =
h.meanY() *
h.sumBinHeights();
242 double sumwy2 = (
h.meanY() *
h.meanY() +
h.rmsY() *
h.rmsY() ) *
h.sumBinHeights();
246 for (
int i = -2; i < xAxis().bins(); ++i ) {
247 for (
int j = -2;
j < yAxis().bins(); ++
j ) {
249 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ),
h.binHeight( i,
j ) );
250 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ),
h.binError( i,
j ) );
252 if ( i >= 0 &&
j >= 0 ) { sumwxy +=
h.binHeight( i,
j ) *
h.binMeanX( i,
j ) *
h.binMeanY( i,
j ); }
257 m_rep->SetEntries(
h.allEntries() );
260 m_rep->PutStats( stat.
data() );
265 # pragma warning( pop )