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
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
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
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
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
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,iMap->second);
00447 oss.str("");
00448 oss << iMap->first;
00449 hBadModulesTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00450
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,iMap->second);
00460 oss.str("");
00461 oss << iMap->first;
00462 hBadFibersTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00463
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,iMap->second);
00473 oss.str("");
00474 oss << iMap->first;
00475 hBadAPVsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00476
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,iMap->second);
00486 oss.str("");
00487 oss << iMap->first;
00488 hBadStripsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00489
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,iMap->second);
00499 oss.str("");
00500 oss << iMap->first;
00501 hBadStripsFromAPVsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00502
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,iMap->second);
00512 oss.str("");
00513 oss << iMap->first;
00514 hAllBadStripsTK->GetXaxis()->SetBinLabel(j,oss.str().c_str());
00515
00516 }
00517 TCanvas* cAllBadStripsTK = new TCanvas();
00518 hAllBadStripsTK->Draw();
00519 cAllBadStripsTK->Update();
00520
00521
00522
00523
00524
00525 TFile* outFile = new TFile(outFileName, "UPDATE");
00526
00527
00528
00529 outFile->cd();
00530 hBadModulesTK->Write();
00531 hBadFibersTK->Write();
00532 hBadAPVsTK->Write();
00533 hBadStripsTK->Write();
00534 hBadStripsFromAPVsTK->Write();
00535 hAllBadStripsTK->Write();
00536
00537
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 }