00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <memory>
00012 #include <iostream>
00013 #include <sstream>
00014 #include <iomanip>
00015 #include <algorithm>
00016 #include <cmath>
00017 #include <math.h>
00018
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 #include "DQMServices/Core/interface/MonitorElement.h"
00023
00024 #ifdef WITH_ECAL_COND_DB
00025 #include "OnlineDB/EcalCondDB/interface/MonOccupancyDat.h"
00026 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00027 #include "DQM/EcalCommon/interface/LogicID.h"
00028 #endif
00029
00030 #include "DQM/EcalCommon/interface/UtilsClient.h"
00031 #include "DQM/EcalCommon/interface/Numbers.h"
00032
00033 #include "DQM/EcalBarrelMonitorClient/interface/EBBeamCaloClient.h"
00034
00035 EBBeamCaloClient::EBBeamCaloClient(const edm::ParameterSet& ps) {
00036
00037
00038 cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00039
00040
00041 verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00042
00043
00044 debug_ = ps.getUntrackedParameter<bool>("debug", false);
00045
00046
00047 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00048
00049
00050 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00051
00052
00053 superModules_.reserve(36);
00054 for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00055 superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00056
00057 checkedSteps_.reserve(86);
00058
00059 minEvtNum_ = 1800;
00060
00061 aveEne1_ = 1850; E1Th_ = 900;
00062 aveEne3x3_ = 2600; E3x3Th_ = 2600;
00063 RMSEne3x3_ = 800;
00064
00065 ReadCryErrThr_ = 0.01;
00066
00067 prescaling_ = 20;
00068
00070 for(int u=0;u<cryInArray_;u++) {
00071 hBGains_[u] = 0;
00072 hBpulse_[u] = 0;
00073
00074 }
00075 hBEne1_ = 0;
00076
00077 hBAllNeededCry_ = 0;
00078 hBNumReadCry_ = 0;
00079 hBE3x3_ = 0;
00080 hBE3x3Moving_ = 0;
00081 hBCryOnBeam_ = 0;
00082 hBMaxEneCry_ = 0;
00083 hBReadCryErrors_ = 0;
00084 hBE1vsCry_ = 0;
00085 hBE3x3vsCry_ = 0;
00086 hBEntriesvsCry_ = 0;
00087 hBcryDone_ = 0;
00088 hBBeamCentered_ = 0;
00089 hbTBmoving_ = 0;
00090 hbE1MaxCry_ = 0;
00091 hbDesync_ = 0;
00092 pBCriInBeamEvents_ = 0;
00093
00094 meEBBCaloRedGreen_ = 0;
00095 meEBBCaloRedGreenReadCry_ = 0;
00096 meEBBCaloRedGreenSteps_ = 0;
00097 }
00098
00099 EBBeamCaloClient::~EBBeamCaloClient() {
00100
00101 }
00102
00103 void EBBeamCaloClient::beginJob(void) {
00104
00105 dqmStore_ = edm::Service<DQMStore>().operator->();
00106
00107 if ( debug_ ) std::cout << "EBBeamCaloClient: beginJob" << std::endl;
00108
00109 ievt_ = 0;
00110 jevt_ = 0;
00111
00112 }
00113
00114 void EBBeamCaloClient::beginRun(void) {
00115
00116 if ( debug_ ) std::cout << "EBBeamCaloClient: beginRun" << std::endl;
00117
00118 jevt_ = 0;
00119
00120 this->setup();
00121
00122 }
00123
00124 void EBBeamCaloClient::endJob(void) {
00125
00126 if ( debug_ ) std::cout << "EBBeamCaloClient: endJob, ievt = " << ievt_ << std::endl;
00127
00128 this->cleanup();
00129
00130 }
00131
00132 void EBBeamCaloClient::endRun(void) {
00133
00134 if ( debug_ ) std::cout << "EBBeamCaloClient: endRun, jevt = " << jevt_ << std::endl;
00135
00136 this->cleanup();
00137
00138 }
00139
00140 void EBBeamCaloClient::setup(void) {
00141
00142 std::string name;
00143
00144 dqmStore_->setCurrentFolder( prefixME_ + "/EBBeamCaloClient" );
00145
00146 if ( meEBBCaloRedGreen_ ) dqmStore_->removeElement( meEBBCaloRedGreen_->getName() );
00147 name = "EBBCT quality";
00148 meEBBCaloRedGreen_ = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
00149
00150 meEBBCaloRedGreen_->Reset();
00151
00152 for ( int ie = 1; ie <= 85; ie++ ) {
00153 for ( int ip = 1; ip <= 20; ip++ ) {
00154
00155 meEBBCaloRedGreen_ ->setBinContent( ie, ip, 2. );
00156
00157 }
00158 }
00159
00160 if ( meEBBCaloRedGreenReadCry_ ) dqmStore_->removeElement( meEBBCaloRedGreenReadCry_->getName() );
00161 name = "EBBCT quality read crystal errors";
00162 meEBBCaloRedGreenReadCry_ = dqmStore_->book2D(name, name, 1, 0., 1., 1, 0., 1.);
00163 meEBBCaloRedGreenReadCry_->Reset();
00164 meEBBCaloRedGreenReadCry_ ->setBinContent( 1, 1, 2. );
00165
00166 if( meEBBCaloRedGreenSteps_ ) dqmStore_->removeElement( meEBBCaloRedGreenSteps_->getName() );
00167 name = "EBBCT quality entries or read crystals errors";
00168 meEBBCaloRedGreenSteps_ = dqmStore_->book2D(name, name, 86, 1., 87., 1, 0., 1.);
00169 meEBBCaloRedGreenSteps_->setAxisTitle("step in the scan");
00170 meEBBCaloRedGreenSteps_->Reset();
00171 for( int bin=1; bin <87; bin++) { meEBBCaloRedGreenSteps_->setBinContent( bin, 1, 2. );}
00172
00173 }
00174
00175 void EBBeamCaloClient::cleanup(void) {
00176 if ( ! enableCleanup_ ) return;
00177 if ( cloneME_ ) {
00178 for(int u=0;u<cryInArray_;u++) {
00179 if(hBGains_[u]) delete hBGains_[u];
00180 if(hBpulse_[u]) delete hBpulse_[u];
00181
00182 }
00183 if(hBEne1_) delete hBEne1_;
00184
00185 if(hBAllNeededCry_) delete hBAllNeededCry_;
00186 if(hBNumReadCry_) delete hBNumReadCry_;
00187 if(hBE3x3_) delete hBE3x3_;
00188 if(hBE3x3Moving_) delete hBE3x3Moving_;
00189 if(hBCryOnBeam_) delete hBCryOnBeam_;
00190 if(hBMaxEneCry_) delete hBMaxEneCry_;
00191 if(hBReadCryErrors_) delete hBReadCryErrors_;
00192 if(hBE1vsCry_) delete hBE1vsCry_;
00193 if(hBE3x3vsCry_) delete hBE3x3vsCry_;
00194 if(hBEntriesvsCry_) delete hBEntriesvsCry_;
00195 if(hBcryDone_) delete hBcryDone_;
00196 if(hBBeamCentered_) delete hBBeamCentered_;
00197 if(hbTBmoving_) delete hbTBmoving_;
00198 if(hbE1MaxCry_) delete hbE1MaxCry_;
00199 if(hbDesync_) delete hbDesync_;
00200 if(pBCriInBeamEvents_) delete pBCriInBeamEvents_;
00201 }
00202
00203 for(int u=0;u<cryInArray_;u++) {
00204 hBGains_[u] = 0;
00205 hBpulse_[u] = 0;
00206
00207 }
00208 hBEne1_ = 0;
00209
00210 hBAllNeededCry_ = 0;
00211 hBNumReadCry_ = 0;
00212 hBE3x3_ = 0;
00213 hBE3x3Moving_ = 0;
00214 hBCryOnBeam_ = 0;
00215 hBMaxEneCry_ = 0;
00216 hBReadCryErrors_ = 0;
00217 hBE1vsCry_ = 0;
00218 hBE3x3vsCry_ = 0;
00219 hBEntriesvsCry_ = 0;
00220 hBcryDone_ = 0;
00221 hBBeamCentered_ = 0;
00222 hbTBmoving_ = 0;
00223 hbE1MaxCry_ = 0;
00224 hbDesync_ = 0;
00225 pBCriInBeamEvents_ =0;
00226
00227 dqmStore_->setCurrentFolder( prefixME_ + "/EBBeamCaloClient" );
00228
00229 if ( meEBBCaloRedGreen_) dqmStore_->removeElement( meEBBCaloRedGreen_->getName() );
00230 meEBBCaloRedGreen_ = 0;
00231 if ( meEBBCaloRedGreenReadCry_) dqmStore_->removeElement( meEBBCaloRedGreenReadCry_->getName() );
00232 meEBBCaloRedGreenReadCry_ = 0;
00233 if( meEBBCaloRedGreenSteps_ ) dqmStore_->removeElement ( meEBBCaloRedGreenSteps_->getName() );
00234 meEBBCaloRedGreenSteps_ = 0;
00235 }
00236
00237 #ifdef WITH_ECAL_COND_DB
00238 bool EBBeamCaloClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00239
00240 status = true;
00241
00242 EcalLogicID ecid;
00243
00244 MonOccupancyDat o;
00245 std::map<EcalLogicID, MonOccupancyDat> dataset;
00246
00247 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00248
00249 int ism = superModules_[i];
00250
00251 if ( verbose_ ) {
00252 std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00253 std::cout << std::endl;
00254 }
00255
00256 const float n_min_tot = 1000.;
00257
00258 float num01, num02;
00259 float mean01;
00260
00261 for ( int ie = 1; ie <= 85; ie++ ) {
00262 for ( int ip = 1; ip <= 20; ip++ ) {
00263
00264 num01 = num02 = -1.;
00265 mean01 = -1.;
00266
00267 bool update_channel = false;
00268
00269 if ( hBCryOnBeam_ && hBCryOnBeam_->GetEntries() >= n_min_tot ) {
00270 num01 = hBCryOnBeam_->GetBinContent(ie, ip);
00271 update_channel = true;
00272 }
00273
00274 if ( hBMaxEneCry_ && hBMaxEneCry_->GetEntries() >= n_min_tot ) {
00275 num02 = hBMaxEneCry_->GetBinContent(ie, ip);
00276 update_channel = true;
00277 }
00278
00279 mean01 = 0.;
00280
00281 int ic = (ip-1) + 20*(ie-1) + 1;
00282 int step = 0;
00283 if (hBcryDone_) { step = (int) hBcryDone_->GetBinContent(ic);}
00284 if( step > 0 && step < 86) {
00285
00286 if( hBE1vsCry_ ) {mean01 = hBE1vsCry_->GetBinContent(ic);}
00287 }
00288
00289 if ( update_channel ) {
00290
00291 if ( Numbers::icEB(ism, ie, ip) == 1 ) {
00292
00293 if ( verbose_ ) {
00294 std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00295 std::cout << "CryOnBeam (" << ie << "," << ip << ") " << num01 << std::endl;
00296 std::cout << "MaxEneCry (" << ie << "," << ip << ") " << num02 << std::endl;
00297 std::cout << "E1 (" << ie << "," << ip << ") " << mean01 << std::endl;
00298 std::cout << std::endl;
00299 }
00300
00301 }
00302
00303 o.setEventsOverHighThreshold(int(num01));
00304 o.setEventsOverLowThreshold(int(num02));
00305
00306 o.setAvgEnergy(mean01);
00307
00308 if ( econn ) {
00309 ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
00310 dataset[ecid] = o;
00311 }
00312
00313 }
00314
00315 }
00316 }
00317
00318 }
00319
00320 if ( econn ) {
00321 try {
00322 if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
00323 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00324 if ( verbose_ ) std::cout << "done." << std::endl;
00325 } catch (std::runtime_error &e) {
00326 std::cerr << e.what() << std::endl;
00327 }
00328 }
00329
00330 return true;
00331
00332 }
00333 #endif
00334
00335 void EBBeamCaloClient::analyze(void) {
00336
00337 ievt_++;
00338 jevt_++;
00339 if ( ievt_ % 10 == 0 ) {
00340 if ( debug_ ) std::cout << "EBBeamCaloClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00341 }
00342
00343 MonitorElement* me = 0;
00344
00345 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT crystals done");
00346 hBcryDone_ = UtilsClient::getHisto( me, cloneME_, hBcryDone_ );
00347
00348 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT crystal on beam");
00349 hBCryOnBeam_ = UtilsClient::getHisto( me, cloneME_, hBCryOnBeam_);
00350
00351 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT all needed crystals readout");
00352 hBAllNeededCry_ = UtilsClient::getHisto( me, cloneME_, hBAllNeededCry_);
00353
00354 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT readout crystals number");
00355 hBNumReadCry_ = UtilsClient::getHisto( me, cloneME_, hBNumReadCry_);
00356
00357 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT rec Ene sum 3x3");
00358 hBE3x3_ = UtilsClient::getHisto( me, cloneME_, hBE3x3_);
00359
00360 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT readout crystals errors");
00361 hBReadCryErrors_ = UtilsClient::getHisto( me, cloneME_, hBReadCryErrors_);
00362
00363 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT rec energy cry 5");
00364 hBEne1_ = UtilsClient::getHisto( me, cloneME_, hBEne1_);
00365
00366 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT crystal with maximum rec energy");
00367 hBMaxEneCry_ = UtilsClient::getHisto( me, cloneME_, hBMaxEneCry_);
00368
00369 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT average rec energy in the 3x3 array");
00370 hBE3x3vsCry_ = UtilsClient::getHisto( me, cloneME_, hBE3x3vsCry_);
00371
00372 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT average rec energy in the single crystal");
00373 hBE1vsCry_ = UtilsClient::getHisto( me, cloneME_, hBE1vsCry_);
00374
00375 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT number of entries");
00376 hBEntriesvsCry_ = UtilsClient::getHisto( me, cloneME_, hBEntriesvsCry_);
00377
00378 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT energy deposition in the 3x3");
00379 hBBeamCentered_ = UtilsClient::getHisto( me, cloneME_, hBBeamCentered_);
00380
00381 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT table is moving");
00382 hbTBmoving_ = UtilsClient::getHisto( me, cloneME_, hbTBmoving_);
00383
00384 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT crystal in beam vs event");
00385 pBCriInBeamEvents_ = UtilsClient::getHisto( me, cloneME_, pBCriInBeamEvents_);
00386
00387 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT E1 in the max cry");
00388 hbE1MaxCry_ = UtilsClient::getHisto( me, cloneME_, hbE1MaxCry_);
00389
00390 me = dqmStore_->get(prefixME_ + "/EBBeamCaloTask/EBBCT Desynchronization vs step");
00391 hbDesync_ = UtilsClient::getHisto( me, cloneME_, hbDesync_);
00392
00393 std::stringstream ss;
00394 for(int ind = 0; ind < cryInArray_; ind ++) {
00395 ss.str("");
00396 ss << prefixME_ << "/EBBeamCaloTask/EBBCT pulse profile in G12 cry " << std::setfill('0') << std::setw(1) << ind+1;
00397 me = dqmStore_->get(ss.str());
00398 hBpulse_[ind] = UtilsClient::getHisto( me, cloneME_, hBpulse_[ind]);
00399
00400 ss.str("");
00401 ss << prefixME_ << "/EBBeamCaloTask/EBBCT found gains cry " << std::setfill('0') << std::setw(1) << ind+1;
00402 me = dqmStore_->get(ss.str());
00403 hBGains_[ind] = UtilsClient::getHisto( me, cloneME_, hBGains_[ind]);
00404 }
00405
00406 int DoneCry = 0;
00407 if (hBcryDone_) {
00408 for(int cry=1 ; cry<1701 ; cry ++) {
00409 int step = (int) hBcryDone_->GetBinContent(cry);
00410 if( step>0 ) {
00411 DoneCry++;
00412 float E3x3RMS = -1, E3x3 =-1, E1=-1;
00413 if(hBE3x3vsCry_) {
00414
00415
00416 E3x3RMS = hBE3x3vsCry_->GetBinError(cry);
00417 E3x3 = hBE3x3vsCry_->GetBinContent(cry);
00418 }
00419
00420 if( hBE1vsCry_) {E1=hBE1vsCry_->GetBinContent(cry);}
00421 bool RMS3x3 = ( E3x3RMS < RMSEne3x3_ && E3x3RMS >= 0 );
00422 bool Mean3x3 = ( std::abs( E3x3 - aveEne3x3_ ) < E3x3Th_);
00423 bool Mean1 = ( std::abs( E1 - aveEne1_ ) < E1Th_ );
00424 int ieta = ( cry - 1)/20 + 1 ;
00425 int iphi = ( cry - 1)%20 + 1 ;
00426
00427 if(ieta >0 && iphi >0 ) {
00428 if(RMS3x3 && Mean3x3 && Mean1) {meEBBCaloRedGreen_->setBinContent(ieta,iphi,1.);}
00429 else {meEBBCaloRedGreen_->setBinContent(ieta,iphi,0.);}
00430 }
00431
00432 float Entries = -1;
00433
00434 if ( hBEntriesvsCry_ ) {Entries = hBEntriesvsCry_->GetBinContent(cry);}
00435 bool Nent = ( Entries * prescaling_ > minEvtNum_ );
00436 bool readCryOk = true;
00437 if( hBReadCryErrors_ ) {
00438 int step_bin = hBReadCryErrors_->GetXaxis()->FindFixBin(step);
00439 if ( step_bin > 0 && step_bin < hBReadCryErrors_->GetNbinsX() ) {
00440 if ( hBReadCryErrors_->GetBinContent(step_bin) <= Entries*ReadCryErrThr_ ) {readCryOk = true;}
00441 else {readCryOk = false;}
00442 }
00443 }
00444
00445 if(Nent && readCryOk ) { meEBBCaloRedGreenSteps_->setBinContent(step,1,1.);}
00446 else{ meEBBCaloRedGreenSteps_->setBinContent(step,1,0.);}
00447
00448 if (readCryOk && meEBBCaloRedGreenReadCry_->getBinContent(1,1) != 0.) { meEBBCaloRedGreenReadCry_->setBinContent(1,1, 1.);}
00449 else if ( !readCryOk ) { meEBBCaloRedGreenReadCry_->setBinContent(1,1, 0.);}
00450 }
00451 }
00452 }
00453
00454 if(DoneCry == 1) {
00455 float nEvt = 0;
00456 if(hBE3x3_) {nEvt = hBE3x3_->GetEntries();}
00457 if(nEvt > 1*prescaling_ && hBE3x3_ && hBEne1_ && hBCryOnBeam_ && meEBBCaloRedGreen_) {
00458 bool RMS3x3 = ( hBE3x3_->GetRMS() < RMSEne3x3_ );
00459 bool Mean3x3 = ( std::abs( hBE3x3_->GetMean() - aveEne3x3_ ) < E3x3Th_ );
00460 bool Mean1 = ( std::abs( hBEne1_->GetMean() - aveEne1_ ) < E1Th_ );
00461
00462 int ieta=0,iphi=0;
00463 float found =0;
00464 for (int b_eta =1; b_eta<86; b_eta++) {
00465 for (int b_phi =1; b_phi<21; b_phi++) {
00466 float bc = hBCryOnBeam_->GetBinContent(b_eta,b_phi);
00467 if(bc > found) { found =bc; ieta = b_eta; iphi= b_phi;}
00468 }
00469 }
00470 if(ieta >0 && iphi >0 ) {
00471 if(RMS3x3 && Mean3x3 && Mean1) {meEBBCaloRedGreen_->setBinContent(ieta,iphi,1.);}
00472 else {meEBBCaloRedGreen_->setBinContent(ieta,iphi,0.);}
00473 }
00474 }
00475 if(hBReadCryErrors_) {
00476 float nErr = hBReadCryErrors_->GetBinContent(1);
00477 if( nErr > nEvt*ReadCryErrThr_ ) { meEBBCaloRedGreenReadCry_->setBinContent(1,1,0.);}
00478 else { meEBBCaloRedGreenReadCry_->setBinContent(1,1,1.);}
00479 }
00480 }
00481 }
00482