CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQM/EcalBarrelMonitorClient/src/EBPedestalOnlineClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBPedestalOnlineClient.cc
00003  *
00004  * $Date: 2012/04/27 13:45:59 $
00005  * $Revision: 1.167 $
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 "DQM/EcalBarrelMonitorClient/interface/EBPedestalOnlineClient.h"
00036 
00037 EBPedestalOnlineClient::EBPedestalOnlineClient(const edm::ParameterSet& ps) {
00038 
00039   // cloneME switch
00040   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00041 
00042   // verbose switch
00043   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00044 
00045   // debug switch
00046   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00047 
00048   // prefixME path
00049   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00050 
00051   subfolder_ = ps.getUntrackedParameter<std::string>("subfolder", "");
00052 
00053   // enableCleanup_ switch
00054   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00055 
00056   // vector of selected Super Modules (Defaults to all 36).
00057   superModules_.reserve(36);
00058   for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00059   superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00060 
00061   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00062 
00063     int ism = superModules_[i];
00064 
00065     h03_[ism-1] = 0;
00066 
00067   }
00068 
00069   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00070 
00071     int ism = superModules_[i];
00072 
00073     meg03_[ism-1] = 0;
00074 
00075     mep03_[ism-1] = 0;
00076 
00077     mer03_[ism-1] = 0;
00078 
00079   }
00080 
00081   expectedMean_ = 200.0;
00082   discrepancyMean_ = 25.0;
00083   RMSThreshold_ = 3.0;
00084   RMSThresholdHighEta_ = 6.0;
00085 
00086 }
00087 
00088 EBPedestalOnlineClient::~EBPedestalOnlineClient() {
00089 
00090 }
00091 
00092 void EBPedestalOnlineClient::beginJob(void) {
00093 
00094   dqmStore_ = edm::Service<DQMStore>().operator->();
00095 
00096   if ( debug_ ) std::cout << "EBPedestalOnlineClient: beginJob" << std::endl;
00097 
00098   ievt_ = 0;
00099   jevt_ = 0;
00100 
00101 }
00102 
00103 void EBPedestalOnlineClient::beginRun(void) {
00104 
00105   if ( debug_ ) std::cout << "EBPedestalOnlineClient: beginRun" << std::endl;
00106 
00107   jevt_ = 0;
00108 
00109   this->setup();
00110 
00111 }
00112 
00113 void EBPedestalOnlineClient::endJob(void) {
00114 
00115   if ( debug_ ) std::cout << "EBPedestalOnlineClient: endJob, ievt = " << ievt_ << std::endl;
00116 
00117   this->cleanup();
00118 
00119 }
00120 
00121 void EBPedestalOnlineClient::endRun(void) {
00122 
00123   if ( debug_ ) std::cout << "EBPedestalOnlineClient: endRun, jevt = " << jevt_ << std::endl;
00124 
00125   this->cleanup();
00126 
00127 }
00128 
00129 void EBPedestalOnlineClient::setup(void) {
00130 
00131   std::string name;
00132 
00133   dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient" );
00134 
00135   if(subfolder_.size())
00136     dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient/" + subfolder_);
00137 
00138   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00139 
00140     int ism = superModules_[i];
00141 
00142     if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00143     name = "EBPOT pedestal quality G12 " + Numbers::sEB(ism);
00144     meg03_[ism-1] = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
00145     meg03_[ism-1]->setAxisTitle("ieta", 1);
00146     meg03_[ism-1]->setAxisTitle("iphi", 2);
00147 
00148     if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00149     name = "EBPOT pedestal mean G12 " + Numbers::sEB(ism);
00150     mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
00151     mep03_[ism-1]->setAxisTitle("mean", 1);
00152 
00153     if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00154     name = "EBPOT pedestal rms G12 " + Numbers::sEB(ism);
00155     mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0.,  10.);
00156     mer03_[ism-1]->setAxisTitle("rms", 1);
00157 
00158   }
00159 
00160   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00161 
00162     int ism = superModules_[i];
00163 
00164     if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00165 
00166     for ( int ie = 1; ie <= 85; ie++ ) {
00167       for ( int ip = 1; ip <= 20; ip++ ) {
00168 
00169         meg03_[ism-1]->setBinContent( ie, ip, 2. );
00170 
00171       }
00172     }
00173 
00174     if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00175     if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00176 
00177   }
00178 
00179 }
00180 
00181 void EBPedestalOnlineClient::cleanup(void) {
00182 
00183   if ( ! enableCleanup_ ) return;
00184 
00185   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00186 
00187     int ism = superModules_[i];
00188 
00189     if ( cloneME_ ) {
00190       if ( h03_[ism-1] ) delete h03_[ism-1];
00191     }
00192 
00193     h03_[ism-1] = 0;
00194 
00195   }
00196 
00197   dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient" );
00198 
00199   if(subfolder_.size())
00200     dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient/" + subfolder_);
00201 
00202   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00203 
00204     int ism = superModules_[i];
00205 
00206     if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00207     meg03_[ism-1] = 0;
00208 
00209     if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00210     mep03_[ism-1] = 0;
00211 
00212     if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00213     mer03_[ism-1] = 0;
00214 
00215   }
00216 
00217 }
00218 
00219 #ifdef WITH_ECAL_COND_DB
00220 bool EBPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00221 
00222   status = true;
00223 
00224   EcalLogicID ecid;
00225 
00226   MonPedestalsOnlineDat p;
00227   std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
00228 
00229   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00230 
00231     int ism = superModules_[i];
00232 
00233     if ( verbose_ ) {
00234       std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00235       std::cout << std::endl;
00236       UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
00237     }
00238 
00239     float num03;
00240     float mean03;
00241     float rms03;
00242 
00243     for ( int ie = 1; ie <= 85; ie++ ) {
00244       for ( int ip = 1; ip <= 20; ip++ ) {
00245 
00246         bool update03;
00247 
00248         update03 = UtilsClient::getBinStatistics(h03_[ism-1], ie, ip, num03, mean03, rms03);
00249 
00250         if ( update03 ) {
00251 
00252           if ( Numbers::icEB(ism, ie, ip) == 1 ) {
00253 
00254             if ( verbose_ ) {
00255               std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00256               std::cout << "G12 (" << ie << "," << ip << ") " << num03  << " " << mean03 << " " << rms03  << std::endl;
00257               std::cout << std::endl;
00258             }
00259 
00260           }
00261 
00262           p.setADCMeanG12(mean03);
00263           p.setADCRMSG12(rms03);
00264 
00265           if ( UtilsClient::getBinStatus(meg03_[ism-1], ie, ip) ) {
00266             p.setTaskStatus(true);
00267           } else {
00268             p.setTaskStatus(false);
00269           }
00270 
00271           status = status && UtilsClient::getBinQuality(meg03_[ism-1], ie, ip);
00272 
00273           int ic = Numbers::indexEB(ism, ie, ip);
00274 
00275           if ( econn ) {
00276             ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
00277             dataset[ecid] = p;
00278           }
00279 
00280         }
00281 
00282       }
00283     }
00284 
00285   }
00286 
00287   if ( econn ) {
00288     try {
00289       if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
00290       if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00291       if ( verbose_ ) std::cout << "done." << std::endl;
00292     } catch (std::runtime_error &e) {
00293       std::cerr << e.what() << std::endl;
00294     }
00295   }
00296 
00297   return true;
00298 
00299 }
00300 #endif
00301 
00302 void EBPedestalOnlineClient::analyze(void) {
00303 
00304   ievt_++;
00305   jevt_++;
00306   if ( ievt_ % 10 == 0 ) {
00307     if ( debug_ ) std::cout << "EBPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00308   }
00309 
00310   uint32_t bits03 = 0;
00311   bits03 |= 1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR;
00312   bits03 |= 1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR;
00313 
00314   std::string subdir(subfolder_.size() ? subfolder_ + "/" : "");
00315 
00316   MonitorElement* me;
00317 
00318   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00319 
00320     int ism = superModules_[i];
00321 
00322     me = dqmStore_->get( prefixME_ + "/EBPedestalOnlineTask/" + subdir + "Gain12/EBPOT pedestal " + Numbers::sEB(ism) + " G12" );
00323     h03_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h03_[ism-1] );
00324     if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00325     if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00326     if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00327 
00328     for ( int ie = 1; ie <= 85; ie++ ) {
00329       for ( int ip = 1; ip <= 20; ip++ ) {
00330 
00331         if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ie, ip, 2.);
00332 
00333         bool update03;
00334 
00335         float num03;
00336         float mean03;
00337         float rms03;
00338 
00339         update03 = UtilsClient::getBinStatistics(h03_[ism-1], ie, ip, num03, mean03, rms03);
00340 
00341         if ( update03 ) {
00342 
00343           float val;
00344 
00345           val = 1.;
00346           if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
00347             val = 0.;
00348           if ( (ie<=40 && rms03 > RMSThreshold_) || (ie>40 && rms03 > RMSThresholdHighEta_) )
00349             val = 0.;
00350           if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ie, ip, val);
00351 
00352           if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
00353           if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
00354 
00355         }
00356 
00357         if ( Masks::maskChannel(ism, ie, ip, bits03, EcalBarrel) ) UtilsClient::maskBinContent( meg03_[ism-1], ie, ip );
00358 
00359       }
00360     }
00361 
00362   }
00363 
00364 }
00365