CMS 3D CMS Logo

DTDataIntegrityTest.cc
Go to the documentation of this file.
1 /*
2  * \file DTDataIntegrityTest.cc
3  *
4  * \author S. Bolognesi - CERN
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah ncpp-um-my
7  *
8  *
9  */
10 
12 
13 //Framework
20 
21 #include <iostream>
22 #include <string>
23 
24 using namespace std;
25 using namespace edm;
26 
28  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest") << "[DTDataIntegrityTest]: Constructor";
29 
30  // prescale on the # of LS to update the test
31  prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
32 
33  checkUros = ps.getUntrackedParameter<bool>("checkUros", false);
34 
35  bookingdone = false;
36 }
37 
39  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest")
40  << "DataIntegrityTest: analyzed " << nupdates << " updates";
41 }
42 
44  DQMStore::IGetter& igetter,
45  edm::LuminosityBlock const& lumiSeg,
46  edm::EventSetup const& context) {
47  if (!bookingdone) {
48  //nSTAEvents = 0;
49  nupdates = 0;
50  run = 0;
51 
52  // book the summary histogram
53 
54  ibooker.setCurrentFolder("DT/00-DataIntegrity");
55 
56  summaryHisto = ibooker.book2D("DataIntegritySummary", "Summary Data Integrity", 12, 1, 13, 5, -2, 3);
57  summaryHisto->setAxisTitle("Sector", 1);
58  summaryHisto->setAxisTitle("Wheel", 2);
59 
60  ibooker.setCurrentFolder("DT/00-DataIntegrity");
61 
62  summaryTDCHisto = ibooker.book2D("DataIntegrityTDCSummary", "TDC Summary Data Integrity", 12, 1, 13, 5, -2, 3);
63  summaryTDCHisto->setAxisTitle("Sector", 1);
64  summaryTDCHisto->setAxisTitle("Wheel", 2);
65 
66  ibooker.setCurrentFolder("DT/00-DataIntegrity");
67 
68  glbSummaryHisto = ibooker.book2D("DataIntegrityGlbSummary", "Summary Data Integrity", 12, 1, 13, 5, -2, 3);
69  glbSummaryHisto->setAxisTitle("Sector", 1);
70  glbSummaryHisto->setAxisTitle("Wheel", 2);
71 
72  context.get<DTReadOutMappingRcd>().get(mapping);
73  } //booking
74  bookingdone = true;
75 
76  // counts number of lumiSegs
77  nLumiSegs = lumiSeg.id().luminosityBlock();
78  string nLumiSegs_s = to_string(nLumiSegs);
79 
80  // prescale factor
81  if (nLumiSegs % prescaleFactor != 0)
82  return;
83 
84  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest")
85  << "[DTDataIntegrityTest]: End of LS " << nLumiSegs << ", performing client operations";
86 
87  // counts number of updats
88  nupdates++;
89 
90  //Counter for x bin in the timing histos
91  counter++;
92 
93  //Loop on FED id
94  //Monitoring only real used FEDs
95  int FEDIDmax = FEDNumbering::MAXDTFEDID;
96  int FEDIDmin = FEDNumbering::MINDTFEDID;
97  if (checkUros) {
100  }
101 
102  for (int dduId = FEDIDmin; dduId <= FEDIDmax; ++dduId) {
103  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest") << "[DTDataIntegrityTest]:FED Id: " << dduId;
104 
105  //Each nTimeBin onUpdate remove timing histos and book a new bunch of them
106  string dduId_s = to_string(dduId);
107 
108  string histoType;
109 
110  //Check if the list of ROS is compatible with the channels enabled
111  string rosStatusName = "DT/00-DataIntegrity/FED" + dduId_s + "/FED" + dduId_s + "_ROSStatus";
112  if (checkUros)
113  rosStatusName = "DT/00-DataIntegrity/FED" + dduId_s + "/FED" + dduId_s + "_uROSStatus";
114  MonitorElement* FED_ROSStatus = igetter.get(rosStatusName);
115 
116  // Get the error summary histo
117  string fedSummaryName = "DT/00-DataIntegrity/FED" + dduId_s + "_ROSSummary";
118  MonitorElement* FED_ROSSummary = nullptr;
119  MonitorElement* FED_ROSSummary1 = nullptr;
120  MonitorElement* FED_ROSSummary2 = nullptr;
121  string fedSummaryName1 = "";
122  string fedSummaryName2 = "";
123  string sign = "-";
124  if (checkUros) {
125  if (dduId == FEDIDmin || dduId == FEDIDmax) {
126  if (dduId == FEDIDmax)
127  sign = "";
128  fedSummaryName2 = "DT/00-DataIntegrity/ROSSummary_W" + sign + "2";
129  fedSummaryName1 = "DT/00-DataIntegrity/ROSSummary_W" + sign + "1";
130  FED_ROSSummary1 = igetter.get(fedSummaryName1);
131  FED_ROSSummary2 = igetter.get(fedSummaryName2);
132  } else {
133  fedSummaryName = "DT/00-DataIntegrity/ROSSummary_W0";
134  FED_ROSSummary1 = igetter.get(fedSummaryName);
135  FED_ROSSummary2 = igetter.get(fedSummaryName); //for wheel compatibility...
136  }
137  } else
138  FED_ROSSummary = igetter.get(fedSummaryName); //legacy case
139 
140  // Get the event length plot (used to count # of processed evts)
141  string fedEvLenName = "DT/00-DataIntegrity/FED" + dduId_s + "/FED" + dduId_s + "_EventLength";
142  MonitorElement* FED_EvLength = igetter.get(fedEvLenName);
143 
144  // Get the histos for FED integrity
145  string fedIntegrityFolder = "DT/00-DataIntegrity/";
146  MonitorElement* hFEDEntry = igetter.get(fedIntegrityFolder + "FEDEntries");
147  MonitorElement* hFEDFatal = igetter.get(fedIntegrityFolder + "FEDFatal");
148  MonitorElement* hFEDNonFatal = igetter.get(fedIntegrityFolder + "FEDNonFatal");
149 
150  if (checkUros) {
151  if (hFEDEntry) {
152  int offsetFED = 1368;
153  // Check that the FED is in the ReadOut using the FEDIntegrity histos
154  bool fedNotReadout = (hFEDEntry->getBinContent(dduId - offsetFED)) == 0;
155  int wheel = dduId - offsetFED - 2;
156  if (FED_ROSSummary1 && FED_ROSSummary2 && FED_ROSStatus && FED_EvLength && !fedNotReadout) {
157  TH2F* histoFEDSummary1 = FED_ROSSummary1->getTH2F();
158  TH2F* histoFEDSummary2 = FED_ROSSummary2->getTH2F(); // same for central FED...
159  TH2F* histoROSStatus = FED_ROSStatus->getTH2F();
160  TH1F* histoEvLength = FED_EvLength->getTH1F();
161 
162  int nFEDEvts = histoEvLength->Integral();
163  //if(dduId==FEDIDmin || dduId==FEDIDmax) nFEDEvts = nFEDEvts/2.; // split in 2 for external FEDs
164  if (!(nFEDEvts > 0))
165  continue;
166  int extraFEDevents1 = 0;
167  int extraFEDevents2 = 0;
168 
169  for (int urosNumber = 1; urosNumber <= DOCESLOTS; ++urosNumber) { // loop on the uROS
170  string urosNumber_s = to_string(urosNumber);
171  // Get the event length plot for this uROS (used to count # of processed evts)
172  string fedUrosEvLenName = "DT/00-DataIntegrity/FED" + dduId_s + "/uROS" + urosNumber_s + "/FED" + dduId_s +
173  "_uROS" + urosNumber_s + "_EventLength";
174  MonitorElement* FED_uROS_EvLength = igetter.get(fedUrosEvLenName);
175  TH1F* histoUrosEvLength = FED_uROS_EvLength->getTH1F();
176  int nFEDEvtsUros = histoUrosEvLength->Integral();
177 
178  //station 4 sectors drievn by uROS 1 & 2
179  if (urosNumber == 1) {
180  extraFEDevents1 = nFEDEvtsUros;
181  continue;
182  }
183  if (urosNumber == 2) {
184  extraFEDevents2 = nFEDEvtsUros;
185  continue;
186  }
187 
188  if (nFEDEvtsUros > 0) { //this uROS is active
189  nFEDEvtsUros = extraFEDevents1 + extraFEDevents2 + nFEDEvtsUros / 3.; // split in 3 ROS
190  float nGErrors = histoROSStatus->Integral(1, 12, urosNumber, urosNumber); //Only Global Errors,
191  //not possible to distinguish which ROS, so coumting them in the 3/12 ROSes
192 
193  int ros = getROS(urosNumber, 0);
194  for (int iros = ros; iros < (ros + 3); ++iros) {
195  // -1,0,+1 wheels
196  float nROBErrors1 = histoFEDSummary1->Integral(1, 5, iros, iros); //Errors and Not OK Flag
197  float nErrors1 = nROBErrors1 + nGErrors;
198  float result1 = 0.;
199  if (nFEDEvtsUros != 0)
200  result1 = max((float)0., ((float)nFEDEvtsUros - nROBErrors1) / (float)nFEDEvtsUros);
201  summaryHisto->setBinContent(iros, wheel + 3, result1);
202  double tdcResult1 = -2;
203  float nTDCErrors1 = histoFEDSummary1->Integral(6, 6, iros, iros); //Only TDC fatal considered
204  if (nTDCErrors1 == 0) { // no errors
205  tdcResult1 = 0.5;
206  } else { // there are errors
207  tdcResult1 = 2.5;
208  }
209  summaryTDCHisto->setBinContent(iros, wheel + 3, tdcResult1);
210 
211  // FIXME: different errors should have different weights
212  float sectPerc1 = 0.;
213  if (nFEDEvtsUros != 0)
214  sectPerc1 = max((float)0., ((float)nFEDEvtsUros - nErrors1) / (float)nFEDEvtsUros);
215  glbSummaryHisto->setBinContent(iros, wheel + 3, sectPerc1);
216  if (dduId == (FEDIDmax - 1))
217  continue; //wheel 0 case
218 
219  // -2,+2 wheels
220  float nROBErrors2 = histoFEDSummary2->Integral(1, 5, iros, iros); //Errors and Not OK Flag
221  float nErrors2 = nROBErrors2 + nGErrors;
222  float result2 = 0.;
223  if (nFEDEvtsUros != 0)
224  result2 = max((float)0., ((float)nFEDEvtsUros - nROBErrors2) / (float)nFEDEvtsUros);
225  summaryHisto->setBinContent(iros, wheel * 2 + 3, result2);
226 
227  double tdcResult2 = -2;
228  float nTDCErrors2 = histoFEDSummary2->Integral(6, 6, iros, iros); //Only TDC fatal considered
229  if (nTDCErrors2 == 0) { // no errors
230  tdcResult2 = 0.5;
231  } else { // there are errors
232  tdcResult2 = 2.5;
233  }
234  summaryTDCHisto->setBinContent(iros, wheel * 2 + 3, tdcResult2);
235 
236  // FIXME: different errors should have different weights
237  float sectPerc2 = 0.;
238  if (nFEDEvtsUros != 0)
239  sectPerc2 = max((float)0., ((float)nFEDEvtsUros - nErrors2) / (float)nFEDEvtsUros);
240  glbSummaryHisto->setBinContent(iros, wheel * 2 + 3, sectPerc2);
241  } //loop in three ros
242  } // this uROS is active
243  } //loop on uros
244  } else { // no data in this FED: it is off, no ROS suummary/status or evLength and fedNotReadout
245  for (int i = 1; i <= DOCESLOTS; ++i) {
246  summaryHisto->setBinContent(i, wheel + 3, 0.5);
247  summaryTDCHisto->setBinContent(i, wheel + 3, 1.5);
248  glbSummaryHisto->setBinContent(i, wheel + 3, 0.5);
249  if (dduId == (FEDIDmax - 1))
250  continue; //wheel 0 case
251  summaryHisto->setBinContent(i, wheel * 2 + 3, 0.5);
252  summaryTDCHisto->setBinContent(i, wheel * 2 + 3, 1.5);
253  glbSummaryHisto->setBinContent(i, wheel * 2 + 3, 0.5);
254  } //loop on uros
255  } // no data in this FED: it is off, no ROS suummary/status or evLength
256 
257  } //FEDentry
258  } else { //legacy case
259  if (hFEDEntry && hFEDFatal && hFEDNonFatal) {
260  if (FED_ROSSummary && FED_ROSStatus && FED_EvLength) {
261  TH2F* histoFEDSummary = FED_ROSSummary->getTH2F();
262  TH2F* histoROSStatus = FED_ROSStatus->getTH2F();
263  TH1F* histoEvLength = FED_EvLength->getTH1F();
264  // Check that the FED is in the ReadOut using the FEDIntegrity histos
265  bool fedNotReadout =
266  (hFEDEntry->getBinContent(dduId - 769) == 0 && hFEDFatal->getBinContent(dduId - 769) == 0 &&
267  hFEDNonFatal->getBinContent(dduId - 769) == 0);
268 
269  int nFEDEvts = histoEvLength->Integral();
270  for (int rosNumber = 1; rosNumber <= 12; ++rosNumber) { // loop on the ROS
271  int wheelNumber, sectorNumber;
272  if (!readOutToGeometry(dduId, rosNumber, wheelNumber, sectorNumber)) {
273  float nErrors = histoFEDSummary->Integral(1, 14, rosNumber, rosNumber);
274  float nROBErrors = histoROSStatus->Integral(2, 8, rosNumber, rosNumber);
275  nErrors += nROBErrors;
276  float result = 0.;
277  if (nFEDEvts != 0)
278  result = max((float)0., ((float)nFEDEvts - nROBErrors) / (float)nFEDEvts);
279  summaryHisto->setBinContent(sectorNumber, wheelNumber + 3, result);
280  int tdcResult = -2;
281  float nTDCErrors = histoFEDSummary->Integral(15, 15, rosNumber, rosNumber);
282  if (nTDCErrors == 0) { // no errors
283  tdcResult = 0;
284  } else { // there are errors
285  tdcResult = 2;
286  }
287  summaryTDCHisto->setBinContent(sectorNumber, wheelNumber + 3, tdcResult);
288  // FIXME: different errors should have different weights
289  float sectPerc = max((float)0., ((float)nFEDEvts - nErrors) / (float)nFEDEvts);
290  glbSummaryHisto->setBinContent(sectorNumber, wheelNumber + 3, sectPerc);
291 
292  if (fedNotReadout) {
293  // no data in this FED: it is off
294  summaryHisto->setBinContent(sectorNumber, wheelNumber + 3, 0);
295  summaryTDCHisto->setBinContent(sectorNumber, wheelNumber + 3, 1);
296  glbSummaryHisto->setBinContent(sectorNumber, wheelNumber + 3, 0);
297  } //fedNotReadout
298  } //mapping
299  } //loop on ros
300  } else { // no data in this FED: it is off, no ROS suummary/status or evLength
301  for (int rosNumber = 1; rosNumber <= 12; ++rosNumber) {
302  int wheelNumber, sectorNumber;
303  if (!readOutToGeometry(dduId, rosNumber, wheelNumber, sectorNumber)) {
304  summaryHisto->setBinContent(sectorNumber, wheelNumber + 3, 0);
305  summaryTDCHisto->setBinContent(sectorNumber, wheelNumber + 3, 1);
306  glbSummaryHisto->setBinContent(sectorNumber, wheelNumber + 3, 0);
307  } //mapping
308  } //loop on ros
309  } // no data in this FED: it is off, no ROS suummary/status or evLength
310 
311  } // no FED entry, fatal, nonfatal
312 
313  } //legacy case
314 
315  } // loop on dduIds
316 }
317 
319  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest") << "[DTDataIntegrityTest] endjob called!";
320 }
321 
322 string DTDataIntegrityTest::getMEName(string histoType, int FEDId) {
323  //Use the DDU name to find the ME
324  stringstream dduID_s;
325  dduID_s << FEDId;
326 
327  string folderName = "DT/00-DataIntegrity/FED" + dduID_s.str();
328 
329  string histoName = folderName + "/FED" + dduID_s.str() + "_" + histoType;
330  return histoName;
331 }
332 
333 void DTDataIntegrityTest::bookHistos(DQMStore::IBooker& ibooker, string histoType, int dduId) {
334  stringstream dduId_s;
335  dduId_s << dduId;
336 
337  ibooker.setCurrentFolder("DT/00-DataIntegrity/FED" + dduId_s.str());
338  string histoName;
339 }
340 
341 int DTDataIntegrityTest::readOutToGeometry(int dduId, int ros, int& wheel, int& sector) {
342  int dummy;
343  return mapping->readOutToGeometry(dduId, ros, 2, 2, 2, wheel, dummy, sector, dummy, dummy, dummy);
344 }
345 
346 int DTDataIntegrityTest::getROS(int uROS, int link) {
347  int slot = 0;
348  switch (uROS) {
349  case 1: {
350  slot = 5;
351  break;
352  }
353  case 2: {
354  slot = 11;
355  break;
356  }
357  case 3: {
358  slot = 1;
359  break;
360  }
361  case 4: {
362  slot = 7;
363  break;
364  }
365  case 5: {
366  slot = 2;
367  break;
368  }
369  case 6: {
370  slot = 8;
371  break;
372  }
373  case 9: {
374  slot = 9;
375  break;
376  }
377  case 10: {
378  slot = 3;
379  break;
380  }
381  case 11: {
382  slot = 10;
383  break;
384  }
385  case 12: {
386  slot = 4;
387  break;
388  }
389  }
390 
391  if (slot % 6 == 5)
392  return link + 1;
393 
394  int ros = (link / 24) + 3 * (slot % 6) - 2;
395  return ros;
396 }
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
int readOutToGeometry(int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId &wireId) const
transform identifiers
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
virtual TH1F * getTH1F() const
MonitorElement * summaryTDCHisto
DTDataIntegrityTest(const edm::ParameterSet &ps)
Constructor.
MonitorElement * glbSummaryHisto
static const int DOCESLOTS
std::string getMEName(std::string histoType, int FEDId)
Get the ME name.
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
DQM Client Diagnostic.
def wheelNumber(wheell)
Definition: plotscripts.py:47
virtual double getBinContent(int binx) const
get content of bin (1-D)
MonitorElement * summaryHisto
#define LogTrace(id)
int readOutToGeometry(int dduId, int rosNumber, int &wheel, int &sector)
edm::ESHandle< DTReadOutMapping > mapping
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
LuminosityBlockNumber_t luminosityBlock() const
int getROS(int uROS, int link)
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
~DTDataIntegrityTest() override
Destructor.
HLT enums.
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
T get() const
Definition: EventSetup.h:73
void bookHistos(DQMStore::IBooker &, std::string histoType, int dduId)
Book the MEs.
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:437
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)