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 #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 "DataFormats/EcalDetId/interface/EEDetId.h"
00036
00037 #include "DQM/EcalEndcapMonitorClient/interface/EEPedestalOnlineClient.h"
00038
00039 EEPedestalOnlineClient::EEPedestalOnlineClient(const edm::ParameterSet& ps) {
00040
00041
00042 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00043
00044
00045 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00046
00047
00048 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00049
00050
00051 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00052
00053
00054 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00055
00056
00057 superModules_.reserve(18);
00058 for ( unsigned int i = 1; i <= 18; 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_ = 4.0;
00084 RMSThresholdInternal_ = 8.0;
00085
00086 }
00087
00088 EEPedestalOnlineClient::~EEPedestalOnlineClient() {
00089
00090 }
00091
00092 void EEPedestalOnlineClient::beginJob(void) {
00093
00094 dqmStore_ = edm::Service<DQMStore>().operator->();
00095
00096 if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginJob" << std::endl;
00097
00098 ievt_ = 0;
00099 jevt_ = 0;
00100
00101 }
00102
00103 void EEPedestalOnlineClient::beginRun(void) {
00104
00105 if ( debug_ ) std::cout << "EEPedestalOnlineClient: beginRun" << std::endl;
00106
00107 jevt_ = 0;
00108
00109 this->setup();
00110
00111 }
00112
00113 void EEPedestalOnlineClient::endJob(void) {
00114
00115 if ( debug_ ) std::cout << "EEPedestalOnlineClient: endJob, ievt = " << ievt_ << std::endl;
00116
00117 this->cleanup();
00118
00119 }
00120
00121 void EEPedestalOnlineClient::endRun(void) {
00122
00123 if ( debug_ ) std::cout << "EEPedestalOnlineClient: endRun, jevt = " << jevt_ << std::endl;
00124
00125 this->cleanup();
00126
00127 }
00128
00129 void EEPedestalOnlineClient::setup(void) {
00130
00131 std::string name;
00132
00133 dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
00134
00135 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00136
00137 int ism = superModules_[i];
00138
00139 if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00140 name = "EEPOT pedestal quality G12 " + Numbers::sEE(ism);
00141 meg03_[ism-1] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
00142 meg03_[ism-1]->setAxisTitle("ix", 1);
00143 if ( ism >= 1 && ism <= 9 ) meg03_[ism-1]->setAxisTitle("101-ix", 1);
00144 meg03_[ism-1]->setAxisTitle("iy", 2);
00145
00146 if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00147 name = "EEPOT pedestal mean G12 " + Numbers::sEE(ism);
00148 mep03_[ism-1] = dqmStore_->book1D(name, name, 100, 150., 250.);
00149 mep03_[ism-1]->setAxisTitle("mean", 1);
00150
00151 if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00152 name = "EEPOT pedestal rms G12 " + Numbers::sEE(ism);
00153 mer03_[ism-1] = dqmStore_->book1D(name, name, 100, 0., 10.);
00154 mer03_[ism-1]->setAxisTitle("rms", 1);
00155
00156 }
00157
00158 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00159
00160 int ism = superModules_[i];
00161
00162 if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00163
00164 for ( int ix = 1; ix <= 50; ix++ ) {
00165 for ( int iy = 1; iy <= 50; iy++ ) {
00166
00167 meg03_[ism-1]->setBinContent( ix, iy, 6. );
00168
00169 int jx = ix + Numbers::ix0EE(ism);
00170 int jy = iy + Numbers::iy0EE(ism);
00171
00172 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00173
00174 if ( Numbers::validEE(ism, jx, jy) ) {
00175 meg03_[ism-1]->setBinContent( ix, iy, 2. );
00176 }
00177
00178 }
00179 }
00180
00181 if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00182 if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00183
00184 }
00185
00186 }
00187
00188 void EEPedestalOnlineClient::cleanup(void) {
00189
00190 if ( ! enableCleanup_ ) return;
00191
00192 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00193
00194 int ism = superModules_[i];
00195
00196 if ( cloneME_ ) {
00197 if ( h03_[ism-1] ) delete h03_[ism-1];
00198 }
00199
00200 h03_[ism-1] = 0;
00201
00202 }
00203
00204 dqmStore_->setCurrentFolder( prefixME_ + "/EEPedestalOnlineClient" );
00205
00206 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00207
00208 int ism = superModules_[i];
00209
00210 if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00211 meg03_[ism-1] = 0;
00212
00213 if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00214 mep03_[ism-1] = 0;
00215
00216 if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00217 mer03_[ism-1] = 0;
00218
00219 }
00220
00221 }
00222
00223 #ifdef WITH_ECAL_COND_DB
00224 bool EEPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00225
00226 status = true;
00227
00228 EcalLogicID ecid;
00229
00230 MonPedestalsOnlineDat p;
00231 std::map<EcalLogicID, MonPedestalsOnlineDat> dataset;
00232
00233 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00234
00235 int ism = superModules_[i];
00236
00237 if ( verbose_ ) {
00238 std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00239 std::cout << std::endl;
00240 UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
00241 }
00242
00243 float num03;
00244 float mean03;
00245 float rms03;
00246
00247 for ( int ix = 1; ix <= 50; ix++ ) {
00248 for ( int iy = 1; iy <= 50; iy++ ) {
00249
00250 int jx = ix + Numbers::ix0EE(ism);
00251 int jy = iy + Numbers::iy0EE(ism);
00252
00253 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00254
00255 if ( ! Numbers::validEE(ism, jx, jy) ) continue;
00256
00257 bool update03;
00258
00259 update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
00260
00261 if ( update03 ) {
00262
00263 if ( Numbers::icEE(ism, jx, jy) == 1 ) {
00264
00265 if ( verbose_ ) {
00266 std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00267 std::cout << "G12 (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num03 << " " << mean03 << " " << rms03 << std::endl;
00268 std::cout << std::endl;
00269 }
00270
00271 }
00272
00273 p.setADCMeanG12(mean03);
00274 p.setADCRMSG12(rms03);
00275
00276 if ( UtilsClient::getBinStatus(meg03_[ism-1], ix, iy) ) {
00277 p.setTaskStatus(true);
00278 } else {
00279 p.setTaskStatus(false);
00280 }
00281
00282 status = status && UtilsClient::getBinQuality(meg03_[ism-1], ix, iy);
00283
00284 int ic = Numbers::indexEE(ism, jx, jy);
00285
00286 if ( ic == -1 ) continue;
00287
00288 if ( econn ) {
00289 ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
00290 dataset[ecid] = p;
00291 }
00292
00293 }
00294
00295 }
00296 }
00297
00298 }
00299
00300 if ( econn ) {
00301 try {
00302 if ( verbose_ ) std::cout << "Inserting MonPedestalsOnlineDat ..." << std::endl;
00303 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00304 if ( verbose_ ) std::cout << "done." << std::endl;
00305 } catch (std::runtime_error &e) {
00306 std::cerr << e.what() << std::endl;
00307 }
00308 }
00309
00310 return true;
00311
00312 }
00313 #endif
00314
00315 void EEPedestalOnlineClient::analyze(void) {
00316
00317 ievt_++;
00318 jevt_++;
00319 if ( ievt_ % 10 == 0 ) {
00320 if ( debug_ ) std::cout << "EEPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00321 }
00322
00323 uint32_t bits03 = 0;
00324 bits03 |= 1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR;
00325 bits03 |= 1 << EcalDQMStatusHelper::PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR;
00326
00327 MonitorElement* me;
00328
00329 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00330
00331 int ism = superModules_[i];
00332
00333 me = dqmStore_->get( prefixME_ + "/EEPedestalOnlineTask/Gain12/EEPOT pedestal " + Numbers::sEE(ism) + " G12" );
00334 h03_[ism-1] = UtilsClient::getHisto( me, cloneME_, h03_[ism-1] );
00335
00336 if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00337 if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00338 if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00339
00340 for ( int ix = 1; ix <= 50; ix++ ) {
00341 for ( int iy = 1; iy <= 50; iy++ ) {
00342
00343 if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, 6.);
00344
00345 int jx = ix + Numbers::ix0EE(ism);
00346 int jy = iy + Numbers::iy0EE(ism);
00347
00348 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00349
00350 if ( Numbers::validEE(ism, jx, jy) ) {
00351 if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent( ix, iy, 2. );
00352 }
00353
00354
00355 float radius = std::sqrt((jx-50.)*(jx-50.)+(jy-50.)*(jy-50.));
00356
00357 bool update03;
00358
00359 float num03;
00360 float mean03;
00361 float rms03;
00362
00363 update03 = UtilsClient::getBinStatistics(h03_[ism-1], ix, iy, num03, mean03, rms03);
00364
00365 if ( update03 ) {
00366
00367 float val;
00368
00369 val = 1.;
00370 if ( std::abs(mean03 - expectedMean_) > discrepancyMean_ )
00371 val = 0.;
00372 if ( (radius >= 20. && rms03 > RMSThreshold_) || (radius < 20. && rms03 > RMSThresholdInternal_) )
00373 val = 0.;
00374 if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ix, iy, val);
00375
00376 if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
00377 if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
00378
00379 }
00380
00381 if ( Masks::maskChannel(ism, ix, iy, bits03, EcalEndcap) ) UtilsClient::maskBinContent( meg03_[ism-1], ix, iy );
00382
00383 }
00384 }
00385
00386 }
00387
00388 }
00389