Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

SFH1F.C

Go to the documentation of this file.
00001 
00026 #include "jbltools/sfh/SFH1F.h"
00027 #include "jbltools/sfh/FloatFunBase.h"
00028 #include "jbltools/sfh/BaseCutBase.h"
00029 #include "jbltools/sfh/FillIterator.h"
00030 
00031 // system headers
00032 #include <iostream>
00033 
00034 static const char *ident="@(#)$Id: SFH1F.C,v 1.16 2005/08/23 12:05:44 blist Exp $";
00035 
00036 SFH1F::SFH1F (const char* name, 
00037               const char* title, 
00038               Int_t nbinsx, Axis_t xlow, Axis_t xup,
00039               const ROListPoR& hhl, 
00040               const FloatFunPoR& xfun_, 
00041               const BaseCutPoR& cut_, 
00042               const FloatFunPoR& wfun_, 
00043               const FillIteratorPoR& iter_) 
00044 : RegH1F (name, title, nbinsx, xlow, xup, hhl), 
00045   xfun(xfun_.pff), cut(cut_.pbc), wfun(wfun_.pff), iter(iter_.pfi) 
00046 {
00047   checkIterators(name);
00048 }
00049   
00050   
00051 SFH1F::SFH1F (const char* name, 
00052               const char* title, 
00053               Int_t nbinsx, const Float_t* xbins,
00054               const ROListPoR& hhl,
00055               const FloatFunPoR& xfun_, 
00056               const BaseCutPoR& cut_, 
00057               const FloatFunPoR& wfun_, 
00058               FillIteratorPoR iter_) 
00059 : RegH1F (name, title, nbinsx, xbins, hhl), 
00060   xfun(xfun_.pff), cut(cut_.pbc), wfun(wfun_.pff), iter(iter_.pfi) 
00061 {
00062   checkIterators(name);
00063 }
00064 
00065 SFH1F::SFH1F (const char* name, 
00066               const char* title, 
00067               Int_t nbinsx, const Double_t* xbins,
00068               const ROListPoR& hhl, 
00069               const FloatFunPoR& xfun_, 
00070               const BaseCutPoR& cut_, 
00071               const FloatFunPoR& wfun_, 
00072               FillIteratorPoR iter_) 
00073 : RegH1F (name, title, nbinsx, xbins, hhl), 
00074   xfun(xfun_.pff), cut(cut_.pbc), wfun(wfun_.pff), iter(iter_.pfi) 
00075 {
00076   checkIterators(name);
00077 }
00078 
00079 SFH1F::SFH1F (const char* name, 
00080               const char* title, 
00081               const Binning& binning,
00082               const ROListPoR& hhl, 
00083               const FloatFunPoR& xfun_, 
00084               const BaseCutPoR& cut_, 
00085               const FloatFunPoR& wfun_, 
00086               FillIteratorPoR iter_) 
00087 : RegH1F (name, title, binning, hhl), 
00088   xfun(xfun_.pff), cut(cut_.pbc), wfun(wfun_.pff), iter(iter_.pfi) 
00089 {
00090   checkIterators(name);
00091 }
00092 
00093 
00094 SFH1F::SFH1F (const char* name, 
00095               const char* title, 
00096               const TH1F& source, 
00097               const ROListPoR& hhl,
00098               const FloatFunPoR& xfun_,          
00099               const BaseCutPoR& cut_, 
00100               const FloatFunPoR& wfun_, 
00101               FillIteratorPoR iter_) 
00102 : RegH1F (name, title, source, hhl), 
00103   xfun(xfun_.pff), cut(cut_.pbc), wfun(wfun_.pff), iter(iter_.pfi) 
00104 {
00105   if (name) SetName (name);
00106   if (title) SetTitle (title);
00107   // we want something self-filling => erease original histogram content!
00108   for (int i = 0; i < this->GetNbinsX(); ++i) this->SetBinContent (i, 0.);
00109 }
00110 
00111 SFH1F::~SFH1F() {}
00112   
00113 void SFH1F::Fill() {
00114   if (!xfun) return;
00115   if (!iter || iter->reset()) {
00116     do {
00117       if (!cut || (*cut)()) {
00118         Float_FF w = wfun ? (*wfun)() : 1.;
00119         this->TH1F::Fill ((*xfun)(), w);
00120       } 
00121     } while (iter && iter->next());  
00122   }
00123 }
00124 
00125 template<class Fun1, class Fun2>
00126 void SFH1F::checkTwoIterators(const char *name, 
00127                               const char *fun1name, Fun1 *fun1, 
00128                               const char *fun2name, Fun2 *fun2) {
00129   if (fun1 && fun1->getIterator() && 
00130       fun2  && fun2->getIterator() &&
00131       fun1->getIterator() != fun2->getIterator()) {
00132     std::cerr << "SFH1F: Iterators '" << fun1->getIterator()->getName() 
00133               << "' of " << fun1name
00134               << " '" << fun1->getName() << "'"
00135               << " and '" << fun2->getIterator()->getName() << "' of " << fun2name
00136               << " '" << fun2->getName() << "'"
00137               << " are different for histogram "
00138               << name << "!\n";
00139   }
00140   assert (!fun1 || !fun1->getIterator() || !fun2  || !fun2->getIterator()  || fun1->getIterator() == fun2->getIterator());
00141 }                       
00142 template<class Fun>
00143 void SFH1F::checkOneIterator (const char *name, 
00144                               const char *funname, 
00145                                     Fun  *fun) {
00146   if (fun && fun->getIterator()) {
00147     if (iter) {
00148       if (fun->getIterator() != iter) {
00149         std::cerr << "SFH1F: Iterator '" 
00150                   << fun->getIterator()->getName() 
00151                   << "' of " << funname 
00152                   << " '" << fun->getName() << "'"
00153                   << " and iter '" << iter->getName() 
00154                   << "'are different for histogram "
00155                   << name << "!\n";
00156       }
00157     }
00158     else {
00159 #if(DEBUG>=2)      
00160       std::cerr << "SFH1F: Iterator '" 
00161                 << fun->getIterator()->getName() << "' of " 
00162                 << funname
00163                 << " '" << fun->getName() << "'"
00164                 << " used as iterator for histogram "
00165                 << name << ".\n";
00166 #endif
00167       iter = const_cast<FillIterator *>(fun->getIterator());
00168     }
00169   }
00170   assert (!fun || !fun->getIterator() || fun->getIterator() == iter);
00171 }                       
00172 
00173 void SFH1F::checkIterators(const char *name) {
00174   checkTwoIterators (name, "xfun", xfun, "cut",     cut);
00175   checkTwoIterators (name, "xfun", xfun, "wfun",    wfun);
00176   checkTwoIterators (name, "wfun", wfun, "cut",     cut);
00177 
00178   checkOneIterator (name, "xfun",    xfun);
00179   checkOneIterator (name, "wfun",    wfun);
00180   checkOneIterator (name, "cut",     cut);
00181 }
00182 
00183 

Generated on Thu Oct 26 12:52:59 2006 for SFH by doxygen 1.3.2