CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/EcalEndcapMonitorTasks/src/EELedTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EELedTask.cc
00003  *
00004  * $Date: 2012/05/15 11:12:27 $
00005  * $Revision: 1.73 $
00006  * \author G. Della Ricca
00007  *
00008 */
00009 
00010 #include <iostream>
00011 #include <sstream>
00012 #include <vector>
00013 
00014 #include "FWCore/ServiceRegistry/interface/Service.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "DQMServices/Core/interface/MonitorElement.h"
00018 
00019 #include "DQMServices/Core/interface/DQMStore.h"
00020 
00021 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00022 
00023 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00024 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00025 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00026 #include "DataFormats/EcalDigi/interface/EEDataFrame.h"
00027 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00028 #include "DataFormats/EcalRecHit/interface/EcalUncalibratedRecHit.h"
00029 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00030 
00031 #include "DQM/EcalCommon/interface/Numbers.h"
00032 #include "DQM/EcalCommon/interface/NumbersPn.h"
00033 
00034 #include "DQM/EcalEndcapMonitorTasks/interface/EELedTask.h"
00035 
00036 EELedTask::EELedTask(const edm::ParameterSet& ps){
00037 
00038   init_ = false;
00039 
00040   dqmStore_ = edm::Service<DQMStore>().operator->();
00041 
00042   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00043 
00044   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00045 
00046   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00047 
00048   EcalRawDataCollection_ = ps.getParameter<edm::InputTag>("EcalRawDataCollection");
00049   EEDigiCollection_ = ps.getParameter<edm::InputTag>("EEDigiCollection");
00050   EcalPnDiodeDigiCollection_ = ps.getParameter<edm::InputTag>("EcalPnDiodeDigiCollection");
00051   EcalUncalibratedRecHitCollection_ = ps.getParameter<edm::InputTag>("EcalUncalibratedRecHitCollection");
00052 
00053   // vector of enabled wavelengths (Default to all 2)
00054   ledWavelengths_.reserve(2);
00055   for ( unsigned int i = 1; i <= 2; i++ ) ledWavelengths_.push_back(i);
00056   ledWavelengths_ = ps.getUntrackedParameter<std::vector<int> >("ledWavelengths", ledWavelengths_);
00057 
00058   for (int i = 0; i < 18; i++) {
00059     meShapeMapL1_[i] = 0;
00060     meAmplMapL1_[i] = 0;
00061     meTimeMapL1_[i] = 0;
00062     meAmplPNMapL1_[i] = 0;
00063     mePnAmplMapG01L1_[i] = 0;
00064     mePnPedMapG01L1_[i] = 0;
00065     mePnAmplMapG16L1_[i] = 0;
00066     mePnPedMapG16L1_[i] = 0;
00067 
00068     meShapeMapL2_[i] = 0;
00069     meAmplMapL2_[i] = 0;
00070     meTimeMapL2_[i] = 0;
00071     meAmplPNMapL2_[i] = 0;
00072     mePnAmplMapG01L2_[i] = 0;
00073     mePnPedMapG01L2_[i] = 0;
00074     mePnAmplMapG16L2_[i] = 0;
00075     mePnPedMapG16L2_[i] = 0;
00076   }
00077 
00078 }
00079 
00080 EELedTask::~EELedTask(){
00081 
00082 }
00083 
00084 void EELedTask::beginJob(void){
00085 
00086   ievt_ = 0;
00087 
00088   if ( dqmStore_ ) {
00089     dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask");
00090     dqmStore_->rmdir(prefixME_ + "/EELedTask");
00091   }
00092 
00093 }
00094 
00095 void EELedTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00096 
00097   Numbers::initGeometry(c, false);
00098 
00099   if ( ! mergeRuns_ ) this->reset();
00100 
00101 }
00102 
00103 void EELedTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00104 
00105   for (int i = 0; i < 18; i++) {
00106     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 1) != ledWavelengths_.end() ) {
00107       if ( meShapeMapL1_[i] )  meShapeMapL1_[i]->Reset();
00108       if ( meAmplMapL1_[i] ) meAmplMapL1_[i]->Reset();
00109       if ( meTimeMapL1_[i] ) meTimeMapL1_[i]->Reset();
00110       if ( meAmplPNMapL1_[i] ) meAmplPNMapL1_[i]->Reset();
00111     }
00112 
00113     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 2) != ledWavelengths_.end() ) {
00114       if ( meShapeMapL2_[i] )  meShapeMapL2_[i]->Reset();
00115       if ( meAmplMapL2_[i] ) meAmplMapL2_[i]->Reset();
00116       if ( meTimeMapL2_[i] ) meTimeMapL2_[i]->Reset();
00117       if ( meAmplPNMapL2_[i] ) meAmplPNMapL2_[i]->Reset();
00118     }
00119 
00120     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 1) != ledWavelengths_.end() ) {
00121       if ( mePnAmplMapG01L1_[i] ) mePnAmplMapG01L1_[i]->Reset();
00122       if ( mePnPedMapG01L1_[i] ) mePnPedMapG01L1_[i]->Reset();
00123 
00124       if ( mePnAmplMapG16L1_[i] ) mePnAmplMapG16L1_[i]->Reset();
00125       if ( mePnPedMapG16L1_[i] ) mePnPedMapG16L1_[i]->Reset();
00126     }
00127 
00128     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 2) != ledWavelengths_.end() ) {
00129       if ( mePnAmplMapG01L2_[i] ) mePnAmplMapG01L2_[i]->Reset();
00130       if ( mePnPedMapG01L2_[i] ) mePnPedMapG01L2_[i]->Reset();
00131 
00132       if ( mePnAmplMapG16L2_[i] ) mePnAmplMapG16L2_[i]->Reset();
00133       if ( mePnPedMapG16L2_[i] ) mePnPedMapG16L2_[i]->Reset();
00134     }
00135   }
00136 
00137 }
00138 
00139 void EELedTask::reset(void) {
00140 
00141 }
00142 
00143 void EELedTask::setup(void){
00144 
00145   init_ = true;
00146 
00147   std::string name;
00148   std::stringstream LedN, LN;
00149 
00150   if ( dqmStore_ ) {
00151     dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask");
00152 
00153     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 1) != ledWavelengths_.end() ) {
00154 
00155       LedN.str("");
00156       LedN << "Led" << 1;
00157       LN.str("");
00158       LN << "L" << 1;
00159 
00160       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str());
00161       for (int i = 0; i < 18; i++) {
00162         name = "EELDT shape " + Numbers::sEE(i+1) + " " + LN.str();
00163         meShapeMapL1_[i] = dqmStore_->bookProfile2D(name, name, 850, 0., 850., 10, 0., 10., 4096, 0., 4096., "s");
00164         meShapeMapL1_[i]->setAxisTitle("channel", 1);
00165         meShapeMapL1_[i]->setAxisTitle("sample", 2);
00166         meShapeMapL1_[i]->setAxisTitle("amplitude", 3);
00167         dqmStore_->tag(meShapeMapL1_[i], i+1);
00168 
00169         name = "EELDT amplitude " + Numbers::sEE(i+1) + " " + LN.str(); 
00170         meAmplMapL1_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 4096, 0., 4096.*12., "s");
00171         meAmplMapL1_[i]->setAxisTitle("ix", 1);
00172         if ( i+1 >= 1 && i+1 <= 9 ) meAmplMapL1_[i]->setAxisTitle("101-ix", 1);
00173         meAmplMapL1_[i]->setAxisTitle("iy", 2);
00174         dqmStore_->tag(meAmplMapL1_[i], i+1);
00175 
00176         name = "EELDT timing " + Numbers::sEE(i+1) + " " + LN.str(); 
00177         meTimeMapL1_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 250, 0., 10., "s");
00178         meTimeMapL1_[i]->setAxisTitle("ix", 1);
00179         if ( i+1 >= 1 && i+1 <= 9 ) meTimeMapL1_[i]->setAxisTitle("101-ix", 1);
00180         meTimeMapL1_[i]->setAxisTitle("iy", 2);
00181         dqmStore_->tag(meTimeMapL1_[i], i+1);
00182 
00183         name = "EELDT amplitude over PN " + Numbers::sEE(i+1) + " " + LN.str(); 
00184         meAmplPNMapL1_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 4096, 0., 4096.*12., "s");
00185         meAmplPNMapL1_[i]->setAxisTitle("ix", 1);
00186         if ( i+1 >= 1 && i+1 <= 9 ) meAmplPNMapL1_[i]->setAxisTitle("101-ix", 1);
00187         meAmplPNMapL1_[i]->setAxisTitle("iy", 2);
00188         dqmStore_->tag(meAmplPNMapL1_[i], i+1);
00189       }
00190 
00191       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str() + "/PN");
00192 
00193       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str() + "/PN/Gain01");
00194       for (int i = 0; i < 18; i++) {
00195         name = "EELDT PNs amplitude " + Numbers::sEE(i+1) + " G01 " + LN.str();
00196         mePnAmplMapG01L1_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00197         mePnAmplMapG01L1_[i]->setAxisTitle("channel", 1);
00198         mePnAmplMapG01L1_[i]->setAxisTitle("amplitude", 2);
00199         dqmStore_->tag(mePnAmplMapG01L1_[i], i+1);
00200 
00201         name = "EELDT PNs pedestal " + Numbers::sEE(i+1) + " G01 " + LN.str();
00202         mePnPedMapG01L1_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00203         mePnPedMapG01L1_[i]->setAxisTitle("channel", 1);
00204         mePnPedMapG01L1_[i]->setAxisTitle("pedestal", 2);
00205         dqmStore_->tag(mePnPedMapG01L1_[i], i+1);
00206       }
00207 
00208       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str() + "/PN/Gain16");
00209 
00210       for (int i = 0; i < 18; i++) {
00211         name = "EELDT PNs amplitude " + Numbers::sEE(i+1) + " G16 " + LN.str();
00212         mePnAmplMapG16L1_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00213         mePnAmplMapG16L1_[i]->setAxisTitle("channel", 1);
00214         mePnAmplMapG16L1_[i]->setAxisTitle("amplitude", 2);
00215         dqmStore_->tag(mePnAmplMapG16L1_[i], i+1);
00216 
00217         name = "EELDT PNs pedestal " + Numbers::sEE(i+1) + " G16 " + LN.str();
00218         mePnPedMapG16L1_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00219         mePnPedMapG16L1_[i]->setAxisTitle("channel", 1);
00220         mePnPedMapG16L1_[i]->setAxisTitle("pedestal", 2);
00221         dqmStore_->tag(mePnPedMapG16L1_[i], i+1);
00222       }
00223 
00224     }
00225 
00226     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 2) != ledWavelengths_.end() ) {
00227 
00228       LedN.str("");
00229       LedN << "Led" << 2;
00230       LN.str("");
00231       LN << "L" << 2;
00232 
00233       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str());
00234       for (int i = 0; i < 18; i++) {
00235         name = "EELDT shape " + Numbers::sEE(i+1) + " " + LN.str();
00236         meShapeMapL2_[i] = dqmStore_->bookProfile2D(name, name, 850, 0., 850., 10, 0., 10., 4096, 0., 4096., "s");
00237         meShapeMapL2_[i]->setAxisTitle("channel", 1);
00238         meShapeMapL2_[i]->setAxisTitle("sample", 2);
00239         meShapeMapL2_[i]->setAxisTitle("amplitude", 3);
00240         dqmStore_->tag(meShapeMapL2_[i], i+1);
00241 
00242         name = "EELDT amplitude " + Numbers::sEE(i+1) + " " + LN.str(); 
00243         meAmplMapL2_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 4096, 0., 4096.*12., "s");
00244         meAmplMapL2_[i]->setAxisTitle("ix", 1);
00245         if ( i+1 >= 1 && i+1 <= 9 ) meAmplMapL2_[i]->setAxisTitle("101-ix", 1);
00246         meAmplMapL2_[i]->setAxisTitle("iy", 2);
00247         dqmStore_->tag(meAmplMapL2_[i], i+1);
00248 
00249         name = "EELDT timing " + Numbers::sEE(i+1) + " " + LN.str(); 
00250         meTimeMapL2_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 250, 0., 10., "s");
00251         meTimeMapL2_[i]->setAxisTitle("ix", 1);
00252         if ( i+1 >= 1 && i+1 <= 9 ) meTimeMapL2_[i]->setAxisTitle("101-ix", 1);
00253         meTimeMapL2_[i]->setAxisTitle("iy", 2);
00254         dqmStore_->tag(meTimeMapL2_[i], i+1);
00255 
00256         name = "EELDT amplitude over PN " + Numbers::sEE(i+1) + " " + LN.str(); 
00257         meAmplPNMapL2_[i] = dqmStore_->bookProfile2D(name, name, 50, Numbers::ix0EE(i+1)+0., Numbers::ix0EE(i+1)+50., 50, Numbers::iy0EE(i+1)+0., Numbers::iy0EE(i+1)+50., 4096, 0., 4096.*12., "s");
00258         meAmplPNMapL2_[i]->setAxisTitle("ix", 1);
00259         if ( i+1 >= 1 && i+1 <= 9 ) meAmplPNMapL2_[i]->setAxisTitle("101-ix", 1);
00260         meAmplPNMapL2_[i]->setAxisTitle("iy", 2);
00261         dqmStore_->tag(meAmplPNMapL2_[i], i+1);
00262       }
00263 
00264       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str() + "/PN");
00265 
00266       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str() + "/PN/Gain01");
00267       for (int i = 0; i < 18; i++) {
00268         name = "EELDT PNs amplitude " + Numbers::sEE(i+1) + " G01 " + LN.str();
00269         mePnAmplMapG01L2_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00270         mePnAmplMapG01L2_[i]->setAxisTitle("channel", 1);
00271         mePnAmplMapG01L2_[i]->setAxisTitle("amplitude", 2);
00272         dqmStore_->tag(mePnAmplMapG01L2_[i], i+1);
00273 
00274         name = "EELDT PNs pedestal " + Numbers::sEE(i+1) + " G01 " + LN.str();
00275         mePnPedMapG01L2_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00276         mePnPedMapG01L2_[i]->setAxisTitle("channel", 1);
00277         mePnPedMapG01L2_[i]->setAxisTitle("pedestal", 2);
00278         dqmStore_->tag(mePnPedMapG01L2_[i], i+1);
00279       }
00280 
00281       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/" + LedN.str() + "/PN/Gain16");
00282 
00283       for (int i = 0; i < 18; i++) {
00284         name = "EELDT PNs amplitude " + Numbers::sEE(i+1) + " G16 " + LN.str();
00285         mePnAmplMapG16L2_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00286         mePnAmplMapG16L2_[i]->setAxisTitle("channel", 1);
00287         mePnAmplMapG16L2_[i]->setAxisTitle("amplitude", 2);
00288         dqmStore_->tag(mePnAmplMapG16L2_[i], i+1);
00289 
00290         name = "EELDT PNs pedestal " + Numbers::sEE(i+1) + " G16 " + LN.str();
00291         mePnPedMapG16L2_[i] = dqmStore_->bookProfile(name, name, 10, 0., 10., 4096, 0., 4096., "s");
00292         mePnPedMapG16L2_[i]->setAxisTitle("channel", 1);
00293         mePnPedMapG16L2_[i]->setAxisTitle("pedestal", 2);
00294         dqmStore_->tag(mePnPedMapG16L2_[i], i+1);
00295       }
00296 
00297     }
00298 
00299   }
00300 
00301 }
00302 
00303 void EELedTask::cleanup(void){
00304 
00305   if ( ! init_ ) return;
00306 
00307   if ( dqmStore_ ) {
00308     dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask");
00309 
00310     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 1) != ledWavelengths_.end() ) {
00311 
00312       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led1");
00313       for (int i = 0; i < 18; i++) {
00314         if ( meShapeMapL1_[i] )  dqmStore_->removeElement( meShapeMapL1_[i]->getName() );
00315         meShapeMapL1_[i] = 0;
00316         if ( meAmplMapL1_[i] ) dqmStore_->removeElement( meAmplMapL1_[i]->getName() );
00317         meAmplMapL1_[i] = 0;
00318         if ( meTimeMapL1_[i] ) dqmStore_->removeElement( meTimeMapL1_[i]->getName() );
00319         meTimeMapL1_[i] = 0;
00320         if ( meAmplPNMapL1_[i] ) dqmStore_->removeElement( meAmplPNMapL1_[i]->getName() );
00321         meAmplPNMapL1_[i] = 0;
00322       }
00323 
00324     }
00325 
00326     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 2) != ledWavelengths_.end() ) {
00327 
00328       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led2");
00329       for (int i = 0; i < 18; i++) {
00330         if ( meShapeMapL2_[i] )  dqmStore_->removeElement( meShapeMapL2_[i]->getName() );
00331         meShapeMapL2_[i] = 0;
00332         if ( meAmplMapL2_[i] ) dqmStore_->removeElement( meAmplMapL2_[i]->getName() );
00333         meAmplMapL2_[i] = 0;
00334         if ( meTimeMapL2_[i] ) dqmStore_->removeElement( meTimeMapL2_[i]->getName() );
00335         meTimeMapL2_[i] = 0;
00336         if ( meAmplPNMapL2_[i] ) dqmStore_->removeElement( meAmplPNMapL2_[i]->getName() );
00337         meAmplPNMapL2_[i] = 0;
00338       }
00339 
00340     }
00341 
00342     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 1) != ledWavelengths_.end() ) {
00343 
00344       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led1/PN");
00345 
00346       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led1/PN/Gain01");
00347       for (int i = 0; i < 18; i++) {
00348         if ( mePnAmplMapG01L1_[i] ) dqmStore_->removeElement( mePnAmplMapG01L1_[i]->getName() );
00349         mePnAmplMapG01L1_[i] = 0;
00350         if ( mePnPedMapG01L1_[i] ) dqmStore_->removeElement( mePnPedMapG01L1_[i]->getName() );
00351         mePnPedMapG01L1_[i] = 0;
00352       }
00353 
00354       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led1/PN/Gain16");
00355       for (int i = 0; i < 18; i++) {
00356         if ( mePnAmplMapG16L1_[i] ) dqmStore_->removeElement( mePnAmplMapG16L1_[i]->getName() );
00357         mePnAmplMapG16L1_[i] = 0;
00358         if ( mePnPedMapG16L1_[i] ) dqmStore_->removeElement( mePnPedMapG16L1_[i]->getName() );
00359         mePnPedMapG16L1_[i] = 0;
00360       }
00361 
00362     }
00363 
00364     if ( find(ledWavelengths_.begin(), ledWavelengths_.end(), 2) != ledWavelengths_.end() ) {
00365 
00366       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led2/PN");
00367 
00368       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led2/PN/Gain01");
00369       for (int i = 0; i < 18; i++) {
00370         if ( mePnAmplMapG01L2_[i] ) dqmStore_->removeElement( mePnAmplMapG01L2_[i]->getName() );
00371         mePnAmplMapG01L2_[i] = 0;
00372         if ( mePnPedMapG01L2_[i] ) dqmStore_->removeElement( mePnPedMapG01L2_[i]->getName() );
00373         mePnPedMapG01L2_[i] = 0;
00374       }
00375 
00376       dqmStore_->setCurrentFolder(prefixME_ + "/EELedTask/Led2/PN/Gain16");
00377       for (int i = 0; i < 18; i++) {
00378         if ( mePnAmplMapG16L2_[i] ) dqmStore_->removeElement( mePnAmplMapG16L2_[i]->getName() );
00379         mePnAmplMapG16L2_[i] = 0;
00380         if ( mePnPedMapG16L2_[i] ) dqmStore_->removeElement( mePnPedMapG16L2_[i]->getName() );
00381         mePnPedMapG16L2_[i] = 0;
00382       }
00383 
00384     }
00385 
00386   }
00387 
00388   init_ = false;
00389 
00390 }
00391 
00392 void EELedTask::endJob(void){
00393 
00394   edm::LogInfo("EELedTask") << "analyzed " << ievt_ << " events";
00395 
00396   if ( enableCleanup_ ) this->cleanup();
00397 
00398 }
00399 
00400 void EELedTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00401 
00402   bool enable = false;
00403   int runType[18];
00404   for (int i=0; i<18; i++) runType[i] = -1;
00405   unsigned rtHalf[18];
00406   for (int i=0; i<18; i++) rtHalf[i] = -1;
00407   int waveLength[18];
00408   for (int i=0; i<18; i++) waveLength[i] = -1;
00409 
00410   edm::Handle<EcalRawDataCollection> dcchs;
00411 
00412   if ( e.getByLabel(EcalRawDataCollection_, dcchs) ) {
00413 
00414     for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00415 
00416       if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
00417 
00418       int ism = Numbers::iSM( *dcchItr, EcalEndcap );
00419 
00420       runType[ism-1] = dcchItr->getRunType();
00421       rtHalf[ism-1] = dcchItr->getRtHalf();
00422       waveLength[ism-1] = dcchItr->getEventSettings().wavelength;
00423 
00424       if ( dcchItr->getRunType() == EcalDCCHeaderBlock::LED_STD ||
00425            dcchItr->getRunType() == EcalDCCHeaderBlock::LED_GAP ) enable = true;
00426 
00427     }
00428 
00429   } else {
00430 
00431     edm::LogWarning("EELedTask") << EcalRawDataCollection_ << " not available";
00432 
00433   }
00434 
00435   if ( ! enable ) return;
00436 
00437   if ( ! init_ ) this->setup();
00438 
00439   ievt_++;
00440 
00441   bool numPN[80];
00442   float adcPN[80];
00443   for ( int i = 0; i < 80; i++ ) {
00444     numPN[i] = false;
00445     adcPN[i] = 0.;
00446   }
00447 
00448   std::vector<int> PNs;
00449   PNs.reserve(12);
00450 
00451   edm::Handle<EEDigiCollection> digis;
00452 
00453   if ( e.getByLabel(EEDigiCollection_, digis) ) {
00454 
00455     int maxpos[10];
00456     for(int i(0); i < 10; i++)
00457       maxpos[i] = 0;
00458     int nReadouts(0);
00459 
00460     for ( EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
00461 
00462       EEDetId id = digiItr->id();
00463 
00464       int ism = Numbers::iSM( id );
00465 
00466       if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::LED_STD ||
00467                runType[ism-1] == EcalDCCHeaderBlock::LED_GAP ) ) continue;
00468 
00469       if ( rtHalf[ism-1] != Numbers::RtHalf(id) ) continue;
00470 
00471       nReadouts++;
00472 
00473       EEDataFrame dataframe = (*digiItr);
00474 
00475       int iMax(-1);
00476       float max(0.);
00477       float min(4096.);
00478       for (int i = 0; i < 10; i++) {
00479         int adc = dataframe.sample(i).adc();
00480         if(adc > max){
00481           max = adc;
00482           iMax = i;
00483         }
00484         if(adc < min)
00485           min = adc;
00486       }
00487       if(iMax >= 0 && max - min > 20.)
00488         maxpos[iMax] += 1;
00489 
00490     }
00491 
00492     int threshold(nReadouts / 2);
00493     enable = false;
00494     for(int i(0); i < 10; i++){
00495       if(maxpos[i] > threshold){
00496         enable = true;
00497         break;
00498       }
00499     }
00500 
00501     if(!enable) return;
00502 
00503     int need = digis->size();
00504     LogDebug("EELedTask") << "event " << ievt_ << " digi collection size " << need;
00505 
00506     for ( EEDigiCollection::const_iterator digiItr = digis->begin(); digiItr != digis->end(); ++digiItr ) {
00507 
00508       EEDetId id = digiItr->id();
00509 
00510       int ix = id.ix();
00511       int iy = id.iy();
00512 
00513       int ism = Numbers::iSM( id );
00514 
00515       if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::LED_STD ||
00516                runType[ism-1] == EcalDCCHeaderBlock::LED_GAP ) ) continue;
00517 
00518       if ( runType[ism-1] == EcalDCCHeaderBlock::LED_GAP &&
00519            rtHalf[ism-1] != Numbers::RtHalf(id) ) continue;
00520 
00521       int ic = Numbers::icEE(ism, ix, iy);
00522 
00523       EEDataFrame dataframe = (*digiItr);
00524 
00525       for (int i = 0; i < 10; i++) {
00526 
00527         int adc = dataframe.sample(i).adc();
00528 
00529         MonitorElement* meShapeMap = 0;
00530 
00531         if ( Numbers::RtHalf(id) == 0 || Numbers::RtHalf(id) == 1 ) {
00532 
00533           if ( waveLength[ism-1] == 0 ) meShapeMap = meShapeMapL1_[ism-1];
00534           if ( waveLength[ism-1] == 2 ) meShapeMap = meShapeMapL2_[ism-1];
00535 
00536         } else {
00537 
00538           edm::LogWarning("EELedTask") << " RtHalf = " << Numbers::RtHalf(id);
00539 
00540         }
00541 
00542         float xval = float(adc);
00543 
00544         if ( meShapeMap ) meShapeMap->Fill(ic - 0.5, i + 0.5, xval);
00545 
00546       }
00547 
00548       NumbersPn::getPNs( ism, ix, iy, PNs );
00549 
00550       for (unsigned int i=0; i<PNs.size(); i++) {
00551         int ipn = PNs[i];
00552         if ( ipn >= 0 && ipn < 80 ) numPN[ipn] = true;
00553       }
00554 
00555     }
00556 
00557   } else {
00558 
00559     edm::LogWarning("EELedTask") << EEDigiCollection_ << " not available";
00560 
00561   }
00562 
00563   edm::Handle<EcalPnDiodeDigiCollection> pns;
00564 
00565   if ( e.getByLabel(EcalPnDiodeDigiCollection_, pns) ) {
00566 
00567     int nep = pns->size();
00568     LogDebug("EELedTask") << "event " << ievt_ << " pns collection size " << nep;
00569 
00570     for ( EcalPnDiodeDigiCollection::const_iterator pnItr = pns->begin(); pnItr != pns->end(); ++pnItr ) {
00571 
00572       if ( Numbers::subDet( pnItr->id() ) != EcalEndcap ) continue;
00573 
00574       int ism = Numbers::iSM( pnItr->id() );
00575 
00576       int num = pnItr->id().iPnId();
00577 
00578       if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::LED_STD ||
00579                runType[ism-1] == EcalDCCHeaderBlock::LED_GAP ) ) continue;
00580 
00581       int ipn = NumbersPn::ipnEE( ism, num );
00582 
00583       if ( ipn >= 0 && ipn < 80 && numPN[ipn] == false ) continue;
00584 
00585       float xvalped = 0.;
00586 
00587       for (int i = 0; i < 4; i++) {
00588 
00589         int adc = pnItr->sample(i).adc();
00590 
00591         MonitorElement* mePNPed = 0;
00592 
00593         if ( pnItr->sample(i).gainId() == 0 ) {
00594           if ( waveLength[ism-1] == 0 ) mePNPed = mePnPedMapG01L1_[ism-1];
00595           if ( waveLength[ism-1] == 2 ) mePNPed = mePnPedMapG01L2_[ism-1];
00596         }
00597         if ( pnItr->sample(i).gainId() == 1 ) {
00598           if ( waveLength[ism-1] == 0 ) mePNPed = mePnPedMapG16L1_[ism-1];
00599           if ( waveLength[ism-1] == 2 ) mePNPed = mePnPedMapG16L2_[ism-1];
00600         }
00601 
00602         float xval = float(adc);
00603 
00604         if ( mePNPed ) mePNPed->Fill(num - 0.5, xval);
00605 
00606         xvalped = xvalped + xval;
00607 
00608       }
00609 
00610       xvalped = xvalped / 4;
00611 
00612       float xvalmax = 0.;
00613 
00614       MonitorElement* mePN = 0;
00615 
00616       for (int i = 0; i < 50; i++) {
00617 
00618         int adc = pnItr->sample(i).adc();
00619 
00620         float xval = float(adc);
00621 
00622         if ( xval >= xvalmax ) xvalmax = xval;
00623 
00624       }
00625 
00626       xvalmax = xvalmax - xvalped;
00627 
00628       if ( pnItr->sample(0).gainId() == 0 ) {
00629         if ( waveLength[ism-1] == 0 ) mePN = mePnAmplMapG01L1_[ism-1];
00630         if ( waveLength[ism-1] == 2 ) mePN = mePnAmplMapG01L2_[ism-1];
00631       }
00632       if ( pnItr->sample(0).gainId() == 1 ) {
00633         if ( waveLength[ism-1] == 0 ) mePN = mePnAmplMapG16L1_[ism-1];
00634         if ( waveLength[ism-1] == 2 ) mePN = mePnAmplMapG16L2_[ism-1];
00635       }
00636 
00637       if ( mePN ) mePN->Fill(num - 0.5, xvalmax);
00638 
00639       if ( ipn >= 0 && ipn < 80 ) adcPN[ipn] = xvalmax;
00640 
00641     }
00642 
00643   } else {
00644 
00645     edm::LogWarning("EELedTask") << EcalPnDiodeDigiCollection_ << " not available";
00646 
00647   }
00648 
00649   edm::Handle<EcalUncalibratedRecHitCollection> hits;
00650 
00651   if ( e.getByLabel(EcalUncalibratedRecHitCollection_, hits) ) {
00652 
00653     int neh = hits->size();
00654     LogDebug("EELedTask") << "event " << ievt_ << " hits collection size " << neh;
00655 
00656     for ( EcalUncalibratedRecHitCollection::const_iterator hitItr = hits->begin(); hitItr != hits->end(); ++hitItr ) {
00657 
00658       EEDetId id = hitItr->id();
00659 
00660       int ix = id.ix();
00661       int iy = id.iy();
00662 
00663       int ism = Numbers::iSM( id );
00664 
00665       if ( ism >= 1 && ism <= 9 ) ix = 101 - ix;
00666 
00667       float xix = ix - 0.5;
00668       float xiy = iy - 0.5;
00669 
00670       if ( ! ( runType[ism-1] == EcalDCCHeaderBlock::LED_STD ||
00671                runType[ism-1] == EcalDCCHeaderBlock::LED_GAP ) ) continue;
00672 
00673       if ( runType[ism-1] == EcalDCCHeaderBlock::LED_GAP &&
00674            rtHalf[ism-1] != Numbers::RtHalf(id) ) continue;
00675 
00676       MonitorElement* meAmplMap = 0;
00677       MonitorElement* meTimeMap = 0;
00678       MonitorElement* meAmplPNMap = 0;
00679 
00680       // Temporary measure to remove broken LED boxes for L1
00681       if(waveLength[ism - 1] == 0){
00682         if(ism == 14){
00683           EcalElectronicsId eid(Numbers::getElectronicsMapping()->getElectronicsId(id));
00684           int tower(eid.towerId());
00685           if(tower == 1 || tower == 2 || tower == 3 || tower == 4 || tower == 5 || tower == 6 || tower == 9 || tower == 15) continue;
00686         }
00687         else if(ism == 15){
00688           EcalElectronicsId eid(Numbers::getElectronicsMapping()->getElectronicsId(id));
00689           int tower(eid.towerId());
00690           if(tower == 3 || tower == 4 || tower == 10 || tower == 11 || tower == 12 || tower == 18 || tower == 19 || tower == 25) continue;
00691         }
00692       }
00693 
00694       if ( Numbers::RtHalf(id) == 0 || Numbers::RtHalf(id) == 1 ) {
00695 
00696         if ( waveLength[ism-1] == 0 ) {
00697           meAmplMap = meAmplMapL1_[ism-1];
00698           meTimeMap = meTimeMapL1_[ism-1];
00699           meAmplPNMap = meAmplPNMapL1_[ism-1];
00700         }
00701         if ( waveLength[ism-1] == 2 ) {
00702           meAmplMap = meAmplMapL2_[ism-1];
00703           meTimeMap = meTimeMapL2_[ism-1];
00704           meAmplPNMap = meAmplPNMapL2_[ism-1];
00705         }
00706 
00707       } else {
00708 
00709         edm::LogWarning("EELedTask") << " RtHalf = " << Numbers::RtHalf(id);
00710 
00711       }
00712 
00713       float xval = hitItr->amplitude();
00714       if ( xval <= 0. ) xval = 0.0;
00715       float yval = hitItr->jitter() + 6.0;
00716       if ( yval <= 0. ) yval = 0.0;
00717       float zval = hitItr->pedestal();
00718       if ( zval <= 0. ) zval = 0.0;
00719 
00720       if ( meAmplMap ) meAmplMap->Fill(xix, xiy, xval);
00721 
00722       if ( xval > 16. ) {
00723         if ( meTimeMap ) meTimeMap->Fill(xix, xiy, yval);
00724       }
00725 
00726       float wval = 0.;
00727 
00728       NumbersPn::getPNs( ism, ix, iy, PNs );
00729 
00730       if ( PNs.size() > 0 ) {
00731         int ipn = PNs[0];
00732         if ( ipn >= 0 && ipn < 80 ) {
00733           if ( adcPN[ipn] != 0. ) wval = xval / adcPN[ipn];
00734         }
00735       }
00736 
00737       if ( meAmplPNMap ) meAmplPNMap->Fill(xix, xiy, wval);
00738 
00739     }
00740 
00741   } else {
00742 
00743     edm::LogWarning("EELedTask") << EcalUncalibratedRecHitCollection_ << " not available";
00744 
00745   }
00746 
00747 }
00748