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
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
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
00069
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
00083
00084
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
00101 if( dir_ )
00102 dir_->Write();
00103
00104
00105
00106
00107
00108 }