Anaphe Home Page Reference Documentation

Main Page     Namespaces     Classes     Source Code    

Builder.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // 
00004 // Copyright (C) CERN, Geneva 
00005 // 
00006 
00007 #include <assert.h>
00008 
00009 #include <algorithm>
00010 #include "CHBook/CHBook.h"
00011 #include "CHBook/globalFunctions.h"
00012 #include "CHBook/CHBookHisto.h"
00013 #include "CHBook/CHBookHisto2.h"
00014 #include "Builder.h"
00015 
00016 
00017 namespace Anaphe {
00018 
00019 namespace AIDA_HBook {
00020 
00021 
00022 
00023 
00025 //                             //
00026 // constructors and destructor //
00027 //                             //
00029 
00030 Builder::Builder(void)
00031   : silent(false)
00032 {
00033   // nop
00034 }
00035 
00036 
00037 
00038 
00039 Builder::Builder(const Builder& rhs)
00040   : silent(rhs.silent)
00041 {
00042   // nop
00043 }
00044 
00045 
00046 
00047 
00048 Builder::~Builder(void)
00049 {
00050   // nop
00051 }
00052 
00053 
00054 
00055 const Builder& Builder::operator=(const Builder& rhs)
00056 {
00057   silent = rhs.silent;
00058   return *this;
00059 }
00060 
00061 
00062 
00063 
00065 //                //
00066 // public methods //
00067 //                //
00069 
00070 void Builder::noWarnings(const bool& b)
00071 {
00072   silent = b;
00073 }
00074 
00075 
00076 
00077 
00078 CHBookHisto* Builder::buildFrom(const HistoParameters1D& hp, const int& id)
00079 {
00080   // cerr << "checking consistency " << endl;
00081   bool ok = hp.consistent();
00082   if ( ok ) {
00083     // cerr << "  consistent parameters " << endl;
00084     return makeNewCHBookHisto(hp, id);
00085   } else {
00086     //cerr << "INconsistent parameters " << endl;
00087     return 0;
00088   }
00089 }
00090 
00091 
00092 
00093 
00094 CHBookHisto2* Builder::buildFrom(const HistoParameters2D& hp, const int& id)
00095 {
00096   if (hp.consistent()) return makeNewCHBookHisto2(hp, id);
00097   else return 0; 
00098 }
00099 
00100 
00101 
00102 
00104 //                 //
00105 // private methods //
00106 //                 //
00108 
00109 CHBookHisto* Builder::makeNewCHBookHisto(const HistoParameters1D& hp,
00110                                                const int& id) const
00111 {
00112   CHBookHisto* h = 0;
00113   // create the empty histo with fixed- or variable-width bins as required
00114   AIDA_STD::vector<float> floatVec;
00115   for (AIDA_STD::vector<double>::const_iterator i = hp.edgesX().begin();
00116        i != hp.edgesX().end(); ++i) floatVec.push_back(static_cast<float>(*i));
00117 
00118   if (floatVec.empty()) {
00119     h = new CHBookHisto(id, hp.title().c_str(), hp.nbX(), 
00120                         hp.lowX(), hp.highX());
00121   } else {
00122     h = new CHBookHisto(id, hp.title().c_str(), floatVec);
00123   }
00124   assert (h != 0);
00125 
00126   // make vector of pairs for CHBook function
00127   AIDA_STD::vector<AIDA_STD::pair<float,float> > vec;
00128   extractPairs(hp, vec);
00129   // fill histo
00130   if (h) pokeCHBookHisto(*h, hp.meanX(), hp.rmsX(), hp.ebe(), hp.nev(), vec);
00131 
00132   return h;
00133 }
00134 
00135 
00136 
00137 
00138 CHBookHisto2* Builder::makeNewCHBookHisto2(const HistoParameters2D& hp, 
00139                                                  const int& id) const
00140 {
00141   CHBookHisto2* h = 0;
00142   // 2D variable binning not available in HBOOK - tell user but continue anyway
00143   if  (!hp.edgesX().empty() || !hp.edgesY().empty()) no2DVarError();
00144   // create the empty histo
00145   h = new CHBookHisto2(id, hp.title().c_str(), hp.nbX(), hp.lowX(), hp.highX(), 
00146                        hp.nbY(), hp.lowY(), hp.highY());
00147   // make vector of vectors of (value, average error) pairs for CHBook function
00148   AIDA_STD::vector<AIDA_STD::vector<AIDA_STD::pair<float,float> > > vec;
00149   extractPairs(hp, vec);
00150   // fill histo
00151   if (h) pokeCHBookHisto2(*h, hp.meanX(), hp.rmsX(), hp.meanY(), hp.rmsY(), 
00152                           hp.ebe(), hp.nev(), vec);
00153   return h;
00154 }
00155 
00156 
00157 
00158 
00159 void Builder::extractPairs(const HistoParameters1D& hp,
00160   AIDA_STD::vector<AIDA_STD::pair<float,float> >& vec) const
00161 {
00162   vec.clear();
00163   for (HistoParameters::VecDataCIt i = hp.values().begin(); i != hp.values().end(); ++i) {
00164     vec.push_back(AIDA_STD::make_pair(static_cast<float>(i->height), 
00165                                       static_cast<float>(i->error)  )
00166                   );
00167   }
00168 }
00169 
00170 
00171 
00172 
00173 void Builder::extractPairs(const HistoParameters2D& hp,
00174   AIDA_STD::vector<AIDA_STD::vector<AIDA_STD::pair<float,float> > >& vec) const
00175 {
00176   AIDA_STD::vector<AIDA_STD::pair<float,float> > row;
00177   vec.clear();
00178   for (HistoParameters::VecVecDataCIt i = hp.values().begin(); 
00179        i != hp.values().end(); ++i) {
00180     row.clear();
00181     for (HistoParameters::VecDataCIt j = i->begin(); j != i->end(); ++j) {
00182       row.push_back(AIDA_STD::make_pair(static_cast<float>(j->height),
00183                                         static_cast<float>(j->error)  )
00184                     );
00185     }
00186     vec.push_back(row);
00187   }
00188 }
00189 
00190 
00191 
00192 
00193 void Builder::no2DVarError(void) const
00194 {
00195   errorMessage("variable-binned 2D histos not available in HBOOK - using equal binning");
00196 }
00197 
00198 
00199 
00200 
00201 void Builder::errorMessage(const AIDA_STD::string& msg) const
00202 {
00203   if (!silent) AIDA_STD::cerr << "AIDA_HBook::Builder ERROR: " << msg <<  AIDA_STD::endl;
00204 }
00205 
00206 
00207 
00208 
00209 } // end of namespace AIDA_HBook
00210 
00211 } // end of namespace Anaphe


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