CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
moduleOccupancyPlots.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <sstream>
4 #include <string>
5 
6 #include "TFile.h"
7 #include "TH1D.h"
8 #include "TCanvas.h"
9 
10 #define NOISEPREFIX "Profile_NoiseFromCondDB__det__"
11 #define PEDESTALPREFIX "Profile_PedestalFromCondDB__det__"
12 #define OCCUPANCYPREFIX "ClusterDigiPosition__det__"
13 
14 void printPlot(TH1D* hist, char* prefix, char* postfix);
15 
16 int main(int argc, char *argv[]) {
17 
18  char* rootfilename;
19  char* modulelistname;
20  int pnbits;
21  char* prefix;
22  char* postfix;
23 
24  if(argc==6) {
25  rootfilename = argv[1];
26  modulelistname = argv[2];
27  pnbits = atoi(argv[3]);
28  prefix = argv[4];
29  postfix = argv[5];
30  }
31  else {
32  std::cout << "Wrong number of parameters " << argc << std::endl;
33  return 1;
34  }
35 
36  std::cout << "ready to go " << rootfilename << ' ' << modulelistname << std::endl;
37 
38  TFile* rootfile = new TFile(rootfilename,"READ");
39  if(!rootfile) {
40  std::cout << "Problems with input root file" << std::endl;
41  return 2;
42  }
43  int detid;
44  std::ifstream modulelist(modulelistname);
45 
46  std::stringstream outrootfilename;
47  outrootfilename << prefix << "SummaryFile" << postfix << ".root";
48  TFile* outrootfile = new TFile(outrootfilename.str().c_str(),"CREATE");
49 
50  while (modulelist >> detid) {
51  std::cout << " ready to go with detid " << detid << " " << pnbits << std::endl;
52  // bit 0: noise
53  if(pnbits & 1) {
54  std::stringstream histoname;
55  histoname << NOISEPREFIX << detid;
56  std::cout << " ready to go with histogram " << histoname.str() << std::endl;
57  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
58  if(hist) {
59  std:: cout << histoname.str() << " found!" << std::endl;
60  printPlot(hist,prefix,postfix);
61  hist->Write();
62  } else {
63  std:: cout << histoname.str() << " NOT found..." << std::endl;
64  }
65  }
66  // bit 1: pedestal
67  if(pnbits & 2) {
68  std::stringstream histoname;
69  histoname << PEDESTALPREFIX << detid;
70  std::cout << " ready to go with histogram " << histoname.str() << std::endl;
71  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
72  if(hist) {
73  std:: cout << histoname.str() << " found!" << std::endl;
74  printPlot(hist,prefix,postfix);
75  hist->Write();
76  } else {
77  std:: cout << histoname.str() << " NOT found..." << std::endl;
78  }
79  }
80  // bit 2: pedestal
81  if(pnbits & 4) {
82  std::stringstream histoname;
83  histoname << OCCUPANCYPREFIX << detid;
84  std::cout << " ready to go with histogram " << histoname.str() << std::endl;
85  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
86  if(hist) {
87  std:: cout << histoname.str() << " found!" << std::endl;
88  printPlot(hist,prefix,postfix);
89  hist->Write();
90  } else {
91  std:: cout << histoname.str() << " NOT found..." << std::endl;
92  }
93  }
94  }
95 
96  outrootfile->Close();
97 
98  return 0;
99 
100 }
101 
102 void printPlot(TH1D* hist, char* prefix, char* postfix) {
103 
104  TCanvas* cc= new TCanvas;
105  hist->Draw();
106  std::stringstream filename;
107  filename << prefix << hist->GetName() << postfix << ".png";
108  cc->Print(filename.str().c_str());
109  delete cc;
110 
111 }
void printPlot(TH1D *hist, char *prefix, char *postfix)
int main(int argc, char **argv)
#define NOISEPREFIX
#define OCCUPANCYPREFIX
tuple argc
Definition: dir2webdir.py:38
#define PEDESTALPREFIX
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121