CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DQM/EcalEndcapMonitorTasks/src/EEDataCertificationTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEDataCertificationTask.cc
00003  *
00004  * $Date: 2012/04/27 13:46:14 $
00005  * $Revision: 1.31 $
00006  * \author E. Di Marco
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <algorithm>
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 "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00021 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00022 
00023 #include "DQMServices/Core/interface/MonitorElement.h"
00024 #include "DQMServices/Core/interface/DQMStore.h"
00025 
00026 #include "DQM/EcalCommon/interface/Numbers.h"
00027 #include "DQM/EcalCommon/interface/UtilsClient.h"
00028 
00029 #include "DQM/EcalEndcapMonitorTasks/interface/EEDataCertificationTask.h"
00030 
00031 EEDataCertificationTask::EEDataCertificationTask(const edm::ParameterSet& ps) {
00032 
00033   // cloneME switch
00034   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
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   meEEDataCertificationSummary_ = 0;
00045   meEEDataCertificationSummaryMap_ = 0;
00046   for (int i = 0; i < 18; i++) {
00047     meEEDataCertification_[i] = 0;
00048   }
00049 
00050   hDQM_ = 0;
00051   hDAQ_ = 0;
00052   hIntegrityByLumi_ = 0;
00053   hFrontendByLumi_ = 0;
00054   hSynchronizationByLumi_ = 0;
00055 
00056 }
00057 
00058 EEDataCertificationTask::~EEDataCertificationTask() {
00059 
00060 }
00061 
00062 void EEDataCertificationTask::beginJob(void){
00063 
00064   if ( dqmStore_ ) {
00065 
00066     std::string name;
00067 
00068     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00069 
00070     meEEDataCertificationSummary_ = dqmStore_->bookFloat( "CertificationSummary" );
00071     meEEDataCertificationSummary_->Fill(-1.0);
00072 
00073     name = "CertificationSummaryMap";
00074     meEEDataCertificationSummaryMap_ = dqmStore_->book2D(name, name, 40, 0., 200., 20, 0., 100.);
00075     meEEDataCertificationSummaryMap_->setAxisTitle("ix / ix+100", 1);
00076     meEEDataCertificationSummaryMap_->setAxisTitle("iy", 2);
00077 
00078     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/CertificationContents");
00079 
00080     for (int i = 0; i < 18; i++) {
00081       meEEDataCertification_[i] = dqmStore_->bookFloat( "EcalEndcap_" + Numbers::sEE(i+1) );
00082       meEEDataCertification_[i]->Fill(-1.0);
00083     }
00084 
00085   }
00086 
00087 }
00088 
00089 void EEDataCertificationTask::endJob(void) {
00090 
00091   if ( enableCleanup_ ) this->cleanup();
00092 
00093 }
00094 
00095 void EEDataCertificationTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const  edm::EventSetup& iSetup){
00096 
00097 }
00098 
00099 void EEDataCertificationTask::endLuminosityBlock(const edm::LuminosityBlock&  lumiBlock, const  edm::EventSetup& iSetup) {
00100 
00101   this->reset();
00102 
00103   MonitorElement* me;
00104 
00105   // evaluate the DQM quality of observables checked by lumi
00106   float DQMVal[18];
00107   for (int i = 0; i < 18; i++) {
00108     DQMVal[i] = -1.;
00109   }
00110 
00111   edm::ESHandle< EcalElectronicsMapping > handle;
00112   iSetup.get< EcalMappingRcd >().get(handle);
00113   const EcalElectronicsMapping *map = handle.product();
00114   if( ! map ) edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00115 
00116   me = dqmStore_->get( prefixME_ + "/EEIntegrityTask/EEIT weighted integrity errors by lumi" );
00117   hIntegrityByLumi_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hIntegrityByLumi_ );
00118 
00119   me = dqmStore_->get( prefixME_ + "/EEStatusFlagsTask/FEStatus/EESFT weighted frontend errors by lumi" );
00120   hFrontendByLumi_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hFrontendByLumi_ );
00121 
00122   me = dqmStore_->get( prefixME_ + "/EERawDataTask/EERDT FE synchronization errors by lumi" );
00123   hSynchronizationByLumi_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hSynchronizationByLumi_ );
00124 
00125   if( hIntegrityByLumi_ && hFrontendByLumi_ && hSynchronizationByLumi_ && map) {
00126 
00127     float integrityErrSum = 0.;
00128     float integrityQual = 1.0;
00129     float frontendErrSum = 0.;
00130     float frontendQual = 1.0;
00131     float synchronizationErrSum = 0.;
00132     float synchronizationQual = 1.0;
00133 
00134     for ( int i=0; i<18; i++) {
00135       float ismIntegrityQual = 1.0;
00136       if( hIntegrityByLumi_->GetBinContent(0) > 0 ) {
00137         float errors = hIntegrityByLumi_->GetBinContent(i+1);
00138         ismIntegrityQual = 1.0 - errors/hIntegrityByLumi_->GetBinContent(0);
00139         integrityErrSum += errors;
00140       }
00141       float ismFrontendQual = 1.0;
00142       if( hFrontendByLumi_->GetBinContent(0) > 0 ) {
00143         float errors = hFrontendByLumi_->GetBinContent(i+1);
00144         ismFrontendQual = 1.0 - errors/hFrontendByLumi_->GetBinContent(0);
00145         frontendErrSum += errors;
00146       }
00147       float ismSynchronizationQual = 1.0;
00148       if( hSynchronizationByLumi_->GetBinContent(0) > 0 ) {
00149         float errors = hSynchronizationByLumi_->GetBinContent(i+1);
00150         ismSynchronizationQual = 1.0 - errors/hSynchronizationByLumi_->GetBinContent(0);
00151         synchronizationErrSum += errors;
00152       }
00153       float minVal= std::min(ismIntegrityQual,ismFrontendQual);
00154       DQMVal[i] = std::min(minVal,ismSynchronizationQual);
00155     }
00156 
00157     if( hIntegrityByLumi_->GetBinContent(0) > 0 ) integrityQual = 1.0 - integrityErrSum/hIntegrityByLumi_->GetBinContent(0)/18.;
00158     if( hFrontendByLumi_->GetBinContent(0) > 0 ) frontendQual = 1.0 - frontendErrSum/hFrontendByLumi_->GetBinContent(0)/18.;
00159     if( hSynchronizationByLumi_->GetBinContent(0) > 0 ) synchronizationQual = 1.0 - synchronizationErrSum/hSynchronizationByLumi_->GetBinContent(0)/36.;
00160     float minVal = std::min(integrityQual,frontendQual);
00161     float totDQMVal = std::min(minVal,synchronizationQual);
00162 
00163     me = dqmStore_->get( prefixME_ + "/EventInfo/reportSummary" );
00164     if( me ) me->Fill(totDQMVal);
00165 
00166     for ( int i=0; i<18; i++) {
00167       me = dqmStore_->get( prefixME_ + "/EventInfo/reportSummaryContents/EcalEndcap_" + Numbers::sEE(i+1) );
00168       if( me ) me->Fill(DQMVal[i]);
00169 
00170       me = dqmStore_->get( prefixME_ + "/EventInfo/reportSummaryMap" );
00171       if( me ) {
00172         for(int t=1 ; t<=nTowerMax_ ; t++){
00173           if(! map->dccTowerConstituents(DccId_[i], t).size() ) continue;
00174           std::vector<EcalScDetId> scs = map->getEcalScDetId(DccId_[i], t, false);
00175           for(unsigned u=0 ; u<scs.size() ; u++){
00176             int jx = scs[u].ix() + (scs[u].zside()<0 ? 0 : 20);
00177             int jy = scs[u].iy();
00178             me->setBinContent(jx,jy, DQMVal[i]);
00179           }
00180         }
00181       }
00182     }
00183 
00184   }
00185 
00186   // now combine reduced DQM with DCS and DAQ
00187   me = dqmStore_->get( prefixME_ + "/EventInfo/DAQSummaryMap" );
00188   hDAQ_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDAQ_ );
00189 
00190   me = dqmStore_->get( prefixME_ + "/EventInfo/DCSSummaryMap" );
00191   hDCS_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDCS_ );
00192 
00193   float sumCert = 0.;
00194   float sumCertEE[18];
00195   int nValidChannels = 0;
00196   int nValidChannelsEE[18];
00197 
00198   if ( meEEDataCertificationSummaryMap_ ){
00199     for(int ix=1 ; ix<=meEEDataCertificationSummaryMap_->getNbinsX() ; ix++){
00200       for(int iy=1 ; iy<=meEEDataCertificationSummaryMap_->getNbinsY() ; iy++){
00201         meEEDataCertificationSummaryMap_->setBinContent( ix, iy, -1.0 );
00202       }
00203     }
00204   }
00205 
00206   for (int i = 0; i < 18; i++) {
00207     sumCertEE[i] = 0;
00208     nValidChannelsEE[i] = 0;
00209 
00210     for(int t=1 ; t<=nTowerMax_ ; t++){
00211 
00212       std::vector<DetId> crystals = map->dccTowerConstituents(DccId_[i], t);
00213       if(!crystals.size()) continue; // getEcalScDetId throws an exception when no crystal is found
00214 
00215       std::vector<EcalScDetId> scs = map->getEcalScDetId(DccId_[i], t, false);
00216       for(unsigned u=0 ; u<scs.size() ; u++){
00217 
00218         int jx = scs[u].ix() + (scs[u].zside()<0 ? 0 : 20);
00219         int jy = scs[u].iy();
00220 
00221         float xvalDQM = DQMVal[i];
00222 
00223         float xvalDAQ, xvalDCS;
00224         xvalDAQ = xvalDCS = -1.;
00225         float xcert = -1.;
00226 
00227         if ( hDAQ_ ) xvalDAQ = hDAQ_->GetBinContent( jx, jy );
00228         if ( hDCS_ ) xvalDCS = hDCS_->GetBinContent( jx, jy );
00229 
00230         if ( xvalDQM == -1 || ( xvalDAQ == -1 && xvalDCS == -1 ) ) {
00231           // problems: DQM empty or DAQ and DCS not available
00232           xcert = 0.0;
00233         } else {
00234           // do not consider the white value of DAQ and DCS (problems with DB)
00235           xcert = std::abs(xvalDQM) * std::abs(xvalDAQ) * std::abs(xvalDCS);
00236         }
00237 
00238         if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->setBinContent( jx, jy, xcert );
00239 
00240         int ncrystals = 0;
00241 
00242         for(std::vector<DetId>::const_iterator it=crystals.begin() ; it!=crystals.end() ; ++it){
00243           EEDetId id(*it);
00244           if( id.zside() == scs[u].zside() && (id.ix()-1)/5+1 == scs[u].ix() && (id.iy()-1)/5+1 == scs[u].iy() ) ncrystals++;
00245         }
00246 
00247         sumCertEE[i] += xcert * ncrystals;
00248         nValidChannelsEE[i] += ncrystals;
00249 
00250         sumCert += xcert * ncrystals;
00251         nValidChannels += ncrystals;
00252 
00253       }
00254     }
00255 
00256     if( meEEDataCertification_[i] ) {
00257       if( nValidChannelsEE[i]>0 ) meEEDataCertification_[i]->Fill( sumCertEE[i]/nValidChannelsEE[i] );
00258       else meEEDataCertification_[i]->Fill( 0.0 );
00259     }
00260   }
00261 
00262   if( meEEDataCertificationSummary_ ) {
00263     if( nValidChannels>0 ) meEEDataCertificationSummary_->Fill( sumCert/nValidChannels );
00264     else meEEDataCertificationSummary_->Fill( 0.0 );
00265   }
00266 
00267 }
00268 
00269 void EEDataCertificationTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00270 
00271   if ( ! mergeRuns_ ) this->reset();
00272 
00273 }
00274 
00275 void EEDataCertificationTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00276 
00277   this->reset();
00278 
00279   edm::ESHandle< EcalElectronicsMapping > handle;
00280   c.get< EcalMappingRcd >().get(handle);
00281   const EcalElectronicsMapping *map = handle.product();
00282   if( ! map ){
00283     edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00284     return;
00285   }
00286 
00287   MonitorElement* me;
00288 
00289   me = dqmStore_->get( prefixME_ + "/EventInfo/reportSummaryMap" );
00290   hDQM_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDQM_ );
00291 
00292   me = dqmStore_->get( prefixME_ + "/EventInfo/DAQSummaryMap" );
00293   hDAQ_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDAQ_ );
00294 
00295   me = dqmStore_->get( prefixME_ + "/EventInfo/DCSSummaryMap" );
00296   hDCS_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDCS_ );
00297 
00298   float sumCert = 0.;
00299   float sumCertEE[18];
00300   int nValidChannels = 0;
00301   int nValidChannelsEE[18];
00302 
00303   if ( meEEDataCertificationSummaryMap_ ){
00304     for(int ix=1 ; ix<=meEEDataCertificationSummaryMap_->getNbinsX() ; ix++){
00305       for(int iy=1 ; iy<=meEEDataCertificationSummaryMap_->getNbinsY() ; iy++){
00306         meEEDataCertificationSummaryMap_->setBinContent( ix, iy, -1.0 );
00307       }
00308     }
00309   }
00310 
00311   for (int i = 0; i < 18; i++) {
00312     sumCertEE[i] = 0;
00313     nValidChannelsEE[i] = 0;
00314 
00315     for(int t=1 ; t<=nTowerMax_ ; t++){
00316 
00317       std::vector<DetId> crystals = map->dccTowerConstituents(DccId_[i], t);
00318       if(!crystals.size()) continue;
00319 
00320       std::vector<EcalScDetId> scs = map->getEcalScDetId(DccId_[i], t, false);
00321       for(unsigned u=0 ; u<scs.size() ; u++){
00322 
00323         int jx = scs[u].ix() + (scs[u].zside()<0 ? 0 : 20);
00324         int jy = scs[u].iy();
00325 
00326         float xvalDQM, xvalDAQ, xvalDCS;
00327         xvalDQM = xvalDAQ = xvalDCS = -1.;
00328         float xcert = -1.;
00329 
00330         if ( hDQM_ ) xvalDQM = hDQM_->GetBinContent( jx, jy );
00331         if ( hDAQ_ ) xvalDAQ = hDAQ_->GetBinContent( jx, jy );
00332         if ( hDCS_ ) xvalDCS = hDCS_->GetBinContent( jx, jy );
00333 
00334         if ( xvalDQM == -1 || ( xvalDAQ == -1 && xvalDCS == -1 ) ) {
00335           // problems: DQM empty or DAQ and DCS not available
00336           xcert = 0.0;
00337         } else {
00338           // do not consider the white value of DAQ and DCS (problems with DB)
00339           xcert = std::abs(xvalDQM) * std::abs(xvalDAQ) * std::abs(xvalDCS);
00340         }
00341 
00342         if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->setBinContent( jx, jy, xcert );
00343 
00344         int ncrystals = 0;
00345 
00346         for(std::vector<DetId>::const_iterator it=crystals.begin() ; it!=crystals.end() ; ++it){
00347           EEDetId id(*it);
00348           if( id.zside() == scs[u].zside() && (id.ix()-1)/5+1 == scs[u].ix() && (id.iy()-1)/5+1 == scs[u].iy() ) ncrystals++;
00349         }
00350 
00351         sumCertEE[i] += xcert * ncrystals;
00352         nValidChannelsEE[i] += ncrystals;
00353 
00354         sumCert += xcert * ncrystals;
00355         nValidChannels += ncrystals;
00356 
00357       }
00358     }
00359 
00360     if( meEEDataCertification_[i] ) {
00361       if( nValidChannelsEE[i]>0 ) meEEDataCertification_[i]->Fill( sumCertEE[i]/nValidChannelsEE[i] );
00362       else meEEDataCertification_[i]->Fill( 0.0 );
00363     }
00364   }
00365 
00366   if( meEEDataCertificationSummary_ ) {
00367     if( nValidChannels>0 ) meEEDataCertificationSummary_->Fill( sumCert/nValidChannels );
00368     else meEEDataCertificationSummary_->Fill( 0.0 );
00369   }
00370 
00371 }
00372 
00373 void EEDataCertificationTask::reset(void) {
00374 
00375   if ( meEEDataCertificationSummary_ ) meEEDataCertificationSummary_->Reset();
00376 
00377   for (int i = 0; i < 18; i++) {
00378     if ( meEEDataCertification_[i] ) meEEDataCertification_[i]->Reset();
00379   }
00380 
00381   if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->Reset();
00382 
00383   if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->Reset();
00384 
00385 }
00386 
00387 
00388 void EEDataCertificationTask::cleanup(void){
00389 
00390   if ( cloneME_ ) {
00391     if( hDQM_ ) delete hDQM_;
00392     if( hDAQ_ ) delete hDAQ_;
00393     if( hDCS_ ) delete hDCS_;
00394     if( hIntegrityByLumi_ ) delete hIntegrityByLumi_;
00395     if( hFrontendByLumi_ ) delete hFrontendByLumi_;
00396     if( hSynchronizationByLumi_ ) delete hSynchronizationByLumi_;
00397   }
00398   hDQM_ = 0;
00399   hDAQ_ = 0;
00400   hDCS_ = 0;
00401   hIntegrityByLumi_ = 0;
00402   hFrontendByLumi_ = 0;
00403   hSynchronizationByLumi_ = 0;
00404 
00405   if ( dqmStore_ ) {
00406     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00407     if ( meEEDataCertificationSummary_ ) dqmStore_->removeElement( meEEDataCertificationSummary_->getName() );
00408     if ( meEEDataCertificationSummaryMap_ ) dqmStore_->removeElement( meEEDataCertificationSummaryMap_->getName() );
00409 
00410     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/CertificationContents");
00411     for (int i = 0; i < 18; i++) {
00412       if ( meEEDataCertification_[i] ) dqmStore_->removeElement( meEEDataCertification_[i]->getName() );
00413     }
00414   }
00415 
00416 }
00417 
00418 void EEDataCertificationTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00419 
00420 }