CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/SiStripMonitorSummary/bin/makeTKTrend.cc

Go to the documentation of this file.
00001 #include <fstream>
00002 #include <iostream>
00003 #include <vector>
00004 #include <map>
00005 #include <string>
00006 #include <sstream>
00007 
00008 #include "TFile.h"
00009 #include "TVectorT.h"
00010 #include "TGraph.h"
00011 #include "TGaxis.h"
00012 #include "TCanvas.h"
00013 #include "TH1F.h"
00014 #include "TFile.h"
00015 
00016 void makeTKTrend(const char* inFileName, const char* outFileName, std::string subDetName, std::string partName, const unsigned int partNumber);
00017 
00018 int main(int argc , char *argv[]) {
00019 
00020   if(argc==6) {
00021     char* inFileName = argv[1];
00022     char* outFileName = argv[2];
00023     char* subDetName = argv[3];
00024     char* partName = argv[4];
00025     int partNumber = atoi(argv[5]);
00026 
00027     std::cout << "ready to make trend plots from " 
00028               << inFileName << " to " << outFileName << " for " 
00029               << subDetName << " " << partName << " " << partNumber << std::endl;
00030 
00031     
00032     int returncode = 0;
00033     makeTKTrend(inFileName,outFileName,subDetName,partName,partNumber);
00034 
00035     return  returncode;
00036 
00037   }
00038   else {std::cout << "Too few arguments: " << argc << std::endl; return -1; }
00039 
00040   return -9;
00041 
00042 }
00043 
00044 void makeTKTrend(const char* inFileName, const char* outFileName, std::string subDetName, std::string partName, const unsigned int partNumber)
00045 {
00046   // Maps <Run number, nBad>
00047   std::map<unsigned int, unsigned int> badModulesTK;
00048   std::map<unsigned int, unsigned int> badFibersTK;
00049   std::map<unsigned int, unsigned int> badAPVsTK;
00050   std::map<unsigned int, unsigned int> badStripsTK;
00051   std::map<unsigned int, unsigned int> badStripsFromAPVsTK;
00052   std::map<unsigned int, unsigned int> allBadStripsTK;
00053   
00054   std::ostringstream oss;
00055   
00056   if(partName=="All") partName="";
00057 
00058 //   // Number of modules, fibers, APVs, strips for each tracker part
00059 //   std::vector< std::string > tkParts;
00060 //   tkParts.push_back("Tracker");
00061 //   tkParts.push_back("TIB");
00062 //   tkParts.push_back("TID");
00063 //   tkParts.push_back("TOB");
00064 //   tkParts.push_back("TEC");
00065 //   tkParts.push_back("TIB Layer 1");
00066 //   tkParts.push_back("TIB Layer 2");
00067 //   tkParts.push_back("TIB Layer 3");
00068 //   tkParts.push_back("TIB Layer 4");
00069 //   tkParts.push_back("TID+ Disk 1");
00070 //   tkParts.push_back("TID+ Disk 2");
00071 //   tkParts.push_back("TID+ Disk 3");
00072 //   tkParts.push_back("TID- Disk 1");
00073 //   tkParts.push_back("TID- Disk 2");
00074 //   tkParts.push_back("TID- Disk 3");
00075 //   tkParts.push_back("TOB Layer 1");
00076 //   tkParts.push_back("TOB Layer 2");
00077 //   tkParts.push_back("TOB Layer 3");
00078 //   tkParts.push_back("TOB Layer 4");
00079 //   tkParts.push_back("TOB Layer 5");
00080 //   tkParts.push_back("TOB Layer 6");
00081 //   tkParts.push_back("TEC+ Disk 1");
00082 //   tkParts.push_back("TEC+ Disk 2");
00083 //   tkParts.push_back("TEC+ Disk 3");
00084 //   tkParts.push_back("TEC+ Disk 4");
00085 //   tkParts.push_back("TEC+ Disk 5");
00086 //   tkParts.push_back("TEC+ Disk 6");
00087 //   tkParts.push_back("TEC+ Disk 7");
00088 //   tkParts.push_back("TEC+ Disk 8");
00089 //   tkParts.push_back("TEC+ Disk 9");
00090 //   tkParts.push_back("TEC- Disk 1");
00091 //   tkParts.push_back("TEC- Disk 2");
00092 //   tkParts.push_back("TEC- Disk 3");
00093 //   tkParts.push_back("TEC- Disk 4");
00094 //   tkParts.push_back("TEC- Disk 5");
00095 //   tkParts.push_back("TEC- Disk 6");
00096 //   tkParts.push_back("TEC- Disk 7");
00097 //   tkParts.push_back("TEC- Disk 8");
00098 //   tkParts.push_back("TEC- Disk 9");
00099 //   
00100 //   std::vector<unsigned int> nModules;
00101 //   nModules.push_back(15148);
00102 //   nModules.push_back(2724);
00103 //   nModules.push_back(816);
00104 //   nModules.push_back(5208);
00105 //   nModules.push_back(6400);
00106 //   nModules.push_back(672);
00107 //   nModules.push_back(864);
00108 //   nModules.push_back(540);
00109 //   nModules.push_back(648);
00110 //   nModules.push_back(136);
00111 //   nModules.push_back(136);
00112 //   nModules.push_back(136);
00113 //   nModules.push_back(136);
00114 //   nModules.push_back(136);
00115 //   nModules.push_back(136);
00116 //   nModules.push_back(1008);
00117 //   nModules.push_back(1152);
00118 //   nModules.push_back(648);
00119 //   nModules.push_back(720);
00120 //   nModules.push_back(792);
00121 //   nModules.push_back(888);
00122 //   nModules.push_back(408);
00123 //   nModules.push_back(408);
00124 //   nModules.push_back(408);
00125 //   nModules.push_back(360);
00126 //   nModules.push_back(360);
00127 //   nModules.push_back(360);
00128 //   nModules.push_back(312);
00129 //   nModules.push_back(312);
00130 //   nModules.push_back(272);
00131 //   nModules.push_back(408);
00132 //   nModules.push_back(408);
00133 //   nModules.push_back(408);
00134 //   nModules.push_back(360);
00135 //   nModules.push_back(360);
00136 //   nModules.push_back(360);
00137 //   nModules.push_back(312);
00138 //   nModules.push_back(312);
00139 //   nModules.push_back(272);
00140 //   
00141 //   std::vector<unsigned int> nFibers;
00142 //   nFibers.push_back(36392);
00143 //   nFibers.push_back(6984);
00144 //   nFibers.push_back(2208);
00145 //   nFibers.push_back(12096);
00146 //   nFibers.push_back(15104);
00147 //   nFibers.push_back(2016);
00148 //   nFibers.push_back(2592);
00149 //   nFibers.push_back(1080);
00150 //   nFibers.push_back(1296);
00151 //   nFibers.push_back(368);
00152 //   nFibers.push_back(368);
00153 //   nFibers.push_back(368);
00154 //   nFibers.push_back(368);
00155 //   nFibers.push_back(368);
00156 //   nFibers.push_back(368);
00157 //   nFibers.push_back(2016);
00158 //   nFibers.push_back(2304);
00159 //   nFibers.push_back(1296);
00160 //   nFibers.push_back(1440);
00161 //   nFibers.push_back(2376);
00162 //   nFibers.push_back(2664);
00163 //   nFibers.push_back(992);
00164 //   nFibers.push_back(992);
00165 //   nFibers.push_back(992);
00166 //   nFibers.push_back(848);
00167 //   nFibers.push_back(848);
00168 //   nFibers.push_back(848);
00169 //   nFibers.push_back(704);
00170 //   nFibers.push_back(704);
00171 //   nFibers.push_back(624);
00172 //   nFibers.push_back(992);
00173 //   nFibers.push_back(992);
00174 //   nFibers.push_back(992);
00175 //   nFibers.push_back(848);
00176 //   nFibers.push_back(848);
00177 //   nFibers.push_back(848);
00178 //   nFibers.push_back(704);
00179 //   nFibers.push_back(704);
00180 //   nFibers.push_back(624);
00181 //   
00182 //   std::vector<unsigned int> nAPVs;
00183 //   nAPVs.push_back(72784);
00184 //   nAPVs.push_back(13968);
00185 //   nAPVs.push_back(4416);
00186 //   nAPVs.push_back(24192);
00187 //   nAPVs.push_back(30208);
00188 //   nAPVs.push_back(4032);
00189 //   nAPVs.push_back(5184);
00190 //   nAPVs.push_back(2160);
00191 //   nAPVs.push_back(2592);
00192 //   nAPVs.push_back(736);
00193 //   nAPVs.push_back(736);
00194 //   nAPVs.push_back(736);
00195 //   nAPVs.push_back(736);
00196 //   nAPVs.push_back(736);
00197 //   nAPVs.push_back(736);
00198 //   nAPVs.push_back(4032);
00199 //   nAPVs.push_back(4608);
00200 //   nAPVs.push_back(2592);
00201 //   nAPVs.push_back(2880);
00202 //   nAPVs.push_back(4752);
00203 //   nAPVs.push_back(5328);
00204 //   nAPVs.push_back(1984);
00205 //   nAPVs.push_back(1984);
00206 //   nAPVs.push_back(1984);
00207 //   nAPVs.push_back(1696);
00208 //   nAPVs.push_back(1696);
00209 //   nAPVs.push_back(1696);
00210 //   nAPVs.push_back(1408);
00211 //   nAPVs.push_back(1408);
00212 //   nAPVs.push_back(1248);
00213 //   nAPVs.push_back(1984);
00214 //   nAPVs.push_back(1984);
00215 //   nAPVs.push_back(1984);
00216 //   nAPVs.push_back(1696);
00217 //   nAPVs.push_back(1696);
00218 //   nAPVs.push_back(1696);
00219 //   nAPVs.push_back(1408);
00220 //   nAPVs.push_back(1408);
00221 //   nAPVs.push_back(1248);
00222 //   
00223 //   std::vector<unsigned int> nStrips;
00224 //   nStrips.push_back(9316352);
00225 //   nStrips.push_back(1787904);
00226 //   nStrips.push_back(565248);
00227 //   nStrips.push_back(3096576);
00228 //   nStrips.push_back(3866624);
00229 //   nStrips.push_back(516096);
00230 //   nStrips.push_back(663552);
00231 //   nStrips.push_back(276480);
00232 //   nStrips.push_back(331776);
00233 //   nStrips.push_back(94208);
00234 //   nStrips.push_back(94208);
00235 //   nStrips.push_back(94208);
00236 //   nStrips.push_back(94208);
00237 //   nStrips.push_back(94208);
00238 //   nStrips.push_back(94208);
00239 //   nStrips.push_back(516096);
00240 //   nStrips.push_back(589824);
00241 //   nStrips.push_back(331776);
00242 //   nStrips.push_back(368640);
00243 //   nStrips.push_back(608256);
00244 //   nStrips.push_back(681984);
00245 //   nStrips.push_back(253952);
00246 //   nStrips.push_back(253952);
00247 //   nStrips.push_back(253952);
00248 //   nStrips.push_back(217088);
00249 //   nStrips.push_back(217088);
00250 //   nStrips.push_back(217088);
00251 //   nStrips.push_back(180224);
00252 //   nStrips.push_back(180224);
00253 //   nStrips.push_back(159744);
00254 //   nStrips.push_back(253952);
00255 //   nStrips.push_back(253952);
00256 //   nStrips.push_back(253952);
00257 //   nStrips.push_back(217088);
00258 //   nStrips.push_back(217088);
00259 //   nStrips.push_back(217088);
00260 //   nStrips.push_back(180224);
00261 //   nStrips.push_back(180224);
00262 //   nStrips.push_back(159744);
00263 //   
00264 //   // Map with <name of tracker part, count of channels in the part>
00265 //   std::map<std::string, unsigned int> allModulesTK;
00266 //   std::map<std::string, unsigned int> allFibersTK;
00267 //   std::map<std::string, unsigned int> allAPVsTK;
00268 //   std::map<std::string, unsigned int> allStripsTK;
00269 //   for(unsigned int i = 0; i < tkParts.size(); i++)
00270 //   {
00271 //     allModulesTK[tkParts[i].c_str()] = nModules[i];
00272 //     allFibersTK[tkParts[i].c_str()] = nFibers[i];
00273 //     allAPVsTK[tkParts[i].c_str()] = nAPVs[i];
00274 //     allStripsTK[tkParts[i].c_str()] = nStrips[i];
00275 //   }
00276 //   
00277 // //   for(std::map< std::string, unsigned int>::iterator it = allStripsTK.begin(); it != allStripsTK.end(); it++)
00278 // //   {
00279 // //     std::cout << it->first.c_str() << " " << it->second << std::endl;
00280 // //   }
00281 //   
00282 //   // Finds number of channels from above map
00283 //   std::string completePartName = subDetName;
00284 //   if(partName.compare("") != 0)
00285 //     completePartName += " " + partName;
00286 //   if(partNumber != 0)
00287 //   {
00288 //     oss.str("");
00289 //     oss << partNumber;
00290 //     completePartName += " " + oss.str();
00291 //   }
00292   
00293 //   // Total number of channels in currently processed map
00294 //   const unsigned int nModulesInPart = allModulesTK[completePartName.c_str()];
00295 //   const unsigned int nFibersInPart = allFibersTK[completePartName.c_str()];
00296 //   const unsigned int nAPVsInPart = allAPVsTK[completePartName.c_str()];
00297 //   const unsigned int nStripsInPart = allStripsTK[completePartName.c_str()];
00298   
00299   // Read input file
00300   std::ifstream resultsFile(inFileName);
00301   unsigned int runIOV;
00302   unsigned int values[6];
00303   do
00304   {
00305     resultsFile >> runIOV;
00306     resultsFile >> values[0] >> values[1] >> values[2] >> values[3] >> values[4] >> values[5];
00307     //    std::cout << runIOV << " " << values[0] << " " << values[1] << " " << values[2] << " " << values[3] << " " << values[4] << " " << values[5] << std::endl;
00308     badModulesTK[runIOV]=values[0];
00309     badFibersTK[runIOV]=values[1];
00310     badAPVsTK[runIOV]=values[2];
00311     badStripsTK[runIOV]=values[3];
00312     badStripsFromAPVsTK[runIOV]=values[4];
00313     allBadStripsTK[runIOV]=values[5];
00314   }
00315   while(!resultsFile.eof());
00316   
00317   const unsigned int IOVSize = badStripsTK.size();
00318   
00319   // Create histograms
00320   std::string histoName;
00321   std::string histoTitle;
00322   
00323   oss.str("");
00324   histoName = "hBadModules" + subDetName + partName;
00325   if(partNumber!=0)
00326   {
00327     oss << partNumber;
00328     histoName += oss.str();
00329   }
00330   oss.str("");
00331   histoTitle = "Bad modules in " + subDetName;
00332   if(partName!="")
00333   {
00334     histoTitle += " " + partName;
00335   }
00336   if(partNumber!=0)
00337   {
00338     oss << partNumber;
00339     histoTitle += " " + oss.str();
00340   }
00341   TH1F* hBadModulesTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
00342 
00343   oss.str("");
00344   histoName = "hBadFibers" + subDetName + partName;
00345   if(partNumber!=0)
00346   {
00347     oss << partNumber;
00348     histoName += oss.str();
00349   }
00350   oss.str("");
00351   histoTitle = "Bad fibers in " + subDetName;
00352   if(partName!="")
00353   {
00354     histoTitle += " " + partName;
00355   }
00356   if(partNumber!=0)
00357   {
00358     oss << partNumber;
00359     histoTitle += " " + oss.str();
00360   }
00361   TH1F* hBadFibersTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
00362   
00363   oss.str("");
00364   histoName = "hBadAPVs" + subDetName + partName;
00365   if(partNumber!=0)
00366   {
00367     oss << partNumber;
00368     histoName += oss.str();
00369   }
00370   oss.str("");
00371   histoTitle = "Bad APVs in " + subDetName;
00372   if(partName!="")
00373   {
00374     histoTitle += " " + partName;
00375   }
00376   if(partNumber!=0)
00377   {
00378     oss << partNumber;
00379     histoTitle += " " + oss.str();
00380   }
00381   TH1F* hBadAPVsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
00382   
00383   oss.str("");
00384   histoName = "hBadStrips" + subDetName + partName;
00385   if(partNumber!=0)
00386   {
00387     oss << partNumber;
00388     histoName += oss.str();
00389   }
00390   oss.str("");
00391   histoTitle = "Bad strips in " + subDetName;
00392   if(partName!="")
00393   {
00394     histoTitle += " " + partName;
00395   }
00396   if(partNumber!=0)
00397   {
00398     oss << partNumber;
00399     histoTitle += " " + oss.str();
00400   }
00401   TH1F* hBadStripsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
00402   
00403   oss.str("");
00404   histoName = "hBadStripsFromAPVs" + subDetName + partName;
00405   if(partNumber!=0)
00406   {
00407     oss << partNumber;
00408     histoName += oss.str();
00409   }
00410   oss.str("");
00411   histoTitle = "Bad strips from APVs in " + subDetName;
00412   if(partName!="")
00413   {
00414     histoTitle += " " + partName;
00415   }
00416   if(partNumber!=0)
00417   {
00418     oss << partNumber;
00419     histoTitle += " " + oss.str();
00420   }
00421   TH1F* hBadStripsFromAPVsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
00422   
00423   oss.str("");
00424   histoName = "hAllBadStrips" + subDetName + partName;
00425   if(partNumber!=0)
00426   {
00427     oss << partNumber;
00428     histoName += oss.str();
00429   }
00430   oss.str("");
00431   histoTitle = "All bad strips in " + subDetName;
00432   if(partName!="")
00433   {
00434     histoTitle += " " + partName;
00435   }
00436   if(partNumber!=0)
00437   {
00438     oss << partNumber;
00439     histoTitle += " " + oss.str();
00440   }
00441   TH1F* hAllBadStripsTK = new TH1F(histoName.c_str(), histoTitle.c_str(), IOVSize, 0.5, IOVSize+0.5);
00442   
00443   unsigned int j = 0;
00444   for(std::map<unsigned int, unsigned int>::iterator iMap=badModulesTK.begin(); iMap!=badModulesTK.end(); iMap++ )
00445   {
00446     hBadModulesTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nModulesInPart*/);
00447     oss.str("");
00448     oss << iMap->first;
00449     hBadModulesTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00450     //    std::cout << hBadModulesTK->GetBinContent(j) << std::endl;
00451   }
00452   TCanvas* cBadModulesTK = new TCanvas();
00453   hBadModulesTK->Draw();
00454   cBadModulesTK->Update();
00455   
00456   j = 0;
00457   for(std::map<unsigned int, unsigned int>::iterator iMap=badFibersTK.begin(); iMap!=badFibersTK.end(); iMap++ )
00458   {
00459     hBadFibersTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nFibersInPart*/);
00460     oss.str("");
00461     oss << iMap->first;
00462     hBadFibersTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00463     //    std::cout << hBadFibersTK->GetBinContent(j) << std::endl;
00464   }
00465   TCanvas* cBadFibersTK = new TCanvas();
00466   hBadFibersTK->Draw();
00467   cBadFibersTK->Update();
00468   
00469   j = 0;
00470   for(std::map<unsigned int, unsigned int>::iterator iMap=badAPVsTK.begin(); iMap!=badAPVsTK.end(); iMap++ )
00471   {
00472     hBadAPVsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nAPVsInPart*/);
00473     oss.str("");
00474     oss << iMap->first;
00475     hBadAPVsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00476     //    std::cout << hBadAPVsTK->GetBinContent(j) << std::endl;
00477   }
00478   TCanvas* cBadAPVsTK = new TCanvas();
00479   hBadAPVsTK->Draw();
00480   cBadAPVsTK->Update();
00481 
00482   j = 0;
00483   for(std::map<unsigned int, unsigned int>::iterator iMap=badStripsTK.begin(); iMap!=badStripsTK.end(); iMap++ )
00484   {
00485     hBadStripsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nStripsInPart*/);
00486     oss.str("");
00487     oss << iMap->first;
00488     hBadStripsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00489     //    std::cout << hBadStripsTK->GetBinContent(j) << std::endl;
00490   }
00491   TCanvas* cBadStripsTK = new TCanvas();
00492   hBadStripsTK->Draw();
00493   cBadStripsTK->Update();
00494   
00495   j = 0;
00496   for(std::map<unsigned int, unsigned int>::iterator iMap=badStripsFromAPVsTK.begin(); iMap!=badStripsFromAPVsTK.end(); iMap++ )
00497   {
00498     hBadStripsFromAPVsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nStripsInPart*/);
00499     oss.str("");
00500     oss << iMap->first;
00501     hBadStripsFromAPVsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00502     //    std::cout << hBadStripsTK->GetBinContent(j) << std::endl;
00503   }
00504   TCanvas* cBadStripsFromAPVsTK = new TCanvas();
00505   hBadStripsFromAPVsTK->Draw();
00506   cBadStripsFromAPVsTK->Update();
00507 
00508   j = 0;
00509   for(std::map<unsigned int, unsigned int>::iterator iMap=allBadStripsTK.begin(); iMap!=allBadStripsTK.end(); iMap++ )
00510   {
00511     hAllBadStripsTK->SetBinContent(++j,/*(double)*/iMap->second/*/(double)nStripsInPart*/);
00512     oss.str("");
00513     oss << iMap->first;
00514     hAllBadStripsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00515     //    std::cout << hAllBadStripsTK->GetBinContent(j) << std::endl;
00516   }
00517   TCanvas* cAllBadStripsTK = new TCanvas();
00518   hAllBadStripsTK->Draw();
00519   cAllBadStripsTK->Update();
00520   
00521   // Write histograms to output file
00522   
00523   //  std::cout << "Ready to open the file " << outFileName << std::endl;
00524 
00525   TFile* outFile = new TFile(outFileName, "UPDATE");
00526 
00527   //  std::cout << "File opened: " << outFileName << std::endl;
00528 
00529   outFile->cd();
00530   hBadModulesTK->Write();
00531   hBadFibersTK->Write();
00532   hBadAPVsTK->Write();
00533   hBadStripsTK->Write();
00534   hBadStripsFromAPVsTK->Write();
00535   hAllBadStripsTK->Write();
00536 
00537   //  std::cout << "histograms written in " << outFileName << std::endl;
00538 
00539   delete outFile;
00540   delete hBadModulesTK;
00541   delete hBadFibersTK;
00542   delete hBadAPVsTK;
00543   delete hBadStripsTK;
00544   delete hBadStripsFromAPVsTK;
00545   delete hAllBadStripsTK;
00546   delete cBadModulesTK;
00547   delete cBadFibersTK;
00548   delete cBadAPVsTK;
00549   delete cBadStripsTK;
00550   delete cBadStripsFromAPVsTK;
00551   delete cAllBadStripsTK;
00552 
00553 }