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 "DQM/EcalCommon/interface/UtilsClient.h"
00023 #include "DQM/EcalCommon/interface/LogicID.h"
00024 #include "DQM/EcalCommon/interface/Numbers.h"
00025
00026 #include <DQM/EcalBarrelMonitorClient/interface/EBOccupancyClient.h>
00027
00028 using namespace cms;
00029 using namespace edm;
00030 using namespace std;
00031
00032 EBOccupancyClient::EBOccupancyClient(const ParameterSet& ps) {
00033
00034
00035 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00036
00037
00038 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00039
00040
00041 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00042
00043
00044 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00045
00046
00047 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00048
00049
00050 superModules_.reserve(36);
00051 for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00052 superModules_ = ps.getUntrackedParameter<vector<int> >("superModules", superModules_);
00053
00054 for ( int i=0; i<3; i++) {
00055 h01_[i] = 0;
00056 h01ProjEta_[i] = 0;
00057 h01ProjPhi_[i] = 0;
00058 }
00059
00060 for ( int i=0; i<2; i++) {
00061 h02_[i] = 0;
00062 h02ProjEta_[i] = 0;
00063 h02ProjPhi_[i] = 0;
00064 }
00065
00066 }
00067
00068 EBOccupancyClient::~EBOccupancyClient() {
00069
00070 }
00071
00072 void EBOccupancyClient::beginJob(DQMStore* dqmStore) {
00073
00074 dqmStore_ = dqmStore;
00075
00076 if ( debug_ ) cout << "EBOccupancyClient: beginJob" << endl;
00077
00078 ievt_ = 0;
00079 jevt_ = 0;
00080
00081 }
00082
00083 void EBOccupancyClient::beginRun(void) {
00084
00085 if ( debug_ ) cout << "EBOccupancyClient: beginRun" << endl;
00086
00087 jevt_ = 0;
00088
00089 this->setup();
00090
00091 }
00092
00093 void EBOccupancyClient::endJob(void) {
00094
00095 if ( debug_ ) cout << "EBOccupancyClient: endJob, ievt = " << ievt_ << endl;
00096
00097 this->cleanup();
00098
00099 }
00100
00101 void EBOccupancyClient::endRun(void) {
00102
00103 if ( debug_ ) cout << "EBOccupancyClient: endRun, jevt = " << jevt_ << endl;
00104
00105 this->cleanup();
00106
00107 }
00108
00109 void EBOccupancyClient::setup(void) {
00110
00111 dqmStore_->setCurrentFolder( prefixME_ + "/EBOccupancyClient" );
00112
00113 }
00114
00115 void EBOccupancyClient::cleanup(void) {
00116
00117 if ( ! enableCleanup_ ) return;
00118
00119 if ( cloneME_ ) {
00120
00121 for ( int i=0; i<3; ++i ) {
00122 if ( h01_[i] ) delete h01_[i];
00123 if ( h01ProjEta_[i] ) delete h01ProjEta_[i];
00124 if ( h01ProjPhi_[i] ) delete h01ProjPhi_[i];
00125 }
00126
00127 for ( int i=0; i<2; ++i ) {
00128 if ( h02_[i] ) delete h02_[i];
00129 if ( h02ProjEta_[i] ) delete h02ProjEta_[i];
00130 if ( h02ProjPhi_[i] ) delete h02ProjPhi_[i];
00131 }
00132
00133 }
00134
00135 for ( int i=0; i<3; ++i ) {
00136 h01_[i] = 0;
00137 h01ProjEta_[i] = 0;
00138 h01ProjPhi_[i] = 0;
00139 }
00140
00141 for ( int i=0; i<2; ++i ) {
00142 h02_[i] = 0;
00143 h02ProjEta_[i] = 0;
00144 h02ProjPhi_[i] = 0;
00145 }
00146
00147 }
00148
00149 bool EBOccupancyClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status, bool flag) {
00150
00151 status = true;
00152
00153 if ( ! flag ) return false;
00154
00155 return true;
00156
00157 }
00158
00159 void EBOccupancyClient::analyze(void) {
00160
00161 ievt_++;
00162 jevt_++;
00163 if ( ievt_ % 10 == 0 ) {
00164 if ( debug_ ) cout << "EBOccupancyClient: ievt/jevt = " << ievt_ << "/" << jevt_ << endl;
00165 }
00166
00167 char histo[200];
00168
00169 MonitorElement* me;
00170
00171 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT digi occupancy").c_str());
00172 me = dqmStore_->get(histo);
00173 h01_[0] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[0] );
00174
00175 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT digi occupancy projection eta").c_str());
00176 me = dqmStore_->get(histo);
00177 h01ProjEta_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[0] );
00178
00179 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT digi occupancy projection phi").c_str());
00180 me = dqmStore_->get(histo);
00181 h01ProjPhi_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[0] );
00182
00183 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy").c_str());
00184 me = dqmStore_->get(histo);
00185 h01_[1] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[1] );
00186
00187 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy projection eta").c_str());
00188 me = dqmStore_->get(histo);
00189 h01ProjEta_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[1] );
00190
00191 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy projection phi").c_str());
00192 me = dqmStore_->get(histo);
00193 h01ProjPhi_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[1] );
00194
00195 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy").c_str());
00196 me = dqmStore_->get(histo);
00197 h01_[2] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[2] );
00198
00199 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy projection eta").c_str());
00200 me = dqmStore_->get(histo);
00201 h01ProjEta_[2] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[2] );
00202
00203 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy projection phi").c_str());
00204 me = dqmStore_->get(histo);
00205 h01ProjPhi_[2] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[2] );
00206
00207 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy").c_str());
00208 me = dqmStore_->get(histo);
00209 h02_[0] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h02_[0] );
00210
00211 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy projection eta").c_str());
00212 me = dqmStore_->get(histo);
00213 h02ProjEta_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjEta_[0] );
00214
00215 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy projection phi").c_str());
00216 me = dqmStore_->get(histo);
00217 h02ProjPhi_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjPhi_[0] );
00218
00219 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy").c_str());
00220 me = dqmStore_->get(histo);
00221 h02_[1] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h02_[1] );
00222
00223 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy projection eta").c_str());
00224 me = dqmStore_->get(histo);
00225 h02ProjEta_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjEta_[1] );
00226
00227 sprintf(histo, (prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy projection phi").c_str());
00228 me = dqmStore_->get(histo);
00229 h02ProjPhi_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjPhi_[1] );
00230
00231 }
00232
00233 void EBOccupancyClient::softReset(bool flag) {
00234
00235 }
00236
00237 void EBOccupancyClient::htmlOutput(int run, string& htmlDir, string& htmlName) {
00238
00239 if ( verbose_ ) cout << "Preparing EBOccupancyClient html output ..." << endl;
00240
00241 ofstream htmlFile;
00242
00243 htmlFile.open((htmlDir + htmlName).c_str());
00244
00245
00246 htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> " << endl;
00247 htmlFile << "<html> " << endl;
00248 htmlFile << "<head> " << endl;
00249 htmlFile << " <meta content=\"text/html; charset=ISO-8859-1\" " << endl;
00250 htmlFile << " https-equiv=\"content-type\"> " << endl;
00251 htmlFile << " <title>Monitor:OccupancyTask output</title> " << endl;
00252 htmlFile << "</head> " << endl;
00253 htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << endl;
00254 htmlFile << "<body> " << endl;
00255
00256 htmlFile << "<a name=""top""></a>" << endl;
00257 htmlFile << "<h2>Run: " << endl;
00258 htmlFile << " <span " << endl;
00259 htmlFile << " style=\"color: rgb(0, 0, 153);\">" << run << "</span></h2>" << endl;
00260 htmlFile << "<h2>Monitoring task: <span " << endl;
00261 htmlFile << " style=\"color: rgb(0, 0, 153);\">OCCUPANCY</span></h2> " << endl;
00262 htmlFile << "<hr>" << endl;
00263
00264
00265
00266 const int csize1D = 250;
00267 const int csize2D = 300;
00268
00269 int pCol4[10];
00270 for ( int i = 0; i < 10; i++ ) pCol4[i] = 401+i;
00271
00272 TH2C dummy( "dummy", "dummy for eb", 18, 0., 360., 2, -85., 85.);
00273 for ( short sm=0; sm<36; sm++ ) {
00274 int x = 1 + sm%18;
00275 int y = 1 + sm/18;
00276 dummy.SetBinContent(x, y, Numbers::iEB(sm+1));
00277 }
00278 dummy.SetMarkerSize(2);
00279 dummy.SetMinimum(-18.01);
00280
00281 TH2C dummyTP( "dummyTP", "dummy for eb TP", 18, 0., 72., 2, -17., 17.);
00282 for ( short sm=0; sm<36; sm++ ) {
00283 int x = 1 + sm%18;
00284 int y = 1 + sm/18;
00285 dummyTP.SetBinContent(x, y, Numbers::iEB(sm+1));
00286 }
00287 dummyTP.SetMarkerSize(2);
00288 dummyTP.SetMinimum(-18.01);
00289
00290 string imgNameMap[3], imgNameProjEta[3], imgNameProjPhi[3];
00291 string imgNameMapThr[2], imgNameProjEtaThr[2], imgNameProjPhiThr[2];
00292 string imgName, meName;
00293
00294 TCanvas* cMap = new TCanvas("cMap", "cMap", int(360./170.*csize2D), csize2D);
00295 TCanvas* cProj = new TCanvas("cProj", "cProj", csize1D, csize1D);
00296
00297 TH2F* obj2f;
00298 TH1F* obj1fEta;
00299 TH1F* obj1fPhi;
00300
00301 gStyle->SetPaintTextFormat("+g");
00302
00303
00304 for ( int iMap=0; iMap<3; iMap++ ) {
00305
00306 imgNameMap[iMap] = "";
00307
00308 obj2f = h01_[iMap];
00309
00310 if ( obj2f ) {
00311
00312 meName = obj2f->GetName();
00313
00314 replace(meName.begin(), meName.end(), ' ', '_');
00315 imgNameMap[iMap] = meName + ".png";
00316 imgName = htmlDir + imgNameMap[iMap];
00317
00318 cMap->cd();
00319 gStyle->SetOptStat(" ");
00320 gStyle->SetPalette(10, pCol4);
00321 obj2f->GetXaxis()->SetNdivisions(18, kFALSE);
00322 obj2f->GetYaxis()->SetNdivisions(2);
00323 cMap->SetGridx();
00324 cMap->SetGridy();
00325 obj2f->Draw("colz");
00326 if ( iMap == 2 ) dummyTP.Draw("text,same");
00327 else dummy.Draw("text,same");
00328 cMap->Update();
00329 cMap->SaveAs(imgName.c_str());
00330
00331 }
00332
00333 obj1fEta = h01ProjEta_[iMap];
00334
00335 if ( obj1fEta ) {
00336
00337 meName = obj1fEta->GetName();
00338
00339 replace(meName.begin(), meName.end(), ' ', '_');
00340 imgNameProjEta[iMap] = meName + ".png";
00341 imgName = htmlDir + imgNameProjEta[iMap];
00342
00343 cProj->cd();
00344 gStyle->SetOptStat("emr");
00345 obj1fEta->SetStats(kTRUE);
00346 obj1fEta->Draw("pe");
00347 cProj->Update();
00348 cProj->SaveAs(imgName.c_str());
00349
00350 }
00351
00352 obj1fPhi = h01ProjPhi_[iMap];
00353
00354 if ( obj1fPhi ) {
00355
00356 meName = obj1fPhi->GetName();
00357
00358 replace(meName.begin(), meName.end(), ' ', '_');
00359 imgNameProjPhi[iMap] = meName + ".png";
00360 imgName = htmlDir + imgNameProjPhi[iMap];
00361
00362 cProj->cd();
00363 gStyle->SetOptStat("emr");
00364 obj1fPhi->SetStats(kTRUE);
00365 obj1fPhi->Draw("pe");
00366 cProj->Update();
00367 cProj->SaveAs(imgName.c_str());
00368
00369 }
00370
00371 }
00372
00373
00374 for ( int iMap=0; iMap<2; iMap++ ) {
00375
00376 imgNameMapThr[iMap] = "";
00377
00378 obj2f = h02_[iMap];
00379
00380 if ( obj2f ) {
00381
00382 meName = obj2f->GetName();
00383
00384 replace(meName.begin(), meName.end(), ' ', '_');
00385 imgNameMapThr[iMap] = meName + ".png";
00386 imgName = htmlDir + imgNameMapThr[iMap];
00387
00388 cMap->cd();
00389 gStyle->SetOptStat(" ");
00390 gStyle->SetPalette(10, pCol4);
00391 obj2f->GetXaxis()->SetNdivisions(18, kFALSE);
00392 obj2f->GetYaxis()->SetNdivisions(2);
00393 cMap->SetGridx();
00394 cMap->SetGridy();
00395 obj2f->Draw("colz");
00396 if ( iMap == 1 ) dummyTP.Draw("text,same");
00397 else dummy.Draw("text,same");
00398 cMap->Update();
00399 cMap->SaveAs(imgName.c_str());
00400
00401 }
00402
00403 obj1fEta = h02ProjEta_[iMap];
00404
00405 if ( obj1fEta ) {
00406
00407 meName = obj1fEta->GetName();
00408
00409 replace(meName.begin(), meName.end(), ' ', '_');
00410 imgNameProjEtaThr[iMap] = meName + ".png";
00411 imgName = htmlDir + imgNameProjEtaThr[iMap];
00412
00413 cProj->cd();
00414 gStyle->SetOptStat("emr");
00415 obj1fEta->SetStats(kTRUE);
00416 obj1fEta->Draw("pe");
00417 cProj->Update();
00418 cProj->SaveAs(imgName.c_str());
00419
00420 }
00421
00422 obj1fPhi = h02ProjPhi_[iMap];
00423
00424 if ( obj1fPhi ) {
00425
00426 meName = obj1fPhi->GetName();
00427
00428 replace(meName.begin(), meName.end(), ' ', '_');
00429 imgNameProjPhiThr[iMap] = meName + ".png";
00430 imgName = htmlDir + imgNameProjPhiThr[iMap];
00431
00432 cProj->cd();
00433 gStyle->SetOptStat("emr");
00434 obj1fPhi->SetStats(kTRUE);
00435 obj1fPhi->Draw("pe");
00436 cProj->Update();
00437 cProj->SaveAs(imgName.c_str());
00438
00439 }
00440
00441 }
00442
00443 gStyle->SetPaintTextFormat();
00444
00445 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00446 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00447 htmlFile << "<tr align=\"center\">" << endl;
00448
00449 for (int iMap=0; iMap<3; iMap++) {
00450 if ( imgNameMap[iMap].size() != 0 )
00451 htmlFile << "<td><img src=\"" << imgNameMap[iMap] << "\"></td>" << endl;
00452 else
00453 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00454 }
00455
00456 htmlFile << "</tr>" << endl;
00457 htmlFile << "</table>" << endl;
00458 htmlFile << "<br>" << endl;
00459
00460 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00461 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00462 htmlFile << "<tr align=\"center\">" << endl;
00463
00464 for (int iMap=0; iMap<3; iMap++) {
00465 if ( imgNameProjEta[iMap].size() != 0 )
00466 htmlFile << "<td><img src=\"" << imgNameProjEta[iMap] << "\"></td>" << endl;
00467 else
00468 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00469 if ( imgNameProjPhi[iMap].size() != 0 )
00470 htmlFile << "<td><img src=\"" << imgNameProjPhi[iMap] << "\"></td>" << endl;
00471 else
00472 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00473 }
00474
00475 htmlFile << "</tr>" << endl;
00476 htmlFile << "</table>" << endl;
00477 htmlFile << "<br>" << endl;
00478
00479 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00480 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00481 htmlFile << "<tr align=\"center\">" << endl;
00482
00483 for (int iMap=0; iMap<2; iMap++) {
00484 if ( imgNameMapThr[iMap].size() != 0 )
00485 htmlFile << "<td><img src=\"" << imgNameMapThr[iMap] << "\"></td>" << endl;
00486 else
00487 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00488 }
00489
00490 htmlFile << "</tr>" << endl;
00491 htmlFile << "</table>" << endl;
00492 htmlFile << "<br>" << endl;
00493
00494 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00495 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00496 htmlFile << "<tr align=\"center\">" << endl;
00497
00498 for (int iMap=0; iMap<2; iMap++) {
00499 if ( imgNameProjEtaThr[iMap].size() != 0 )
00500 htmlFile << "<td><img src=\"" << imgNameProjEtaThr[iMap] << "\"></td>" << endl;
00501 else
00502 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00503 if ( imgNameProjPhiThr[iMap].size() != 0 )
00504 htmlFile << "<td><img src=\"" << imgNameProjPhiThr[iMap] << "\"></td>" << endl;
00505 else
00506 htmlFile << "<td><img src=\"" << " " << "\"></td>" << endl;
00507 }
00508
00509 htmlFile << "</tr>" << endl;
00510 htmlFile << "</table>" << endl;
00511 htmlFile << "<br>" << endl;
00512
00513 htmlFile.close();
00514
00515 }
00516