14 # pragma warning( disable : 2259 )
32 TH3D* imp =
dynamic_cast<TH3D*
>( rep );
33 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
35 m_xAxis.initialize( m_rep->GetXaxis(),
true );
36 m_yAxis.initialize( m_rep->GetYaxis(),
true );
37 m_zAxis.initialize( m_rep->GetZaxis(),
true );
38 const TArrayD* a = m_rep->GetSumw2();
39 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
40 setTitle( m_rep->GetTitle() );
46 const std::string& title,
int nBinsX,
double xlow,
47 double xup,
int nBinsY,
double ylow,
double yup,
48 int nBinsZ,
double zlow,
double zup ) {
49 auto p =
new Histogram3D(
50 new TH3D( title.c_str(), title.c_str(), nBinsX, xlow, xup, nBinsY, ylow, yup, nBinsZ, zlow, zup ) );
57 const std::string& title,
const Edges& eX,
58 const Edges& eY,
const Edges& eZ ) {
59 auto p =
new Histogram3D(
new TH3D( title.c_str(), title.c_str(), eX.size() - 1, &eX.front(), eY.size() - 1,
60 &eY.front(), eZ.size() - 1, &eZ.front() ) );
66 const AIDA::IHistogram3D& hist ) {
67 TH3D*
h = getRepresentation<AIDA::IHistogram3D, TH3D>( hist );
68 Histogram3D*
n =
h ?
new Histogram3D(
new TH3D( *
h ) ) :
nullptr;
79 m_rep->SetDirectory(
nullptr );
83 adoptRepresentation( rep );
87 m_rep->SetDirectory(
nullptr );
92 double centreY,
double centreZ ) {
93 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ), rIndexZ( k ), height );
94 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ), rIndexZ( k ), error );
96 if ( i >= 0 &&
j >= 0 && k >= 0 ) {
97 m_sumwx += centreX * height;
98 m_sumwy += centreY * height;
99 m_sumwz += centreZ * height;
101 m_sumEntries += entries;
116 auto guard = std::scoped_lock{ m_fillSerialization };
117 m_rep->Fill( x, y, z, weight );
122 if ( className ==
"AIDA::IHistogram3D" ) {
123 return (AIDA::IHistogram3D*)
this;
124 }
else if ( className ==
"AIDA::IHistogram" ) {
125 return (AIDA::IHistogram*)
this;
131 m_rep->SetEntries( m_sumEntries );
132 std::vector<double> stat( 11 );
134 stat[0] = sumBinHeights();
136 if ( std::abs( equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
137 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
145 if ( std::abs( sumBinHeights() ) > std::numeric_limits<double>::epsilon() ) {
146 meanX = m_sumwx / sumBinHeights();
147 meanY = m_sumwy / sumBinHeights();
148 meanZ = m_sumwz / sumBinHeights();
150 stat[3] = ( meanX * meanX + rmsX * rmsX ) * sumBinHeights();
151 stat[5] = ( meanY * meanY + rmsY * rmsY ) * sumBinHeights();
152 stat[8] = ( meanZ * meanZ + rmsZ * rmsZ ) * sumBinHeights();
154 m_rep->PutStats( &stat.front() );
160 std::string titlestr =
h.title();
161 const char* title = titlestr.c_str();
162 if (
h.xAxis().isFixedBinning() &&
h.yAxis().isFixedBinning() &&
h.zAxis().isFixedBinning() ) {
163 m_rep = std::make_unique<TH3D>( title, title,
h.xAxis().bins(),
h.xAxis().lowerEdge(),
h.xAxis().upperEdge(),
164 h.yAxis().bins(),
h.yAxis().lowerEdge(),
h.yAxis().upperEdge(),
h.zAxis().bins(),
165 h.zAxis().lowerEdge(),
h.zAxis().upperEdge() );
168 for (
int i = 0; i <
h.xAxis().bins(); ++i ) eX.push_back(
h.xAxis().binLowerEdge( i ) );
170 eX.push_back(
h.xAxis().upperEdge() );
171 for (
int i = 0; i <
h.yAxis().bins(); ++i ) eY.push_back(
h.yAxis().binLowerEdge( i ) );
173 eY.push_back(
h.yAxis().upperEdge() );
174 for (
int i = 0; i <
h.zAxis().bins(); ++i ) eZ.push_back(
h.zAxis().binLowerEdge( i ) );
176 eZ.push_back(
h.zAxis().upperEdge() );
178 new TH3D( title, title, eX.size() - 1, &eX.front(), eY.size() - 1, &eY.front(), eZ.size() - 1, &eZ.front() ) );
180 m_xAxis.initialize( m_rep->GetXaxis(),
true );
181 m_yAxis.initialize( m_rep->GetYaxis(),
true );
182 m_zAxis.initialize( m_rep->GetZaxis(),
true );
183 const TArrayD* a = m_rep->GetSumw2();
184 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
191 double sumw =
h.sumBinHeights();
193 if ( std::abs(
h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
194 sumw2 = ( sumw * sumw ) /
h.equivalentBinEntries();
195 double sumwx =
h.meanX() *
h.sumBinHeights();
196 double sumwx2 = (
h.meanX() *
h.meanX() +
h.rmsX() *
h.rmsX() ) *
h.sumBinHeights();
197 double sumwy =
h.meanY() *
h.sumBinHeights();
198 double sumwy2 = (
h.meanY() *
h.meanY() +
h.rmsY() *
h.rmsY() ) *
h.sumBinHeights();
199 double sumwz =
h.meanZ() *
h.sumBinHeights();
200 double sumwz2 = (
h.meanZ() *
h.meanZ() +
h.rmsZ() *
h.rmsZ() ) *
h.sumBinHeights();
206 for (
int i = -2; i < xAxis().bins(); ++i ) {
207 for (
int j = -2;
j < yAxis().bins(); ++
j ) {
208 for (
int k = -2; k < zAxis().bins(); ++k ) {
209 m_rep->SetBinContent( rIndexX( i ), rIndexY(
j ), rIndexZ( k ),
h.binHeight( i,
j, k ) );
210 m_rep->SetBinError( rIndexX( i ), rIndexY(
j ), rIndexZ( k ),
h.binError( i,
j, k ) );
212 if ( i >= 0 &&
j >= 0 && k >= 0 ) {
213 sumwxy +=
h.binHeight( i,
j, k ) *
h.binMeanX( i,
j, k ) *
h.binMeanY( i,
j, k );
214 sumwxz +=
h.binHeight( i,
j, k ) *
h.binMeanX( i,
j, k ) *
h.binMeanZ( i,
j, k );
215 sumwyz +=
h.binHeight( i,
j, k ) *
h.binMeanY( i,
j, k ) *
h.binMeanZ( i,
j, k );
222 m_rep->SetEntries(
h.allEntries() );
225 std::vector<double> stat( 11 );
237 m_rep->PutStats( &stat.front() );