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