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

SFMatrixOfHProf.C

Go to the documentation of this file.
00001 
00021 #include "jbltools/sfh/SFMatrixOfHProf.h"
00022 #include "jbltools/sfh/RegHProf.h"
00023 #include "jbltools/sfh/BinningFun.h"
00024 #include "jbltools/sfh/BaseCutBase.h"
00025 #include "jbltools/sfh/FloatFunBase.h"
00026 #include "jbltools/sfh/FillIterator.h"
00027 
00028 #include <TFile.h>
00029 #include <TAxis.h>
00030 
00031 #include <iostream>
00032 #include <cassert>
00033 
00034 using std::endl;
00035 using std::cout;
00036 using std::cerr;
00037 
00038 static const char *ident="@(#)$Id: SFMatrixOfHProf.C,v 1.5 2005/08/23 12:05:44 blist Exp $";
00039 
00040 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00041                                   const char* title_, 
00042                                   const ROListPoR& rol, 
00043                                   const FloatFunPoR& xfun_,   
00044                                   const FloatFunPoR& yfun_,   
00045                                   const BaseCutPoR& cut_,     
00046                                   const FloatFunPoR& wfun_,   
00047                                   const BinningFunPoR& binning1_, 
00048                                   const BinningFunPoR& binning2_,
00049                                   const FillIteratorPoR& iter_) 
00050 : MatrixOfHProf (name_, title_, rol, binning1_, binning2_),
00051   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00052 {
00053 }  
00054 
00055 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00056                                   const char* title_, 
00057                                   Int_t nbinsx,  
00058                                   Axis_t xlow,  
00059                                   Axis_t xup,  
00060                                   Option_t *option_,             
00061                                   const ROListPoR& rol, 
00062                                   const FloatFunPoR& xfun_,   
00063                                   const FloatFunPoR& yfun_,   
00064                                   const BaseCutPoR& cut_,     
00065                                   const FloatFunPoR& wfun_,   
00066                                   const BinningFunPoR& binning1_, 
00067                                   const BinningFunPoR& binning2_,
00068                                   const FillIteratorPoR& iter_) 
00069 : MatrixOfHProf (name_, title_, nbinsx, xlow, xup, option_, rol, binning1_, binning2_),
00070   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00071 {
00072   checkIterators(name_);
00073 }  
00074 
00075 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00076                                   const char* title_, 
00077                                   Int_t nbinsx,  
00078                                   Axis_t xlow,  
00079                                   Axis_t xup,  
00080                                   Axis_t ylow_,
00081                                   Axis_t yup_, 
00082                                   Option_t *option_,             
00083                                   const ROListPoR& rol, 
00084                                   const FloatFunPoR& xfun_,   
00085                                   const FloatFunPoR& yfun_,   
00086                                   const BaseCutPoR& cut_,     
00087                                   const FloatFunPoR& wfun_,   
00088                                   const BinningFunPoR& binning1_, 
00089                                   const BinningFunPoR& binning2_,
00090                                   const FillIteratorPoR& iter_) 
00091 : MatrixOfHProf (name_, title_, nbinsx, xlow, xup, ylow_, yup_, option_, rol, binning1_, binning2_),
00092   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00093 {
00094   checkIterators(name_);
00095 }  
00096 
00097 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00098                                   const char* title_, 
00099                                   Int_t nbinsx,  
00100                                   const Double_t *xbins,  
00101                                   Option_t *option_,             
00102                                   const ROListPoR& rol, 
00103                                   const FloatFunPoR& xfun_,   
00104                                   const FloatFunPoR& yfun_,   
00105                                   const BaseCutPoR& cut_,     
00106                                   const FloatFunPoR& wfun_,   
00107                                   const BinningFunPoR& binning1_,
00108                                   const BinningFunPoR& binning2_,
00109                                   const FillIteratorPoR& iter_) 
00110 : MatrixOfHProf (name_, title_, nbinsx, xbins, option_, rol, binning1_, binning2_),
00111   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00112 {
00113   checkIterators(name_);
00114 }  
00115 
00116 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00117                                   const char* title_, 
00118                                   Int_t nbinsx,  
00119                                   const Double_t *xbins,  
00120                                   Axis_t ylow_,
00121                                   Axis_t yup_, 
00122                                   Option_t *option_,             
00123                                   const ROListPoR& rol, 
00124                                   const FloatFunPoR& xfun_,   
00125                                   const FloatFunPoR& yfun_,   
00126                                   const BaseCutPoR& cut_,     
00127                                   const FloatFunPoR& wfun_,   
00128                                   const BinningFunPoR& binning1_, 
00129                                   const BinningFunPoR& binning2_,
00130                                   const FillIteratorPoR& iter_) 
00131 : MatrixOfHProf (name_, title_, nbinsx, xbins, ylow_, yup_, option_, rol, binning1_, binning2_),
00132   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00133 {
00134   checkIterators(name_);
00135 }  
00136 
00137 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00138                                   const char* title_, 
00139                                   Int_t nbinsx,  
00140                                   const Float_t *xbins,  
00141                                   Option_t *option_,             
00142                                   const ROListPoR& rol, 
00143                                   const FloatFunPoR& xfun_,   
00144                                   const FloatFunPoR& yfun_,   
00145                                   const BaseCutPoR& cut_,     
00146                                   const FloatFunPoR& wfun_,   
00147                                   const BinningFunPoR& binning1_, 
00148                                   const BinningFunPoR& binning2_,
00149                                   const FillIteratorPoR& iter_) 
00150 : MatrixOfHProf (name_, title_, nbinsx, xbins, option_, rol, binning1_, binning2_),
00151   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi) 
00152 {
00153   checkIterators(name_);
00154 }  
00155 
00156 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00157                                   const char* title_, 
00158                                   Int_t nbinsx,  
00159                                   const Float_t *xbins,  
00160                                   Axis_t ylow_,
00161                                   Axis_t yup_, 
00162                                   Option_t *option_,             
00163                                   const ROListPoR& rol, 
00164                                   const FloatFunPoR& xfun_,   
00165                                   const FloatFunPoR& yfun_,   
00166                                   const BaseCutPoR& cut_,     
00167                                   const FloatFunPoR& wfun_,   
00168                                   const BinningFunPoR& binning1_, 
00169                                   const BinningFunPoR& binning2_,
00170                                   const FillIteratorPoR& iter_) 
00171 : MatrixOfHProf (name_, title_, nbinsx, xbins, ylow_, yup_, option_, rol, binning1_, binning2_),
00172   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00173 {
00174   checkIterators(name_);
00175 }  
00176 
00177 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00178                                   const char* title_, 
00179                                   const Binning& axisbinning_,  
00180                                   Option_t *option_,             
00181                                   const ROListPoR& rol, 
00182                                   const FloatFunPoR& xfun_,   
00183                                   const FloatFunPoR& yfun_,   
00184                                   const BaseCutPoR& cut_,     
00185                                   const FloatFunPoR& wfun_,   
00186                                   const BinningFunPoR& binning1_, 
00187                                   const BinningFunPoR& binning2_,
00188                                   const FillIteratorPoR& iter_) 
00189 : MatrixOfHProf (name_, title_, axisbinning_, option_, rol, binning1_, binning2_),
00190   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00191 {
00192   checkIterators(name_);
00193 }  
00194 
00195 SFMatrixOfHProf::SFMatrixOfHProf (const char* name_,  
00196                                   const char* title_, 
00197                                   const Binning& axisbinning_,  
00198                                   Axis_t ylow_,
00199                                   Axis_t yup_, 
00200                                   Option_t *option_,             
00201                                   const ROListPoR& rol, 
00202                                   const FloatFunPoR& xfun_,   
00203                                   const FloatFunPoR& yfun_,   
00204                                   const BaseCutPoR& cut_,     
00205                                   const FloatFunPoR& wfun_,   
00206                                   const BinningFunPoR& binning1_, 
00207                                   const BinningFunPoR& binning2_,
00208                                   const FillIteratorPoR& iter_) 
00209 : MatrixOfHProf (name_, title_, axisbinning_, ylow_, yup_, option_, rol, binning1_, binning2_),
00210   xfun (xfun_.pff), yfun (yfun_.pff), cut(cut_.pbc), wfun (wfun_.pff), iter(iter_.pfi)
00211 {
00212   checkIterators(name_);
00213 }  
00214 
00215 
00216 SFMatrixOfHProf::~SFMatrixOfHProf () {
00217 }                    
00218 
00219 
00220 void SFMatrixOfHProf::Fill () {
00221   BinningFun *binning1 = getBinning(1);
00222   BinningFun *binning2 = getBinning(2);
00223   assert (binning1);
00224   assert (binning2);
00225   int ibin1, ibin2;
00226   
00227   if (!xfun) return;
00228   if (!yfun) return;
00229   
00230 //   if (!iter || iter->reset()) {
00231 //     do {
00232 //       if (!cut || (*cut)()) {
00233 //         Float_FF w = wfun ? (*wfun)() : 1.;
00234 //         int ibin1 = (*binning1)();
00235 //         if (ibin1 < 0) return;
00236 //         int ibin2 = (*binning2)();
00237 //         if (ibin2 < 0) return;
00238 //         IndexType ibin = getBinNumber (ibin1, ibin2);
00239 //   
00240 //         if (TProfile *tprof=dynamic_cast<TProfile *>(getEntry(ibin))) tprof->Fill ((*xfun)(), (*yfun)(), w);
00241 //       } 
00242 //     } while (iter && iter->next());  
00243 //   }
00244   if (!iter || iter->reset()) {
00245     if (binning1->isExclusive()) {
00246       if (binning2->isExclusive()) {
00247         // binning 1 exclusive, 2 exclusive
00248         do {
00249           if (!cut || (*cut)()) {
00250             Float_FF w = wfun ? (*wfun)() : 1.;
00251             if ((ibin1 = (*binning1)()) >= 0) {
00252               if ((ibin2 = (*binning2)()) >= 0) {
00253                 IndexType ibin = getBinNumber (ibin1, ibin2);
00254                 assert (ibin >= 0 && ibin < getEntries());
00255                 if (TProfile *tprof=dynamic_cast<TProfile *>(getEntry(ibin))) tprof->Fill ((*xfun)(), (*yfun)(), w);
00256               } 
00257             } 
00258           } 
00259         } while (iter && iter->next());  
00260       }
00261       else {
00262         // binning 1 exclusive, 2 non-exclusive
00263         do {
00264           if (!cut || (*cut)()) {
00265             Float_FF w = wfun ? (*wfun)() : 1.;
00266             Float_FF x = (*xfun)();
00267             Float_FF y = (*yfun)();
00268             if ((ibin1 = (*binning1)()) >= 0) {
00269               for (ibin2 = 0; ibin2 < binning2->getNBins(); ++ibin2) {
00270                 if ((*binning2)(ibin2)) {
00271                   IndexType ibin = getBinNumber (ibin1, ibin2);
00272                   assert (ibin >= 0 && ibin < getEntries());
00273                   if (TProfile *tprof=dynamic_cast<TProfile *>(getEntry(ibin))) tprof->Fill (x, y, w);
00274                 } 
00275               }
00276             } 
00277           } 
00278         } while (iter && iter->next());  
00279       }
00280     }
00281     else {
00282       if (binning2->isExclusive()) {
00283         // binning 1 non-exclusive, 2 exclusive
00284         do {
00285           if (!cut || (*cut)()) {
00286             Float_FF w = wfun ? (*wfun)() : 1.;
00287             Float_FF x = (*xfun)();
00288             Float_FF y = (*yfun)();
00289             if ((ibin2 = (*binning2)()) >= 0) {
00290               for (ibin1 = 0; ibin1 < binning1->getNBins(); ++ibin1) {
00291                 if ((*binning1)(ibin1)) {
00292                   IndexType ibin = getBinNumber (ibin1, ibin2);
00293                   assert (ibin >= 0 && ibin < getEntries());
00294                   if (TProfile *tprof=dynamic_cast<TProfile *>(getEntry(ibin))) tprof->Fill (x, y, w);
00295                 } 
00296               }
00297             } 
00298           } 
00299         } while (iter && iter->next());  
00300       }
00301       else {
00302         // binning 1 non-exclusive, 2 non-exclusive
00303         do {
00304           if (!cut || (*cut)()) {
00305             Float_FF w = wfun ? (*wfun)() : 1.;
00306             Float_FF x = (*xfun)();
00307             Float_FF y = (*yfun)();
00308             for (ibin1 = 0; ibin1 < binning1->getNBins(); ++ibin1) {
00309               if ((*binning1)(ibin1)) {
00310                 for (ibin2 = 0; ibin2 < binning2->getNBins(); ++ibin2) {
00311                   if ((*binning2)(ibin2)) {
00312                     IndexType ibin = getBinNumber (ibin1, ibin2);
00313                     assert (ibin >= 0 && ibin < getEntries());
00314                     if (TProfile *tprof=dynamic_cast<TProfile *>(getEntry(ibin))) tprof->Fill (x, y, w);
00315                   } 
00316                 }
00317               }
00318             } 
00319           } 
00320         } while (iter && iter->next());  
00321       }
00322     }
00323   }
00324 }
00325   
00326 
00327 template<class Fun1, class Fun2>
00328 void SFMatrixOfHProf::checkTwoIterators(const char *name, 
00329                                           const char *fun1name, Fun1 *fun1, 
00330                                           const char *fun2name, Fun2 *fun2) {
00331   if (fun1 && fun1->getIterator() && 
00332       fun2  && fun2->getIterator() &&
00333       fun1->getIterator() != fun2->getIterator()) {
00334     std::cerr << "SFMatrixOfHProf: Iterators of " << fun1name
00335               << " and " << fun2name
00336               << " are different for histogram "
00337               << name << "!" << std::endl;
00338   }
00339   assert (!fun1 || !fun1->getIterator() || !fun2  || !fun2->getIterator()  || fun1->getIterator() == fun2->getIterator());
00340 }                       
00341 template<class Fun>
00342 void SFMatrixOfHProf::checkOneIterator (const char *name, 
00343                                           const char *funname, 
00344                                                 Fun  *fun) {
00345   if (fun && fun->getIterator()) {
00346     if (iter) {
00347       if (fun->getIterator() != iter) {
00348         std::cerr << "SFMatrixOfHProf: Iterator '" 
00349                   << fun->getIterator()->getName() 
00350                   << "' of " << funname 
00351                   << " '" << fun->getName() << "'"
00352                   << " and iter '" << iter->getName() 
00353                   << "'are different for histogram "
00354                   << name << "!\n";
00355       }
00356     }
00357     else {
00358 #if(DEBUG>=2)      
00359       std::cerr << "SFMatrixOfHProf: Iterator '" 
00360                 << fun->getIterator()->getName() << "' of " 
00361                 << funname
00362                 << " '" << fun->getName() << "'"
00363                 << " used as iterator for histogram "
00364                 << name << ".\n";
00365 #endif
00366       iter = const_cast<FillIterator *>(fun->getIterator());
00367     }
00368   }
00369   assert (!fun || !fun->getIterator() || fun->getIterator() == iter);
00370 }                       
00371 
00372 void SFMatrixOfHProf::checkIterators(const char *name) {
00373   const BinningFun *binning = getBinning();
00374   assert (binning);
00375   checkTwoIterators (name, "xfun", xfun, "yfun",    yfun);
00376   checkTwoIterators (name, "xfun", xfun, "cut",     cut);
00377   checkTwoIterators (name, "xfun", xfun, "wfun",    wfun);
00378   checkTwoIterators (name, "xfun", xfun, "binning", binning);
00379   checkTwoIterators (name, "yfun", yfun, "cut",     cut);
00380   checkTwoIterators (name, "yfun", yfun, "wfun",    wfun);
00381   checkTwoIterators (name, "yfun", yfun, "binning", binning);
00382   checkTwoIterators (name, "wfun", wfun, "cut",     cut);
00383   checkTwoIterators (name, "wfun", wfun, "binning", binning);
00384   checkTwoIterators (name, "cut",  cut,  "binning", binning);
00385 
00386   checkOneIterator (name, "xfun",    xfun);
00387   checkOneIterator (name, "yfun",    yfun);
00388   checkOneIterator (name, "wfun",    wfun);
00389   checkOneIterator (name, "cut",     cut);
00390   checkOneIterator (name, "binning", binning);
00391 }
00392   

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