File indexing completed on 2024-09-11 04:32:26
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 =
0158 new DTTimeEvolutionHisto(ibooker, "EnabledROChannelsVsLS", "Fraction of RO channels", 500, 5, true, 3);
0159 }
0160 }
0161
0162
0163
0164 if (checkUros) {
0165 if (chamberMapUros.empty())
0166 fillChamberMap(igetter, context);
0167 } else {
0168 if (chamberMap.empty())
0169 fillChamberMap(igetter, context);
0170 }
0171
0172
0173 run = lumiSeg.run();
0174
0175
0176
0177 nLumiSegs = lumiSeg.id().luminosityBlock();
0178
0179
0180 if (nLumiSegs % prescaleFactor != 0 || offlineMode)
0181 return;
0182
0183 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0184 << "[DTBlockedROChannelsTest]: End of LS " << nLumiSegs
0185 << ". Client called in online mode, performing client operations";
0186
0187 performClientDiagnostic(igetter);
0188
0189
0190 nupdates++;
0191 }
0192
0193 void DTBlockedROChannelsTest::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0194 if (offlineMode) {
0195 LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0196 << "[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
0197 performClientDiagnostic(igetter);
0198 }
0199 }
0200
0201 void DTBlockedROChannelsTest::performClientDiagnostic(DQMStore::IGetter& igetter) {
0202
0203
0204
0205
0206
0207 MonitorElement* procEvt = igetter.get("DT/EventInfo/processedEvents");
0208 if (procEvt != nullptr) {
0209 int procEvents = procEvt->getIntValue();
0210 nevents = procEvents - neventsPrev;
0211 neventsPrev = procEvents;
0212 }
0213
0214
0215 double totalPerc = prevTotalPerc;
0216
0217 if (nevents != 0) {
0218
0219
0220 summaryHisto->Reset();
0221 for (int wheel = -2; wheel != 3; ++wheel) {
0222 wheelHistos[wheel]->Reset();
0223 }
0224
0225 totalPerc = 0.;
0226
0227 if (checkUros) {
0228
0229 for (map<DTChamberId, DTLinkBinsMap>::iterator chAndLinks = chamberMapUros.begin();
0230 chAndLinks != chamberMapUros.end();
0231 ++chAndLinks) {
0232 DTChamberId chId = (*chAndLinks).first;
0233 double scale = 1.;
0234 int sectorForPlot = chId.sector();
0235 if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
0236 sectorForPlot = 4;
0237 scale = 0.5;
0238 } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
0239 sectorForPlot = 10;
0240 scale = 0.5;
0241 }
0242
0243
0244 double chPercent = (*chAndLinks).second.getChamberPercentage(igetter);
0245 wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
0246 totalPerc += chPercent * scale * 1. /
0247 240.;
0248
0249
0250 summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
0251 }
0252 }
0253 else {
0254
0255 for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
0256 ++chAndRobs) {
0257 DTChamberId chId = (*chAndRobs).first;
0258 double scale = 1.;
0259 int sectorForPlot = chId.sector();
0260 if (sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() == 4)) {
0261 sectorForPlot = 4;
0262 scale = 0.5;
0263 } else if (sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() == 4)) {
0264 sectorForPlot = 10;
0265 scale = 0.5;
0266 }
0267
0268
0269 double chPercent = (*chAndRobs).second.getChamberPercentage(igetter);
0270 wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
0271 totalPerc += chPercent * scale * 1. /
0272 240.;
0273
0274
0275 summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
0276 }
0277 }
0278 }
0279
0280 if (!offlineMode) {
0281 hSystFractionVsLS->accumulateValueTimeSlot(totalPerc);
0282 hSystFractionVsLS->updateTimeSlot(nLumiSegs, nevents);
0283 prevTotalPerc = totalPerc;
0284 }
0285 }
0286
0287 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int rob, int& wheel, int& station, int& sector) {
0288 int dummy = 0;
0289 return mapping->readOutToGeometry(dduId, ros, rob, 2, 2, wheel, station, sector, dummy, dummy, dummy);
0290 }
0291
0292 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap(DQMStore::IGetter& igetter, const int fed, const int ros)
0293 : rosBin(ros), init_(true), rosValue(0) {
0294
0295
0296 stringstream mename;
0297 mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros << "/FED" << fed << "_ROS" << ros << "_ROSError";
0298 rosHName = mename.str();
0299
0300 stringstream whname;
0301 whname << "DT/00-DataIntegrity/FED" << fed << "/FED" << fed << "_ROSStatus";
0302 dduHName = whname.str();
0303
0304 meROS = igetter.get(rosHName);
0305 meDDU = igetter.get(dduHName);
0306 }
0307
0308 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap() : init_(true), meROS(nullptr), meDDU(nullptr) {}
0309
0310 DTBlockedROChannelsTest::DTRobBinsMap::~DTRobBinsMap() {}
0311
0312
0313 void DTBlockedROChannelsTest::DTRobBinsMap::addRobBin(int robBin) { robsAndValues[robBin] = getValueRobBin(robBin); }
0314
0315 int DTBlockedROChannelsTest::DTRobBinsMap::getValueRobBin(int robBin) const {
0316 if (init_)
0317 return 0;
0318 int value = 0;
0319 if (meROS) {
0320 value += (int)meROS->getBinContent(9, robBin);
0321 value += (int)meROS->getBinContent(11, robBin);
0322 }
0323 return value;
0324 }
0325
0326 int DTBlockedROChannelsTest::DTRobBinsMap::getValueRos() const {
0327 int value = 0;
0328 if (meDDU) {
0329 value += (int)meDDU->getBinContent(2, rosBin);
0330 value += (int)meDDU->getBinContent(10, rosBin);
0331 }
0332 return value;
0333 }
0334
0335 bool DTBlockedROChannelsTest::DTRobBinsMap::robChanged(int robBin) {
0336
0337 if (robsAndValues.find(robBin) == robsAndValues.end()) {
0338 LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0339 << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
0340 return false;
0341 }
0342
0343 int newValue = getValueRobBin(robBin);
0344 if (newValue > robsAndValues[robBin]) {
0345 robsAndValues[robBin] = newValue;
0346 return true;
0347 }
0348 return false;
0349 }
0350
0351 double DTBlockedROChannelsTest::DTRobBinsMap::getChamberPercentage(DQMStore::IGetter& igetter) {
0352 meROS = igetter.get(rosHName);
0353 meDDU = igetter.get(dduHName);
0354 int nChangedROBs = 0;
0355
0356
0357 int newValue = getValueRos();
0358 if (newValue > rosValue) {
0359 rosValue = newValue;
0360 return 0.;
0361 }
0362
0363 for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
0364 ++robAndValue) {
0365 if (robChanged((*robAndValue).first))
0366 nChangedROBs++;
0367 }
0368 return 1. - ((double)nChangedROBs / (double)robsAndValues.size());
0369 }
0370
0371 void DTBlockedROChannelsTest::DTRobBinsMap::readNewValues(DQMStore::IGetter& igetter) {
0372 meROS = igetter.get(rosHName);
0373 meDDU = igetter.get(dduHName);
0374
0375 rosValue = getValueRos();
0376 for (map<int, int>::const_iterator robAndValue = robsAndValues.begin(); robAndValue != robsAndValues.end();
0377 ++robAndValue) {
0378 robChanged((*robAndValue).first);
0379 }
0380 }
0381
0382
0383 DTBlockedROChannelsTest::DTLinkBinsMap::DTLinkBinsMap(DQMStore::IGetter& igetter, const int ddu, const int ros)
0384 : init_(true) {
0385 int wheel = (ddu - 770) % 5 - 2;
0386
0387
0388 urosHName = "DT/00-DataIntegrity/Wheel" + to_string(wheel) + "/Sector" + to_string(ros) + "/W" + to_string(wheel) +
0389 "_Sector" + to_string(ros) + "_ROSError";
0390 meuROS = igetter.get(urosHName);
0391 }
0392
0393 DTBlockedROChannelsTest::DTLinkBinsMap::DTLinkBinsMap() : init_(false), meuROS(nullptr) {}
0394
0395 DTBlockedROChannelsTest::DTLinkBinsMap::~DTLinkBinsMap() {}
0396
0397 void DTBlockedROChannelsTest::DTLinkBinsMap::addLinkBin(int linkBin) {
0398 linksAndValues[linkBin] = getValueLinkBin(linkBin);
0399 }
0400
0401 int DTBlockedROChannelsTest::DTLinkBinsMap::getValueLinkBin(int linkBin) const {
0402 if (!init_)
0403 return 0;
0404 int value = 0;
0405 if (meuROS) {
0406 value += (int)meuROS->getBinContent(5, linkBin);
0407 }
0408 return value;
0409 }
0410
0411 bool DTBlockedROChannelsTest::DTLinkBinsMap::linkChanged(int linkBin) {
0412
0413 if (linksAndValues.find(linkBin) == linksAndValues.end()) {
0414 LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
0415 << "[DTLinkBinsMap]***Error: Link: " << linkBin << " is not valid" << endl;
0416 return false;
0417 }
0418
0419 int newValue = getValueLinkBin(linkBin);
0420 if (newValue > linksAndValues[linkBin]) {
0421 linksAndValues[linkBin] = newValue;
0422 return true;
0423 }
0424 return false;
0425 }
0426
0427 double DTBlockedROChannelsTest::DTLinkBinsMap::getChamberPercentage(DQMStore::IGetter& igetter) {
0428 meuROS = igetter.get(urosHName);
0429 int nChangedLinks = 0;
0430
0431 for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
0432 ++linkAndValue) {
0433 if (linkChanged((*linkAndValue).first))
0434 nChangedLinks++;
0435 }
0436 return 1. - ((double)nChangedLinks / (double)linksAndValues.size());
0437 }
0438
0439 void DTBlockedROChannelsTest::DTLinkBinsMap::readNewValues(DQMStore::IGetter& igetter) {
0440 meuROS = igetter.get(urosHName);
0441
0442 for (map<int, int>::const_iterator linkAndValue = linksAndValues.begin(); linkAndValue != linksAndValues.end();
0443 ++linkAndValue) {
0444 linkChanged((*linkAndValue).first);
0445 }
0446 }
0447
0448
0449 int DTBlockedROChannelsTest::theDDU(int crate, int slot, int link, bool tenDDU) {
0450 int ros = theROS(slot, link);
0451
0452 int ddu = 772;
0453
0454
0455
0456 if (crate == FEDNumbering::MINDTUROSFEDID) {
0457 if (slot < 7)
0458 ddu = 770;
0459 else
0460 ddu = 771;
0461 }
0462
0463 if (crate == (FEDNumbering::MINDTUROSFEDID + 1)) {
0464 ddu = 772;
0465 }
0466
0467 if (crate == FEDNumbering::MAXDTUROSFEDID) {
0468 if (slot < 7)
0469 ddu = 773;
0470 else
0471 ddu = 774;
0472 }
0473
0474 if (ros > 6 && tenDDU && ddu < 775)
0475 ddu += 5;
0476
0477 return ddu;
0478 }
0479
0480 int DTBlockedROChannelsTest::theROS(int slot, int link) {
0481 if (slot % 6 == 5)
0482 return link + 1;
0483
0484 int ros = (link / 24) + 3 * (slot % 6) - 2;
0485 return ros;
0486 }
0487
0488 int DTBlockedROChannelsTest::theROB(int slot, int link) {
0489 if (slot % 6 == 5)
0490 return 23;
0491
0492 int rob = link % 24;
0493 if (rob < 15)
0494 return rob;
0495 if (rob == 15)
0496 return 24;
0497 return rob - 1;
0498 }
0499
0500
0501 #include "FWCore/Framework/interface/MakerMacros.h"
0502 DEFINE_FWK_MODULE(DTBlockedROChannelsTest);