File indexing completed on 2022-07-22 00:50:31
0001
0002
0003
0004
0005
0006
0007
0008 #include "DQM/DTMonitorClient/src/DTBlockedROChannelsTest.h"
0009
0010
0011 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0012 #include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
0013 #include "DQMServices/Core/interface/DQMStore.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
0017 #include <iostream>
0018 #include <string>
0019
0020 using namespace std;
0021 using namespace edm;
0022
0023 DTBlockedROChannelsTest::DTBlockedROChannelsTest(const ParameterSet& ps)
0024 : nevents(0),
0025 neventsPrev(0),
0026 prevNLumiSegs(0),
0027 prevTotalPerc(0),
0028 mappingToken_(esConsumes<edm::Transition::BeginRun>()),
0029 hSystFractionVsLS(nullptr) {
0030 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest") << "[DTBlockedROChannelsTest]: Constructor";
0031
0032
0033 prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
0034
0035 offlineMode = ps.getUntrackedParameter<bool>("offlineMode", true);
0036
0037 checkUros = ps.getUntrackedParameter<bool>("checkUros", true);
0038 }
0039
0040 DTBlockedROChannelsTest::~DTBlockedROChannelsTest() {
0041 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0042 << "DataIntegrityTest: analyzed " << nupdates << " updates";
0043 }
0044
0045 void DTBlockedROChannelsTest::beginRun(const Run& run, const EventSetup& setup) {
0046
0047 mapping = &setup.getData(mappingToken_);
0048 nupdates = 0;
0049 return;
0050 }
0051
0052 void DTBlockedROChannelsTest::fillChamberMap(DQMStore::IGetter& igetter, const EventSetup& context) {
0053 int dummy = 0;
0054 bool tenDDU = !mapping->readOutToGeometry(779, 7, 1, 1, 1, dummy, dummy, dummy, dummy, dummy, dummy);
0055
0056 if (checkUros) {
0057 for (int crate = FEDNumbering::MINDTUROSFEDID; crate <= FEDNumbering::MAXDTUROSFEDID; ++crate) {
0058 for (int mapSlot = 1; mapSlot != 13; ++mapSlot) {
0059 for (int link = 0; link != 72; ++link) {
0060
0061 if (mapSlot == 6)
0062 continue;
0063 if (crate == 1370 && mapSlot > 5)
0064 continue;
0065 if ((mapSlot == 5 || mapSlot == 11) && link > 11)
0066 continue;
0067
0068 int wheel = 0;
0069 int station = 0;
0070 int sector = 0;
0071
0072 int dduId = theDDU(crate, mapSlot, link, tenDDU);
0073 int ros = theROS(mapSlot, link);
0074 int rob = theROB(mapSlot, link);
0075
0076
0077 readOutToGeometry(dduId, ros, rob, wheel, station, sector);
0078 if (station > 0) {
0079
0080 DTChamberId chId(wheel, station, sector);
0081 if (chamberMapUros.find(chId) == chamberMapUros.end()) {
0082 chamberMapUros[chId] = DTLinkBinsMap(igetter, dduId, ros);
0083 chamberMapUros[chId].addLinkBin(link % 24);
0084 }
0085 chamberMapUros[chId].addLinkBin(link % 24);
0086 } else {
0087 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0088 << "[DTLinkBinsMap] FED: " << crate << "mapSlot: " << mapSlot << " Link: " << link
0089 << " not in the mapping!" << endl;
0090 }
0091 }
0092 }
0093 }
0094 }
0095 else {
0096
0097
0098 for (int dduId = FEDNumbering::MINDTFEDID; dduId <= FEDNumbering::MAXDTFEDID; ++dduId) {
0099 for (int ros = 1; ros != 13; ++ros) {
0100 for (int rob = 1; rob != 26; ++rob) {
0101 int wheel = 0;
0102 int station = 0;
0103 int sector = 0;
0104 if (!mapping->readOutToGeometry(dduId, ros, rob - 1, 0, 2, wheel, station, sector, dummy, dummy, dummy) ||
0105 !mapping->readOutToGeometry(dduId, ros, rob - 1, 0, 16, wheel, station, sector, dummy, dummy, dummy)) {
0106 DTChamberId chId(wheel, station, sector);
0107 if (chamberMap.find(chId) == chamberMap.end()) {
0108 chamberMap[chId] = DTRobBinsMap(igetter, dduId, ros);
0109 chamberMap[chId].addRobBin(rob);
0110 }
0111 chamberMap[chId].addRobBin(rob);
0112 } else {
0113 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0114 << "[DTRobBinsMap] FED: " << dduId << " ROS " << ros << " ROB: " << rob - 1 << " not in the mapping!"
0115 << endl;
0116 }
0117 }
0118 }
0119 }
0120
0121 for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
0122 ++chAndRobs) {
0123 chAndRobs->second.init(false);
0124 }
0125 }
0126 }
0127
0128 void DTBlockedROChannelsTest::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0129 DQMStore::IGetter& igetter,
0130 edm::LuminosityBlock const& lumiSeg,
0131 edm::EventSetup const& context) {
0132
0133
0134
0135
0136 if (wheelHistos.empty()) {
0137
0138 ibooker.setCurrentFolder("DT/00-ROChannels");
0139 summaryHisto = ibooker.book2D("ROChannelSummary", "Summary Blocked RO Channels", 12, 1, 13, 5, -2, 3);
0140 summaryHisto->setAxisTitle("Sector", 1);
0141 summaryHisto->setAxisTitle("Wheel", 2);
0142
0143 for (int wheel = -2; wheel != 3; ++wheel) {
0144 stringstream namestream;
0145 namestream << "ROChannelSummary_W" << wheel;
0146 stringstream titlestream;
0147 titlestream << "Blocked RO Channels (Wh " << wheel << ")";
0148 wheelHistos[wheel] = ibooker.book2D(namestream.str().c_str(), titlestream.str().c_str(), 12, 1, 13, 4, 1, 5);
0149 wheelHistos[wheel]->setAxisTitle("Sector", 1);
0150 wheelHistos[wheel]->setBinLabel(1, "MB1", 2);
0151 wheelHistos[wheel]->setBinLabel(2, "MB2", 2);
0152 wheelHistos[wheel]->setBinLabel(3, "MB3", 2);
0153 wheelHistos[wheel]->setBinLabel(4, "MB4", 2);
0154 }
0155
0156 if (!offlineMode) {
0157 hSystFractionVsLS = new DTTimeEvolutionHisto(ibooker, "EnabledROChannelsVsLS", "% RO channels", 500, 5, true, 3);
0158 }
0159 }
0160
0161
0162
0163 if (checkUros) {
0164 if (chamberMapUros.empty())
0165 fillChamberMap(igetter, context);
0166 } else {
0167 if (chamberMap.empty())
0168 fillChamberMap(igetter, context);
0169 }
0170
0171
0172 run = lumiSeg.run();
0173
0174
0175
0176 nLumiSegs = lumiSeg.id().luminosityBlock();
0177
0178
0179 if (nLumiSegs % prescaleFactor != 0 || offlineMode)
0180 return;
0181
0182 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0183 << "[DTBlockedROChannelsTest]: End of LS " << nLumiSegs
0184 << ". Client called in online mode, performing client operations";
0185
0186 performClientDiagnostic(igetter);
0187
0188
0189 nupdates++;
0190 }
0191
0192 void DTBlockedROChannelsTest::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0193 if (offlineMode) {
0194 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0195 << "[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
0196 performClientDiagnostic(igetter);
0197 }
0198 }
0199
0200 void DTBlockedROChannelsTest::performClientDiagnostic(DQMStore::IGetter& igetter) {
0201
0202
0203
0204
0205
0206 MonitorElement* procEvt = igetter.get("DT/EventInfo/processedEvents");
0207 if (procEvt != nullptr) {
0208 int procEvents = procEvt->getIntValue();
0209 nevents = procEvents - neventsPrev;
0210 neventsPrev = procEvents;
0211 }
0212
0213
0214 double totalPerc = prevTotalPerc;
0215
0216 if (nevents != 0) {
0217
0218
0219 summaryHisto->Reset();
0220 for (int wheel = -2; wheel != 3; ++wheel) {
0221 wheelHistos[wheel]->Reset();
0222 }
0223
0224 totalPerc = 0.;
0225
0226 if (checkUros) {
0227
0228 for (map<DTChamberId, DTLinkBinsMap>::iterator chAndLinks = chamberMapUros.begin();
0229 chAndLinks != chamberMapUros.end();
0230 ++chAndLinks) {
0231 DTChamberId chId = (*chAndLinks).first;
0232 double scale = 1.;
0233 int sectorForPlot = chId.sector();
0234 if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
0235 sectorForPlot = 4;
0236 scale = 0.5;
0237 } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
0238 sectorForPlot = 10;
0239 scale = 0.5;
0240 }
0241
0242
0243 double chPercent = (*chAndLinks).second.getChamberPercentage(igetter);
0244 wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
0245 totalPerc += chPercent * scale * 1. /
0246 240.;
0247
0248
0249 summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
0250 }
0251 }
0252 else {
0253
0254 for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
0255 ++chAndRobs) {
0256 DTChamberId chId = (*chAndRobs).first;
0257 double scale = 1.;
0258 int sectorForPlot = chId.sector();
0259 if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
0260 sectorForPlot = 4;
0261 scale = 0.5;
0262 } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
0263 sectorForPlot = 10;
0264 scale = 0.5;
0265 }
0266
0267
0268 double chPercent = (*chAndRobs).second.getChamberPercentage(igetter);
0269 wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
0270 totalPerc += chPercent * scale * 1. /
0271 240.;
0272
0273
0274 summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
0275 }
0276 }
0277 }
0278
0279 if (!offlineMode) {
0280 hSystFractionVsLS->accumulateValueTimeSlot(totalPerc);
0281 hSystFractionVsLS->updateTimeSlot(nLumiSegs, nevents);
0282 prevTotalPerc = totalPerc;
0283 }
0284 }
0285
0286 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int rob, int& wheel, int& station, int& sector) {
0287 int dummy = 0;
0288 return mapping->readOutToGeometry(dduId, ros, rob, 2, 2, wheel, station, sector, dummy, dummy, dummy);
0289 }
0290
0291 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap(DQMStore::IGetter& igetter, const int fed, const int ros)
0292 : rosBin(ros), init_(true), rosValue(0) {
0293
0294
0295 stringstream mename;
0296 mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros << "/FED" << fed << "_ROS" << ros << "_ROSError";
0297 rosHName = mename.str();
0298
0299 stringstream whname;
0300 whname << "DT/00-DataIntegrity/FED" << fed << "/FED" << fed << "_ROSStatus";
0301 dduHName = whname.str();
0302
0303 meROS = igetter.get(rosHName);
0304 meDDU = igetter.get(dduHName);
0305 }
0306
0307 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap() : init_(true), meROS(nullptr), meDDU(nullptr) {}
0308
0309 DTBlockedROChannelsTest::DTRobBinsMap::~DTRobBinsMap() {}
0310
0311
0312 void DTBlockedROChannelsTest::DTRobBinsMap::addRobBin(int robBin) { robsAndValues[robBin] = getValueRobBin(robBin); }
0313
0314 int DTBlockedROChannelsTest::DTRobBinsMap::getValueRobBin(int robBin) const {
0315 if (init_)
0316 return 0;
0317 int value = 0;
0318 if (meROS) {
0319 value += (int)meROS->getBinContent(9, robBin);
0320 value += (int)meROS->getBinContent(11, robBin);
0321 }
0322 return value;
0323 }
0324
0325 int DTBlockedROChannelsTest::DTRobBinsMap::getValueRos() const {
0326 int value = 0;
0327 if (meDDU) {
0328 value += (int)meDDU->getBinContent(2, rosBin);
0329 value += (int)meDDU->getBinContent(10, rosBin);
0330 }
0331 return value;
0332 }
0333
0334 bool DTBlockedROChannelsTest::DTRobBinsMap::robChanged(int robBin) {
0335
0336 if (robsAndValues.find(robBin) == robsAndValues.end()) {
0337 LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0338 << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
0339 return false;
0340 }
0341
0342 int newValue = getValueRobBin(robBin);
0343 if (newValue > robsAndValues[robBin]) {
0344 robsAndValues[robBin] = newValue;
0345 return true;
0346 }
0347 return false;
0348 }
0349
0350 double DTBlockedROChannelsTest::DTRobBinsMap::getChamberPercentage(DQMStore::IGetter& igetter) {
0351 meROS = igetter.get(rosHName);
0352 meDDU = igetter.get(dduHName);
0353 int nChangedROBs = 0;
0354
0355
0356 int newValue = getValueRos();
0357 if (newValue > rosValue) {
0358 rosValue = newValue;
0359 return 0.;
0360 }
0361
0362 for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
0363 ++robAndValue) {
0364 if (robChanged((*robAndValue).first))
0365 nChangedROBs++;
0366 }
0367 return 1. - ((double)nChangedROBs / (double)robsAndValues.size());
0368 }
0369
0370 void DTBlockedROChannelsTest::DTRobBinsMap::readNewValues(DQMStore::IGetter& igetter) {
0371 meROS = igetter.get(rosHName);
0372 meDDU = igetter.get(dduHName);
0373
0374 rosValue = getValueRos();
0375 for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
0376 ++robAndValue) {
0377 robChanged((*robAndValue).first);
0378 }
0379 }
0380
0381
0382 DTBlockedROChannelsTest::DTLinkBinsMap::DTLinkBinsMap(DQMStore::IGetter& igetter, const int ddu, const int ros)
0383 : init_(true) {
0384 int wheel = (ddu - 770) % 5 - 2;
0385
0386
0387 urosHName = "DT/00-DataIntegrity/Wheel" + to_string(wheel) + "/Sector" + to_string(ros) + "/W" + to_string(wheel) +
0388 "_Sector" + to_string(ros) + "_ROSError";
0389 meuROS = igetter.get(urosHName);
0390 }
0391
0392 DTBlockedROChannelsTest::DTLinkBinsMap::DTLinkBinsMap() : init_(false), meuROS(nullptr) {}
0393
0394 DTBlockedROChannelsTest::DTLinkBinsMap::~DTLinkBinsMap() {}
0395
0396 void DTBlockedROChannelsTest::DTLinkBinsMap::addLinkBin(int linkBin) {
0397 linksAndValues[linkBin] = getValueLinkBin(linkBin);
0398 }
0399
0400 int DTBlockedROChannelsTest::DTLinkBinsMap::getValueLinkBin(int linkBin) const {
0401 if (!init_)
0402 return 0;
0403 int value = 0;
0404 if (meuROS) {
0405 value += (int)meuROS->getBinContent(5, linkBin);
0406 }
0407 return value;
0408 }
0409
0410 bool DTBlockedROChannelsTest::DTLinkBinsMap::linkChanged(int linkBin) {
0411
0412 if (linksAndValues.find(linkBin) == linksAndValues.end()) {
0413 LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0414 << "[DTLinkBinsMap]***Error: Link: " << linkBin << " is not valid" << endl;
0415 return false;
0416 }
0417
0418 int newValue = getValueLinkBin(linkBin);
0419 if (newValue > linksAndValues[linkBin]) {
0420 linksAndValues[linkBin] = newValue;
0421 return true;
0422 }
0423 return false;
0424 }
0425
0426 double DTBlockedROChannelsTest::DTLinkBinsMap::getChamberPercentage(DQMStore::IGetter& igetter) {
0427 meuROS = igetter.get(urosHName);
0428 int nChangedLinks = 0;
0429
0430 for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
0431 ++linkAndValue) {
0432 if (linkChanged((*linkAndValue).first))
0433 nChangedLinks++;
0434 }
0435 return 1. - ((double)nChangedLinks / (double)linksAndValues.size());
0436 }
0437
0438 void DTBlockedROChannelsTest::DTLinkBinsMap::readNewValues(DQMStore::IGetter& igetter) {
0439 meuROS = igetter.get(urosHName);
0440
0441 for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
0442 ++linkAndValue) {
0443 linkChanged((*linkAndValue).first);
0444 }
0445 }
0446
0447
0448 int DTBlockedROChannelsTest::theDDU(int crate, int slot, int link, bool tenDDU) {
0449 int ros = theROS(slot, link);
0450
0451 int ddu = 772;
0452
0453
0454
0455 if (crate == FEDNumbering::MINDTUROSFEDID) {
0456 if (slot < 7)
0457 ddu = 770;
0458 else
0459 ddu = 771;
0460 }
0461
0462 if (crate == (FEDNumbering::MINDTUROSFEDID + 1)) {
0463 ddu = 772;
0464 }
0465
0466 if (crate == FEDNumbering::MAXDTUROSFEDID) {
0467 if (slot < 7)
0468 ddu = 773;
0469 else
0470 ddu = 774;
0471 }
0472
0473 if (ros > 6 && tenDDU && ddu < 775)
0474 ddu += 5;
0475
0476 return ddu;
0477 }
0478
0479 int DTBlockedROChannelsTest::theROS(int slot, int link) {
0480 if (slot % 6 == 5)
0481 return link + 1;
0482
0483 int ros = (link / 24) + 3 * (slot % 6) - 2;
0484 return ros;
0485 }
0486
0487 int DTBlockedROChannelsTest::theROB(int slot, int link) {
0488 if (slot % 6 == 5)
0489 return 23;
0490
0491 int rob = link % 24;
0492 if (rob < 15)
0493 return rob;
0494 if (rob == 15)
0495 return 24;
0496 return rob - 1;
0497 }
0498
0499
0500 #include "FWCore/Framework/interface/MakerMacros.h"
0501 DEFINE_FWK_MODULE(DTBlockedROChannelsTest);