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