CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalBarrelMonitorClient/src/EBOccupancyClient.cc

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