00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <memory>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <iomanip>
00015 #include <math.h>
00016
00017 #include "FWCore/ServiceRegistry/interface/Service.h"
00018
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 #include "DQMServices/Core/interface/MonitorElement.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/EcalBarrelMonitorClient/interface/EBOccupancyClient.h"
00032
00033 EBOccupancyClient::EBOccupancyClient(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(36);
00052 for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00053 superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00054
00055 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00056 int ism = superModules_[i];
00057 i01_[ism-1] = 0;
00058 i02_[ism-1] = 0;
00059 }
00060
00061 for ( int i=0; i<3; i++) {
00062 h01_[i] = 0;
00063 h01ProjEta_[i] = 0;
00064 h01ProjPhi_[i] = 0;
00065 }
00066
00067 for ( int i=0; i<2; i++) {
00068 h02_[i] = 0;
00069 h02ProjEta_[i] = 0;
00070 h02ProjPhi_[i] = 0;
00071 }
00072
00073 }
00074
00075 EBOccupancyClient::~EBOccupancyClient() {
00076
00077 }
00078
00079 void EBOccupancyClient::beginJob(void) {
00080
00081 dqmStore_ = edm::Service<DQMStore>().operator->();
00082
00083 if ( debug_ ) std::cout << "EBOccupancyClient: beginJob" << std::endl;
00084
00085 ievt_ = 0;
00086 jevt_ = 0;
00087
00088 }
00089
00090 void EBOccupancyClient::beginRun(void) {
00091
00092 if ( debug_ ) std::cout << "EBOccupancyClient: beginRun" << std::endl;
00093
00094 jevt_ = 0;
00095
00096 this->setup();
00097
00098 }
00099
00100 void EBOccupancyClient::endJob(void) {
00101
00102 if ( debug_ ) std::cout << "EBOccupancyClient: endJob, ievt = " << ievt_ << std::endl;
00103
00104 this->cleanup();
00105
00106 }
00107
00108 void EBOccupancyClient::endRun(void) {
00109
00110 if ( debug_ ) std::cout << "EBOccupancyClient: endRun, jevt = " << jevt_ << std::endl;
00111
00112 this->cleanup();
00113
00114 }
00115
00116 void EBOccupancyClient::setup(void) {
00117
00118 dqmStore_->setCurrentFolder( prefixME_ + "/EBOccupancyClient" );
00119
00120 }
00121
00122 void EBOccupancyClient::cleanup(void) {
00123
00124 if ( ! enableCleanup_ ) return;
00125
00126 if ( cloneME_ ) {
00127
00128 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00129 int ism = superModules_[i];
00130 if ( i01_[ism-1] ) delete i01_[ism-1];
00131 if ( i02_[ism-1] ) delete i02_[ism-1];
00132 }
00133
00134 for ( int i=0; i<3; ++i ) {
00135 if ( h01_[i] ) delete h01_[i];
00136 if ( h01ProjEta_[i] ) delete h01ProjEta_[i];
00137 if ( h01ProjPhi_[i] ) delete h01ProjPhi_[i];
00138 }
00139
00140 for ( int i=0; i<2; ++i ) {
00141 if ( h02_[i] ) delete h02_[i];
00142 if ( h02ProjEta_[i] ) delete h02ProjEta_[i];
00143 if ( h02ProjPhi_[i] ) delete h02ProjPhi_[i];
00144 }
00145
00146 }
00147
00148 for ( int i=0; i<3; ++i ) {
00149 h01_[i] = 0;
00150 h01ProjEta_[i] = 0;
00151 h01ProjPhi_[i] = 0;
00152 }
00153
00154 for ( int i=0; i<2; ++i ) {
00155 h02_[i] = 0;
00156 h02ProjEta_[i] = 0;
00157 h02ProjPhi_[i] = 0;
00158 }
00159
00160 }
00161
00162 #ifdef WITH_ECAL_COND_DB
00163 bool EBOccupancyClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00164
00165 status = true;
00166
00167 EcalLogicID ecid;
00168
00169 MonOccupancyDat o;
00170 std::map<EcalLogicID, MonOccupancyDat> dataset;
00171
00172 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00173
00174 int ism = superModules_[i];
00175
00176 if ( verbose_ ) {
00177 std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00178 std::cout << std::endl;
00179 }
00180
00181 const float n_min_tot = 1000.;
00182 const float n_min_bin = 10.;
00183
00184 float num01, num02;
00185 float mean01, mean02;
00186 float rms01, rms02;
00187
00188 for ( int ie = 1; ie <= 85; ie++ ) {
00189 for ( int ip = 1; ip <= 20; ip++ ) {
00190
00191 num01 = num02 = -1.;
00192 mean01 = mean02 = -1.;
00193 rms01 = rms02 = -1.;
00194
00195 bool update_channel = false;
00196
00197 if ( i01_[ism-1] && i01_[ism-1]->GetEntries() >= n_min_tot ) {
00198 num01 = i01_[ism-1]->GetBinContent(ie, ip);
00199 if ( num01 >= n_min_bin ) update_channel = true;
00200 }
00201
00202 if ( i02_[ism-1] && i02_[ism-1]->GetEntries() >= n_min_tot ) {
00203 num02 = i02_[ism-1]->GetBinEntries(i02_[ism-1]->GetBin(ie, ip));
00204 if ( num02 >= n_min_bin ) {
00205 mean02 = i02_[ism-1]->GetBinContent(ie, ip);
00206 rms02 = i02_[ism-1]->GetBinError(ie, ip);
00207 }
00208 }
00209
00210 if ( update_channel ) {
00211
00212 if ( Numbers::icEB(ism, ie, ip) == 1 ) {
00213
00214 if ( verbose_ ) {
00215 std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00216 std::cout << "Digi (" << ie << "," << ip << ") " << num01 << " " << mean01 << " " << rms01 << std::endl;
00217 std::cout << "RecHitThr (" << ie << "," << ip << ") " << num02 << " " << mean02 << " " << rms02 << std::endl;
00218 std::cout << std::endl;
00219 }
00220
00221 }
00222
00223 o.setEventsOverLowThreshold(int(num01));
00224 o.setEventsOverHighThreshold(int(num02));
00225
00226 o.setAvgEnergy(mean02);
00227
00228 int ic = Numbers::indexEB(ism, ie, ip);
00229
00230 if ( econn ) {
00231 ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
00232 dataset[ecid] = o;
00233 }
00234
00235 }
00236
00237 }
00238 }
00239
00240 }
00241
00242 if ( econn ) {
00243 try {
00244 if ( verbose_ ) std::cout << "Inserting MonOccupancyDat ..." << std::endl;
00245 if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00246 if ( verbose_ ) std::cout << "done." << std::endl;
00247 } catch (std::runtime_error &e) {
00248 std::cerr << e.what() << std::endl;
00249 }
00250 }
00251
00252 return true;
00253
00254 }
00255 #endif
00256
00257 void EBOccupancyClient::analyze(void) {
00258
00259 ievt_++;
00260 jevt_++;
00261 if ( ievt_ % 10 == 0 ) {
00262 if ( debug_ ) std::cout << "EBOccupancyClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00263 }
00264
00265 MonitorElement* me;
00266
00267 for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00268
00269 int ism = superModules_[i];
00270
00271 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy " + Numbers::sEB(ism) );
00272 i01_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, i01_[ism-1] );
00273
00274 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit energy " + Numbers::sEB(ism) );
00275 i02_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, i02_[ism-1] );
00276
00277 }
00278
00279 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy" );
00280 h01_[0] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[0] );
00281
00282 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy projection eta" );
00283 h01ProjEta_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[0] );
00284
00285 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT digi occupancy projection phi" );
00286 h01ProjPhi_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[0] );
00287
00288 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy" );
00289 h01_[1] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[1] );
00290
00291 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy projection eta" );
00292 h01ProjEta_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[1] );
00293
00294 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit occupancy projection phi" );
00295 h01ProjPhi_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[1] );
00296
00297 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy" );
00298 h01_[2] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h01_[2] );
00299
00300 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy projection eta" );
00301 h01ProjEta_[2] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjEta_[2] );
00302
00303 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi occupancy projection phi" );
00304 h01ProjPhi_[2] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h01ProjPhi_[2] );
00305
00306 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy" );
00307 h02_[0] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h02_[0] );
00308
00309 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy projection eta" );
00310 h02ProjEta_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjEta_[0] );
00311
00312 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT rec hit thr occupancy projection phi" );
00313 h02ProjPhi_[0] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjPhi_[0] );
00314
00315 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy" );
00316 h02_[1] = UtilsClient::getHisto<TH2F*> ( me, cloneME_, h02_[1] );
00317
00318 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy projection eta" );
00319 h02ProjEta_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjEta_[1] );
00320
00321 me = dqmStore_->get( prefixME_ + "/EBOccupancyTask/EBOT TP digi thr occupancy projection phi" );
00322 h02ProjPhi_[1] = UtilsClient::getHisto<TH1F*> ( me, cloneME_, h02ProjPhi_[1] );
00323
00324 }
00325