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 "DataFormats/EcalDetId/interface/EEDetId.h"
00034
00035 #include "DQM/EcalEndcapMonitorClient/interface/EETimingClient.h"
00036
00037 EETimingClient::EETimingClient(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(18);
00056 for ( unsigned int i = 1; i <= 18; 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 h01_[ism-1] = 0;
00064 h02_[ism-1] = 0;
00065
00066 meh01_[ism-1] = 0;
00067 meh02_[ism-1] = 0;
00068
00069 }
00070
00071 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00072
00073 int ism = superModules_[i];
00074
00075 meg01_[ism-1] = 0;
00076
00077 mea01_[ism-1] = 0;
00078
00079 mep01_[ism-1] = 0;
00080
00081 mer01_[ism-1] = 0;
00082
00083 }
00084
00085 expectedMean_ = 0.0;
00086 discrepancyMean_ = 25.0;
00087 RMSThreshold_ = 125.;
00088
00089 }
00090
00091 EETimingClient::~EETimingClient() {
00092
00093 }
00094
00095 void EETimingClient::beginJob(void) {
00096
00097 dqmStore_ = edm::Service<DQMStore>().operator->();
00098
00099 if ( debug_ ) std::cout << "EETimingClient: beginJob" << std::endl;
00100
00101 ievt_ = 0;
00102 jevt_ = 0;
00103
00104 }
00105
00106 void EETimingClient::beginRun(void) {
00107
00108 if ( debug_ ) std::cout << "EETimingClient: beginRun" << std::endl;
00109
00110 jevt_ = 0;
00111
00112 this->setup();
00113
00114 }
00115
00116 void EETimingClient::endJob(void) {
00117
00118 if ( debug_ ) std::cout << "EETimingClient: endJob, ievt = " << ievt_ << std::endl;
00119
00120 this->cleanup();
00121
00122 }
00123
00124 void EETimingClient::endRun(void) {
00125
00126 if ( debug_ ) std::cout << "EETimingClient: endRun, jevt = " << jevt_ << std::endl;
00127
00128 this->cleanup();
00129
00130 }
00131
00132 void EETimingClient::setup(void) {
00133
00134 char histo[200];
00135
00136 dqmStore_->setCurrentFolder( prefixME_ + "/EETimingClient" );
00137
00138 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00139
00140 int ism = superModules_[i];
00141
00142 if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
00143 sprintf(histo, "EETMT timing quality %s", Numbers::sEE(ism).c_str());
00144 meg01_[ism-1] = dqmStore_->book2D(histo, histo, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
00145 meg01_[ism-1]->setAxisTitle("ix", 1);
00146 if ( ism >= 1 && ism <= 9 ) meg01_[ism-1]->setAxisTitle("101-ix", 1);
00147 meg01_[ism-1]->setAxisTitle("iy", 2);
00148
00149 if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
00150 sprintf(histo, "EETMT timing %s", Numbers::sEE(ism).c_str());
00151 mea01_[ism-1] = dqmStore_->book1D(histo, histo, 850, 0., 850.);
00152 mea01_[ism-1]->setAxisTitle("channel", 1);
00153 mea01_[ism-1]->setAxisTitle("time (ns)", 2);
00154
00155 if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
00156 sprintf(histo, "EETMT timing mean %s", Numbers::sEE(ism).c_str());
00157 mep01_[ism-1] = dqmStore_->book1D(histo, histo, 100, -50., 50.);
00158 mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
00159
00160 if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
00161 sprintf(histo, "EETMT timing rms %s", Numbers::sEE(ism).c_str());
00162 mer01_[ism-1] = dqmStore_->book1D(histo, histo, 100, 0.0, 150.0);
00163 mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
00164
00165 }
00166
00167 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00168
00169 int ism = superModules_[i];
00170
00171 if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
00172
00173 for ( int ix = 1; ix <= 50; ix++ ) {
00174 for ( int iy = 1; iy <= 50; iy++ ) {
00175
00176 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 6. );
00177
00178 int jx = ix + Numbers::ix0EE(ism);
00179 int jy = iy + Numbers::iy0EE(ism);
00180
00181 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00182
00183 if ( Numbers::validEE(ism, jx, jy) ) {
00184 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 2. );
00185 }
00186
00187 }
00188 }
00189
00190 if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
00191 if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
00192 if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
00193
00194 }
00195
00196 }
00197
00198 void EETimingClient::cleanup(void) {
00199
00200 if ( ! enableCleanup_ ) return;
00201
00202 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00203
00204 int ism = superModules_[i];
00205
00206 if ( cloneME_ ) {
00207 if ( h01_[ism-1] ) delete h01_[ism-1];
00208 if ( h02_[ism-1] ) delete h02_[ism-1];
00209 }
00210
00211 h01_[ism-1] = 0;
00212 h02_[ism-1] = 0;
00213
00214 meh01_[ism-1] = 0;
00215 meh02_[ism-1] = 0;
00216
00217 }
00218
00219 dqmStore_->setCurrentFolder( prefixME_ + "/EETimingClient" );
00220
00221 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00222
00223 int ism = superModules_[i];
00224
00225 if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
00226 meg01_[ism-1] = 0;
00227
00228 if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
00229 mea01_[ism-1] = 0;
00230
00231 if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
00232 mep01_[ism-1] = 0;
00233
00234 if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
00235 mer01_[ism-1] = 0;
00236
00237 }
00238
00239 }
00240
00241 #ifdef WITH_ECAL_COND_DB
00242 bool EETimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00243
00244 status = true;
00245
00246 EcalLogicID ecid;
00247
00248 MonTimingCrystalDat t;
00249 std::map<EcalLogicID, MonTimingCrystalDat> dataset;
00250
00251 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00252
00253 int ism = superModules_[i];
00254
00255 if ( verbose_ ) {
00256 std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00257 std::cout << std::endl;
00258 UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
00259 }
00260
00261 float num01;
00262 float mean01;
00263 float rms01;
00264
00265 for ( int ix = 1; ix <= 50; ix++ ) {
00266 for ( int iy = 1; iy <= 50; iy++ ) {
00267
00268 int jx = ix + Numbers::ix0EE(ism);
00269 int jy = iy + Numbers::iy0EE(ism);
00270
00271 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00272
00273 if ( ! Numbers::validEE(ism, jx, jy) ) continue;
00274
00275 bool update01;
00276
00277 update01 = UtilsClient::getBinStatistics(h01_[ism-1], ix, iy, num01, mean01, rms01);
00278
00279 mean01 -= 50.;
00280
00281 if ( update01 ) {
00282
00283 if ( Numbers::icEE(ism, jx, jy) == 1 ) {
00284
00285 if ( verbose_ ) {
00286 std::cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00287 std::cout << "crystal (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
00288 std::cout << std::endl;
00289 }
00290
00291 }
00292
00293 t.setTimingMean(mean01);
00294 t.setTimingRMS(rms01);
00295
00296 if ( UtilsClient::getBinStatus(meg01_[ism-1], ix, iy) ) {
00297 t.setTaskStatus(true);
00298 } else {
00299 t.setTaskStatus(false);
00300 }
00301
00302 status = status && UtilsClient::getBinQuality(meg01_[ism-1], ix, iy);
00303
00304 int ic = Numbers::indexEE(ism, jx, jy);
00305
00306 if ( ic == -1 ) continue;
00307
00308 if ( econn ) {
00309 ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
00310 dataset[ecid] = t;
00311 }
00312
00313 }
00314
00315 }
00316 }
00317
00318 }
00319
00320 if ( econn ) {
00321 try {
00322 if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
00323 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00324 if ( verbose_ ) std::cout << "done." << std::endl;
00325 } catch (std::runtime_error &e) {
00326 std::cerr << e.what() << std::endl;
00327 }
00328 }
00329
00330 return true;
00331
00332 }
00333 #endif
00334
00335 void EETimingClient::analyze(void) {
00336
00337 ievt_++;
00338 jevt_++;
00339 if ( ievt_ % 10 == 0 ) {
00340 if ( debug_ ) std::cout << "EETimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00341 }
00342
00343 uint32_t bits01 = 0;
00344 bits01 |= 1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING;
00345
00346 char histo[200];
00347
00348 MonitorElement* me;
00349
00350 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00351
00352 int ism = superModules_[i];
00353
00354 sprintf(histo, (prefixME_ + "/EETimingTask/EETMT timing %s").c_str(), Numbers::sEE(ism).c_str());
00355 me = dqmStore_->get(histo);
00356 h01_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h01_[ism-1] );
00357 meh01_[ism-1] = me;
00358
00359 sprintf(histo, (prefixME_ + "/EETimingTask/EETMT timing vs amplitude %s").c_str(), Numbers::sEE(ism).c_str());
00360 me = dqmStore_->get(histo);
00361 h02_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h02_[ism-1] );
00362 meh02_[ism-1] = me;
00363
00364 if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
00365 if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
00366 if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
00367 if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
00368
00369 for ( int ix = 1; ix <= 50; ix++ ) {
00370 for ( int iy = 1; iy <= 50; iy++ ) {
00371
00372 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ix, iy, 6.);
00373
00374 int jx = ix + Numbers::ix0EE(ism);
00375 int jy = iy + Numbers::iy0EE(ism);
00376
00377 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00378
00379 if ( Numbers::validEE(ism, jx, jy) ) {
00380 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ix, iy, 2. );
00381 }
00382
00383 bool update01;
00384
00385 float num01;
00386 float mean01;
00387 float rms01;
00388
00389 update01 = UtilsClient::getBinStatistics(h01_[ism-1], ix, iy, num01, mean01, rms01);
00390
00391 mean01 -= 50.;
00392
00393 if ( update01 ) {
00394
00395 float val;
00396
00397 val = 1.;
00398 if ( std::abs(mean01 - expectedMean_) > discrepancyMean_ )
00399 val = 0.;
00400 if ( rms01 > RMSThreshold_ )
00401 val = 0.;
00402 if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ix, iy, val);
00403
00404 int ic = Numbers::icEE(ism, jx, jy);
00405
00406 if ( ic != -1 ) {
00407 if ( mea01_[ism-1] ) {
00408 mea01_[ism-1]->setBinContent(ic, mean01);
00409 mea01_[ism-1]->setBinError(ic, rms01);
00410 }
00411
00412 if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
00413 if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
00414 }
00415
00416 }
00417
00418 if ( Masks::maskChannel(ism, ix, iy, bits01, EcalEndcap) ) UtilsClient::maskBinContent( meg01_[ism-1], ix, iy );
00419
00420 }
00421 }
00422
00423 }
00424
00425 }
00426