CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/EcalEndcapMonitorTasks/src/EESelectiveReadoutTask.cc

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