CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalEndcapMonitorClient/src/EEPedestalOnlineClient.cc

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