Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

AIDAProfileHist.cpp

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


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