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