CMS 3D CMS Logo

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

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