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

SetOfHistograms.C

Go to the documentation of this file.
00001 
00021 #include "jbltools/sfh/SetOfHistograms.h"
00022 #include "jbltools/sfh/RegH1F.h"
00023 #include "jbltools/sfh/BinningFun.h"
00024 
00025 #include <TFile.h>
00026 #include <TF1.h>
00027 #include <TAxis.h>
00028 
00029 #include <iostream>
00030 #include <cmath>
00031 #include <cassert>
00032 
00033 static const char *ident="@(#)$Id: SetOfHistograms.C,v 1.22 2006/06/30 11:05:00 blist Exp $";
00034 
00035 SetOfHistograms::SetOfHistograms (const char* name_, 
00036                                   const char* title_, 
00037                                   const ROListPoR& hhl, 
00038                                   const BinningFunPoR& binning_) 
00039 : SetOfH (name_, title_, hhl, binning_)
00040 {
00041 }  
00042 
00043 SetOfHistograms::SetOfHistograms (const char* name_, 
00044                                   const char* title_, 
00045                                   Int_t nbinsx, 
00046                                   Axis_t xlow, 
00047                                   Axis_t xup,  
00048                                   const ROListPoR& hhl, 
00049                                   const BinningFunPoR& binning_) 
00050 : SetOfH (name_, title_, hhl, binning_),
00051   axisbinning (nbinsx, xlow, xup)
00052 {
00053   initHistos ();
00054 }  
00055 
00056 
00057 SetOfHistograms::SetOfHistograms (const char* name_, 
00058                                   const char* title_, 
00059                                   Int_t nbinsx, 
00060                                   const Double_t* xbins,  
00061                                   const ROListPoR& hhl, 
00062                                   const BinningFunPoR& binning_) 
00063 : SetOfH (name_, title_, hhl, binning_),
00064   axisbinning (nbinsx, xbins)
00065 {
00066   initHistos ();
00067 }  
00068 
00069 
00070 SetOfHistograms::SetOfHistograms (const char* name_, 
00071                                   const char* title_, 
00072                                   Int_t nbinsx, 
00073                                   const Float_t* xbins,  
00074                                   const ROListPoR& hhl,
00075                                   const BinningFunPoR& binning_) 
00076 : SetOfH (name_, title_, hhl, binning_),
00077   axisbinning (nbinsx, xbins)
00078 {
00079   initHistos ();
00080 }  
00081 
00082 SetOfHistograms::SetOfHistograms (const char* name_, 
00083                                   const char* title_, 
00084                                   const Binning& axisbinning_,  
00085                                   const ROListPoR& hhl, 
00086                                   const BinningFunPoR& binning_) 
00087 : SetOfH (name_, title_, hhl, binning_),
00088   axisbinning (axisbinning_)
00089 {
00090   initHistos ();
00091 }  
00092 
00093 
00094 SetOfHistograms::SetOfHistograms (const char* name_, 
00095                                   const char* title_, 
00096                                   TFile& file, 
00097                                   const ROListPoR& hhl, 
00098                                   const BinningFunPoR& binning_) 
00099 : SetOfH (name_, title_, hhl, binning_)
00100 {
00101   BinningFun *binning = getBinning();
00102   assert (binning);
00103   for (IndexType i = 0; i < static_cast<IndexType>(binning->getNBins()); i++) {
00104     const char *hname = genBinName(i);
00105     new RegH1F (hname, file, *this);
00106     delete[] hname;
00107   }
00108 }  
00109 
00110 
00111 void SetOfHistograms::initHisto (IndexType i)
00112 {
00113   const char *htitle = genBinTitle(i);
00114   const char *hname = genBinName(i);
00115   RegH1F *h = new RegH1F (hname, htitle, axisbinning, 0);
00116   registerObject (i, h);
00117   delete[] hname;
00118   delete[] htitle;
00119 }
00120 
00121 
00122 RegH1F *SetOfHistograms::getHisto (IndexType i) {
00123   return dynamic_cast<RegH1F *>(getEntry(i));
00124 }
00125 
00126 RegH1F *SetOfHistograms::getHisto (iterator i) {
00127   return dynamic_cast<RegH1F *>(getEntry(i));
00128 }
00129 
00130 const RegH1F *SetOfHistograms::getHisto (const_iterator i) const {
00131   return dynamic_cast<const RegH1F *>(getEntry(i));
00132 }
00133 
00134 
00135 SetOfHistograms::~SetOfHistograms () {
00136 }                    
00137 
00138   
00139 RegH1F *SetOfHistograms::getSummary(Option_t* option_, const ROListPoR& hhl) {
00140   TString opt = option_;
00141   opt.ToLower();
00142   
00143   int number = 99999;
00144   if (opt.Contains("m")) number = 99998;
00145   
00146   int hnamlen = strlen (getName()) + 5 + 1;
00147   char *hname = new char[hnamlen];
00148   snprintf (hname, hnamlen, "%s%5d", getName(), number);
00149   int htitlen = strlen (getTitle()) + 1 + strlen ("Summary") + 1;
00150   char *htitle = new char[htitlen];
00151   snprintf (htitle, htitlen, "%s Summary", getTitle());
00152   RegH1F *result = 0;
00153   
00154   BinningFun *binning = getBinning();
00155   assert (binning);
00156 //   Int_t nbinsx = binning->getNBins();
00157 //   Axis_t xlow = -0.5;
00158 //   Axis_t xup = nbinsx-0.5;
00159   result = new RegH1F (hname, htitle, *binning, hhl);
00160   if (result == 0)  {
00161     std::cerr << "SetOfHistograms::getSummary: Cannot create histo!"
00162          << std::endl;
00163   } else {
00164     for (const_iterator i = begin(); i != end(); ++i) {
00165       const RegH1F *h = getHisto (i);
00166       if (h) {
00167         Int_t ibin = getIndex(i) + 1;
00168         Stat_t content = 0;
00169         Stat_t error2 = 0;
00170         h->getHistInfo (option_, content, error2);
00171         result->SetBinContent (ibin, content);
00172 //        result->SetBinError2  (ibin, error2);
00173 //  root TH1 has only SetBinError :(
00174         result->SetBinError  (ibin, sqrt(error2));
00175       }
00176     }
00177   }
00178   delete[] hname;
00179   delete[] htitle;
00180   
00181   return result;
00182 
00183 }
00184   
00185 RegH1F *SetOfHistograms::getSummary(Option_t* option_, const char *fname,
00186                        int parnumber, int hnumber, const char *tcomment, const ROListPoR& hhl) {
00187                        
00188   if (fname == 0) return 0;
00189   if (tcomment == 0) tcomment = "";
00190   
00191   int hnamlen = strlen (getName()) + 5 + 1;
00192   char *hname = new char[hnamlen];
00193   snprintf (hname, hnamlen, "%s%5d", getName(), hnumber);
00194   int htitlen = strlen (getTitle()) + 20 + strlen(fname) + strlen(tcomment);
00195   char *htitle = new char[htitlen];
00196   snprintf (htitle, htitlen, "%s: Par %d of %s %s", getTitle(), parnumber, fname, tcomment);
00197   RegH1F *result = 0;
00198   
00199   BinningFun *binning = getBinning();
00200   assert (binning);
00201   result = new RegH1F (hname, htitle, *binning, hhl);
00202   if (result == 0)  {
00203     std::cerr << "SetOfHistograms::getSummary: Cannot create histo!"
00204          << std::endl;
00205   } else {
00206     for (const_iterator i = begin(); i != end(); ++i) {
00207       const RegH1F *h = getHisto (i);
00208       if (h) {
00209         TF1 *f = h->GetFunction (fname);
00210         if (f) {
00211           double content = f->GetParameter (parnumber);
00212           double error = f->GetParError (parnumber);
00213           Int_t ibin = getIndex(i) + 1;
00214           result->SetBinContent (ibin, content);
00215           result->SetBinError  (ibin, error);
00216         }
00217       }
00218     }
00219   }
00220   delete[] hname;
00221   delete[] htitle;
00222   
00223   return result;
00224 
00225 }
00226  
00227 RegH1F* SetOfHistograms::getSum (const char* name, const char* title, 
00228                                  const ROListPoR& hhl, int lowbin, int highbin) const {
00229   IndexType low = (lowbin < 0) ? 0 : lowbin;
00230   IndexType high = (highbin < lowbin || highbin < 0) ? getHighestEntry() : highbin;
00231   const_iterator i = lower_bound(low);
00232   const RegH1F *h = getHisto (i);
00233   assert (h);
00234   RegH1F *result = new RegH1F (name, title, *h, hhl);
00235   if (result) {
00236     for (++i; i != upper_bound (high); ++i) result->Add (getHisto (i));
00237   }
00238   return result;
00239 }
00240 
00241   

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