CMS 3D CMS Logo

ESIntegrityTask.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
9 
11 
18 
20 
21 using namespace cms;
22 using namespace edm;
23 using namespace std;
24 
26  prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
27  lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable");
28 
29  dccCollections_ = consumes<ESRawDataCollection>(ps.getParameter<InputTag>("ESDCCCollections"));
30  kchipCollections_ = consumes<ESLocalRawDataCollection>(ps.getParameter<InputTag>("ESKChipCollections"));
31 
32  // read in look-up table
33  for (int i = 0; i < 2; ++i)
34  for (int j = 0; j < 2; ++j)
35  for (int k = 0; k < 40; ++k)
36  for (int m = 0; m < 40; ++m) {
37  fed_[i][j][k][m] = -1;
38  kchip_[i][j][k][m] = -1;
39  fiber_[i][j][k][m] = -1;
40  }
41 
42  int nLines_, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
43  ifstream file;
44  file.open(lookup_.fullPath().c_str());
45  if (file.is_open()) {
46  file >> nLines_;
47 
48  for (int i = 0; i < nLines_; ++i) {
49  file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
50 
51  z = (iz == -1) ? 2 : iz;
52  fed_[z - 1][ip - 1][ix - 1][iy - 1] = fed;
53  kchip_[z - 1][ip - 1][ix - 1][iy - 1] = kchip;
54  fiber_[z - 1][ip - 1][ix - 1][iy - 1] = (fiber - 1) + (optorx - 1) * 12;
55  }
56  } else {
57  cout << "ESIntegrityTask : Look up table file can not be found in " << lookup_.fullPath().c_str() << endl;
58  }
59 
60  ievt_ = 0;
61 }
62 
63 void ESIntegrityTask::dqmEndRun(const Run& r, const EventSetup& c) {
64  // In case of Lumi based analysis Disable SoftReset from Integrity histogram to get full statistics
65  // TODO: no longer possible, clone histo beforehand if full statisticcs at end of run are required.
66 }
67 
69  const edm::EventSetup& c) const {
70  LogInfo("ESIntegrityTask") << "analyzed " << ievt_ << " events";
71  // In case of Lumi based analysis SoftReset the Integrity histogram
72  auto lumiCache = std::make_shared<ESIntLSCache>();
73  lumiCache->ievtLS_ = 0;
74 
75  for (int iz = 0; iz < 2; ++iz) {
76  for (int ip = 0; ip < 2; ++ip) {
77  meDIErrorsByLS_[iz][ip]->Reset();
78  for (int ix = 0; ix < 40; ++ix) {
79  for (int iy = 0; iy < 40; ++iy) {
80  (lumiCache->DIErrorsByLS_)[iz][ip][ix][iy] = 0;
81  }
82  }
83  }
84  }
85 
86  meDCCCRCErrByLS_->Reset();
87  meFiberErrCodeByLS_->Reset();
88  meFiberOffByLS_->Reset();
89  meOptoBCByLS_->Reset();
90  meSLinkCRCErrByLS_->Reset();
91 
92  return lumiCache;
93 }
94 
96  calculateDIFraction(lumi, c);
97 }
98 
100  char histo[200];
101 
102  iBooker.setCurrentFolder(prefixME_ + "/ESIntegrityTask");
103 
104  sprintf(histo, "ES FEDs used for data taking");
105  meFED_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
106  meFED_->setAxisTitle("ES FED", 1);
107  meFED_->setAxisTitle("Num of Events", 2);
108 
109  sprintf(histo, "ES Gain used for data taking");
110  meGain_ = iBooker.book1D(histo, histo, 2, -0.5, 1.5);
111  meGain_->setAxisTitle("ES Gain", 1);
112  meGain_->setAxisTitle("Num of Events", 2);
113 
114  sprintf(histo, "ES DCC Error codes");
115  meDCCErr_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 6, -0.5, 5.5);
116  meDCCErr_->setAxisTitle("ES FED", 1);
117  meDCCErr_->setAxisTitle("ES DCC Error code", 2);
118 
119  sprintf(histo, "ES SLink CRC Errors");
120  meSLinkCRCErr_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
121  meSLinkCRCErr_->setAxisTitle("ES FED", 1);
122  meSLinkCRCErr_->setAxisTitle("Num of Events", 2);
123 
124  sprintf(histo, "ES DCC CRC Errors");
125  meDCCCRCErr_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
126  meDCCCRCErr_->setAxisTitle("ES FED", 1);
127  meDCCCRCErr_->setAxisTitle("ES OptoRX", 2);
128 
129  sprintf(histo, "ES OptoRX used for data taking");
130  meOptoRX_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
131  meOptoRX_->setAxisTitle("ES FED", 1);
132  meOptoRX_->setAxisTitle("ES OptoRX", 2);
133 
134  sprintf(histo, "ES OptoRX BC mismatch");
135  meOptoBC_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
136  meOptoBC_->setAxisTitle("ES FED", 1);
137  meOptoBC_->setAxisTitle("ES OptoRX", 2);
138 
139  sprintf(histo, "ES Fiber Bad Status");
140  meFiberBadStatus_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
141  meFiberBadStatus_->setAxisTitle("ES FED", 1);
142  meFiberBadStatus_->setAxisTitle("Fiber Number", 2);
143 
144  sprintf(histo, "ES Fiber Error Code");
145  meFiberErrCode_ = iBooker.book1D(histo, histo, 17, -0.5, 16.5);
146  meFiberErrCode_->setAxisTitle("Fiber Error Code", 1);
147 
148  sprintf(histo, "ES Fiber Off");
149 
150  meFiberOff_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
151  meFiberOff_->setAxisTitle("ES FED", 1);
152  meFiberOff_->setAxisTitle("Fiber Number", 2);
153 
154  sprintf(histo, "ES Warning Event Dropped");
155  meEVDR_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
156  meEVDR_->setAxisTitle("ES FED", 1);
157  meEVDR_->setAxisTitle("Fiber Number", 2);
158 
159  sprintf(histo, "ES KChip Flag 1 Error codes");
160  meKF1_ = iBooker.book2D(histo, histo, 1550, -0.5, 1549.5, 16, -0.5, 15.5);
161  meKF1_->setAxisTitle("ES KChip", 1);
162  meKF1_->setAxisTitle("ES KChip F1 Error Code ", 2);
163 
164  sprintf(histo, "ES KChip Flag 2 Error codes");
165  meKF2_ = iBooker.book2D(histo, histo, 1550, -0.5, 1549.5, 16, -0.5, 15.5);
166  meKF2_->setAxisTitle("ES KChip", 1);
167  meKF2_->setAxisTitle("ES KChip F1 Error Code ", 2);
168 
169  sprintf(histo, "ES KChip BC mismatch with OptoRX");
170  meKBC_ = iBooker.book1D(histo, histo, 1550, -0.5, 1549.5);
171  meKBC_->setAxisTitle("ES KChip", 1);
172  meKBC_->setAxisTitle("Num of BC mismatch", 2);
173 
174  sprintf(histo, "ES KChip EC mismatch with OptoRX");
175  meKEC_ = iBooker.book1D(histo, histo, 1550, -0.5, 1549.5);
176  meKEC_->setAxisTitle("ES KChip", 1);
177  meKEC_->setAxisTitle("Num of EC mismatch", 2);
178 
179  for (int i = 0; i < 2; ++i)
180  for (int j = 0; j < 2; ++j) {
181  int iz = (i == 0) ? 1 : -1;
182  sprintf(histo, "ES Integrity Errors Z %d P %d", iz, j + 1);
183  meDIErrors_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
184  meDIErrors_[i][j]->setAxisTitle("Si X", 1);
185  meDIErrors_[i][j]->setAxisTitle("Si Y", 2);
186  }
187 
188  // LS-based histos
189  sprintf(histo, "ES Good Channel Fraction");
190  meDIFraction_ = iBooker.book2D(histo, histo, 3, 1.0, 3.0, 3, 1.0, 3.0);
191 
192  iBooker.setCurrentFolder(prefixME_ + "/ByLumiSection");
193 
194  sprintf(histo, "ES SLink CRC Errors");
195  meSLinkCRCErrByLS_ = iBooker.book1D(histo, histo, 56, 519.5, 575.5);
196  meSLinkCRCErrByLS_->setAxisTitle("ES FED", 1);
197  meSLinkCRCErrByLS_->setAxisTitle("Num of Events", 2);
198 
199  sprintf(histo, "ES DCC CRC Errors");
200  meDCCCRCErrByLS_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
201  meDCCCRCErrByLS_->setAxisTitle("ES FED", 1);
202  meDCCCRCErrByLS_->setAxisTitle("ES OptoRX", 2);
203 
204  sprintf(histo, "ES OptoRX BC mismatch");
205  meOptoBCByLS_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
206  meOptoBCByLS_->setAxisTitle("ES FED", 1);
207  meOptoBCByLS_->setAxisTitle("ES OptoRX", 2);
208 
209  sprintf(histo, "ES Fiber Error Code");
210  meFiberErrCodeByLS_ = iBooker.book1D(histo, histo, 17, -0.5, 16.5);
211  meFiberErrCodeByLS_->setAxisTitle("Fiber Error Code", 1);
212 
213  sprintf(histo, "ES Fiber Off");
214  meFiberOffByLS_ = iBooker.book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
215  meFiberOffByLS_->setAxisTitle("ES FED", 1);
216  meFiberOffByLS_->setAxisTitle("Fiber Number", 2);
217 
218  for (int i = 0; i < 2; ++i) {
219  for (int j = 0; j < 2; ++j) {
220  int iz = (i == 0) ? 1 : -1;
221  sprintf(histo, "ES Integrity Errors Z %d P %d", iz, j + 1);
222  meDIErrorsByLS_[i][j] = iBooker.book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
223  meDIErrorsByLS_[i][j]->setAxisTitle("Si X", 1);
224  meDIErrorsByLS_[i][j]->setAxisTitle("Si Y", 2);
225  }
226  }
227 }
228 
229 void ESIntegrityTask::endJob(void) { LogInfo("ESIntegrityTask") << "analyzed " << ievt_ << " events"; }
230 
232  ievt_++;
233  auto lumiCache = luminosityBlockCache(e.getLuminosityBlock().index());
234  ++(lumiCache->ievtLS_);
235 
238 
239  // Fill # of events
240  meDCCErr_->Fill(575, 2, 1);
241  meDCCCRCErr_->Fill(575, 2, 1);
242  meDCCCRCErrByLS_->Fill(575, 2, 1);
243  meOptoRX_->Fill(575, 2, 1);
244  meOptoBC_->Fill(575, 2, 1);
245  meOptoBCByLS_->Fill(575, 2, 1);
246  meFiberBadStatus_->Fill(575, 36, 1);
247  meFiberOff_->Fill(575, 36, 1);
248  meFiberOffByLS_->Fill(575, 36, 1);
249  meEVDR_->Fill(575, 36, 1);
250 
251  // # of DI errors
252  Double_t nDIErr[56][36];
253  for (int i = 0; i < 56; ++i)
254  for (int j = 0; j < 36; ++j)
255  nDIErr[i][j] = 0;
256 
257  // DCC
258  vector<int> fiberStatus;
259  if (e.getByToken(dccCollections_, dccs)) {
260  for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
261  const ESDCCHeaderBlock& dcc = (*dccItr);
262 
263  meFED_->Fill(dcc.fedId());
264 
265  meDCCErr_->Fill(dcc.fedId(), dcc.getDCCErrors());
266 
267  // SLink CRC error
268  if (dcc.getDCCErrors() == 101) {
269  meSLinkCRCErr_->Fill(dcc.fedId());
270  meSLinkCRCErrByLS_->Fill(dcc.fedId());
271  for (int j = 0; j < 36; ++j)
272  nDIErr[dcc.fedId() - 520][j]++;
273  }
274 
275  if (dcc.getOptoRX0() == 129) {
276  meOptoRX_->Fill(dcc.fedId(), 0);
277  if (((dcc.getOptoBC0() - 15) & 0x0fff) != dcc.getBX()) {
278  meOptoBC_->Fill(dcc.fedId(), 0);
279  meOptoBCByLS_->Fill(dcc.fedId(), 0);
280  }
281  }
282  if (dcc.getOptoRX1() == 129) {
283  meOptoRX_->Fill(dcc.fedId(), 1);
284  if (((dcc.getOptoBC1() - 15) & 0x0fff) != dcc.getBX()) {
285  meOptoBC_->Fill(dcc.fedId(), 1);
286  meOptoBCByLS_->Fill(dcc.fedId(), 1);
287  }
288  }
289  if (dcc.getOptoRX2() == 129) {
290  meOptoRX_->Fill(dcc.fedId(), 2);
291  if (((dcc.getOptoBC2() - 15) & 0x0fff) != dcc.getBX()) {
292  meOptoBC_->Fill(dcc.fedId(), 2);
293  meOptoBCByLS_->Fill(dcc.fedId(), 2);
294  }
295  }
296 
297  if (dcc.getOptoRX0() == 128) {
298  meDCCCRCErr_->Fill(dcc.fedId(), 0);
299  meDCCCRCErrByLS_->Fill(dcc.fedId(), 0);
300  for (int j = 0; j < 12; ++j)
301  nDIErr[dcc.fedId() - 520][j]++;
302  }
303  if (dcc.getOptoRX1() == 128) {
304  meDCCCRCErr_->Fill(dcc.fedId(), 1);
305  meDCCCRCErrByLS_->Fill(dcc.fedId(), 1);
306  for (int j = 12; j < 24; ++j)
307  nDIErr[dcc.fedId() - 520][j]++;
308  }
309  if (dcc.getOptoRX2() == 128) {
310  meDCCCRCErr_->Fill(dcc.fedId(), 2);
311  meDCCCRCErrByLS_->Fill(dcc.fedId(), 2);
312  for (int j = 24; j < 36; ++j)
313  nDIErr[dcc.fedId() - 520][j]++;
314  }
315 
316  fiberStatus = dcc.getFEChannelStatus();
317 
318  for (unsigned int i = 0; i < fiberStatus.size(); ++i) {
319  if (fiberStatus[i] == 4 || fiberStatus[i] == 8 || fiberStatus[i] == 10 || fiberStatus[i] == 11 ||
320  fiberStatus[i] == 12) {
321  meFiberBadStatus_->Fill(dcc.fedId(), i + 1, 1);
322  meFiberErrCode_->Fill(fiberStatus[i]);
323  meFiberErrCodeByLS_->Fill(fiberStatus[i]);
324  nDIErr[dcc.fedId() - 520][i]++;
325  }
326  if (fiberStatus[i] == 7) {
327  meFiberOff_->Fill(dcc.fedId(), i + 1, 1);
328  meFiberOffByLS_->Fill(dcc.fedId(), i + 1, 1);
329  }
330  if (fiberStatus[i] == 6) {
331  meFiberErrCode_->Fill(fiberStatus[i]);
332  meFiberErrCodeByLS_->Fill(fiberStatus[i]);
333  meEVDR_->Fill(dcc.fedId(), i + 1, 1);
334  }
335  }
336 
337  runtype_ = dcc.getRunType();
338  seqtype_ = dcc.getSeqType();
339  dac_ = dcc.getDAC();
340  gain_ = dcc.getGain();
341  precision_ = dcc.getPrecision();
342 
343  meGain_->Fill(gain_);
344  }
345  } else {
346  LogWarning("ESIntegrityTask") << "dccCollections not available";
347  }
348 
349  // KCHIP's
350  if (e.getByToken(kchipCollections_, kchips)) {
351  for (ESLocalRawDataCollection::const_iterator kItr = kchips->begin(); kItr != kchips->end(); ++kItr) {
352  ESKCHIPBlock kchip = (*kItr);
353 
354  meKF1_->Fill(kchip.id(), kchip.getFlag1());
355  meKF2_->Fill(kchip.id(), kchip.getFlag2());
356  if (kchip.getBC() != kchip.getOptoBC())
357  meKBC_->Fill(kchip.id());
358  if (kchip.getEC() != kchip.getOptoEC())
359  meKEC_->Fill(kchip.id());
360  }
361  } else {
362  LogWarning("ESIntegrityTask") << "kchipCollections not available";
363  }
364 
365  // Fill # of DI errors
366  for (int iz = 0; iz < 2; ++iz)
367  for (int ip = 0; ip < 2; ++ip)
368  for (int ix = 0; ix < 40; ++ix)
369  for (int iy = 0; iy < 40; ++iy) {
370  if (fed_[iz][ip][ix][iy] == -1)
371  continue;
372 
373  if (nDIErr[fed_[iz][ip][ix][iy] - 520][fiber_[iz][ip][ix][iy]] > 0) {
374  meDIErrors_[iz][ip]->Fill(ix + 1, iy + 1, 1);
375  (lumiCache->DIErrorsByLS_)[iz][ip][ix][iy] += 1;
376  meDIErrorsByLS_[iz][ip]->Fill(ix + 1, iy + 1, 1);
377  }
378  }
379 }
380 //
381 // -- Calculate Data Integrity Fraction
382 //
384  float nValidChannels = 0;
385  float nGlobalErrors = 0;
386  auto lumiCache = luminosityBlockCache(lumi.index());
387 
388  for (int i = 0; i < 2; ++i) {
389  for (int j = 0; j < 2; ++j) {
390  float nValidChannelsES = 0;
391  float nGlobalErrorsES = 0;
392  float reportSummaryES = -1;
393  for (int x = 0; x < 40; ++x) {
394  for (int y = 0; y < 40; ++y) {
395  float val = 1.0 * ((lumiCache->DIErrorsByLS_)[i][j][x][y]);
396  if (fed_[i][j][x][y] == -1)
397  continue;
398  if ((lumiCache->ievtLS_) != 0)
399  nGlobalErrors += val / (lumiCache->ievtLS_);
400  nValidChannels++;
401  if ((lumiCache->ievtLS_) != 0)
402  nGlobalErrorsES += val / (lumiCache->ievtLS_);
403  nValidChannelsES++;
404  }
405  }
406  if (nValidChannelsES != 0)
407  reportSummaryES = 1 - nGlobalErrorsES / nValidChannelsES;
408  meDIFraction_->setBinContent(i + 1, j + 1, reportSummaryES);
409  }
410  }
411  float reportSummary = -1.0;
412  if (nValidChannels != 0)
413  reportSummary = 1.0 - nGlobalErrors / nValidChannels;
414  meDIFraction_->setBinContent(3, 3, reportSummary);
415 }
int getBC() const
Definition: ESKCHIPBlock.h:33
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::shared_ptr< ESIntLSCache > globalBeginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &c) const override
Begin Lumi.
int getFlag2() const
Definition: ESKCHIPBlock.h:38
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::vector< T >::const_iterator const_iterator
void dqmEndRun(const edm::Run &r, const edm::EventSetup &c) override
EndRun.
int getOptoEC() const
Definition: ESKCHIPBlock.h:36
T getUntrackedParameter(std::string const &, T const &) const
void calculateDIFraction(const edm::LuminosityBlock &lumi, const edm::EventSetup &c)
Calculate Data Integrity Fraction.
int getEC() const
Definition: ESKCHIPBlock.h:34
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
Namespace of DDCMS conversion namespace.
const_iterator end() const
int getOptoBC() const
Definition: ESKCHIPBlock.h:35
Log< level::Info, false > LogInfo
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
void endJob(void) override
EndJob.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
HLT enums.
static const char gain_[]
float x
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
ESIntegrityTask(const edm::ParameterSet &ps)
Log< level::Warning, false > LogWarning
const int & id() const
Definition: ESKCHIPBlock.h:13
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Analyze.
int getFlag1() const
Definition: ESKCHIPBlock.h:37
void globalEndLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &c) override
End Lumi.
Definition: Run.h:45
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)