CMS 3D CMS Logo

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

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