Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:12:02

0001 #include <fstream>
0002 #include <iostream>
0003 #include <vector>
0004 #include <map>
0005 #include <string>
0006 #include <sstream>
0007 
0008 #include "TFile.h"
0009 #include "TVectorT.h"
0010 #include "TGraph.h"
0011 #include "TGaxis.h"
0012 #include "TCanvas.h"
0013 #include "TH1F.h"
0014 #include "TFile.h"
0015 
0016 void makeTKTrend(const char* inFileName,
0017                  const char* outFileName,
0018                  std::string subDetName,
0019                  std::string partName,
0020                  const unsigned int partNumber);
0021 
0022 int main(int argc, char* argv[]) {
0023   if (argc == 6) {
0024     char* inFileName = argv[1];
0025     char* outFileName = argv[2];
0026     char* subDetName = argv[3];
0027     char* partName = argv[4];
0028     int partNumber = atoi(argv[5]);
0029 
0030     std::cout << "ready to make trend plots from " << inFileName << " to " << outFileName << " for " << subDetName
0031               << " " << partName << " " << partNumber << std::endl;
0032 
0033     int returncode = 0;
0034     makeTKTrend(inFileName, outFileName, subDetName, partName, partNumber);
0035 
0036     return returncode;
0037 
0038   } else {
0039     std::cout << "Too few arguments: " << argc << std::endl;
0040     return -1;
0041   }
0042 
0043   return -9;
0044 }
0045 
0046 void makeTKTrend(const char* inFileName,
0047                  const char* outFileName,
0048                  std::string subDetName,
0049                  std::string partName,
0050                  const unsigned int partNumber) {
0051   // Maps <Run number, nBad>
0052   std::map<unsigned int, unsigned int> badModulesTK;
0053   std::map<unsigned int, unsigned int> badFibersTK;
0054   std::map<unsigned int, unsigned int> badAPVsTK;
0055   std::map<unsigned int, unsigned int> badStripsTK;
0056   std::map<unsigned int, unsigned int> badStripsFromAPVsTK;
0057   std::map<unsigned int, unsigned int> allBadStripsTK;
0058 
0059   std::ostringstream oss;
0060 
0061   if (partName == "All")
0062     partName = "";
0063 
0064   //   // Number of modules, fibers, APVs, strips for each tracker part
0065   //   std::vector< std::string > tkParts;
0066   //   tkParts.push_back("Tracker");
0067   //   tkParts.push_back("TIB");
0068   //   tkParts.push_back("TID");
0069   //   tkParts.push_back("TOB");
0070   //   tkParts.push_back("TEC");
0071   //   tkParts.push_back("TIB Layer 1");
0072   //   tkParts.push_back("TIB Layer 2");
0073   //   tkParts.push_back("TIB Layer 3");
0074   //   tkParts.push_back("TIB Layer 4");
0075   //   tkParts.push_back("TID+ Disk 1");
0076   //   tkParts.push_back("TID+ Disk 2");
0077   //   tkParts.push_back("TID+ Disk 3");
0078   //   tkParts.push_back("TID- Disk 1");
0079   //   tkParts.push_back("TID- Disk 2");
0080   //   tkParts.push_back("TID- Disk 3");
0081   //   tkParts.push_back("TOB Layer 1");
0082   //   tkParts.push_back("TOB Layer 2");
0083   //   tkParts.push_back("TOB Layer 3");
0084   //   tkParts.push_back("TOB Layer 4");
0085   //   tkParts.push_back("TOB Layer 5");
0086   //   tkParts.push_back("TOB Layer 6");
0087   //   tkParts.push_back("TEC+ Disk 1");
0088   //   tkParts.push_back("TEC+ Disk 2");
0089   //   tkParts.push_back("TEC+ Disk 3");
0090   //   tkParts.push_back("TEC+ Disk 4");
0091   //   tkParts.push_back("TEC+ Disk 5");
0092   //   tkParts.push_back("TEC+ Disk 6");
0093   //   tkParts.push_back("TEC+ Disk 7");
0094   //   tkParts.push_back("TEC+ Disk 8");
0095   //   tkParts.push_back("TEC+ Disk 9");
0096   //   tkParts.push_back("TEC- Disk 1");
0097   //   tkParts.push_back("TEC- Disk 2");
0098   //   tkParts.push_back("TEC- Disk 3");
0099   //   tkParts.push_back("TEC- Disk 4");
0100   //   tkParts.push_back("TEC- Disk 5");
0101   //   tkParts.push_back("TEC- Disk 6");
0102   //   tkParts.push_back("TEC- Disk 7");
0103   //   tkParts.push_back("TEC- Disk 8");
0104   //   tkParts.push_back("TEC- Disk 9");
0105   //
0106   //   std::vector<unsigned int> nModules;
0107   //   nModules.push_back(15148);
0108   //   nModules.push_back(2724);
0109   //   nModules.push_back(816);
0110   //   nModules.push_back(5208);
0111   //   nModules.push_back(6400);
0112   //   nModules.push_back(672);
0113   //   nModules.push_back(864);
0114   //   nModules.push_back(540);
0115   //   nModules.push_back(648);
0116   //   nModules.push_back(136);
0117   //   nModules.push_back(136);
0118   //   nModules.push_back(136);
0119   //   nModules.push_back(136);
0120   //   nModules.push_back(136);
0121   //   nModules.push_back(136);
0122   //   nModules.push_back(1008);
0123   //   nModules.push_back(1152);
0124   //   nModules.push_back(648);
0125   //   nModules.push_back(720);
0126   //   nModules.push_back(792);
0127   //   nModules.push_back(888);
0128   //   nModules.push_back(408);
0129   //   nModules.push_back(408);
0130   //   nModules.push_back(408);
0131   //   nModules.push_back(360);
0132   //   nModules.push_back(360);
0133   //   nModules.push_back(360);
0134   //   nModules.push_back(312);
0135   //   nModules.push_back(312);
0136   //   nModules.push_back(272);
0137   //   nModules.push_back(408);
0138   //   nModules.push_back(408);
0139   //   nModules.push_back(408);
0140   //   nModules.push_back(360);
0141   //   nModules.push_back(360);
0142   //   nModules.push_back(360);
0143   //   nModules.push_back(312);
0144   //   nModules.push_back(312);
0145   //   nModules.push_back(272);
0146   //
0147   //   std::vector<unsigned int> nFibers;
0148   //   nFibers.push_back(36392);
0149   //   nFibers.push_back(6984);
0150   //   nFibers.push_back(2208);
0151   //   nFibers.push_back(12096);
0152   //   nFibers.push_back(15104);
0153   //   nFibers.push_back(2016);
0154   //   nFibers.push_back(2592);
0155   //   nFibers.push_back(1080);
0156   //   nFibers.push_back(1296);
0157   //   nFibers.push_back(368);
0158   //   nFibers.push_back(368);
0159   //   nFibers.push_back(368);
0160   //   nFibers.push_back(368);
0161   //   nFibers.push_back(368);
0162   //   nFibers.push_back(368);
0163   //   nFibers.push_back(2016);
0164   //   nFibers.push_back(2304);
0165   //   nFibers.push_back(1296);
0166   //   nFibers.push_back(1440);
0167   //   nFibers.push_back(2376);
0168   //   nFibers.push_back(2664);
0169   //   nFibers.push_back(992);
0170   //   nFibers.push_back(992);
0171   //   nFibers.push_back(992);
0172   //   nFibers.push_back(848);
0173   //   nFibers.push_back(848);
0174   //   nFibers.push_back(848);
0175   //   nFibers.push_back(704);
0176   //   nFibers.push_back(704);
0177   //   nFibers.push_back(624);
0178   //   nFibers.push_back(992);
0179   //   nFibers.push_back(992);
0180   //   nFibers.push_back(992);
0181   //   nFibers.push_back(848);
0182   //   nFibers.push_back(848);
0183   //   nFibers.push_back(848);
0184   //   nFibers.push_back(704);
0185   //   nFibers.push_back(704);
0186   //   nFibers.push_back(624);
0187   //
0188   //   std::vector<unsigned int> nAPVs;
0189   //   nAPVs.push_back(72784);
0190   //   nAPVs.push_back(13968);
0191   //   nAPVs.push_back(4416);
0192   //   nAPVs.push_back(24192);
0193   //   nAPVs.push_back(30208);
0194   //   nAPVs.push_back(4032);
0195   //   nAPVs.push_back(5184);
0196   //   nAPVs.push_back(2160);
0197   //   nAPVs.push_back(2592);
0198   //   nAPVs.push_back(736);
0199   //   nAPVs.push_back(736);
0200   //   nAPVs.push_back(736);
0201   //   nAPVs.push_back(736);
0202   //   nAPVs.push_back(736);
0203   //   nAPVs.push_back(736);
0204   //   nAPVs.push_back(4032);
0205   //   nAPVs.push_back(4608);
0206   //   nAPVs.push_back(2592);
0207   //   nAPVs.push_back(2880);
0208   //   nAPVs.push_back(4752);
0209   //   nAPVs.push_back(5328);
0210   //   nAPVs.push_back(1984);
0211   //   nAPVs.push_back(1984);
0212   //   nAPVs.push_back(1984);
0213   //   nAPVs.push_back(1696);
0214   //   nAPVs.push_back(1696);
0215   //   nAPVs.push_back(1696);
0216   //   nAPVs.push_back(1408);
0217   //   nAPVs.push_back(1408);
0218   //   nAPVs.push_back(1248);
0219   //   nAPVs.push_back(1984);
0220   //   nAPVs.push_back(1984);
0221   //   nAPVs.push_back(1984);
0222   //   nAPVs.push_back(1696);
0223   //   nAPVs.push_back(1696);
0224   //   nAPVs.push_back(1696);
0225   //   nAPVs.push_back(1408);
0226   //   nAPVs.push_back(1408);
0227   //   nAPVs.push_back(1248);
0228   //
0229   //   std::vector<unsigned int> nStrips;
0230   //   nStrips.push_back(9316352);
0231   //   nStrips.push_back(1787904);
0232   //   nStrips.push_back(565248);
0233   //   nStrips.push_back(3096576);
0234   //   nStrips.push_back(3866624);
0235   //   nStrips.push_back(516096);
0236   //   nStrips.push_back(663552);
0237   //   nStrips.push_back(276480);
0238   //   nStrips.push_back(331776);
0239   //   nStrips.push_back(94208);
0240   //   nStrips.push_back(94208);
0241   //   nStrips.push_back(94208);
0242   //   nStrips.push_back(94208);
0243   //   nStrips.push_back(94208);
0244   //   nStrips.push_back(94208);
0245   //   nStrips.push_back(516096);
0246   //   nStrips.push_back(589824);
0247   //   nStrips.push_back(331776);
0248   //   nStrips.push_back(368640);
0249   //   nStrips.push_back(608256);
0250   //   nStrips.push_back(681984);
0251   //   nStrips.push_back(253952);
0252   //   nStrips.push_back(253952);
0253   //   nStrips.push_back(253952);
0254   //   nStrips.push_back(217088);
0255   //   nStrips.push_back(217088);
0256   //   nStrips.push_back(217088);
0257   //   nStrips.push_back(180224);
0258   //   nStrips.push_back(180224);
0259   //   nStrips.push_back(159744);
0260   //   nStrips.push_back(253952);
0261   //   nStrips.push_back(253952);
0262   //   nStrips.push_back(253952);
0263   //   nStrips.push_back(217088);
0264   //   nStrips.push_back(217088);
0265   //   nStrips.push_back(217088);
0266   //   nStrips.push_back(180224);
0267   //   nStrips.push_back(180224);
0268   //   nStrips.push_back(159744);
0269   //
0270   //   // Map with <name of tracker part, count of channels in the part>
0271   //   std::map<std::string, unsigned int> allModulesTK;
0272   //   std::map<std::string, unsigned int> allFibersTK;
0273   //   std::map<std::string, unsigned int> allAPVsTK;
0274   //   std::map<std::string, unsigned int> allStripsTK;
0275   //   for(unsigned int i = 0; i < tkParts.size(); i++)
0276   //   {
0277   //     allModulesTK[tkParts[i].c_str()] = nModules[i];
0278   //     allFibersTK[tkParts[i].c_str()] = nFibers[i];
0279   //     allAPVsTK[tkParts[i].c_str()] = nAPVs[i];
0280   //     allStripsTK[tkParts[i].c_str()] = nStrips[i];
0281   //   }
0282   //
0283   // //   for(std::map< std::string, unsigned int>::iterator it = allStripsTK.begin(); it != allStripsTK.end(); it++)
0284   // //   {
0285   // //     std::cout << it->first.c_str() << " " << it->second << std::endl;
0286   // //   }
0287   //
0288   //   // Finds number of channels from above map
0289   //   std::string completePartName = subDetName;
0290   //   if(partName.compare("") != 0)
0291   //     completePartName += " " + partName;
0292   //   if(partNumber != 0)
0293   //   {
0294   //     oss.str("");
0295   //     oss << partNumber;
0296   //     completePartName += " " + oss.str();
0297   //   }
0298 
0299   //   // Total number of channels in currently processed map
0300   //   const unsigned int nModulesInPart = allModulesTK[completePartName.c_str()];
0301   //   const unsigned int nFibersInPart = allFibersTK[completePartName.c_str()];
0302   //   const unsigned int nAPVsInPart = allAPVsTK[completePartName.c_str()];
0303   //   const unsigned int nStripsInPart = allStripsTK[completePartName.c_str()];
0304 
0305   // Read input file
0306   std::ifstream resultsFile(inFileName);
0307   unsigned int runIOV;
0308   unsigned int values[6];
0309   do {
0310     resultsFile >> runIOV;
0311     resultsFile >> values[0] >> values[1] >> values[2] >> values[3] >> values[4] >> values[5];
0312     //    std::cout << runIOV << " " << values[0] << " " << values[1] << " " << values[2] << " " << values[3] << " " << values[4] << " " << values[5] << std::endl;
0313     badModulesTK[runIOV] = values[0];
0314     badFibersTK[runIOV] = values[1];
0315     badAPVsTK[runIOV] = values[2];
0316     badStripsTK[runIOV] = values[3];
0317     badStripsFromAPVsTK[runIOV] = values[4];
0318     allBadStripsTK[runIOV] = values[5];
0319   } while (!resultsFile.eof());
0320 
0321   const unsigned int IOVSize = badStripsTK.size();
0322 
0323   // Create histograms
0324   std::string histoName;
0325   std::string histoTitle;
0326 
0327   oss.str("");
0328   histoName = "hBadModules" + subDetName + partName;
0329   if (partNumber != 0) {
0330     oss << partNumber;
0331     histoName += oss.str();
0332   }
0333   oss.str("");
0334   histoTitle = "Bad modules in " + subDetName;
0335   if (!partName.empty()) {
0336     histoTitle += " " + partName;
0337   }
0338   if (partNumber != 0) {
0339     oss << partNumber;
0340     histoTitle += " " + oss.str();
0341   }
0342   TH1F* hBadModulesTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize + 0.5);
0343 
0344   oss.str("");
0345   histoName = "hBadFibers" + subDetName + partName;
0346   if (partNumber != 0) {
0347     oss << partNumber;
0348     histoName += oss.str();
0349   }
0350   oss.str("");
0351   histoTitle = "Bad fibers in " + subDetName;
0352   if (!partName.empty()) {
0353     histoTitle += " " + partName;
0354   }
0355   if (partNumber != 0) {
0356     oss << partNumber;
0357     histoTitle += " " + oss.str();
0358   }
0359   TH1F* hBadFibersTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize + 0.5);
0360 
0361   oss.str("");
0362   histoName = "hBadAPVs" + subDetName + partName;
0363   if (partNumber != 0) {
0364     oss << partNumber;
0365     histoName += oss.str();
0366   }
0367   oss.str("");
0368   histoTitle = "Bad APVs in " + subDetName;
0369   if (!partName.empty()) {
0370     histoTitle += " " + partName;
0371   }
0372   if (partNumber != 0) {
0373     oss << partNumber;
0374     histoTitle += " " + oss.str();
0375   }
0376   TH1F* hBadAPVsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize + 0.5);
0377 
0378   oss.str("");
0379   histoName = "hBadStrips" + subDetName + partName;
0380   if (partNumber != 0) {
0381     oss << partNumber;
0382     histoName += oss.str();
0383   }
0384   oss.str("");
0385   histoTitle = "Bad strips in " + subDetName;
0386   if (!partName.empty()) {
0387     histoTitle += " " + partName;
0388   }
0389   if (partNumber != 0) {
0390     oss << partNumber;
0391     histoTitle += " " + oss.str();
0392   }
0393   TH1F* hBadStripsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize + 0.5);
0394 
0395   oss.str("");
0396   histoName = "hBadStripsFromAPVs" + subDetName + partName;
0397   if (partNumber != 0) {
0398     oss << partNumber;
0399     histoName += oss.str();
0400   }
0401   oss.str("");
0402   histoTitle = "Bad strips from APVs in " + subDetName;
0403   if (!partName.empty()) {
0404     histoTitle += " " + partName;
0405   }
0406   if (partNumber != 0) {
0407     oss << partNumber;
0408     histoTitle += " " + oss.str();
0409   }
0410   TH1F* hBadStripsFromAPVsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize + 0.5);
0411 
0412   oss.str("");
0413   histoName = "hAllBadStrips" + subDetName + partName;
0414   if (partNumber != 0) {
0415     oss << partNumber;
0416     histoName += oss.str();
0417   }
0418   oss.str("");
0419   histoTitle = "All bad strips in " + subDetName;
0420   if (!partName.empty()) {
0421     histoTitle += " " + partName;
0422   }
0423   if (partNumber != 0) {
0424     oss << partNumber;
0425     histoTitle += " " + oss.str();
0426   }
0427   TH1F* hAllBadStripsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize + 0.5);
0428 
0429   unsigned int j = 0;
0430   for (std::map<unsigned int, unsigned int>::iterator iMap = badModulesTK.begin(); iMap != badModulesTK.end(); iMap++) {
0431     hBadModulesTK->SetBinContent(++j, /*(double)*/ iMap->second /*/(double)nModulesInPart*/);
0432     oss.str("");
0433     oss << iMap->first;
0434     hBadModulesTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0435     //    std::cout << hBadModulesTK->GetBinContent(j) << std::endl;
0436   }
0437   TCanvas* cBadModulesTK = new TCanvas();
0438   hBadModulesTK->Draw();
0439   cBadModulesTK->Update();
0440 
0441   j = 0;
0442   for (std::map<unsigned int, unsigned int>::iterator iMap = badFibersTK.begin(); iMap != badFibersTK.end(); iMap++) {
0443     hBadFibersTK->SetBinContent(++j, /*(double)*/ iMap->second /*/(double)nFibersInPart*/);
0444     oss.str("");
0445     oss << iMap->first;
0446     hBadFibersTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0447     //    std::cout << hBadFibersTK->GetBinContent(j) << std::endl;
0448   }
0449   TCanvas* cBadFibersTK = new TCanvas();
0450   hBadFibersTK->Draw();
0451   cBadFibersTK->Update();
0452 
0453   j = 0;
0454   for (std::map<unsigned int, unsigned int>::iterator iMap = badAPVsTK.begin(); iMap != badAPVsTK.end(); iMap++) {
0455     hBadAPVsTK->SetBinContent(++j, /*(double)*/ iMap->second /*/(double)nAPVsInPart*/);
0456     oss.str("");
0457     oss << iMap->first;
0458     hBadAPVsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0459     //    std::cout << hBadAPVsTK->GetBinContent(j) << std::endl;
0460   }
0461   TCanvas* cBadAPVsTK = new TCanvas();
0462   hBadAPVsTK->Draw();
0463   cBadAPVsTK->Update();
0464 
0465   j = 0;
0466   for (std::map<unsigned int, unsigned int>::iterator iMap = badStripsTK.begin(); iMap != badStripsTK.end(); iMap++) {
0467     hBadStripsTK->SetBinContent(++j, /*(double)*/ iMap->second /*/(double)nStripsInPart*/);
0468     oss.str("");
0469     oss << iMap->first;
0470     hBadStripsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0471     //    std::cout << hBadStripsTK->GetBinContent(j) << std::endl;
0472   }
0473   TCanvas* cBadStripsTK = new TCanvas();
0474   hBadStripsTK->Draw();
0475   cBadStripsTK->Update();
0476 
0477   j = 0;
0478   for (std::map<unsigned int, unsigned int>::iterator iMap = badStripsFromAPVsTK.begin();
0479        iMap != badStripsFromAPVsTK.end();
0480        iMap++) {
0481     hBadStripsFromAPVsTK->SetBinContent(++j, /*(double)*/ iMap->second /*/(double)nStripsInPart*/);
0482     oss.str("");
0483     oss << iMap->first;
0484     hBadStripsFromAPVsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0485     //    std::cout << hBadStripsTK->GetBinContent(j) << std::endl;
0486   }
0487   TCanvas* cBadStripsFromAPVsTK = new TCanvas();
0488   hBadStripsFromAPVsTK->Draw();
0489   cBadStripsFromAPVsTK->Update();
0490 
0491   j = 0;
0492   for (std::map<unsigned int, unsigned int>::iterator iMap = allBadStripsTK.begin(); iMap != allBadStripsTK.end();
0493        iMap++) {
0494     hAllBadStripsTK->SetBinContent(++j, /*(double)*/ iMap->second /*/(double)nStripsInPart*/);
0495     oss.str("");
0496     oss << iMap->first;
0497     hAllBadStripsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0498     //    std::cout << hAllBadStripsTK->GetBinContent(j) << std::endl;
0499   }
0500   TCanvas* cAllBadStripsTK = new TCanvas();
0501   hAllBadStripsTK->Draw();
0502   cAllBadStripsTK->Update();
0503 
0504   // Write histograms to output file
0505 
0506   //  std::cout << "Ready to open the file " << outFileName << std::endl;
0507 
0508   TFile* outFile = new TFile(outFileName, "UPDATE");
0509 
0510   //  std::cout << "File opened: " << outFileName << std::endl;
0511 
0512   outFile->cd();
0513   hBadModulesTK->Write();
0514   hBadFibersTK->Write();
0515   hBadAPVsTK->Write();
0516   hBadStripsTK->Write();
0517   hBadStripsFromAPVsTK->Write();
0518   hAllBadStripsTK->Write();
0519 
0520   //  std::cout << "histograms written in " << outFileName << std::endl;
0521 
0522   delete outFile;
0523   delete hBadModulesTK;
0524   delete hBadFibersTK;
0525   delete hBadAPVsTK;
0526   delete hBadStripsTK;
0527   delete hBadStripsFromAPVsTK;
0528   delete hAllBadStripsTK;
0529   delete cBadModulesTK;
0530   delete cBadFibersTK;
0531   delete cBadAPVsTK;
0532   delete cBadStripsTK;
0533   delete cBadStripsFromAPVsTK;
0534   delete cAllBadStripsTK;
0535 }