Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:44:29

0001 #include "DQMOffline/PFTau/interface/Benchmark.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "DQMServices/Core/interface/DQMStore.h"
0006 
0007 #include <TDirectory.h>
0008 
0009 using namespace std;
0010 
0011 Benchmark::~Benchmark() noexcept(false) {}
0012 
0013 void Benchmark::setDirectory(TDirectory *dir) { dir_ = dir; }
0014 
0015 TH1F *Benchmark::book1D(
0016     DQMStore::IBooker &b, const char *histname, const char *title, int nbins, float xmin, float xmax) {
0017   edm::LogInfo("Benchmark") << " Benchmark::book1D "
0018                             << "booking " << histname;
0019   return b.book1D(histname, title, nbins, xmin, xmax)->getTH1F();
0020 }
0021 
0022 TH2F *Benchmark::book2D(DQMStore::IBooker &b,
0023                         const char *histname,
0024                         const char *title,
0025                         int nbinsx,
0026                         float xmin,
0027                         float xmax,
0028                         int nbinsy,
0029                         float ymin,
0030                         float ymax) {
0031   edm::LogInfo("Benchmark") << " Benchmark::book2D "
0032                             << "booked " << histname;
0033   return b.book2D(histname, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax)->getTH2F();
0034 }
0035 
0036 TH2F *Benchmark::book2D(DQMStore::IBooker &b,
0037                         const char *histname,
0038                         const char *title,
0039                         int nbinsx,
0040                         float *xbins,
0041                         int nbinsy,
0042                         float ymin,
0043                         float ymax) {
0044   edm::LogInfo("Benchmark") << " Benchmark::book2D "
0045                             << " booked " << histname;
0046 
0047   // need to build the y bin array manually, due to a missing function in
0048   // DQMStore
0049   vector<float> ybins(nbinsy + 1);
0050   double binsize = (ymax - ymin) / nbinsy;
0051   for (int i = 0; i <= nbinsy; ++i) {
0052     ybins[i] = ymin + i * binsize;
0053   }
0054 
0055   return b.book2D(histname, title, nbinsx, xbins, nbinsy, &ybins[0])->getTH2F();
0056 }
0057 
0058 TProfile *Benchmark::bookProfile(DQMStore::IBooker &b,
0059                                  const char *histname,
0060                                  const char *title,
0061                                  int nbinsx,
0062                                  float xmin,
0063                                  float xmax,
0064                                  float ymin,
0065                                  float ymax,
0066                                  const char *option) {
0067   edm::LogInfo("Benchmark") << " Benchmark::bookProfile "
0068                             << "booked " << histname;
0069   return b.bookProfile(histname, title, nbinsx, xmin, xmax, 0.0, 0.0, option)->getTProfile();
0070 }
0071 
0072 TProfile *Benchmark::bookProfile(DQMStore::IBooker &b,
0073                                  const char *histname,
0074                                  const char *title,
0075                                  int nbinsx,
0076                                  float *xbins,
0077                                  float ymin,
0078                                  float ymax,
0079                                  const char *option) {
0080   // need to convert the float bin array into a double bin array, because the
0081   // DQMStore TProfile functions take floats, while the  DQMStore TH2 functions
0082   // take double.
0083   vector<double> xbinsd(nbinsx + 1);
0084   for (int i = 0; i <= nbinsx; ++i) {
0085     xbinsd[i] = xbins[i];
0086   }
0087 
0088   edm::LogInfo("Benchmark") << " Benchmark::bookProfile "
0089                             << "booked " << histname;
0090   return b.bookProfile(histname, title, nbinsx, &xbinsd[0], ymin, ymax, option)->getTProfile();
0091 }
0092 
0093 void Benchmark::write() {
0094   // COLIN not sure about the root mode
0095   if (dir_)
0096     dir_->Write();
0097 
0098   // COLIN remove old bullshit:
0099   //   if ( ame.size() != 0 && file_)
0100   //     cout<<"saving histograms in "<<fileName<<endl;
0101   //     file_->Write(fileName.c_str());
0102 }