CMS 3D CMS Logo

DTBlockedROChannelsTest.cc
Go to the documentation of this file.
1 /*
2  * \file DTBlockedROChannelsTest.cc
3  *
4  * \author G. Cerminara - University and INFN Torino
5  *
6  */
7 
9 
10 //Framework
19 #include <iostream>
20 #include <string>
21 
22 
23 using namespace std;
24 using namespace edm;
25 
26 
28  neventsPrev(0),
29  prevNLumiSegs(0),
30  prevTotalPerc(0),
31  hSystFractionVsLS(nullptr)
32 {
33  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
34  << "[DTBlockedROChannelsTest]: Constructor";
35 
36  // prescale on the # of LS to update the test
37  prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
38 
39  offlineMode = ps.getUntrackedParameter<bool>("offlineMode", true);
40 
41  checkUros = ps.getUntrackedParameter<bool>("checkUros", true);
42 
43 }
44 
45 
46 
48  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
49  << "DataIntegrityTest: analyzed " << nupdates << " updates";
50 }
51 
52 
54 {
55 
56  nupdates = 0;
57  return;
58 }
59 
60 
62  // get the RO mapping
63  context.get<DTReadOutMappingRcd>().get(mapping);
64  int dummy = 0;
65  bool tenDDU = !mapping->readOutToGeometry(779, 7, 1, 1, 1,
66  dummy, dummy, dummy,
67  dummy, dummy, dummy);
68 
69  if (checkUros){
70  for(int crate = FEDNumbering::MINDTUROSFEDID; crate<=FEDNumbering::MAXDTUROSFEDID; ++crate) { //loop over FEDs
71  for (int mapSlot=1; mapSlot!=13; ++mapSlot){ //loop over mapSlot
72  for (int link=0; link!=72; ++link){ //loop over links
73  //skip non existing links
74  if (mapSlot==6) continue;
75  if (crate==1370 && mapSlot>5) continue;
76  if ((mapSlot==5 || mapSlot==11) && link>11) continue;
77 
78  int wheel = 0;
79  int station = 0;
80  int sector = 0;
81 
82  int dduId = theDDU(crate, mapSlot, link, tenDDU) ;
83  int ros = theROS(mapSlot, link);
84  int rob = theROB(mapSlot, link);
85 
86 // mapping->readOutToGeometry(dduId,ros,rob,2,2,wheel,station,sector,dummy,dummy,dummy);
87  readOutToGeometry(dduId,ros,rob,wheel,station,sector);
88  if (station>0) {
89  //std::cout<<" FED "<<crate<<" mapSlot "<< mapSlot<<" Link "<<link<<" Wh "<<wheel<<" station "<<station<<" sector "<<sector <<endl;
90  DTChamberId chId(wheel, station, sector);
91  if(chamberMapUros.find(chId) == chamberMapUros.end()) {
92  chamberMapUros[chId] = DTLinkBinsMap(igetter, dduId, ros);
93  chamberMapUros[chId].addLinkBin(link%24);
94  }
95  chamberMapUros[chId].addLinkBin(link%24);
96  } else {
97  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
98  << "[DTLinkBinsMap] FED: " << crate << "mapSlot: " << mapSlot << " Link: " << link
99  << " not in the mapping!" << endl;
100  }
101  } //loop on links
102  } //loop on mapSlots
103  } //loop on crates
104  } //checkUros
105  else{
106  // fill the map of the robs per chamber
107  // //FIXME: monitoring only real used FEDs
108  for(int dduId = FEDNumbering::MINDTFEDID; dduId<=FEDNumbering::MAXDTFEDID; ++dduId) { //loop over DDUs
109  for(int ros = 1; ros != 13; ++ros) { // loop over ROSs
110  for(int rob = 1; rob != 26; ++rob) { // loop over ROBs
111  int wheel = 0;
112  int station = 0;
113  int sector = 0;
114  if(!mapping->readOutToGeometry(dduId,ros,rob-1,0,2,wheel,station,sector,dummy,dummy,dummy) ||
115  !mapping->readOutToGeometry(dduId,ros,rob-1,0,16,wheel,station,sector,dummy,dummy,dummy)) {
116  DTChamberId chId(wheel, station, sector);
117  if(chamberMap.find(chId) == chamberMap.end()) {
118  chamberMap[chId] = DTRobBinsMap(igetter, dduId, ros);
119  chamberMap[chId].addRobBin(rob);
120  }
121  chamberMap[chId].addRobBin(rob);
122  } else {
123  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
124  << "[DTRobBinsMap] FED: " << dduId << " ROS " << ros << " ROB: " << rob-1
125  << " not in the mapping!" << endl;
126  }
127  }
128  }
129  }
130  // loop over all chambers and remove the init flag
131  for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
132  chAndRobs != chamberMap.end(); ++chAndRobs) {
133  chAndRobs->second.init(false);
134  }
135  } //Legacy
136 }
137 
138 
140  edm::LuminosityBlock const & lumiSeg, edm::EventSetup const& context){
141 
142  //FR moved the following from beginJob!
143 
144  // book the summary histogram
145 
146  if (wheelHistos.empty()) { // this is an attempt to make these bookings only once!
147 
148  ibooker.setCurrentFolder("DT/00-ROChannels");
149  summaryHisto = ibooker.book2D("ROChannelSummary","Summary Blocked RO Channels",12,1,13,5,-2,3);
150  summaryHisto->setAxisTitle("Sector",1);
151  summaryHisto->setAxisTitle("Wheel",2);
152 
153  for(int wheel = -2; wheel != 3; ++wheel) {
154  stringstream namestream; namestream << "ROChannelSummary_W" << wheel;
155  stringstream titlestream; titlestream << "Blocked RO Channels (Wh " << wheel << ")";
156  wheelHistos[wheel] = ibooker.book2D(namestream.str().c_str(),titlestream.str().c_str(),12,1,13,4,1,5);
157  wheelHistos[wheel]->setAxisTitle("Sector",1);
158  wheelHistos[wheel]->setBinLabel(1,"MB1",2);
159  wheelHistos[wheel]->setBinLabel(2,"MB2",2);
160  wheelHistos[wheel]->setBinLabel(3,"MB3",2);
161  wheelHistos[wheel]->setBinLabel(4,"MB4",2);
162  }
163 
164  if(!offlineMode) {
165  hSystFractionVsLS = new DTTimeEvolutionHisto(ibooker, "EnabledROChannelsVsLS", "% RO channels",
166  500, 5, true, 3);
167  }
168  } // end attempt to make these bookings only once!
169 
170 
171  //FR moved here from beginRun
172 
173  if(checkUros){
174  if (chamberMapUros.empty()) fillChamberMap(igetter, context);
175  }
176  else{
177  if (chamberMap.empty()) fillChamberMap(igetter, context);
178  }
179 
180  //FR moved here from beginLuminosityBlock
181  run = lumiSeg.run();
182 
183  //FR moved here from endLuminosityBlock
184  // counts number of lumiSegs
185  nLumiSegs = lumiSeg.id().luminosityBlock();
186 
187  // prescale factor
188  if (nLumiSegs%prescaleFactor != 0 || offlineMode) return;
189 
190  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
191  <<"[DTBlockedROChannelsTest]: End of LS " << nLumiSegs << ". Client called in online mode, performing client operations";
192 
193  performClientDiagnostic(igetter);
194 
195  // counts number of updats
196  nupdates++;
197 
198 }
199 
201 
202  if (offlineMode) {
203  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
204  <<"[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
205  performClientDiagnostic(igetter);
206  }
207 }
208 
210 
211  //FR: I've commented the if below. Either in online mode or in offline mode, when the diagnostic is called
212  // compute first the number of events. It will be: event/lumisection in the online case, it will be: total number
213  // of events (neventsPrev=0) in the offline case, when the diagnostic is called only once from the dqmEndJob
214 
215  //if(nevents == 0) { // hack to work also in offline DQM
216  MonitorElement *procEvt = igetter.get("DT/EventInfo/processedEvents");
217  if(procEvt != nullptr) {
218  int procEvents = procEvt->getIntValue();
219  nevents = procEvents - neventsPrev;
220  neventsPrev = procEvents;
221  }
222  //}
223 
224  double totalPerc = prevTotalPerc;
225  // check again!
226  if(nevents != 0) { // skip the computation if no events in the last LS
227 
228  // reset the histos
229  summaryHisto->Reset();
230  for(int wheel = -2; wheel != 3; ++wheel) {
231  wheelHistos[wheel]->Reset();
232  }
233 
234  totalPerc = 0.;
235 
236  if (checkUros){
237  // loop over all chambers and fill the wheel plots
238  for(map<DTChamberId, DTLinkBinsMap>::iterator chAndLinks = chamberMapUros.begin();
239  chAndLinks != chamberMapUros.end(); ++chAndLinks) {
240  DTChamberId chId = (*chAndLinks).first;
241  double scale = 1.;
242  int sectorForPlot = chId.sector();
243  if(sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() ==4)) {
244  sectorForPlot = 4;
245  scale = 0.5;
246  } else if(sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() ==4)) {
247  sectorForPlot = 10;
248  scale = 0.5;
249  }
250 
251  // NOTE: can be called only ONCE per event per each chamber
252  double chPercent = (*chAndLinks).second.getChamberPercentage(igetter);
253  wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(),
254  scale*chPercent);
255  totalPerc += chPercent*scale*1./240.; // CB has to be 240 as double stations are taken into account by scale factor
256 
257  // Fill the summary
258  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25*scale*chPercent);
259  }
260  }//Uros case
261  else{ //Legacy case
262  // loop over all chambers and fill the wheel plots
263  for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
264  chAndRobs != chamberMap.end(); ++chAndRobs) {
265  DTChamberId chId = (*chAndRobs).first;
266  double scale = 1.;
267  int sectorForPlot = chId.sector();
268  if(sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() ==4)) {
269  sectorForPlot = 4;
270  scale = 0.5;
271  } else if(sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() ==4)) {
272  sectorForPlot = 10;
273  scale = 0.5;
274  }
275 
276  // NOTE: can be called only ONCE per event per each chamber
277  double chPercent = (*chAndRobs).second.getChamberPercentage(igetter);
278  wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(),
279  scale*chPercent);
280  totalPerc += chPercent*scale*1./240.; // CB has to be 240 as double stations are taken into account by scale factor
281 
282  // Fill the summary
283  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25*scale*chPercent);
284  }
285  } //Legacy case
286  } //nevents != 0
287 
288  if(!offlineMode) { // fill trend histo only in online
291  prevTotalPerc = totalPerc;
292  }
293 
294 }
295 
296 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int rob, int& wheel, int &station, int& sector){
297 
298  int dummy=0;
299  return mapping->readOutToGeometry(dduId,ros,rob,2,2,wheel,station,sector,dummy,dummy,dummy);
300 
301 }
302 
304  rosBin(ros),
305  init_(true),
306  rosValue(0)
307 {
308 
309  // get the pointer to the corresondig histo
310  // Legacy
311  stringstream mename; mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros
312  << "/FED" << fed << "_ROS" << ros << "_ROSError";
313  rosHName = mename.str();
314 
315  stringstream whname; whname << "DT/00-DataIntegrity/FED" << fed
316  << "/FED" << fed << "_ROSStatus";
317  dduHName = whname.str();
318 
319  meROS = igetter.get(rosHName);
320  meDDU = igetter.get(dduHName);
321 }
322 
324  meROS(nullptr),
325  meDDU(nullptr){}
326 
328 
329 
330 
331  // add a rob to the set of robs
333  robsAndValues[robBin] = getValueRobBin(robBin);
334  }
335 
336 
337 
338 
340  if (init_)
341  return 0;
342  int value = 0;
343  if(meROS) {
344  value += (int)meROS->getBinContent(9,robBin);
345  value += (int)meROS->getBinContent(11,robBin);
346  }
347  return value;
348  }
349 
350 
351 
353  int value = 0;
354  if(meDDU) {
355  value += (int)meDDU->getBinContent(2,rosBin);
356  value += (int)meDDU->getBinContent(10,rosBin);
357  }
358  return value;
359 }
360 
361 
363  // check that this is a valid ROB for this map (= it has been added!)
364  if(robsAndValues.find(robBin) == robsAndValues.end()) {
365  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
366  << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
367  return false;
368  }
369 
370  int newValue = getValueRobBin(robBin);
371  if(newValue > robsAndValues[robBin]) {
372  robsAndValues[robBin] = newValue;
373  return true;
374  }
375  return false;
376 }
377 
378 
380  meROS = igetter.get(rosHName);
381  meDDU = igetter.get(dduHName);
382  int nChangedROBs = 0;
383 
384  // check if ros status has changed
385  int newValue = getValueRos();
386  if(newValue > rosValue) {
387  rosValue= newValue;
388  return 0.;
389  }
390 
391  for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
392  robAndValue != robsAndValues.end(); ++robAndValue) {
393  if(robChanged((*robAndValue).first)) nChangedROBs++;
394  }
395  return 1.-((double)nChangedROBs/(double)robsAndValues.size());
396 }
397 
398 
400  meROS = igetter.get(rosHName);
401  meDDU = igetter.get(dduHName);
402 
403  rosValue = getValueRos();
404  for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
405  robAndValue != robsAndValues.end(); ++robAndValue) {
406  robChanged((*robAndValue).first);
407  }
408 }
409 
410 // uROS starting on 2018
412  init_(true)
413 {
414  int wheel = (ddu - 770)%5 - 2;
415 
416  // get the pointer to the corresondig histo
417  urosHName = "DT/00-DataIntegrity/Wheel" + to_string(wheel) + "/ROS" + to_string(ros)
418  + "/W" + to_string(wheel) + "_ROS" + to_string(ros) + "_ROSError";
419  meuROS = igetter.get(urosHName);
420 }
421 
423  meuROS(nullptr){}
424 
426 
428  linksAndValues[linkBin] = getValueLinkBin(linkBin);
429  }
430 
431 
433  if (!init_)
434  return 0;
435  int value = 0;
436  if(meuROS) {
437  value += (int)meuROS->getBinContent(5,linkBin); //ONLY NotOKFlag
438  }
439  return value;
440  }
441 
443  // check that this is a valid Link for this map (= it has been added!)
444  if(linksAndValues.find(linkBin) == linksAndValues.end()) {
445  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
446  << "[DTLinkBinsMap]***Error: Link: " << linkBin << " is not valid" << endl;
447  return false;
448  }
449 
450  int newValue = getValueLinkBin(linkBin);
451  if(newValue > linksAndValues[linkBin]) {
452  linksAndValues[linkBin] = newValue;
453  return true;
454  }
455  return false;
456 }
457 
458 
460  meuROS = igetter.get(urosHName);
461  int nChangedLinks = 0;
462 
463  for(map<int, int>::const_iterator linkAndValue = linksAndValues.begin();
464  linkAndValue != linksAndValues.end(); ++linkAndValue) {
465  if(linkChanged((*linkAndValue).first)) nChangedLinks++;
466  }
467  return 1.-((double)nChangedLinks/(double)linksAndValues.size());
468 }
469 
470 
472  meuROS = igetter.get(urosHName);
473 
474  for(map<int, int>::const_iterator linkAndValue = linksAndValues.begin();
475  linkAndValue != linksAndValues.end(); ++linkAndValue) {
476  linkChanged((*linkAndValue).first);
477  }
478 }
479 
480 
481 
482 // Conversions
483 int DTBlockedROChannelsTest::theDDU(int crate, int slot, int link, bool tenDDU) {
484 
485  int ros = theROS(slot,link);
486 
487  int ddu = 772;
488  //if (crate == 1368) { ddu = 775; }
489  //Needed just in case this FED should be used due to fibers lenght
490 
491  if (crate == FEDNumbering::MINDTUROSFEDID) {
492  if (slot < 7)
493  ddu = 770;
494  else
495  ddu = 771;
496  }
497 
498  if (crate == (FEDNumbering::MINDTUROSFEDID+1)) { ddu = 772; }
499 
500  if (crate == FEDNumbering::MAXDTUROSFEDID) {
501  if (slot < 7)
502  ddu = 773;
503  else
504  ddu = 774;
505  }
506 
507  if (ros > 6 && tenDDU && ddu < 775)
508  ddu += 5;
509 
510  return ddu;
511 }
512 
513 int DTBlockedROChannelsTest::theROS(int slot, int link) {
514 
515  if (slot%6 == 5) return link+1;
516 
517  int ros = (link/24) + 3*(slot%6) - 2;
518  return ros;
519 }
520 
521 
522 int DTBlockedROChannelsTest::theROB(int slot, int link) {
523 
524  if (slot%6 == 5) return 23;
525 
526  int rob = link%24;
527  if (rob < 15) return rob;
528  if (rob == 15) return 24;
529  return rob-1;
530 }
531 
532 
533 // FIXME: move to SealModule
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
int theROB(int slot, int link)
int64_t getIntValue() const
DTTimeEvolutionHisto * hSystFractionVsLS
void accumulateValueTimeSlot(float value)
std::map< DTChamberId, DTLinkBinsMap > chamberMapUros
std::map< int, MonitorElement * > wheelHistos
void performClientDiagnostic(DQMStore::IGetter &igetter)
DQM Client operations.
int readOutToGeometry(int dduId, int rosId, int robId, int tdcId, int channelId, DTWireId &wireId) const
transform identifiers
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
DQM Client Diagnostic in online mode.
std::map< DTChamberId, DTRobBinsMap > chamberMap
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
#define nullptr
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
int theROS(int slot, int link)
void fillChamberMap(DQMStore::IGetter &igetter, const edm::EventSetup &c)
void Fill(long long x)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
DTBlockedROChannelsTest(const edm::ParameterSet &ps)
Constructor.
void readNewValues(DQMStore::IGetter &igetter)
RunNumber_t run() const
Definition: value.py:1
void Reset()
reset ME (ie. contents, errors, etc)
edm::ESHandle< DTReadOutMapping > mapping
#define LogTrace(id)
MonitorElement * get(std::string const &path)
Definition: DQMStore.cc:303
void readNewValues(DQMStore::IGetter &igetter)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
LuminosityBlockNumber_t luminosityBlock() const
int theDDU(int crate, int slot, int link, bool tenDDU)
void updateTimeSlot(int ls, int nEventsInLS)
double getBinContent(int binx) const
get content of bin (1-D)
HLT enums.
int sector() const
Definition: DTChamberId.h:61
T get() const
Definition: EventSetup.h:71
int readOutToGeometry(int dduId, int rosNumber, int robNumber, int &wheel, int &station, int &sector)
double getChamberPercentage(DQMStore::IGetter &)
void beginRun(const edm::Run &, const edm::EventSetup &) override
BeginRun.
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
~DTBlockedROChannelsTest() override
Destructor.
double getChamberPercentage(DQMStore::IGetter &)
Definition: Run.h:45