CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
makeTKTrend.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <iostream>
3 #include <vector>
4 #include <map>
5 #include <string>
6 #include <sstream>
7 
8 #include "TFile.h"
9 #include "TVectorT.h"
10 #include "TGraph.h"
11 #include "TGaxis.h"
12 #include "TCanvas.h"
13 #include "TH1F.h"
14 #include "TFile.h"
15 
16 void makeTKTrend(const char* inFileName, const char* outFileName, std::string subDetName, std::string partName, const unsigned int partNumber);
17 
18 int main(int argc , char *argv[]) {
19 
20  if(argc==6) {
21  char* inFileName = argv[1];
22  char* outFileName = argv[2];
23  char* subDetName = argv[3];
24  char* partName = argv[4];
25  int partNumber = atoi(argv[5]);
26 
27  std::cout << "ready to make trend plots from "
28  << inFileName << " to " << outFileName << " for "
29  << subDetName << " " << partName << " " << partNumber << std::endl;
30 
31 
32  int returncode = 0;
33  makeTKTrend(inFileName,outFileName,subDetName,partName,partNumber);
34 
35  return returncode;
36 
37  }
38  else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
39 
40  return -9;
41 
42 }
43 
44 void makeTKTrend(const char* inFileName, const char* outFileName, std::string subDetName, std::string partName, const unsigned int partNumber)
45 {
46  // Maps <Run number, nBad>
47  std::map<unsigned int, unsigned int> badModulesTK;
48  std::map<unsigned int, unsigned int> badFibersTK;
49  std::map<unsigned int, unsigned int> badAPVsTK;
50  std::map<unsigned int, unsigned int> badStripsTK;
51  std::map<unsigned int, unsigned int> badStripsFromAPVsTK;
52  std::map<unsigned int, unsigned int> allBadStripsTK;
53 
54  std::ostringstream oss;
55 
56  if(partName=="All") partName="";
57 
58 // // Number of modules, fibers, APVs, strips for each tracker part
59 // std::vector< std::string > tkParts;
60 // tkParts.push_back("Tracker");
61 // tkParts.push_back("TIB");
62 // tkParts.push_back("TID");
63 // tkParts.push_back("TOB");
64 // tkParts.push_back("TEC");
65 // tkParts.push_back("TIB Layer 1");
66 // tkParts.push_back("TIB Layer 2");
67 // tkParts.push_back("TIB Layer 3");
68 // tkParts.push_back("TIB Layer 4");
69 // tkParts.push_back("TID+ Disk 1");
70 // tkParts.push_back("TID+ Disk 2");
71 // tkParts.push_back("TID+ Disk 3");
72 // tkParts.push_back("TID- Disk 1");
73 // tkParts.push_back("TID- Disk 2");
74 // tkParts.push_back("TID- Disk 3");
75 // tkParts.push_back("TOB Layer 1");
76 // tkParts.push_back("TOB Layer 2");
77 // tkParts.push_back("TOB Layer 3");
78 // tkParts.push_back("TOB Layer 4");
79 // tkParts.push_back("TOB Layer 5");
80 // tkParts.push_back("TOB Layer 6");
81 // tkParts.push_back("TEC+ Disk 1");
82 // tkParts.push_back("TEC+ Disk 2");
83 // tkParts.push_back("TEC+ Disk 3");
84 // tkParts.push_back("TEC+ Disk 4");
85 // tkParts.push_back("TEC+ Disk 5");
86 // tkParts.push_back("TEC+ Disk 6");
87 // tkParts.push_back("TEC+ Disk 7");
88 // tkParts.push_back("TEC+ Disk 8");
89 // tkParts.push_back("TEC+ Disk 9");
90 // tkParts.push_back("TEC- Disk 1");
91 // tkParts.push_back("TEC- Disk 2");
92 // tkParts.push_back("TEC- Disk 3");
93 // tkParts.push_back("TEC- Disk 4");
94 // tkParts.push_back("TEC- Disk 5");
95 // tkParts.push_back("TEC- Disk 6");
96 // tkParts.push_back("TEC- Disk 7");
97 // tkParts.push_back("TEC- Disk 8");
98 // tkParts.push_back("TEC- Disk 9");
99 //
100 // std::vector<unsigned int> nModules;
101 // nModules.push_back(15148);
102 // nModules.push_back(2724);
103 // nModules.push_back(816);
104 // nModules.push_back(5208);
105 // nModules.push_back(6400);
106 // nModules.push_back(672);
107 // nModules.push_back(864);
108 // nModules.push_back(540);
109 // nModules.push_back(648);
110 // nModules.push_back(136);
111 // nModules.push_back(136);
112 // nModules.push_back(136);
113 // nModules.push_back(136);
114 // nModules.push_back(136);
115 // nModules.push_back(136);
116 // nModules.push_back(1008);
117 // nModules.push_back(1152);
118 // nModules.push_back(648);
119 // nModules.push_back(720);
120 // nModules.push_back(792);
121 // nModules.push_back(888);
122 // nModules.push_back(408);
123 // nModules.push_back(408);
124 // nModules.push_back(408);
125 // nModules.push_back(360);
126 // nModules.push_back(360);
127 // nModules.push_back(360);
128 // nModules.push_back(312);
129 // nModules.push_back(312);
130 // nModules.push_back(272);
131 // nModules.push_back(408);
132 // nModules.push_back(408);
133 // nModules.push_back(408);
134 // nModules.push_back(360);
135 // nModules.push_back(360);
136 // nModules.push_back(360);
137 // nModules.push_back(312);
138 // nModules.push_back(312);
139 // nModules.push_back(272);
140 //
141 // std::vector<unsigned int> nFibers;
142 // nFibers.push_back(36392);
143 // nFibers.push_back(6984);
144 // nFibers.push_back(2208);
145 // nFibers.push_back(12096);
146 // nFibers.push_back(15104);
147 // nFibers.push_back(2016);
148 // nFibers.push_back(2592);
149 // nFibers.push_back(1080);
150 // nFibers.push_back(1296);
151 // nFibers.push_back(368);
152 // nFibers.push_back(368);
153 // nFibers.push_back(368);
154 // nFibers.push_back(368);
155 // nFibers.push_back(368);
156 // nFibers.push_back(368);
157 // nFibers.push_back(2016);
158 // nFibers.push_back(2304);
159 // nFibers.push_back(1296);
160 // nFibers.push_back(1440);
161 // nFibers.push_back(2376);
162 // nFibers.push_back(2664);
163 // nFibers.push_back(992);
164 // nFibers.push_back(992);
165 // nFibers.push_back(992);
166 // nFibers.push_back(848);
167 // nFibers.push_back(848);
168 // nFibers.push_back(848);
169 // nFibers.push_back(704);
170 // nFibers.push_back(704);
171 // nFibers.push_back(624);
172 // nFibers.push_back(992);
173 // nFibers.push_back(992);
174 // nFibers.push_back(992);
175 // nFibers.push_back(848);
176 // nFibers.push_back(848);
177 // nFibers.push_back(848);
178 // nFibers.push_back(704);
179 // nFibers.push_back(704);
180 // nFibers.push_back(624);
181 //
182 // std::vector<unsigned int> nAPVs;
183 // nAPVs.push_back(72784);
184 // nAPVs.push_back(13968);
185 // nAPVs.push_back(4416);
186 // nAPVs.push_back(24192);
187 // nAPVs.push_back(30208);
188 // nAPVs.push_back(4032);
189 // nAPVs.push_back(5184);
190 // nAPVs.push_back(2160);
191 // nAPVs.push_back(2592);
192 // nAPVs.push_back(736);
193 // nAPVs.push_back(736);
194 // nAPVs.push_back(736);
195 // nAPVs.push_back(736);
196 // nAPVs.push_back(736);
197 // nAPVs.push_back(736);
198 // nAPVs.push_back(4032);
199 // nAPVs.push_back(4608);
200 // nAPVs.push_back(2592);
201 // nAPVs.push_back(2880);
202 // nAPVs.push_back(4752);
203 // nAPVs.push_back(5328);
204 // nAPVs.push_back(1984);
205 // nAPVs.push_back(1984);
206 // nAPVs.push_back(1984);
207 // nAPVs.push_back(1696);
208 // nAPVs.push_back(1696);
209 // nAPVs.push_back(1696);
210 // nAPVs.push_back(1408);
211 // nAPVs.push_back(1408);
212 // nAPVs.push_back(1248);
213 // nAPVs.push_back(1984);
214 // nAPVs.push_back(1984);
215 // nAPVs.push_back(1984);
216 // nAPVs.push_back(1696);
217 // nAPVs.push_back(1696);
218 // nAPVs.push_back(1696);
219 // nAPVs.push_back(1408);
220 // nAPVs.push_back(1408);
221 // nAPVs.push_back(1248);
222 //
223 // std::vector<unsigned int> nStrips;
224 // nStrips.push_back(9316352);
225 // nStrips.push_back(1787904);
226 // nStrips.push_back(565248);
227 // nStrips.push_back(3096576);
228 // nStrips.push_back(3866624);
229 // nStrips.push_back(516096);
230 // nStrips.push_back(663552);
231 // nStrips.push_back(276480);
232 // nStrips.push_back(331776);
233 // nStrips.push_back(94208);
234 // nStrips.push_back(94208);
235 // nStrips.push_back(94208);
236 // nStrips.push_back(94208);
237 // nStrips.push_back(94208);
238 // nStrips.push_back(94208);
239 // nStrips.push_back(516096);
240 // nStrips.push_back(589824);
241 // nStrips.push_back(331776);
242 // nStrips.push_back(368640);
243 // nStrips.push_back(608256);
244 // nStrips.push_back(681984);
245 // nStrips.push_back(253952);
246 // nStrips.push_back(253952);
247 // nStrips.push_back(253952);
248 // nStrips.push_back(217088);
249 // nStrips.push_back(217088);
250 // nStrips.push_back(217088);
251 // nStrips.push_back(180224);
252 // nStrips.push_back(180224);
253 // nStrips.push_back(159744);
254 // nStrips.push_back(253952);
255 // nStrips.push_back(253952);
256 // nStrips.push_back(253952);
257 // nStrips.push_back(217088);
258 // nStrips.push_back(217088);
259 // nStrips.push_back(217088);
260 // nStrips.push_back(180224);
261 // nStrips.push_back(180224);
262 // nStrips.push_back(159744);
263 //
264 // // Map with <name of tracker part, count of channels in the part>
265 // std::map<std::string, unsigned int> allModulesTK;
266 // std::map<std::string, unsigned int> allFibersTK;
267 // std::map<std::string, unsigned int> allAPVsTK;
268 // std::map<std::string, unsigned int> allStripsTK;
269 // for(unsigned int i = 0; i < tkParts.size(); i++)
270 // {
271 // allModulesTK[tkParts[i].c_str()] = nModules[i];
272 // allFibersTK[tkParts[i].c_str()] = nFibers[i];
273 // allAPVsTK[tkParts[i].c_str()] = nAPVs[i];
274 // allStripsTK[tkParts[i].c_str()] = nStrips[i];
275 // }
276 //
277 // // for(std::map< std::string, unsigned int>::iterator it = allStripsTK.begin(); it != allStripsTK.end(); it++)
278 // // {
279 // // std::cout << it->first.c_str() << " " << it->second << std::endl;
280 // // }
281 //
282 // // Finds number of channels from above map
283 // std::string completePartName = subDetName;
284 // if(partName.compare("") != 0)
285 // completePartName += " " + partName;
286 // if(partNumber != 0)
287 // {
288 // oss.str("");
289 // oss << partNumber;
290 // completePartName += " " + oss.str();
291 // }
292 
293 // // Total number of channels in currently processed map
294 // const unsigned int nModulesInPart = allModulesTK[completePartName.c_str()];
295 // const unsigned int nFibersInPart = allFibersTK[completePartName.c_str()];
296 // const unsigned int nAPVsInPart = allAPVsTK[completePartName.c_str()];
297 // const unsigned int nStripsInPart = allStripsTK[completePartName.c_str()];
298 
299  // Read input file
300  std::ifstream resultsFile(inFileName);
301  unsigned int runIOV;
302  unsigned int values[6];
303  do
304  {
305  resultsFile >> runIOV;
306  resultsFile >> values[0] >> values[1] >> values[2] >> values[3] >> values[4] >> values[5];
307  // std::cout << runIOV << " " << values[0] << " " << values[1] << " " << values[2] << " " << values[3] << " " << values[4] << " " << values[5] << std::endl;
308  badModulesTK[runIOV]=values[0];
309  badFibersTK[runIOV]=values[1];
310  badAPVsTK[runIOV]=values[2];
311  badStripsTK[runIOV]=values[3];
312  badStripsFromAPVsTK[runIOV]=values[4];
313  allBadStripsTK[runIOV]=values[5];
314  }
315  while(!resultsFile.eof());
316 
317  const unsigned int IOVSize = badStripsTK.size();
318 
319  // Create histograms
320  std::string histoName;
321  std::string histoTitle;
322 
323  oss.str("");
324  histoName = "hBadModules" + subDetName + partName;
325  if(partNumber!=0)
326  {
327  oss << partNumber;
328  histoName += oss.str();
329  }
330  oss.str("");
331  histoTitle = "Bad modules in " + subDetName;
332  if(partName!="")
333  {
334  histoTitle += " " + partName;
335  }
336  if(partNumber!=0)
337  {
338  oss << partNumber;
339  histoTitle += " " + oss.str();
340  }
341  TH1F* hBadModulesTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
342 
343  oss.str("");
344  histoName = "hBadFibers" + subDetName + partName;
345  if(partNumber!=0)
346  {
347  oss << partNumber;
348  histoName += oss.str();
349  }
350  oss.str("");
351  histoTitle = "Bad fibers in " + subDetName;
352  if(partName!="")
353  {
354  histoTitle += " " + partName;
355  }
356  if(partNumber!=0)
357  {
358  oss << partNumber;
359  histoTitle += " " + oss.str();
360  }
361  TH1F* hBadFibersTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
362 
363  oss.str("");
364  histoName = "hBadAPVs" + subDetName + partName;
365  if(partNumber!=0)
366  {
367  oss << partNumber;
368  histoName += oss.str();
369  }
370  oss.str("");
371  histoTitle = "Bad APVs in " + subDetName;
372  if(partName!="")
373  {
374  histoTitle += " " + partName;
375  }
376  if(partNumber!=0)
377  {
378  oss << partNumber;
379  histoTitle += " " + oss.str();
380  }
381  TH1F* hBadAPVsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
382 
383  oss.str("");
384  histoName = "hBadStrips" + subDetName + partName;
385  if(partNumber!=0)
386  {
387  oss << partNumber;
388  histoName += oss.str();
389  }
390  oss.str("");
391  histoTitle = "Bad strips in " + subDetName;
392  if(partName!="")
393  {
394  histoTitle += " " + partName;
395  }
396  if(partNumber!=0)
397  {
398  oss << partNumber;
399  histoTitle += " " + oss.str();
400  }
401  TH1F* hBadStripsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
402 
403  oss.str("");
404  histoName = "hBadStripsFromAPVs" + subDetName + partName;
405  if(partNumber!=0)
406  {
407  oss << partNumber;
408  histoName += oss.str();
409  }
410  oss.str("");
411  histoTitle = "Bad strips from APVs in " + subDetName;
412  if(partName!="")
413  {
414  histoTitle += " " + partName;
415  }
416  if(partNumber!=0)
417  {
418  oss << partNumber;
419  histoTitle += " " + oss.str();
420  }
421  TH1F* hBadStripsFromAPVsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
422 
423  oss.str("");
424  histoName = "hAllBadStrips" + subDetName + partName;
425  if(partNumber!=0)
426  {
427  oss << partNumber;
428  histoName += oss.str();
429  }
430  oss.str("");
431  histoTitle = "All bad strips in " + subDetName;
432  if(partName!="")
433  {
434  histoTitle += " " + partName;
435  }
436  if(partNumber!=0)
437  {
438  oss << partNumber;
439  histoTitle += " " + oss.str();
440  }
441  TH1F* hAllBadStripsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
442 
443  unsigned int j = 0;
444  for(std::map<unsigned int, unsigned int>::iterator iMap=badModulesTK.begin(); iMap!=badModulesTK.end(); iMap++ )
445  {
446  hBadModulesTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nModulesInPart*/);
447  oss.str("");
448  oss << iMap->first;
449  hBadModulesTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
450  // std::cout << hBadModulesTK->GetBinContent(j) << std::endl;
451  }
452  TCanvas* cBadModulesTK = new TCanvas();
453  hBadModulesTK->Draw();
454  cBadModulesTK->Update();
455 
456  j = 0;
457  for(std::map<unsigned int, unsigned int>::iterator iMap=badFibersTK.begin(); iMap!=badFibersTK.end(); iMap++ )
458  {
459  hBadFibersTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nFibersInPart*/);
460  oss.str("");
461  oss << iMap->first;
462  hBadFibersTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
463  // std::cout << hBadFibersTK->GetBinContent(j) << std::endl;
464  }
465  TCanvas* cBadFibersTK = new TCanvas();
466  hBadFibersTK->Draw();
467  cBadFibersTK->Update();
468 
469  j = 0;
470  for(std::map<unsigned int, unsigned int>::iterator iMap=badAPVsTK.begin(); iMap!=badAPVsTK.end(); iMap++ )
471  {
472  hBadAPVsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nAPVsInPart*/);
473  oss.str("");
474  oss << iMap->first;
475  hBadAPVsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
476  // std::cout << hBadAPVsTK->GetBinContent(j) << std::endl;
477  }
478  TCanvas* cBadAPVsTK = new TCanvas();
479  hBadAPVsTK->Draw();
480  cBadAPVsTK->Update();
481 
482  j = 0;
483  for(std::map<unsigned int, unsigned int>::iterator iMap=badStripsTK.begin(); iMap!=badStripsTK.end(); iMap++ )
484  {
485  hBadStripsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nStripsInPart*/);
486  oss.str("");
487  oss << iMap->first;
488  hBadStripsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
489  // std::cout << hBadStripsTK->GetBinContent(j) << std::endl;
490  }
491  TCanvas* cBadStripsTK = new TCanvas();
492  hBadStripsTK->Draw();
493  cBadStripsTK->Update();
494 
495  j = 0;
496  for(std::map<unsigned int, unsigned int>::iterator iMap=badStripsFromAPVsTK.begin(); iMap!=badStripsFromAPVsTK.end(); iMap++ )
497  {
498  hBadStripsFromAPVsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nStripsInPart*/);
499  oss.str("");
500  oss << iMap->first;
501  hBadStripsFromAPVsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
502  // std::cout << hBadStripsTK->GetBinContent(j) << std::endl;
503  }
504  TCanvas* cBadStripsFromAPVsTK = new TCanvas();
505  hBadStripsFromAPVsTK->Draw();
506  cBadStripsFromAPVsTK->Update();
507 
508  j = 0;
509  for(std::map<unsigned int, unsigned int>::iterator iMap=allBadStripsTK.begin(); iMap!=allBadStripsTK.end(); iMap++ )
510  {
511  hAllBadStripsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nStripsInPart*/);
512  oss.str("");
513  oss << iMap->first;
514  hAllBadStripsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
515  // std::cout << hAllBadStripsTK->GetBinContent(j) << std::endl;
516  }
517  TCanvas* cAllBadStripsTK = new TCanvas();
518  hAllBadStripsTK->Draw();
519  cAllBadStripsTK->Update();
520 
521  // Write histograms to output file
522 
523  // std::cout << "Ready to open the file " << outFileName << std::endl;
524 
525  TFile* outFile = new TFile(outFileName, "UPDATE");
526 
527  // std::cout << "File opened: " << outFileName << std::endl;
528 
529  outFile->cd();
530  hBadModulesTK->Write();
531  hBadFibersTK->Write();
532  hBadAPVsTK->Write();
533  hBadStripsTK->Write();
534  hBadStripsFromAPVsTK->Write();
535  hAllBadStripsTK->Write();
536 
537  // std::cout << "histograms written in " << outFileName << std::endl;
538 
539  delete outFile;
540  delete hBadModulesTK;
541  delete hBadFibersTK;
542  delete hBadAPVsTK;
543  delete hBadStripsTK;
544  delete hBadStripsFromAPVsTK;
545  delete hAllBadStripsTK;
546  delete cBadModulesTK;
547  delete cBadFibersTK;
548  delete cBadAPVsTK;
549  delete cBadStripsTK;
550  delete cBadStripsFromAPVsTK;
551  delete cAllBadStripsTK;
552 
553 }
void makeTKTrend(const char *inFileName, const char *outFileName, std::string subDetName, std::string partName, const unsigned int partNumber)
Definition: makeTKTrend.cc:44
int j
Definition: DBlmapReader.cc:9
tuple argc
Definition: dir2webdir.py:38
tuple cout
Definition: gather_cfg.py:145