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