00001 #include <iostream>
00002 #include <fstream>
00003 #include <vector>
00004
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/Framework/interface/MakerMacros.h"
00008 #include "FWCore/Framework/interface/Frameworkfwd.h"
00009
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "DQMServices/Core/interface/DQMStore.h"
00012
00013 #include "DataFormats/DetId/interface/DetId.h"
00014 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00015 #include "DataFormats/EcalDigi/interface/ESDataFrame.h"
00016 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00017 #include "DataFormats/EcalRawData/interface/ESDCCHeaderBlock.h"
00018 #include "DataFormats/EcalRawData/interface/ESKCHIPBlock.h"
00019 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00020
00021 #include "DQM/EcalPreshowerMonitorModule/interface/ESIntegrityTask.h"
00022
00023 using namespace cms;
00024 using namespace edm;
00025 using namespace std;
00026
00027 ESIntegrityTask::ESIntegrityTask(const ParameterSet& ps) {
00028
00029 init_ = false;
00030
00031 dqmStore_ = Service<DQMStore>().operator->();
00032
00033 prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
00034 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00035 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00036 lookup_ = ps.getUntrackedParameter<FileInPath>("LookupTable");
00037
00038 dccCollections_ = ps.getParameter<InputTag>("ESDCCCollections");
00039 kchipCollections_ = ps.getParameter<InputTag>("ESKChipCollections");
00040
00041 doLumiAnalysis_ = ps.getParameter<bool>("DoLumiAnalysis");
00042
00043
00044 for (int i=0; i<2; ++i)
00045 for (int j=0; j<2; ++j)
00046 for (int k=0; k<40; ++k)
00047 for (int m=0; m<40; ++m) {
00048 fed_[i][j][k][m] = -1;
00049 kchip_[i][j][k][m] = -1;
00050 fiber_[i][j][k][m] = -1;
00051 }
00052
00053 int nLines_, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
00054 ifstream file;
00055 file.open(lookup_.fullPath().c_str());
00056 if( file.is_open() ) {
00057
00058 file >> nLines_;
00059
00060 for (int i=0; i<nLines_; ++i) {
00061 file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
00062
00063 z = (iz==-1) ? 2:iz;
00064 fed_[z-1][ip-1][ix-1][iy-1] = fed;
00065 kchip_[z-1][ip-1][ix-1][iy-1] = kchip;
00066 fiber_[z-1][ip-1][ix-1][iy-1] = (fiber-1)+(optorx-1)*12;
00067 }
00068 }
00069 else {
00070 cout<<"ESIntegrityTask : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
00071 }
00072
00073 }
00074
00075 ESIntegrityTask::~ESIntegrityTask() {
00076 }
00077
00078 void ESIntegrityTask::beginJob(void) {
00079
00080 ievt_ = 0;
00081
00082 if ( dqmStore_ ) {
00083 dqmStore_->setCurrentFolder(prefixME_ + "/ESIntegrityTask");
00084 dqmStore_->rmdir(prefixME_ + "/ESIntegrityTask");
00085 }
00086
00087 }
00088
00089 void ESIntegrityTask::beginRun(const Run& r, const EventSetup& c) {
00090
00091 if ( ! init_ ) this->setup();
00092 if ( ! mergeRuns_ ) this->reset();
00093
00094 }
00095
00096 void ESIntegrityTask::endRun(const Run& r, const EventSetup& c) {
00097
00098 if (doLumiAnalysis_) {
00099 for (int i=0; i<2; ++i) {
00100 for (int j=0; j<2; ++j) {
00101 if (meDIErrors_[i][j]) {
00102 dqmStore_->disableSoftReset(meDIErrors_[i][j]);
00103 }
00104 }
00105 }
00106 }
00107 }
00108
00109 void ESIntegrityTask::beginLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup & c) {
00110
00111 LogInfo("ESIntegrityTask") << "analyzed " << ievt_ << " events";
00112
00113 if (doLumiAnalysis_) {
00114 for (int i=0; i<2; ++i) {
00115 for (int j=0; j<2; ++j) {
00116 if (meDIErrors_[i][j]) {
00117 dqmStore_->softReset(meDIErrors_[i][j]);
00118 }
00119 }
00120 }
00121 ievt_ = 0;
00122 }
00123 }
00124
00125 void ESIntegrityTask::endLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup & c){
00126 if (doLumiAnalysis_) calculateDIFraction();
00127 }
00128
00129 void ESIntegrityTask::reset(void) {
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 }
00143
00144 void ESIntegrityTask::setup(void){
00145
00146 init_ = true;
00147
00148 char histo[200];
00149
00150 if (dqmStore_) {
00151 dqmStore_->setCurrentFolder(prefixME_ + "/ESIntegrityTask");
00152
00153 sprintf(histo, "ES FEDs used for data taking");
00154 meFED_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
00155 meFED_->setAxisTitle("ES FED", 1);
00156 meFED_->setAxisTitle("Num of Events", 2);
00157
00158 sprintf(histo, "ES Gain used for data taking");
00159 meGain_ = dqmStore_->book1D(histo, histo, 2, -0.5, 1.5);
00160 meGain_->setAxisTitle("ES Gain", 1);
00161 meGain_->setAxisTitle("Num of Events", 2);
00162
00163 sprintf(histo, "ES DCC Error codes");
00164 meDCCErr_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 6, -0.5, 5.5);
00165 meDCCErr_->setAxisTitle("ES FED", 1);
00166 meDCCErr_->setAxisTitle("ES DCC Error code", 2);
00167
00168 sprintf(histo, "ES SLink CRC Errors");
00169 meSLinkCRCErr_ = dqmStore_->book1D(histo, histo, 56, 519.5, 575.5);
00170 meSLinkCRCErr_->setAxisTitle("ES FED", 1);
00171 meSLinkCRCErr_->setAxisTitle("Num of Events", 2);
00172
00173 sprintf(histo, "ES DCC CRC Errors");
00174 meDCCCRCErr_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
00175 meDCCCRCErr_->setAxisTitle("ES FED", 1);
00176 meDCCCRCErr_->setAxisTitle("ES OptoRX", 2);
00177
00178 sprintf(histo, "ES OptoRX used for data taking");
00179 meOptoRX_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
00180 meOptoRX_->setAxisTitle("ES FED", 1);
00181 meOptoRX_->setAxisTitle("ES OptoRX", 2);
00182
00183 sprintf(histo, "ES OptoRX BC mismatch");
00184 meOptoBC_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 3, -0.5, 2.5);
00185 meOptoBC_->setAxisTitle("ES FED", 1);
00186 meOptoBC_->setAxisTitle("ES OptoRX", 2);
00187
00188 sprintf(histo, "ES Fiber Bad Status");
00189 meFiberBadStatus_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
00190 meFiberBadStatus_->setAxisTitle("ES FED", 1);
00191 meFiberBadStatus_->setAxisTitle("Fiber Number", 2);
00192
00193 sprintf(histo, "ES Fiber Error Code");
00194 meFiberErrCode_ = dqmStore_->book1D(histo, histo, 17, -0.5, 16.5);
00195 meFiberErrCode_->setAxisTitle("Fiber Error Code", 1);
00196
00197 sprintf(histo, "ES Fiber Off");
00198
00199 meFiberOff_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
00200 meFiberOff_->setAxisTitle("ES FED", 1);
00201 meFiberOff_->setAxisTitle("Fiber Number", 2);
00202
00203 sprintf(histo, "ES Warning Event Dropped");
00204 meEVDR_ = dqmStore_->book2D(histo, histo, 56, 519.5, 575.5, 36, 0.5, 36.5);
00205 meEVDR_->setAxisTitle("ES FED", 1);
00206 meEVDR_->setAxisTitle("Fiber Number", 2);
00207
00208 sprintf(histo, "ES KChip Flag 1 Error codes");
00209 meKF1_ = dqmStore_->book2D(histo, histo, 1550, -0.5, 1549.5, 16, -0.5, 15.5);
00210 meKF1_->setAxisTitle("ES KChip", 1);
00211 meKF1_->setAxisTitle("ES KChip F1 Error Code ", 2);
00212
00213 sprintf(histo, "ES KChip Flag 2 Error codes");
00214 meKF2_ = dqmStore_->book2D(histo, histo, 1550, -0.5, 1549.5, 16, -0.5, 15.5);
00215 meKF2_->setAxisTitle("ES KChip", 1);
00216 meKF2_->setAxisTitle("ES KChip F1 Error Code ", 2);
00217
00218 sprintf(histo, "ES KChip BC mismatch with OptoRX");
00219 meKBC_ = dqmStore_->book1D(histo, histo, 1550, -0.5, 1549.5);
00220 meKBC_->setAxisTitle("ES KChip", 1);
00221 meKBC_->setAxisTitle("Num of BC mismatch", 2);
00222
00223 sprintf(histo, "ES KChip EC mismatch with OptoRX");
00224 meKEC_ = dqmStore_->book1D(histo, histo, 1550, -0.5, 1549.5);
00225 meKEC_->setAxisTitle("ES KChip", 1);
00226 meKEC_->setAxisTitle("Num of EC mismatch", 2);
00227
00228 for (int i=0; i<2; ++i)
00229 for (int j=0; j<2; ++j) {
00230 int iz = (i==0)? 1:-1;
00231 sprintf(histo, "ES Integrity Errors Z %d P %d", iz, j+1);
00232 meDIErrors_[i][j] = dqmStore_->book2D(histo, histo, 40, 0.5, 40.5, 40, 0.5, 40.5);
00233 meDIErrors_[i][j]->setAxisTitle("Si X", 1);
00234 meDIErrors_[i][j]->setAxisTitle("Si Y", 2);
00235 }
00236
00237 if (doLumiAnalysis_) {
00238 sprintf(histo, "ES Good Channel Fraction");
00239 meDIFraction_ = dqmStore_->book2D(histo, histo, 3, 1.0, 3.0, 3, 1.0, 3.0);
00240 meDIFraction_->setLumiFlag();
00241 }
00242 }
00243
00244
00245 }
00246
00247 void ESIntegrityTask::cleanup(void){
00248
00249 if ( ! init_ ) return;
00250
00251 if ( dqmStore_ ) {
00252
00253 }
00254
00255 init_ = false;
00256
00257 }
00258
00259 void ESIntegrityTask::endJob(void){
00260
00261 LogInfo("ESIntegrityTask") << "analyzed " << ievt_ << " events";
00262
00263 if ( enableCleanup_ ) this->cleanup();
00264
00265 }
00266
00267 void ESIntegrityTask::analyze(const Event& e, const EventSetup& c){
00268
00269 if ( ! init_ ) this->setup();
00270
00271 ievt_++;
00272
00273 Handle<ESRawDataCollection> dccs;
00274 Handle<ESLocalRawDataCollection> kchips;
00275
00276
00277 meDCCErr_->Fill(575, 2, 1);
00278 meDCCCRCErr_->Fill(575, 2, 1);
00279 meOptoRX_->Fill(575, 2, 1);
00280 meOptoBC_->Fill(575, 2, 1);
00281 meFiberBadStatus_->Fill(575, 36, 1);
00282 meFiberOff_->Fill(575, 36, 1);
00283 meEVDR_->Fill(575, 36, 1);
00284
00285
00286 Double_t nDIErr[56][36];
00287 for (int i=0; i<56; ++i)
00288 for (int j=0; j<36; ++j)
00289 nDIErr[i][j] = 0;
00290
00291
00292 vector<int> fiberStatus;
00293 if ( e.getByLabel(dccCollections_, dccs) ) {
00294
00295 for (ESRawDataCollection::const_iterator dccItr = dccs->begin(); dccItr != dccs->end(); ++dccItr) {
00296 ESDCCHeaderBlock dcc = (*dccItr);
00297
00298 meFED_->Fill(dcc.fedId());
00299
00300 meDCCErr_->Fill(dcc.fedId(), dcc.getDCCErrors());
00301
00302
00303 if (dcc.getDCCErrors() == 101) {
00304 meSLinkCRCErr_->Fill(dcc.fedId());
00305 for (int j=0; j<36; ++j) nDIErr[dcc.fedId()-520][j]++;
00306 }
00307
00308 if (dcc.getOptoRX0() == 129) {
00309 meOptoRX_->Fill(dcc.fedId(), 0);
00310 if (((dcc.getOptoBC0()-15) & 0x0fff) != dcc.getBX()) meOptoBC_->Fill(dcc.fedId(), 0);
00311 }
00312 if (dcc.getOptoRX1() == 129) {
00313 meOptoRX_->Fill(dcc.fedId(), 1);
00314 if (((dcc.getOptoBC1()-15) & 0x0fff) != dcc.getBX()) meOptoBC_->Fill(dcc.fedId(), 1);
00315 }
00316 if (dcc.getOptoRX2() == 129) {
00317 meOptoRX_->Fill(dcc.fedId(), 2);
00318 if (((dcc.getOptoBC2()-15) & 0x0fff) != dcc.getBX()) meOptoBC_->Fill(dcc.fedId(), 2);
00319 }
00320
00321 if (dcc.getOptoRX0() == 128) {
00322 meDCCCRCErr_->Fill(dcc.fedId(), 0);
00323 for (int j=0; j<12; ++j) nDIErr[dcc.fedId()-520][j]++;
00324 }
00325 if (dcc.getOptoRX1() == 128) {
00326 meDCCCRCErr_->Fill(dcc.fedId(), 1);
00327 for (int j=12; j<24; ++j) nDIErr[dcc.fedId()-520][j]++;
00328 }
00329 if (dcc.getOptoRX2() == 128) {
00330 meDCCCRCErr_->Fill(dcc.fedId(), 2);
00331 for (int j=24; j<36; ++j) nDIErr[dcc.fedId()-520][j]++;
00332 }
00333
00334 fiberStatus = dcc.getFEChannelStatus();
00335
00336 for (unsigned int i=0; i<fiberStatus.size(); ++i) {
00337 if (fiberStatus[i]==4 || fiberStatus[i]==8 || fiberStatus[i]==10 || fiberStatus[i]==11 || fiberStatus[i]==12) {
00338 meFiberBadStatus_->Fill(dcc.fedId(), i+1, 1);
00339 meFiberErrCode_->Fill(fiberStatus[i]);
00340 nDIErr[dcc.fedId()-520][i]++;
00341 }
00342 if (fiberStatus[i]==7)
00343 meFiberOff_->Fill(dcc.fedId(), i+1, 1);
00344 if (fiberStatus[i]==6) {
00345 meFiberErrCode_->Fill(fiberStatus[i]);
00346 meEVDR_->Fill(dcc.fedId(), i+1, 1);
00347 }
00348 }
00349
00350 runtype_ = dcc.getRunType();
00351 seqtype_ = dcc.getSeqType();
00352 dac_ = dcc.getDAC();
00353 gain_ = dcc.getGain();
00354 precision_ = dcc.getPrecision();
00355
00356 meGain_->Fill(gain_);
00357 }
00358 } else {
00359 LogWarning("ESIntegrityTask") << dccCollections_ << " not available";
00360 }
00361
00362
00363 if ( e.getByLabel(kchipCollections_, kchips) ) {
00364
00365 for (ESLocalRawDataCollection::const_iterator kItr = kchips->begin(); kItr != kchips->end(); ++kItr) {
00366
00367 ESKCHIPBlock kchip = (*kItr);
00368
00369 meKF1_->Fill(kchip.id(), kchip.getFlag1());
00370 meKF2_->Fill(kchip.id(), kchip.getFlag2());
00371 if (kchip.getBC() != kchip.getOptoBC()) meKBC_->Fill(kchip.id());
00372 if (kchip.getEC() != kchip.getOptoEC()) meKEC_->Fill(kchip.id());
00373 }
00374 } else {
00375 LogWarning("ESIntegrityTask") << kchipCollections_ << " not available";
00376 }
00377
00378
00379 for (int iz=0; iz<2; ++iz)
00380 for (int ip=0; ip<2; ++ip)
00381 for (int ix=0; ix<40; ++ix)
00382 for (int iy=0; iy<40; ++iy) {
00383
00384 if (fed_[iz][ip][ix][iy] == -1) continue;
00385
00386 if (nDIErr[fed_[iz][ip][ix][iy]-520][fiber_[iz][ip][ix][iy]] > 0)
00387 meDIErrors_[iz][ip]->Fill(ix+1, iy+1, 1);
00388
00389 }
00390
00391 }
00392
00393
00394
00395 void ESIntegrityTask::calculateDIFraction(void){
00396
00397 float nValidChannels=0;
00398 float nGlobalErrors=0;
00399
00400 for (int i=0; i<2; ++i) {
00401 for (int j=0; j<2; ++j) {
00402 float nValidChannelsES=0;
00403 float nGlobalErrorsES = 0;
00404 float reportSummaryES = -1;
00405 if (!meDIErrors_[i][j]) continue;
00406 for (int x=0; x<40; ++x) {
00407 for (int y=0; y<40; ++y) {
00408 float val = meDIErrors_[i][j]->getBinContent(x+1, y+1);
00409 if (fed_[i][j][x][y] == -1) continue;
00410 if (ievt_ != 0) nGlobalErrors += val/ievt_;
00411 nValidChannels++;
00412 if (ievt_ != 0) nGlobalErrorsES += val/ievt_;
00413 nValidChannelsES++;
00414 }
00415 }
00416 if (nValidChannelsES != 0) reportSummaryES = 1 - nGlobalErrorsES/nValidChannelsES;
00417 meDIFraction_->setBinContent(i+1, j+1, reportSummaryES);
00418 }
00419 }
00420 float reportSummary = -1.0;
00421 if (nValidChannels != 0) reportSummary = 1.0 - nGlobalErrors/nValidChannels;
00422 meDIFraction_->setBinContent(3,3, reportSummary);
00423 }
00424 DEFINE_FWK_MODULE(ESIntegrityTask);