CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/EcalEndcapMonitorTasks/src/EEDcsInfoTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEDcsInfoTask.cc
00003  *
00004  * $Date: 2011/08/30 09:28:42 $
00005  * $Revision: 1.20 $
00006  * \author E. Di Marco
00007  *
00008 */
00009 
00010 #include <iostream>
00011 
00012 #include "FWCore/ServiceRegistry/interface/Service.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 
00017 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00018 
00019 #include "CondFormats/EcalObjects/interface/EcalDCSTowerStatus.h"
00020 #include "CondFormats/DataRecord/interface/EcalDCSTowerStatusRcd.h"
00021 
00022 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00023 
00024 #include "DQMServices/Core/interface/MonitorElement.h"
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 
00027 #include "DQM/EcalCommon/interface/Numbers.h"
00028 
00029 #include "DQM/EcalEndcapMonitorTasks/interface/EEDcsInfoTask.h"
00030 
00031 EEDcsInfoTask::EEDcsInfoTask(const edm::ParameterSet& ps) {
00032 
00033   dqmStore_ = edm::Service<DQMStore>().operator->();
00034 
00035   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00036 
00037   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00038 
00039   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00040 
00041   meEEDcsFraction_ = 0;
00042   meEEDcsActiveMap_ = 0;
00043   for (int i = 0; i < 18; i++) {
00044     meEEDcsActive_[i] = 0;
00045   }
00046 
00047 }
00048 
00049 EEDcsInfoTask::~EEDcsInfoTask() {
00050 
00051 }
00052 
00053 void EEDcsInfoTask::beginJob(void){
00054 
00055   if ( dqmStore_ ) {
00056 
00057     std::string name;
00058 
00059     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00060 
00061     meEEDcsFraction_ = dqmStore_->bookFloat( "DCSSummary" );
00062     meEEDcsFraction_->Fill(0.0);
00063 
00064     name = "DCSSummaryMap";
00065     meEEDcsActiveMap_ = dqmStore_->book2D(name, name, 40, 0., 200., 20, 0., 100.);
00066     meEEDcsActiveMap_->setAxisTitle("ix / ix+100", 1);
00067     meEEDcsActiveMap_->setAxisTitle("iy", 2);
00068 
00069     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DCSContents");
00070 
00071     for (int i = 0; i < 18; i++) {
00072       meEEDcsActive_[i] = dqmStore_->bookFloat( "EcalEndcap_" + Numbers::sEE(i+1) );
00073       meEEDcsActive_[i]->Fill(-1.0);
00074     }
00075 
00076   }
00077 
00078 }
00079 
00080 void EEDcsInfoTask::endJob(void) {
00081 
00082   if ( enableCleanup_ ) this->cleanup();
00083 
00084 }
00085 
00086 void EEDcsInfoTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const  edm::EventSetup& iSetup){
00087 
00088   // information is by run, so fill the same for the run and for every lumi section
00089   for ( int itx = 0; itx < 40; itx++ ) {
00090     for ( int ity = 0; ity < 20; ity++ ) {
00091       readyLumi[itx][ity] = 1;
00092     }
00093   }
00094 
00095   if ( !iSetup.find( edm::eventsetup::EventSetupRecordKey::makeKey<EcalDCSTowerStatusRcd>() ) ) {
00096     edm::LogWarning("EEDcsInfoTask") << "EcalDCSTowerStatus record not found";
00097     return;
00098   }
00099 
00100   edm::ESHandle<EcalDCSTowerStatus> pDCSStatus;
00101   iSetup.get<EcalDCSTowerStatusRcd>().get(pDCSStatus);
00102   if ( !pDCSStatus.isValid() ) {
00103     edm::LogWarning("EEDcsInfoTask") << "EcalDCSTowerStatus record not valid";
00104     return;
00105   }
00106   const EcalDCSTowerStatus* dcsStatus = pDCSStatus.product();
00107 
00108   edm::ESHandle< EcalElectronicsMapping > pElecMapping;
00109   iSetup.get< EcalMappingRcd >().get(pElecMapping);
00110   if( !pElecMapping.isValid() ) {
00111     edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00112     return;
00113   }
00114   const EcalElectronicsMapping *map = pElecMapping.product();
00115 
00116   std::vector<DetId> crystals;
00117   std::vector<EcalScDetId> scs;
00118 
00119   for(unsigned i=0 ; i<sizeof(DccId_)/sizeof(int) ; i++){
00120     for(int t=1 ; t<=nTowerMax_ ; t++){
00121 
00122       crystals = map->dccTowerConstituents(DccId_[i], t);
00123       if(!crystals.size()) continue;
00124 
00125       scs = map->getEcalScDetId(DccId_[i], t, false);
00126 
00127       for(unsigned u=0 ; u<scs.size() ; u++){
00128 
00129         uint16_t dbStatus = 0; // 0 = good
00130         EcalDCSTowerStatus::const_iterator dcsStatusIt = dcsStatus->find( scs[u].rawId() );
00131         if ( dcsStatusIt != dcsStatus->end() ) dbStatus = dcsStatusIt->getStatusCode();
00132         
00133         if ( dbStatus > 0 ) {
00134           int jx = scs[u].ix() - 1 + (scs[u].zside()<0 ? 0 : 20);
00135           int jy = scs[u].iy() - 1;
00136           readyRun[jx][jy] = 0;
00137           readyLumi[jx][jy] = 0;
00138         }
00139       }
00140     }
00141   }
00142 
00143 //   for(int iz=-1; iz<=1; iz+=2) {
00144 //     for(int itx=0 ; itx<20; itx++) {
00145 //       for(int ity=0 ; ity<20; ity++) {
00146 //         if (EcalScDetId::validDetId(itx+1,ity+1,iz )){
00147 
00148 //           EcalScDetId eeid(itx+1,ity+1,iz);
00149 
00150 //           uint16_t dbStatus = 0; // 0 = good
00151 //           EcalDCSTowerStatus::const_iterator dcsStatusIt = dcsStatus->find( eeid.rawId() );
00152 //           if ( dcsStatusIt != dcsStatus->end() ) dbStatus = dcsStatusIt->getStatusCode();
00153 
00154 //           if ( dbStatus > 0 ) {
00155 //             int offsetSC = (iz > 0) ? 0 : 20;
00156 //             readyRun[offsetSC+itx][ity] = 0;
00157 //             readyLumi[offsetSC+itx][ity] = 0;
00158 //           }
00159 
00160 //         }
00161 //       }
00162 //     }
00163 //   }
00164 
00165 }
00166 
00167 void EEDcsInfoTask::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup) {
00168 
00169   edm::ESHandle< EcalElectronicsMapping > handle;
00170   iSetup.get< EcalMappingRcd >().get(handle);
00171   const EcalElectronicsMapping *map = handle.product();
00172   if( ! map ) edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00173   else this->fillMonitorElements(readyLumi, map);
00174 
00175 }
00176 
00177 void EEDcsInfoTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00178 
00179   if ( ! mergeRuns_ ) this->reset();
00180 
00181   for ( int itx = 0; itx < 40; itx++ ) {
00182     for ( int ity = 0; ity < 20; ity++ ) {
00183       readyRun[itx][ity] = 1;
00184     }
00185   }
00186 
00187 }
00188 
00189 void EEDcsInfoTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00190 
00191   edm::ESHandle< EcalElectronicsMapping > handle;
00192   c.get< EcalMappingRcd >().get(handle);
00193   const EcalElectronicsMapping *map = handle.product();
00194   if( ! map ) edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00195   else this->fillMonitorElements(readyRun, map);
00196 
00197 }
00198 
00199 void EEDcsInfoTask::reset(void) {
00200 
00201   if ( meEEDcsFraction_ ) meEEDcsFraction_->Reset();
00202 
00203   for (int i = 0; i < 18; i++) {
00204     if ( meEEDcsActive_[i] ) meEEDcsActive_[i]->Reset();
00205   }
00206 
00207   if ( meEEDcsActiveMap_ ) meEEDcsActiveMap_->Reset();
00208 
00209 }
00210 
00211 
00212 void EEDcsInfoTask::cleanup(void){
00213 
00214   if ( dqmStore_ ) {
00215 
00216     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00217 
00218     if ( meEEDcsFraction_ ) dqmStore_->removeElement( meEEDcsFraction_->getName() );
00219 
00220     if ( meEEDcsActiveMap_ ) dqmStore_->removeElement( meEEDcsActiveMap_->getName() );
00221 
00222     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DCSContents");
00223 
00224     for (int i = 0; i < 18; i++) {
00225       if ( meEEDcsActive_[i] ) dqmStore_->removeElement( meEEDcsActive_[i]->getName() );
00226     }
00227 
00228   }
00229 
00230 }
00231 
00232 void EEDcsInfoTask::fillMonitorElements(int ready[40][20], const EcalElectronicsMapping *map) {
00233 
00234   float readySum[18];
00235   int nValidChannels[18];
00236   for ( int ism = 0; ism < 18; ism++ ) {
00237     readySum[ism] = 0;
00238     nValidChannels[ism] = 0;
00239   }
00240   float readySumTot = 0.;
00241   int nValidChannelsTot = 0;
00242 
00243   if(meEEDcsActiveMap_){
00244     for(int ix=1 ; ix<=meEEDcsActiveMap_->getNbinsX() ; ix++){
00245       for(int iy=1 ; iy<=meEEDcsActiveMap_->getNbinsY() ; iy++){
00246         meEEDcsActiveMap_->setBinContent( ix, iy, -1.0 );
00247       }
00248     }
00249   }
00250 
00251   std::vector<DetId> crystals;
00252   std::vector<EcalScDetId> scs;
00253 
00254   for ( unsigned iDcc = 0; iDcc < sizeof(DccId_)/sizeof(int); iDcc++) {
00255     for ( int t = 1; t<=nTowerMax_; t++ ) {
00256 
00257       crystals = map->dccTowerConstituents(DccId_[iDcc], t);
00258       if(!crystals.size()) continue;
00259 
00260       scs = map->getEcalScDetId(DccId_[iDcc], t, false);
00261 
00262       for(unsigned u=0 ; u<scs.size() ; u++){ // most of the time one DCC tower = one SC
00263 
00264         int jx = scs[u].ix() - 1 + (scs[u].zside()<0 ? 0 : 20);
00265         int jy = scs[u].iy() - 1;
00266 
00267         if(meEEDcsActiveMap_) meEEDcsActiveMap_->setBinContent( jx+1, jy+1, ready[jx][jy] );
00268 
00269         int ncrystals = 0;
00270 
00271         for(std::vector<DetId>::const_iterator it=crystals.begin() ; it!=crystals.end() ; ++it){
00272           EEDetId id(*it);
00273           if( id.zside() == scs[u].zside() && (id.ix()-1)/5+1 == scs[u].ix() && (id.iy()-1)/5+1 == scs[u].iy() ) ncrystals++;
00274         }
00275 
00276         if(ready[jx][jy]) {
00277           readySum[iDcc] += ncrystals;
00278           readySumTot += ncrystals;
00279         }
00280 
00281         nValidChannels[iDcc] += ncrystals;
00282         nValidChannelsTot += ncrystals;
00283       }
00284     }
00285 
00286     if( meEEDcsActive_[iDcc] ) meEEDcsActive_[iDcc]->Fill( readySum[iDcc]/float(nValidChannels[iDcc]) );
00287   }
00288 
00289   if( meEEDcsFraction_ ) meEEDcsFraction_->Fill( readySumTot/float(nValidChannelsTot) );
00290 
00291 }
00292 
00293 void EEDcsInfoTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00294 
00295 }