File indexing completed on 2024-04-06 12:08:52
0001 #include <fstream>
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005 #include <cassert>
0006 #include <map>
0007 #include <vector>
0008
0009 #include "TH1F.h"
0010 #include "TH2F.h"
0011 #include "TLegend.h"
0012 #include "TFile.h"
0013 #include "TCanvas.h"
0014 #include "TROOT.h"
0015 #include "TStyle.h"
0016 #include "TString.h"
0017 #include "TDirectory.h"
0018
0019 int main(int argc, char** argv) {
0020
0021 if (argc < 4){
0022 std::cout << "Usage: " << argv[0]
0023 << " <path to file> <number of runs> <run number list>"
0024 << std::endl;
0025 return 0;
0026 }
0027
0028
0029 unsigned int nRuns;
0030 std::istringstream(argv[2])>>nRuns;
0031
0032 std::vector<unsigned int> runs;
0033
0034
0035
0036
0037
0038
0039 unsigned int nDirNotFound = 0;
0040 unsigned int nFileNotFound = 0;
0041
0042 std::ofstream txtoutfile;
0043 txtoutfile.open("SpyErrors.dat",std::ios::out);
0044 txtoutfile << "| Error type | run # | fedID | rate of error |" << std::endl;
0045
0046 TString baseName = argv[1];
0047 baseName += "/";
0048
0049 unsigned int nErr = 0;
0050
0051 for (unsigned int r(0); r<nRuns; r++){
0052
0053 unsigned int lRun;
0054 std::istringstream(argv[3+r])>>lRun;
0055
0056 std::cout << "Processing run " << lRun << std::endl;
0057
0058 runs.push_back(lRun);
0059
0060
0061 TString fileName = baseName;
0062 fileName += lRun;
0063 fileName += "/DQMStore.root";
0064
0065 TFile *f = TFile::Open(fileName);
0066
0067 if (!f) {
0068 std::cout << " -- File " << fileName << " not found." << std::endl;
0069 return 0;
0070 }
0071
0072 TString dirName = "DQMData/SiStrip/ReadoutView/";
0073 std::cout << " -- Directory " << dirName << std::endl;
0074
0075 if (!f->cd(dirName)) {
0076 std::cerr << " -- Folder not found. Check if file valid or source code valid. Going to next run." << std::endl;
0077 nDirNotFound++;
0078
0079 continue;
0080 }
0081
0082
0083 TString normDir = dirName;
0084 normDir += "SpyMonitoringSummary";
0085 if (!f->cd(normDir)) {
0086 std::cerr << "Folder not found, please check file " << __FILE__ << ", line " << __LINE__ << std::endl;
0087 nDirNotFound++;
0088 return 0;
0089 };
0090
0091 TH1F *hNorm = (TH1F*)gDirectory->Get("nNoData");
0092 double norm = hNorm->GetEntries();
0093
0094
0095
0096
0097 const unsigned int nErrs = 11;
0098 TString lFedName[nErrs] = {"MinZero","MaxSat",
0099 "LowTrimDAC","HighTrimDAC",
0100 "LowRange","HighRange",
0101 "OutOfSync","OtherPbs",
0102 "ApvErrorBit","ApvAddressError",
0103 "NegativePeds"};
0104
0105 for (unsigned int iH(0); iH<nErrs; iH++){
0106 TH1F *FEDobj = (TH1F*)gDirectory->Get(lFedName[iH]);
0107 if (!FEDobj) {
0108 std::cout << "Error, histogram " << lFedName[iH] << " not found. Continue..." << std::endl;
0109 continue;
0110 }
0111 else {
0112 if (FEDobj->GetEntries() != 0) {
0113 for (int bin(1); bin<FEDobj->GetNbinsX()+1; bin++){
0114 if (FEDobj->GetBinContent(bin)>0){
0115 unsigned int iFed = bin+49;
0116 float lStat = FEDobj->GetBinContent(bin)*1./norm;
0117 txtoutfile << lFedName[iH] << " " << lRun << " " << iFed << " " << lStat << std::endl;
0118 }
0119 }
0120 }
0121 }
0122 }
0123
0124
0125 for (unsigned int ifed(50); ifed<500;ifed++){
0126
0127 TString fedDir = dirName;
0128 fedDir += "FrontEndDriver";
0129 fedDir += ifed;
0130
0131 if (!f->cd(fedDir)) continue;
0132 else {
0133 std::cout << " - Errors detected for FED " << ifed << std::endl;
0134 txtoutfile << " ***************************************** " << std::endl
0135 << " **** Channel/APV errors for FED " << ifed << " **** " << std::endl
0136 << " ***************************************** " << std::endl;
0137 }
0138
0139 TDirectory *current = gDirectory;
0140
0141
0142 for (unsigned int iH(0); iH<nErrs; iH++){
0143 TString objName = lFedName[iH];
0144 objName += "ForFED";
0145 objName += ifed;
0146 TH1F *obj = (TH1F*)current->Get(objName);
0147
0148 if (!obj) {
0149 std::cout << "Error, histogram " << objName << " not found. Exiting..." << std::endl;
0150 continue;
0151 }
0152 else {
0153 if (obj->GetEntries() != 0) {
0154 for (int bin(1); bin<obj->GetNbinsX()+1; bin++){
0155 unsigned int iCh = bin-1;
0156
0157
0158 if (obj->GetBinContent(bin)>0){
0159 float lStat = obj->GetBinContent(bin)/norm*1.;
0160
0161
0162
0163
0164
0165 txtoutfile << objName << " " << lRun << " " << ifed << " " << iCh << " " << lStat << std::endl;
0166 nErr++;
0167 }
0168 }
0169 }
0170 }
0171 }
0172 }
0173
0174 }
0175
0176
0177
0178 assert (runs.size() == nRuns);
0179
0180 std::cout << "Found " << nErr << " Channels/APVs with errors in " << nRuns << " runs processed." << std::endl;
0181 std::cout << "Number of runs where file was not found : " << nFileNotFound << std::endl;
0182 std::cout << "Number of runs where folder was not found : " << nDirNotFound << std::endl;
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 txtoutfile.close();
0228
0229 return 1;
0230
0231 }