CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQM/DTMonitorClient/src/DTBlockedROChannelsTest.cc

Go to the documentation of this file.
00001 
00002 /*
00003  * \file DTBlockedROChannelsTest.cc
00004  * 
00005  * $Date: 2012/03/13 09:00:51 $
00006  * $Revision: 1.14 $
00007  * \author G. Cerminara - University and INFN Torino
00008  *
00009  */
00010 
00011 #include <DQM/DTMonitorClient/src/DTBlockedROChannelsTest.h>
00012 
00013 //Framework
00014 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00015 #include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
00016 #include "CondFormats/DataRecord/interface/DTReadOutMappingRcd.h"
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
00022 #include <iostream>
00023 #include <string>
00024 
00025 
00026 using namespace std;
00027 using namespace edm;
00028 
00029 
00030 DTBlockedROChannelsTest::DTBlockedROChannelsTest(const ParameterSet& ps) : nevents(0),
00031   neventsPrev(0),
00032   prevNLumiSegs(0),
00033   prevTotalPerc(0),
00034   hSystFractionVsLS(0) 
00035 {
00036   LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00037     << "[DTBlockedROChannelsTest]: Constructor";
00038 
00039   // prescale on the # of LS to update the test
00040   prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
00041 
00042   offlineMode = ps.getUntrackedParameter<bool>("offlineMode", true);
00043 }
00044 
00045 
00046 
00047 DTBlockedROChannelsTest::~DTBlockedROChannelsTest() {
00048   LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00049     << "DataIntegrityTest: analyzed " << nupdates << " updates";
00050 }
00051 
00052 
00053 
00054 // book histos
00055 void DTBlockedROChannelsTest::beginJob() {
00056   LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00057     << "[DTBlockedROChannelsTest]: BeginJob";
00058 
00059   nupdates = 0;
00060   run=0;
00061 
00062   dbe = Service<DQMStore>().operator->();
00063 
00064   // book the summary histogram
00065   dbe->setCurrentFolder("DT/00-ROChannels");
00066   summaryHisto = dbe->book2D("ROChannelSummary","Summary Blocked RO Channels",12,1,13,5,-2,3);
00067   summaryHisto->setAxisTitle("Sector",1);
00068   summaryHisto->setAxisTitle("Wheel",2);
00069 
00070   for(int wheel = -2; wheel != 3; ++wheel) {
00071     stringstream namestream;  namestream << "ROChannelSummary_W" << wheel;
00072     stringstream titlestream; titlestream << "Blocked RO Channels (Wh " << wheel << ")";
00073     wheelHitos[wheel] = dbe->book2D(namestream.str().c_str(),titlestream.str().c_str(),12,1,13,4,1,5);
00074     wheelHitos[wheel]->setAxisTitle("Sector",1);
00075     wheelHitos[wheel]->setBinLabel(1,"MB1",2);
00076     wheelHitos[wheel]->setBinLabel(2,"MB2",2);
00077     wheelHitos[wheel]->setBinLabel(3,"MB3",2);
00078     wheelHitos[wheel]->setBinLabel(4,"MB4",2);
00079   }
00080 
00081   if(!offlineMode) {
00082     hSystFractionVsLS = new DTTimeEvolutionHisto(dbe, "EnabledROChannelsVsLS", "% RO channels",
00083         500, 5, true, 3);
00084   }
00085 
00086 }
00087 
00088 
00089 
00090 
00091 void DTBlockedROChannelsTest::beginRun(const Run& run, const EventSetup& context) {
00092   // get the RO mapping
00093   context.get<DTReadOutMappingRcd>().get(mapping);
00094 
00095   // fill the map of the robs per chamber
00096   for(int dduId = FEDNumbering::MINDTFEDID; dduId<=FEDNumbering::MAXDTFEDID; ++dduId) { //loop over DDUs
00097     for(int ros = 1; ros != 13; ++ros) { // loop over ROSs
00098       for(int rob = 1; rob != 26; ++rob) { // loop over ROBs    
00099         int wheel = 0;
00100         int station = 0;
00101         int sector = 0;
00102         int dummy = 0;
00103         if(!mapping->readOutToGeometry(dduId,ros,rob-1,0,2,wheel,station,sector,dummy,dummy,dummy) ||
00104             !mapping->readOutToGeometry(dduId,ros,rob-1,0,16,wheel,station,sector,dummy,dummy,dummy)) {
00105           DTChamberId chId(wheel, station, sector);
00106           if(chamberMap.find(chId) == chamberMap.end()) {
00107             chamberMap[chId] = DTRobBinsMap(dduId, ros, dbe);
00108             chamberMap[chId].addRobBin(rob);
00109           } 
00110           chamberMap[chId].addRobBin(rob);
00111         } else {
00112           LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00113             << "[DTRobBinsMap] FED: " << dduId << " ROS " << ros << " ROB: " << rob-1
00114             << " not in the mapping!" << endl;
00115         }
00116       }
00117     }
00118   }
00119   // loop over all chambers and remove the init flag
00120   for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
00121       chAndRobs != chamberMap.end(); ++chAndRobs) {
00122     chAndRobs->second.init(false);
00123   }
00124 }
00125 
00126 
00127 
00128 void DTBlockedROChannelsTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg,
00129     EventSetup const& context) {
00130   LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00131     <<"[DTBlockedROChannelsTest]: Begin of LS transition";
00132 
00133   // Get the run number
00134   run = lumiSeg.run();
00135   nevents = 0;
00136 
00137   //   // loop over all chambers and read the values at the beginning of the LS
00138   //   for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
00139   //       chAndRobs != chamberMap.end(); ++chAndRobs) {
00140   //     (*chAndRobs).second.readNewValues(); 
00141   //   }
00142 
00143 }
00144 
00145 
00146 
00147 void DTBlockedROChannelsTest::analyze(const Event& e, const EventSetup& context){
00148   // count the analyzed events
00149   nevents++;
00150   if(nevents%1000 == 0)
00151     LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00152       << "[DTBlockedROChannelsTest]: "<<nevents<<" events";
00153 }
00154 
00155 
00156 
00157 void DTBlockedROChannelsTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00158 
00159   // counts number of lumiSegs 
00160   nLumiSegs = lumiSeg.id().luminosityBlock();
00161 
00162   // prescale factor
00163   if (nLumiSegs%prescaleFactor != 0 || offlineMode) return;
00164 
00165   LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00166     <<"[DTBlockedROChannelsTest]: End of LS " << nLumiSegs << ". Client called in online mode, performing client operations";
00167   performClientDiagnostic();
00168 
00169   // counts number of updats 
00170   nupdates++;
00171 
00172 }
00173 
00174 
00175 void DTBlockedROChannelsTest::performClientDiagnostic() {
00176 
00177   // skip empty LSs
00178 
00179   if(nevents == 0) { // hack to work also in offline DQM
00180     MonitorElement *procEvt =  dbe->get("DT/EventInfo/processedEvents");
00181     if(procEvt != 0) {
00182       int procEvents = procEvt->getIntValue();
00183       nevents = procEvents - neventsPrev;
00184       neventsPrev = procEvents;
00185     }
00186   }
00187 
00188   double totalPerc = prevTotalPerc;
00189   // check again!
00190   if(nevents != 0) { // skip the computation if no events in the last LS
00191 
00192     // reset the histos
00193     summaryHisto->Reset();
00194     for(int wheel = -2; wheel != 3; ++wheel) {
00195       wheelHitos[wheel]->Reset();
00196     }
00197 
00198     totalPerc = 0.;
00199 
00200     // loop over all chambers and fill the wheel plots
00201     for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
00202         chAndRobs != chamberMap.end(); ++chAndRobs) {
00203       DTChamberId chId = (*chAndRobs).first;
00204       double scale = 1.;
00205       int sectorForPlot = chId.sector();
00206       if(sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() ==4)) {
00207         sectorForPlot = 4;
00208         scale = 0.5;
00209       } else if(sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() ==4)) {
00210         sectorForPlot = 10;
00211         scale = 0.5;
00212       }
00213 
00214       // NOTE: can be called only ONCE per event per each chamber
00215       double chPercent = (*chAndRobs).second.getChamberPercentage(); 
00216       wheelHitos[chId.wheel()]->Fill(sectorForPlot, chId.station(),
00217           scale*chPercent);
00218       totalPerc += chPercent*scale*1./240.; // CB has to be 240 as double stations are taken into account by scale factor
00219       //       if(chPercent != 1.) {
00220       //        cout << "Ch: " << (*chAndRobs).first << endl;
00221       //        cout << "      perc: " << chPercent << endl;
00222       //       }
00223       // Fill the summary
00224       summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25*scale*chPercent);
00225     }
00226   }
00227 
00228   // commented out since trend plots need to be updated in by lumi certification  
00229   //   // this part is executed even if no events were processed in order to include the last LS 
00230   //   if(offlineMode) { // save the results in a map and draw them in the end-run
00231   //     if(resultsPerLumi.size() == 0) { // the first 2 LS are analyzed together
00232   // //       cout << "LS: " << nLumiSegs << " total %: " << totalPerc << endl;
00233   //       resultsPerLumi[nLumiSegs] = totalPerc;
00234   //     } else {
00235   // //       cout << "LS: " << nLumiSegs << " total %: " << prevTotalPerc << endl;
00236   //       resultsPerLumi[nLumiSegs] = prevTotalPerc;
00237   //     }
00238   //     prevTotalPerc = totalPerc;
00239   //     prevNLumiSegs = nLumiSegs;
00240 
00241   //   } else { // directly fill the histo
00242   //     hSystFractionVsLS->accumulateValueTimeSlot(totalPerc);
00243   //     hSystFractionVsLS->updateTimeSlot(nLumiSegs, nevents);
00244   //     prevTotalPerc = totalPerc;
00245   //   }
00246 
00247   if(!offlineMode) { // fill trend histo only in online
00248     hSystFractionVsLS->accumulateValueTimeSlot(totalPerc);
00249     hSystFractionVsLS->updateTimeSlot(nLumiSegs, nevents);
00250     prevTotalPerc = totalPerc;
00251   }
00252 
00253 }
00254 
00255 
00256 
00257 void DTBlockedROChannelsTest::endJob(){
00258   LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00259     <<"[DTBlockedROChannelsTest] endjob called!";
00260 }
00261 
00262 
00263 
00264 
00265 void DTBlockedROChannelsTest::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00266 
00267   if (offlineMode) {
00268     LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00269       <<"[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
00270     performClientDiagnostic();
00271   }
00272   // commented out since trend plots need to be updated in by lumi certification  
00273   //   if(offlineMode) {
00274   //     // fill a trend plot based on the results stored in the map
00275   //     float fBin = resultsPerLumi.begin()->first;
00276   //     float lBin = resultsPerLumi.rbegin()->first;
00277   //     dbe->setCurrentFolder("DT/00-ROChannels");
00278 
00279   //     //   MonitorElement* hSystFractionVsLS =  dbe->book1D("EnabledROChannelsVsLS", "% RO channels vs LS", nBins,fBin,lBin);
00280   //     hSystFractionVsLS = new DTTimeEvolutionHisto(dbe, "EnabledROChannelsVsLS", "% RO channels",
00281   //                                             (int)lBin-(int)fBin, fBin, 1, false, 2);
00282 
00283   //     for(map<int, double>::const_iterator bin = resultsPerLumi.begin();
00284   //    bin != resultsPerLumi.end(); ++bin) {
00285   //       hSystFractionVsLS->setTimeSlotValue((*bin).second, (*bin).first);
00286   //     }
00287   //   }
00288 }
00289 
00290 
00291 
00292 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int& wheel, int& sector){
00293 
00294   int dummy;
00295   return mapping->readOutToGeometry(dduId,ros,2,2,2,wheel,dummy,sector,dummy,dummy,dummy);
00296 
00297 }
00298 
00299 
00300 
00301 
00302 
00303 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap(const int fed, const int ros, const DQMStore* dbe) : rosBin(ros),
00304   init_(true),
00305   rosValue(0)
00306 {
00307 
00308   // get the pointer to the corresondig histo
00309   stringstream mename; mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros
00310     << "/FED" << fed << "_ROS" << ros << "_ROSError";
00311   rosHName = mename.str();
00312 
00313   stringstream whname; whname << "DT/00-DataIntegrity/FED" << fed
00314     << "/FED" << fed << "_ROSStatus";
00315   dduHName = whname.str();
00316 
00317   meROS = dbe->get(rosHName);
00318   meDDU = dbe->get(dduHName);
00319 
00320   theDbe = dbe;
00321 }
00322 
00323 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap() : init_(true),
00324   meROS(0),
00325   meDDU(0){}
00326 
00327   DTBlockedROChannelsTest::DTRobBinsMap::~DTRobBinsMap() {}
00328 
00329 
00330 
00331   // add a rob to the set of robs
00332   void DTBlockedROChannelsTest::DTRobBinsMap::addRobBin(int robBin) {
00333     robsAndValues[robBin] = getValueRobBin(robBin);
00334   }
00335 
00336 
00337 
00338 
00339   int DTBlockedROChannelsTest::DTRobBinsMap::getValueRobBin(int robBin) const {
00340     if (init_)
00341       return 0;
00342     int value = 0;
00343     if(meROS) {
00344       value += (int)meROS->getBinContent(9,robBin);
00345       value += (int)meROS->getBinContent(11,robBin);
00346     }
00347     return value;
00348   }
00349 
00350 
00351 
00352 
00353 int DTBlockedROChannelsTest::DTRobBinsMap::getValueRos() const {
00354   int value = 0;
00355   if(meDDU) {
00356     value += (int)meDDU->getBinContent(2,rosBin);
00357     value += (int)meDDU->getBinContent(10,rosBin);
00358   }
00359   return value;
00360 }
00361 
00362 
00363 
00364 
00365 bool DTBlockedROChannelsTest::DTRobBinsMap::robChanged(int robBin) {
00366   // check that this is a valid ROB for this map (= it has been added!)
00367   if(robsAndValues.find(robBin) == robsAndValues.end()) {
00368     LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
00369       << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
00370     return false;
00371   }
00372 
00373   int newValue = getValueRobBin(robBin);
00374   if(newValue > robsAndValues[robBin]) {
00375     robsAndValues[robBin] = newValue;
00376     return true;
00377   }
00378   return false;
00379 }
00380 
00381 
00382 
00383 
00384 double DTBlockedROChannelsTest::DTRobBinsMap::getChamberPercentage() {
00385   meROS = theDbe->get(rosHName);
00386   meDDU = theDbe->get(dduHName);
00387   int nChangedROBs = 0;
00388 
00389   // check if ros status has changed
00390   int newValue = getValueRos();
00391   if(newValue > rosValue) {
00392     rosValue= newValue;
00393     return 0.;
00394   }
00395 
00396   for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
00397       robAndValue != robsAndValues.end(); ++robAndValue) {
00398     if(robChanged((*robAndValue).first)) nChangedROBs++;
00399   }
00400   return 1.-((double)nChangedROBs/(double)robsAndValues.size());
00401 }
00402 
00403 
00404 void DTBlockedROChannelsTest::DTRobBinsMap::readNewValues() {
00405   meROS = theDbe->get(rosHName);
00406   meDDU = theDbe->get(dduHName);
00407 
00408   rosValue = getValueRos();
00409   for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
00410       robAndValue != robsAndValues.end(); ++robAndValue) {
00411     robChanged((*robAndValue).first);
00412   }
00413 }
00414 
00415 
00416 
00417 
00418 // FIXME: move to SealModule
00419 #include "FWCore/Framework/interface/MakerMacros.h"
00420 DEFINE_FWK_MODULE(DTBlockedROChannelsTest);