CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQMOffline/PFTau/src/Benchmark.cc

Go to the documentation of this file.
00001 #include "DQMOffline/PFTau/interface/Benchmark.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 
00005 #include "DQMServices/Core/interface/MonitorElement.h"
00006 #include "DQMServices/Core/interface/DQMStore.h"
00007 
00008 #include <TDirectory.h>
00009 
00010 
00011 using namespace std;
00012 
00013 DQMStore* Benchmark::DQM_ = 0;
00014 
00015 Benchmark::~Benchmark() {
00016 
00017 }
00018 
00019 void Benchmark::setDirectory(TDirectory* dir) {
00020   dir_ = dir;
00021   DQM_ = 0; 
00022 } 
00023 
00024 
00025 TH1F* Benchmark::book1D(const char* histname, const char* title, 
00026                         int nbins, float xmin, float xmax) {
00027   // DQM_ has to be initialized in a child analyzer.
00028   if(DQM_) {
00029     edm::LogInfo("Benchmark") << " Benchmark::book1D " << "booking "<<histname;
00030     return DQM_->book1D(histname,title,nbins,xmin, xmax)->getTH1F();
00031   }
00032   else if(dir_){
00033     TDirectory *oldpwd = gDirectory; 
00034     dir_->cd();
00035     TH1F *hist =  new TH1F(histname, title, nbins, xmin, xmax);
00036     cout<<"booking (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
00037     oldpwd->cd();
00038     return hist;
00039   }
00040   else assert(0);
00041 }
00042 
00043 TH2F* Benchmark::book2D(const char* histname, const char* title, 
00044                         int nbinsx, float xmin, float xmax,
00045                         int nbinsy, float ymin, float ymax ) {
00046   // DQM_ has to be initialized in a child analyzer.
00047   if(DQM_) {
00048     edm::LogInfo("Benchmark") << " Benchmark::book2D "<<"booked "<<histname;
00049     return DQM_->book2D(histname,title,nbinsx,xmin, xmax, nbinsy, ymin, ymax)->getTH2F();
00050   }
00051   else if(dir_) {
00052     TDirectory *oldpwd = gDirectory; 
00053     dir_->cd();
00054     TH2F *hist = new TH2F(histname, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
00055     cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
00056     oldpwd->cd();
00057     return hist;
00058   }
00059   else assert(0);
00060 }
00061 
00062 TH2F* Benchmark::book2D(const char* histname, const char* title, 
00063                         int nbinsx, float* xbins,
00064                         int nbinsy, float ymin, float ymax ) {
00065   if(DQM_) {
00066     edm::LogInfo("Benchmark") << " Benchmark::book2D " << " booked "<<histname;
00067     
00068     // need to build the y bin array manually, due to a missing 
00069     // function in DQMStore
00070     vector<float> ybins( nbinsy+1 );
00071     double binsize = (ymax - ymin) / nbinsy;
00072     for(int i=0; i<=nbinsy; ++i) {
00073       ybins[i] = ymin + i*binsize;
00074     } 
00075     
00076     return DQM_->book2D(histname,title,nbinsx, xbins, nbinsy, &ybins[0])->getTH2F();
00077   }
00078   else if(dir_) {
00079     TDirectory *oldpwd = gDirectory; 
00080     dir_->cd();
00081 
00082     // need to convert the float bin array into a double bin array,
00083     // because the DQMStore functions take floats, while the ROOT functions
00084     // take double. 
00085     vector<double> xbinsd(nbinsx+1); 
00086     for(int i=0; i<=nbinsx; ++i) {
00087       xbinsd[i] = xbins[i];
00088     }
00089 
00090     TH2F *hist = new TH2F(histname, title, nbinsx, &xbinsd[0], nbinsy, ymin, ymax);
00091     cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
00092     oldpwd->cd();
00093     return hist;
00094   }
00095   else assert(0);
00096 }
00097 
00098 
00099 void Benchmark::write() {
00100   //COLIN not sure about the root mode 
00101   if( dir_ )
00102     dir_->Write();
00103 
00104   //COLIN remove old bullshit:
00105 //   if ( ame.size() != 0 && file_)
00106 //     cout<<"saving histograms in "<<fileName<<endl;
00107 //     file_->Write(fileName.c_str());
00108 }