CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQM/SiStripMonitorPedestals/src/SiStripMonitorQuality.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripMonitorQuality
00004 // Class:      SiStripMonitorQuality
00005 // 
00013 //
00014 // Original Author:  Suchandra Dutta
00015 //         Created:  Fri Dec  7 20:50 CET 2007
00016 // $Id: SiStripMonitorQuality.cc,v 1.6 2012/01/08 09:13:38 eulisse Exp $
00017 //
00018 //
00019 
00020 #include "FWCore/ServiceRegistry/interface/Service.h"
00021 
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 #include "DQMServices/Core/interface/MonitorElement.h"
00024 
00025 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00026 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00027 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00028 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00029 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00030 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00031 
00032 
00033 #include <FWCore/Framework/interface/EventSetup.h>
00034 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00035 
00036 #include "DQM/SiStripMonitorPedestals/interface/SiStripMonitorQuality.h"
00037 
00038 // std
00039 #include <cstdlib>
00040 #include <cmath>
00041 #include <numeric>
00042 #include <algorithm>
00043 
00044 SiStripMonitorQuality::SiStripMonitorQuality(edm::ParameterSet const& iConfig):
00045   dqmStore_(edm::Service<DQMStore>().operator->()),
00046   conf_(iConfig),
00047   m_cacheID_(0)
00048 
00049 
00050 {
00051   edm::LogInfo("SiStripMonitorQuality") <<"SiStripMonitorQuality  " 
00052                                           << " Constructing....... ";     
00053 }
00054 
00055 
00056 SiStripMonitorQuality::~SiStripMonitorQuality()
00057 {
00058   edm::LogInfo("SiStripMonitorQuality") <<"SiStripMonitorQuality  " 
00059                                           << " Destructing....... ";     
00060 }
00061 //
00062 // -- Begin Job
00063 //
00064 void SiStripMonitorQuality::beginJob() {
00065 }
00066 //
00067 // -- BeginRun
00068 //
00069 void SiStripMonitorQuality::beginRun(edm::Run const& run, edm::EventSetup const& eSetup){
00070 }
00071 
00072 
00073 // ------------ method called to produce the data  ------------
00074 void SiStripMonitorQuality::analyze(edm::Event const& iEvent, edm::EventSetup const& eSetup)
00075 {
00076   unsigned long long cacheID = eSetup.get<SiStripQualityRcd>().cacheIdentifier();  
00077   if (m_cacheID_ == cacheID) return;
00078   
00079   m_cacheID_ = cacheID;       
00080 
00081   std::string quality_label = conf_.getParameter<std::string>("StripQualityLabel");
00082   eSetup.get<SiStripQualityRcd>().get(quality_label,stripQuality_);
00083   eSetup.get<SiStripDetCablingRcd>().get( detCabling_ );
00084   
00085   edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze: "<<
00086     " Reading SiStripQuality "<< std::endl;
00087 
00088   SiStripBadStrip::RegistryIterator rbegin = stripQuality_->getRegistryVectorBegin();
00089   SiStripBadStrip::RegistryIterator rend   = stripQuality_->getRegistryVectorEnd();
00090   uint32_t detid;
00091     
00092   if (rbegin==rend) return;
00093 
00094   for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
00095     
00096     detid = rp->detid;
00097     // Check consistency in DetId
00098     if (detid == 0 || detid == 0xFFFFFFFF){
00099       edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::analyze : " 
00100                                                << "Wrong DetId !!!!!! " <<  detid << " Neglecting !!!!!! ";
00101       continue;
00102     }
00103     // check if the detid is connected in cabling
00104     if (!detCabling_->IsConnected(detid)) {
00105       edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::analyze : " 
00106                                            << " DetId " <<  detid << " not connected,  Neglecting !!!!!! ";
00107       continue;
00108     }
00109     MonitorElement* me = getQualityME(detid);
00110     SiStripBadStrip::Range range = SiStripBadStrip::Range( stripQuality_->getDataVectorBegin()+rp->ibegin , 
00111                                                            stripQuality_->getDataVectorBegin()+rp->iend );
00112     SiStripBadStrip::ContainerIterator it=range.first;
00113     for(;it!=range.second;++it){
00114       unsigned int value=(*it);
00115       short str_start = stripQuality_->decode(value).firstStrip;
00116       short str_end   = str_start + stripQuality_->decode(value).range;
00117       for ( short isr = str_start; isr < str_end + 1; isr++) {        
00118         if (isr <= (me->getNbinsX()-1)) me->Fill(isr+1, 1.0);
00119       }
00120     }
00121   }
00122 }
00123 //
00124 // -- End Run
00125 //    
00126 void SiStripMonitorQuality::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
00127   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00128   std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00129   if (outputMEsInRootFile) {    
00130     dqmStore_->showDirStructure();
00131     dqmStore_->save(outputFileName);
00132   }
00133 }
00134 //
00135 // -- End Job
00136 //
00137 void SiStripMonitorQuality::endJob(void){
00138   edm::LogInfo("SiStripMonitorQuality") <<"SiStripMonitorQuality::EndJob: " 
00139                                           << " Finishing!! ";        
00140 }
00141 //
00142 // -- End Job
00143 //
00144 MonitorElement* SiStripMonitorQuality::getQualityME(uint32_t idet){
00145 
00146   std::map<uint32_t, MonitorElement* >::iterator pos = QualityMEs.find(idet);
00147   MonitorElement* det_me;
00148   if (pos != QualityMEs.end()) {
00149     det_me = pos->second;
00150     det_me->Reset();
00151   } else {
00152     int nStrip =  detCabling_->nApvPairs(idet) * 256;
00153 
00154     // use SistripHistoId for producing histogram id (and title)
00155     SiStripHistoId hidmanager;
00156     // create SiStripFolderOrganizer
00157     SiStripFolderOrganizer folder_organizer;
00158     // set appropriate folder using SiStripFolderOrganizer
00159     folder_organizer.setDetectorFolder(idet); // pass the detid to this method
00160 
00161     std::string hid;
00162     hid = hidmanager.createHistoId("StripQualityFromCondDB","det", idet);
00163     
00164     det_me = dqmStore_->book1D(hid, hid, nStrip,0.5,nStrip+0.5);
00165     dqmStore_->tag(det_me, idet);
00166     det_me->setAxisTitle("Strip Number",1);
00167     det_me->setAxisTitle("Quality Flag from CondDB ",2);
00168     QualityMEs.insert( std::make_pair(idet, det_me));
00169   }
00170   return det_me;
00171 }
00172 DEFINE_FWK_MODULE(SiStripMonitorQuality);
00173