CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQM/EcalBarrelMonitorClient/src/EBTimingClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBTimingClient.cc
00003  *
00004  * $Date: 2012/04/27 13:45:59 $
00005  * $Revision: 1.115 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <memory>
00011 #include <iostream>
00012 #include <fstream>
00013 #include <iomanip>
00014 #include <math.h>
00015 
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 #include "DQMServices/Core/interface/MonitorElement.h"
00020 
00021 #ifdef WITH_ECAL_COND_DB
00022 #include "OnlineDB/EcalCondDB/interface/MonTimingCrystalDat.h"
00023 #include "OnlineDB/EcalCondDB/interface/RunCrystalErrorsDat.h"
00024 #include "OnlineDB/EcalCondDB/interface/RunTTErrorsDat.h"
00025 #include "OnlineDB/EcalCondDB/interface/EcalCondDBInterface.h"
00026 #include "DQM/EcalCommon/interface/LogicID.h"
00027 #endif
00028 
00029 #include "DQM/EcalCommon/interface/Masks.h"
00030 
00031 #include "DQM/EcalCommon/interface/UtilsClient.h"
00032 #include "DQM/EcalCommon/interface/Numbers.h"
00033 
00034 #include "DQM/EcalBarrelMonitorClient/interface/EBTimingClient.h"
00035 
00036 EBTimingClient::EBTimingClient(const edm::ParameterSet& ps) {
00037 
00038   // cloneME switch
00039   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00040 
00041   // verbose switch
00042   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00043 
00044   // debug switch
00045   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00046 
00047   // prefixME path
00048   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00049 
00050   // enableCleanup_ switch
00051   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00052 
00053   // vector of selected Super Modules (Defaults to all 36).
00054   superModules_.reserve(36);
00055   for ( unsigned int i = 1; i <= 36; i++ ) superModules_.push_back(i);
00056   superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00057 
00058   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00059 
00060     int ism = superModules_[i];
00061 
00062     h01_[ism-1] = 0;
00063     h02_[ism-1] = 0;
00064 
00065     meh01_[ism-1] = 0;
00066     meh02_[ism-1] = 0;
00067 
00068   }
00069 
00070   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00071 
00072     int ism = superModules_[i];
00073 
00074     meg01_[ism-1] = 0;
00075 
00076     mea01_[ism-1] = 0;
00077 
00078     mep01_[ism-1] = 0;
00079 
00080     mer01_[ism-1] = 0;
00081 
00082   }
00083 
00084   meTimeSummaryMapProjEta_ = 0;
00085   meTimeSummaryMapProjPhi_ = 0;
00086 
00087   expectedMean_ = 0.0;
00088   discrepancyMean_ = 2.0;
00089   RMSThreshold_ = 6.0;
00090 
00091   nHitThreshold_ = ps.getUntrackedParameter<int>("timingNHitThrehold", 5);
00092 
00093   ievt_ = 0;
00094   jevt_ = 0;
00095   dqmStore_ = 0;
00096 }
00097 
00098 EBTimingClient::~EBTimingClient() {
00099 
00100 }
00101 
00102 void EBTimingClient::beginJob(void) {
00103 
00104   dqmStore_ = edm::Service<DQMStore>().operator->();
00105 
00106   if ( debug_ ) std::cout << "EBTimingClient: beginJob" << std::endl;
00107 
00108   ievt_ = 0;
00109   jevt_ = 0;
00110 
00111 }
00112 
00113 void EBTimingClient::beginRun(void) {
00114 
00115   if ( debug_ ) std::cout << "EBTimingClient: beginRun" << std::endl;
00116 
00117   jevt_ = 0;
00118 
00119   this->setup();
00120 
00121 }
00122 
00123 void EBTimingClient::endJob(void) {
00124 
00125   if ( debug_ ) std::cout << "EBTimingClient: endJob, ievt = " << ievt_ << std::endl;
00126 
00127   this->cleanup();
00128 
00129 }
00130 
00131 void EBTimingClient::endRun(void) {
00132 
00133   if ( debug_ ) std::cout << "EBTimingClient: endRun, jevt = " << jevt_ << std::endl;
00134 
00135   this->cleanup();
00136 
00137 }
00138 
00139 void EBTimingClient::setup(void) {
00140 
00141   std::string name;
00142 
00143   dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
00144 
00145   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00146 
00147     int ism = superModules_[i];
00148 
00149     if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
00150     name = "EBTMT timing quality " + Numbers::sEB(ism);
00151     meg01_[ism-1] = dqmStore_->book2D(name, name, 85, 0., 85., 20, 0., 20.);
00152     meg01_[ism-1]->setAxisTitle("ieta", 1);
00153     meg01_[ism-1]->setAxisTitle("iphi", 2);
00154 
00155     if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
00156     name = "EBTMT timing " + Numbers::sEB(ism);
00157     mea01_[ism-1] = dqmStore_->book1D(name, name, 1700, 0., 1700.);
00158     mea01_[ism-1]->setAxisTitle("channel", 1);
00159     mea01_[ism-1]->setAxisTitle("time (ns)", 2);
00160 
00161     if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
00162     name = "EBTMT timing mean " + Numbers::sEB(ism);
00163     mep01_[ism-1] = dqmStore_->book1D(name, name, 100, -25.0, 25.0);
00164     mep01_[ism-1]->setAxisTitle("mean (ns)", 1);
00165 
00166     if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
00167     name = "EBTMT timing rms " + Numbers::sEB(ism);
00168     mer01_[ism-1] = dqmStore_->book1D(name, name, 100, 0.0, 10.0);
00169     mer01_[ism-1]->setAxisTitle("rms (ns)", 1);
00170 
00171   }
00172 
00173   name = "EBTMT timing projection eta";
00174   meTimeSummaryMapProjEta_ = dqmStore_->bookProfile(name, name, 34, -85., 85., -20., 20., "");
00175   meTimeSummaryMapProjEta_->setAxisTitle("jeta", 1);
00176   meTimeSummaryMapProjEta_->setAxisTitle("time (ns)", 2);
00177 
00178   name = "EBTMT timing projection phi";
00179   meTimeSummaryMapProjPhi_ = dqmStore_->bookProfile(name, name, 72, 0., 360., -20., 20., "");
00180   meTimeSummaryMapProjPhi_->setAxisTitle("jphi", 1);
00181   meTimeSummaryMapProjPhi_->setAxisTitle("time (ns)", 2);
00182 
00183   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00184 
00185     int ism = superModules_[i];
00186 
00187     if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
00188 
00189     for ( int ie = 1; ie <= 85; ie++ ) {
00190       for ( int ip = 1; ip <= 20; ip++ ) {
00191 
00192         if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent( ie, ip, 2. );
00193 
00194       }
00195     }
00196 
00197     if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
00198     if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
00199     if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
00200 
00201   }
00202 
00203 
00204 
00205 }
00206 
00207 void EBTimingClient::cleanup(void) {
00208 
00209   if ( ! enableCleanup_ ) return;
00210 
00211   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00212 
00213     int ism = superModules_[i];
00214 
00215     if ( cloneME_ ) {
00216       if ( h01_[ism-1] ) delete h01_[ism-1];
00217       if ( h02_[ism-1] ) delete h02_[ism-1];
00218     }
00219 
00220     h01_[ism-1] = 0;
00221     h02_[ism-1] = 0;
00222 
00223     meh01_[ism-1] = 0;
00224     meh02_[ism-1] = 0;
00225 
00226   }
00227 
00228   dqmStore_->setCurrentFolder( prefixME_ + "/EBTimingClient" );
00229 
00230   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00231 
00232     int ism = superModules_[i];
00233 
00234     if ( meg01_[ism-1] ) dqmStore_->removeElement( meg01_[ism-1]->getName() );
00235     meg01_[ism-1] = 0;
00236 
00237     if ( mea01_[ism-1] ) dqmStore_->removeElement( mea01_[ism-1]->getName() );
00238     mea01_[ism-1] = 0;
00239 
00240     if ( mep01_[ism-1] ) dqmStore_->removeElement( mep01_[ism-1]->getName() );
00241     mep01_[ism-1] = 0;
00242 
00243     if ( mer01_[ism-1] ) dqmStore_->removeElement( mer01_[ism-1]->getName() );
00244     mer01_[ism-1] = 0;
00245 
00246   }
00247 
00248   if ( meTimeSummaryMapProjEta_ ) dqmStore_->removeElement( meTimeSummaryMapProjEta_->getName() );
00249   if ( meTimeSummaryMapProjPhi_ ) dqmStore_->removeElement( meTimeSummaryMapProjPhi_->getName() );
00250 
00251 }
00252 
00253 #ifdef WITH_ECAL_COND_DB
00254 bool EBTimingClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00255 
00256   status = true;
00257 
00258   EcalLogicID ecid;
00259 
00260   MonTimingCrystalDat t;
00261   std::map<EcalLogicID, MonTimingCrystalDat> dataset;
00262 
00263   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00264 
00265     int ism = superModules_[i];
00266 
00267     if ( verbose_ ) {
00268       std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00269       std::cout << std::endl;
00270       UtilsClient::printBadChannels(meg01_[ism-1], h01_[ism-1]);
00271     }
00272 
00273     float num01;
00274     float mean01;
00275     float rms01;
00276 
00277     for ( int ie = 1; ie <= 85; ie++ ) {
00278       for ( int ip = 1; ip <= 20; ip++ ) {
00279 
00280         bool update01;
00281 
00282         update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01, nHitThreshold_);
00283         // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
00284         mean01 -= 50.;
00285 
00286         if ( update01 ) {
00287 
00288           if ( Numbers::icEB(ism, ie, ip) == 1 ) {
00289 
00290             if ( verbose_ ) {
00291               std::cout << "Preparing dataset for " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00292               std::cout << "crystal (" << ie << "," << ip << ") " << num01  << " " << mean01 << " " << rms01  << std::endl;
00293               std::cout << std::endl;
00294             }
00295 
00296           }
00297 
00298           t.setTimingMean(mean01);
00299           t.setTimingRMS(rms01);
00300 
00301           if ( UtilsClient::getBinStatus(meg01_[ism-1], ie, ip) ) {
00302             t.setTaskStatus(true);
00303           } else {
00304             t.setTaskStatus(false);
00305           }
00306 
00307           status = status && UtilsClient::getBinQuality(meg01_[ism-1], ie, ip);
00308 
00309           int ic = Numbers::indexEB(ism, ie, ip);
00310 
00311           if ( econn ) {
00312             ecid = LogicID::getEcalLogicID("EB_crystal_number", Numbers::iSM(ism, EcalBarrel), ic);
00313             dataset[ecid] = t;
00314           }
00315 
00316         }
00317 
00318       }
00319     }
00320 
00321   }
00322 
00323   if ( econn ) {
00324     try {
00325       if ( verbose_ ) std::cout << "Inserting MonTimingCrystalDat ..." << std::endl;
00326       if ( dataset.size() != 0 ) econn->insertDataArraySet(&dataset, moniov);
00327       if ( verbose_ ) std::cout << "done." << std::endl;
00328     } catch (std::runtime_error &e) {
00329       std::cerr << e.what() << std::endl;
00330     }
00331   }
00332 
00333   return true;
00334 
00335 }
00336 #endif
00337 
00338 void EBTimingClient::analyze(void) {
00339 
00340   ievt_++;
00341   jevt_++;
00342   if ( ievt_ % 10 == 0 ) {
00343     if ( debug_ ) std::cout << "EBTimingClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00344   }
00345 
00346   uint32_t bits01 = 0;
00347   bits01 |= 1 << EcalDQMStatusHelper::PHYSICS_BAD_CHANNEL_WARNING;
00348 
00349   MonitorElement* me;
00350 
00351   if( meTimeSummaryMapProjEta_ ) meTimeSummaryMapProjEta_->Reset();
00352   if( meTimeSummaryMapProjPhi_ ) meTimeSummaryMapProjPhi_->Reset();
00353 
00354   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00355 
00356     int ism = superModules_[i];
00357 
00358     me = dqmStore_->get( prefixME_ + "/EBTimingTask/EBTMT timing " + Numbers::sEB(ism) );
00359     h01_[ism-1] = UtilsClient::getHisto<TProfile2D*>( me, cloneME_, h01_[ism-1] );
00360     meh01_[ism-1] = me;
00361 
00362     me = dqmStore_->get( prefixME_ + "/EBTimingTask/EBTMT timing vs amplitude " + Numbers::sEB(ism) );
00363     h02_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, h02_[ism-1] );
00364     meh02_[ism-1] = me;
00365 
00366     if ( meg01_[ism-1] ) meg01_[ism-1]->Reset();
00367     if ( mea01_[ism-1] ) mea01_[ism-1]->Reset();
00368     if ( mep01_[ism-1] ) mep01_[ism-1]->Reset();
00369     if ( mer01_[ism-1] ) mer01_[ism-1]->Reset();
00370 
00371     for ( int ie = 1; ie <= 85; ie++ ) {
00372       for ( int ip = 1; ip <= 20; ip++ ) {
00373 
00374         if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, 2.);
00375 
00376         bool update01;
00377 
00378         float num01;
00379         float mean01;
00380         float rms01;
00381 
00382         update01 = UtilsClient::getBinStatistics(h01_[ism-1], ie, ip, num01, mean01, rms01, nHitThreshold_);
00383         // Task timing map is shifted of +50 ns for graphical reasons. Shift back it.
00384         mean01 -= 50.;
00385 
00386         if ( update01 ) {
00387 
00388           float val;
00389 
00390           val = 1.;
00391           if ( std::abs(mean01 - expectedMean_) > discrepancyMean_ )
00392             val = 0.;
00393           if ( rms01 > RMSThreshold_ )
00394             val = 0.;
00395           if ( meg01_[ism-1] ) meg01_[ism-1]->setBinContent(ie, ip, val);
00396 
00397           int ic = Numbers::icEB(ism, ie, ip);
00398 
00399           if ( mea01_[ism-1] ) {
00400             mea01_[ism-1]->setBinContent(ic, mean01);
00401             mea01_[ism-1]->setBinError(ic, rms01);
00402           }
00403           if ( mep01_[ism-1] ) mep01_[ism-1]->Fill(mean01);
00404           if ( mer01_[ism-1] ) mer01_[ism-1]->Fill(rms01);
00405 
00406           float eta, phi;
00407 
00408           if ( ism <= 18 ) {
00409             eta = -ie+0.5;
00410             phi = ip+20*(ism-1)-0.5;
00411           } else {
00412             eta = ie-0.5;
00413             phi = (20-ip)+20*(ism-19)+0.5;
00414           }
00415 
00416           if( meTimeSummaryMapProjEta_ ) meTimeSummaryMapProjEta_->Fill(eta, mean01);
00417           if( meTimeSummaryMapProjPhi_ ) meTimeSummaryMapProjPhi_->Fill(phi, mean01);
00418 
00419         }
00420 
00421         if ( Masks::maskChannel(ism, ie, ip, bits01, EcalBarrel) ) UtilsClient::maskBinContent( meg01_[ism-1], ie, ip );
00422 
00423 
00424 
00425       }
00426     }
00427 
00428   }
00429 
00430 }
00431