4 #pragma warning(disable:2259)
10 #pragma warning(disable:4996)
13 #include "GaudiKernel/DataObject.h"
14 #include "GaudiKernel/ObjectFactory.h"
36 bool fill (
double x,
double y,
double z,
double weight)
override;
38 virtual bool setBinContents(
int i,
int j,
int k,
int entries,
double height,
double error,
double centreX,
double centreY,
double centreZ );
40 virtual bool setRms(
double rmsX,
double rmsY,
double rmsZ);
42 bool reset()
override;
44 void* cast(
const std::string & className)
const override;
46 void copyFromAida(
const AIDA::IHistogram3D &
h);
48 const CLID&
clID()
const override {
return classID(); }
62 TH3D* imp =
dynamic_cast<TH3D*
>(rep);
63 if ( !imp )
throw std::runtime_error(
"Cannot adopt native histogram representation.");
65 m_xAxis.initialize(m_rep->GetXaxis(),
true);
66 m_yAxis.initialize(m_rep->GetYaxis(),
true);
67 m_zAxis.initialize(m_rep->GetZaxis(),
true);
68 const TArrayD* a = m_rep->GetSumw2();
69 if ( !a || (a && a->GetSize()==0) ) m_rep->Sumw2();
70 setTitle(m_rep->GetTitle());
75 std::pair<DataObject*,AIDA::IHistogram3D*>
76 Gaudi::createH3D(
const std::string& title,
int nBinsX,
double xlow,
double xup,
int nBinsY,
double ylow,
double yup,
int nBinsZ,
double zlow,
double zup) {
77 auto p =
new Histogram3D(
new TH3D(title.c_str(),title.c_str(),nBinsX,xlow,xup,nBinsY,ylow,yup,nBinsZ,zlow,zup));
82 std::pair<DataObject*,AIDA::IHistogram3D*>
83 Gaudi::createH3D(
const std::string& title,
const Edges& eX,
const Edges& eY,
const Edges& eZ) {
84 auto p =
new Histogram3D(
new TH3D(title.c_str(),title.c_str(),eX.size()-1,&eX.front(), eY.size()-1,&eY.front(), eZ.size()-1,&eZ.front()));
88 std::pair<DataObject*,AIDA::IHistogram3D*>
Gaudi::createH3D(
const AIDA::IHistogram3D& hist) {
89 TH3D *
h = getRepresentation<AIDA::IHistogram3D,TH3D>(hist);
90 Histogram3D *
n = h ?
new Histogram3D(
new TH3D(*h)) : nullptr;
102 m_rep->SetDirectory(
nullptr);
106 adoptRepresentation(rep);
110 m_rep->SetDirectory(
nullptr);
115 m_rep->SetBinContent(rIndexX(i), rIndexY(j), rIndexZ(k), height);
116 m_rep->SetBinError(rIndexX(i), rIndexY(j), rIndexZ(k), error);
118 if (i >=0 && j >= 0 && k >= 0) {
119 m_sumwx += centreX*height;
120 m_sumwy += centreY*height;
121 m_sumwz += centreZ*height;
123 m_sumEntries += entries;
137 m_rep->Fill ( x , y, z, weight );
142 if (className ==
"AIDA::IHistogram3D") {
143 return (AIDA::IHistogram3D*)
this;
145 else if (className ==
"AIDA::IHistogram") {
146 return (AIDA::IHistogram*)
this;
154 #pragma warning(push)
155 #pragma warning(disable:1572)
158 m_rep->SetEntries(m_sumEntries);
159 std::vector<double> stat(11);
161 stat[0] = sumBinHeights();
163 if (equivalentBinEntries() != 0)
164 stat[1] = ( sumBinHeights() * sumBinHeights() ) / equivalentBinEntries();
167 if ( sumBinHeights() != 0 ) meanX = m_sumwx/ sumBinHeights();
168 stat[3] = ( meanX*meanX + rmsX*rmsX )* sumBinHeights();
171 if ( sumBinHeights() != 0 ) meanY = m_sumwy/ sumBinHeights();
172 stat[5] = ( meanY*meanY + rmsY*rmsY )* sumBinHeights();
176 if ( sumBinHeights() != 0 ) meanZ = m_sumwz/ sumBinHeights();
177 stat[8] = ( meanZ*meanZ + rmsZ*rmsZ )* sumBinHeights();
180 m_rep->PutStats(&stat.front());
186 const char* tit = h.title().c_str();
187 if (h.xAxis().isFixedBinning() && h.yAxis().isFixedBinning() && h.zAxis().isFixedBinning() ) {
188 m_rep.reset(
new TH3D(tit,tit,
189 h.xAxis().bins(), h.xAxis().lowerEdge(), h.xAxis().upperEdge(),
190 h.yAxis().bins(), h.yAxis().lowerEdge(), h.yAxis().upperEdge(),
191 h.zAxis().bins(), h.zAxis().lowerEdge(), h.zAxis().upperEdge() ) );
195 for (
int i =0;
i < h.xAxis().bins(); ++
i)
196 eX.push_back(h.xAxis().binLowerEdge(
i));
198 eX.push_back(h.xAxis().upperEdge() );
199 for (
int i =0;
i < h.yAxis().bins(); ++
i)
200 eY.push_back(h.yAxis().binLowerEdge(
i));
202 eY.push_back(h.yAxis().upperEdge() );
203 for (
int i =0;
i < h.zAxis().bins(); ++
i)
204 eZ.push_back(h.zAxis().binLowerEdge(
i));
206 eZ.push_back(h.zAxis().upperEdge() );
207 m_rep.reset(
new TH3D(tit,tit,eX.size()-1,&eX.front(),eY.size()-1,&eY.front(),eZ.size()-1,&eZ.front()) );
209 m_xAxis.initialize(m_rep->GetXaxis(),
true);
210 m_yAxis.initialize(m_rep->GetYaxis(),
true);
211 m_zAxis.initialize(m_rep->GetZaxis(),
true);
212 const TArrayD* a = m_rep->GetSumw2();
213 if ( !a || (a && a->GetSize()==0) ) m_rep->Sumw2();
220 double sumw = h.sumBinHeights();
222 if (h.equivalentBinEntries() != 0)
223 sumw2 = ( sumw * sumw ) /h.equivalentBinEntries();
224 double sumwx = h.meanX()*h.sumBinHeights();
225 double sumwx2 = (h.meanX()*h.meanX() + h.rmsX()*h.rmsX() )*h.sumBinHeights();
226 double sumwy = h.meanY()*h.sumBinHeights();
227 double sumwy2 = (h.meanY()*h.meanY() + h.rmsY()*h.rmsY() )*h.sumBinHeights();
228 double sumwz = h.meanZ()*h.sumBinHeights();
229 double sumwz2 = (h.meanZ()*h.meanZ() + h.rmsZ()*h.rmsZ() )*h.sumBinHeights();
235 for (
int i=-2;
i < xAxis().bins(); ++
i) {
236 for (
int j=-2; j < yAxis().bins(); ++j) {
237 for (
int k=-2; k < zAxis().bins(); ++k) {
238 m_rep->SetBinContent(rIndexX(
i), rIndexY(j), rIndexZ(k), h.binHeight(
i,j,k) );
239 m_rep->SetBinError(rIndexX(
i), rIndexY(j), rIndexZ(k), h.binError(
i,j,k) );
241 if (
i >= 0 && j >= 0 && k >= 0) {
242 sumwxy += h.binHeight(
i,j,k)*h.binMeanX(
i,j,k)*h.binMeanY(
i,j,k);
243 sumwxz += h.binHeight(
i,j,k)*h.binMeanX(
i,j,k)*h.binMeanZ(
i,j,k);
244 sumwyz += h.binHeight(
i,j,k)*h.binMeanY(
i,j,k)*h.binMeanZ(
i,j,k);
251 m_rep->SetEntries(h.allEntries());
254 std::vector<double> stat(11);
266 m_rep->PutStats(&stat.front());
GAUDI_API void fill(AIDA::IHistogram1D *histo, const double value, const double weight=1.0)
simple function to fill AIDA::IHistogram1D objects
static const CLID & classID()
std::vector< double > Edges
void * cast(const std::string &className) const override
Introspection method.
virtual bool setBinContents(int i, int j, int k, int entries, double height, double error, double centreX, double centreY, double centreZ)
Fast filling method for a given bin. It can be also the over/underflow bin.
Histogram3D()
Standard Constructor.
AIDA implementation for 2 D histograms using ROOT THD2.
const CLID & clID() const override
Retrieve reference to class defininition identifier.
bool setTitle(const std::string &title) override
Set the title of the object.
bool fill(double x, double y, double z, double weight) override
Fill bin content.
void copyFromAida(const AIDA::IHistogram3D &h)
Create new histogram from any AIDA based histogram.
std::unique_ptr< IMPLEMENTATION > m_rep
Reference to underlying implementation.
std::pair< DataObject *, AIDA::IHistogram3D * > createH3D(const AIDA::IHistogram3D &hist)
Copy constructor.
virtual bool setRms(double rmsX, double rmsY, double rmsZ)
Sets the rms of the histogram.
void adoptRepresentation(TObject *rep) override
Adopt ROOT histogram representation.
unsigned int CLID
Class ID definition.
#define DECLARE_DATAOBJECT_FACTORY(x)
A DataObject is the base class of any identifiable object on any data store.
Helper functions to set/get the application return code.
Common AIDA implementation stuff for histograms and profiles using ROOT implementations.