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