00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <memory>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <iomanip>
00015
00016 #include "TCanvas.h"
00017 #include "TStyle.h"
00018 #include "TGraph.h"
00019 #include "TLine.h"
00020
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022
00023 #include "OnlineDB/EcalCondDB/interface/MonOccupancyDat.h"
00024
00025 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00026
00027 #include "DQM/EcalCommon/interface/UtilsClient.h"
00028 #include "DQM/EcalCommon/interface/LogicID.h"
00029 #include "DQM/EcalCommon/interface/Numbers.h"
00030
00031 #include <DQM/EcalEndcapMonitorClient/interface/EECosmicClient.h>
00032
00033 using namespace cms;
00034 using namespace edm;
00035 using namespace std;
00036
00037 EECosmicClient::EECosmicClient(const 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<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<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 h03_[ism-1] = 0;
00066 h04_[ism-1] = 0;
00067
00068 meh01_[ism-1] = 0;
00069 meh02_[ism-1] = 0;
00070 meh03_[ism-1] = 0;
00071 meh04_[ism-1] = 0;
00072
00073 }
00074
00075 }
00076
00077 EECosmicClient::~EECosmicClient() {
00078
00079 }
00080
00081 void EECosmicClient::beginJob(DQMStore* dqmStore) {
00082
00083 dqmStore_ = dqmStore;
00084
00085 if ( debug_ ) cout << "EECosmicClient: beginJob" << endl;
00086
00087 ievt_ = 0;
00088 jevt_ = 0;
00089
00090 }
00091
00092 void EECosmicClient::beginRun(void) {
00093
00094 if ( debug_ ) cout << "EECosmicClient: beginRun" << endl;
00095
00096 jevt_ = 0;
00097
00098 this->setup();
00099
00100 }
00101
00102 void EECosmicClient::endJob(void) {
00103
00104 if ( debug_ ) cout << "EECosmicClient: endJob, ievt = " << ievt_ << endl;
00105
00106 this->cleanup();
00107
00108 }
00109
00110 void EECosmicClient::endRun(void) {
00111
00112 if ( debug_ ) cout << "EECosmicClient: endRun, jevt = " << jevt_ << endl;
00113
00114 this->cleanup();
00115
00116 }
00117
00118 void EECosmicClient::setup(void) {
00119
00120 }
00121
00122 void EECosmicClient::cleanup(void) {
00123
00124 if ( ! enableCleanup_ ) return;
00125
00126 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00127
00128 int ism = superModules_[i];
00129
00130 if ( cloneME_ ) {
00131 if ( h01_[ism-1] ) delete h01_[ism-1];
00132 if ( h02_[ism-1] ) delete h02_[ism-1];
00133 if ( h03_[ism-1] ) delete h03_[ism-1];
00134 if ( h04_[ism-1] ) delete h04_[ism-1];
00135 }
00136
00137 h01_[ism-1] = 0;
00138 h02_[ism-1] = 0;
00139 h03_[ism-1] = 0;
00140 h04_[ism-1] = 0;
00141
00142 meh01_[ism-1] = 0;
00143 meh02_[ism-1] = 0;
00144 meh03_[ism-1] = 0;
00145 meh04_[ism-1] = 0;
00146
00147 }
00148
00149 }
00150
00151 bool EECosmicClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status, bool flag) {
00152
00153 status = true;
00154
00155 if ( ! flag ) return false;
00156
00157 EcalLogicID ecid;
00158
00159 MonOccupancyDat o;
00160 map<EcalLogicID, MonOccupancyDat> dataset;
00161
00162 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00163
00164 int ism = superModules_[i];
00165
00166 if ( verbose_ ) {
00167 cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << endl;
00168 cout << endl;
00169 }
00170
00171 const float n_min_tot = 1000.;
00172 const float n_min_bin = 10.;
00173
00174 float num01, num02;
00175 float mean01, mean02;
00176 float rms01, rms02;
00177
00178 for ( int ix = 1; ix <= 50; ix++ ) {
00179 for ( int iy = 1; iy <= 50; iy++ ) {
00180
00181 int jx = ix + Numbers::ix0EE(ism);
00182 int jy = iy + Numbers::iy0EE(ism);
00183
00184 if ( ism >= 1 && ism <= 9 ) jx = 101 - jx;
00185
00186 if ( ! Numbers::validEE(ism, jx, jy) ) continue;
00187
00188 num01 = num02 = -1.;
00189 mean01 = mean02 = -1.;
00190 rms01 = rms02 = -1.;
00191
00192 bool update_channel = false;
00193
00194 if ( h01_[ism-1] && h01_[ism-1]->GetEntries() >= n_min_tot ) {
00195 num01 = h01_[ism-1]->GetBinEntries(h01_[ism-1]->GetBin(ix, iy));
00196 if ( num01 >= n_min_bin ) {
00197 mean01 = h01_[ism-1]->GetBinContent(ix, iy);
00198 rms01 = h01_[ism-1]->GetBinError(ix, iy);
00199 update_channel = true;
00200 }
00201 }
00202
00203 if ( h02_[ism-1] && h02_[ism-1]->GetEntries() >= n_min_tot ) {
00204 num02 = h02_[ism-1]->GetBinEntries(h02_[ism-1]->GetBin(ix, iy));
00205 if ( num02 >= n_min_bin ) {
00206 mean02 = h02_[ism-1]->GetBinContent(ix, iy);
00207 rms02 = h02_[ism-1]->GetBinError(ix, iy);
00208 update_channel = true;
00209 }
00210 }
00211
00212 if ( update_channel ) {
00213
00214 if ( Numbers::icEE(ism, jx, jy) == 1 ) {
00215
00216 if ( verbose_ ) {
00217 cout << "Preparing dataset for " << Numbers::sEE(ism) << " (ism=" << ism << ")" << endl;
00218 cout << "Cut (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num01 << " " << mean01 << " " << rms01 << endl;
00219 cout << "Sel (" << Numbers::ix0EE(i+1)+ix << "," << Numbers::iy0EE(i+1)+iy << ") " << num02 << " " << mean02 << " " << rms02 << endl;
00220 cout << endl;
00221 }
00222
00223 }
00224
00225 o.setEventsOverLowThreshold(int(num01));
00226 o.setEventsOverHighThreshold(int(num02));
00227
00228 o.setAvgEnergy(mean01);
00229
00230 int ic = Numbers::indexEE(ism, jx, jy);
00231
00232 if ( ic == -1 ) continue;
00233
00234 if ( econn ) {
00235 ecid = LogicID::getEcalLogicID("EE_crystal_number", Numbers::iSM(ism, EcalEndcap), ic);
00236 dataset[ecid] = o;
00237 }
00238
00239 }
00240
00241 }
00242 }
00243
00244 }
00245
00246 if ( econn ) {
00247 try {
00248 if ( verbose_ ) cout << "Inserting MonOccupancyDat ..." << endl;
00249 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00250 if ( verbose_ ) cout << "done." << endl;
00251 } catch (runtime_error &e) {
00252 cerr << e.what() << endl;
00253 }
00254 }
00255
00256 return true;
00257
00258 }
00259
00260 void EECosmicClient::analyze(void) {
00261
00262 ievt_++;
00263 jevt_++;
00264 if ( ievt_ % 10 == 0 ) {
00265 if ( debug_ ) cout << "EECosmicClient: ievt/jevt = " << ievt_ << "/" << jevt_ << endl;
00266 }
00267
00268 char histo[200];
00269
00270 MonitorElement* me;
00271
00272 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00273
00274 int ism = superModules_[i];
00275
00276 sprintf(histo, (prefixME_ + "/EECosmicTask/Cut/EECT energy cut %s").c_str(), Numbers::sEE(ism).c_str());
00277 me = dqmStore_->get(histo);
00278 h01_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h01_[ism-1] );
00279 meh01_[ism-1] = me;
00280
00281 sprintf(histo, (prefixME_ + "/EECosmicTask/Sel/EECT energy sel %s").c_str(), Numbers::sEE(ism).c_str());
00282 me = dqmStore_->get(histo);
00283 h02_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h02_[ism-1] );
00284 meh02_[ism-1] = me;
00285
00286 sprintf(histo, (prefixME_ + "/EECosmicTask/Spectrum/EECT 1x1 energy spectrum %s").c_str(), Numbers::sEE(ism).c_str());
00287 me = dqmStore_->get(histo);
00288 h03_[ism-1] = UtilsClient::getHisto<TH1F*>( me, cloneME_, h03_[ism-1] );
00289 meh03_[ism-1] = me;
00290
00291 sprintf(histo, (prefixME_ + "/EECosmicTask/Spectrum/EECT 3x3 energy spectrum %s").c_str(), Numbers::sEE(ism).c_str());
00292 me = dqmStore_->get(histo);
00293 h04_[ism-1] = UtilsClient::getHisto<TH1F*>( me, cloneME_, h04_[ism-1] );
00294 meh04_[ism-1] = me;
00295
00296 }
00297
00298 }
00299
00300 void EECosmicClient::softReset(bool flag) {
00301
00302 }
00303
00304 void EECosmicClient::htmlOutput(int run, string& htmlDir, string& htmlName) {
00305
00306 if ( verbose_ ) cout << "Preparing EECosmicClient html output ..." << endl;
00307
00308 ofstream htmlFile;
00309
00310 htmlFile.open((htmlDir + htmlName).c_str());
00311
00312
00313 htmlFile << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"> " << endl;
00314 htmlFile << "<html> " << endl;
00315 htmlFile << "<head> " << endl;
00316 htmlFile << " <meta content=\"text/html; charset=ISO-8859-1\" " << endl;
00317 htmlFile << " https-equiv=\"content-type\"> " << endl;
00318 htmlFile << " <title>Monitor:CosmicTask output</title> " << endl;
00319 htmlFile << "</head> " << endl;
00320 htmlFile << "<style type=\"text/css\"> td { font-weight: bold } </style>" << endl;
00321 htmlFile << "<body> " << endl;
00322
00323 htmlFile << "<a name=""top""></a>" << endl;
00324 htmlFile << "<h2>Run: " << endl;
00325 htmlFile << " <span " << endl;
00326 htmlFile << " style=\"color: rgb(0, 0, 153);\">" << run << "</span></h2>" << endl;
00327 htmlFile << "<h2>Monitoring task: <span " << endl;
00328 htmlFile << " style=\"color: rgb(0, 0, 153);\">COSMIC</span></h2> " << endl;
00329 htmlFile << "<hr>" << endl;
00330
00331
00332
00333
00334 htmlFile << "<table border=1>" << std::endl;
00335 for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00336 htmlFile << "<td bgcolor=white><a href=""#"
00337 << Numbers::sEE(superModules_[i]) << ">"
00338 << setfill( '0' ) << setw(2) << superModules_[i] << "</a></td>";
00339 }
00340 htmlFile << std::endl << "</table>" << std::endl;
00341
00342
00343
00344 const int csize = 250;
00345
00346 const double histMax = 1.e15;
00347
00348 int pCol4[10];
00349 for ( int i = 0; i < 10; i++ ) pCol4[i] = 401+i;
00350
00351 TH2S labelGrid("labelGrid","label grid", 100, -2., 98., 100, -2., 98.);
00352 for ( short j=0; j<400; j++ ) {
00353 int x = 5*(1 + j%20);
00354 int y = 5*(1 + j/20);
00355 labelGrid.SetBinContent(x, y, Numbers::inTowersEE[j]);
00356 }
00357 labelGrid.SetMarkerSize(1);
00358 labelGrid.SetMinimum(0.1);
00359
00360 string imgNameME[4], imgName, meName;
00361
00362 TCanvas* cMe = new TCanvas("cMe", "Temp", 2*csize, 2*csize);
00363 TCanvas* cAmp = new TCanvas("cAmp", "Temp", csize, csize);
00364
00365 TProfile2D* objp;
00366 TH1F* obj1f;
00367
00368
00369
00370 for ( unsigned int i=0; i<superModules_.size(); i ++ ) {
00371
00372 int ism = superModules_[i];
00373
00374
00375
00376 for ( int iCanvas = 1; iCanvas <= 2; iCanvas++ ) {
00377
00378 imgNameME[iCanvas-1] = "";
00379
00380 objp = 0;
00381 switch ( iCanvas ) {
00382 case 1:
00383 objp = h01_[ism-1];
00384 break;
00385 case 2:
00386 objp = h02_[ism-1];
00387 break;
00388 default:
00389 break;
00390 }
00391
00392 if ( objp ) {
00393
00394 meName = objp->GetName();
00395
00396 replace(meName.begin(), meName.end(), ' ', '_');
00397 imgNameME[iCanvas-1] = meName + ".png";
00398 imgName = htmlDir + imgNameME[iCanvas-1];
00399
00400 cMe->cd();
00401 gStyle->SetOptStat(" ");
00402 gStyle->SetPalette(10, pCol4);
00403 cMe->SetGridx();
00404 cMe->SetGridy();
00405 objp->GetXaxis()->SetLabelSize(0.02);
00406 objp->GetXaxis()->SetTitleSize(0.02);
00407 objp->GetYaxis()->SetLabelSize(0.02);
00408 objp->GetYaxis()->SetTitleSize(0.02);
00409 objp->GetZaxis()->SetLabelSize(0.02);
00410 objp->GetZaxis()->SetTitleSize(0.02);
00411 objp->Draw("colz");
00412 int x1 = labelGrid.GetXaxis()->FindFixBin(Numbers::ix0EE(ism)+0.);
00413 int x2 = labelGrid.GetXaxis()->FindFixBin(Numbers::ix0EE(ism)+50.);
00414 int y1 = labelGrid.GetYaxis()->FindFixBin(Numbers::iy0EE(ism)+0.);
00415 int y2 = labelGrid.GetYaxis()->FindFixBin(Numbers::iy0EE(ism)+50.);
00416 labelGrid.GetXaxis()->SetRange(x1, x2);
00417 labelGrid.GetYaxis()->SetRange(y1, y2);
00418 labelGrid.Draw("text,same");
00419 cMe->SetBit(TGraph::kClipFrame);
00420 TLine l;
00421 l.SetLineWidth(1);
00422 for ( int i=0; i<201; i=i+1) {
00423 if ( (Numbers::ixSectorsEE[i]!=0 || Numbers::iySectorsEE[i]!=0) && (Numbers::ixSectorsEE[i+1]!=0 || Numbers::iySectorsEE[i+1]!=0) ) {
00424 l.DrawLine(Numbers::ixSectorsEE[i], Numbers::iySectorsEE[i], Numbers::ixSectorsEE[i+1], Numbers::iySectorsEE[i+1]);
00425 }
00426 }
00427 cMe->Update();
00428 cMe->SaveAs(imgName.c_str());
00429
00430 }
00431
00432 }
00433
00434
00435
00436 imgNameME[2] = "";
00437
00438 obj1f = h03_[ism-1];
00439
00440 if ( obj1f ) {
00441
00442 meName = obj1f->GetName();
00443
00444 replace(meName.begin(), meName.end(), ' ', '_');
00445 imgNameME[2] = meName + ".png";
00446 imgName = htmlDir + imgNameME[2];
00447
00448 cAmp->cd();
00449 gStyle->SetOptStat("euomr");
00450 obj1f->SetStats(kTRUE);
00451 if ( obj1f->GetMaximum(histMax) > 0. ) {
00452 gPad->SetLogy(kTRUE);
00453 } else {
00454 gPad->SetLogy(kFALSE);
00455 }
00456 obj1f->Draw();
00457 cAmp->Update();
00458 cAmp->SaveAs(imgName.c_str());
00459 gPad->SetLogy(kFALSE);
00460
00461 }
00462
00463 imgNameME[3] = "";
00464
00465 obj1f = h04_[ism-1];
00466
00467 if ( obj1f ) {
00468
00469 meName = obj1f->GetName();
00470
00471 replace(meName.begin(), meName.end(), ' ', '_');
00472 imgNameME[3] = meName + ".png";
00473 imgName = htmlDir + imgNameME[3];
00474
00475 cAmp->cd();
00476 gStyle->SetOptStat("euomr");
00477 obj1f->SetStats(kTRUE);
00478 if ( obj1f->GetMaximum(histMax) > 0. ) {
00479 gPad->SetLogy(kTRUE);
00480 } else {
00481 gPad->SetLogy(kFALSE);
00482 }
00483 obj1f->Draw();
00484 cAmp->Update();
00485 cAmp->SaveAs(imgName.c_str());
00486 gPad->SetLogy(kFALSE);
00487
00488 }
00489
00490 if( i>0 ) htmlFile << "<a href=""#top"">Top</a>" << std::endl;
00491 htmlFile << "<hr>" << std::endl;
00492 htmlFile << "<h3><a name="""
00493 << Numbers::sEE(ism) << """></a><strong>"
00494 << Numbers::sEE(ism) << "</strong></h3>" << endl;
00495 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00496 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00497 htmlFile << "<tr align=\"center\">" << endl;
00498
00499 for ( int iCanvas = 1 ; iCanvas <= 2 ; iCanvas++ ) {
00500
00501 if ( imgNameME[iCanvas-1].size() != 0 )
00502 htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameME[iCanvas-1] << "\"></td>" << endl;
00503 else
00504 htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00505
00506 }
00507
00508 htmlFile << "</tr>" << endl;
00509 htmlFile << "</table>" << endl;
00510 htmlFile << "<br>" << endl;
00511
00512 htmlFile << "<table border=\"0\" cellspacing=\"0\" " << endl;
00513 htmlFile << "cellpadding=\"10\" align=\"center\"> " << endl;
00514 htmlFile << "<tr align=\"center\">" << endl;
00515
00516 for ( int iCanvas = 3 ; iCanvas <= 4 ; iCanvas++ ) {
00517
00518 if ( imgNameME[iCanvas-1].size() != 0 )
00519 htmlFile << "<td colspan=\"2\"><img src=\"" << imgNameME[iCanvas-1] << "\"></td>" << endl;
00520 else
00521 htmlFile << "<td colspan=\"2\"><img src=\"" << " " << "\"></td>" << endl;
00522
00523 }
00524
00525 htmlFile << "</tr>" << endl;
00526 htmlFile << "</table>" << endl;
00527 htmlFile << "<br>" << endl;
00528
00529 }
00530
00531 delete cMe;
00532 delete cAmp;
00533
00534
00535 htmlFile << "</body> " << endl;
00536 htmlFile << "</html> " << endl;
00537
00538 htmlFile.close();
00539
00540 }
00541