CMS 3D CMS Logo

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 "TDirectoryFile.h"
9 #include "TCanvas.h"
10 
11 #define NOISEPREFIX "Profile_NoiseFromCondDB__det__"
12 #define PEDESTALPREFIX "Profile_PedestalFromCondDB__det__"
13 #define OCCUPANCYPREFIX "ClusterDigiPosition__det__"
14 
15 void printPlot(TH1D* hist, char* prefix, char* postfix);
16 int getChannelNumber(int ival);
17 
18 int main(int argc, char *argv[]) {
19 
20  char* rootfilename;
21  char* modulelistname;
22  int pnbits;
23  char* prefix;
24  char* postfix;
25 
26  bool debugPrint = false;
27  bool imagePrint = false;
28 
29  if(argc==6) {
30  rootfilename = argv[1];
31  modulelistname = argv[2];
32  pnbits = atoi(argv[3]);
33  prefix = argv[4];
34  postfix = argv[5];
35  }
36  else {
37  std::cout << "Wrong number of parameters " << argc << std::endl;
38  return 1;
39  }
40 
41  if (debugPrint) std::cout << "ready to go " << rootfilename << ' ' << modulelistname << std::endl;
42 
43  TFile* rootfile = TFile::Open(rootfilename,"READ");
44  if(!rootfile) {
45  std::cout << "Problems with input root file" << std::endl;
46  return 2;
47  }
48  int detid;
49  std::ifstream modulelist(modulelistname);
50 
51  std::stringstream outrootfilename;
52  outrootfilename << prefix << "SummaryFile" << postfix << ".root";
53  TFile* outrootfile = TFile::Open(outrootfilename.str().c_str(),"RECREATE");
54 
55  TH1D* th_summary = nullptr;
56  Double_t TotalEvents = 0.0;
57  Double_t TotalDigis = 0.0;
58 
59  TH1D* TotEvents= new TH1D("TotEvents","TotEvents",1,0,1);
60 
61  if(pnbits & 4) {
62  TDirectoryFile* tdir = (TDirectoryFile*) rootfile->FindObjectAny("AlCaReco");
63  TH1D* hist = (TH1D*)tdir->FindObjectAny("TotalNumberOfCluster__TIB");
64  if (hist) {
65  TotalEvents = hist->GetEntries();
66  TotEvents->SetBinContent(1,TotalEvents);
67  TotEvents->Write();
68  }
69  }
70  while (modulelist >> detid) {
71  if (debugPrint) std::cout << " ready to go with detid " << detid << " " << pnbits << std::endl;
72  // bit 0: noise
73  if(pnbits & 1) {
74  std::stringstream histoname;
75  histoname << NOISEPREFIX << detid;
76  if (debugPrint) std::cout << " ready to go with histogram " << histoname.str() << std::endl;
77  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
78  if(hist) {
79  if (debugPrint) std::cout << histoname.str() << " found!" << std::endl;
80  if (imagePrint) printPlot(hist,prefix,postfix);
81  hist->Write();
82  } else {
83  std::cout << histoname.str() << " NOT found..." << std::endl;
84  }
85  }
86  // bit 1: pedestal
87  if(pnbits & 2) {
88  std::stringstream histoname;
89  histoname << PEDESTALPREFIX << detid;
90  if (debugPrint) std::cout << " ready to go with histogram " << histoname.str() << std::endl;
91  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
92  if(hist) {
93  if (debugPrint) std::cout << histoname.str() << " found!" << std::endl;
94  if (imagePrint) printPlot(hist,prefix,postfix);
95  hist->Write();
96  } else {
97  std::cout << histoname.str() << " NOT found..." << std::endl;
98  }
99  }
100  // bit 2: Occupancy
101  if(pnbits & 4) {
102  std::stringstream histoname;
103  histoname << OCCUPANCYPREFIX << detid;
104  std::string SummaryName= "ClusterDigiPosition__det__Summary";
105 
106  if (debugPrint) std::cout << " ready to go with histogram " << histoname.str() << std::endl;
107  if (th_summary == nullptr) th_summary = new TH1D(SummaryName.c_str(), SummaryName.c_str(), 768, 0.5, 768.5);
108  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
109  if(hist) {
110  if (debugPrint) std::cout << histoname.str() << " found!" << hist->GetEntries() << std::endl;
111  for (int i = 1; i < hist->GetNbinsX()+1; i++) {
112  th_summary->AddBinContent(i, hist->GetBinContent(i));
113  TotalDigis += hist->GetBinContent(i);
114  }
115  hist->SetLineColor(2);
116  if (imagePrint) printPlot(hist,prefix,postfix);
117  hist->Write();
118  } else {
119  std::cout << histoname.str() << " NOT found..." << std::endl;
120  }
121  }
122  // bit 3 : reorder
123  if(pnbits & 8) {
124  std::stringstream histoname;
125  histoname << OCCUPANCYPREFIX << detid;
126  if (debugPrint) std::cout << " ready to go with histogram " << histoname.str() << std::endl;
127  TH1D* hist = (TH1D*)rootfile->FindObjectAny(histoname.str().c_str());
128  if(hist) {
129  if (debugPrint) std::cout << histoname.str() << " found!" << std::endl;
130  std::stringstream histoname_reorder;
131  histoname_reorder << OCCUPANCYPREFIX <<"_reorder_"<< detid;
132  TH1D* hist_reorder = new TH1D(histoname_reorder.str().c_str(), histoname_reorder.str().c_str(),
133  hist->GetXaxis()->GetNbins(), hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax());
134  for (int i = 0; i < hist_reorder->GetNbinsX(); i++) {
135  int chan = getChannelNumber(i);
136  hist_reorder->SetBinContent(i+1,hist->GetBinContent(chan));
137  }
138  hist->Write();
139  hist_reorder->Write();
140  } else {
141  std::cout << histoname.str() << " NOT found..." << std::endl;
142  }
143  }
144 
145  }
146  if (th_summary) {
147  std::string fname = rootfilename;
148  std::string run = fname.substr(fname.find("R000")+4,6);
149  if (TotalEvents) {
150  Double_t fac = 1.0/TotalEvents;
151  th_summary->Scale(fac);
152  std::cout << " Run Number " << run << " Events " << TotalEvents << " Total # of Digis " << TotalDigis << " Av. Digis " << TotalDigis*fac << std::endl;
153  th_summary->SetEntries(TotalDigis*fac);
154 
155  }
156  th_summary->Write();
157  printPlot(th_summary,prefix,postfix);
158  }
159 
160  outrootfile->Close();
161 
162  return 0;
163 
164 }
165 
166 void printPlot(TH1D* hist, char* prefix, char* postfix) {
167 
168  TCanvas* cc= new TCanvas;
169  hist->Draw();
170  std::stringstream filename;
171  filename << prefix << hist->GetName() << postfix << ".png";
172  cc->Print(filename.str().c_str());
173  delete cc;
174 
175 }
176 int getChannelNumber(int ival) {
177 
178  int chan=int(32*fmod(int(fmod(ival,256.)/2.),4.) +
179  8*int(int(fmod(ival,256.)/2.)/4.) -
180  31*int(int(fmod(ival,256.)/2.)/16.) +
181  fmod(fmod(ival,256.),2.)*128 +
182  int(ival/256)*256);
183  return chan;
184 }
cmsBatch.argv
argv
Definition: cmsBatch.py:279
mps_fire.i
i
Definition: mps_fire.py:428
OCCUPANCYPREFIX
#define OCCUPANCYPREFIX
Definition: moduleOccupancyPlots.cc:13
dir2webdir.argc
argc
Definition: dir2webdir.py:39
gather_cfg.cout
cout
Definition: gather_cfg.py:144
getChannelNumber
int getChannelNumber(int ival)
Definition: moduleOccupancyPlots.cc:176
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
main
int main(int argc, char *argv[])
Definition: moduleOccupancyPlots.cc:18
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
printPlot
void printPlot(TH1D *hist, char *prefix, char *postfix)
Definition: moduleOccupancyPlots.cc:166
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
createfilelist.int
int
Definition: createfilelist.py:10
cc
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
writedatasetfile.run
run
Definition: writedatasetfile.py:27
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
doHarvest.rootfile
rootfile
Definition: doHarvest.py:122
NOISEPREFIX
#define NOISEPREFIX
Definition: moduleOccupancyPlots.cc:11
hcallasereventfilter2012_cfi.prefix
prefix
Definition: hcallasereventfilter2012_cfi.py:10
PEDESTALPREFIX
#define PEDESTALPREFIX
Definition: moduleOccupancyPlots.cc:12