CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/EcalBarrelMonitorClient/src/EBTriggerTowerClient.cc

Go to the documentation of this file.
00001 /*
00002  * \file EBTriggerTowerClient.cc
00003  *
00004  * $Date: 2012/04/27 13:45:59 $
00005  * $Revision: 1.131 $
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/EcalBarrelMonitorClient/interface/EBTriggerTowerClient.h"
00025 
00026 EBTriggerTowerClient::EBTriggerTowerClient(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 36).
00044   superModules_.reserve(36);
00045   for ( unsigned int i = 1; i <= 36; 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 EBTriggerTowerClient::~EBTriggerTowerClient() {
00072 
00073 }
00074 
00075 void EBTriggerTowerClient::beginJob(void) {
00076 
00077   dqmStore_ = edm::Service<DQMStore>().operator->();
00078 
00079   if ( debug_ ) std::cout << "EBTriggerTowerClient: beginJob" << std::endl;
00080 
00081   ievt_ = 0;
00082   jevt_ = 0;
00083 
00084 }
00085 
00086 void EBTriggerTowerClient::beginRun(void) {
00087 
00088   if ( debug_ ) std::cout << "EBTriggerTowerClient: beginRun" << std::endl;
00089 
00090   jevt_ = 0;
00091 
00092   this->setup();
00093 
00094 }
00095 
00096 void EBTriggerTowerClient::endJob(void) {
00097 
00098   if ( debug_ ) std::cout << "EBTriggerTowerClient: endJob, ievt = " << ievt_ << std::endl;
00099 
00100   this->cleanup();
00101 
00102 }
00103 
00104 void EBTriggerTowerClient::endRun(void) {
00105 
00106   if ( debug_ ) std::cout << "EBTriggerTowerClient: endRun, jevt = " << jevt_ << std::endl;
00107 
00108   this->cleanup();
00109 
00110 }
00111 
00112 void EBTriggerTowerClient::setup(void) {
00113 
00114   std::string name;
00115 
00116   dqmStore_->setCurrentFolder( prefixME_ + "/EBTriggerTowerClient" );
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 = "EBTTT Trigger Primitives Timing " + Numbers::sEB(ism);
00124     me_o01_[ism-1] = dqmStore_->book2D(name, name, 17, 0., 17., 4, 0., 4.);
00125     me_o01_[ism-1]->setAxisTitle("ieta'", 1);
00126     me_o01_[ism-1]->setAxisTitle("iphi'", 2);
00127 
00128     if ( me_o02_[ism-1] ) dqmStore_->removeElement( me_o02_[ism-1]->getName() );
00129     name = "EBTTT Non Single Timing " + Numbers::sEB(ism);
00130     me_o02_[ism-1] = dqmStore_->book2D(name, name, 17, 0., 17., 4, 0., 4.);
00131     me_o02_[ism-1]->setAxisTitle("ieta'", 1);
00132     me_o02_[ism-1]->setAxisTitle("iphi'", 2);
00133     me_o02_[ism-1]->setAxisTitle("fraction", 3);
00134 
00135   }
00136 
00137   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00138 
00139     int ism = superModules_[i];
00140 
00141     if ( me_o01_[ism-1] ) me_o01_[ism-1]->Reset();
00142     if ( me_o02_[ism-1] ) me_o02_[ism-1]->Reset();
00143 
00144   }
00145 
00146 }
00147 
00148 void EBTriggerTowerClient::cleanup(void) {
00149 
00150   if ( ! enableCleanup_ ) return;
00151 
00152   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00153 
00154     int ism = superModules_[i];
00155 
00156     if ( cloneME_ ) {
00157       if ( l01_[ism-1] ) delete l01_[ism-1];
00158       if ( o01_[ism-1] ) delete o01_[ism-1];
00159     }
00160 
00161     l01_[ism-1] = 0;
00162     o01_[ism-1] = 0;
00163 
00164     mel01_[ism-1] = 0;
00165     meo01_[ism-1] = 0;
00166 
00167   }
00168 
00169   dqmStore_->setCurrentFolder( prefixME_ + "/EBTriggerTowerClient" );
00170 
00171   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00172 
00173     int ism = superModules_[i];
00174 
00175     if ( me_o01_[ism-1] ) dqmStore_->removeElement( me_o01_[ism-1]->getName() );
00176     me_o01_[ism-1] = 0;
00177     if ( me_o02_[ism-1] ) dqmStore_->removeElement( me_o02_[ism-1]->getName() );
00178     me_o02_[ism-1] = 0;
00179 
00180   }
00181 
00182 }
00183 
00184 #ifdef WITH_ECAL_COND_DB
00185 bool EBTriggerTowerClient::writeDb(EcalCondDBInterface* econn, RunIOV* runiov, MonRunIOV* moniov, bool& status) {
00186 
00187   status = true;
00188 
00189   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00190 
00191     int ism = superModules_[i];
00192 
00193     if ( verbose_ ) {
00194       std::cout << " " << Numbers::sEB(ism) << " (ism=" << ism << ")" << std::endl;
00195       std::cout << std::endl;
00196       UtilsClient::printBadChannels(mel01_[ism-1], UtilsClient::getHisto<TH2F*>(mel01_[ism-1]), true);
00197     }
00198 
00199   }
00200 
00201   return true;
00202 
00203 }
00204 #endif
00205 
00206 void EBTriggerTowerClient::analyze(void) {
00207 
00208   ievt_++;
00209   jevt_++;
00210   if ( ievt_ % 10 == 0 ) {
00211     if ( debug_ ) std::cout << "EBTriggerTowerClient: ievt/jevt = " << ievt_ << "/" << jevt_ << std::endl;
00212   }
00213 
00214   MonitorElement* me;
00215 
00216   for ( unsigned int i=0; i<superModules_.size(); i++ ) {
00217 
00218     int ism = superModules_[i];
00219 
00220     me = dqmStore_->get( prefixME_ + "/EBTriggerTowerTask/EBTTT EmulError " + Numbers::sEB(ism) );
00221     l01_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, l01_[ism-1] );
00222     mel01_[ism-1] = me;
00223 
00224     me = dqmStore_->get( prefixME_ + "/EBTriggerTowerTask/EBTTT EmulFineGrainVetoError " + Numbers::sEB(ism) );
00225     l02_[ism-1] = UtilsClient::getHisto<TH2F*>( me, cloneME_, l02_[ism-1] );
00226     mel02_[ism-1] = me;
00227 
00228     me = dqmStore_->get( prefixME_ + "/EBTriggerTowerTask/EBTTT EmulMatch " + Numbers::sEB(ism) );
00229     o01_[ism-1] = UtilsClient::getHisto<TH3F*>( me, cloneME_, o01_[ism-1] );
00230     meo01_[ism-1] = me;
00231 
00232     if ( me_o01_[ism-1] ) me_o01_[ism-1]->Reset();
00233     if ( me_o02_[ism-1] ) me_o02_[ism-1]->Reset();
00234 
00235     for (int ie = 1; ie <= 17; ie++) {
00236       for (int ip = 1; ip <= 4; ip++) {
00237 
00238         if ( o01_[ism-1] ) {
00239           // find the most frequent TP timing that matches the emulator
00240           float index=-1;
00241           double max=0;
00242           double total=0;
00243           for (int j=0; j<6; j++) {
00244             double sampleEntries = o01_[ism-1]->GetBinContent(ie, ip, j+1);
00245             if(sampleEntries > max) {
00246               index=j;
00247               max = sampleEntries;
00248             }
00249             total += sampleEntries;
00250           }
00251           if ( max > 0 ) {
00252             if ( index == 0 ) {
00253               me_o01_[ism-1]->setBinContent(ie, ip, -1);
00254             } else {
00255               me_o01_[ism-1]->setBinContent(ie, ip, index );
00256             }
00257           }
00258           double fraction = (total > 0) ? 1.0 - max/total : 0.;
00259           if ( me_o02_[ism-1] ) me_o02_[ism-1]->setBinContent(ie, ip, fraction);
00260         }
00261 
00262       }
00263     }
00264 
00265   }
00266 
00267 }
00268