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