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

SetOfH.C

Go to the documentation of this file.
00001 
00023 #include "jbltools/sfh/SetOfH.h"
00024 #include "jbltools/sfh/BinningFun.h"
00025 #include "jbltools/sfh/RegH1F.h"
00026 
00027 #include <TFile.h>
00028 #include <TF1.h>
00029 #include <TAxis.h>
00030 
00031 #include <iostream>
00032 #include <cmath>
00033 #include <cassert>
00034 
00035 static const char *ident="@(#)$Id: SetOfH.C,v 1.8 2005/09/06 11:27:25 blist Exp $";
00036 
00037 SetOfH::SetOfH (const char* name_, 
00038                 const char* title_, 
00039                 const ROListPoR& hhl, 
00040                 const BinningFunPoR& binning1_,
00041                 Option_t* option_) 
00042 : name (0), title (0),
00043   binning1 (binning1_.pbf), binning2 (0), binning3 (0), option (0)
00044 {
00045   init (name_, title_, option_);
00046   if (hhl.prol) hhl.prol->registerObject (this);
00047 }  
00048 
00049 SetOfH::SetOfH (const char* name_, 
00050                 const char* title_, 
00051                 const ROListPoR& hhl, 
00052                 const BinningFunPoR& binning1_,
00053                 const BinningFunPoR& binning2_,
00054                 Option_t* option_) 
00055 : name (0), title (0),
00056   binning1 (binning1_.pbf), binning2 (binning2_.pbf), binning3 (0), option (0)
00057 {
00058   init (name_, title_, option_);
00059   if (hhl.prol) hhl.prol->registerObject (this);
00060 }  
00061 
00062 void SetOfH::init (const char* name_, const char* title_, Option_t *option_) {
00063   if (!name_) name_ = "?";
00064   if (!title_) title_ = "?";
00065   if (name_) {
00066     name = new char[strlen (name_)+1];
00067     strcpy (name, name_);
00068   }
00069   if (title_) {
00070     title = new char[strlen (title_)+1];
00071     strcpy (title, title_);
00072   }
00073   if (option_) {
00074     option = new char[strlen (option_)+1];
00075     strcpy (option, option_);
00076   }
00077 }
00078 
00079 
00080 void SetOfH::initHistos () {
00081   IndexType nbins = binning1 ? binning1->getNBins() : 0;
00082   for (IndexType i = 0; i < nbins; i++) {
00083     this->initHisto(i);
00084   }
00085 }
00086 
00087 
00088 
00089 TH1 *SetOfH::getHisto (unsigned int i) {
00090   if (i >= getEntries()) return 0;
00091   return dynamic_cast<TH1 *>(getEntry(i));
00092 }
00093 
00094 const char *SetOfH::genBinTitle (IndexType i) const {
00095     if (binning1==0) return 0;
00096     const char *bintitle = binning1->getBinTitle(i);
00097     if (!bintitle) {
00098       char *bt = new char[10];
00099       snprintf (bt, 10, "%lld", i);
00100       bintitle = bt;
00101     }
00102     size_t size = strlen (title) + 1 + strlen (bintitle) + 1;
00103     char *htitle = new char[size];
00104     snprintf (htitle, size, "%s %s", title, bintitle);
00105     delete[] bintitle;
00106     return htitle;
00107 }
00108 
00109 const char *SetOfH::genBinName (IndexType i) const {
00110     if (binning1==0) return 0;
00111     const char *binname = binning1->getBinName(i);
00112     if (!binname) {
00113       char *bn = new char[10];
00114       snprintf (bn, 10, "%lld", i);
00115       binname = bn;
00116     }
00117     size_t size = strlen (name) + strlen (binname) + 1;
00118     char *hname = new char[size];
00119     snprintf (hname, size, "%s%s", name, binname);
00120     delete[] binname;
00121     return hname;
00122 }
00123 
00124 SetOfH::~SetOfH () {
00125   // cout << "~SetOfH(): deleting " << title << endl;
00126   delete[] name;
00127   name = 0;
00128   delete[] title;
00129   title = 0;
00130   delete[] option;
00131   option = 0;
00132 }                    
00133 
00134 void SetOfH::Divide(TF1* f1, Double_t c1) {
00135   for (iterator i = begin(); i != end(); ++i) {
00136     if (TH1 *h = dynamic_cast<TH1 *>(getEntry(i))) h->Divide(f1, c1);
00137   }
00138 }
00139 
00140 void SetOfH::Divide(const TH1 *h1) {
00141   for (iterator i = begin(); i != end(); ++i) {
00142     if (TH1 *h = dynamic_cast<TH1 *>(getEntry(i))) h->Divide(h1);
00143   }
00144 }
00145 
00146 void SetOfH::Divide(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2, Option_t* option) {
00147   for (iterator i = begin(); i != end(); ++i) {
00148     if (TH1 *h = dynamic_cast<TH1 *>(getEntry(i))) h->Divide(h1, h2, c1, c2, option);
00149   }
00150 }
00151              
00152 void SetOfH::Divide(const SetOfH *soh) {
00153   if (soh == 0) return;
00154   if (getEntries() != soh->getEntries()) {
00155     std::cerr << "SetOfH::Divide(const SetOfH *): number of histograms differ for " 
00156               << getName() << " and " << soh->getName() << std::endl; 
00157   }
00158   
00159   for (iterator i = begin(); i != end(); ++i) {
00160     TH1 *h = dynamic_cast<TH1 *>(getEntry(i));
00161     TH1 *h1 = dynamic_cast<TH1 *>(soh->getEntry(getIndex(i)));
00162     if (h && h1) h->Divide (h1);
00163     else if (h || h1) std::cerr << "SetOfH::Divide(const SetOfH&): histo missing for index " << getIndex(i)
00164                 << " in set " << (h ? soh : this)->getName() << std::endl;
00165   }
00166 }
00167 
00168 void SetOfH::Divide(const SetOfH *soh1, const SetOfH *soh2, 
00169                     Double_t c1, Double_t c2, Option_t* option) {
00170   if (soh1 == 0 || soh2 == 0) return;
00171   if (getEntries() != soh1->getEntries() || getEntries() != soh2->getEntries()) {
00172     std::cerr << "SetOfH::Divide(...): number of histograms differ for " 
00173               << getName() << " and " << soh1->getName() << " and " << soh2->getName() << std::endl; 
00174   }
00175   for (iterator i = begin(); i != end(); ++i) {
00176     TH1 *h = dynamic_cast<TH1 *>(getEntry(i));
00177     TH1 *h1 = dynamic_cast<TH1 *>(soh1->getEntry(getIndex(i)));
00178     TH1 *h2 = dynamic_cast<TH1 *>(soh2->getEntry(getIndex(i)));
00179     if (h && h1 && h2) h->Divide (h1, h2, c1, c2, option);
00180     else if (h || h1 || h2) 
00181       std::cerr << "SetOfH::Divide(const SetOfH *, const SetOfH *, ...): histo missing for index " << getIndex(i)
00182                 << " in set " << (h ? (h1 ? soh2 : soh1) : this)->getName() << std::endl;
00183   }
00184 }
00185 
00186 
00187 void SetOfH::Divide(const SetOfH *soh1, const SetOfH *soh2, 
00188                     const SetOfH *soh3, Double_t c1, Double_t c2) {
00189   if (soh1 == 0 || soh2 == 0 || soh3 == 0) return;
00190   if (getEntries() != soh1->getEntries() || 
00191       getEntries() != soh2->getEntries() || 
00192       getEntries() != soh3->getEntries()) {
00193     std::cerr << "SetOfHistograms::Divide(...): number of histograms differ for " 
00194               << getName() << " and " << soh1->getName() << " and " << soh2->getName() 
00195               << " and " << soh3->getName() << std::endl;  
00196   }
00197   for (iterator i = begin(); i != end(); ++i) {
00198     RegH1F *h = dynamic_cast<RegH1F *>(getEntry(i));
00199     TH1 *h1 = dynamic_cast<TH1 *>(soh1->getEntry(getIndex(i)));
00200     TH1 *h2 = dynamic_cast<TH1 *>(soh2->getEntry(getIndex(i)));
00201     TH1 *h3 = dynamic_cast<TH1 *>(soh3->getEntry(getIndex(i)));
00202     if (h && h1 && h2 && h3) h->Divide (h1, h2, h3, c1, c2);
00203     else if (h || h1 || h2 || h3) 
00204       std::cerr << "SetOfH::Divide(const SetOfH *, const SetOfH *, ...): histo missing for index " << getIndex(i)
00205                 << " in set " << (h ? (h1 ? (h2 ? soh3 : soh2) : soh1) : this)->getName() << std::endl;
00206   }
00207 }
00208   
00209 void SetOfH::Multiply(TF1 *f1, Double_t c1) {
00210   for (iterator i = begin(); i != end(); ++i) {
00211     if (TH1 *h = dynamic_cast<TH1 *>(getEntry(i))) h->Multiply(f1, c1);
00212   }
00213 }
00214 
00215 void SetOfH::Multiply(const TH1 *h1) {
00216   for (iterator i = begin(); i != end(); ++i) {
00217     if (TH1 *h = dynamic_cast<TH1 *>(getEntry(i))) h->Multiply(h1);
00218   }
00219 }
00220 
00221 void SetOfH::Multiply(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2, Option_t* option) {
00222   for (iterator i = begin(); i != end(); ++i) {
00223     if (TH1 *h = dynamic_cast<TH1 *>(getEntry(i))) h->Multiply(h1, h2, c1, c2, option);
00224   }
00225 }
00226              
00227 void SetOfH::Multiply(const SetOfH *soh) {
00228   if (soh == 0) return;
00229   if (getEntries() != soh->getEntries()) {
00230     std::cerr << "SetOfH::Multiply(const SetOfH *): number of histograms differ for " 
00231               << getName() << " and " << soh->getName() << std::endl;
00232   }
00233   
00234   for (iterator i = begin(); i != end(); ++i) {
00235     TH1 *h = dynamic_cast<TH1 *>(getEntry(i));
00236     TH1 *h1 = dynamic_cast<TH1 *>(soh->getEntry(getIndex(i)));
00237     if (h && h1) h->Multiply (h1);
00238     else if (h || h1) 
00239       std::cerr << "SetOfH::Multiply(const SetOfH *): histo missing for index " << getIndex(i)
00240                 << " in set " << (h ? soh : this)->getName() << std::endl;
00241   }
00242 }
00243 
00244 void SetOfH::Multiply(const SetOfH *soh1, 
00245                       const SetOfH *soh2, 
00246                       Double_t c1, Double_t c2, 
00247                       Option_t* option) {
00248   if (soh1 == 0 || soh2 == 0) return;                             
00249   if (getEntries() != soh1->getEntries() || getEntries() != soh2->getEntries()) {
00250     std::cerr << "SetOfH::Multiply(const SetOfH *, const SetOfH *, ...): number of histograms differ for " 
00251               << getName() << " and " << soh1->getName() << " and " << soh2->getName() << std::endl;
00252   }
00253   for (iterator i = begin(); i != end(); ++i) {
00254     TH1 *h = dynamic_cast<TH1 *>(getEntry(i));
00255     TH1 *h1 = dynamic_cast<TH1 *>(soh1->getEntry(getIndex(i)));
00256     TH1 *h2 = dynamic_cast<TH1 *>(soh2->getEntry(getIndex(i)));
00257     if (h && h1 && h2) h->Multiply (h1, h2, c1, c2, option);
00258     else if (h || h1 || h2) 
00259       std::cerr << "SetOfH::Multiply(const SetOfH *, const SetOfH *, ...): histo missing for index " << getIndex(i)
00260                 << " in set " << (h ? (h1 ? soh2 : soh1) : this)->getName() << std::endl;
00261   }
00262 }
00263   
00264 void SetOfH::Add(const SetOfH *soh, Double_t c1) {
00265   if (soh == 0) return;
00266   if (getEntries() != soh->getEntries()) {
00267     std::cerr << "SetOfH::Add(const SetOfH *): number of histograms differ!" 
00268               << std::endl;
00269   }
00270   
00271   for (iterator i = begin(); i != end(); ++i) {
00272     TH1 *h = dynamic_cast<TH1 *>(getEntry(i));
00273     TH1 *h1 = dynamic_cast<TH1 *>(soh->getEntry(getIndex(i)));
00274     if (h && h1) h->Add (h1, c1);
00275     else if (h || h1) 
00276       std::cerr << "SetOfH::Add(const SetOfH *): histo missing for index " << getIndex(i)
00277                 << " in set " << (h ? soh : this)->getName() << std::endl;
00278   }
00279 }
00280   
00281 
00282   

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