CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/EcalEndcapMonitorClient/src/EEOccupancyClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EEOccupancyClient.cc
00003  *
00004  * $Date: 2012/04/27 13:46:07 $
00005  * $Revision: 1.46 $
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/MonOccupancyDat.h"
00024 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00025 #include "DQM/EcalCommon/interface/LogicID.h"
00026 #endif
00027 
00028 #include "DQM/EcalCommon/interface/UtilsClient.h"
00029 #include "DQM/EcalCommon/interface/Numbers.h"
00030 
00031 #include "DQM/EcalEndcapMonitorClient/interface/EEOccupancyClient.h"
00032 
00033 EEOccupancyClient::EEOccupancyClient(const edm::ParameterSet& ps) {
00034 
00035   // cloneME switch
00036   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00037 
00038   // verbose switch
00039   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00040 
00041   // debug switch
00042   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00043 
00044   // prefixME path
00045   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00046 
00047   // enableCleanup_ switch
00048   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00049 
00050   // vector of selected Super Modules (Defaults to all 18).
00051   superModules_.reserve(18);
00052   for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
00053   superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00054 
00055   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00056     int ism = superModules_[i];
00057     i01_[ism-1] = 0;
00058     i02_[ism-1] = 0;
00059   }
00060 
00061   for ( int i=0; i<3; i++) {
00062     h01_[0][i] = 0;
00063     h01ProjEta_[0][i] = 0;
00064     h01ProjPhi_[0][i] = 0;
00065     h01_[1][i] = 0;
00066     h01ProjEta_[1][i] = 0;
00067     h01ProjPhi_[1][i] = 0;
00068   }
00069 
00070   for ( int i=0; i<2; i++) {
00071     h02_[0][i] = 0;
00072     h02ProjEta_[0][i] = 0;
00073     h02ProjPhi_[0][i] = 0;
00074     h02_[1][i] = 0;
00075     h02ProjEta_[1][i] = 0;
00076     h02ProjPhi_[1][i] = 0;
00077   }
00078 
00079 }
00080 
00081 EEOccupancyClient::~EEOccupancyClient() {
00082 
00083 }
00084 
00085 void EEOccupancyClient::beginJob(void) {
00086 
00087   dqmStore_ = edm::Service<DQMStore>().operator->();
00088 
00089   if ( debug_ ) std::cout << "EEOccupancyClient: beginJob" << std::endl;
00090 
00091   ievt_ = 0;
00092   jevt_ = 0;
00093 
00094 }
00095 
00096 void EEOccupancyClient::beginRun(void) {
00097 
00098   if ( debug_ ) std::cout << "EEOccupancyClient: beginRun" << std::endl;
00099 
00100   jevt_ = 0;
00101 
00102   this->setup();
00103 
00104 }
00105 
00106 void EEOccupancyClient::endJob(void) {
00107 
00108   if ( debug_ ) std::cout << "EEOccupancyClient: endJob, ievt = " << ievt_ << std::endl;
00109 
00110   this->cleanup();
00111 
00112 }
00113 
00114 void EEOccupancyClient::endRun(void) {
00115 
00116   if ( debug_ ) std::cout << "EEOccupancyClient: endRun, jevt = " << jevt_ << std::endl;
00117 
00118   this->cleanup();
00119 
00120 }
00121 
00122 void EEOccupancyClient::setup(void) {
00123 
00124   dqmStore_->setCurrentFolder( prefixME_ + "/EEOccupancyClient" );
00125 
00126 }
00127 
00128 void EEOccupancyClient::cleanup(void) {
00129 
00130   if ( ! enableCleanup_ ) return;
00131 
00132   if ( cloneME_ ) {
00133 
00134     for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00135       int ism = superModules_[i];
00136       if ( i01_[ism-1] ) delete i01_[ism-1];
00137       if ( i02_[ism-1] ) delete i02_[ism-1];
00138     }
00139 
00140     for ( int i=0; i<3; ++i ) {
00141       if ( h01_[0][i] ) delete h01_[0][i];
00142       if ( h01ProjEta_[0][i] ) delete h01ProjEta_[0][i];
00143       if ( h01ProjPhi_[0][i] ) delete h01ProjPhi_[0][i];
00144       if ( h01_[1][i] ) delete h01_[1][i];
00145       if ( h01ProjEta_[1][i] ) delete h01ProjEta_[1][i];
00146       if ( h01ProjPhi_[1][i] ) delete h01ProjPhi_[1][i];
00147     }
00148 
00149     for ( int i=0; i<2; ++i ) {
00150       if ( h02_[0][i] ) delete h02_[0][i];
00151       if ( h02ProjEta_[0][i] ) delete h02ProjEta_[0][i];
00152       if ( h02ProjPhi_[0][i] ) delete h02ProjPhi_[0][i];
00153       if ( h01_[1][i] ) delete h01_[1][i];
00154       if ( h01ProjEta_[1][i] ) delete h01ProjEta_[1][i];
00155       if ( h01ProjPhi_[1][i] ) delete h01ProjPhi_[1][i];
00156     }
00157 
00158   }
00159 
00160   for ( int i=0; i<3; i++) {
00161     h01_[0][i] = 0;
00162     h01ProjEta_[0][i] = 0;
00163     h01ProjPhi_[0][i] = 0;
00164     h01_[1][i] = 0;
00165     h01ProjEta_[1][i] = 0;
00166     h01ProjPhi_[1][i] = 0;
00167   }
00168 
00169   for ( int i=0; i<2; i++) {
00170     h02_[0][i] = 0;
00171     h02ProjEta_[0][i] = 0;
00172     h02ProjPhi_[0][i] = 0;
00173     h02_[1][i] = 0;
00174     h02ProjEta_[1][i] = 0;
00175     h02ProjPhi_[1][i] = 0;
00176   }
00177 
00178 }
00179 
00180 #ifdef WITH_ECAL_COND_DB
00181 bool EEOccupancyClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00182 
00183   status = true;
00184 
00185   EcalLogicID ecid;
00186 
00187   MonOccupancyDat o;
00188   std::map<EcalLogicID, MonOccupancyDat> dataset;
00189 
00190   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00191 
00192     int ism = superModules_[i];
00193 
00194     if ( verbose_ ) {
00195       std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00196       std::cout << std::endl;
00197     }
00198 
00199     const float n_min_tot = 1000.;
00200     const float n_min_bin = 10.;
00201 
00202     float num01, num02;
00203     float mean01, mean02;
00204     float rms01, rms02;
00205 
00206     for ( int ix = 1; ix <= 50; ix++ ) {
00207       for ( int iy = 1; iy <= 50; iy++ ) {
00208 
00209         int jx = ix + Numbers::ix0EE(ism);
00210         int jy = iy + Numbers::iy0EE(ism);
00211 
00212         if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00213 
00214         if ( ! Numbers::validEE(ism, jx, jy) ) continue;
00215 
00216         num01  = num02  = -1.;
00217         mean01 = mean02 = -1.;
00218         rms01  = rms02  = -1.;
00219 
00220         bool update_channel = false;
00221 
00222         if ( i01_[ism-1] && i01_[ism-1]->GetEntries() >= n_min_tot ) {
00223           num01 = i01_[ism-1]->GetBinContent(i01_[ism-1]->GetBin(ix, iy));
00224           if ( num01 >= n_min_bin ) update_channel = true;
00225         }
00226 
00227         if ( i02_[ism-1] && i02_[ism-1]->GetEntries() >= n_min_tot ) {
00228           num02 = i02_[ism-1]->GetBinEntries(i02_[ism-1]->GetBin(ix, iy));
00229           if ( num02 >= n_min_bin ) {
00230             mean02 = i02_[ism-1]->GetBinContent(ix, iy);
00231             rms02  = i02_[ism-1]->GetBinError(ix, iy);
00232           }
00233         }
00234 
00235         if ( update_channel ) {
00236 
00237           if ( Numbers::icEE(ism, jx, jy) == 1 ) {
00238 
00239             if ( verbose_ ) {
00240               std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00241               std::cout << "Digi (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01  << " " << mean01 << " " << rms01  << std::endl;
00242               std::cout << "RecHitThr (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num02  << " " << mean02 << " " << rms02  << std::endl;
00243               std::cout << std::endl;
00244             }
00245 
00246           }
00247 
00248           o.setEventsOverLowThreshold(int(num01));
00249           o.setEventsOverHighThreshold(int(num02));
00250 
00251           o.setAvgEnergy(mean02);
00252 
00253           int ic = Numbers::indexEE(ism, jx, jy);
00254 
00255           if ( ic == -1 ) continue;
00256 
00257           if ( econn ) {
00258             ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
00259             dataset[ecid] = o;
00260           }
00261 
00262         }
00263 
00264       }
00265     }
00266 
00267   }
00268 
00269   if ( econn ) {
00270     try {
00271       if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
00272       if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00273       if ( verbose_ ) std::cout << "done." << std::endl;
00274     } catch (std::runtime_error &e) {
00275       std::cerr << e.what() << std::endl;
00276     }
00277   }
00278 
00279   return true;
00280 
00281 }
00282 #endif
00283 
00284 void EEOccupancyClient::analyze(void) {
00285 
00286   ievt_++;
00287   jevt_++;
00288   if ( ievt_ % 10 == 0 ) {
00289     if ( debug_ ) std::cout << "EEOccupancyClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00290   }
00291 
00292   MonitorElement* me;
00293 
00294   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00295 
00296     int ism = superModules_[i];
00297 
00298     me = dqmStore_->get( prefixME_ + "/EEOccupancyTask/EEOT digi occupancy " + Numbers::sEE(ism) );
00299     i01_[ism-1] = UtilsClient::getHisto( me, cloneME_, i01_[ism-1] );
00300 
00301     me = dqmStore_->get( prefixME_ + "/EEOccupancyTask/EEOT rec hit energy " + Numbers::sEE(ism) );
00302     i02_[ism-1] = UtilsClient::getHisto( me, cloneME_, i02_[ism-1] );
00303 
00304   }
00305 
00306   me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE -" );
00307   h01_[0][0] = UtilsClient::getHisto( me, cloneME_, h01_[0][0] );
00308 
00309   me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE - projection eta" );
00310   h01ProjEta_[0][0] = UtilsClient::getHisto( me, cloneME_, h01ProjEta_[0][0] );
00311 
00312   me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE - projection phi" );
00313   h01ProjPhi_[0][0] = UtilsClient::getHisto( me, cloneME_, h01ProjPhi_[0][0] );
00314 
00315   me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE +" );
00316   h01_[1][0] = UtilsClient::getHisto( me, cloneME_, h01_[1][0] );
00317 
00318   me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE + projection eta" );
00319   h01ProjEta_[1][0] = UtilsClient::getHisto( me, cloneME_, h01ProjEta_[1][0] );
00320 
00321   me = dqmStore_->get( "/EEOccupancyTask/EEOT digi occupancy EE + projection phi" );
00322   h01ProjPhi_[1][0] = UtilsClient::getHisto( me, cloneME_, h01ProjPhi_[1][0] );
00323 
00324   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE -" );
00325   h01_[0][1] = UtilsClient::getHisto( me, cloneME_, h01_[0][1] );
00326 
00327   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE - projection eta" );
00328   h01ProjEta_[0][1] = UtilsClient::getHisto( me, cloneME_, h01ProjEta_[0][1] );
00329 
00330   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE - projection phi" );
00331   h01ProjPhi_[0][1] = UtilsClient::getHisto( me, cloneME_, h01ProjPhi_[0][1] );
00332 
00333   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE +" );
00334   h01_[1][1] = UtilsClient::getHisto( me, cloneME_, h01_[1][1] );
00335 
00336   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE + projection eta" );
00337   h01ProjEta_[1][1] = UtilsClient::getHisto( me, cloneME_, h01ProjEta_[1][1] );
00338 
00339   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit occupancy EE + projection phi" );
00340   h01ProjPhi_[1][1] = UtilsClient::getHisto( me, cloneME_, h01ProjPhi_[1][1] );
00341 
00342   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE -" );
00343   h01_[0][2] = UtilsClient::getHisto( me, cloneME_, h01_[0][2] );
00344 
00345   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE - projection eta" );
00346   h01ProjEta_[0][2] = UtilsClient::getHisto( me, cloneME_, h01ProjEta_[0][2] );
00347 
00348   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE - projection phi" );
00349   h01ProjPhi_[0][2] = UtilsClient::getHisto( me, cloneME_, h01ProjPhi_[0][2] );
00350 
00351   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE +" );
00352   h01_[1][2] = UtilsClient::getHisto( me, cloneME_, h01_[1][2] );
00353 
00354   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE + projection eta" );
00355   h01ProjEta_[1][2] = UtilsClient::getHisto( me, cloneME_, h01ProjEta_[1][2] );
00356 
00357   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi occupancy EE + projection phi" );
00358   h01ProjPhi_[1][2] = UtilsClient::getHisto( me, cloneME_, h01ProjPhi_[1][2] );
00359 
00360   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE -" );
00361   h02_[0][0] = UtilsClient::getHisto( me, cloneME_, h02_[0][0] );
00362 
00363   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE - projection eta" );
00364   h02ProjEta_[0][0] = UtilsClient::getHisto( me, cloneME_, h02ProjEta_[0][0] );
00365 
00366   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE - projection phi" );
00367   h02ProjPhi_[0][0] = UtilsClient::getHisto( me, cloneME_, h02ProjPhi_[0][0] );
00368 
00369   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE +" );
00370   h02_[1][0] = UtilsClient::getHisto( me, cloneME_, h02_[1][0] );
00371 
00372   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE + projection eta" );
00373   h02ProjEta_[1][0] = UtilsClient::getHisto( me, cloneME_, h02ProjEta_[1][0] );
00374 
00375   me = dqmStore_->get( "/EEOccupancyTask/EEOT rec hit thr occupancy EE + projection phi" );
00376   h02ProjPhi_[1][0] = UtilsClient::getHisto( me, cloneME_, h02ProjPhi_[1][0] );
00377 
00378   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE -" );
00379   h02_[0][1] = UtilsClient::getHisto( me, cloneME_, h02_[0][1] );
00380 
00381   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE - projection eta" );
00382   h02ProjEta_[0][1] = UtilsClient::getHisto( me, cloneME_, h02ProjEta_[0][1] );
00383 
00384   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE - projection phi" );
00385   h02ProjPhi_[0][1] = UtilsClient::getHisto( me, cloneME_, h02ProjPhi_[0][1] );
00386 
00387   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE +" );
00388   h02_[1][1] = UtilsClient::getHisto( me, cloneME_, h02_[1][1] );
00389 
00390   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE + projection eta" );
00391   h02ProjEta_[1][1] = UtilsClient::getHisto( me, cloneME_, h02ProjEta_[1][1] );
00392 
00393   me = dqmStore_->get( "/EEOccupancyTask/EEOT TP digi thr occupancy EE + projection phi" );
00394   h02ProjPhi_[1][1] = UtilsClient::getHisto( me, cloneME_, h02ProjPhi_[1][1] );
00395 
00396 }
00397