CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DQM/EcalEndcapMonitorTasks/src/EEDaqInfoTask.cc

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