Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-03 04:09:55

0001 /*
0002  * \file DTBlockedROChannelsTest.cc
0003  * 
0004  * \author G. Cerminara - University and INFN Torino
0005  *
0006  */
0007 
0008 #include "DQM/DTMonitorClient/src/DTBlockedROChannelsTest.h"
0009 
0010 //Framework
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   // prescale on the # of LS to update the test
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   // get the RO mapping
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) {  //loop over FEDs
0058       for (int mapSlot = 1; mapSlot != 13; ++mapSlot) {  //loop over mapSlot
0059         for (int link = 0; link != 72; ++link) {         //loop over links
0060                                                          //skip non existing links
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           //          mapping->readOutToGeometry(dduId,ros,rob,2,2,wheel,station,sector,dummy,dummy,dummy);
0077           readOutToGeometry(dduId, ros, rob, wheel, station, sector);
0078           if (station > 0) {
0079             //std::cout<<" FED "<<crate<<" mapSlot "<< mapSlot<<" Link "<<link<<" Wh "<<wheel<<" station "<<station<<" sector "<<sector <<endl;
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         }  //loop on links
0092       }    //loop on mapSlots
0093     }      //loop on crates
0094   }        //checkUros
0095   else {
0096     // fill the map of the robs per chamber
0097     // //FIXME: monitoring only real used FEDs
0098     for (int dduId = FEDNumbering::MINDTFEDID; dduId <= FEDNumbering::MAXDTFEDID; ++dduId) {  //loop over DDUs
0099       for (int ros = 1; ros != 13; ++ros) {                                                   // loop over ROSs
0100         for (int rob = 1; rob != 26; ++rob) {                                                 // loop over ROBs
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     // loop over all chambers and remove the init flag
0121     for (map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin(); chAndRobs != chamberMap.end();
0122          ++chAndRobs) {
0123       chAndRobs->second.init(false);
0124     }
0125   }  //Legacy
0126 }
0127 
0128 void DTBlockedROChannelsTest::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0129                                                     DQMStore::IGetter& igetter,
0130                                                     edm::LuminosityBlock const& lumiSeg,
0131                                                     edm::EventSetup const& context) {
0132   //FR moved the following from beginJob!
0133 
0134   // book the summary histogram
0135 
0136   if (wheelHistos.empty()) {  // this is an attempt to make these bookings only once!
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   }  // end attempt to make these bookings only once!
0161 
0162   //FR moved here from beginRun
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   //FR moved here from beginLuminosityBlock
0173   run = lumiSeg.run();
0174 
0175   //FR moved here from endLuminosityBlock
0176   // counts number of lumiSegs
0177   nLumiSegs = lumiSeg.id().luminosityBlock();
0178 
0179   // prescale factor
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   // counts number of updats
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   //FR: I've commented the if below. Either in online mode or in offline mode, when the diagnostic is called
0203   // compute first the number of events. It will be: event/lumisection in the online case, it will be: total number
0204   // of events (neventsPrev=0) in the offline case, when the diagnostic is called only once from the dqmEndJob
0205 
0206   //if(nevents == 0) { // hack to work also in offline DQM
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   // check again!
0217   if (nevents != 0) {  // skip the computation if no events in the last LS
0218 
0219     // reset the histos
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       // loop over all chambers and fill the wheel plots
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         // NOTE: can be called only ONCE per event per each chamber
0244         double chPercent = (*chAndLinks).second.getChamberPercentage(igetter);
0245         wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
0246         totalPerc += chPercent * scale * 1. /
0247                      240.;  // CB has to be 240 as double stations are taken into account by scale factor
0248 
0249         // Fill the summary
0250         summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
0251       }
0252     }       //Uros case
0253     else {  //Legacy case
0254       // loop over all chambers and fill the wheel plots
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         // NOTE: can be called only ONCE per event per each chamber
0269         double chPercent = (*chAndRobs).second.getChamberPercentage(igetter);
0270         wheelHistos[chId.wheel()]->Fill(sectorForPlot, chId.station(), scale * chPercent);
0271         totalPerc += chPercent * scale * 1. /
0272                      240.;  // CB has to be 240 as double stations are taken into account by scale factor
0273 
0274         // Fill the summary
0275         summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25 * scale * chPercent);
0276       }
0277     }  //Legacy case
0278   }    //nevents != 0
0279 
0280   if (!offlineMode) {  // fill trend histo only in online
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   // get the pointer to the corresondig histo
0295   // Legacy
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 // add a rob to the set of robs
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   // check that this is a valid ROB for this map (= it has been added!)
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   // check if ros status has changed
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 // uROS starting on 2018
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   // get the pointer to the corresondig histo
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);  //ONLY NotOKFlag
0407   }
0408   return value;
0409 }
0410 
0411 bool DTBlockedROChannelsTest::DTLinkBinsMap::linkChanged(int linkBin) {
0412   // check that this is a valid Link for this map (= it has been added!)
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 // Conversions
0449 int DTBlockedROChannelsTest::theDDU(int crate, int slot, int link, bool tenDDU) {
0450   int ros = theROS(slot, link);
0451 
0452   int ddu = 772;
0453   //if (crate == 1368) { ddu = 775; }
0454   //Needed just in case this FED should be used due to fibers lenght
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 // FIXME: move to SealModule
0501 #include "FWCore/Framework/interface/MakerMacros.h"
0502 DEFINE_FWK_MODULE(DTBlockedROChannelsTest);