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