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