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