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

SFMatrixOfHistograms.C

Go to the documentation of this file.
00001 
00027 #include "jbltools/sfh/SFMatrixOfHistograms.h"
00028 #include "jbltools/sfh/BaseCutBase.h"
00029 #include "jbltools/sfh/FloatFunBase.h"
00030 #include "jbltools/sfh/BinningFun.h"
00031 #include "jbltools/sfh/ROList.h"
00032 #include "jbltools/sfh/SFH1F.h"
00033 #include "jbltools/sfh/FillIterator.h"
00034 
00035 #include <cassert>
00036 #include <iostream>
00037 
00038 static const char *ident="@(#)$Id: SFMatrixOfHistograms.C,v 1.18 2005/08/23 12:05:44 blist Exp $";
00039 
00040 SFMatrixOfHistograms::SFMatrixOfHistograms (const char* name_, 
00041                                             const char* title_, 
00042                                             const ROListPoR& hhl, 
00043                                             const FloatFunPoR& xfun_, 
00044                                             const BaseCutPoR& cut_,  
00045                                             const FloatFunPoR& wfun_, 
00046                                             const BinningFunPoR& binning1_, 
00047                                             const BinningFunPoR& binning2_, 
00048                                             const FillIteratorPoR& iter_) 
00049 :  MatrixOfHistograms  (name_, title_, hhl, binning1_, binning2_),
00050    xfun (xfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00051 {
00052   checkIterators(name_);
00053 }              
00054     
00055 SFMatrixOfHistograms::SFMatrixOfHistograms (const char* name_, 
00056                                             const char* title_, 
00057                                             Int_t nbinsx, 
00058                                             Axis_t xlow, 
00059                                             Axis_t xup, 
00060                                             const ROListPoR& hhl, 
00061                                             const FloatFunPoR& xfun_,
00062                                             const BaseCutPoR& cut_, 
00063                                             const FloatFunPoR& wfun_, 
00064                                             const BinningFunPoR& binning1_, 
00065                                             const BinningFunPoR& binning2_, 
00066                                             const FillIteratorPoR& iter_) 
00067 :  MatrixOfHistograms  (name_, title_, nbinsx, xlow, xup, hhl, binning1_, binning2_),
00068    xfun (xfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00069 {
00070   checkIterators(name_);
00071 }              
00072     
00073 SFMatrixOfHistograms::SFMatrixOfHistograms (const char* name_, 
00074                                             const char* title_, 
00075                                             Int_t nbinsx, 
00076                                             const Double_t *xbins, 
00077                                             const ROListPoR& hhl, 
00078                                             const FloatFunPoR& xfun_,  
00079                                             const BaseCutPoR& cut_, 
00080                                             const FloatFunPoR& wfun_, 
00081                                             const BinningFunPoR& binning1_, 
00082                                             const BinningFunPoR& binning2_, 
00083                                             const FillIteratorPoR& iter_) 
00084 :  MatrixOfHistograms  (name_, title_, nbinsx, xbins, hhl, binning1_, binning2_),
00085    xfun (xfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00086 {
00087   checkIterators(name_);
00088 }              
00089     
00090 SFMatrixOfHistograms::SFMatrixOfHistograms (const char* name_,  
00091                                             const char* title_, 
00092                                             Int_t nbinsx, 
00093                                             const Float_t *xbins, 
00094                                             const ROListPoR& hhl,  
00095                                             const FloatFunPoR& xfun_, 
00096                                             const BaseCutPoR& cut_,  
00097                                             const FloatFunPoR& wfun_, 
00098                                             const BinningFunPoR& binning1_,  
00099                                             const BinningFunPoR& binning2_, 
00100                                             const FillIteratorPoR& iter_) 
00101 :  MatrixOfHistograms  (name_, title_, nbinsx, xbins, hhl, binning1_, binning2_),
00102    xfun (xfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00103 {
00104   checkIterators(name_);
00105 }              
00106     
00107 SFMatrixOfHistograms::SFMatrixOfHistograms (const char* name_,  
00108                                             const char* title_, 
00109                                             const Binning& axisbinning,
00110                                             const ROListPoR& hhl,  
00111                                             const FloatFunPoR& xfun_, 
00112                                             const BaseCutPoR& cut_,  
00113                                             const FloatFunPoR& wfun_, 
00114                                             const BinningFunPoR& binning1_,  
00115                                             const BinningFunPoR& binning2_, 
00116                                             const FillIteratorPoR& iter_) 
00117 :  MatrixOfHistograms  (name_, title_, axisbinning, hhl, binning1_, binning2_),
00118    xfun (xfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00119 {
00120   checkIterators(name_);
00121 }              
00122     
00123 SFMatrixOfHistograms::~SFMatrixOfHistograms () {}
00124 
00125 void SFMatrixOfHistograms::Fill () {
00126   BinningFun *binning1 = getBinning(1);
00127   BinningFun *binning2 = getBinning(2);
00128   assert (binning1);
00129   assert (binning2);
00130   int ibin1, ibin2;
00131   
00132   if (!xfun) return;
00133   if (!iter || iter->reset()) {
00134     if (binning1->isExclusive()) {
00135       if (binning2->isExclusive()) {
00136         // binning 1 exclusive, 2 exclusive
00137         do {
00138           if (!cut || (*cut)()) {
00139             Float_FF w = wfun ? (*wfun)() : 1.;
00140             if ((ibin1 = (*binning1)()) >= 0) {
00141               if ((ibin2 = (*binning2)()) >= 0) {
00142                 IndexType ibin = getBinNumber (ibin1, ibin2);
00143                 assert (ibin >= 0 && ibin < getEntries());
00144                 if (TH1F *th1f=dynamic_cast<TH1F *>(getEntry(ibin))) th1f->Fill ((*xfun)(), w);
00145               } 
00146             } 
00147           } 
00148         } while (iter && iter->next());  
00149       }
00150       else {
00151         // binning 1 exclusive, 2 non-exclusive
00152         do {
00153           if (!cut || (*cut)()) {
00154             Float_FF w = wfun ? (*wfun)() : 1.;
00155             Float_FF x = (*xfun)();
00156             if ((ibin1 = (*binning1)()) >= 0) {
00157               for (ibin2 = 0; ibin2 < binning2->getNBins(); ++ibin2) {
00158                 if ((*binning2)(ibin2)) {
00159                   IndexType ibin = getBinNumber (ibin1, ibin2);
00160                   assert (ibin >= 0 && ibin < getEntries());
00161                   if (TH1F *th1f=dynamic_cast<TH1F *>(getEntry(ibin))) th1f->Fill (x, w);
00162                 } 
00163               }
00164             } 
00165           } 
00166         } while (iter && iter->next());  
00167       }
00168     }
00169     else {
00170       if (binning2->isExclusive()) {
00171         // binning 1 non-exclusive, 2 exclusive
00172         do {
00173           if (!cut || (*cut)()) {
00174             Float_FF w = wfun ? (*wfun)() : 1.;
00175             Float_FF x = (*xfun)();
00176             if ((ibin2 = (*binning2)()) >= 0) {
00177               for (ibin1 = 0; ibin1 < binning1->getNBins(); ++ibin1) {
00178                 if ((*binning1)(ibin1)) {
00179                   IndexType ibin = getBinNumber (ibin1, ibin2);
00180                   assert (ibin >= 0 && ibin < getEntries());
00181                   if (TH1F *th1f=dynamic_cast<TH1F *>(getEntry(ibin))) th1f->Fill (x, w);
00182                 } 
00183               }
00184             } 
00185           } 
00186         } while (iter && iter->next());  
00187       }
00188       else {
00189         // binning 1 non-exclusive, 2 non-exclusive
00190         do {
00191           if (!cut || (*cut)()) {
00192             Float_FF w = wfun ? (*wfun)() : 1.;
00193             Float_FF x = (*xfun)();
00194             for (ibin1 = 0; ibin1 < binning1->getNBins(); ++ibin1) {
00195               if ((*binning1)(ibin1)) {
00196                 for (ibin2 = 0; ibin2 < binning2->getNBins(); ++ibin2) {
00197                   if ((*binning2)(ibin2)) {
00198                     IndexType ibin = getBinNumber (ibin1, ibin2);
00199                     assert (ibin >= 0 && ibin < getEntries());
00200                     if (TH1F *th1f=dynamic_cast<TH1F *>(getEntry(ibin))) th1f->Fill (x, w);
00201                   } 
00202                 }
00203               }
00204             } 
00205           } 
00206         } while (iter && iter->next());  
00207       }
00208     }
00209   }
00210 }
00211 
00212 template<class Fun1, class Fun2>
00213 void SFMatrixOfHistograms::checkTwoIterators(const char *name, 
00214                                           const char *fun1name, Fun1 *fun1, 
00215                                           const char *fun2name, Fun2 *fun2) {
00216   if (fun1 && fun1->getIterator() && 
00217       fun2  && fun2->getIterator() &&
00218       fun1->getIterator() != fun2->getIterator()) {
00219     std::cerr << "SFMatrixOfHistograms: Iterators of " << fun1name
00220               << " and " << fun2name
00221               << " are different for histogram "
00222               << name << "!" << std::endl;
00223   }
00224   assert (!fun1 || !fun1->getIterator() || !fun2  || !fun2->getIterator()  || fun1->getIterator() == fun2->getIterator());
00225 }                       
00226 template<class Fun>
00227 void SFMatrixOfHistograms::checkOneIterator (const char *name, 
00228                                           const char *funname, 
00229                                           Fun *fun) {
00230   if (fun && fun->getIterator()) {
00231     if (iter) {
00232       if (fun->getIterator() != iter) {
00233         std::cerr << "SFMatrixOfHistograms: Iterator '" 
00234                   << fun->getIterator()->getName() 
00235                   << "' of " << funname 
00236                   << " '" << fun->getName() << "'"
00237                   << " and iter '" << iter->getName() 
00238                   << "'are different for histogram "
00239                   << name << "!\n";
00240       }
00241     }
00242     else {
00243 #if(DEBUG>=2)      
00244       std::cerr << "SFMatrixOfHistograms: Iterator '" 
00245                 << fun->getIterator()->getName() << "' of " 
00246                 << funname
00247                 << " '" << fun->getName() << "'"
00248                 << " used as iterator for histogram "
00249                 << name << ".\n";
00250 #endif
00251       iter = const_cast<FillIterator *>(fun->getIterator());
00252     }
00253   }
00254   assert (!fun || !fun->getIterator() || fun->getIterator() == iter);
00255 }                       
00256 
00257 void SFMatrixOfHistograms::checkIterators(const char *name) {
00258   BinningFun *binning1 = getBinning(1);
00259   BinningFun *binning2 = getBinning(2);
00260   assert (binning1);
00261   assert (binning2);
00262   
00263   checkTwoIterators (name, "xfun",     xfun,     "cut",      cut);
00264   checkTwoIterators (name, "xfun",     xfun,     "wfun",     wfun);
00265   checkTwoIterators (name, "xfun",     xfun,     "binning1", binning1);
00266   checkTwoIterators (name, "xfun",     xfun,     "binning2", binning2);
00267   checkTwoIterators (name, "wfun",     wfun,     "cut",      cut);
00268   checkTwoIterators (name, "wfun",     wfun,     "binning1", binning1);
00269   checkTwoIterators (name, "wfun",     wfun,     "binning2", binning2);
00270   checkTwoIterators (name, "cut",      cut,      "binning1", binning1);
00271   checkTwoIterators (name, "cut",      cut,      "binning2", binning2);
00272   checkTwoIterators (name, "binning1", binning1, "binning2", binning2);
00273 
00274   checkOneIterator  (name, "xfun",     xfun);
00275   checkOneIterator  (name, "wfun",     wfun);
00276   checkOneIterator  (name, "cut",      cut);
00277   checkOneIterator  (name, "binning1", binning1);
00278   checkOneIterator  (name, "binning2", binning2);
00279 }

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