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

ROList.C

Go to the documentation of this file.
00001 
00032 #include "jbltools/sfh/ROList.h"
00033 #include "jbltools/sfh/HVisitors.h"
00034 
00035 #include <TVirtualPS.h>
00036 #include <TPad.h>
00037 #include <TNamed.h>
00038 
00039 #include <iostream>
00040 #include <cassert>
00041 #include <string>
00042 
00043 static const char *ident="@(#)$Id: ROList.C,v 1.15 2006/05/15 13:28:19 zimmerto Exp $";
00044 
00045 ROList::ROList ()
00046 {}
00047 
00048 ROList::ROList (const ROListPoR& mother)
00049 {
00050   // std::cout << "ROList::ROList (const ROListPoR& mother)\n";
00051 #if(DEBUG>=3)
00052   if (mother.prol) std::cerr << "... registering with mother\n";
00053 #endif
00054   if (mother.prol) mother.prol->registerObject (this);
00055 }
00056 
00057 int ROList::registerObject (RegO* h) {
00058   theMap [getHighestEntry()] = h;
00059 #if(DEBUG>=3)
00060   if (TNamed *tn = dynamic_cast<TNamed *>(h)) {
00061     std::cout << "ROList::registerObject: Have registered object "
00062               << tn->GetName() << std::endl;
00063     
00064   }
00065 #endif
00066   return getEntries();
00067 }
00068 
00069 int ROList::registerObject (IndexType n, RegO* h) {
00070   theMap [n] = h;
00071 #if(DEBUG>=3)
00072   if (TNamed *tn = dynamic_cast<TNamed *>(h)) {
00073     std::cout << "ROList::registerObject: Have registered object "
00074               << tn->GetName() << std::endl;
00075     
00076   }
00077 #endif
00078   return getEntries();
00079 }
00080 
00081 ROList::~ROList () {
00082   for (iterator iter = begin(); iter != end(); ++iter) {
00083     delete iter->second;
00084     iter->second = 0;
00085   } 
00086 }
00087 
00088 void ROList::Write () {
00089   visit (Writer());
00090 }
00091 
00092 ROList& ROList::visit (HVisitor& v) {
00093   for (iterator iter = begin(); iter != end(); ++iter) {
00094     if (iter->second) {
00095       if (ROList *rol = dynamic_cast<ROList *>(iter->second)) {
00096         rol->visit (v);
00097       }
00098       else {
00099         if (iter->second) v.visit(*(iter->second));
00100       }
00101     }
00102   }
00103   return *this;
00104 }
00105 
00106 ROList&  ROList::visit (const ConstHVisitor& v) {
00107   for (iterator iter = begin(); iter != end(); ++iter) {
00108     if (iter->second) {
00109       if (ROList *rol = dynamic_cast<ROList *>(iter->second)) {
00110         rol->visit (v);
00111       }
00112       else {
00113         if (iter->second) v.visit(*(iter->second));
00114       }
00115     }
00116   }
00117   return *this;
00118 }
00119 
00120 int ROList::Draw (TPad *pad, TVirtualPS *ps,
00121                    Option_t *option,
00122                    bool across,
00123                    Int_t nx, Int_t ny,
00124                    Float_t xmargin, Float_t ymargin, 
00125                    Int_t color,
00126                    Int_t log, bool recursive, int izone) {
00127   if (!pad) {
00128     std::cerr << "HasHistogramList::Draw: No pad, no Draw()!\n";
00129     return 0;
00130   }      
00131   assert (pad);  
00132   
00133   // std::cout << "ROList::Draw: drawing " << getEntries() << " histos\n";                 
00134                              
00135   // loop over all histograms
00136   IndexType n = nx*ny;
00137   IndexType i = izone;
00138   for (iterator iter = begin(); iter != end(); ++iter, ++i) {
00139     // std::cout << "ROList::Draw: drawing #" << i << "\n";                 
00140     if (i % n == 0) {
00141       if (i!=0 && ps) ps->NewPage();
00142       i = 0;
00143  
00144       pad->Clear();
00145       pad->Divide (nx, ny, xmargin, ymargin, color);
00146     }
00147     if (across) {
00148       pad->cd (i+1);
00149     }
00150     else {
00151       int ix = i / ny;
00152       int iy = i % ny;
00153       pad->cd (iy*nx + ix + 1);
00154     }
00155     if (log & LOGY) gPad->SetLogy();
00156     if (log & LOGX) gPad->SetLogx();
00157     
00158     if (ROList *rol = dynamic_cast<ROList *>(iter->second)) {
00159       i = rol->Draw (pad, ps, option, across, nx, ny, xmargin,  ymargin, color, log, i);
00160     } else {
00161       if (TH1 *th1=dynamic_cast<TH1 *>(iter->second))th1->Draw(option);
00162       if (((i+1) % n == 0) || (i+1) == getEntries()) {
00163         pad->Update();
00164         // std::cout << "ROList::Draw: Calling pad->Update()\n"; 
00165       }                
00166     }
00167   }
00168   // std::cout << "ROList::Draw: finished\n";  
00169   return i;               
00170 } 
00171   
00172 int ROList::Draw (TPad *pad, TVirtualPS *ps,
00173                       Option_t *option,
00174                       bool across,
00175                       Int_t nx, Int_t ny,
00176                       Int_t log, bool recursive, int izone) {
00177   return Draw (pad, ps, option, across, nx, ny, 0.01, 0.01, 0, log, recursive, izone);
00178 }
00179 
00180 void ROList::DrawCutFlow (TPad *pad, TVirtualPS *ps,
00181                           Option_t *option,
00182                           Option_t *sameoption,
00183                           bool across,
00184                           Int_t nx, Int_t ny,
00185                           Float_t xmargin, Float_t ymargin, 
00186                           Int_t color,
00187                           Int_t log, bool recursive, bool backward) {
00188   if (!pad) {
00189     std::cerr << "HasHistogramList::DrawCutFlow: No pad, no Draw()!\n";
00190     return;
00191   }      
00192   assert (pad);  
00193   
00194   if (!option) option = "";
00195   if (!sameoption) sameoption = " same";
00196   
00197   std::cout << "ROList::Draw: drawing " << getEntries() << " histos\n";                 
00198   std::cout << "nx/ny = " << nx << " " << ny << "\n";                 
00199   std::cout << "log = " << log << "\n";                 
00200                              
00201   // loop over all histograms
00202   IndexType n = nx*ny;
00203   IndexType i = 0;
00204   iterator last = 0;
00205   for (iterator iter = begin(); iter != end(); ++iter, ++i) {
00206     iterator next = iter;
00207     ++next;
00208     // std::cout << "ROList::DrawCutFlow: drawing #" << i << "\n";                 
00209     if (i % n == 0) {
00210       i = 0;
00211       if (ps) ps->NewPage();
00212  
00213       pad->Clear();
00214       pad->Divide (nx, ny, xmargin, ymargin, color);
00215     }
00216     if (across) {
00217       pad->cd (i+1);
00218     }
00219     else {
00220       int ix = i / ny;
00221       int iy = i % ny;
00222       pad->cd (iy*nx + ix + 1);
00223     }
00224     if (log & LOGY) gPad->SetLogy();
00225     if (log & LOGX) gPad->SetLogx();
00226     
00227     if (ROList *rol = dynamic_cast<ROList *>(iter->second)) {
00228       if (recursive) {
00229         rol->DrawCutFlow (pad, ps, option, sameoption, across, nx, ny, xmargin, ymargin, color, log, recursive, backward);
00230         i = 0;
00231       }
00232     } else {
00233       if (TH1 *th1     = dynamic_cast<TH1 *>(iter->second)) {
00234         TH1 *th1other = 0;
00235         if (backward) {
00236           th1other = (iter != begin()) ? dynamic_cast<TH1 *>(last->second) : 0;
00237         } else {
00238           th1other = (next != end()) ? dynamic_cast<TH1 *>(next->second) : 0;
00239         }
00240         float maxi = th1->GetMaximum();
00241         if (th1other && th1other->GetMaximum() > maxi) {
00242           maxi = th1other->GetMaximum();
00243           th1->SetMaximum(1.1*maxi);
00244           th1->Draw (option);
00245           th1->SetMaximum(-1111);   // Default value = "no maximum"
00246         }
00247         else th1->Draw (option);
00248         if (th1other) {
00249           Color_t oldcolor = th1other->GetLineColor();
00250           th1other->SetLineColor(2);
00251           th1other->DrawCopy (sameoption);
00252           th1other->SetLineColor(oldcolor);
00253         }
00254       }
00255       if (((i+1) % n == 0) || (i+1) == getEntries()) {
00256         pad->Update();
00257         // std::cout << "ROList::Draw: Calling pad->Update()\n"; 
00258       }                
00259     }
00260     last = iter;
00261   }
00262   // std::cout << "ROList::Draw: finished\n";                 
00263 } 
00264   
00265 void ROList::DrawCutFlow (TPad *pad, TVirtualPS *ps,
00266                       Option_t *option,
00267                       Option_t *sameoption,
00268                       bool across,
00269                       Int_t nx, Int_t ny,
00270                       Int_t log, bool recursive, bool backward) {
00271   DrawCutFlow (pad, ps, option, sameoption, across, nx, ny, 0.01, 0.01, 0, log, recursive, backward);
00272 }
00273 
00274 // DrawFunc by Ronnie Weber
00275 int ROList::DrawFunc (TPad *pad, TVirtualPS *ps,
00276                       Option_t *option,
00277                       const char *fname,
00278                       bool across,
00279                       Int_t nx, Int_t ny,
00280                       Float_t xmargin, Float_t ymargin,
00281                       Int_t color,
00282                       Int_t log, bool recursive, int izone) {
00283   if (!pad) {
00284     std::cerr << "HasHistogramList::Draw: No pad, no Draw()!\n";
00285     return 0;
00286   }      
00287   assert (pad);  
00288   
00289   // std::cout << "ROList::Draw: drawing " << getEntries() << " histos\n";                 
00290                              
00291   // loop over all histograms
00292   IndexType n = nx*ny;
00293   IndexType i = izone;
00294   for (iterator iter = begin(); iter != end(); ++iter, ++i) {
00295     // std::cout << "ROList::Draw: drawing #" << i << "\n";                 
00296     if (i % n == 0) {
00297       if (i!=0 && ps) ps->NewPage();
00298       i = 0;
00299  
00300       pad->Clear();
00301       pad->Divide (nx, ny, xmargin, ymargin, color);
00302     }
00303     if (across) {
00304       pad->cd (i+1);
00305     }
00306     else {
00307       int ix = i / ny;
00308       int iy = i % ny;
00309       pad->cd (iy*nx + ix + 1);
00310     }
00311     if (log & LOGY) gPad->SetLogy();
00312     if (log & LOGX) gPad->SetLogx();
00313     
00314     if (ROList *rol = dynamic_cast<ROList *>(iter->second)) {
00315       i = rol->DrawFunc (pad, ps, option, fname, across, nx, ny, xmargin,  ymargin, color, log, i);
00316     } else {
00317       if (TH1 *th1=dynamic_cast<TH1 *>(iter->second)){
00318         if(TF1 *f = th1->GetFunction(fname)) {
00319           std::cout << "ROList::DrawFunc: temp. enabling function " << fname
00320                     << " for drawing of " << th1->GetName() << "\n";
00321           f->SetBit(BIT(9), 0);
00322         } else {
00323           std::cout << "ROList::DrawFunc: ERROR - could not find function " << fname
00324                     << " for drawing of " << th1->GetName() << "\n";
00325         }
00326         th1->DrawCopy(option);
00327         if(TF1 *f = th1->GetFunction(fname)) {
00328           f->SetBit(BIT(9), 1);
00329         }
00330       }
00331       if (((i+1) % n == 0) || (i+1) == getEntries()) {
00332         pad->Update();
00333         // std::cout << "ROList::Draw: Calling pad->Update()\n"; 
00334       }                
00335     }
00336   }
00337   // std::cout << "ROList::Draw: finished\n";  
00338   return i;               
00339 } 
00340   
00341 int ROList::DrawFunc (TPad *pad, TVirtualPS *ps,
00342                       Option_t *option,
00343                       const char *fname,
00344                       bool across,
00345                       Int_t nx, Int_t ny,
00346                       Int_t log, bool recursive, int izone) {
00347   return DrawFunc (pad, ps, option, fname, across, nx, ny, 0.01, 0.01, 0, log, recursive, izone);
00348 }
00349 

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