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 function in DQMStore
69  vector<float> ybins( nbinsy+1 );
70  double binsize = (ymax - ymin) / nbinsy;
71  for(int i=0; i<=nbinsy; ++i) {
72  ybins[i] = ymin + i*binsize;
73  }
74 
75  return DQM_->book2D(histname,title,nbinsx, xbins, nbinsy, &ybins[0])->getTH2F();
76  }
77  else if(dir_) {
78  TDirectory *oldpwd = gDirectory;
79  dir_->cd();
80 
81  // need to convert the float bin array into a double bin array, because the DQMStore functions take floats, while the ROOT functions take double.
82  vector<double> xbinsd(nbinsx+1);
83  for(int i=0; i<=nbinsx; ++i) {
84  xbinsd[i] = xbins[i];
85  }
86 
87  TH2F *hist = new TH2F(histname, title, nbinsx, &xbinsd[0], nbinsy, ymin, ymax);
88  cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
89  oldpwd->cd();
90  return hist;
91  }
92  else assert(0);
93 }
94 
95 TProfile* Benchmark::bookProfile(const char* histname, const char* title,
96  int nbinsx, float xmin, float xmax,
97  float ymin, float ymax, const char* option ) {
98  // DQM_ has to be initialized in a child analyzer.
99  if(DQM_) {
100  edm::LogInfo("Benchmark") << " Benchmark::bookProfile "<<"booked "<<histname;
101  return DQM_->bookProfile(histname, title, nbinsx, xmin, xmax, 0.0, 0.0, option )->getTProfile();
102  }
103  else if(dir_) {
104  TDirectory *oldpwd = gDirectory;
105  dir_->cd();
106  TProfile *hist = new TProfile(histname, title, nbinsx, xmin, xmax, ymin, ymax, option);
107  cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
108  oldpwd->cd();
109  return hist;
110  }
111  else assert(0);
112 }
113 
114 TProfile* Benchmark::bookProfile(const char* histname, const char* title,
115  int nbinsx, float* xbins,
116  float ymin, float ymax, const char* option ) {
117 
118  // need to convert the float bin array into a double bin array, because the DQMStore TProfile functions take floats, while the DQMStore TH2 functions take double.
119  vector<double> xbinsd(nbinsx+1);
120  for(int i=0; i<=nbinsx; ++i) {
121  xbinsd[i] = xbins[i];
122  }
123 
124  // DQM_ has to be initialized in a child analyzer.
125  if(DQM_) {
126  edm::LogInfo("Benchmark") << " Benchmark::bookProfile "<<"booked "<<histname;
127  return DQM_->bookProfile(histname, title, nbinsx, &xbinsd[0], ymin, ymax, option)->getTProfile();
128  }
129  else if(dir_) {
130  TDirectory *oldpwd = gDirectory;
131  dir_->cd();
132  TProfile *hist = new TProfile(histname, title, nbinsx, &xbinsd[0], ymin, ymax, option);
133  cout<<"booked (ROOT mode) "<<histname<<" in "<<dir_->GetName()<<endl;
134  oldpwd->cd();
135  return hist;
136  }
137  else assert(0);
138 }
139 
140 
142  //COLIN not sure about the root mode
143  if( dir_ )
144  dir_->Write();
145 
146  //COLIN remove old bullshit:
147 // if ( ame.size() != 0 && file_)
148 // cout<<"saving histograms in "<<fileName<<endl;
149 // file_->Write(fileName.c_str());
150 }
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:141
static DQMStore * DQM_
Definition: Benchmark.h:40
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
TProfile * bookProfile(const char *histname, const char *title, int nbinsx, float xmin, float xmax, float ymin, float ymax, const char *option)
book a TProfile histogram, either with DQM or plain root.
Definition: Benchmark.cc:95
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