CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Benchmark.cc
Go to the documentation of this file.
2 
4 
7 
8 #include <TDirectory.h>
9 
10 
11 using namespace std;
12 
14 
16 
17 }
18 
19 void Benchmark::setDirectory(TDirectory* dir) {
20  dir_ = dir;
21  DQM_ = 0;
22 }
23 
24 
25 TH1F* Benchmark::book1D(const char* histname, const char* title,
26  int nbins, float xmin, float xmax) {
27  // DQM_ has to be initialized in a child analyzer.
28  if(DQM_) {
29  edm::LogInfo("Benchmark") << " Benchmark::book1D " << "booking "<<histname;
30  return DQM_->book1D(histname,title,nbins,xmin, xmax)->getTH1F();
31  }
32  else if(dir_){
33  TDirectory *oldpwd = gDirectory;
34  dir_->cd();
35  TH1F *hist = new TH1F(histname, title, nbins, xmin, xmax);
36  cout<<"booking (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
37  oldpwd->cd();
38  return hist;
39  }
40  else assert(0);
41 }
42 
43 TH2F* Benchmark::book2D(const char* histname, const char* title,
44  int nbinsx, float xmin, float xmax,
45  int nbinsy, float ymin, float ymax ) {
46  // DQM_ has to be initialized in a child analyzer.
47  if(DQM_) {
48  edm::LogInfo("Benchmark") << " Benchmark::book2D "<<"booked "<<histname;
49  return DQM_->book2D(histname,title,nbinsx,xmin, xmax, nbinsy, ymin, ymax)->getTH2F();
50  }
51  else if(dir_) {
52  TDirectory *oldpwd = gDirectory;
53  dir_->cd();
54  TH2F *hist = new TH2F(histname, title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
55  cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
56  oldpwd->cd();
57  return hist;
58  }
59  else assert(0);
60 }
61 
62 TH2F* Benchmark::book2D(const char* histname, const char* title,
63  int nbinsx, float* xbins,
64  int nbinsy, float ymin, float ymax ) {
65  if(DQM_) {
66  edm::LogInfo("Benchmark") << " Benchmark::book2D " << " booked "<<histname;
67 
68  // need to build the y bin array manually, due to a missing
69  // function in DQMStore
70  vector<float> ybins( nbinsy+1 );
71  double binsize = (ymax - ymin) / nbinsy;
72  for(int i=0; i<=nbinsy; ++i) {
73  ybins[i] = ymin + i*binsize;
74  }
75 
76  return DQM_->book2D(histname,title,nbinsx, xbins, nbinsy, &ybins[0])->getTH2F();
77  }
78  else if(dir_) {
79  TDirectory *oldpwd = gDirectory;
80  dir_->cd();
81 
82  // need to convert the float bin array into a double bin array,
83  // because the DQMStore functions take floats, while the ROOT functions
84  // take double.
85  vector<double> xbinsd(nbinsx+1);
86  for(int i=0; i<=nbinsx; ++i) {
87  xbinsd[i] = xbins[i];
88  }
89 
90  TH2F *hist = new TH2F(histname, title, nbinsx, &xbinsd[0], nbinsy, ymin, ymax);
91  cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
92  oldpwd->cd();
93  return hist;
94  }
95  else assert(0);
96 }
97 
98 
100  //COLIN not sure about the root mode
101  if( dir_ )
102  dir_->Write();
103 
104  //COLIN remove old bullshit:
105 // if ( ame.size() != 0 && file_)
106 // cout<<"saving histograms in "<<fileName<<endl;
107 // file_->Write(fileName.c_str());
108 }
int i
Definition: DBlmapReader.cc:9
const double xbins[]
static const char dir_[]
virtual void setDirectory(TDirectory *dir)
Definition: Benchmark.cc:19
void write()
write to the TFile, in plain ROOT mode. No need to call this function in DQM mode ...
Definition: Benchmark.cc:99
static DQMStore * DQM_
Definition: Benchmark.h:39
virtual ~Benchmark()
Definition: Benchmark.cc:15
TH2F * book2D(const char *histname, const char *title, int nbinsx, float xmin, float xmax, int nbinsy, float ymin, float ymax)
book a 2D histogram, either with DQM or plain root.
Definition: Benchmark.cc:43
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
TH1F * book1D(const char *histname, const char *title, int nbins, float xmin, float xmax)
book a 1D histogram, either with DQM or plain root.
Definition: Benchmark.cc:25