1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
#include <fstream>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <map>
#include <vector>
#include "TH1F.h"
#include "TH2F.h"
#include "TLegend.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TROOT.h"
#include "TStyle.h"
#include "TString.h"
#include "TDirectory.h"
int main(int argc, char** argv) {//main
if (argc < 4){
std::cout << "Usage: " << argv[0]
<< " <path to file> <number of runs> <run number list>"
<< std::endl;
return 0;
}
unsigned int nRuns;
std::istringstream(argv[2])>>nRuns;
std::vector<unsigned int> runs;
//std::map<unsigned int,std::vector<std::pair<unsigned int,float> > > lMap;
//std::pair<std::map<unsigned int,std::vector<std::pair<unsigned int,float> > >::iterator,bool> lMapIter;
//std::map<unsigned int,double> lMapFED;
unsigned int nDirNotFound = 0;
unsigned int nFileNotFound = 0;
std::ofstream txtoutfile;
txtoutfile.open("SpyErrors.dat",std::ios::out);
txtoutfile << "| Error type | run # | fedID | rate of error |" << std::endl;
TString baseName = argv[1];
baseName += "/";
unsigned int nErr = 0;
for (unsigned int r(0); r<nRuns; r++){//loop on runs
unsigned int lRun;
std::istringstream(argv[3+r])>>lRun;
std::cout << "Processing run " << lRun << std::endl;
runs.push_back(lRun);
TString fileName = baseName;
fileName += lRun;
fileName += "/DQMStore.root";
TFile *f = TFile::Open(fileName);
if (!f) {
std::cout << " -- File " << fileName << " not found." << std::endl;
return 0;
}
TString dirName = "DQMData/SiStrip/ReadoutView/";
std::cout << " -- Directory " << dirName << std::endl;
if (!f->cd(dirName)) {
std::cerr << " -- Folder not found. Check if file valid or source code valid. Going to next run." << std::endl;
nDirNotFound++;
//return 0;
continue;
}
//looking for object with name chNames etc...
TString normDir = dirName;
normDir += "SpyMonitoringSummary";
if (!f->cd(normDir)) {
std::cerr << "Folder not found, please check file " << __FILE__ << ", line " << __LINE__ << std::endl;
nDirNotFound++;
return 0;
};
TH1F *hNorm = (TH1F*)gDirectory->Get("nNoData");
double norm = hNorm->GetEntries();
//lMapFED.insert(std::pair<unsigned int,double>(lRun,hNorm->GetMean()));
//find out which FEDs are in error, and which error
const unsigned int nErrs = 11;
TString lFedName[nErrs] = {"MinZero","MaxSat",
"LowTrimDAC","HighTrimDAC",
"LowRange","HighRange",
"OutOfSync","OtherPbs",
"ApvErrorBit","ApvAddressError",
"NegativePeds"};
for (unsigned int iH(0); iH<nErrs; iH++){
TH1F *FEDobj = (TH1F*)gDirectory->Get(lFedName[iH]);
if (!FEDobj) {
std::cout << "Error, histogram " << lFedName[iH] << " not found. Continue..." << std::endl;
continue;//return 0;
}
else {
if (FEDobj->GetEntries() != 0) {
for (int bin(1); bin<FEDobj->GetNbinsX()+1; bin++){
if (FEDobj->GetBinContent(bin)>0){
unsigned int iFed = bin+49;
float lStat = FEDobj->GetBinContent(bin)*1./norm;
txtoutfile << lFedName[iH] << " " << lRun << " " << iFed << " " << lStat << std::endl;
}
}
}
}
}
for (unsigned int ifed(50); ifed<500;ifed++){//loop on FEDs
TString fedDir = dirName;
fedDir += "FrontEndDriver";
fedDir += ifed;
if (!f->cd(fedDir)) continue;
else {
std::cout << " - Errors detected for FED " << ifed << std::endl;
txtoutfile << " ***************************************** " << std::endl
<< " **** Channel/APV errors for FED " << ifed << " **** " << std::endl
<< " ***************************************** " << std::endl;
}
TDirectory *current = gDirectory;
//channel histos
for (unsigned int iH(0); iH<nErrs; iH++){
TString objName = lFedName[iH];
objName += "ForFED";
objName += ifed;
TH1F *obj = (TH1F*)current->Get(objName);
if (!obj) {
std::cout << "Error, histogram " << objName << " not found. Exiting..." << std::endl;
continue;//return 0;
}
else {
if (obj->GetEntries() != 0) {
for (int bin(1); bin<obj->GetNbinsX()+1; bin++){
unsigned int iCh = bin-1;
//if (obj->GetNbinsX() < 100) iCh = 96*ifed+bin-1;
//else iCh = 192*ifed+bin-1;
if (obj->GetBinContent(bin)>0){
float lStat = obj->GetBinContent(bin)/norm*1.;
//std::vector<std::pair<unsigned int, float> > lVec;
//lVec.push_back(std::pair<unsigned int, float>(lRun,lStat));
//lMapIter = lMap.insert(std::pair<unsigned int,std::vector<std::pair<unsigned int,float> > >(iCh,lVec));
//if (!lMapIter.second) ((lMapIter.first)->second).push_back(std::pair<unsigned int, float>(lRun,lStat));
txtoutfile << objName << " " << lRun << " " << ifed << " " << iCh << " " << lStat << std::endl;
nErr++;
}
}
}
}
}//loop on errors
}//loop on feds
}//loop on runs
//unsigned int nErr = lMap.size();
assert (runs.size() == nRuns);
std::cout << "Found " << nErr << " Channels/APVs with errors in " << nRuns << " runs processed." << std::endl;
std::cout << "Number of runs where file was not found : " << nFileNotFound << std::endl;
std::cout << "Number of runs where folder was not found : " << nDirNotFound << std::endl;
// TFile *outfile = TFile::Open("APVAddressErrors.root","RECREATE");
// outfile->cd();
// TH1F *h[nErr];
// std::map<unsigned int,std::vector<std::pair<unsigned int,float> > >::iterator lIter = lMap.begin();
// unsigned int e = 0;
// for (;lIter!=lMap.end(); lIter++){
// unsigned int lCh = lIter->first;
// std::ostringstream lName;
// lName << "ErrorFed" << static_cast<unsigned int>(lCh/192.) << "Ch" << static_cast<unsigned int>(lCh%192/2.) << "APV" << lCh%2;
// h[e] = new TH1F(lName.str().c_str(),"rate of APVAddressError vs run",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
// std::vector<std::pair<unsigned int,float> > lVec = lIter->second;
// unsigned int nBins = lVec.size();
// for (unsigned int b(0); b<nBins; b++){
// //std::cout <<"Run " << lVec.at(b).first << ", runs[0] = " << runs[0] << ", runs[" << nRuns-1 << "] = " << runs[nRuns-1] << std::endl;
// h[e]->SetBinContent(lVec.at(b).first-runs[0]+1,lVec.at(b).second);
// //std::cout << "Setting bin " << lVec.at(b).first-runs[0]+1 << " content to " << lVec.at(b).second << std::endl;
// }
// //h[e]->Write();
// e++;
// }
// TH1F *hRate = new TH1F("hRate",";run #",runs[nRuns-1]-runs[0]+1,runs[0],runs[nRuns-1]+1);
// std::map<unsigned int,double>::iterator lIterFED = lMapFED.begin();
// for (;lIterFED!=lMapFED.end(); lIterFED++){
// hRate->SetBinContent(lIterFED->first-runs[0]+1,lIterFED->second);
// }
// outfile->Write();
// outfile->Close();
txtoutfile.close();
return 1;
}//main
|