14 # pragma warning( disable : 2259 )
20 # pragma warning( disable : 4996 )
34 auto p =
new Histogram1D(
new TH1D( title.
c_str(), title.
c_str(), nBins, xlow, xup ) );
41 auto p =
new Histogram1D(
new TH1D( title.
c_str(), title.
c_str(), e.size() - 1, &e.front() ) );
47 const AIDA::IHistogram1D& hist ) {
48 TH1D*
h = getRepresentation<AIDA::IHistogram1D, TH1D>( hist );
49 auto n = (
h ?
new Histogram1D(
new TH1D( *
h ) ) :
nullptr );
58 if ( className ==
"AIDA::IHistogram1D" )
return const_cast<AIDA::IHistogram1D*
>( (AIDA::IHistogram1D*)
this );
59 if ( className ==
"AIDA::IHistogram" )
return const_cast<AIDA::IHistogram*
>( (AIDA::IHistogram*)
this );
65 if ( binHeight(
index ) <= 0 )
return 0;
66 double xx = binHeight(
index ) / binError(
index );
67 return int( xx * xx + 0.5 );
72 TH1D* imp =
dynamic_cast<TH1D*
>( rep );
73 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
82 init( m_rep->GetTitle() );
87 m_classType =
"IHistogram1D";
88 if ( initialize_axis ) { m_axis.initialize( m_rep->GetXaxis(),
false ); }
89 const TArrayD* a = m_rep->GetSumw2();
90 if ( !a || ( a && a->GetSize() == 0 ) ) m_rep->Sumw2();
92 m_rep->SetDirectory(
nullptr );
100 for (
int i = 1,
n = m_rep->GetNbinsX(); i <=
n; ++i ) {
101 m_sumwx += m_rep->GetBinContent( i ) * m_rep->GetBinCenter( i );
102 m_sumEntries += m_rep->GetBinContent( i );
109 return Base::reset();
116 init( m_rep->GetTitle() );
122 m_rep->SetBinContent( rIndex( i ), height );
123 m_rep->SetBinError( rIndex( i ), error );
125 if ( i != AIDA::IAxis::UNDERFLOW_BIN && i != AIDA::IAxis::OVERFLOW_BIN ) m_sumwx += centre * height;
126 m_sumEntries += entries;
131 m_rep->SetEntries( m_sumEntries );
134 stat[0] = sumBinHeights();
137 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
141 stat[3] = ( mean * mean + rms * rms ) * sumBinHeights();
142 m_rep->PutStats( &stat.
front() );
148 m_rep->SetEntries( allEntries );
152 stat[0] = sumBinHeights();
156 stat[1] = ( sumBinHeights() * sumBinHeights() ) / eqBinEntries;
158 stat[2] = mean * sumBinHeights();
160 stat[3] = ( mean * mean + rms * rms ) * sumBinHeights();
161 m_rep->PutStats( &stat.
front() );
167 auto guard = std::scoped_lock{ m_fillSerialization };
168 m_rep->Fill( x, weight );
175 if (
h.axis().isFixedBinning() ) {
177 new TH1D( title.
c_str(), title.
c_str(),
h.axis().bins(),
h.axis().lowerEdge(),
h.axis().upperEdge() ) );
180 for (
int i = 0; i <
h.axis().bins(); ++i ) { e.
push_back(
h.axis().binLowerEdge( i ) ); }
182 e.push_back(
h.axis().upperEdge() );
183 m_rep.reset(
new TH1D( title.
c_str(), title.
c_str(), e.size() - 1, &e.front() ) );
185 m_axis.initialize( m_rep->GetXaxis(),
false );
190 double sumw =
h.sumBinHeights();
194 sumw2 = ( sumw * sumw ) /
h.equivalentBinEntries();
196 double sumwx =
h.mean() *
h.sumBinHeights();
197 double sumwx2 = (
h.mean() *
h.mean() +
h.rms() *
h.rms() ) *
h.sumBinHeights();
200 for (
int i = -2; i < axis().bins(); ++i ) {
202 m_rep->SetBinContent( rIndex( i ),
h.binHeight( i ) );
203 m_rep->SetBinError( rIndex( i ),
h.binError( i ) );
207 m_rep->SetEntries(
h.allEntries() );
214 m_rep->PutStats( &stat.
front() );
222 for (
int j = 0;
j <
size;
j++ ) {
225 if ( !annotation().addItem(
key, value ) ) { annotation().setValue(
key, value ); };
226 if (
"Title" ==
key ) { title = value; }
228 double lowerEdge, upperEdge, binHeight, binError;
229 int isFixedBinning, bins;
230 s >> isFixedBinning >> bins;
232 if ( isFixedBinning ) {
233 s >> lowerEdge >> upperEdge;
234 m_rep.reset(
new TH1D( title.
c_str(), title.
c_str(), bins, lowerEdge, upperEdge ) );
238 for (
int i = 0; i <= bins; ++i ) s >> edges[i];
239 m_rep.reset(
new TH1D( title.
c_str(), title.
c_str(), edges.size() - 1, &edges.front() ) );
241 m_axis.initialize( m_rep->GetXaxis(),
true );
246 for (
int i = 0; i <= bins + 1; ++i ) {
247 s >> binHeight >> binError;
248 m_rep->SetBinContent( i, binHeight );
249 m_rep->SetBinError( i, binError );
253 m_rep->SetEntries( allEntries );
255 s >> stats[0] >> stats[1] >> stats[2] >> stats[3];
256 m_rep->PutStats( stats );
262 s << static_cast<int>( annotation().
size() );
263 for (
int i = 0; i < annotation().size(); i++ ) {
264 s << annotation().key( i );
265 s << annotation().value( i );
267 const AIDA::IAxis& axis( this->axis() );
268 const int isFixedBinning = axis.isFixedBinning();
269 const int bins = axis.bins();
270 s << isFixedBinning << bins;
271 if ( isFixedBinning ) {
272 s << axis.lowerEdge();
274 for (
int i = 0; i < bins; ++i )
s << axis.binLowerEdge( i );
276 s << axis.upperEdge();
277 for (
int i = 0; i <= bins + 1; ++i )
s << m_rep->GetBinContent( i ) << m_rep->GetBinError( i );
279 s << m_rep->GetEntries();
281 m_rep->GetStats( stats );
282 s << stats[0] << stats[1] << stats[2] << stats[3];