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

SFEffSetOfHistograms.C

Go to the documentation of this file.
00001 
00012 #include "jbltools/sfh/SFEffSetOfHistograms.h"
00013 #include "jbltools/sfh/BaseCutBase.h"
00014 #include "jbltools/sfh/FloatFunBase.h"
00015 #include "jbltools/sfh/BinningFun.h"
00016 #include "jbltools/sfh/ROList.h"
00017 #include "jbltools/sfh/FillIterator.h"
00018 
00019 #include <TVirtualPS.h>
00020 #include <TPad.h>
00021 
00022 // system headers
00023 #include <cstdio>
00024 #include <cstring>
00025 #include <cassert>
00026 #include <iostream>
00027 
00028 static const char *ident="@(#)$Id: SFEffSetOfHistograms.C,v 1.4 2005/07/08 15:01:35 blist Exp $";
00029 
00030 
00031 class EffBinningFun: public BinningFun {
00032 public:
00033   EffBinningFun ()
00034   : BinningFun (3, -0.5, 2.5)
00035   {}
00036   
00037   virtual int operator() () const {return 0;} 
00038   
00039   virtual const char *getBinName(int i) const {
00040     size_t size = 4;
00041     char *name = new char[size];
00042     switch (i) {
00043       case 0:  std::snprintf (name, size, "Cut1"); break;
00044       case 1:  std::snprintf (name, size, "Cut2"); break;
00045       case 2:  std::snprintf (name, size, "Eff"); break;
00046       default: std::snprintf (name, size, "???"); break;
00047     }
00048     return name;
00049   }
00050   
00051   virtual const char *getBinTitle(int i) const {
00052     size_t size = 11;
00053     char *title = new char[size];
00054     switch (i) {
00055       case 0:  std::snprintf (title, size, "Cut 1"); break;
00056       case 1:  std::snprintf (title, size, "Cut 2"); break;
00057       case 2:  std::snprintf (title, size, "Efficiency"); break;
00058       default: std::snprintf (title, size, "???"); break;
00059     }
00060     return title;
00061   }
00062   protected:  
00064     virtual ~EffBinningFun() {}; 
00065 };
00066 
00067 static BinningFun& effbinning = *new EffBinningFun;
00068 
00069 SFEffSetOfHistograms::SFEffSetOfHistograms (const char* name_,  
00070                                       const char* title_, 
00071                                       Int_t nbinsx,  
00072                                       Axis_t xlow,  
00073                                       Axis_t xup, 
00074                                       const ROListPoR& hhl,  
00075                                       const FloatFunPoR& xfun_, 
00076                                       const BaseCutPoR& cut0_,  
00077                                       const BaseCutPoR& cut1_,  
00078                                       const BaseCutPoR& cut2_,  
00079                                       const FloatFunPoR& wfun_, 
00080                                       const FillIteratorPoR& iter_,
00081                                       Option_t* div_option_) 
00082 :  SetOfHistograms  (name_, title_, nbinsx, xlow, xup, hhl, effbinning),
00083    xfun (xfun_.pff), cut0(cut0_.pbc), cut1(cut1_.pbc), cut2(cut2_.pbc), 
00084    wfun (wfun_.pff), iter(iter_.pfi), div_option(0)
00085 {
00086   copy_option (div_option_);
00087   checkIterators(name_);
00088 }              
00089     
00090 SFEffSetOfHistograms::SFEffSetOfHistograms (const char* name_,  
00091                                       const char* title_, 
00092                                       Int_t nbinsx,  
00093                                       const Double_t* xbins,  
00094                                       const ROListPoR& hhl,  
00095                                       const FloatFunPoR& xfun_, 
00096                                       const BaseCutPoR& cut0_,  
00097                                       const BaseCutPoR& cut1_,  
00098                                       const BaseCutPoR& cut2_,  
00099                                       const FloatFunPoR& wfun_, 
00100                                       const FillIteratorPoR& iter_,
00101                                       Option_t* div_option_) 
00102 :  SetOfHistograms  (name_, title_, nbinsx, xbins, hhl, effbinning),
00103    xfun (xfun_.pff), cut0(cut0_.pbc), cut1(cut1_.pbc), cut2(cut2_.pbc), 
00104    wfun (wfun_.pff), iter(iter_.pfi), div_option(0)
00105 {
00106   copy_option (div_option_);
00107   checkIterators(name_);
00108 }              
00109     
00110 SFEffSetOfHistograms::SFEffSetOfHistograms (const char* name_,  
00111                                       const char* title_, 
00112                                       Int_t nbinsx,  
00113                                       const Float_t* xbins,  
00114                                       const ROListPoR& hhl,  
00115                                       const FloatFunPoR& xfun_,  
00116                                       const BaseCutPoR& cut0_,  
00117                                       const BaseCutPoR& cut1_,  
00118                                       const BaseCutPoR& cut2_,  
00119                                       const FloatFunPoR& wfun_, 
00120                                       const FillIteratorPoR& iter_,
00121                                       Option_t* div_option_) 
00122 :  SetOfHistograms  (name_, title_, nbinsx, xbins, hhl, effbinning),
00123    xfun (xfun_.pff), cut0(cut0_.pbc), cut1(cut1_.pbc), cut2(cut2_.pbc), 
00124    wfun (wfun_.pff), iter(iter_.pfi), div_option(0)
00125 {
00126   copy_option (div_option_);
00127   checkIterators(name_);
00128 }              
00129       
00130 SFEffSetOfHistograms::SFEffSetOfHistograms (const char* name_,  
00131                                       const char* title_, 
00132                                       const Binning& axisbinning,  
00133                                       const ROListPoR& hhl,  
00134                                       const FloatFunPoR& xfun_,  
00135                                       const BaseCutPoR& cut0_,  
00136                                       const BaseCutPoR& cut1_,  
00137                                       const BaseCutPoR& cut2_,  
00138                                       const FloatFunPoR& wfun_, 
00139                                       const FillIteratorPoR& iter_,
00140                                       Option_t* div_option_) 
00141 :  SetOfHistograms  (name_, title_, axisbinning, hhl, effbinning),
00142    xfun (xfun_.pff), cut0(cut0_.pbc), cut1(cut1_.pbc), cut2(cut2_.pbc), 
00143    wfun (wfun_.pff), iter(iter_.pfi), div_option(0)
00144 {
00145   copy_option (div_option_);
00146   checkIterators(name_);
00147 }              
00148       
00149     
00150 SFEffSetOfHistograms::~SFEffSetOfHistograms () {
00151   delete[] div_option;
00152 }
00153 
00154 void SFEffSetOfHistograms::Fill () {
00155   if (!xfun) return;
00156   if (!iter || iter->reset()) {
00157     do {
00158       if (!cut0 || (*cut0)()) {
00159         float w = wfun ? (*wfun)() : 1.;
00160         float x = xfun ? (*xfun)() : 1.;
00161         if (!cut1 || (*cut1)()) {
00162           if (TH1F *th1f=dynamic_cast<TH1F *>(getEntry(0))) th1f->Fill (x, w);
00163         }
00164         if (!cut2 || (*cut2)()) {
00165           if (TH1F *th1f=dynamic_cast<TH1F *>(getEntry(1))) th1f->Fill (x, w);
00166         }
00167       }
00168     } while (iter && iter->next());  
00169   }
00170 }
00171 
00172 void SFEffSetOfHistograms::Draw (Option_t *option) {
00173   Divide(); 
00174   if (TH1 *th1=dynamic_cast<TH1 *>(getEntry(2))) th1->Draw(option);
00175 }
00176 
00177 void SFEffSetOfHistograms::Draw (TPad *pad, TVirtualPS *ps,
00178                       Option_t *option,
00179                       bool across,
00180                       Int_t nx, Int_t ny,
00181                       Float_t xmargin, Float_t ymargin, 
00182                       Int_t color,
00183                       bool log) {
00184   assert (pad); 
00185   
00186   if (ps) ps->NewPage();
00187  
00188   pad->Clear();
00189   pad->Divide (nx, ny, xmargin, ymargin, color);
00190   pad->cd (1);
00191   if (log) gPad->SetLogy();
00192   Draw();  
00193   pad->Update();
00194 }
00195   
00196 void SFEffSetOfHistograms::Draw (TPad *pad, TVirtualPS *ps,
00197                       Option_t *option,
00198                       bool across,
00199                       Int_t nx, Int_t ny,
00200                       bool log) {
00201   Draw (pad, ps, option, across, nx, ny, 0.01, 0.01, 0, log);
00202 }
00203 
00204 void SFEffSetOfHistograms::Divide () {
00205   if (TH1 *th1_1=dynamic_cast<TH1 *>(getEntry(0))) 
00206     if (TH1 *th1_2=dynamic_cast<TH1 *>(getEntry(1))) 
00207       if (TH1 *th1_3=dynamic_cast<TH1 *>(getEntry(2))) 
00208         th1_3->Divide (th1_2, th1_1, 1, 1, div_option);
00209 }
00210 
00211 void SFEffSetOfHistograms::copy_option (Option_t *div_option_) {
00212   if (div_option_) {
00213     size_t len = strlen (div_option_)+1;
00214     div_option = new char[len];
00215     strncpy (div_option, div_option_, len);
00216   }
00217 }
00218 
00219 void SFEffSetOfHistograms::checkIterators(const char *name) {
00220   if (xfun && xfun->getIterator() && 
00221       cut0 && cut0->getIterator() &&
00222       xfun->getIterator() != cut0->getIterator()) {
00223     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of xfun and cut0 are different for histogram "
00224          << name << "!" << std::endl;
00225   }
00226   if (xfun && xfun->getIterator() && 
00227       cut1  && cut1->getIterator() &&
00228       xfun->getIterator() != cut1->getIterator()) {
00229     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of xfun and cut1 are different for histogram "
00230          << name << "!" << std::endl;
00231   }
00232   if (xfun && xfun->getIterator() && 
00233       cut2 && cut2->getIterator() &&
00234       xfun->getIterator() != cut2->getIterator()) {
00235     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of xfun and cut2 are different for histogram "
00236          << name << "!" << std::endl;
00237   }
00238   if (xfun && xfun->getIterator() && 
00239       wfun && wfun->getIterator() &&
00240       xfun->getIterator() != wfun->getIterator()) {
00241     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of xfun and wfun are different for histogram "
00242          << name << "!" << std::endl;
00243   }
00244   if (wfun && wfun->getIterator() && 
00245       cut0 && cut0->getIterator() &&
00246       wfun->getIterator() != cut0->getIterator()) {
00247     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of wfun and cut0 are different for histogram "
00248          << name << "!" << std::endl;
00249   }
00250   if (wfun && wfun->getIterator() && 
00251       cut1 && cut1->getIterator() &&
00252       wfun->getIterator() != cut1->getIterator()) {
00253     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of wfun and cut1 are different for histogram "
00254          << name << "!" << std::endl;
00255   }
00256   if (wfun && wfun->getIterator() && 
00257       cut2 && cut2->getIterator() &&
00258       wfun->getIterator() != cut2->getIterator()) {
00259     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of wfun and cut2 are different for histogram "
00260          << name << "!" << std::endl;
00261   }
00262   if (cut0 && cut0->getIterator() && 
00263       cut1 && cut1->getIterator() &&
00264       cut0->getIterator() != cut1->getIterator()) {
00265     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of cut0 and cut1 are different for histogram "
00266          << name << "!" << std::endl;
00267   }
00268   if (cut0 && cut0->getIterator() && 
00269       cut2 && cut2->getIterator() &&
00270       cut0->getIterator() != cut2->getIterator()) {
00271     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of cut0 and cut2 are different for histogram "
00272          << name << "!" << std::endl;
00273   }
00274   if (cut1 && cut1->getIterator() && 
00275       cut2 && cut2->getIterator() &&
00276       cut1->getIterator() != cut2->getIterator()) {
00277     std::cerr << "SFEffSetOfHistograms::checkIterators: Iterators of cut1 and cut2 are different for histogram "
00278          << name << "!" << std::endl;
00279   }
00280   assert (!xfun || !xfun->getIterator() || !cut0 || !cut0->getIterator() || xfun->getIterator() == cut0->getIterator());
00281   assert (!xfun || !xfun->getIterator() || !cut1 || !cut1->getIterator() || xfun->getIterator() == cut1->getIterator());
00282   assert (!xfun || !xfun->getIterator() || !cut2 || !cut2->getIterator() || xfun->getIterator() == cut2->getIterator());
00283   assert (!xfun || !xfun->getIterator() || !wfun || !wfun->getIterator() || xfun->getIterator() == wfun->getIterator());
00284   assert (!wfun || !wfun->getIterator() || !cut0 || !cut0->getIterator() || wfun->getIterator() == cut0->getIterator());
00285   assert (!wfun || !wfun->getIterator() || !cut1 || !cut1->getIterator() || wfun->getIterator() == cut1->getIterator());
00286   assert (!wfun || !wfun->getIterator() || !cut2 || !cut2->getIterator() || wfun->getIterator() == cut2->getIterator());
00287   assert (!cut0 || !cut0->getIterator() || !cut1 || !cut1->getIterator() || cut0->getIterator() == cut1->getIterator());
00288   assert (!cut0 || !cut0->getIterator() || !cut2 || !cut2->getIterator() || cut0->getIterator() == cut2->getIterator());
00289   assert (!cut1 || !cut1->getIterator() || !cut2 || !cut2->getIterator() || cut1->getIterator() == cut2->getIterator());
00290 
00291   if (xfun && xfun->getIterator()) {
00292     if (iter) {
00293       if (xfun->getIterator() != iter) {
00294         std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of xfun and iter are different for histogram "
00295                   << name << "!" << std::endl;
00296       }
00297     }
00298     else {
00299       std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of xfun used as iterator for histogram "
00300                 << name << "!" << std::endl;
00301       iter = const_cast<FillIterator *>(xfun->getIterator());
00302     }
00303   }
00304   if (cut0 && cut0->getIterator()) {
00305     if (iter) {
00306       if (cut0->getIterator() != iter) {
00307         std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of cut0 and iter are different for histogram "
00308                   << name << "!" << std::endl;
00309       }
00310     }
00311     else {
00312       std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of cut0 used as iterator for histogram "
00313                 << name << "!" << std::endl;
00314       iter = const_cast<FillIterator *>(cut0->getIterator());
00315     }
00316   }
00317   if (cut1 && cut1->getIterator()) {
00318     if (iter) {
00319       if (cut1->getIterator() != iter) {
00320         std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of cut1 and iter are different for histogram "
00321                   << name << "!" << std::endl;
00322       }
00323     }
00324     else {
00325       std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of cut1 used as iterator for histogram "
00326                 << name << "!" << std::endl;
00327       iter = const_cast<FillIterator *>(cut1->getIterator());
00328     }
00329   }
00330   if (cut2 && cut2->getIterator()) {
00331     if (iter) {
00332       if (cut2->getIterator() != iter) {
00333         std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of cut2 and iter are different for histogram "
00334                   << name << "!" << std::endl;
00335       }
00336     }
00337     else {
00338       std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of cut2 used as iterator for histogram "
00339                 << name << "!" << std::endl;
00340       iter = const_cast<FillIterator *>(cut2->getIterator());
00341     }
00342   }
00343   if (wfun && wfun->getIterator()) {
00344     if (iter) {
00345       if (wfun->getIterator() != iter) {
00346         std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of wfun and iter are different for histogram "
00347                   << name << "!" << std::endl;
00348       }
00349     }
00350     else {
00351       std::cerr << "SFEffSetOfHistograms::checkIterators: Iterator of wfun used as iterator for histogram "
00352                 << name << "!" << std::endl;
00353       iter = const_cast<FillIterator *>(wfun->getIterator());
00354     }
00355   }
00356   assert (!xfun || !xfun->getIterator() || xfun->getIterator() == iter);
00357   assert (!cut0 || !cut0->getIterator() || cut0->getIterator()  == iter);
00358   assert (!cut1 || !cut1->getIterator() || cut1->getIterator()  == iter);
00359   assert (!cut2 || !cut2->getIterator() || cut2->getIterator()  == iter);
00360   assert (!wfun || !wfun->getIterator() || wfun->getIterator() == iter);
00361 }

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