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 "TCanvas.h"
00018 #include "TStyle.h"
00019
00020 #include "DQMServices/Core/interface/DQMStore.h"
00021
00022 #include "OnlineDB/EcalCondDB/interface/MonPedestalsOnlineDat.h"
00023 #include "OnlineDB/EcalCondDB/interface/RunCrystalErrorsDat.h"
00024 #include "OnlineDB/EcalCondDB/interface/RunTTErrorsDat.h"
00025
00026 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00027
00028 #include "CondTools/Ecal/interface/EcalErrorDictionary.h"
00029
00030 #include "DQM/EcalCommon/interface/EcalErrorMask.h"
00031 #include "DQM/EcalCommon/interface/UtilsClient.h"
00032 #include "DQM/EcalCommon/interface/LogicID.h"
00033 #include "DQM/EcalCommon/interface/Numbers.h"
00034
00035 #include <DQM/EcalBarrelMonitorClient/interface/EBPedestalOnlineClient.h>
00036
00037 using namespace cms;
00038 using namespace edm;
00039 using namespace std;
00040
00041 EBPedestalOnlineClient::EBPedestalOnlineClient(const ParameterSet& ps) {
00042
00043
00044 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00045
00046
00047 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00048
00049
00050 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00051
00052
00053 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00054
00055
00056 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00057
00058
00059 superModules_.reserve(36);
00060 for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00061 superModules_ = ps.getUntrackedParameter<vector<int> >("superModules", superModules_);
00062
00063 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00064
00065 int ism = superModules_[i];
00066
00067 h03_[ism-1] = 0;
00068
00069 }
00070
00071 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00072
00073 int ism = superModules_[i];
00074
00075 meg03_[ism-1] = 0;
00076
00077 mep03_[ism-1] = 0;
00078
00079 mer03_[ism-1] = 0;
00080
00081 }
00082
00083 expectedMean_ = 200.0;
00084 discrepancyMean_ = 25.0;
00085 RMSThreshold_ = 2.0;
00086
00087 }
00088
00089 EBPedestalOnlineClient::~EBPedestalOnlineClient() {
00090
00091 }
00092
00093 void EBPedestalOnlineClient::beginJob(DQMStore* dqmStore) {
00094
00095 dqmStore_ = dqmStore;
00096
00097 if ( debug_ ) cout << "EBPedestalOnlineClient: beginJob" << endl;
00098
00099 ievt_ = 0;
00100 jevt_ = 0;
00101
00102 }
00103
00104 void EBPedestalOnlineClient::beginRun(void) {
00105
00106 if ( debug_ ) cout << "EBPedestalOnlineClient: beginRun" << endl;
00107
00108 jevt_ = 0;
00109
00110 this->setup();
00111
00112 }
00113
00114 void EBPedestalOnlineClient::endJob(void) {
00115
00116 if ( debug_ ) cout << "EBPedestalOnlineClient: endJob, ievt = " << ievt_ << endl;
00117
00118 this->cleanup();
00119
00120 }
00121
00122 void EBPedestalOnlineClient::endRun(void) {
00123
00124 if ( debug_ ) cout << "EBPedestalOnlineClient: endRun, jevt = " << jevt_ << endl;
00125
00126 this->cleanup();
00127
00128 }
00129
00130 void EBPedestalOnlineClient::setup(void) {
00131
00132 char histo[200];
00133
00134 dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient" );
00135
00136 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00137
00138 int ism = superModules_[i];
00139
00140 if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00141 sprintf(histo, "EBPOT pedestal quality G12 %s", Numbers::sEB(ism).c_str());
00142 meg03_[ism-1] = dqmStore_->book2D(histo, histo, 85, 0., 85., 20, 0., 20.);
00143 meg03_[ism-1]->setAxisTitle("ieta", 1);
00144 meg03_[ism-1]->setAxisTitle("iphi", 2);
00145
00146 if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00147 sprintf(histo, "EBPOT pedestal mean G12 %s", Numbers::sEB(ism).c_str());
00148 mep03_[ism-1] = dqmStore_->book1D(histo, histo, 100, 150., 250.);
00149 mep03_[ism-1]->setAxisTitle("mean", 1);
00150
00151 if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00152 sprintf(histo, "EBPOT pedestal rms G12 %s", Numbers::sEB(ism).c_str());
00153 mer03_[ism-1] = dqmStore_->book1D(histo, histo, 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 ie = 1; ie <= 85; ie++ ) {
00165 for ( int ip = 1; ip <= 20; ip++ ) {
00166
00167 meg03_[ism-1]->setBinContent( ie, ip, 2. );
00168
00169 }
00170 }
00171
00172 if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00173 if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00174
00175 }
00176
00177 }
00178
00179 void EBPedestalOnlineClient::cleanup(void) {
00180
00181 if ( ! enableCleanup_ ) return;
00182
00183 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00184
00185 int ism = superModules_[i];
00186
00187 if ( cloneME_ ) {
00188 if ( h03_[ism-1] ) delete h03_[ism-1];
00189 }
00190
00191 h03_[ism-1] = 0;
00192
00193 }
00194
00195 dqmStore_->setCurrentFolder( prefixME_ + "/EBPedestalOnlineClient" );
00196
00197 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00198
00199 int ism = superModules_[i];
00200
00201 if ( meg03_[ism-1] ) dqmStore_->removeElement( meg03_[ism-1]->getName() );
00202 meg03_[ism-1] = 0;
00203
00204 if ( mep03_[ism-1] ) dqmStore_->removeElement( mep03_[ism-1]->getName() );
00205 mep03_[ism-1] = 0;
00206
00207 if ( mer03_[ism-1] ) dqmStore_->removeElement( mer03_[ism-1]->getName() );
00208 mer03_[ism-1] = 0;
00209
00210 }
00211
00212 }
00213
00214 bool EBPedestalOnlineClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status, bool flag) {
00215
00216 status = true;
00217
00218 if ( flag ) this->softReset(false);
00219
00220 EcalLogicID ecid;
00221
00222 MonPedestalsOnlineDat p;
00223 map<EcalLogicID, MonPedestalsOnlineDat> dataset;
00224
00225 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00226
00227 int ism = superModules_[i];
00228
00229 if ( verbose_ ) {
00230 cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << endl;
00231 cout << endl;
00232 UtilsClient::printBadChannels(meg03_[ism-1], h03_[ism-1]);
00233 }
00234
00235 float num03;
00236 float mean03;
00237 float rms03;
00238
00239 for ( int ie = 1; ie <= 85; ie++ ) {
00240 for ( int ip = 1; ip <= 20; ip++ ) {
00241
00242 bool update03;
00243
00244 update03 = UtilsClient::getBinStatistics(h03_[ism-1], ie, ip, num03, mean03, rms03);
00245
00246 if ( update03 ) {
00247
00248 if ( Numbers::icEB(ism, ie, ip) == 1 ) {
00249
00250 if ( verbose_ ) {
00251 cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << endl;
00252 cout << "G12 (" << ie << "," << ip << ") " << num03 << " " << mean03 << " " << rms03 << endl;
00253 cout << endl;
00254 }
00255
00256 }
00257
00258 p.setADCMeanG12(mean03);
00259 p.setADCRMSG12(rms03);
00260
00261 if ( UtilsClient::getBinStatus(meg03_[ism-1], ie, ip) ) {
00262 p.setTaskStatus(true);
00263 } else {
00264 p.setTaskStatus(false);
00265 }
00266
00267 status = status && UtilsClient::getBinQuality(meg03_[ism-1], ie, ip);
00268
00269 int ic = Numbers::indexEB(ism, ie, ip);
00270
00271 if ( econn ) {
00272 ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
00273 dataset[ecid] = p;
00274 }
00275
00276 }
00277
00278 }
00279 }
00280
00281 }
00282
00283 if ( econn ) {
00284 try {
00285 if ( verbose_ ) cout << "Inserting MonPedestalsOnlineDat ..." << endl;
00286 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00287 if ( verbose_ ) cout << "done." << endl;
00288 } catch (runtime_error &e) {
00289 cerr << e.what() << endl;
00290 }
00291 }
00292
00293 if ( ! flag ) this->softReset(true);
00294
00295 return true;
00296
00297 }
00298
00299 void EBPedestalOnlineClient::analyze(void) {
00300
00301 ievt_++;
00302 jevt_++;
00303 if ( ievt_ % 10 == 0 ) {
00304 if ( debug_ ) cout << "EBPedestalOnlineClient: ievt/jevt = " << ievt_ << "/" << jevt_ << endl;
00305 }
00306
00307 uint64_t bits03 = 0;
00308 bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_MEAN_WARNING");
00309 bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_RMS_WARNING");
00310 bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_MEAN_ERROR");
00311 bits03 |= EcalErrorDictionary::getMask("PEDESTAL_ONLINE_HIGH_GAIN_RMS_ERROR");
00312
00313 map<EcalLogicID, RunCrystalErrorsDat> mask1;
00314 map<EcalLogicID, RunTTErrorsDat> mask2;
00315
00316 EcalErrorMask::fetchDataSet(&mask1);
00317 EcalErrorMask::fetchDataSet(&mask2);
00318
00319 char histo[200];
00320
00321 MonitorElement* me;
00322
00323 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00324
00325 int ism = superModules_[i];
00326
00327 sprintf(histo, (prefixME_ + "/EBPedestalOnlineTask/Gain12/EBPOT pedestal %s G12").c_str(), Numbers::sEB(ism).c_str());
00328 me = dqmStore_->get(histo);
00329 h03_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h03_[ism-1] );
00330 if ( meg03_[ism-1] ) meg03_[ism-1]->Reset();
00331 if ( mep03_[ism-1] ) mep03_[ism-1]->Reset();
00332 if ( mer03_[ism-1] ) mer03_[ism-1]->Reset();
00333
00334 for ( int ie = 1; ie <= 85; ie++ ) {
00335 for ( int ip = 1; ip <= 20; ip++ ) {
00336
00337 if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ie, ip, 2.);
00338
00339 bool update03;
00340
00341 float num03;
00342 float mean03;
00343 float rms03;
00344
00345 update03 = UtilsClient::getBinStatistics(h03_[ism-1], ie, ip, num03, mean03, rms03);
00346
00347 if ( update03 ) {
00348
00349 float val;
00350
00351 val = 1.;
00352 if ( fabs(mean03 - expectedMean_) > discrepancyMean_ )
00353 val = 0.;
00354 if ( rms03 > RMSThreshold_ )
00355 val = 0.;
00356 if ( meg03_[ism-1] ) meg03_[ism-1]->setBinContent(ie, ip, val);
00357
00358 if ( mep03_[ism-1] ) mep03_[ism-1]->Fill(mean03);
00359 if ( mer03_[ism-1] ) mer03_[ism-1]->Fill(rms03);
00360
00361 }
00362
00363
00364
00365 if ( mask1.size() != 0 ) {
00366 map<EcalLogicID, RunCrystalErrorsDat>::const_iterator m;
00367 for (m = mask1.begin(); m != mask1.end(); m++) {
00368
00369 EcalLogicID ecid = m->first;
00370
00371 int ic = Numbers::indexEB(ism, ie, ip);
00372
00373 if ( ecid.getLogicID() == LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic).getLogicID() ) {
00374 if ( (m->second).getErrorBits() & bits03 ) {
00375 UtilsClient::maskBinContent( meg03_[ism-1], ie, ip );
00376 }
00377 }
00378
00379 }
00380 }
00381
00382
00383
00384 if ( mask2.size() != 0 ) {
00385 map<EcalLogicID, RunTTErrorsDat>::const_iterator m;
00386 for (m = mask2.begin(); m != mask2.end(); m++) {
00387
00388 EcalLogicID ecid = m->first;
00389
00390 int itt = Numbers::iTT(ism, EcalBarrel, ie, ip);
00391
00392 if ( ecid.getLogicID() == LogicID::getEcalLogicID("EB_trigger_tower", Numbers::iSM(ism, EcalBarrel), itt).getLogicID() ) {
00393 if ( (m->second).getErrorBits() & bits03 ) {
00394 UtilsClient::maskBinContent( meg03_[ism-1], ie, ip );
00395 }
00396 }
00397
00398 }
00399 }
00400
00401 }
00402 }
00403
00404 }
00405
00406 }
00407
00408 void EBPedestalOnlineClient::softReset(bool flag) {
00409
00410 char histo[200];
00411
00412 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00413
00414 int ism = superModules_[i];
00415
00416 sprintf(histo, (prefixME_ + "/EBPedestalOnlineTask/Gain12/EBPOT pedestal %s G12").c_str(), Numbers::sEB(ism).c_str());
00417 MonitorElement* me = dqmStore_->get(histo);
00418
00419 if ( flag ) {
00420 if ( me ) dqmStore_->softReset(me);
00421 } else {
00422
00423 }
00424
00425 }
00426
00427 }
00428
00429 void EBPedestalOnlineClient::htmlOutput(int run, string& htmlDir, string& htmlName) {
00430
00431 if ( verbose_ ) cout << "Preparing EBPedestalOnlineClient html output ..." << endl;
00432
00433 ofstream htmlFile;
00434
00435 htmlFile.open((htmlDir + htmlName).c_str());
00436
00437
00438 htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> " << endl;
00439 htmlFile << "<html> " << endl;
00440 htmlFile << "<head> " << endl;
00441 htmlFile << " <meta content=\"text/html; charset=ISO-8859-1\" " << endl;
00442 htmlFile << " https-equiv=\"content-type\"> " << endl;
00443 htmlFile << " <title>Monitor:PedestalOnlineTask output</title> " << endl;
00444 htmlFile << "</head> " << endl;
00445 htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << endl;
00446 htmlFile << "<body> " << endl;
00447
00448 htmlFile << "<a name=""top""></a>" << endl;
00449 htmlFile << "<h2>Run: " << endl;
00450 htmlFile << " <span " << endl;
00451 htmlFile << " style=\"color: rgb(0, 0, 153);\">" << run << "</span></h2>" << endl;
00452 htmlFile << "<h2>Monitoring task: <span " << endl;
00453 htmlFile << " style=\"color: rgb(0, 0, 153);\">PEDESTAL ONLINE</span></h2> " << endl;
00454 htmlFile << "<hr>" << endl;
00455 htmlFile << "<table border=1><tr><td bgcolor=red>channel has problems in this task</td>" << endl;
00456 htmlFile << "<td bgcolor=lime>channel has NO problems</td>" << endl;
00457 htmlFile << "<td bgcolor=yellow>channel is missing</td></table>" << endl;
00458 htmlFile << "<br>" << endl;
00459 htmlFile << "<table border=1>" << std::endl;
00460 for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00461 htmlFile << "<td bgcolor=white><a href=""#"
00462 << Numbers::sEB(superModules_[i]) << ">"
00463 << setfill( '0' ) << setw(2) << superModules_[i] << "</a></td>";
00464 }
00465 htmlFile << std::endl << "</table>" << std::endl;
00466
00467
00468
00469 const int csize = 250;
00470
00471 const double histMax = 1.e15;
00472
00473 int pCol3[7] = { 301, 302, 303, 304, 305, 306, 307 };
00474
00475 TH2C dummy( "dummy", "dummy for sm", 85, 0., 85., 20, 0., 20. );
00476 for ( int i = 0; i < 68; i++ ) {
00477 int a = 2 + ( i/4 ) * 5;
00478 int b = 2 + ( i%4 ) * 5;
00479 dummy.Fill( a, b, i+1 );
00480 }
00481 dummy.SetMarkerSize(2);
00482 dummy.SetMinimum(0.1);
00483
00484 string imgNameQual, imgNameMean, imgNameRMS, imgName, meName;
00485
00486 TCanvas* cQual = new TCanvas("cQual", "Temp", 3*csize, csize);
00487 TCanvas* cMean = new TCanvas("cMean", "Temp", csize, csize);
00488 TCanvas* cRMS = new TCanvas("cRMS", "Temp", csize, csize);
00489
00490 TH2F* obj2f;
00491 TH1F* obj1f;
00492
00493
00494
00495 for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00496
00497 int ism = superModules_[i];
00498
00499
00500
00501 imgNameQual = "";
00502
00503 obj2f = 0;
00504 obj2f = UtilsClient::getHisto<TH2F*>( meg03_[ism-1] );
00505
00506 if ( obj2f ) {
00507
00508 meName = obj2f->GetName();
00509
00510 replace(meName.begin(), meName.end(), ' ', '_');
00511 imgNameQual = meName + ".png";
00512 imgName = htmlDir + imgNameQual;
00513
00514 cQual->cd();
00515 gStyle->SetOptStat(" ");
00516 gStyle->SetPalette(7, pCol3);
00517 obj2f->GetXaxis()->SetNdivisions(17);
00518 obj2f->GetYaxis()->SetNdivisions(4);
00519 cQual->SetGridx();
00520 cQual->SetGridy();
00521 obj2f->SetMinimum(-0.00000001);
00522 obj2f->SetMaximum(7.0);
00523 obj2f->Draw("col");
00524 dummy.Draw("text,same");
00525 cQual->Update();
00526 cQual->SaveAs(imgName.c_str());
00527
00528 }
00529
00530
00531
00532 imgNameMean = "";
00533
00534 obj1f = 0;
00535 obj1f = UtilsClient::getHisto<TH1F*>( mep03_[ism-1] );
00536
00537 if ( obj1f ) {
00538
00539 meName = obj1f->GetName();
00540
00541 replace(meName.begin(), meName.end(), ' ', '_');
00542 imgNameMean = meName + ".png";
00543 imgName = htmlDir + imgNameMean;
00544
00545 cMean->cd();
00546 gStyle->SetOptStat("euomr");
00547 obj1f->SetStats(kTRUE);
00548 if ( obj1f->GetMaximum(histMax) > 0. ) {
00549 gPad->SetLogy(kTRUE);
00550 } else {
00551 gPad->SetLogy(kFALSE);
00552 }
00553 obj1f->Draw();
00554 cMean->Update();
00555 cMean->SaveAs(imgName.c_str());
00556 gPad->SetLogy(kFALSE);
00557
00558 }
00559
00560
00561
00562 obj1f = 0;
00563 obj1f = UtilsClient::getHisto<TH1F*>( mer03_[ism-1] );
00564
00565 imgNameRMS = "";
00566
00567 if ( obj1f ) {
00568
00569 meName = obj1f->GetName();
00570
00571 replace(meName.begin(), meName.end(), ' ', '_');
00572 imgNameRMS = meName + ".png";
00573 imgName = htmlDir + imgNameRMS;
00574
00575 cRMS->cd();
00576 gStyle->SetOptStat("euomr");
00577 obj1f->SetStats(kTRUE);
00578 if ( obj1f->GetMaximum(histMax) > 0. ) {
00579 gPad->SetLogy(kTRUE);
00580 } else {
00581 gPad->SetLogy(kFALSE);
00582 }
00583 obj1f->Draw();
00584 cRMS->Update();
00585 cRMS->SaveAs(imgName.c_str());
00586 gPad->SetLogy(kFALSE);
00587
00588 }
00589
00590 if( i>0 ) htmlFile << "<a href=""#top"">Top</a>" << std::endl;
00591 htmlFile << "<hr>" << std::endl;
00592 htmlFile << "<h3><a name="""
00593 << Numbers::sEB(ism) << """></a><strong>"
00594 << Numbers::sEB(ism) << "</strong></h3>" << endl;
00595 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00596 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00597 htmlFile << "<tr align=\"center\">" << endl;
00598
00599 if ( imgNameQual.size() != 0 )
00600 htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameQual << "\"></td>" << endl;
00601 else
00602 htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00603
00604 htmlFile << "</tr>" << endl;
00605 htmlFile << "<tr>" << endl;
00606
00607 if ( imgNameMean.size() != 0 )
00608 htmlFile << "<td><img src=\"" << imgNameMean << "\"></td>" << endl;
00609 else
00610 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00611
00612 if ( imgNameRMS.size() != 0 )
00613 htmlFile << "<td><img src=\"" << imgNameRMS << "\"></td>" << endl;
00614 else
00615 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00616
00617 htmlFile << "</tr>" << endl;
00618
00619 htmlFile << "</table>" << endl;
00620 htmlFile << "<br>" << endl;
00621
00622 }
00623
00624 delete cQual;
00625 delete cMean;
00626 delete cRMS;
00627
00628
00629 htmlFile << "</body> " << endl;
00630 htmlFile << "</html> " << endl;
00631
00632 htmlFile.close();
00633
00634 }
00635