14# pragma warning( disable : 2259 )
27 const std::string& title,
int nBins,
double xlow,
29 auto p =
new Histogram1D(
new TH1D( title.c_str(), title.c_str(), nBins, xlow, xup ) );
30 svcLocator->monitoringHub().registerEntity(
"", path,
"histogram:Histogram:double", *p );
35 const std::string& title,
const Edges& e ) {
36 auto p =
new Histogram1D(
new TH1D( title.c_str(), title.c_str(), e.size() - 1, &e.front() ) );
37 svcLocator->monitoringHub().registerEntity(
"", path,
"histogram:Histogram:double", *p );
42 const AIDA::IHistogram1D& hist ) {
45 if ( n ) {
svcLocator->monitoringHub().registerEntity(
"", path,
"histogram:Histogram:double", *n ); }
53 if ( className ==
"AIDA::IHistogram1D" )
return const_cast<AIDA::IHistogram1D*
>( (AIDA::IHistogram1D*)
this );
54 if ( className ==
"AIDA::IHistogram" )
return const_cast<AIDA::IHistogram*
>( (AIDA::IHistogram*)
this );
62 return int( xx * xx + 0.5 );
67 TH1D* imp =
dynamic_cast<TH1D*
>( rep );
68 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation." );
83 if ( initialize_axis ) {
m_axis.initialize(
m_rep->GetXaxis(),
false ); }
84 const TArrayD* a =
m_rep->GetSumw2();
85 if ( !a || ( a && a->GetSize() == 0 ) )
m_rep->Sumw2();
87 m_rep->SetDirectory(
nullptr );
95 for (
int i = 1, n =
m_rep->GetNbinsX(); i <= n; ++i ) {
120 if ( i != AIDA::IAxis::UNDERFLOW_BIN && i != AIDA::IAxis::OVERFLOW_BIN )
m_sumwx += centre * height;
127 std::vector<double> stat( 11 );
137 m_rep->PutStats( &stat.front() );
145 std::vector<double> stat( 11 );
150 if (
std::abs( eqBinEntries ) > std::numeric_limits<double>::epsilon() )
156 m_rep->PutStats( &stat.front() );
163 m_rep->Fill( x, weight );
169 std::string
title = h.title() +
"Copy";
170 if ( h.axis().isFixedBinning() ) {
172 new TH1D(
title.c_str(),
title.c_str(), h.axis().bins(), h.axis().lowerEdge(), h.axis().upperEdge() ) );
175 for (
int i = 0; i < h.axis().bins(); ++i ) { e.push_back( h.axis().binLowerEdge( i ) ); }
177 e.push_back( h.axis().upperEdge() );
178 m_rep.reset(
new TH1D(
title.c_str(),
title.c_str(), e.size() - 1, &e.front() ) );
185 double sumw = h.sumBinHeights();
188 if (
std::abs( h.equivalentBinEntries() ) > std::numeric_limits<double>::epsilon() )
189 sumw2 = ( sumw * sumw ) / h.equivalentBinEntries();
191 double sumwx = h.mean() * h.sumBinHeights();
192 double sumwx2 = ( h.mean() * h.mean() + h.rms() * h.rms() ) * h.sumBinHeights();
195 for (
int i = -2; i <
axis().bins(); ++i ) {
197 m_rep->SetBinContent(
rIndex( i ), h.binHeight( i ) );
198 m_rep->SetBinError(
rIndex( i ), h.binError( i ) );
202 m_rep->SetEntries( h.allEntries() );
204 std::vector<double> stat( 11 );
209 m_rep->PutStats( &stat.front() );
217 for (
int j = 0; j < size; j++ ) {
218 std::string key, value;
221 if (
"Title" == key ) {
title = value; }
224 int isFixedBinning, bins;
225 s >> isFixedBinning >> bins;
227 if ( isFixedBinning ) {
228 s >> lowerEdge >> upperEdge;
229 m_rep.reset(
new TH1D(
title.c_str(),
title.c_str(), bins, lowerEdge, upperEdge ) );
232 edges.resize( bins );
233 for (
int i = 0; i <= bins; ++i ) s >> edges[i];
234 m_rep.reset(
new TH1D(
title.c_str(),
title.c_str(), edges.size() - 1, &edges.front() ) );
241 for (
int i = 0; i <= bins + 1; ++i ) {
250 s >> stats[0] >> stats[1] >> stats[2] >> stats[3];
251 m_rep->PutStats( stats );
258 for (
int i = 0; i <
annotation().size(); i++ ) {
262 const AIDA::IAxis&
axis( this->
axis() );
263 const int isFixedBinning =
axis.isFixedBinning();
264 const int bins =
axis.bins();
265 s << isFixedBinning << bins;
266 if ( isFixedBinning ) {
267 s <<
axis.lowerEdge();
269 for (
int i = 0; i < bins; ++i ) s <<
axis.binLowerEdge( i );
271 s <<
axis.upperEdge();
272 for (
int i = 0; i <= bins + 1; ++i ) s <<
m_rep->GetBinContent( i ) <<
m_rep->GetBinError( i );
274 s <<
m_rep->GetEntries();
276 m_rep->GetStats( stats );
277 s << stats[0] << stats[1] << stats[2] << stats[3];
AIDA::IAnnotation & annotation() override
int allEntries() const override
int binEntries(int index) const override
Number of entries in the corresponding bin (ie the number of times fill was called for this bin).
std::string title() const override
double binHeight(int index) const override
virtual double equivalentBinEntries() const
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
void * cast(const std::string &cl) const override
Manual cast by class name.
bool setTitle(const std::string &title) override
double sumBinHeights() const override
Generic1D< AIDA::IHistogram1D, TH1D > Base
double rms() const override
double binError(int index) const override
virtual int rIndex(int index) const
std::unique_ptr< TH1D > m_rep
int entries() const override
double mean() const override
AIDA implementation for 1 D histograms using ROOT THD1.
StreamBuffer & serialize(StreamBuffer &s)
Serialization mechanism, Serialize the object for reading.
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
Histogram1D()
Standard constructor.
double m_sumwx
cache sumwx when setting contents since I don't have bin mean
bool setRms(double rms)
Update histogram RMS.
std::mutex m_fillSerialization
virtual bool setStatistics(int allEntries, double eqBinEntries, double mean, double rms)
set histogram statistics
void init(const std::string &title, bool initialize_axis=true)
bool fill(double x, double weight) override
Fill the Profile1D with a value and the corresponding weight.
virtual bool setBinContents(int i, int entries, double height, double error, double centre)
set bin content (entries and centre are not used )
void copyFromAida(const AIDA::IHistogram1D &h)
Create new histogram from any AIDA based histogram.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
The stream buffer is a small object collecting object data.
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
GAUDI_API ISvcLocator * svcLocator()
T * getRepresentation(const Q &hist)
std::pair< DataObject *, AIDA::IHistogram1D * > createH1D(ISvcLocator *svcLocator, const std::string &path, const AIDA::IHistogram1D &hist)
Copy constructor.
Gaudi::ParticleID abs(const Gaudi::ParticleID &p)
Return the absolute value for a PID.