CMS 3D CMS Logo

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

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