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
19 
20 #include <iostream>
21 #include <string>
22 
23 using namespace std;
24 using namespace edm;
25 
27  : nevents(0), mappingToken_(esConsumes<edm::Transition::EndLuminosityBlock>()) {
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  bookingdone = false;
34 }
35 
37  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest")
38  << "DataIntegrityTest: analyzed " << nupdates << " updates";
39 }
40 
42  DQMStore::IGetter& igetter,
43  edm::LuminosityBlock const& lumiSeg,
44  edm::EventSetup const& context) {
45  if (!bookingdone) {
46  //nSTAEvents = 0;
47  nupdates = 0;
48  run = 0;
49 
50  // book the summary histogram
51 
52  ibooker.setCurrentFolder("DT/00-DataIntegrity");
53 
54  summaryHisto = ibooker.book2D("DataIntegritySummary", "Summary Data Integrity", 12, 1, 13, 5, -2, 3);
55  summaryHisto->setAxisTitle("Sector", 1);
56  summaryHisto->setAxisTitle("Wheel", 2);
57 
58  ibooker.setCurrentFolder("DT/00-DataIntegrity");
59 
60  summaryTDCHisto = ibooker.book2D("DataIntegrityTDCSummary", "TDC Summary Data Integrity", 12, 1, 13, 5, -2, 3);
61  summaryTDCHisto->setAxisTitle("Sector", 1);
62  summaryTDCHisto->setAxisTitle("Wheel", 2);
63 
64  ibooker.setCurrentFolder("DT/00-DataIntegrity");
65 
66  glbSummaryHisto = ibooker.book2D("DataIntegrityGlbSummary", "Summary Data Integrity", 12, 1, 13, 5, -2, 3);
67  glbSummaryHisto->setAxisTitle("Sector", 1);
68  glbSummaryHisto->setAxisTitle("Wheel", 2);
69 
70  mapping = &context.getData(mappingToken_);
71  } //booking
72  bookingdone = true;
73 
74  // counts number of lumiSegs
75  nLumiSegs = lumiSeg.id().luminosityBlock();
76  string nLumiSegs_s = to_string(nLumiSegs);
77 
78  // prescale factor
79  if (nLumiSegs % prescaleFactor != 0)
80  return;
81 
82  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest")
83  << "[DTDataIntegrityTest]: End of LS " << nLumiSegs << ", performing client operations";
84 
85  // counts number of updats
86  nupdates++;
87 
88  //Counter for x bin in the timing histos
89  counter++;
90 
91  //Loop on FED id
92  //Monitoring only real used FEDs
93  int FEDIDmin = FEDNumbering::MINDTUROSFEDID;
94  int FEDIDmax = FEDNumbering::MAXDTUROSFEDID;
95 
96  for (int dduId = FEDIDmin; dduId <= FEDIDmax; ++dduId) {
97  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest") << "[DTDataIntegrityTest]:FED Id: " << dduId;
98 
99  //Each nTimeBin onUpdate remove timing histos and book a new bunch of them
100  string dduId_s = to_string(dduId);
101 
102  string histoType;
103 
104  //Check if the list of ROS is compatible with the channels enabled
105  string rosStatusName = "DT/00-DataIntegrity/FED" + dduId_s + "/FED" + dduId_s + "_uROSStatus";
106  MonitorElement* FED_ROSStatus = igetter.get(rosStatusName);
107 
108  // Get the error summary histo
109  string fedSummaryName = "DT/00-DataIntegrity/FED" + dduId_s + "_ROSSummary";
110  MonitorElement* FED_ROSSummary1 = nullptr;
111  MonitorElement* FED_ROSSummary2 = nullptr;
112  string fedSummaryName1 = "";
113  string fedSummaryName2 = "";
114  string sign = "-";
115  if (dduId == FEDIDmin || dduId == FEDIDmax) {
116  if (dduId == FEDIDmax)
117  sign = "";
118  fedSummaryName2 = "DT/00-DataIntegrity/ROSSummary_W" + sign + "2";
119  fedSummaryName1 = "DT/00-DataIntegrity/ROSSummary_W" + sign + "1";
120  FED_ROSSummary1 = igetter.get(fedSummaryName1);
121  FED_ROSSummary2 = igetter.get(fedSummaryName2);
122  } else {
123  fedSummaryName = "DT/00-DataIntegrity/ROSSummary_W0";
124  FED_ROSSummary1 = igetter.get(fedSummaryName);
125  FED_ROSSummary2 = igetter.get(fedSummaryName); //for wheel compatibility...
126  }
127 
128  // Get the event length plot (used to count # of processed evts)
129  string fedEvLenName = "DT/00-DataIntegrity/FED" + dduId_s + "/FED" + dduId_s + "_EventLength";
130  MonitorElement* FED_EvLength = igetter.get(fedEvLenName);
131 
132  // Get the histos for FED integrity
133  string fedIntegrityFolder = "DT/00-DataIntegrity/";
134  MonitorElement* hFEDEntry = igetter.get(fedIntegrityFolder + "FEDEntries");
135  MonitorElement* hFEDFatal = igetter.get(fedIntegrityFolder + "FEDFatal");
136 
137  if (hFEDEntry && hFEDFatal) {
138  int offsetFED = 1368;
139  // Check that the FED is in the ReadOut using the FEDIntegrity histos
140  bool fedNotReadout =
141  (hFEDEntry->getBinContent(dduId - offsetFED) == 0 && hFEDFatal->getBinContent(dduId - offsetFED) == 0);
142  int wheel = dduId - offsetFED - 2;
143  if (FED_ROSSummary1 && FED_ROSSummary2 && FED_ROSStatus && FED_EvLength && !fedNotReadout) {
144  TH2F* histoFEDSummary1 = FED_ROSSummary1->getTH2F();
145  TH2F* histoFEDSummary2 = FED_ROSSummary2->getTH2F(); // same for central FED...
146  TH2F* histoROSStatus = FED_ROSStatus->getTH2F();
147  TH1F* histoEvLength = FED_EvLength->getTH1F();
148 
149  int nFEDEvts = histoEvLength->Integral();
150  //if(dduId==FEDIDmin || dduId==FEDIDmax) nFEDEvts = nFEDEvts/2.; // split in 2 for external FEDs
151  if (!(nFEDEvts > 0))
152  continue;
153  int extraFEDevents1 = 0;
154  int extraFEDevents2 = 0;
155 
156  for (int urosNumber = 1; urosNumber <= DOCESLOTS; ++urosNumber) { // loop on the uROS
157  string urosNumber_s = to_string(urosNumber);
158  // Get the event length plot for this uROS (used to count # of processed evts)
159  string fedUrosEvLenName = "DT/00-DataIntegrity/FED" + dduId_s + "/uROS" + urosNumber_s + "/FED" + dduId_s +
160  "_uROS" + urosNumber_s + "_EventLength";
161  MonitorElement* FED_uROS_EvLength = igetter.get(fedUrosEvLenName);
162  TH1F* histoUrosEvLength = FED_uROS_EvLength->getTH1F();
163  int nFEDEvtsUros = histoUrosEvLength->Integral();
164 
165  //station 4 sectors drievn by uROS 1 & 2
166  if (urosNumber == 1) {
167  extraFEDevents1 = nFEDEvtsUros;
168  continue;
169  }
170  if (urosNumber == 2) {
171  extraFEDevents2 = nFEDEvtsUros;
172  continue;
173  }
174 
175  if (nFEDEvtsUros > 0) { //this uROS is active
176  nFEDEvtsUros = extraFEDevents1 + extraFEDevents2 + nFEDEvtsUros / 3.; // split in 3 ROS
177  float nGErrors = histoROSStatus->Integral(1, 12, urosNumber, urosNumber); //Only Global Errors,
178  //not possible to distinguish which ROS, so coumting them in the 3/12 ROSes
179 
180  int ros = getROS(urosNumber, 0);
181  for (int iros = ros; iros < (ros + 3); ++iros) {
182  // -1,0,+1 wheels
183  float nROBErrors1 = histoFEDSummary1->Integral(1, 5, iros, iros); //Errors and Not OK Flag
184  float nErrors1 = nROBErrors1 + nGErrors;
185  float result1 = 0.;
186  if (nFEDEvtsUros != 0)
187  result1 = max((float)0., ((float)nFEDEvtsUros - nROBErrors1) / (float)nFEDEvtsUros);
188  summaryHisto->setBinContent(iros, wheel + 3, result1);
189  double tdcResult1 = -2;
190  float nTDCErrors1 = histoFEDSummary1->Integral(6, 6, iros, iros); //Only TDC fatal considered
191  if (nTDCErrors1 == 0) { // no errors
192  tdcResult1 = 0.5;
193  } else { // there are errors
194  tdcResult1 = 2.5;
195  }
196  summaryTDCHisto->setBinContent(iros, wheel + 3, tdcResult1);
197 
198  // FIXME: different errors should have different weights
199  float sectPerc1 = 0.;
200  if (nFEDEvtsUros != 0)
201  sectPerc1 = max((float)0., ((float)nFEDEvtsUros - nErrors1) / (float)nFEDEvtsUros);
202  glbSummaryHisto->setBinContent(iros, wheel + 3, sectPerc1);
203  if (dduId == (FEDIDmax - 1))
204  continue; //wheel 0 case
205 
206  // -2,+2 wheels
207  float nROBErrors2 = histoFEDSummary2->Integral(1, 5, iros, iros); //Errors and Not OK Flag
208  float nErrors2 = nROBErrors2 + nGErrors;
209  float result2 = 0.;
210  if (nFEDEvtsUros != 0)
211  result2 = max((float)0., ((float)nFEDEvtsUros - nROBErrors2) / (float)nFEDEvtsUros);
212  summaryHisto->setBinContent(iros, wheel * 2 + 3, result2);
213 
214  double tdcResult2 = -2;
215  float nTDCErrors2 = histoFEDSummary2->Integral(6, 6, iros, iros); //Only TDC fatal considered
216  if (nTDCErrors2 == 0) { // no errors
217  tdcResult2 = 0.5;
218  } else { // there are errors
219  tdcResult2 = 2.5;
220  }
221  summaryTDCHisto->setBinContent(iros, wheel * 2 + 3, tdcResult2);
222 
223  // FIXME: different errors should have different weights
224  float sectPerc2 = 0.;
225  if (nFEDEvtsUros != 0)
226  sectPerc2 = max((float)0., ((float)nFEDEvtsUros - nErrors2) / (float)nFEDEvtsUros);
227  glbSummaryHisto->setBinContent(iros, wheel * 2 + 3, sectPerc2);
228  } //loop in three ros
229  } // this uROS is active
230  } //loop on uros
231  } else { // no data in this FED: it is off, no ROS suummary/status or evLength and fedNotReadout
232  for (int i = 1; i <= DOCESLOTS; ++i) {
233  summaryHisto->setBinContent(i, wheel + 3, 0.5);
234  summaryTDCHisto->setBinContent(i, wheel + 3, 1.5);
235  glbSummaryHisto->setBinContent(i, wheel + 3, 0.5);
236  if (dduId == (FEDIDmax - 1))
237  continue; //wheel 0 case
238  summaryHisto->setBinContent(i, wheel * 2 + 3, 0.5);
239  summaryTDCHisto->setBinContent(i, wheel * 2 + 3, 1.5);
240  glbSummaryHisto->setBinContent(i, wheel * 2 + 3, 0.5);
241  } //loop on uros
242  } // no data in this FED: it is off, no ROS suummary/status or evLength
243 
244  } //FEDentry
245 
246  } // loop on dduIds
247 }
248 
250  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTDataIntegrityTest") << "[DTDataIntegrityTest] endjob called!";
251 }
252 
253 string DTDataIntegrityTest::getMEName(string histoType, int FEDId) {
254  //Use the DDU name to find the ME
255  stringstream dduID_s;
256  dduID_s << FEDId;
257 
258  string folderName = "DT/00-DataIntegrity/FED" + dduID_s.str();
259 
260  string histoName = folderName + "/FED" + dduID_s.str() + "_" + histoType;
261  return histoName;
262 }
263 
264 int DTDataIntegrityTest::readOutToGeometry(int dduId, int ros, int& wheel, int& sector) {
265  int dummy;
266  return mapping->readOutToGeometry(dduId, ros, 2, 2, 2, wheel, dummy, sector, dummy, dummy, dummy);
267 }
268 
269 int DTDataIntegrityTest::getROS(int uROS, int link) {
270  int slot = 0;
271  switch (uROS) {
272  case 1: {
273  slot = 5;
274  break;
275  }
276  case 2: {
277  slot = 11;
278  break;
279  }
280  case 3: {
281  slot = 1;
282  break;
283  }
284  case 4: {
285  slot = 7;
286  break;
287  }
288  case 5: {
289  slot = 2;
290  break;
291  }
292  case 6: {
293  slot = 8;
294  break;
295  }
296  case 9: {
297  slot = 9;
298  break;
299  }
300  case 10: {
301  slot = 3;
302  break;
303  }
304  case 11: {
305  slot = 10;
306  break;
307  }
308  case 12: {
309  slot = 4;
310  break;
311  }
312  }
313 
314  if (slot % 6 == 5)
315  return link + 1;
316 
317  int ros = (link / 24) + 3 * (slot % 6) - 2;
318  return ros;
319 }
int readOutToGeometry(int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId &wireId) const
transform identifiers
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
LuminosityBlockNumber_t luminosityBlock() const
edm::ESGetToken< DTReadOutMapping, DTReadOutMappingRcd > mappingToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const DTReadOutMapping * mapping
std::string to_string(const V &value)
Definition: OMSAccess.h:71
MonitorElement * summaryTDCHisto
DTDataIntegrityTest(const edm::ParameterSet &ps)
Constructor.
MonitorElement * glbSummaryHisto
#define LogTrace(id)
static const int DOCESLOTS
T getUntrackedParameter(std::string const &, T const &) const
virtual TH2F * getTH2F() const
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.
Transition
Definition: Transition.h:12
MonitorElement * summaryHisto
int readOutToGeometry(int dduId, int rosNumber, int &wheel, int &sector)
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
LuminosityBlockID id() const
virtual TH1F * getTH1F() 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
int getROS(int uROS, int link)
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
~DTDataIntegrityTest() override
Destructor.
HLT enums.
virtual double getBinContent(int binx) const
get content of bin (1-D)
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)