00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include <algorithm>
00012
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017
00018 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00019
00020 #include "DQMServices/Core/interface/MonitorElement.h"
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022
00023 #include "DQM/EcalCommon/interface/Numbers.h"
00024 #include "DQM/EcalCommon/interface/UtilsClient.h"
00025
00026 #include "DQM/EcalEndcapMonitorTasks/interface/EEDataCertificationTask.h"
00027
00028 EEDataCertificationTask::EEDataCertificationTask(const edm::ParameterSet& ps) {
00029
00030
00031 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00032
00033 dqmStore_ = edm::Service<DQMStore>().operator->();
00034
00035 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00036
00037 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00038
00039 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00040
00041 meEEDataCertificationSummary_ = 0;
00042 meEEDataCertificationSummaryMap_ = 0;
00043 for (int i = 0; i < 18; i++) {
00044 meEEDataCertification_[i] = 0;
00045 }
00046
00047 hDQM_ = 0;
00048 hDAQ_ = 0;
00049 hIntegrityByLumi_ = 0;
00050 hFrontendByLumi_ = 0;
00051 hSynchronizationByLumi_ = 0;
00052
00053 }
00054
00055 EEDataCertificationTask::~EEDataCertificationTask() {
00056
00057 }
00058
00059 void EEDataCertificationTask::beginJob(void){
00060
00061 char histo[200];
00062
00063 if ( dqmStore_ ) {
00064
00065 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00066
00067 sprintf(histo, "CertificationSummary");
00068 meEEDataCertificationSummary_ = dqmStore_->bookFloat(histo);
00069 meEEDataCertificationSummary_->Fill(-1.0);
00070
00071 sprintf(histo, "CertificationSummaryMap");
00072 meEEDataCertificationSummaryMap_ = dqmStore_->book2D(histo,histo, 200, 0., 200., 100, 0., 100.);
00073 meEEDataCertificationSummaryMap_->setAxisTitle("jx", 1);
00074 meEEDataCertificationSummaryMap_->setAxisTitle("jy", 2);
00075
00076 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/CertificationContents");
00077
00078 for (int i = 0; i < 18; i++) {
00079 sprintf(histo, "EcalEndcap_%s", Numbers::sEE(i+1).c_str());
00080 meEEDataCertification_[i] = dqmStore_->bookFloat(histo);
00081 meEEDataCertification_[i]->Fill(-1.0);
00082 }
00083
00084 }
00085
00086 }
00087
00088 void EEDataCertificationTask::endJob(void) {
00089
00090 if ( enableCleanup_ ) this->cleanup();
00091
00092 }
00093
00094 void EEDataCertificationTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const edm::EventSetup& iSetup){
00095
00096 }
00097
00098 void EEDataCertificationTask::endLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const edm::EventSetup& iSetup) {
00099
00100 this->reset();
00101
00102 char histo[200];
00103
00104 MonitorElement* me;
00105
00106
00107 float DQMVal[18];
00108 for (int i = 0; i < 18; i++) {
00109 DQMVal[i] = -1.;
00110 }
00111
00112 sprintf(histo, (prefixME_ + "/EEIntegrityTask/EEIT weighted integrity errors by lumi").c_str());
00113 me = dqmStore_->get(histo);
00114 hIntegrityByLumi_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hIntegrityByLumi_ );
00115
00116 sprintf(histo, (prefixME_ + "/EEStatusFlagsTask/FEStatus/EESFT weighted frontend errors by lumi").c_str());
00117 me = dqmStore_->get(histo);
00118 hFrontendByLumi_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hFrontendByLumi_ );
00119
00120 sprintf(histo, (prefixME_ + "/EERawDataTask/EERDT FE synchronization errors by lumi").c_str());
00121 me = dqmStore_->get(histo);
00122 hSynchronizationByLumi_ = UtilsClient::getHisto<TH1F*>( me, cloneME_, hSynchronizationByLumi_ );
00123
00124 if( hIntegrityByLumi_ && hFrontendByLumi_ && hSynchronizationByLumi_ ) {
00125
00126 float integrityErrSum = 0.;
00127 float integrityQual = 1.0;
00128 float frontendErrSum = 0.;
00129 float frontendQual = 1.0;
00130 float synchronizationErrSum = 0.;
00131 float synchronizationQual = 1.0;
00132
00133 for ( int i=0; i<18; i++) {
00134 float ismIntegrityQual = 1.0;
00135 if( hIntegrityByLumi_->GetBinContent(0) > 0 ) {
00136 float errors = hIntegrityByLumi_->GetBinContent(i+1);
00137 ismIntegrityQual = 1.0 - errors/hIntegrityByLumi_->GetBinContent(0);
00138 integrityErrSum += errors;
00139 }
00140 float ismFrontendQual = 1.0;
00141 if( hFrontendByLumi_->GetBinContent(0) > 0 ) {
00142 float errors = hFrontendByLumi_->GetBinContent(i+1);
00143 ismFrontendQual = 1.0 - errors/hFrontendByLumi_->GetBinContent(0);
00144 frontendErrSum += errors;
00145 }
00146 float ismSynchronizationQual = 1.0;
00147 if( hSynchronizationByLumi_->GetBinContent(0) > 0 ) {
00148 float errors = hSynchronizationByLumi_->GetBinContent(i+1);
00149 ismSynchronizationQual = 1.0 - errors/hSynchronizationByLumi_->GetBinContent(0);
00150 synchronizationErrSum += errors;
00151 }
00152 float minVal= std::min(ismIntegrityQual,ismFrontendQual);
00153 DQMVal[i] = std::min(minVal,ismSynchronizationQual);
00154 }
00155
00156 if( hIntegrityByLumi_->GetBinContent(0) > 0 ) integrityQual = 1.0 - integrityErrSum/hIntegrityByLumi_->GetBinContent(0)/18.;
00157 if( hFrontendByLumi_->GetBinContent(0) > 0 ) frontendQual = 1.0 - frontendErrSum/hFrontendByLumi_->GetBinContent(0)/18.;
00158 if( hSynchronizationByLumi_->GetBinContent(0) > 0 ) synchronizationQual = 1.0 - synchronizationErrSum/hSynchronizationByLumi_->GetBinContent(0)/36.;
00159 float minVal = std::min(integrityQual,frontendQual);
00160 float totDQMVal = std::min(minVal,synchronizationQual);
00161
00162 sprintf(histo, (prefixME_ + "/EventInfo/reportSummary").c_str());
00163 me = dqmStore_->get(histo);
00164 if( me ) me->Fill(totDQMVal);
00165
00166 for ( int i=0; i<18; i++) {
00167 sprintf(histo, "EcalEndcap_%s", Numbers::sEE(i+1).c_str());
00168 me = dqmStore_->get(prefixME_ + "/EventInfo/reportSummaryContents/" + histo);
00169 if( me ) me->Fill(DQMVal[i]);
00170
00171 sprintf(histo, "reportSummaryMap");
00172 me = dqmStore_->get(prefixME_ + "/EventInfo/" + histo );
00173 if( me ) {
00174 for ( int ix = 1; ix <= 100; ix++ ) {
00175 for ( int iy = 1; iy <= 100; iy++ ) {
00176 int jx = ( i < 9 ) ? ix : 100 + ix;
00177 int jy = iy;
00178 if ( Numbers::validEE(i+1, ix, iy) ) me->setBinContent(jx, jy, DQMVal[i]);
00179 }
00180 }
00181 }
00182 }
00183
00184 }
00185
00186
00187 sprintf(histo, (prefixME_ + "/EventInfo/DAQSummaryMap").c_str());
00188 me = dqmStore_->get(histo);
00189 hDAQ_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDAQ_ );
00190
00191 sprintf(histo, (prefixME_ + "/EventInfo/DCSSummaryMap").c_str());
00192 me = dqmStore_->get(histo);
00193 hDCS_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDCS_ );
00194
00195 float sumCert = 0.;
00196 float sumCertEE[18];
00197 int nValidChannels = 0;
00198 int nValidChannelsEE[18];
00199
00200 for (int i = 0; i < 18; i++) {
00201 sumCertEE[i] = 0;
00202 nValidChannelsEE[i] = 0;
00203 }
00204
00205 for ( int iz = -1; iz < 2; iz+=2 ) {
00206 for ( int ix = 1; ix <= 100; ix++ ) {
00207 for ( int iy = 1; iy <= 100; iy++ ) {
00208 int jx = (iz==1) ? 100 + ix : ix;
00209 int jy = iy;
00210 if( EEDetId::validDetId(ix, iy, iz) ) {
00211
00212
00213 int ism = 0;
00214 int firstSec = ( iz < 0 ) ? 1 : 10;
00215 int lastSec = ( iz < 0 ) ? 9 : 18;
00216 for (int i = firstSec; i <= lastSec; i++) {
00217 if ( Numbers::validEE(i, ix, iy) ) ism = i;
00218 }
00219
00220 float xvalDQM = DQMVal[ism-1];
00221
00222 float xvalDAQ, xvalDCS;
00223 xvalDAQ = xvalDCS = -1.;
00224 float xcert = -1.;
00225
00226 if ( hDAQ_ ) xvalDAQ = hDAQ_->GetBinContent( jx, jy );
00227 if ( hDCS_ ) xvalDCS = hDCS_->GetBinContent( jx, jy );
00228
00229 if ( xvalDQM == -1 || ( xvalDAQ == -1 && xvalDCS == -1 ) ) {
00230
00231 xcert = 0.0;
00232 } else {
00233
00234 xcert = std::abs(xvalDQM) * std::abs(xvalDAQ) * std::abs(xvalDCS);
00235 }
00236
00237 if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->setBinContent( jx, jy, xcert );
00238
00239 sumCertEE[ism-1] += xcert;
00240 nValidChannelsEE[ism-1]++;
00241
00242 sumCert += xcert;
00243 nValidChannels++;
00244
00245 } else {
00246 if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->setBinContent( jx, jy, -1.0 );
00247 }
00248 }
00249 }
00250 }
00251
00252 if( meEEDataCertificationSummary_ ) {
00253 if( nValidChannels>0 ) meEEDataCertificationSummary_->Fill( sumCert/nValidChannels );
00254 else meEEDataCertificationSummary_->Fill( 0.0 );
00255 }
00256
00257 for (int i = 0; i < 18; i++) {
00258 if( meEEDataCertification_[i] ) {
00259 if( nValidChannelsEE[i]>0 ) meEEDataCertification_[i]->Fill( sumCertEE[i]/nValidChannelsEE[i] );
00260 else meEEDataCertification_[i]->Fill( 0.0 );
00261 }
00262 }
00263
00264 }
00265
00266 void EEDataCertificationTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00267
00268 if ( ! mergeRuns_ ) this->reset();
00269
00270 }
00271
00272 void EEDataCertificationTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00273
00274 this->reset();
00275
00276 char histo[200];
00277
00278 MonitorElement* me;
00279
00280 sprintf(histo, (prefixME_ + "/EventInfo/reportSummaryMap").c_str());
00281 me = dqmStore_->get(histo);
00282 hDQM_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDQM_ );
00283
00284 sprintf(histo, (prefixME_ + "/EventInfo/DAQSummaryMap").c_str());
00285 me = dqmStore_->get(histo);
00286 hDAQ_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDAQ_ );
00287
00288 sprintf(histo, (prefixME_ + "/EventInfo/DCSSummaryMap").c_str());
00289 me = dqmStore_->get(histo);
00290 hDCS_ = UtilsClient::getHisto<TH2F*>( me, cloneME_, hDCS_ );
00291
00292 float sumCert = 0.;
00293 float sumCertEE[18];
00294 int nValidChannels = 0;
00295 int nValidChannelsEE[18];
00296
00297 for (int i = 0; i < 18; i++) {
00298 sumCertEE[i] = 0.;
00299 nValidChannelsEE[i] = 0;
00300 }
00301
00302 for ( int iz = -1; iz < 2; iz+=2 ) {
00303 for ( int ix = 1; ix <= 100; ix++ ) {
00304 for ( int iy = 1; iy <= 100; iy++ ) {
00305 int jx = (iz==1) ? 100 + ix : ix;
00306 int jy = iy;
00307 if( EEDetId::validDetId(ix, iy, iz) ) {
00308
00309 float xvalDQM, xvalDAQ, xvalDCS;
00310 xvalDQM = xvalDAQ = xvalDCS = -1.;
00311 float xcert = -1.;
00312
00313 if ( hDQM_ ) xvalDQM = hDQM_->GetBinContent( jx, jy );
00314 if ( hDAQ_ ) xvalDAQ = hDAQ_->GetBinContent( jx, jy );
00315 if ( hDCS_ ) xvalDCS = hDCS_->GetBinContent( jx, jy );
00316
00317 if ( xvalDQM == -1 || ( xvalDAQ == -1 && xvalDCS == -1 ) ) {
00318
00319 xcert = 0.0;
00320 } else {
00321
00322 xcert = std::abs(xvalDQM) * std::abs(xvalDAQ) * std::abs(xvalDCS);
00323 }
00324
00325 if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->setBinContent( jx, jy, xcert );
00326
00327
00328 int firstSec = ( iz < 0 ) ? 1 : 10;
00329 int lastSec = ( iz < 0 ) ? 9 : 18;
00330 for (int i = firstSec; i <= lastSec; i++) {
00331 if ( Numbers::validEE(i, ix, iy) ) {
00332 sumCertEE[i-1] += xcert;
00333 nValidChannelsEE[i-1]++;
00334 }
00335 }
00336
00337 sumCert += xcert;
00338 nValidChannels++;
00339
00340 } else {
00341 if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->setBinContent( jx, jy, -1.0 );
00342 }
00343 }
00344 }
00345 }
00346
00347 if( meEEDataCertificationSummary_ ) {
00348 if( nValidChannels>0 ) {
00349 meEEDataCertificationSummary_->Fill( sumCert/nValidChannels );
00350 } else {
00351 meEEDataCertificationSummary_->Fill( 0.0 );
00352 }
00353 }
00354
00355 for (int i = 0; i < 18; i++) {
00356 if( meEEDataCertification_[i] ) {
00357 if( nValidChannelsEE[i]>0 ) {
00358 meEEDataCertification_[i]->Fill( sumCertEE[i]/nValidChannelsEE[i] );
00359 } else {
00360 meEEDataCertification_[i]->Fill( 0.0 );
00361 }
00362 }
00363 }
00364
00365 }
00366
00367 void EEDataCertificationTask::reset(void) {
00368
00369 if ( meEEDataCertificationSummary_ ) meEEDataCertificationSummary_->Reset();
00370
00371 for (int i = 0; i < 18; i++) {
00372 if ( meEEDataCertification_[i] ) meEEDataCertification_[i]->Reset();
00373 }
00374
00375 if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->Reset();
00376
00377 if ( meEEDataCertificationSummaryMap_ ) meEEDataCertificationSummaryMap_->Reset();
00378
00379 }
00380
00381
00382 void EEDataCertificationTask::cleanup(void){
00383
00384 if ( cloneME_ ) {
00385 if( hDQM_ ) delete hDQM_;
00386 if( hDAQ_ ) delete hDAQ_;
00387 if( hDCS_ ) delete hDCS_;
00388 if( hIntegrityByLumi_ ) delete hIntegrityByLumi_;
00389 if( hFrontendByLumi_ ) delete hFrontendByLumi_;
00390 if( hSynchronizationByLumi_ ) delete hSynchronizationByLumi_;
00391 }
00392 hDQM_ = 0;
00393 hDAQ_ = 0;
00394 hDCS_ = 0;
00395 hIntegrityByLumi_ = 0;
00396 hFrontendByLumi_ = 0;
00397 hSynchronizationByLumi_ = 0;
00398
00399 if ( dqmStore_ ) {
00400 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00401 if ( meEEDataCertificationSummary_ ) dqmStore_->removeElement( meEEDataCertificationSummary_->getName() );
00402 if ( meEEDataCertificationSummaryMap_ ) dqmStore_->removeElement( meEEDataCertificationSummaryMap_->getName() );
00403
00404 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/CertificationContents");
00405 for (int i = 0; i < 18; i++) {
00406 if ( meEEDataCertification_[i] ) dqmStore_->removeElement( meEEDataCertification_[i]->getName() );
00407 }
00408 }
00409
00410 }
00411
00412 void EEDataCertificationTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00413
00414 }