Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

AIDAHist1DVar.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // 
00004 // Copyright (C) CERN, Geneva 
00005 // 
00006 
00007 
00008 
00009 #if defined __i386__ || defined __sun
00010 # include <strstream>
00011 #else
00012 # include <sstream>
00013 #endif
00014 #include <assert.h>
00015 #include "HepUtilities/SimpleTokenizer.h"
00016 #include "Interfaces/IAnnotation.h"
00017 #include "Interfaces/IAnnotationFactory.h"
00018 #include "Interfaces/IHistogramFactory.h"
00019 #include "CHBook/CHBookHisto.h"
00020 #include "CHBook/CHBookHisto2.h"
00021 #include "AIDAHist1DVar.h"
00022 #include "AIDAAxis.h"
00023 
00024 
00025 
00026 using Anaphe::IAnnotation;
00027 using Anaphe::IAxis;
00028 using Anaphe::IHistogramFactory;
00029 using Anaphe::AIDA_HBook::AIDAAxis;
00030 using Anaphe::AIDA_HBook::AIDAHist1DVar;
00031 using Anaphe::CHBookHisto;
00032 using Anaphe::CHBookHisto2;
00033 
00034 
00035 
00037 //                 //
00038 // Con/Destructors //
00039 //                 //
00041 
00042 AIDAHist1DVar::AIDAHist1DVar(const char* name,
00043                              const AIDA_STD::vector<float>& binEdges,
00044                              const IAnnotation* a, 
00045                              const IHistogramFactory* f)
00046   : axis    (0),
00047     ann     (0), 
00048     factory (const_cast<IHistogramFactory*>(f)),
00049     histo   (0), 
00050     ownsHist(true)
00051 {  
00052   IAnnotationFactory* af = createIAnnotationFactory();
00053   assert(af);
00054   if (a) ann = af->create(a); 
00055   else   ann = af->create();
00056   delete af;
00057   int id = 1;
00058   AIDA_STD::string label = ann->find("ID");
00059   if (label != "") id = getIntFromString(label);
00060   histo = new CHBookHisto(id, name, binEdges);
00061   assert(histo);
00062   if (label == "") ann->add("ID", getStringFromInt(histo->id()));
00063   axis = new AIDAAxis(histo, 0, binEdges);  
00064   assert(axis);
00065 
00066 }
00067 
00068 
00069 
00070 
00071 AIDAHist1DVar::AIDAHist1DVar(const CHBookHisto* h, 
00072                              const IHistogramFactory* f)
00073   : axis    (0),
00074     ann     (0),
00075     factory (const_cast<IHistogramFactory*>(f)),
00076     histo   (const_cast<CHBookHisto*>(h)), 
00077     ownsHist(true)
00078 {
00079   assert(histo);
00080   IAnnotationFactory* af = createIAnnotationFactory();
00081   assert(af);
00082   ann = af->create();
00083   delete af;
00084   int id = histo->id();
00085   ann->add("ID", getStringFromInt(id));
00086   int nbins = histo->bins();
00087   AIDA_STD::vector<float> binEdges(nbins+1);
00088   for (int i = 0; i < nbins; ++i) binEdges[i] = histo->binLowerEdge(i);
00089   binEdges[nbins+1] = histo->upperEdge();
00090   axis = new AIDAAxis(histo, 0, binEdges);
00091   assert(axis);
00092 }
00093 
00094 
00095 
00096 
00097 AIDAHist1DVar::~AIDAHist1DVar(void)
00098 {
00099   // first unregister, as this needs the annotation
00100   //  if (myFactory != 0)  myFactory->unregister(this);
00101   // (tell factory to forget about me ...)
00102   delete axis;
00103   delete ann;
00104   if (ownsHist) delete histo;
00105 }
00106 
00107 
00108 
00109 
00111 //                 //
00112 // Public Methods  //
00113 //                 //
00115 
00116 AIDA_STD::string AIDAHist1DVar::title(void) const
00117 {
00118   if (!histo) { crisisMessage("title"); return ""; }
00119   return AIDA_STD::string(histo->getTitle());
00120 }
00121 
00122 
00123 
00124 
00125 void AIDAHist1DVar::setTitle(const AIDA_STD::string& t)
00126 {
00127   if (!histo) { crisisMessage("setTitle"); return; }
00128   histo->setTitle(const_cast<char*>(t.c_str()));
00129 }
00130 
00131 
00132 
00133 
00134 IAnnotation* AIDAHist1DVar::annotation(void)
00135 {
00136   if (!histo) { crisisMessage("annotation"); return 0; }
00137   return ann; 
00138 }
00139 
00140 
00141 
00142 
00143 int AIDAHist1DVar::dimensions(void) const
00144 {
00145   if (!histo) { crisisMessage("dimensions"); return 0; }
00146   return 1;
00147 }
00148 
00149 
00150 
00151 
00152 void AIDAHist1DVar::reset(void)
00153 {
00154   if (!histo) { crisisMessage("reset"); return; }
00155   histo->reset();
00156 }
00157 
00158 
00159 
00160 
00161 int AIDAHist1DVar::entries(void) const
00162 {
00163   if (!histo) { crisisMessage("entries"); return 0; }
00164   return (allEntries() - extraEntries());
00165 }
00166 
00167 
00168 
00169 
00170 int AIDAHist1DVar::allEntries(void) const 
00171 {
00172   if (!histo) { crisisMessage("allEntries"); return 0; }
00173   return histo->entries();
00174 }
00175 
00176 
00177 
00178 
00179 int AIDAHist1DVar::extraEntries(void) const
00180 {
00181   if (!histo) { crisisMessage("extraEntries"); return 0; }
00182   return static_cast<int>((histo->outOfRangeContent()));
00183 }
00184 
00185 
00186 
00187 double AIDAHist1DVar::equivalentBinEntries(void) const
00188 {
00189   if (!histo) { crisisMessage("equivalentBinEntries"); return 0.0; }
00190   return histo->equivalentEntries();
00191 }
00192 
00193 
00194 
00195 
00196 double AIDAHist1DVar::sumBinHeights(void) const
00197 {
00198   if (!histo) { crisisMessage("sumBinHeights"); return 0.0; }
00199   return histo->sum();
00200 }
00201 
00202 
00203 
00204 
00205 double AIDAHist1DVar::sumAllBinHeights(void) const
00206 {
00207   if (!histo) { crisisMessage("sumAllBinHeights"); return 0.0; }
00208   return sumBinHeights() + sumExtraBinHeights();
00209 }
00210 
00211 
00212 
00213 
00214 double AIDAHist1DVar::sumExtraBinHeights(void) const
00215 {
00216   if (!histo) { crisisMessage("sumExtraBinHeights"); return 0.0; }
00217   return (binHeight(IHistogram::UNDERFLOW_BIN)+ 
00218           binHeight(IHistogram::OVERFLOW_BIN)  );
00219 }
00220 
00221 
00222 
00223 
00224 void AIDAHist1DVar::fill(double x, double weight)
00225 {
00226   if (!histo) { crisisMessage("fill"); return; }
00227   histo->fill(static_cast<float>(x), 
00228               static_cast<float>(weight));
00229 }
00230 
00231 
00232 
00233 
00234 int AIDAHist1DVar::binEntries(int index) const
00235 {
00236   if (!histo) { crisisMessage("binEntries"); return 0; }
00237   return static_cast<int>(binHeight(index));
00238 }
00239 
00240 
00241 
00242 
00243 double AIDAHist1DVar::binHeight(int index) const
00244 {
00245   if (!histo) { crisisMessage("binHeight"); return 0.0; }
00246   else {
00247     int i = index;
00248     if      (i == UNDERFLOW_BIN) i = -1;
00249     else if (i ==  OVERFLOW_BIN) i = histo->bins();
00250     return histo->binContent(index);
00251   }
00252 }
00253 
00254 
00255 
00256 
00257 double AIDAHist1DVar::binError(int index) const
00258 {
00259   if (!histo) { crisisMessage("binError"); return 0.0; }
00260   else {
00261     int i = index;
00262     if      (i == UNDERFLOW_BIN) i = -1;
00263     else if (i ==  OVERFLOW_BIN) i = histo->bins();
00264     return histo->binError(index);
00265   }
00266 }
00267 
00268 
00269 
00270 
00271 double AIDAHist1DVar::mean(void) const
00272 {
00273   if (!histo) { crisisMessage("mean"); return 0.0; }
00274   return histo->mean();
00275 }
00276 
00277 
00278 
00279 
00280 double AIDAHist1DVar::rms(void) const
00281 {
00282   if (!histo) { crisisMessage("rms"); return 0.0; }
00283   return histo->sigma();
00284 }
00285 
00286 
00287 
00288 
00289 double AIDAHist1DVar::minBinHeight(void) const
00290 {
00291   if (!histo) { crisisMessage("minBinHeight"); return 0.0; }
00292   return histo->binContent(histo->minBin());
00293 }
00294 
00295 
00296 
00297 int AIDAHist1DVar::minBin(void) const
00298 {
00299   if (!histo) { crisisMessage("minBin"); return -1; }
00300   return histo->minBin();
00301 }
00302 
00303 
00304 
00305 
00306 double AIDAHist1DVar::maxBinHeight(void) const
00307 {
00308   if (!histo) { crisisMessage("maxBinHeight"); return 0.0; }
00309   return histo->binContent(histo->maxBin());
00310 }
00311 
00312 
00313 
00314 
00315 int AIDAHist1DVar::maxBin(void) const
00316 {
00317   if (!histo) { crisisMessage("maxBin"); return -1; }
00318   return histo->maxBin();  
00319 }
00320 
00321 
00322 
00323 
00324 IAxis* AIDAHist1DVar::xAxis(void) const
00325 {
00326   return axis;
00327 }
00328 
00329 
00330 
00331 
00332 int AIDAHist1DVar::coordToIndex(double coord) const
00333 {
00334   return xAxis()->coordToIndex(coord);
00335 }
00336 
00337 
00338 
00339 
00340 AIDA_STD::ostream& AIDAHist1DVar::print(AIDA_STD::ostream& s) const
00341 {
00342   if (!histo) { crisisMessage("print"); return s; }
00343   histo->print();
00344   return s;
00345 }
00346 
00347 
00348 
00349 
00350 AIDA_STD::ostream& AIDAHist1DVar::write(AIDA_STD::ostream& s) const
00351 {
00352   //ND
00353   if (!histo) { crisisMessage("write"); return s; }
00354   return s;
00355 }
00356 
00357 
00358 
00359 
00360 int AIDAHist1DVar::write(const char* file) const
00361 {
00362   //ND
00363   if (!histo) { crisisMessage("write"); return -1; }
00364   return -1;
00365 }
00366 
00367 
00368 
00369 
00370 const CHBookHisto* AIDAHist1DVar::representation(void) const
00371 { 
00372   return histo; 
00373 }
00374 
00375 
00376 
00377 
00379 //                 //
00380 // Private Methods //
00381 //                 //
00383 
00384 int AIDAHist1DVar::checkIndex(int index) const
00385 {
00386   AIDAAxis* ax = dynamic_cast<AIDAAxis*>(axis);
00387   if (ax) return ax->checkIndex(index);
00388   else return -1;
00389 }
00390 
00391 
00392 
00393 
00394 int AIDAHist1DVar::getIntFromString(const AIDA_STD::string& str) const 
00395 {
00396   int ans = 0;
00397   if (str.length() < 1) return false;
00398   AIDA_STD::string s = str;
00399   for (unsigned int i = 0; i < s.length(); ++i) {
00400     if (s[i] == '0') s.erase(0,1);
00401     else break;
00402   }
00403   if (s.length() < 1) return false;
00404   for (unsigned int i = 0; i < s.length(); ++i) {
00405     if (!isdigit(s[i])) return false;
00406   }
00407   ans = atoi(s.c_str());
00408   return (ans > 0) ? ans : 0;
00409 }
00410 
00411 
00412 
00413 
00414 AIDA_STD::string AIDAHist1DVar::getStringFromInt(const int& i) const
00415 {
00416   AIDA_STD::ostrstream ostr;
00417   ostr << i << AIDA_STD::ends;
00418   return ostr.str();
00419 }
00420 
00421 
00422 
00423 
00424 void AIDAHist1DVar::crisisMessage(const AIDA_STD::string& featureName) const
00425 {
00426   AIDA_STD::cerr << "AIDAHist1DVar::" << featureName
00427                  << "(...): ERROR! CHBookHisto* implementation = 0"
00428                  << AIDA_STD::endl;
00429 }
00430 
00431 
00432 


Anaphe documentation generated by Doxygen (www.doxygen.org)