CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DQM/EcalEndcapMonitorClient/src/EEPedestalOnlineClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEPedestalOnlineClient.cc
00003  *
00004  * $Date: 2012/04/27 13:46:08 $
00005  * $Revision: 1.117 $
00006  * \author G. Della Ricca
00007  * \author F. Cossutti
00008  *
00009 */
00010 
00011 #include <memory>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <iomanip>
00015 #include <math.h>
00016 
00017 #include "FWCore/ServiceRegistry/interface/Service.h"
00018 
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 #include "DQMServices/Core/interface/MonitorElement.h"
00021 
00022 #ifdef WITH_ECAL_COND_DB
00023 #include "OnlineDB/EcalCondDB/interface/MonPedestalsOnlineDat.h"
00024 #include "OnlineDB/EcalCondDB/interface/RunCrystalErrorsDat.h"
00025 #include "OnlineDB/EcalCondDB/interface/RunTTErrorsDat.h"
00026 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00027 #include "DQM/EcalCommon/interface/LogicID.h"
00028 #endif
00029 
00030 #include "DQM/EcalCommon/interface/Masks.h"
00031 
00032 #include "DQM/EcalCommon/interface/UtilsClient.h"
00033 #include "DQM/EcalCommon/interface/Numbers.h"
00034 
00035 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00036 
00037 #include "DQM/EcalEndcapMonitorClient/interface/EEPedestalOnlineClient.h"
00038 
00039 EEPedestalOnlineClient::EEPedestalOnlineClient(const edm::ParameterSet& ps) {
00040 
00041   // cloneME switch
00042   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00043 
00044   // verbose switch
00045   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00046 
00047   // debug switch
00048   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00049 
00050   // prefixME path
00051   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00052 
00053   subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
00054 
00055   // enableCleanup_ switch
00056   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00057 
00058   // vector of selected Super Modules (Defaults to all 18).
00059   superModules_.reserve(18);
00060   for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
00061   superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00062 
00063   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00064 
00065     int ism = superModules_[i];
00066 
00067     h03_[ism-1] = 0;
00068 
00069   }
00070 
00071   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00072 
00073     int ism = superModules_[i];
00074 
00075     meg03_[ism-1] = 0;
00076 
00077     mep03_[ism-1] = 0;
00078 
00079     mer03_[ism-1] = 0;
00080 
00081   }
00082 
00083   expectedMean_ = 200.0;
00084   discrepancyMean_ = 25.0;
00085   RMSThreshold_ = 4.0;
00086   RMSThresholdInternal_ = 8.0;
00087 
00088 }
00089 
00090 EEPedestalOnlineClient::~EEPedestalOnlineClient() {
00091 
00092 }
00093 
00094 void EEPedestalOnlineClient::beginJob(void) {
00095 
00096   dqmStore_ = edm::Service<DQMStore>().operator->();
00097 
00098   if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginJob" << std::endl;
00099 
00100   ievt_ = 0;
00101   jevt_ = 0;
00102 
00103 }
00104 
00105 void EEPedestalOnlineClient::beginRun(void) {
00106 
00107   if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginRun" << std::endl;
00108 
00109   jevt_ = 0;
00110 
00111   this->setup();
00112 
00113 }
00114 
00115 void EEPedestalOnlineClient::endJob(void) {
00116 
00117   if ( debug_ ) std::cout << "EEPedestalOnlineClient: endJob, ievt = " << ievt_ << std::endl;
00118 
00119   this->cleanup();
00120 
00121 }
00122 
00123 void EEPedestalOnlineClient::endRun(void) {
00124 
00125   if ( debug_ ) std::cout << "EEPedestalOnlineClient: endRun, jevt = " << jevt_ << std::endl;
00126 
00127   this->cleanup();
00128 
00129 }
00130 
00131 void EEPedestalOnlineClient::setup(void) {
00132 
00133   std::string name;
00134 
00135   dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
00136 
00137   if(subfolder_.size())
00138     dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineClient/" + subfolder_);
00139 
00140   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00141 
00142     int ism = superModules_[i];
00143 
00144     if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00145     name = "EEPOT pedestal quality G12 " + Numbers::sEE(ism);
00146     meg03_[ism-1] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
00147     meg03_[ism-1]->setAxisTitle("ix", 1);
00148     if ( ism >= 1 && ism <= 9 ) meg03_[ism-1]->setAxisTitle("101-ix", 1);
00149     meg03_[ism-1]->setAxisTitle("iy", 2);
00150 
00151     if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00152     name = "EEPOT pedestal mean G12 " + Numbers::sEE(ism);
00153     mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
00154     mep03_[ism-1]->setAxisTitle("mean", 1);
00155 
00156     if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00157     name = "EEPOT pedestal rms G12 " + Numbers::sEE(ism);
00158     mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0.,  10.);
00159     mer03_[ism-1]->setAxisTitle("rms", 1);
00160 
00161   }
00162 
00163   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00164 
00165     int ism = superModules_[i];
00166 
00167     if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00168 
00169     for ( int ix = 1; ix <= 50; ix++ ) {
00170       for ( int iy = 1; iy <= 50; iy++ ) {
00171 
00172         meg03_[ism-1]->setBinContent( ix, iy, 6. );
00173 
00174         int jx = ix + Numbers::ix0EE(ism);
00175         int jy = iy + Numbers::iy0EE(ism);
00176 
00177         if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00178 
00179         if ( Numbers::validEE(ism, jx, jy) ) {
00180           meg03_[ism-1]->setBinContent( ix, iy, 2. );
00181         }
00182 
00183       }
00184     }
00185 
00186     if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00187     if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00188 
00189   }
00190 
00191 }
00192 
00193 void EEPedestalOnlineClient::cleanup(void) {
00194 
00195   if ( ! enableCleanup_ ) return;
00196 
00197   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00198 
00199     int ism = superModules_[i];
00200 
00201     if ( cloneME_ ) {
00202       if ( h03_[ism-1] ) delete h03_[ism-1];
00203     }
00204 
00205     h03_[ism-1] = 0;
00206 
00207   }
00208 
00209   dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
00210 
00211   if(subfolder_.size())
00212     dqmStore_->setCurrentFolder(prefixME_ + "/EEPedestalOnlineClient/" + subfolder_);
00213 
00214   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00215 
00216     int ism = superModules_[i];
00217 
00218     if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00219     meg03_[ism-1] = 0;
00220 
00221     if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00222     mep03_[ism-1] = 0;
00223 
00224     if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00225     mer03_[ism-1] = 0;
00226 
00227   }
00228 
00229 }
00230 
00231 #ifdef WITH_ECAL_COND_DB
00232 bool EEPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00233 
00234   status = true;
00235 
00236   EcalLogicID ecid;
00237 
00238   MonPedestalsOnlineDat p;
00239   std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
00240 
00241   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00242 
00243     int ism = superModules_[i];
00244 
00245     if ( verbose_ ) {
00246       std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00247       std::cout << std::endl;
00248       UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
00249     }
00250 
00251     float num03;
00252     float mean03;
00253     float rms03;
00254 
00255     for ( int ix = 1; ix <= 50; ix++ ) {
00256       for ( int iy = 1; iy <= 50; iy++ ) {
00257 
00258         int jx = ix + Numbers::ix0EE(ism);
00259         int jy = iy + Numbers::iy0EE(ism);
00260 
00261         if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00262 
00263         if ( ! Numbers::validEE(ism, jx, jy) ) continue;
00264 
00265         bool update03;
00266 
00267         update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
00268 
00269         if ( update03 ) {
00270 
00271           if ( Numbers::icEE(ism, jx, jy) == 1 ) {
00272 
00273             if ( verbose_ ) {
00274               std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00275               std::cout << "G12 (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num03  << " " << mean03 << " " << rms03  << std::endl;
00276               std::cout << std::endl;
00277             }
00278 
00279           }
00280 
00281           p.setADCMeanG12(mean03);
00282           p.setADCRMSG12(rms03);
00283 
00284           if ( UtilsClient::getBinStatus(meg03_[ism-1], ix, iy) ) {
00285             p.setTaskStatus(true);
00286           } else {
00287             p.setTaskStatus(false);
00288           }
00289 
00290           status = status && UtilsClient::getBinQuality(meg03_[ism-1], ix, iy);
00291 
00292           int ic = Numbers::indexEE(ism, jx, jy);
00293 
00294           if ( ic == -1 ) continue;
00295 
00296           if ( econn ) {
00297             ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
00298             dataset[ecid] = p;
00299           }
00300 
00301         }
00302 
00303       }
00304     }
00305 
00306   }
00307 
00308   if ( econn ) {
00309     try {
00310       if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
00311       if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00312       if ( verbose_ ) std::cout << "done." << std::endl;
00313     } catch (std::runtime_error &e) {
00314       std::cerr << e.what() << std::endl;
00315     }
00316   }
00317 
00318   return true;
00319 
00320 }
00321 #endif
00322 
00323 void EEPedestalOnlineClient::analyze(void) {
00324 
00325   ievt_++;
00326   jevt_++;
00327   if ( ievt_ % 10 == 0 ) {
00328     if ( debug_ ) std::cout << "EEPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00329   }
00330 
00331   uint32_t bits03 = 0;
00332   bits03 |= 1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR;
00333   bits03 |= 1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR;
00334 
00335   std::string subdir(subfolder_.size() ? subfolder_ + "/" : "");
00336 
00337   MonitorElement* me;
00338 
00339   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00340 
00341     int ism = superModules_[i];
00342 
00343     me = dqmStore_->get( prefixME_ + "/EEPedestalOnlineTask/" + subdir + "Gain12/EEPOT pedestal " + Numbers::sEE(ism) + " G12" );
00344     h03_[ism-1] = UtilsClient::getHisto( me, cloneME_, h03_[ism-1] );
00345 
00346     if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00347     if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00348     if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00349 
00350     for ( int ix = 1; ix <= 50; ix++ ) {
00351       for ( int iy = 1; iy <= 50; iy++ ) {
00352 
00353         if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, 6.);
00354 
00355         int jx = ix + Numbers::ix0EE(ism);
00356         int jy = iy + Numbers::iy0EE(ism);
00357 
00358         if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00359 
00360         if ( Numbers::validEE(ism, jx, jy) ) {
00361           if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent( ix, iy, 2. );
00362         }
00363 
00364         // OOT pileup affects the region near beam pipe mostly. Use higher threshold for these crystals
00365         float radius = std::sqrt((jx-50.)*(jx-50.)+(jy-50.)*(jy-50.));
00366 
00367         bool update03;
00368 
00369         float num03;
00370         float mean03;
00371         float rms03;
00372 
00373         update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
00374 
00375         if ( update03 ) {
00376 
00377           float val;
00378 
00379           val = 1.;
00380           if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
00381             val = 0.;
00382           if ( (radius >= 20. && rms03 > RMSThreshold_) || (radius < 20. && rms03 > RMSThresholdInternal_) )
00383             val = 0.;
00384           if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, val);
00385 
00386           if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
00387           if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
00388 
00389         }
00390 
00391         if ( Masks::maskChannel(ism, ix, iy, bits03, EcalEndcap) ) UtilsClient::maskBinContent( meg03_[ism-1], ix, iy );
00392 
00393       }
00394     }
00395 
00396   }
00397 
00398 }
00399