File indexing completed on 2024-04-06 12:08:51
0001 #include <fstream>
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005 #include <cassert>
0006
0007 #include "TH1F.h"
0008 #include "TH2F.h"
0009 #include "TLegend.h"
0010 #include "TFile.h"
0011 #include "TCanvas.h"
0012 #include "TROOT.h"
0013 #include "TStyle.h"
0014 #include "TString.h"
0015 #include "TDirectory.h"
0016
0017 int main(int argc, char** argv) {
0018
0019 if (argc < 3){
0020 std::cout << "Usage: " << argv[0]
0021 << " <file> <run number>"
0022 << " <optional: local file>"
0023 << std::endl;
0024 return 0;
0025 }
0026
0027
0028 unsigned int run;
0029 std::istringstream(argv[2])>>run;
0030
0031 bool lLocal=0;
0032 if (argc>3) std::istringstream(argv[3])>>lLocal;
0033
0034 std::ofstream outfile;
0035 TString outName = "FEDChannelErrors_run";
0036 outName += run;
0037 outName += ".txt";
0038 outfile.open(outName,std::ios::out);
0039
0040 if (!outfile) {
0041 std::cerr << "Cannot open file " << outName << " for writting. Please debug! " << std::endl;
0042 return 0;
0043 }
0044
0045 TString histNames[7] = {"OOSBits","UnlockedBits",
0046 "APVAddressErrorBits","APVErrorBits",
0047 "BadMajorityAddresses","FEMissing","FEOverflows"};
0048
0049 TString fileName = argv[1];
0050
0051 TFile *f = TFile::Open(fileName);
0052
0053 if (!f) {
0054 std::cout << "Cannot open file " << fileName << " for reading ! Exiting..." << std::endl;
0055 return 0;
0056 }
0057
0058 TString dirName = "DQMData/";
0059 if (!lLocal) {
0060 dirName += "Run ";
0061 dirName += run;
0062 dirName += "/";
0063 }
0064 dirName += "SiStrip/";
0065 if (!lLocal) dirName += "Run summary/";
0066 dirName += "ReadoutView/";
0067 std::cout << "Directory " << dirName << std::endl;
0068
0069 if (!f->cd(dirName)) {
0070 std::cerr << "Folder not found, please modify source code " << __FILE__ << ", variable dirName!" << std::endl;
0071 return 0;
0072 }
0073
0074
0075 TString normDir = dirName;
0076 normDir += "FedSummary/";
0077 if (!f->cd(normDir)) {
0078 std::cerr << "Folder not found, please modify source code " << __FILE__ << ", line " << __LINE__ << std::endl;
0079 return 0;
0080 };
0081
0082 TH1F *hNorm = (TH1F*)gDirectory->Get("FED/nFEDErrors");
0083 double norm = hNorm->GetEntries();
0084
0085 outfile << " - File contains " << norm << " events." << std::endl
0086 << " - CHANNEL/FE ARE REPORTED IN INTERNAL NUMBERING SCHEME (0-95/0-7, FE #0 is channel 0-11)" << std::endl;
0087
0088 for (unsigned int ifed(50); ifed<500;ifed++){
0089
0090 TString fedDir = dirName;
0091 fedDir += "FrontEndDriver";
0092 fedDir += ifed;
0093
0094 if (!f->cd(fedDir)) continue;
0095 else {
0096 outfile << " - Errors detected for FED " << ifed << std::endl;
0097 }
0098
0099 TDirectory *current = gDirectory;
0100
0101
0102 for (unsigned int iHist(0); iHist<7; iHist++){
0103 TString objName = histNames[iHist];
0104 objName += "ForFED";
0105 objName += ifed;
0106 TH1F *obj = (TH1F*)current->Get(objName);
0107
0108 if (!obj) {
0109 std::cout << "Warning, histogram " << objName << " not found..." << std::endl;
0110 continue;
0111 }
0112 else {
0113 if (obj->GetEntries() != 0) {
0114 for (int bin(1); bin<obj->GetNbinsX()+1; bin++){
0115 if (obj->GetBinContent(bin)>0){
0116 outfile << " --- FED ID " << ifed ;
0117 if (iHist < 2) outfile << ", channel " << bin-1 ;
0118 else if (iHist < 4) outfile << ", APV " << bin-1
0119 << " (channel " << static_cast<int>((bin-1)/2.) << ")";
0120 else outfile << ", FE " << bin-1 ;
0121 std::ostringstream message;
0122 message << " in " << histNames[iHist] << " error for " ;
0123 outfile << message.str() << obj->GetBinContent(bin)/norm*100. << "% of events."
0124 << std::endl;
0125 }
0126 }
0127 }
0128 }
0129 }
0130
0131 }
0132
0133
0134 return 1;
0135
0136 }