CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DQM/EcalEndcapMonitorClient/src/EETriggerTowerClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EETriggerTowerClient.cc
00003  *
00004  * $Date: 2012/04/27 13:46:08 $
00005  * $Revision: 1.102 $
00006  * \author G. Della Ricca
00007  * \author F. Cossutti
00008  *
00009 */
00010 
00011 #include <memory>
00012 #include <iostream>
00013 #include <fstream>
00014 #include <iomanip>
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 #include "DQM/EcalCommon/interface/UtilsClient.h"
00022 #include "DQM/EcalCommon/interface/Numbers.h"
00023 
00024 #include "DQM/EcalEndcapMonitorClient/interface/EETriggerTowerClient.h"
00025 
00026 EETriggerTowerClient::EETriggerTowerClient(const edm::ParameterSet& ps) {
00027 
00028   // cloneME switch
00029   cloneME_ = ps.getUntrackedParameter<bool>("cloneME", true);
00030 
00031   // verbose switch
00032   verbose_ = ps.getUntrackedParameter<bool>("verbose", true);
00033 
00034   // debug switch
00035   debug_ = ps.getUntrackedParameter<bool>("debug", false);
00036 
00037   // prefixME path
00038   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00039 
00040   // enableCleanup_ switch
00041   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00042 
00043   // vector of selected Super Modules (Defaults to all 18).
00044   superModules_.reserve(18);
00045   for ( unsigned int i = 1; i <= 18; i++ ) superModules_.push_back(i);
00046   superModules_ = ps.getUntrackedParameter<std::vector<int> >("superModules", superModules_);
00047 
00048   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00049 
00050     int ism = superModules_[i];
00051 
00052     l01_[ism-1] = 0;
00053     o01_[ism-1] = 0;
00054 
00055     mel01_[ism-1] = 0;
00056     meo01_[ism-1] = 0;
00057 
00058   }
00059 
00060   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00061 
00062     int ism = superModules_[i];
00063 
00064     me_o01_[ism-1] = 0;
00065     me_o02_[ism-1] = 0;
00066 
00067   }
00068 
00069 }
00070 
00071 EETriggerTowerClient::~EETriggerTowerClient() {
00072 
00073 }
00074 
00075 void EETriggerTowerClient::beginJob(void) {
00076 
00077   dqmStore_ = edm::Service<DQMStore>().operator->();
00078 
00079   if ( debug_ ) std::cout << "EETriggerTowerClient: beginJob" << std::endl;
00080 
00081   ievt_ = 0;
00082   jevt_ = 0;
00083 
00084 }
00085 
00086 void EETriggerTowerClient::beginRun(void) {
00087 
00088   if ( debug_ ) std::cout << "EETriggerTowerClient: beginRun" << std::endl;
00089 
00090   jevt_ = 0;
00091 
00092   this->setup();
00093 
00094 }
00095 
00096 void EETriggerTowerClient::endJob(void) {
00097 
00098   if ( debug_ ) std::cout << "EETriggerTowerClient: endJob, ievt = " << ievt_ << std::endl;
00099 
00100   this->cleanup();
00101 
00102 }
00103 
00104 void EETriggerTowerClient::endRun(void) {
00105 
00106   if ( debug_ ) std::cout << "EETriggerTowerClient: endRun, jevt = " << jevt_ << std::endl;
00107 
00108   this->cleanup();
00109 
00110 }
00111 
00112 void EETriggerTowerClient::setup(void) {
00113 
00114   std::string name;
00115 
00116   dqmStore_->setCurrentFolder( prefixME_ + "/EETriggerTowerClient" );
00117 
00118   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00119 
00120     int ism = superModules_[i];
00121 
00122     if ( me_o01_[ism-1] ) dqmStore_->removeElement( me_o01_[ism-1]->getName() );
00123     name = "EETTT Trigger Primitives Timing " + Numbers::sEE(ism);
00124     me_o01_[ism-1] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
00125     me_o01_[ism-1]->setAxisTitle("ix", 1);
00126     if ( ism >= 1 && ism <= 9 ) me_o01_[ism-1]->setAxisTitle("101-ix", 1);
00127     me_o01_[ism-1]->setAxisTitle("iy", 2);
00128 
00129     if ( me_o02_[ism-1] ) dqmStore_->removeElement( me_o02_[ism-1]->getName() );
00130     name = "EETTT Non Single Timing " + Numbers::sEE(ism);
00131     me_o02_[ism-1] = dqmStore_->book2D(name, name, 50, Numbers::ix0EE(ism)+0., Numbers::ix0EE(ism)+50., 50, Numbers::iy0EE(ism)+0., Numbers::iy0EE(ism)+50.);
00132     me_o02_[ism-1]->setAxisTitle("ix", 1);
00133     if ( ism >= 1 && ism <= 9 ) me_o02_[ism-1]->setAxisTitle("101-ix", 1);
00134     me_o02_[ism-1]->setAxisTitle("iy", 2);
00135     me_o02_[ism-1]->setAxisTitle("fraction", 3);
00136 
00137   }
00138 
00139   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00140 
00141     int ism = superModules_[i];
00142 
00143     if ( me_o01_[ism-1] ) me_o01_[ism-1]->Reset();
00144     if ( me_o02_[ism-1] ) me_o02_[ism-1]->Reset();
00145 
00146   }
00147 
00148 }
00149 
00150 void EETriggerTowerClient::cleanup(void) {
00151 
00152   if ( ! enableCleanup_ ) return;
00153 
00154   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00155 
00156     int ism = superModules_[i];
00157 
00158     if ( cloneME_ ) {
00159       if ( l01_[ism-1] ) delete l01_[ism-1];
00160       if ( o01_[ism-1] ) delete o01_[ism-1];
00161     }
00162 
00163     l01_[ism-1] = 0;
00164     o01_[ism-1] = 0;
00165 
00166     mel01_[ism-1] = 0;
00167     meo01_[ism-1] = 0;
00168 
00169   }
00170 
00171   dqmStore_->setCurrentFolder( prefixME_ + "/EETriggerTowerClient" );
00172 
00173   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00174 
00175     int ism = superModules_[i];
00176 
00177     if ( me_o01_[ism-1] ) dqmStore_->removeElement( me_o01_[ism-1]->getName() );
00178     me_o01_[ism-1] = 0;
00179     if ( me_o02_[ism-1] ) dqmStore_->removeElement( me_o02_[ism-1]->getName() );
00180     me_o02_[ism-1] = 0;
00181 
00182   }
00183 
00184 }
00185 
00186 #ifdef WITH_ECAL_COND_DB
00187 bool EETriggerTowerClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00188 
00189   status = true;
00190 
00191   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00192 
00193     int ism = superModules_[i];
00194 
00195     if ( verbose_ ) {
00196       std::cout << " " << Numbers::sEE(ism) << " (ism=" << ism << ")" << std::endl;
00197       std::cout << std::endl;
00198       UtilsClient::printBadChannels(mel01_[ism-1], UtilsClient::getHisto<TH2F*>(mel01_[ism-1]), true);
00199     }
00200 
00201   }
00202 
00203   return true;
00204 
00205 }
00206 #endif
00207 
00208 void EETriggerTowerClient::analyze(void) {
00209 
00210   ievt_++;
00211   jevt_++;
00212   if ( ievt_ % 10 == 0 ) {
00213     if ( debug_ ) std::cout << "EETriggerTowerClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00214   }
00215 
00216   MonitorElement* me;
00217 
00218   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00219 
00220     int ism = superModules_[i];
00221 
00222     me = dqmStore_->get( prefixME_ + "/EETriggerTowerTask/EETTT EmulError " + Numbers::sEE(ism) );
00223     l01_[ism-1] = UtilsClient::getHisto( me, cloneME_, l01_[ism-1] );
00224     mel01_[ism-1] = me;
00225 
00226     me = dqmStore_->get( prefixME_ + "/EETriggerTowerTask/EETTT EmulFineGrainVetoError " + Numbers::sEE(ism) );
00227     l02_[ism-1] = UtilsClient::getHisto( me, cloneME_, l02_[ism-1] );
00228     mel02_[ism-1] = me;
00229 
00230     me = dqmStore_->get( prefixME_ + "/EETriggerTowerTask/EETTT EmulMatch " + Numbers::sEE(ism) );
00231     o01_[ism-1] = UtilsClient::getHisto( me, cloneME_, o01_[ism-1] );
00232     meo01_[ism-1] = me;
00233 
00234     if ( me_o01_[ism-1] ) me_o01_[ism-1]->Reset();
00235     if ( me_o02_[ism-1] ) me_o02_[ism-1]->Reset();
00236 
00237     for (int ix = 1; ix <= 50; ix++) {
00238       for (int iy = 1; iy <= 50; iy++) {
00239 
00240         if ( o01_[ism-1] ) {
00241           // find the most frequent TP timing that matches the emulator
00242           float index=-1;
00243           double max=0;
00244           double total=0;
00245           for (int j=0; j<6; j++) {
00246             double sampleEntries = o01_[ism-1]->GetBinContent(ix, iy, j+1);
00247             if(sampleEntries > max) {
00248               index=j;
00249               max = sampleEntries;
00250             }
00251             total += sampleEntries;
00252           }
00253           if ( max > 0 ) {
00254             if ( index == 0 ) {
00255               me_o01_[ism-1]->setBinContent(ix, iy, -1);
00256             } else {
00257               me_o01_[ism-1]->setBinContent(ix, iy, index );
00258             }
00259           }
00260           double fraction = (total > 0) ? 1.0 - max/total : 0.;
00261           if ( me_o02_[ism-1] ) me_o02_[ism-1]->setBinContent(ix, iy, fraction);
00262         }
00263 
00264       }
00265     }
00266 
00267   }
00268 
00269 }
00270