00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <memory>
00011 #include <iostream>
00012 #include <fstream>
00013 #include <iomanip>
00014 #include <math.h>
00015
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019
00020 #ifdef WITH_ECAL_COND_DB
00021 #include "OnlineDB/EcalCondDB/interface/MonTimingCrystalDat.h"
00022 #include "OnlineDB/EcalCondDB/interface/RunCrystalErrorsDat.h"
00023 #include "OnlineDB/EcalCondDB/interface/RunTTErrorsDat.h"
00024 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00025 #include "DQM/EcalCommon/interface/LogicID.h"
00026 #endif
00027
00028 #include "DQM/EcalCommon/interface/Masks.h"
00029
00030 #include "DQM/EcalCommon/interface/UtilsClient.h"
00031 #include "DQM/EcalCommon/interface/Numbers.h"
00032
00033 #include "DQM/EcalBarrelMonitorClient/interface/EBTimingClient.h"
00034
00035 EBTimingClient::EBTimingClient(const edm::ParameterSet& ps) {
00036
00037
00038 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00039
00040
00041 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00042
00043
00044 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00045
00046
00047 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00048
00049
00050 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00051
00052
00053 superModules_.reserve(36);
00054 for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00055 superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00056
00057 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00058
00059 int ism = superModules_[i];
00060
00061 h01_[ism-1] = 0;
00062 h02_[ism-1] = 0;
00063
00064 meh01_[ism-1] = 0;
00065 meh02_[ism-1] = 0;
00066
00067 }
00068
00069 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00070
00071 int ism = superModules_[i];
00072
00073 meg01_[ism-1] = 0;
00074
00075 mea01_[ism-1] = 0;
00076
00077 mep01_[ism-1] = 0;
00078
00079 mer01_[ism-1] = 0;
00080
00081 }
00082
00083 expectedMean_ = 0.0;
00084 discrepancyMean_ = 12.5;
00085 RMSThreshold_ = 62.5;
00086
00087 }
00088
00089 EBTimingClient::~EBTimingClient() {
00090
00091 }
00092
00093 void EBTimingClient::beginJob(void) {
00094
00095 dqmStore_ = edm::Service<DQMStore>().operator->();
00096
00097 if ( debug_ ) std::cout << "EBTimingClient: beginJob" << std::endl;
00098
00099 ievt_ = 0;
00100 jevt_ = 0;
00101
00102 }
00103
00104 void EBTimingClient::beginRun(void) {
00105
00106 if ( debug_ ) std::cout << "EBTimingClient: beginRun" << std::endl;
00107
00108 jevt_ = 0;
00109
00110 this->setup();
00111
00112 }
00113
00114 void EBTimingClient::endJob(void) {
00115
00116 if ( debug_ ) std::cout << "EBTimingClient: endJob, ievt = " << ievt_ << std::endl;
00117
00118 this->cleanup();
00119
00120 }
00121
00122 void EBTimingClient::endRun(void) {
00123
00124 if ( debug_ ) std::cout << "EBTimingClient: endRun, jevt = " << jevt_ << std::endl;
00125
00126 this->cleanup();
00127
00128 }
00129
00130 void EBTimingClient::setup(void) {
00131
00132 char histo[200];
00133
00134 dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
00135
00136 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00137
00138 int ism = superModules_[i];
00139
00140 if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
00141 sprintf(histo, "EBTMT timing quality %s", Numbers::sEB(ism).c_str());
00142 meg01_[ism-1] = dqmStore_->book2D(histo, histo, 85, 0., 85., 20, 0., 20.);
00143 meg01_[ism-1]->setAxisTitle("ieta", 1);
00144 meg01_[ism-1]->setAxisTitle("iphi", 2);
00145
00146 if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
00147 sprintf(histo, "EBTMT timing %s", Numbers::sEB(ism).c_str());
00148 mea01_[ism-1] = dqmStore_->book1D(histo, histo, 1700, 0., 1700.);
00149 mea01_[ism-1]->setAxisTitle("channel", 1);
00150 mea01_[ism-1]->setAxisTitle("time (ns)", 2);
00151
00152 if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
00153 sprintf(histo, "EBTMT timing mean %s", Numbers::sEB(ism).c_str());
00154 mep01_[ism-1] = dqmStore_->book1D(histo, histo, 100, -50.0, 50.0);
00155 mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
00156
00157 if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
00158 sprintf(histo, "EBTMT timing rms %s", Numbers::sEB(ism).c_str());
00159 mer01_[ism-1] = dqmStore_->book1D(histo, histo, 100, 0.0, 150.0);
00160 mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
00161
00162 }
00163
00164 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00165
00166 int ism = superModules_[i];
00167
00168 if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
00169
00170 for ( int ie = 1; ie <= 85; ie++ ) {
00171 for ( int ip = 1; ip <= 20; ip++ ) {
00172
00173 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ie, ip, 2. );
00174
00175 }
00176 }
00177
00178 if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
00179 if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
00180 if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
00181
00182 }
00183
00184 }
00185
00186 void EBTimingClient::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 ( h01_[ism-1] ) delete h01_[ism-1];
00196 if ( h02_[ism-1] ) delete h02_[ism-1];
00197 }
00198
00199 h01_[ism-1] = 0;
00200 h02_[ism-1] = 0;
00201
00202 meh01_[ism-1] = 0;
00203 meh02_[ism-1] = 0;
00204
00205 }
00206
00207 dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
00208
00209 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00210
00211 int ism = superModules_[i];
00212
00213 if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
00214 meg01_[ism-1] = 0;
00215
00216 if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
00217 mea01_[ism-1] = 0;
00218
00219 if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
00220 mep01_[ism-1] = 0;
00221
00222 if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
00223 mer01_[ism-1] = 0;
00224
00225 }
00226
00227 }
00228
00229 #ifdef WITH_ECAL_COND_DB
00230 bool EBTimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00231
00232 status = true;
00233
00234 EcalLogicID ecid;
00235
00236 MonTimingCrystalDat t;
00237 std::map<EcalLogicID, MonTimingCrystalDat> dataset;
00238
00239 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00240
00241 int ism = superModules_[i];
00242
00243 if ( verbose_ ) {
00244 std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00245 std::cout << std::endl;
00246 UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
00247 }
00248
00249 float num01;
00250 float mean01;
00251 float rms01;
00252
00253 for ( int ie = 1; ie <= 85; ie++ ) {
00254 for ( int ip = 1; ip <= 20; ip++ ) {
00255
00256 bool update01;
00257
00258 update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01);
00259
00260 mean01 -= 50.;
00261
00262 if ( update01 ) {
00263
00264 if ( Numbers::icEB(ism, ie, ip) == 1 ) {
00265
00266 if ( verbose_ ) {
00267 std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00268 std::cout << "crystal (" << ie << "," << ip << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
00269 std::cout << std::endl;
00270 }
00271
00272 }
00273
00274 t.setTimingMean(mean01);
00275 t.setTimingRMS(rms01);
00276
00277 if ( UtilsClient::getBinStatus(meg01_[ism-1], ie, ip) ) {
00278 t.setTaskStatus(true);
00279 } else {
00280 t.setTaskStatus(false);
00281 }
00282
00283 status = status && UtilsClient::getBinQuality(meg01_[ism-1], ie, ip);
00284
00285 int ic = Numbers::indexEB(ism, ie, ip);
00286
00287 if ( econn ) {
00288 ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
00289 dataset[ecid] = t;
00290 }
00291
00292 }
00293
00294 }
00295 }
00296
00297 }
00298
00299 if ( econn ) {
00300 try {
00301 if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
00302 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00303 if ( verbose_ ) std::cout << "done." << std::endl;
00304 } catch (std::runtime_error &e) {
00305 std::cerr << e.what() << std::endl;
00306 }
00307 }
00308
00309 return true;
00310
00311 }
00312 #endif
00313
00314 void EBTimingClient::analyze(void) {
00315
00316 ievt_++;
00317 jevt_++;
00318 if ( ievt_ % 10 == 0 ) {
00319 if ( debug_ ) std::cout << "EBTimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00320 }
00321
00322 uint32_t bits01 = 0;
00323 bits01 |= 1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING;
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_ + "/EBTimingTask/EBTMT timing %s").c_str(), Numbers::sEB(ism).c_str());
00334 me = dqmStore_->get(histo);
00335 h01_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h01_[ism-1] );
00336 meh01_[ism-1] = me;
00337
00338 sprintf(histo, (prefixME_ + "/EBTimingTask/EBTMT timing vs amplitude %s").c_str(), Numbers::sEB(ism).c_str());
00339 me = dqmStore_->get(histo);
00340 h02_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h02_[ism-1] );
00341 meh02_[ism-1] = me;
00342
00343 if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
00344 if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
00345 if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
00346 if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
00347
00348 for ( int ie = 1; ie <= 85; ie++ ) {
00349 for ( int ip = 1; ip <= 20; ip++ ) {
00350
00351 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, 2.);
00352
00353 bool update01;
00354
00355 float num01;
00356 float mean01;
00357 float rms01;
00358
00359 update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01);
00360
00361 mean01 -= 50.;
00362
00363 if ( update01 ) {
00364
00365 float val;
00366
00367 val = 1.;
00368 if ( std::abs(mean01 - expectedMean_) > discrepancyMean_ )
00369 val = 0.;
00370 if ( rms01 > RMSThreshold_ )
00371 val = 0.;
00372 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, val);
00373
00374 int ic = Numbers::icEB(ism, ie, ip);
00375
00376 if ( mea01_[ism-1] ) {
00377 mea01_[ism-1]->setBinContent(ic, mean01);
00378 mea01_[ism-1]->setBinError(ic, rms01);
00379 }
00380 if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
00381 if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
00382
00383 }
00384
00385 if ( Masks::maskChannel(ism, ie, ip, bits01, EcalBarrel) ) UtilsClient::maskBinContent( meg01_[ism-1], ie, ip );
00386
00387 }
00388 }
00389
00390 }
00391
00392 }
00393