CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/EcalEndcapMonitorTasks/src/EESelectiveReadoutTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file EESelectiveReadoutTask.cc
00003  *
00004  * $Date: 2011/03/03 22:12:47 $
00005  * $Revision: 1.60 $
00006  * \author P. Gras
00007  * \author E. Di Marco
00008  *
00009 */
00010 
00011 #include <iostream>
00012 #include <fstream>
00013 #include <vector>
00014 #include <math.h>
00015 #include <cassert>
00016 
00017 #include "FWCore/ServiceRegistry/interface/Service.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019 #include "FWCore/Framework/interface/ESHandle.h"
00020 
00021 #include "DQMServices/Core/interface/MonitorElement.h"
00022 
00023 #include "DQMServices/Core/interface/DQMStore.h"
00024 
00025 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00026 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00027 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00028 
00029 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00030 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00031 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00032 
00033 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00034 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00035 
00036 #include "DQM/EcalCommon/interface/Numbers.h"
00037 
00038 #include "DQM/EcalEndcapMonitorTasks/interface/EESelectiveReadoutTask.h"
00039 
00040 #include "CondFormats/EcalObjects/interface/EcalSRSettings.h"
00041 #include "CondFormats/DataRecord/interface/EcalSRSettingsRcd.h"
00042 
00043 
00044 EESelectiveReadoutTask::EESelectiveReadoutTask(const edm::ParameterSet& ps){
00045 
00046   init_ = false;
00047 
00048   dqmStore_ = edm::Service<DQMStore>().operator->();
00049 
00050   prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00051 
00052   enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00053 
00054   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00055 
00056   // parameters...
00057   EEDigiCollection_ = ps.getParameter<edm::InputTag>("EEDigiCollection");
00058   EEUnsuppressedDigiCollection_ = ps.getParameter<edm::InputTag>("EEUsuppressedDigiCollection");
00059   EESRFlagCollection_ = ps.getParameter<edm::InputTag>("EESRFlagCollection");
00060   EcalTrigPrimDigiCollection_ = ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollection");
00061   FEDRawDataCollection_ = ps.getParameter<edm::InputTag>("FEDRawDataCollection");
00062   firstFIRSample_ = ps.getParameter<int>("ecalDccZs1stSample");
00063 
00064   useCondDb_ = ps.getParameter<bool>("configFromCondDB");
00065   if(!useCondDb_) configFirWeights(ps.getParameter<std::vector<double> >("dccWeights"));
00066 
00067   // histograms...
00068   EEDccEventSize_ = 0;
00069   EEDccEventSizeMap_ = 0;
00070 
00071   for(int i=0; i<2; i++) {
00072     EETowerSize_[i] = 0;
00073     EETTFMismatch_[i] = 0;
00074     EEReadoutUnitForcedBitMap_[i] = 0;
00075     EEFullReadoutSRFlagMap_[i] = 0;
00076     EEFullReadoutSRFlagCount_[i] = 0;
00077     EEZeroSuppression1SRFlagMap_[i] = 0;  
00078     EEHighInterestTriggerTowerFlagMap_[i] = 0;
00079     EEMediumInterestTriggerTowerFlagMap_[i] = 0;
00080     EELowInterestTriggerTowerFlagMap_[i] = 0;
00081     EETTFlags_[i] = 0;
00082     EECompleteZSMap_[i] = 0;
00083     EECompleteZSCount_[i] = 0;
00084     EEDroppedFRMap_[i] = 0;
00085     EEDroppedFRCount_[i] = 0;
00086     EEEventSize_[i] = 0;
00087     EEHighInterestPayload_[i] = 0;
00088     EELowInterestPayload_[i] = 0;
00089     EEHighInterestZsFIR_[i] = 0;
00090     EELowInterestZsFIR_[i] = 0;
00091   }
00092 
00093   // initialize variable binning for DCC size...
00094   float ZSthreshold = 0.608; // kBytes of 1 TT fully readout
00095   float zeroBinSize = ZSthreshold / 20.;
00096   for(int i=0; i<20; i++) ybins[i] = i*zeroBinSize;
00097   for(int i=20; i<133; i++) ybins[i] = ZSthreshold * (i-19);
00098   for(int i=0; i<=18; i++) xbins[i] = i+1;
00099 
00100 }
00101 
00102 EESelectiveReadoutTask::~EESelectiveReadoutTask() {
00103 
00104 }
00105 
00106 void EESelectiveReadoutTask::beginJob(void) {
00107 
00108   ievt_ = 0;
00109 
00110   if ( dqmStore_ ) {
00111     dqmStore_->setCurrentFolder(prefixME_ + "/EESelectiveReadoutTask");
00112     dqmStore_->rmdir(prefixME_ + "/EESelectiveReadoutTask");
00113   }
00114 
00115 }
00116 
00117 void EESelectiveReadoutTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00118 
00119   Numbers::initGeometry(c, false);
00120 
00121   if ( ! mergeRuns_ ) this->reset();
00122 
00123   for(int ix = 0; ix < 20; ix++ ) {
00124     for(int iy = 0; iy < 20; iy++ ) {
00125       for(int iz = 0; iz < 2; iz++) {
00126         nEvtFullReadout[ix][iy][iz] = 0;
00127         nEvtZS1Readout[ix][iy][iz] = 0;
00128         nEvtZSReadout[ix][iy][iz] = 0;
00129         nEvtCompleteReadoutIfZS[ix][iy][iz] = 0;
00130         nEvtDroppedReadoutIfFR[ix][iy][iz] = 0;
00131         nEvtRUForced[ix][iy][iz] = 0;
00132         nEvtAnyReadout[ix][iy][iz] = 0;
00133       }
00134     }
00135   }
00136   for(int ix = 0; ix < 100; ix++ ) {
00137     for(int iy = 0; iy < 100; iy++ ) {
00138       for(int iz = 0; iz < 2; iz++) {
00139         nEvtHighInterest[ix][iy][iz] = 0;
00140         nEvtMediumInterest[ix][iy][iz] = 0;
00141         nEvtLowInterest[ix][iy][iz] = 0;
00142         nEvtAnyInterest[ix][iy][iz] = 0;
00143       }
00144     }
00145   }
00146 
00147   //getting selective readout configuration
00148   if(useCondDb_) {
00149     edm::ESHandle<EcalSRSettings> hSr;
00150     c.get<EcalSRSettingsRcd>().get(hSr);
00151     settings_ = hSr.product();
00152     std::vector<double> wsFromDB;
00153     
00154     std::vector<std::vector<float> > dccs = settings_->dccNormalizedWeights_;
00155     int nws = dccs.size();
00156     if(nws == 1) {
00157       for(std::vector<float>::const_iterator it = dccs[0].begin(); it != dccs[0].end(); it++) {
00158         wsFromDB.push_back(*it);
00159       }
00160     }
00161     else edm::LogWarning("EESelectiveReadoutTask") << "DCC weight set is not exactly 1.";
00162 
00163     configFirWeights(wsFromDB);
00164   }
00165 
00166 }
00167 
00168 void EESelectiveReadoutTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00169 
00170 }
00171 
00172 void EESelectiveReadoutTask::reset(void) {
00173 
00174   if ( EETowerSize_[0] ) EETowerSize_[0]->Reset();
00175   if ( EETowerSize_[1] ) EETowerSize_[1]->Reset();
00176 
00177   if ( EETTFMismatch_[0] ) EETTFMismatch_[0]->Reset();
00178   if ( EETTFMismatch_[1] ) EETTFMismatch_[1]->Reset();
00179 
00180   if ( EEDccEventSize_ ) EEDccEventSize_->Reset();
00181 
00182   if ( EEDccEventSizeMap_ ) EEDccEventSizeMap_->Reset();
00183 
00184   if ( EEReadoutUnitForcedBitMap_[0] ) EEReadoutUnitForcedBitMap_[0]->Reset();
00185   if ( EEReadoutUnitForcedBitMap_[1] ) EEReadoutUnitForcedBitMap_[1]->Reset();
00186 
00187   if ( EEFullReadoutSRFlagMap_[0] ) EEFullReadoutSRFlagMap_[0]->Reset();
00188   if ( EEFullReadoutSRFlagMap_[1] ) EEFullReadoutSRFlagMap_[1]->Reset();
00189 
00190   if ( EEFullReadoutSRFlagCount_[0] ) EEFullReadoutSRFlagCount_[0]->Reset();
00191   if ( EEFullReadoutSRFlagCount_[1] ) EEFullReadoutSRFlagCount_[1]->Reset();
00192   
00193   if ( EEZeroSuppression1SRFlagMap_[0] ) EEZeroSuppression1SRFlagMap_[0]->Reset();
00194   if ( EEZeroSuppression1SRFlagMap_[1] ) EEZeroSuppression1SRFlagMap_[1]->Reset();
00195 
00196   if ( EEHighInterestTriggerTowerFlagMap_[0] ) EEHighInterestTriggerTowerFlagMap_[0]->Reset();
00197   if ( EEHighInterestTriggerTowerFlagMap_[1] ) EEHighInterestTriggerTowerFlagMap_[1]->Reset();
00198 
00199   if ( EEMediumInterestTriggerTowerFlagMap_[0] ) EEMediumInterestTriggerTowerFlagMap_[0]->Reset();
00200   if ( EEMediumInterestTriggerTowerFlagMap_[1] ) EEMediumInterestTriggerTowerFlagMap_[1]->Reset();
00201 
00202   if ( EELowInterestTriggerTowerFlagMap_[0] ) EELowInterestTriggerTowerFlagMap_[0]->Reset();
00203   if ( EELowInterestTriggerTowerFlagMap_[1] ) EELowInterestTriggerTowerFlagMap_[1]->Reset();
00204 
00205   if ( EETTFlags_[0] ) EETTFlags_[0]->Reset();
00206   if ( EETTFlags_[1] ) EETTFlags_[1]->Reset();
00207 
00208   if ( EECompleteZSMap_[0] ) EECompleteZSMap_[0]->Reset();
00209   if ( EECompleteZSMap_[1] ) EECompleteZSMap_[1]->Reset();
00210   
00211   if ( EECompleteZSCount_[0] ) EECompleteZSCount_[0]->Reset();
00212   if ( EECompleteZSCount_[1] ) EECompleteZSCount_[1]->Reset();
00213 
00214   if ( EEDroppedFRMap_[0] ) EEDroppedFRMap_[0]->Reset();
00215   if ( EEDroppedFRMap_[1] ) EEDroppedFRMap_[1]->Reset();
00216 
00217   if ( EEDroppedFRCount_[0] ) EEDroppedFRCount_[0]->Reset();
00218   if ( EEDroppedFRCount_[1] ) EEDroppedFRCount_[1]->Reset();
00219 
00220   if ( EEEventSize_[0] ) EEEventSize_[0]->Reset();
00221   if ( EEEventSize_[1] ) EEEventSize_[1]->Reset();
00222 
00223   if ( EEHighInterestPayload_[0] ) EEHighInterestPayload_[0]->Reset();
00224   if ( EEHighInterestPayload_[1] ) EEHighInterestPayload_[1]->Reset();
00225 
00226   if ( EELowInterestPayload_[0] ) EELowInterestPayload_[0]->Reset();
00227   if ( EELowInterestPayload_[1] ) EELowInterestPayload_[1]->Reset();
00228 
00229   if ( EEHighInterestZsFIR_[0] ) EEHighInterestZsFIR_[0]->Reset();
00230   if ( EEHighInterestZsFIR_[1] ) EEHighInterestZsFIR_[1]->Reset();
00231 
00232   if ( EELowInterestZsFIR_[0] ) EELowInterestZsFIR_[0]->Reset();
00233   if ( EELowInterestZsFIR_[1] ) EELowInterestZsFIR_[1]->Reset();
00234 
00235 }
00236 
00237 void EESelectiveReadoutTask::setup(void) {
00238 
00239   init_ = true;
00240 
00241   char histo[200];
00242 
00243   if ( dqmStore_ ) {
00244     dqmStore_->setCurrentFolder(prefixME_ + "/EESelectiveReadoutTask");
00245 
00246 
00247     sprintf(histo, "EESRT tower event size EE -");
00248     EETowerSize_[0] = dqmStore_->bookProfile2D(histo, histo, 20, 0., 20., 20, 0., 20., 100, 0., 200., "s");
00249     EETowerSize_[0]->setAxisTitle("jx", 1);
00250     EETowerSize_[0]->setAxisTitle("jy", 2);
00251 
00252     sprintf(histo, "EESRT tower event size EE +");
00253     EETowerSize_[1] = dqmStore_->bookProfile2D(histo, histo, 20, 0., 20., 20, 0., 20., 100, 0., 200., "s");
00254     EETowerSize_[1]->setAxisTitle("jx", 1);
00255     EETowerSize_[1]->setAxisTitle("jy", 2);
00256 
00257     sprintf(histo, "EESRT TT flag mismatch EE -");
00258     EETTFMismatch_[0] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00259     EETTFMismatch_[0]->setAxisTitle("jx", 1);
00260     EETTFMismatch_[0]->setAxisTitle("jy", 2);
00261 
00262     sprintf(histo, "EESRT TT flag mismatch EE +");
00263     EETTFMismatch_[1] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00264     EETTFMismatch_[1]->setAxisTitle("jx", 1);
00265     EETTFMismatch_[1]->setAxisTitle("jy", 2);
00266 
00267     sprintf(histo, "EESRT DCC event size");
00268     EEDccEventSize_ = dqmStore_->bookProfile(histo, histo, 18, 1, 19, 100, 0., 200., "s");
00269     EEDccEventSize_->setAxisTitle("event size (kB)", 2);
00270     for (int i = 0; i < 18; i++) {
00271       EEDccEventSize_->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
00272     }
00273 
00274     sprintf(histo, "EESRT event size vs DCC");
00275     EEDccEventSizeMap_ = dqmStore_->book2D(histo, histo, 18, xbins, 132, ybins);
00276     EEDccEventSizeMap_->setAxisTitle("event size (kB)", 2);
00277     for (int i = 0; i < 18; i++) {
00278       EEDccEventSizeMap_->setBinLabel(i+1, Numbers::sEE(i+1).c_str(), 1);
00279     }
00280 
00281     sprintf(histo, "EESRT readout unit with SR forced EE -");
00282     EEReadoutUnitForcedBitMap_[0] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00283     EEReadoutUnitForcedBitMap_[0]->setAxisTitle("jx", 1);
00284     EEReadoutUnitForcedBitMap_[0]->setAxisTitle("jy", 2);
00285     EEReadoutUnitForcedBitMap_[0]->setAxisTitle("rate", 3);
00286 
00287     sprintf(histo, "EESRT readout unit with SR forced EE +");
00288     EEReadoutUnitForcedBitMap_[1] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00289     EEReadoutUnitForcedBitMap_[1]->setAxisTitle("jx", 1);
00290     EEReadoutUnitForcedBitMap_[1]->setAxisTitle("jy", 2);
00291     EEReadoutUnitForcedBitMap_[1]->setAxisTitle("rate", 3);
00292 
00293     sprintf(histo, "EESRT full readout SR Flags EE -");
00294     EEFullReadoutSRFlagMap_[0] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00295     EEFullReadoutSRFlagMap_[0]->setAxisTitle("jx", 1);
00296     EEFullReadoutSRFlagMap_[0]->setAxisTitle("jy", 2);
00297     EEFullReadoutSRFlagMap_[0]->setAxisTitle("rate", 3);
00298 
00299     sprintf(histo, "EESRT full readout SR Flags EE +");
00300     EEFullReadoutSRFlagMap_[1] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00301     EEFullReadoutSRFlagMap_[1]->setAxisTitle("jx", 1);
00302     EEFullReadoutSRFlagMap_[1]->setAxisTitle("jy", 2);
00303     EEFullReadoutSRFlagMap_[1]->setAxisTitle("rate", 3);
00304 
00305     sprintf(histo, "EESRT full readout SR Flags Number EE -");
00306     EEFullReadoutSRFlagCount_[0] = dqmStore_->book1D(histo, histo, 200, 0., 200.);
00307     EEFullReadoutSRFlagCount_[0]->setAxisTitle("Readout Units number", 1);
00308 
00309     sprintf(histo, "EESRT full readout SR Flags Number EE +");
00310     EEFullReadoutSRFlagCount_[1] = dqmStore_->book1D(histo, histo, 200, 0., 200.);
00311     EEFullReadoutSRFlagCount_[1]->setAxisTitle("Fully readout RU number", 1);
00312 
00313     sprintf(histo, "EESRT zero suppression 1 SR Flags EE -");
00314     EEZeroSuppression1SRFlagMap_[0] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00315     EEZeroSuppression1SRFlagMap_[0]->setAxisTitle("jx", 1);
00316     EEZeroSuppression1SRFlagMap_[0]->setAxisTitle("jy", 2);
00317     EEZeroSuppression1SRFlagMap_[0]->setAxisTitle("rate", 3);
00318 
00319     sprintf(histo, "EESRT zero suppression 1 SR Flags EE +");
00320     EEZeroSuppression1SRFlagMap_[1] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00321     EEZeroSuppression1SRFlagMap_[1]->setAxisTitle("jx", 1);
00322     EEZeroSuppression1SRFlagMap_[1]->setAxisTitle("jy", 2);
00323     EEZeroSuppression1SRFlagMap_[1]->setAxisTitle("rate", 3);
00324 
00325     sprintf(histo, "EESRT high interest TT Flags EE -");
00326     EEHighInterestTriggerTowerFlagMap_[0] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00327     EEHighInterestTriggerTowerFlagMap_[0]->setAxisTitle("jx", 1);
00328     EEHighInterestTriggerTowerFlagMap_[0]->setAxisTitle("jy", 2);
00329     EEHighInterestTriggerTowerFlagMap_[0]->setAxisTitle("rate", 3);
00330 
00331     sprintf(histo, "EESRT high interest TT Flags EE +");
00332     EEHighInterestTriggerTowerFlagMap_[1] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00333     EEHighInterestTriggerTowerFlagMap_[1]->setAxisTitle("jx", 1);
00334     EEHighInterestTriggerTowerFlagMap_[1]->setAxisTitle("jy", 2);
00335     EEHighInterestTriggerTowerFlagMap_[1]->setAxisTitle("rate", 3);
00336 
00337     sprintf(histo, "EESRT medium interest TT Flags EE -");
00338     EEMediumInterestTriggerTowerFlagMap_[0] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00339     EEMediumInterestTriggerTowerFlagMap_[0]->setAxisTitle("jx", 1);
00340     EEMediumInterestTriggerTowerFlagMap_[0]->setAxisTitle("jy", 2);
00341     EEMediumInterestTriggerTowerFlagMap_[0]->setAxisTitle("rate", 3);
00342 
00343     sprintf(histo, "EESRT medium interest TT Flags EE +");
00344     EEMediumInterestTriggerTowerFlagMap_[1] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00345     EEMediumInterestTriggerTowerFlagMap_[1]->setAxisTitle("jx", 1);
00346     EEMediumInterestTriggerTowerFlagMap_[1]->setAxisTitle("jy", 2);
00347     EEMediumInterestTriggerTowerFlagMap_[1]->setAxisTitle("rate", 3);
00348 
00349     sprintf(histo, "EESRT low interest TT Flags EE -");
00350     EELowInterestTriggerTowerFlagMap_[0] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00351     EELowInterestTriggerTowerFlagMap_[0]->setAxisTitle("jx", 1);
00352     EELowInterestTriggerTowerFlagMap_[0]->setAxisTitle("jy", 2);
00353     EELowInterestTriggerTowerFlagMap_[0]->setAxisTitle("rate", 3);
00354 
00355     sprintf(histo, "EESRT low interest TT Flags EE +");
00356     EELowInterestTriggerTowerFlagMap_[1] = dqmStore_->book2D(histo, histo, 100, 0., 100., 100, 0., 100.);
00357     EELowInterestTriggerTowerFlagMap_[1]->setAxisTitle("jx", 1);
00358     EELowInterestTriggerTowerFlagMap_[1]->setAxisTitle("jy", 2);
00359     EELowInterestTriggerTowerFlagMap_[1]->setAxisTitle("rate", 3);
00360 
00361     sprintf(histo, "EESRT TT Flags EE -");
00362     EETTFlags_[0] = dqmStore_->book1D(histo, histo, 8, 0., 8.);
00363     EETTFlags_[0]->setAxisTitle("TT Flag value", 1);
00364 
00365     sprintf(histo, "EESRT TT Flags EE +");
00366     EETTFlags_[1] = dqmStore_->book1D(histo, histo, 8, 0., 8.);
00367     EETTFlags_[1]->setAxisTitle("TT Flag value", 1);
00368 
00369     sprintf(histo, "EESRT ZS Flagged Fully Readout EE -");
00370     EECompleteZSMap_[0] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00371     EECompleteZSMap_[0]->setAxisTitle("jphi", 1);
00372     EECompleteZSMap_[0]->setAxisTitle("jeta", 2);
00373     EECompleteZSMap_[0]->setAxisTitle("rate", 3);
00374 
00375     sprintf(histo, "EESRT ZS Flagged Fully Readout EE +");
00376     EECompleteZSMap_[1] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00377     EECompleteZSMap_[1]->setAxisTitle("jphi", 1);
00378     EECompleteZSMap_[1]->setAxisTitle("jeta", 2);
00379     EECompleteZSMap_[1]->setAxisTitle("rate", 3);
00380 
00381     sprintf(histo, "EESRT ZS Flagged Fully Readout Number EE -");
00382     EECompleteZSCount_[0] = dqmStore_->book1D(histo, histo, 20, 0., 20.);
00383     EECompleteZSCount_[0]->setAxisTitle("Readout Units number", 1);
00384 
00385     sprintf(histo, "EESRT ZS Flagged Fully Readout Number EE +");
00386     EECompleteZSCount_[1] = dqmStore_->book1D(histo, histo, 20, 0., 20.);
00387     EECompleteZSCount_[1]->setAxisTitle("Readout Units number", 1);
00388 
00389     sprintf(histo, "EESRT FR Flagged Dropped Readout EE -");
00390     EEDroppedFRMap_[0] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00391     EEDroppedFRMap_[0]->setAxisTitle("jphi", 1);
00392     EEDroppedFRMap_[0]->setAxisTitle("jeta", 2);
00393     EEDroppedFRMap_[0]->setAxisTitle("rate", 3);
00394 
00395     sprintf(histo, "EESRT FR Flagged Dropped Readout EE +");
00396     EEDroppedFRMap_[1] = dqmStore_->book2D(histo, histo, 20, 0., 20., 20, 0., 20.);
00397     EEDroppedFRMap_[1]->setAxisTitle("jphi", 1);
00398     EEDroppedFRMap_[1]->setAxisTitle("jeta", 2);
00399     EEDroppedFRMap_[1]->setAxisTitle("rate", 3);
00400 
00401     sprintf(histo, "EESRT FR Flagged Dropped Readout Number EE -");
00402     EEDroppedFRCount_[0] = dqmStore_->book1D(histo, histo, 20, 0., 20.);
00403     EEDroppedFRCount_[0]->setAxisTitle("Readout Units number", 1);
00404 
00405     sprintf(histo, "EESRT FR Flagged Dropped Readout Number EE +");
00406     EEDroppedFRCount_[1] = dqmStore_->book1D(histo, histo, 20, 0., 20.);
00407     EEDroppedFRCount_[1]->setAxisTitle("Readout Units number", 1);
00408 
00409     sprintf(histo, "EESRT event size EE -");
00410     EEEventSize_[0] = dqmStore_->book1D(histo, histo, 100, 0, 200);
00411     EEEventSize_[0]->setAxisTitle("event size (kB)",1);
00412 
00413     sprintf(histo, "EESRT event size EE +");
00414     EEEventSize_[1] = dqmStore_->book1D(histo, histo, 100, 0, 200);
00415     EEEventSize_[1]->setAxisTitle("event size (kB)",1);
00416 
00417     sprintf(histo, "EESRT high interest payload EE -");
00418     EEHighInterestPayload_[0] =  dqmStore_->book1D(histo, histo, 100, 0, 200);
00419     EEHighInterestPayload_[0]->setAxisTitle("event size (kB)",1);
00420 
00421     sprintf(histo, "EESRT high interest payload EE +");
00422     EEHighInterestPayload_[1] =  dqmStore_->book1D(histo, histo, 100, 0, 200);
00423     EEHighInterestPayload_[1]->setAxisTitle("event size (kB)",1);
00424 
00425     sprintf(histo, "EESRT low interest payload EE -");
00426     EELowInterestPayload_[0] =  dqmStore_->book1D(histo, histo, 100, 0, 200);
00427     EELowInterestPayload_[0]->setAxisTitle("event size (kB)",1);
00428 
00429     sprintf(histo, "EESRT low interest payload EE +");
00430     EELowInterestPayload_[1] =  dqmStore_->book1D(histo, histo, 100, 0, 200);
00431     EELowInterestPayload_[1]->setAxisTitle("event size (kB)",1);
00432 
00433     sprintf(histo, "EESRT high interest ZS filter output EE -");
00434     EEHighInterestZsFIR_[0] = dqmStore_->book1D(histo, histo, 60, -30, 30);
00435     EEHighInterestZsFIR_[0]->setAxisTitle("ADC counts*4",1);
00436 
00437     sprintf(histo, "EESRT high interest ZS filter output EE +");
00438     EEHighInterestZsFIR_[1] = dqmStore_->book1D(histo, histo, 60, -30, 30);
00439     EEHighInterestZsFIR_[1]->setAxisTitle("ADC counts*4",1);
00440 
00441     sprintf(histo, "EESRT low interest ZS filter output EE -");
00442     EELowInterestZsFIR_[0] = dqmStore_->book1D(histo, histo, 60, -30, 30);
00443     EELowInterestZsFIR_[0]->setAxisTitle("ADC counts*4",1);
00444 
00445     sprintf(histo, "EESRT low interest ZS filter output EE +");
00446     EELowInterestZsFIR_[1] = dqmStore_->book1D(histo, histo, 60, -30, 30);
00447     EELowInterestZsFIR_[1]->setAxisTitle("ADC counts*4",1);
00448 
00449   }
00450 
00451 }
00452 
00453 void EESelectiveReadoutTask::cleanup(void){
00454 
00455   if ( ! init_ ) return;
00456 
00457   if ( dqmStore_ ) {
00458     dqmStore_->setCurrentFolder(prefixME_ + "/EESelectiveReadoutTask");
00459 
00460     if ( EETowerSize_[0] ) dqmStore_->removeElement( EETowerSize_[0]->getName() );
00461     EETowerSize_[0] = 0;
00462 
00463     if ( EETowerSize_[1] ) dqmStore_->removeElement( EETowerSize_[1]->getName() );
00464     EETowerSize_[1] = 0;
00465 
00466     if ( EETTFMismatch_[0] ) dqmStore_->removeElement( EETTFMismatch_[0]->getName() );
00467     EETTFMismatch_[0] = 0;
00468 
00469     if ( EETTFMismatch_[1] ) dqmStore_->removeElement( EETTFMismatch_[1]->getName() );
00470     EETTFMismatch_[1] = 0;
00471 
00472     if ( EEDccEventSize_ ) dqmStore_->removeElement( EEDccEventSize_->getName() );
00473     EEDccEventSize_ = 0;
00474 
00475     if ( EEDccEventSizeMap_ ) dqmStore_->removeElement( EEDccEventSizeMap_->getName() );
00476     EEDccEventSizeMap_ = 0;
00477 
00478     if ( EEReadoutUnitForcedBitMap_[0] ) dqmStore_->removeElement( EEReadoutUnitForcedBitMap_[0]->getName() );
00479     EEReadoutUnitForcedBitMap_[0] = 0;
00480 
00481     if ( EEReadoutUnitForcedBitMap_[1] ) dqmStore_->removeElement( EEReadoutUnitForcedBitMap_[1]->getName() );
00482     EEReadoutUnitForcedBitMap_[1] = 0;
00483 
00484     if ( EEFullReadoutSRFlagMap_[0] ) dqmStore_->removeElement( EEFullReadoutSRFlagMap_[0]->getName() );
00485     EEFullReadoutSRFlagMap_[0] = 0;
00486 
00487     if ( EEFullReadoutSRFlagMap_[1] ) dqmStore_->removeElement( EEFullReadoutSRFlagMap_[1]->getName() );
00488     EEFullReadoutSRFlagMap_[1] = 0;
00489 
00490     if ( EEFullReadoutSRFlagCount_[0] ) dqmStore_->removeElement( EEFullReadoutSRFlagCount_[0]->getName() );
00491     EEFullReadoutSRFlagCount_[0] = 0;
00492 
00493     if ( EEFullReadoutSRFlagCount_[1] ) dqmStore_->removeElement( EEFullReadoutSRFlagCount_[1]->getName() );
00494     EEFullReadoutSRFlagCount_[1] = 0;
00495 
00496     if ( EEZeroSuppression1SRFlagMap_[0] ) dqmStore_->removeElement( EEZeroSuppression1SRFlagMap_[0]->getName() );
00497     EEZeroSuppression1SRFlagMap_[0] = 0;
00498 
00499     if ( EEZeroSuppression1SRFlagMap_[1] ) dqmStore_->removeElement( EEZeroSuppression1SRFlagMap_[1]->getName() );
00500     EEZeroSuppression1SRFlagMap_[1] = 0;
00501 
00502     if ( EEHighInterestTriggerTowerFlagMap_[0] ) dqmStore_->removeElement( EEHighInterestTriggerTowerFlagMap_[0]->getName() );
00503     EEHighInterestTriggerTowerFlagMap_[0] = 0;
00504 
00505     if ( EEHighInterestTriggerTowerFlagMap_[1] ) dqmStore_->removeElement( EEHighInterestTriggerTowerFlagMap_[1]->getName() );
00506     EEHighInterestTriggerTowerFlagMap_[1] = 0;
00507 
00508     if ( EELowInterestTriggerTowerFlagMap_[0] ) dqmStore_->removeElement( EELowInterestTriggerTowerFlagMap_[0]->getName() );
00509     EELowInterestTriggerTowerFlagMap_[0] = 0;
00510 
00511     if ( EELowInterestTriggerTowerFlagMap_[1] ) dqmStore_->removeElement( EELowInterestTriggerTowerFlagMap_[1]->getName() );
00512     EELowInterestTriggerTowerFlagMap_[1] = 0;
00513 
00514     if ( EETTFlags_[0] ) dqmStore_->removeElement( EETTFlags_[0]->getName() );
00515     EETTFlags_[0] = 0;
00516 
00517     if ( EETTFlags_[1] ) dqmStore_->removeElement( EETTFlags_[1]->getName() );
00518     EETTFlags_[1] = 0;
00519 
00520     if ( EECompleteZSMap_[0] ) dqmStore_->removeElement( EECompleteZSMap_[0]->getName() );
00521     EECompleteZSMap_[0] = 0;
00522 
00523     if ( EECompleteZSMap_[1] ) dqmStore_->removeElement( EECompleteZSMap_[1]->getName() );
00524     EECompleteZSMap_[1] = 0;
00525 
00526     if ( EECompleteZSCount_[0] ) dqmStore_->removeElement( EECompleteZSCount_[0]->getName() );
00527     EECompleteZSCount_[0] = 0;
00528 
00529     if ( EECompleteZSCount_[1] ) dqmStore_->removeElement( EECompleteZSCount_[1]->getName() );
00530     EECompleteZSCount_[1] = 0;
00531 
00532     if ( EEDroppedFRMap_[0] ) dqmStore_->removeElement( EEDroppedFRMap_[0]->getName() );
00533     EEDroppedFRMap_[0] = 0;
00534 
00535     if ( EEDroppedFRMap_[1] ) dqmStore_->removeElement( EEDroppedFRMap_[1]->getName() );
00536     EEDroppedFRMap_[1] = 0;
00537 
00538     if ( EEDroppedFRCount_[0] ) dqmStore_->removeElement( EEDroppedFRCount_[0]->getName() );
00539     EEDroppedFRCount_[0] = 0;
00540 
00541     if ( EEDroppedFRCount_[1] ) dqmStore_->removeElement( EEDroppedFRCount_[1]->getName() );
00542     EEDroppedFRCount_[1] = 0;
00543 
00544     if ( EEEventSize_[0] ) dqmStore_->removeElement( EEEventSize_[0]->getName() );
00545     EEEventSize_[0] = 0;
00546 
00547     if ( EEEventSize_[1] ) dqmStore_->removeElement( EEEventSize_[1]->getName() );
00548     EEEventSize_[1] = 0;
00549 
00550     if ( EEHighInterestPayload_[0] ) dqmStore_->removeElement( EEHighInterestPayload_[0]->getName() );
00551     EEHighInterestPayload_[0] = 0;
00552 
00553     if ( EEHighInterestPayload_[1] ) dqmStore_->removeElement( EEHighInterestPayload_[1]->getName() );
00554     EEHighInterestPayload_[1] = 0;
00555 
00556     if ( EELowInterestPayload_[0] ) dqmStore_->removeElement( EELowInterestPayload_[0]->getName() );
00557     EELowInterestPayload_[0] = 0;
00558 
00559     if ( EELowInterestPayload_[1] ) dqmStore_->removeElement( EELowInterestPayload_[1]->getName() );
00560     EELowInterestPayload_[1] = 0;
00561 
00562     if ( EEHighInterestZsFIR_[0] ) dqmStore_->removeElement( EEHighInterestZsFIR_[0]->getName() );
00563     EEHighInterestZsFIR_[0] = 0;
00564 
00565     if ( EEHighInterestZsFIR_[1] ) dqmStore_->removeElement( EEHighInterestZsFIR_[1]->getName() );
00566     EEHighInterestZsFIR_[1] = 0;
00567 
00568     if ( EELowInterestZsFIR_[0] ) dqmStore_->removeElement( EELowInterestZsFIR_[0]->getName() );
00569     EELowInterestZsFIR_[0] = 0;
00570 
00571     if ( EELowInterestZsFIR_[1] ) dqmStore_->removeElement( EELowInterestZsFIR_[1]->getName() );
00572     EELowInterestZsFIR_[1] = 0;
00573 
00574   }
00575 
00576   init_ = false;
00577 
00578 }
00579 
00580 void EESelectiveReadoutTask::endJob(void){
00581 
00582   edm::LogInfo("EESelectiveReadoutTask") << "analyzed " << ievt_ << " events";
00583 
00584   if ( enableCleanup_ ) this->cleanup();
00585 
00586 }
00587 
00588 void EESelectiveReadoutTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00589 
00590   if ( ! init_ ) this->setup();
00591 
00592   ievt_++;
00593 
00594   edm::Handle<FEDRawDataCollection> raw;
00595   if ( e.getByLabel(FEDRawDataCollection_, raw) ) {
00596 
00597     int EEFirstFED[2];
00598     EEFirstFED[0] = 601; // EE-
00599     EEFirstFED[1] = 646; // EE+
00600     for(int zside=0; zside<2; zside++) {
00601 
00602       int firstFedOnSide=EEFirstFED[zside];
00603 
00604       for ( int iDcc = 0; iDcc < 9; ++iDcc ) {
00605 
00606         int ism = 0;
00607         if ( zside == 0 ) ism = iDcc+1;
00608         else ism = 10+iDcc;
00609 
00610         EEDccEventSize_->Fill( ism, ((double)raw->FEDData(firstFedOnSide+iDcc).size())/kByte );
00611         EEDccEventSizeMap_->Fill( ism, ((double)raw->FEDData(firstFedOnSide+iDcc).size())/kByte );
00612 
00613       }
00614     }
00615 
00616   } else {
00617     edm::LogWarning("EESelectiveReadoutTask") << FEDRawDataCollection_ << " not available";
00618   }
00619 
00620   // Selective Readout Flags
00621   int nFRO[2], nCompleteZS[2], nDroppedFRO[2];
00622   nFRO[0] = nFRO[1] = 0;
00623   nCompleteZS[0] = nCompleteZS[1] = 0;
00624   nDroppedFRO[0] = nDroppedFRO[1] = 0;
00625   edm::Handle<EESrFlagCollection> eeSrFlags;
00626   if ( e.getByLabel(EESRFlagCollection_,eeSrFlags) ) {
00627 
00628     // Data Volume
00629     double aLowInterest[2];
00630     double aHighInterest[2];
00631     double aAnyInterest[2];
00632 
00633     aLowInterest[0]=0;
00634     aHighInterest[0]=0;
00635     aAnyInterest[0]=0;
00636     aLowInterest[1]=0;
00637     aHighInterest[1]=0;
00638     aAnyInterest[1]=0;
00639 
00640     edm::Handle<EEDigiCollection> eeDigis;
00641     if ( e.getByLabel(EEDigiCollection_ , eeDigis) ) {
00642 
00643       anaDigiInit();
00644 
00645       // channel status
00646       edm::ESHandle<EcalChannelStatus> pChannelStatus;
00647       c.get<EcalChannelStatusRcd>().get(pChannelStatus);
00648       const EcalChannelStatus* chStatus = pChannelStatus.product();  
00649 
00650       for (unsigned int digis=0; digis<eeDigis->size(); ++digis) {
00651         EEDataFrame eedf = (*eeDigis)[digis];
00652         EEDetId id = eedf.id();
00653         EcalChannelStatusMap::const_iterator chit;
00654         chit = chStatus->getMap().find(id.rawId());
00655         uint16_t statusCode = 0;
00656         if( chit != chStatus->getMap().end() ) {
00657           EcalChannelStatusCode ch_code = (*chit);
00658           statusCode = ch_code.getStatusCode();
00659         }
00660         anaDigi(eedf, *eeSrFlags, statusCode);
00661       }
00662 
00663       //low interest channels:
00664       aLowInterest[0] = nEeLI_[0]*bytesPerCrystal/kByte;
00665       EELowInterestPayload_[0]->Fill(aLowInterest[0]);
00666       aLowInterest[1] = nEeLI_[1]*bytesPerCrystal/kByte;
00667       EELowInterestPayload_[1]->Fill(aLowInterest[1]);
00668 
00669       //low interest channels:
00670       aHighInterest[0] = nEeHI_[0]*bytesPerCrystal/kByte;
00671       EEHighInterestPayload_[0]->Fill(aHighInterest[0]);
00672       aHighInterest[1] = nEeHI_[1]*bytesPerCrystal/kByte;
00673       EEHighInterestPayload_[1]->Fill(aHighInterest[1]);
00674 
00675       //any-interest channels:
00676       aAnyInterest[0] = getEeEventSize(nEe_[0])/kByte;
00677       EEEventSize_[0]->Fill(aAnyInterest[0]);
00678       aAnyInterest[1] = getEeEventSize(nEe_[1])/kByte;
00679       EEEventSize_[1]->Fill(aAnyInterest[1]);
00680 
00681       //event size by tower:
00682       for(int ix = 0; ix < 20; ix++ ) {
00683         for(int iy = 0; iy < 20; iy++ ) {
00684           for(int iz = 0; iz < 2; iz++) {
00685 
00686             double towerSize =  nCrySC[ix][iy][iz] * bytesPerCrystal;
00687 
00688             float xix = ix;
00689             if ( iz == 0 ) xix = 19 - xix;
00690             xix += 0.5;
00691 
00692             float xiy = iy+0.5;
00693 
00694             EETowerSize_[iz]->Fill(xix, xiy, towerSize);
00695 
00696           }
00697         }
00698       }
00699 
00700     } else {
00701       edm::LogWarning("EESelectiveReadoutTask") << EEDigiCollection_ << " not available";
00702     }
00703 
00704     // initialize dcchs_ to mask disabled towers
00705     std::map< int, std::vector<short> > towersStatus;
00706     edm::Handle<EcalRawDataCollection> dcchs;
00707 
00708     if( e.getByLabel(FEDRawDataCollection_, dcchs) ) {
00709       for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00710         if ( Numbers::subDet( *dcchItr ) != EcalEndcap ) continue;
00711         int ism = Numbers::iSM( *dcchItr, EcalEndcap );
00712         towersStatus.insert(std::make_pair(ism, dcchItr->getFEStatus()));
00713       }
00714     }
00715 
00716     for ( EESrFlagCollection::const_iterator it = eeSrFlags->begin(); it != eeSrFlags->end(); ++it ) {
00717 
00718       EcalScDetId id = it->id();
00719 
00720       if ( Numbers::subDet( id ) != EcalEndcap ) continue;
00721 
00722       int ix = id.ix();
00723       int iy = id.iy();
00724       int iDcc = dccNumOfRU(id);
00725       int ism = Numbers::iSM( id );
00726       int isc = Numbers::iSC( id );
00727 
00728       int zside = id.zside();
00729 
00730       int iz = ( zside < 0 ) ? 0 : 1;
00731 
00732       if ( zside < 0 ) ix = 21 - ix;
00733 
00734       nEvtAnyReadout[ix-1][iy-1][iz]++;
00735 
00736       int flag = it->value() & ~EcalSrFlag::SRF_FORCED_MASK;
00737 
00738       int status=0;
00739       if( towersStatus[ism].size() > 0 ) status = (towersStatus[ism])[isc];
00740 
00741       if(flag == EcalSrFlag::SRF_FULL) {
00742         nEvtFullReadout[ix-1][iy-1][iz]++;
00743         nFRO[iz]++;
00744         if(nPerRu_[iDcc-1][isc] == 0) {
00745           if(status != 1) nEvtDroppedReadoutIfFR[ix-1][iy-1][iz]++;
00746           nDroppedFRO[iz]++;
00747         }
00748       }
00749 
00750       if(flag == EcalSrFlag::SRF_ZS1) nEvtZS1Readout[ix-1][iy-1][iz]++;
00751 
00752       if(it->value() & EcalSrFlag::SRF_FORCED_MASK) nEvtRUForced[ix-1][iy-1][iz]++;
00753 
00754       if(flag == EcalSrFlag::SRF_ZS1 || flag == EcalSrFlag::SRF_ZS2) {
00755         nEvtZSReadout[ix-1][iy-1][iz]++;
00756         if(nPerRu_[iDcc-1][isc] == getCrystalCount(iDcc,isc)) {
00757           if(status != 1) nEvtCompleteReadoutIfZS[ix-1][iy-1][iz]++;
00758           nCompleteZS[iz]++;
00759         }
00760       }
00761 
00762     }
00763   } else {
00764     edm::LogWarning("EESelectiveReadoutTask") << EESRFlagCollection_ << " not available";
00765   }
00766 
00767   for(int ix = 0; ix < 20; ix++ ) {
00768     for(int iy = 0; iy < 20; iy++ ) {
00769       for(int iz = 0; iz < 2; iz++) {
00770 
00771         if( nEvtAnyReadout[ix][iy][iz] ) {
00772 
00773           float xix = ix;
00774           if ( iz == 0 ) xix = 19 - xix;
00775           xix += 0.5;
00776 
00777           float xiy = iy+0.5;
00778 
00779           float fraction = float(nEvtFullReadout[ix][iy][iz]) / float(nEvtAnyReadout[ix][iy][iz]);
00780           float error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[ix][iy][iz]));
00781 
00782           TH2F *h2d = EEFullReadoutSRFlagMap_[iz]->getTH2F();
00783 
00784           int binx=0, biny=0;
00785 
00786           if( h2d ) {
00787             binx = h2d->GetXaxis()->FindBin(xix);
00788             biny = h2d->GetYaxis()->FindBin(xiy);
00789           }
00790 
00791           EEFullReadoutSRFlagMap_[iz]->setBinContent(binx, biny, fraction);
00792           EEFullReadoutSRFlagMap_[iz]->setBinError(binx, biny, error);
00793 
00794 
00795           fraction = float(nEvtZS1Readout[ix][iy][iz]) / float(nEvtAnyReadout[ix][iy][iz]);
00796           error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[ix][iy][iz]));
00797 
00798           h2d = EEZeroSuppression1SRFlagMap_[iz]->getTH2F();
00799 
00800           if( h2d ) {
00801             binx = h2d->GetXaxis()->FindBin(xix);
00802             biny = h2d->GetYaxis()->FindBin(xiy);
00803           }
00804 
00805           EEZeroSuppression1SRFlagMap_[iz]->setBinContent(binx, biny, fraction);
00806           EEZeroSuppression1SRFlagMap_[iz]->setBinError(binx, biny, error);
00807 
00808 
00809           fraction = float(nEvtRUForced[ix][iy][iz]) / float(nEvtAnyReadout[ix][iy][iz]);
00810           error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[ix][iy][iz]));
00811 
00812           h2d = EEReadoutUnitForcedBitMap_[iz]->getTH2F();
00813 
00814           if( h2d ) {
00815             binx = h2d->GetXaxis()->FindBin(xix);
00816             biny = h2d->GetYaxis()->FindBin(xiy);
00817           }
00818 
00819           EEReadoutUnitForcedBitMap_[iz]->setBinContent(binx, biny, fraction);
00820           EEReadoutUnitForcedBitMap_[iz]->setBinError(binx, biny, error);
00821 
00822           if( nEvtZSReadout[ix][iy][iz] ) {
00823             fraction = float(nEvtCompleteReadoutIfZS[ix][iy][iz]) / float(nEvtZSReadout[ix][iy][iz]);
00824             error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[ix][iy][iz]));
00825             
00826             h2d = EECompleteZSMap_[iz]->getTH2F();
00827             
00828             if( h2d ) {
00829               binx = h2d->GetXaxis()->FindBin(xix);
00830               biny = h2d->GetYaxis()->FindBin(xiy);
00831             }
00832             
00833             EECompleteZSMap_[iz]->setBinContent(binx, biny, fraction);
00834             EECompleteZSMap_[iz]->setBinError(binx, biny, error);
00835           }
00836 
00837           if( nEvtFullReadout[ix][iy][iz] ) {
00838             fraction = float(nEvtDroppedReadoutIfFR[ix][iy][iz]) / float(nEvtFullReadout[ix][iy][iz]);
00839             error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[ix][iy][iz]));
00840             
00841             h2d = EEDroppedFRMap_[iz]->getTH2F();
00842             
00843             if( h2d ) {
00844               binx = h2d->GetXaxis()->FindBin(xix);
00845               biny = h2d->GetYaxis()->FindBin(xiy);
00846             }
00847 
00848             EEDroppedFRMap_[iz]->setBinContent(binx, biny, fraction);
00849             EEDroppedFRMap_[iz]->setBinError(binx, biny, error);
00850           }
00851 
00852         }
00853 
00854       }
00855     }
00856   }
00857 
00858   for(int iz = 0; iz < 2; iz++) {
00859     EEFullReadoutSRFlagCount_[iz]->Fill( nFRO[iz] );
00860     EECompleteZSCount_[iz]->Fill( nCompleteZS[iz] );
00861     EEDroppedFRCount_[iz]->Fill( nDroppedFRO[iz] );
00862   }
00863 
00864   edm::Handle<EcalTrigPrimDigiCollection> TPCollection;
00865   if ( e.getByLabel(EcalTrigPrimDigiCollection_, TPCollection) ) {
00866 
00867     // Trigger Primitives
00868     EcalTrigPrimDigiCollection::const_iterator TPdigi;
00869     for ( TPdigi = TPCollection->begin(); TPdigi != TPCollection->end(); ++TPdigi ) {
00870 
00871       if ( Numbers::subDet( TPdigi->id() ) != EcalEndcap ) continue;
00872 
00873       int ismt = Numbers::iSM( TPdigi->id() );
00874       int zside = TPdigi->id().zside();
00875       int iz = ( zside < 0 ) ? 0 : 1;
00876 
00877       EETTFlags_[iz]->Fill( TPdigi->ttFlag() );
00878 
00879       std::vector<DetId>* crystals = Numbers::crystals( TPdigi->id() );
00880 
00881       for ( unsigned int i=0; i<crystals->size(); i++ ) {
00882 
00883         EEDetId id = (*crystals)[i];
00884 
00885         int ix = id.ix();
00886         int iy = id.iy();
00887         int ism = Numbers::iSM( id );
00888         int itcc = Numbers::iTCC( ism, EcalEndcap, ix, iy );
00889         int itt = Numbers::iTT( ism, EcalEndcap, ix, iy );
00890 
00891         if ( ismt >= 1 && ismt <= 9 ) ix = 101 - ix;
00892 
00893         nEvtAnyInterest[ix-1][iy-1][iz]++;
00894 
00895         if ( (TPdigi->ttFlag() & 0x3) == 0 ) nEvtLowInterest[ix-1][iy-1][iz]++;
00896 
00897         if ( (TPdigi->ttFlag() & 0x3) == 1 ) nEvtMediumInterest[ix-1][iy-1][iz]++;
00898 
00899         if ( (TPdigi->ttFlag() & 0x3) == 3 ) nEvtHighInterest[ix-1][iy-1][iz]++;
00900 
00901         float xix = ix-0.5;
00902         if ( iz == 0 ) xix = 100 - xix;
00903         float xiy = iy-0.5;
00904 
00905         if ( ((TPdigi->ttFlag() & 0x3) == 1 || (TPdigi->ttFlag() & 0x3) == 3)
00906              && nCryTT[itcc-1][itt-1] != (int)crystals->size() ) EETTFMismatch_[iz]->Fill(xix, xiy);
00907 
00908       }
00909 
00910     }
00911   } else {
00912     edm::LogWarning("EESelectiveReadoutTask") << EcalTrigPrimDigiCollection_ << " not available";
00913   }
00914 
00915   for(int ix = 0; ix < 100; ix++ ) {
00916     for(int iy = 0; iy < 100; iy++ ) {
00917       for(int iz = 0; iz < 2; iz++) {
00918 
00919         if( nEvtAnyInterest[ix][iy][iz] ) {
00920 
00921           float xix = ix;
00922           if ( iz == 0 ) xix = 99 - xix;
00923           xix += 0.5;
00924 
00925           float xiy = iy+0.5;
00926 
00927           float fraction = float(nEvtHighInterest[ix][iy][iz]) / float(nEvtAnyInterest[ix][iy][iz]);
00928           float error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[ix][iy][iz]));
00929 
00930           TH2F *h2d = EEHighInterestTriggerTowerFlagMap_[iz]->getTH2F();
00931 
00932           int binx=0, biny=0;
00933 
00934           if( h2d ) {
00935             binx = h2d->GetXaxis()->FindBin(xix);
00936             biny = h2d->GetYaxis()->FindBin(xiy);
00937           }
00938 
00939           EEHighInterestTriggerTowerFlagMap_[iz]->setBinContent(binx, biny, fraction);
00940           EEHighInterestTriggerTowerFlagMap_[iz]->setBinError(binx, biny, error);
00941 
00942 
00943           fraction = float(nEvtMediumInterest[ix][iy][iz]) / float(nEvtAnyInterest[ix][iy][iz]);
00944           error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[ix][iy][iz]));
00945 
00946           h2d = EEMediumInterestTriggerTowerFlagMap_[iz]->getTH2F();
00947 
00948           if( h2d ) {
00949             binx = h2d->GetXaxis()->FindBin(xix);
00950             biny = h2d->GetYaxis()->FindBin(xiy);
00951           }
00952 
00953           EEMediumInterestTriggerTowerFlagMap_[iz]->setBinContent(binx, biny, fraction);
00954           EEMediumInterestTriggerTowerFlagMap_[iz]->setBinError(binx, biny, error);
00955 
00956 
00957           fraction = float(nEvtLowInterest[ix][iy][iz]) / float(nEvtAnyInterest[ix][iy][iz]);
00958           error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[ix][iy][iz]));
00959 
00960           h2d = EELowInterestTriggerTowerFlagMap_[iz]->getTH2F();
00961 
00962           if( h2d ) {
00963             binx = h2d->GetXaxis()->FindBin(xix);
00964             biny = h2d->GetYaxis()->FindBin(xiy);
00965           }
00966 
00967           EELowInterestTriggerTowerFlagMap_[iz]->setBinContent(binx, biny, fraction);
00968           EELowInterestTriggerTowerFlagMap_[iz]->setBinError(binx, biny, error);
00969 
00970         }
00971 
00972       }
00973     }
00974   }
00975 
00976 }
00977 
00978 void EESelectiveReadoutTask::anaDigi(const EEDataFrame& frame, const EESrFlagCollection& srFlagColl, uint16_t statusCode){
00979   
00980   EEDetId id = frame.id();
00981   int ism = Numbers::iSM( id );
00982 
00983   bool endcap = (id.subdetId()==EcalEndcap);
00984 
00985   if(endcap) {
00986     if ( ism >= 1 && ism <= 9 ) {
00987       ++nEe_[0];
00988     } else {
00989       ++nEe_[1];
00990     }
00991 
00992     int ix = id.ix();
00993     int iy = id.iy();
00994 
00995     int iX0 = iXY2cIndex(ix);
00996     int iY0 = iXY2cIndex(iy);
00997     int iZ0 = id.zside()>0?1:0;
00998 
00999     if(!eeRuActive_[iZ0][iX0/scEdge][iY0/scEdge]){
01000       ++nRuPerDcc_[dccNum(id)];
01001       eeRuActive_[iZ0][iX0/scEdge][iY0/scEdge] = true;
01002     }
01003 
01004     EESrFlagCollection::const_iterator srf = srFlagColl.find(readOutUnitOf(id));
01005 
01006     if(srf == srFlagColl.end()){
01007       return;
01008     }
01009 
01010     int ttix = srf->id().ix();
01011     int ttiy = srf->id().iy();
01012 
01013     int zside = srf->id().zside();
01014 
01015     int ttiz = ( zside < 0 ) ? 0 : 1;
01016 
01017     nCrySC[ttix-1][ttiy-1][ttiz]++;
01018 
01019     int itcc = Numbers::iTCC( ism, EcalEndcap, ix, iy );
01020     int itt = Numbers::iTT( ism, EcalEndcap, ix, iy );
01021     nCryTT[itcc-1][itt-1]++;
01022 
01023     bool highInterest = ((srf->value() & ~EcalSrFlag::SRF_FORCED_MASK)
01024                          == EcalSrFlag::SRF_FULL);
01025 
01026     int dccZsFIRval = dccZsFIR(frame, firWeights_, firstFIRSample_, 0);
01027 
01028     if ( ism >= 1 && ism <= 9 ) {
01029       if(highInterest) {
01030         ++nEeHI_[0];
01031         // if(statusCode != 9) EEHighInterestZsFIR_[0]->Fill( dccZsFIRval );
01032         EEHighInterestZsFIR_[0]->Fill( dccZsFIRval );
01033       } else{ //low interest
01034         ++nEeLI_[0];
01035         // if(statusCode != 9) EELowInterestZsFIR_[0]->Fill( dccZsFIRval );
01036         EELowInterestZsFIR_[0]->Fill( dccZsFIRval );
01037       }
01038     } else {
01039       if(highInterest) {
01040         ++nEeHI_[1];
01041         EEHighInterestZsFIR_[1]->Fill( dccZsFIRval );
01042       } else{ //low interest
01043         ++nEeLI_[1];
01044         EELowInterestZsFIR_[1]->Fill( dccZsFIRval );
01045       }
01046     }
01047     int isc = Numbers::iSC( ism, EcalEndcap, ix, iy );
01048     ++nPerDcc_[dccNum(id)-1];
01049     ++nPerRu_[dccNum(id)-1][isc];
01050   }
01051   
01052 }
01053 
01054 void EESelectiveReadoutTask::anaDigiInit(){
01055   nEe_[0] = 0;
01056   nEeLI_[0] = 0;
01057   nEeHI_[0] = 0;
01058   nEe_[1] = 0;
01059   nEeLI_[1] = 0;
01060   nEeHI_[1] = 0;
01061   bzero(nPerDcc_, sizeof(nPerDcc_));
01062   bzero(nRuPerDcc_, sizeof(nRuPerDcc_));
01063   bzero(eeRuActive_, sizeof(eeRuActive_));
01064 
01065   for(int idcc=0; idcc<nECALDcc; idcc++) {
01066     for(int isc=0; isc<nDccChs; isc++) {
01067       nPerRu_[idcc][isc] = 0;
01068     }
01069   }
01070 
01071   for(int iz = 0; iz<2; iz++) {
01072     for(int ix = 0; ix < 20; ix++ ) {
01073       for(int iy = 0; iy < 20; iy++ ) {
01074         nCrySC[ix][iy][iz] = 0;
01075       }
01076     }
01077   }
01078 
01079   for (int itcc = 0; itcc < 108; itcc++) {
01080     for (int itt = 0; itt < 41; itt++) nCryTT[itcc][itt] = 0;
01081   }
01082 
01083 }
01084 
01085 const EcalScDetId
01086 EESelectiveReadoutTask::readOutUnitOf(const EEDetId& xtalId) const {
01087   if (xtalId.ix() > 40 && xtalId.ix() < 61 &&
01088       xtalId.iy() > 40 && xtalId.iy() < 61) {
01089     // crystal belongs to an inner partial supercrystal
01090     return Numbers::getEcalScDetId(xtalId);
01091   } else {
01092     return EcalScDetId((xtalId.ix()-1)/5+1, (xtalId.iy()-1)/5+1, xtalId.zside());
01093   }
01094 }
01095 
01096 unsigned EESelectiveReadoutTask::dccNum(const DetId& xtalId) const {
01097   int j;
01098   int k;
01099 
01100   if ( xtalId.det()!=DetId::Ecal ) {
01101     throw cms::Exception("EESelectiveReadoutTask") << "Crystal does not belong to ECAL";
01102   }
01103 
01104   int iDet = 0;
01105 
01106   if(xtalId.subdetId()==EcalEndcap){
01107     EEDetId eeDetId(xtalId);
01108     j = iXY2cIndex(eeDetId.ix());
01109     k = iXY2cIndex(eeDetId.iy());
01110     int zside = eeDetId.zside();
01111     if ( zside < 0 ) iDet = 0;
01112     else iDet = 2;
01113   } else {
01114     throw cms::Exception("EESelectiveReadoutTask") << "Not ECAL endcap.";
01115   }
01116   int iDcc0 = dccIndex(iDet,j,k);
01117   assert(iDcc0>=0 && iDcc0<nECALDcc);
01118   return iDcc0+1;
01119 }
01120 
01121 unsigned EESelectiveReadoutTask::dccNumOfRU(const EcalScDetId& scId) const {
01122   int j;
01123   int k;
01124 
01125   if ( scId.det()!=DetId::Ecal ) {
01126     throw cms::Exception("EESelectiveReadoutTask") << "SuperCrystal does not belong to ECAL";
01127   }
01128 
01129   int iDet = 0;
01130 
01131   if(scId.subdetId()==EcalEndcap){
01132     j = scId.ix()-1;
01133     k = scId.iy()-1;
01134     int zside = scId.zside();
01135     if ( zside < 0 ) iDet = 0;
01136     else iDet = 2;
01137   } else {
01138     throw cms::Exception("EESelectiveReadoutTask") << "Not ECAL endcap.";
01139   }
01140   int iDcc0 = 0;
01141   int iPhi = dccPhiIndexOfRU(j,k);
01142   if(iPhi<0) iDcc0 = -1;
01143   else iDcc0 = iPhi+iDet/2*45;
01144   assert(iDcc0>=0 && iDcc0<nECALDcc);
01145   return iDcc0+1;
01146 }
01147 
01148 double EESelectiveReadoutTask::getEeEventSize(double nReadXtals) const {
01149   double ruHeaderPayload = 0.;
01150   const int firstEbDcc0 = nEEDcc/2;
01151   for ( int iDcc0 = 0; iDcc0 < nECALDcc; ++iDcc0 ) {
01152     //skip barrel:
01153     if(iDcc0 == firstEbDcc0) iDcc0 += nEBDcc;
01154       ruHeaderPayload += nRuPerDcc_[iDcc0]*8.;
01155   }
01156   return getDccOverhead(EE)*nEEDcc +
01157          nReadXtals*bytesPerCrystal +
01158          ruHeaderPayload;
01159 }
01160 
01161 int EESelectiveReadoutTask::dccPhiIndexOfRU(int i, int j) const {
01162   char flag=endcapDccMap[i+j*20];
01163   return (flag==' ')?-1:(flag-'0');
01164 }
01165 
01166 int EESelectiveReadoutTask::dccIndex(int iDet, int i, int j) const {
01167   int iPhi = dccPhiIndex(i, j);
01168   if(iPhi<0) return -1;
01169   //34 DCCs in barrel and 8 in EE-=>in EE+ DCC numbering starts at 45,
01170   //iDet/2 is 0 for EE- and 1 for EE+:
01171   return iPhi+iDet/2*45;
01172 }
01173 
01174 //This implementation  assumes that int is coded on at least 28-bits,
01175 //which in pratice should be always true.
01176 int
01177 EESelectiveReadoutTask::dccZsFIR(const EcalDataFrame& frame,
01178                                  const std::vector<int>& firWeights,
01179                                  int firstFIRSample,
01180                                  bool* saturated){
01181   const int nFIRTaps = 6;
01182   //FIR filter weights:
01183   const std::vector<int>& w = firWeights;
01184 
01185   //accumulator used to compute weighted sum of samples
01186   int acc = 0;
01187   bool gain12saturated = false;
01188   const int gain12 = 0x01;
01189   const int lastFIRSample = firstFIRSample + nFIRTaps - 1;
01190   //LogDebug("DccFir") << "DCC FIR operation: ";
01191   int iWeight = 0;
01192   for(int iSample=firstFIRSample-1;
01193       iSample<lastFIRSample; ++iSample, ++iWeight){
01194     if(iSample>=0 && iSample < frame.size()){
01195       EcalMGPASample sample(frame[iSample]);
01196       if(sample.gainId()!=gain12) gain12saturated = true;
01197       LogTrace("DccFir") << (iSample>=firstFIRSample?"+":"") << sample.adc()
01198                          << "*(" << w[iWeight] << ")";
01199       acc+=sample.adc()*w[iWeight];
01200     } else{
01201       edm::LogWarning("DccFir") << __FILE__ << ":" << __LINE__ <<
01202         ": Not enough samples in data frame or 'ecalDccZs1stSample' module "
01203         "parameter is not valid...";
01204     }
01205   }
01206   LogTrace("DccFir") << "\n";
01207   //discards the 8 LSBs
01208   //(shift operator cannot be used on negative numbers because
01209   // the result depends on compilator implementation)
01210   acc = (acc>=0)?(acc >> 8):-(-acc >> 8);
01211   //ZS passed if weighted sum acc above ZS threshold or if
01212   //one sample has a lower gain than gain 12 (that is gain 12 output
01213   //is saturated)
01214 
01215   LogTrace("DccFir") << "acc: " << acc << "\n"
01216                      << "saturated: " << (gain12saturated?"yes":"no") << "\n";
01217 
01218   if(saturated){
01219     *saturated = gain12saturated;
01220   }
01221 
01222   return gain12saturated?std::numeric_limits<int>::max():acc;
01223 }
01224 
01225 std::vector<int>
01226 EESelectiveReadoutTask::getFIRWeights(const std::vector<double>&
01227                                       normalizedWeights){
01228   const int nFIRTaps = 6;
01229   std::vector<int> firWeights(nFIRTaps, 0); //default weight: 0;
01230   const static int maxWeight = 0xEFF; //weights coded on 11+1 signed bits
01231   for(unsigned i=0; i < std::min((size_t)nFIRTaps,normalizedWeights.size()); ++i){
01232     firWeights[i] = lround(normalizedWeights[i] * (1<<10));
01233     if(std::abs(firWeights[i])>maxWeight){//overflow
01234       firWeights[i] = firWeights[i]<0?-maxWeight:maxWeight;
01235     }
01236   }
01237   return firWeights;
01238 }
01239 
01240 void
01241 EESelectiveReadoutTask::configFirWeights(std::vector<double> weightsForZsFIR){
01242   bool notNormalized  = false;
01243   bool notInt = false;
01244   for(unsigned i=0; i < weightsForZsFIR.size(); ++i){
01245     if(weightsForZsFIR[i] > 1.) notNormalized = true;
01246     if((int)weightsForZsFIR[i]!=weightsForZsFIR[i]) notInt = true;
01247   }
01248   if(notInt && notNormalized){
01249     throw cms::Exception("InvalidParameter")
01250       << "weigtsForZsFIR paramater values are not valid: they "
01251       << "must either be integer and uses the hardware representation "
01252       << "of the weights or less or equal than 1 and used the normalized "
01253       << "representation.";
01254   }
01255   edm::LogInfo log("DccFir");
01256   if(notNormalized){
01257     firWeights_ = std::vector<int>(weightsForZsFIR.size());
01258     for(unsigned i = 0; i< weightsForZsFIR.size(); ++i){
01259       firWeights_[i] = (int)weightsForZsFIR[i];
01260     }
01261   } else{
01262     firWeights_ = getFIRWeights(weightsForZsFIR);
01263   }
01264 
01265   log << "Input weights for FIR: ";
01266   for(unsigned i = 0; i < weightsForZsFIR.size(); ++i){
01267     log << weightsForZsFIR[i] << "\t";
01268   }
01269 
01270   double s2 = 0.;
01271   log << "\nActual FIR weights: ";
01272   for(unsigned i = 0; i < firWeights_.size(); ++i){
01273     log << firWeights_[i] << "\t";
01274     s2 += firWeights_[i]*firWeights_[i];
01275   }
01276 
01277   s2 = sqrt(s2);
01278   log << "\nNormalized FIR weights after hw representation rounding: ";
01279   for(unsigned i = 0; i < firWeights_.size(); ++i){
01280     log << firWeights_[i] / (double)(1<<10) << "\t";
01281   }
01282 
01283   log <<"\nFirst FIR sample: " << firstFIRSample_;
01284 }
01285 
01286 int EESelectiveReadoutTask::getCrystalCount(int iDcc, int iDccCh) {
01287   if(iDcc<1 || iDcc>54) {
01288     // invalid DCC
01289     return 0;
01290   } else if (10 <= iDcc && iDcc <= 45) {
01291     // EB
01292     return 25;
01293   } else {
01294     // EE
01295     int iDccPhi;
01296     if(iDcc < 10) {
01297       iDccPhi = iDcc;
01298     } else {
01299       iDccPhi = iDcc - 45;
01300     }
01301     switch(iDccPhi*100+iDccCh){
01302       case 110:
01303       case 232:
01304       case 312:
01305       case 412:
01306       case 532:
01307       case 610:
01308       case 830:
01309       case 806:
01310         //inner partials at 12, 3, and 9 o'clock
01311         return 20;
01312       case 134:
01313       case 634:
01314       case 827:
01315       case 803:
01316       return 10;
01317       case 330:
01318       case 430:
01319         return 20;
01320       case 203:
01321       case 503:
01322       case 721:
01323       case 921:
01324         return 21;
01325       default:
01326         return 25;
01327     }
01328   }
01329 }