File indexing completed on 2024-04-06 12:08:53
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
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
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
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
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
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, iMap->second );
0432 oss.str("");
0433 oss << iMap->first;
0434 hBadModulesTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0435
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, iMap->second );
0444 oss.str("");
0445 oss << iMap->first;
0446 hBadFibersTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0447
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, iMap->second );
0456 oss.str("");
0457 oss << iMap->first;
0458 hBadAPVsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0459
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, iMap->second );
0468 oss.str("");
0469 oss << iMap->first;
0470 hBadStripsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0471
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, iMap->second );
0482 oss.str("");
0483 oss << iMap->first;
0484 hBadStripsFromAPVsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0485
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, iMap->second );
0495 oss.str("");
0496 oss << iMap->first;
0497 hAllBadStripsTK->GetXaxis()->SetBinLabel(j, oss.str().c_str());
0498
0499 }
0500 TCanvas* cAllBadStripsTK = new TCanvas();
0501 hAllBadStripsTK->Draw();
0502 cAllBadStripsTK->Update();
0503
0504
0505
0506
0507
0508 TFile* outFile = new TFile(outFileName, "UPDATE");
0509
0510
0511
0512 outFile->cd();
0513 hBadModulesTK->Write();
0514 hBadFibersTK->Write();
0515 hBadAPVsTK->Write();
0516 hBadStripsTK->Write();
0517 hBadStripsFromAPVsTK->Write();
0518 hAllBadStripsTK->Write();
0519
0520
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 }