00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "Histo3DTranslator.h"
00031 #include "AIDA/IHistogram3D.h"
00032 #include "AIDA_Dev/IDevHistogram3D.h"
00033 #include "AIDA_Dev/IDevHistogramFactory.h"
00034 #include "AIDA/IAxis.h"
00035
00036 #include "DataXML/DataObject.h"
00037
00038 static const std::string emptyString = "";
00039
00041 Anaphe::AIDA_XMLStore::Histo3DTranslator::Histo3DTranslator(const AIDA::IHistogram3D * histo, const std::string & name, const std::string & path ) :
00042 m_histo(histo), m_name(name), m_path(path)
00043 {
00044 }
00046 Anaphe::AIDA_XMLStore::Histo3DTranslator::Histo3DTranslator(const DataXML::DataObject * xmlObject) :
00047 m_element(*xmlObject)
00048 {
00049 }
00050
00051
00052 Anaphe::AIDA_XMLStore::Histo3DTranslator::~Histo3DTranslator()
00053 {
00054 }
00055
00056 Anaphe::AIDA_XMLStore::Histo3DTranslator::Histo3DTranslator(const Anaphe::AIDA_XMLStore::Histo3DTranslator &)
00057 {
00058 }
00059
00060 Anaphe::AIDA_XMLStore::Histo3DTranslator & Anaphe::AIDA_XMLStore::Histo3DTranslator::operator = (const Anaphe::AIDA_XMLStore::Histo3DTranslator &rhs)
00061 {
00062 if (this == &rhs) return *this;
00063
00064 return *this;
00065 }
00066
00067 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::toXML()
00068 {
00069
00070 appendObjectHeader(m_element,"histogram3d",m_name,m_histo->title(),m_path);
00071
00072 appendAnnotation(m_element,m_histo->annotation());
00073 if (!setAxes() ) return false;
00074 if (!setStatistics() ) return false;
00075 if (!setData () ) return false;
00076 return true;
00077
00078 }
00079
00080 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::setAxes()
00081 {
00082 appendAxis (m_element, "x", m_histo->xAxis());
00083 appendAxis (m_element, "y", m_histo->yAxis());
00084 appendAxis (m_element, "z", m_histo->zAxis());
00085 return true;
00086 }
00087
00088
00091
00092 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::setStatistics()
00093 {
00094 DataXML::DataObject allStatisticsElement;
00095 allStatisticsElement.setName("statistics");
00096 allStatisticsElement.setAttribute("entries", toString(m_histo->entries()));
00097
00098
00099 appendStatistics(allStatisticsElement, "x", m_histo->meanX(), m_histo->rmsX());
00100 appendStatistics(allStatisticsElement, "y", m_histo->meanY(), m_histo->rmsY());
00101 appendStatistics(allStatisticsElement, "z", m_histo->meanZ(), m_histo->rmsZ());
00102 m_element.appendChild(allStatisticsElement);
00103 return true;
00104 }
00105
00106
00107 bool Anaphe::AIDA_XMLStore::Histo3DTranslator::setData()
00108 {
00109
00110
00111 DataXML::DataObject dataElement;
00112 dataElement.setName("data2d");
00113 const int nbx = (m_histo->xAxis()).bins();
00114 const int nby = (m_histo->yAxis()).bins();
00115 const int nbz = (m_histo->zAxis()).bins();
00116 for (int i = -2; i < nbx; ++i) {
00117 for (int j = -2; j < nby; ++j ) {
00118 for (int k = -2; k < nbz; ++j ) {
00119 int entries = m_histo->binEntries(i,j,k);
00120 double height = m_histo->binHeight (i,j,k);
00121 double error = m_histo->binError (i,j,k);
00122 double binMeanX = m_histo->binMeanX (i,j,k);
00123 double binMeanY = m_histo->binMeanY (i,j,k);
00124 double binMeanZ = m_histo->binMeanZ (i,j,k);
00125 appendHisto3DBinData(dataElement, i, j, k, entries, height, error, binMeanX, binMeanY, binMeanZ);
00126 }
00127 }
00128 }
00129 m_element.appendChild(dataElement);
00130 return true;
00131 }
00132
00134
00135 AIDA::Dev::IDevHistogram3D * Anaphe::AIDA_XMLStore::Histo3DTranslator::createFromXML(AIDA::Dev::IDevHistogramFactory& factory)
00136 {
00137
00138 std::string title, options;
00139 getObjectHeader(m_element,m_name,title,m_path,options);
00140
00141
00142 AnnotationData annoData;
00143 getAnnotation(m_element,annoData);
00144
00145
00146 int numberOfBinsX = 0;
00147 double lowerEdgeX = 0;
00148 double upperEdgeX = 0;
00149 std::vector<double> edgesX;
00150 getAxis(m_element,"x",numberOfBinsX,lowerEdgeX,upperEdgeX,edgesX);
00151 int numberOfBinsY = 0;
00152 double lowerEdgeY = 0;
00153 double upperEdgeY = 0;
00154 std::vector<double> edgesY;
00155 getAxis(m_element,"y",numberOfBinsY,lowerEdgeY,upperEdgeY,edgesY);
00156 int numberOfBinsZ = 0;
00157 double lowerEdgeZ = 0;
00158 double upperEdgeZ = 0;
00159 std::vector<double> edgesZ;
00160 getAxis(m_element,"z",numberOfBinsZ,lowerEdgeZ,upperEdgeZ,edgesZ);
00161
00162
00163
00164
00165 AIDA::Dev::IDevHistogram3D * h = 0;
00166 if (edgesX.empty() )
00167
00168 h = factory.createHistogram3D( title, numberOfBinsX, lowerEdgeX, upperEdgeX, numberOfBinsY, lowerEdgeY, upperEdgeY, numberOfBinsZ, lowerEdgeZ, upperEdgeZ );
00169 else
00170
00171 h = factory.createHistogram3D( title, edgesX, edgesY, edgesZ, emptyString );
00172
00173
00174 double rmsX,rmsY,rmsZ = 0;
00175 const DataXML::DataObject * statElement = m_element.getChild("statistics");
00176 if (statElement) {
00177 double mean,skew = 0;
00178 getStatistics(*statElement,"x",mean,rmsX,skew);
00179 getStatistics(*statElement,"y",mean,rmsY,skew);
00180 getStatistics(*statElement,"z",mean,rmsZ,skew);
00181 }
00182
00183
00184 AIDA::IAnnotation & anno = h->annotation();
00185 setAnnotation(&anno,annoData);
00186
00187
00188
00189 const DataXML::DataObject * dataElement = m_element.getChild("data3d");
00190 if (dataElement) {
00191 for (std::vector<DataXML::DataObject>::const_iterator binElement = dataElement->children().begin(); binElement != dataElement->children().end(); ++binElement) {
00192 if (binElement->name() == "bin3d") {
00193 int xbin,ybin, zbin = -999;
00194 int entries = 0;
00195
00196 double height, error, wMeanX, wMeanY, wMeanZ, wRmsX, wRmsY, wRmsZ, error2, rms = 0;
00197 getHisto3DBinData(*binElement,xbin,ybin,zbin,entries,height,error,wMeanX,wMeanY,wMeanZ,wRmsX,wRmsY,wRmsZ, error2, rms);
00198
00199
00200 h->setBinContents(xbin,ybin,zbin,entries, height, error, wMeanX, wMeanY,wMeanZ);
00201 }
00202 }
00203 }
00204 h->setRms(rmsX,rmsY,rmsZ);
00205
00206 return h;
00207 }