00001
00002
00003
00004
00005
00006
00007
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/EBDetId.h"
00026 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00027
00028 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00029 #include "DataFormats/EcalRawData/interface/EcalRawDataCollections.h"
00030 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00031
00032 #include "CondFormats/EcalObjects/interface/EcalChannelStatus.h"
00033 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00034
00035 #include "DQM/EcalCommon/interface/Numbers.h"
00036
00037 #include "DQM/EcalBarrelMonitorTasks/interface/EBSelectiveReadoutTask.h"
00038
00039 EBSelectiveReadoutTask::EBSelectiveReadoutTask(const edm::ParameterSet& ps){
00040
00041 init_ = false;
00042
00043 dqmStore_ = edm::Service<DQMStore>().operator->();
00044
00045 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00046
00047 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00048
00049 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00050
00051
00052 EBDigiCollection_ = ps.getParameter<edm::InputTag>("EBDigiCollection");
00053 EBUnsuppressedDigiCollection_ = ps.getParameter<edm::InputTag>("EBUsuppressedDigiCollection");
00054 EBSRFlagCollection_ = ps.getParameter<edm::InputTag>("EBSRFlagCollection");
00055 EcalTrigPrimDigiCollection_ = ps.getParameter<edm::InputTag>("EcalTrigPrimDigiCollection");
00056 FEDRawDataCollection_ = ps.getParameter<edm::InputTag>("FEDRawDataCollection");
00057 firstFIRSample_ = ps.getParameter<int>("ecalDccZs1stSample");
00058
00059 configFirWeights(ps.getParameter<std::vector<double> >("dccWeights"));
00060
00061
00062 EBTowerSize_ = 0;
00063 EBTTFMismatch_ = 0;
00064 EBDccEventSize_ = 0;
00065 EBDccEventSizeMap_ = 0;
00066 EBReadoutUnitForcedBitMap_ = 0;
00067 EBFullReadoutSRFlagMap_ = 0;
00068 EBFullReadoutSRFlagCount_ = 0;
00069 EBZeroSuppression1SRFlagMap_ = 0;
00070 EBHighInterestTriggerTowerFlagMap_ = 0;
00071 EBMediumInterestTriggerTowerFlagMap_ = 0;
00072 EBLowInterestTriggerTowerFlagMap_ = 0;
00073 EBTTFlags_ = 0;
00074 EBCompleteZSMap_ = 0;
00075 EBCompleteZSCount_ = 0;
00076 EBDroppedFRMap_ = 0;
00077 EBDroppedFRCount_ = 0;
00078 EBEventSize_ = 0;
00079 EBHighInterestPayload_ = 0;
00080 EBLowInterestPayload_ = 0;
00081 EBHighInterestZsFIR_ = 0;
00082 EBLowInterestZsFIR_ = 0;
00083
00084
00085 float ZSthreshold = 0.608;
00086 float zeroBinSize = ZSthreshold / 20.;
00087 for(int i=0; i<20; i++) ybins[i] = i*zeroBinSize;
00088 for(int i=20; i<89; i++) ybins[i] = ZSthreshold * (i-19);
00089 for(int i=0; i<=36; i++) xbins[i] = i+1;
00090
00091 }
00092
00093 EBSelectiveReadoutTask::~EBSelectiveReadoutTask() {
00094
00095 }
00096
00097 void EBSelectiveReadoutTask::beginJob(void) {
00098
00099 ievt_ = 0;
00100
00101 if ( dqmStore_ ) {
00102 dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
00103 dqmStore_->rmdir(prefixME_ + "/EBSelectiveReadoutTask");
00104 }
00105
00106 }
00107
00108 void EBSelectiveReadoutTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00109
00110 Numbers::initGeometry(c, false);
00111
00112 if ( ! mergeRuns_ ) this->reset();
00113
00114 for(int ietindex = 0; ietindex < 34; ietindex++ ) {
00115 for(int iptindex = 0; iptindex < 72; iptindex++ ) {
00116 nEvtFullReadout[iptindex][ietindex] = 0;
00117 nEvtZS1Readout[iptindex][ietindex] = 0;
00118 nEvtZSReadout[iptindex][ietindex] = 0;
00119 nEvtCompleteReadoutIfZS[iptindex][ietindex] = 0;
00120 nEvtDroppedReadoutIfFR[iptindex][ietindex] = 0;
00121 nEvtRUForced[iptindex][ietindex] = 0;
00122 nEvtAnyReadout[iptindex][ietindex] = 0;
00123 nEvtHighInterest[iptindex][ietindex] = 0;
00124 nEvtMediumInterest[iptindex][ietindex] = 0;
00125 nEvtLowInterest[iptindex][ietindex] = 0;
00126 nEvtAnyInterest[iptindex][ietindex] = 0;
00127 }
00128 }
00129
00130 }
00131
00132 void EBSelectiveReadoutTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00133
00134 }
00135
00136 void EBSelectiveReadoutTask::reset(void) {
00137
00138 if ( EBTowerSize_ ) EBTowerSize_->Reset();
00139
00140 if ( EBTTFMismatch_ ) EBTTFMismatch_->Reset();
00141
00142 if ( EBDccEventSize_ ) EBDccEventSize_->Reset();
00143
00144 if ( EBDccEventSizeMap_ ) EBDccEventSizeMap_->Reset();
00145
00146 if ( EBReadoutUnitForcedBitMap_ ) EBReadoutUnitForcedBitMap_->Reset();
00147
00148 if ( EBFullReadoutSRFlagMap_ ) EBFullReadoutSRFlagMap_->Reset();
00149
00150 if ( EBFullReadoutSRFlagCount_ ) EBFullReadoutSRFlagCount_->Reset();
00151
00152 if ( EBZeroSuppression1SRFlagMap_ ) EBZeroSuppression1SRFlagMap_->Reset();
00153
00154 if ( EBHighInterestTriggerTowerFlagMap_ ) EBHighInterestTriggerTowerFlagMap_->Reset();
00155
00156 if ( EBMediumInterestTriggerTowerFlagMap_ ) EBMediumInterestTriggerTowerFlagMap_->Reset();
00157
00158 if ( EBLowInterestTriggerTowerFlagMap_ ) EBLowInterestTriggerTowerFlagMap_->Reset();
00159
00160 if ( EBTTFlags_ ) EBTTFlags_->Reset();
00161
00162 if ( EBCompleteZSMap_ ) EBCompleteZSMap_->Reset();
00163
00164 if ( EBCompleteZSCount_ ) EBCompleteZSCount_->Reset();
00165
00166 if ( EBDroppedFRMap_ ) EBDroppedFRMap_->Reset();
00167
00168 if ( EBDroppedFRCount_ ) EBDroppedFRCount_->Reset();
00169
00170 if ( EBEventSize_ ) EBEventSize_->Reset();
00171
00172 if ( EBHighInterestPayload_ ) EBHighInterestPayload_->Reset();
00173
00174 if ( EBLowInterestPayload_ ) EBLowInterestPayload_->Reset();
00175
00176 if ( EBHighInterestZsFIR_ ) EBHighInterestZsFIR_->Reset();
00177
00178 if ( EBLowInterestZsFIR_ ) EBLowInterestZsFIR_->Reset();
00179
00180 }
00181
00182 void EBSelectiveReadoutTask::setup(void) {
00183
00184 init_ = true;
00185
00186 char histo[200];
00187
00188 if ( dqmStore_ ) {
00189
00190 dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
00191
00192 sprintf(histo, "EBSRT tower event size");
00193 EBTowerSize_ = dqmStore_->bookProfile2D(histo, histo, 72, 0, 72, 34, -17, 17, 100, 0, 200, "s");
00194 EBTowerSize_->setAxisTitle("jphi", 1);
00195 EBTowerSize_->setAxisTitle("jeta", 2);
00196
00197 sprintf(histo, "EBSRT TT flag mismatch");
00198 EBTTFMismatch_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00199 EBTTFMismatch_->setAxisTitle("jphi", 1);
00200 EBTTFMismatch_->setAxisTitle("jeta", 2);
00201
00202 sprintf(histo, "EBSRT DCC event size");
00203 EBDccEventSize_ = dqmStore_->bookProfile(histo, histo, 36, 1, 37, 100, 0., 200., "s");
00204 EBDccEventSize_->setAxisTitle("event size (kB)", 2);
00205 for (int i = 0; i < 36; i++) {
00206 EBDccEventSize_->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
00207 }
00208
00209 sprintf(histo, "EBSRT event size vs DCC");
00210 EBDccEventSizeMap_ = dqmStore_->book2D(histo, histo, 36, xbins, 88, ybins);
00211 EBDccEventSizeMap_->setAxisTitle("event size (kB)", 2);
00212 for (int i = 0; i < 36; i++) {
00213 EBDccEventSizeMap_->setBinLabel(i+1, Numbers::sEB(i+1).c_str(), 1);
00214 }
00215
00216 sprintf(histo, "EBSRT readout unit with SR forced");
00217 EBReadoutUnitForcedBitMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00218 EBReadoutUnitForcedBitMap_->setAxisTitle("jphi", 1);
00219 EBReadoutUnitForcedBitMap_->setAxisTitle("jeta", 2);
00220 EBReadoutUnitForcedBitMap_->setAxisTitle("rate", 3);
00221
00222 sprintf(histo, "EBSRT full readout SR Flags");
00223 EBFullReadoutSRFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00224 EBFullReadoutSRFlagMap_->setAxisTitle("jphi", 1);
00225 EBFullReadoutSRFlagMap_->setAxisTitle("jeta", 2);
00226 EBFullReadoutSRFlagMap_->setAxisTitle("rate", 3);
00227
00228 sprintf(histo, "EBSRT full readout SR Flags Number");
00229 EBFullReadoutSRFlagCount_ = dqmStore_->book1D(histo, histo, 200, 0., 200.);
00230 EBFullReadoutSRFlagCount_->setAxisTitle("Readout Units number", 1);
00231
00232 sprintf(histo, "EBSRT zero suppression 1 SR Flags");
00233 EBZeroSuppression1SRFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00234 EBZeroSuppression1SRFlagMap_->setAxisTitle("jphi", 1);
00235 EBZeroSuppression1SRFlagMap_->setAxisTitle("jeta", 2);
00236 EBZeroSuppression1SRFlagMap_->setAxisTitle("rate", 3);
00237
00238 sprintf(histo, "EBSRT high interest TT Flags");
00239 EBHighInterestTriggerTowerFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00240 EBHighInterestTriggerTowerFlagMap_->setAxisTitle("jphi", 1);
00241 EBHighInterestTriggerTowerFlagMap_->setAxisTitle("jeta", 2);
00242 EBHighInterestTriggerTowerFlagMap_->setAxisTitle("rate", 3);
00243
00244 sprintf(histo, "EBSRT medium interest TT Flags");
00245 EBMediumInterestTriggerTowerFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00246 EBMediumInterestTriggerTowerFlagMap_->setAxisTitle("jphi", 1);
00247 EBMediumInterestTriggerTowerFlagMap_->setAxisTitle("jeta", 2);
00248 EBMediumInterestTriggerTowerFlagMap_->setAxisTitle("rate", 3);
00249
00250 sprintf(histo, "EBSRT low interest TT Flags");
00251 EBLowInterestTriggerTowerFlagMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00252 EBLowInterestTriggerTowerFlagMap_->setAxisTitle("jphi", 1);
00253 EBLowInterestTriggerTowerFlagMap_->setAxisTitle("jeta", 2);
00254 EBLowInterestTriggerTowerFlagMap_->setAxisTitle("rate", 3);
00255
00256 sprintf(histo, "EBSRT TT Flags");
00257 EBTTFlags_ = dqmStore_->book1D(histo, histo, 8, 0., 8.);
00258 EBTTFlags_->setAxisTitle("TT Flag value", 1);
00259
00260 sprintf(histo, "EBSRT ZS Flagged Fully Readout");
00261 EBCompleteZSMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00262 EBCompleteZSMap_->setAxisTitle("jphi", 1);
00263 EBCompleteZSMap_->setAxisTitle("jeta", 2);
00264 EBCompleteZSMap_->setAxisTitle("rate", 3);
00265
00266 sprintf(histo, "EBSRT ZS Flagged Fully Readout Number");
00267 EBCompleteZSCount_ = dqmStore_->book1D(histo, histo, 20, 0., 20.);
00268 EBCompleteZSCount_->setAxisTitle("Readout Units number", 1);
00269
00270 sprintf(histo, "EBSRT FR Flagged Dropped Readout");
00271 EBDroppedFRMap_ = dqmStore_->book2D(histo, histo, 72, 0, 72, 34, -17, 17);
00272 EBDroppedFRMap_->setAxisTitle("jphi", 1);
00273 EBDroppedFRMap_->setAxisTitle("jeta", 2);
00274 EBDroppedFRMap_->setAxisTitle("rate", 3);
00275
00276 sprintf(histo, "EBSRT FR Flagged Dropped Readout Number");
00277 EBDroppedFRCount_ = dqmStore_->book1D(histo, histo, 20, 0., 20.);
00278 EBDroppedFRCount_->setAxisTitle("Readout Units number", 1);
00279
00280 sprintf(histo, "EBSRT event size");
00281 EBEventSize_ = dqmStore_->book1D(histo, histo, 100, 0, 200);
00282 EBEventSize_->setAxisTitle("event size (kB)",1);
00283
00284 sprintf(histo, "EBSRT high interest payload");
00285 EBHighInterestPayload_ = dqmStore_->book1D(histo, histo, 100, 0, 200);
00286 EBHighInterestPayload_->setAxisTitle("event size (kB)",1);
00287
00288 sprintf(histo, "EBSRT low interest payload");
00289 EBLowInterestPayload_ = dqmStore_->book1D(histo, histo, 100, 0, 200);
00290 EBLowInterestPayload_->setAxisTitle("event size (kB)",1);
00291
00292 sprintf(histo, "EBSRT high interest ZS filter output");
00293 EBHighInterestZsFIR_ = dqmStore_->book1D(histo, histo, 60, -30, 30);
00294 EBHighInterestZsFIR_->setAxisTitle("ADC counts*4",1);
00295
00296 sprintf(histo, "EBSRT low interest ZS filter output");
00297 EBLowInterestZsFIR_ = dqmStore_->book1D(histo, histo, 60, -30, 30);
00298 EBLowInterestZsFIR_->setAxisTitle("ADC counts*4",1);
00299
00300 }
00301
00302 }
00303
00304 void EBSelectiveReadoutTask::cleanup(void){
00305
00306 if ( ! init_ ) return;
00307
00308 if ( dqmStore_ ) {
00309
00310 dqmStore_->setCurrentFolder(prefixME_ + "/EBSelectiveReadoutTask");
00311
00312 if ( EBTowerSize_ ) dqmStore_->removeElement( EBTowerSize_->getName() );
00313 EBTowerSize_ = 0;
00314
00315 if ( EBTTFMismatch_ ) dqmStore_->removeElement( EBTTFMismatch_->getName() );
00316 EBTTFMismatch_ = 0;
00317
00318 if ( EBDccEventSize_ ) dqmStore_->removeElement( EBDccEventSize_->getName() );
00319 EBDccEventSize_ = 0;
00320
00321 if ( EBDccEventSizeMap_ ) dqmStore_->removeElement( EBDccEventSizeMap_->getName() );
00322 EBDccEventSizeMap_ = 0;
00323
00324 if ( EBReadoutUnitForcedBitMap_ ) dqmStore_->removeElement( EBReadoutUnitForcedBitMap_->getName() );
00325 EBReadoutUnitForcedBitMap_ = 0;
00326
00327 if ( EBFullReadoutSRFlagMap_ ) dqmStore_->removeElement( EBFullReadoutSRFlagMap_->getName() );
00328 EBFullReadoutSRFlagMap_ = 0;
00329
00330 if ( EBFullReadoutSRFlagCount_ ) dqmStore_->removeElement( EBFullReadoutSRFlagCount_->getName() );
00331 EBFullReadoutSRFlagCount_ = 0;
00332
00333 if ( EBFullReadoutSRFlagCount_ ) dqmStore_->removeElement( EBFullReadoutSRFlagCount_->getName() );
00334 EBFullReadoutSRFlagCount_ = 0;
00335
00336 if ( EBHighInterestTriggerTowerFlagMap_ ) dqmStore_->removeElement( EBHighInterestTriggerTowerFlagMap_->getName() );
00337 EBHighInterestTriggerTowerFlagMap_ = 0;
00338
00339 if ( EBMediumInterestTriggerTowerFlagMap_ ) dqmStore_->removeElement( EBMediumInterestTriggerTowerFlagMap_->getName() );
00340 EBMediumInterestTriggerTowerFlagMap_ = 0;
00341
00342 if ( EBLowInterestTriggerTowerFlagMap_ ) dqmStore_->removeElement( EBLowInterestTriggerTowerFlagMap_->getName() );
00343 EBLowInterestTriggerTowerFlagMap_ = 0;
00344
00345 if ( EBTTFlags_ ) dqmStore_->removeElement( EBTTFlags_->getName() );
00346 EBTTFlags_ = 0;
00347
00348 if ( EBCompleteZSMap_ ) dqmStore_->removeElement( EBCompleteZSMap_->getName() );
00349 EBCompleteZSMap_ = 0;
00350
00351 if ( EBCompleteZSCount_ ) dqmStore_->removeElement( EBCompleteZSCount_->getName() );
00352 EBCompleteZSCount_ = 0;
00353
00354 if ( EBDroppedFRMap_ ) dqmStore_->removeElement( EBDroppedFRMap_->getName() );
00355 EBDroppedFRMap_ = 0;
00356
00357 if ( EBDroppedFRCount_ ) dqmStore_->removeElement( EBDroppedFRCount_->getName() );
00358 EBDroppedFRCount_ = 0;
00359
00360 if ( EBEventSize_ ) dqmStore_->removeElement( EBEventSize_->getName() );
00361 EBEventSize_ = 0;
00362
00363 if ( EBHighInterestPayload_ ) dqmStore_->removeElement( EBHighInterestPayload_->getName() );
00364 EBHighInterestPayload_ = 0;
00365
00366 if ( EBLowInterestPayload_ ) dqmStore_->removeElement( EBLowInterestPayload_->getName() );
00367 EBLowInterestPayload_ = 0;
00368
00369 if ( EBHighInterestZsFIR_ ) dqmStore_->removeElement( EBHighInterestZsFIR_->getName() );
00370 EBHighInterestZsFIR_ = 0;
00371
00372 if ( EBLowInterestZsFIR_ ) dqmStore_->removeElement( EBLowInterestZsFIR_->getName() );
00373 EBLowInterestZsFIR_ = 0;
00374
00375 }
00376
00377 init_ = false;
00378
00379 }
00380
00381 void EBSelectiveReadoutTask::endJob(void){
00382
00383 edm::LogInfo("EBSelectiveReadoutTask") << "analyzed " << ievt_ << " events";
00384
00385 if ( enableCleanup_ ) this->cleanup();
00386
00387 }
00388
00389 void EBSelectiveReadoutTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00390
00391 if ( ! init_ ) this->setup();
00392
00393 ievt_++;
00394
00395 edm::Handle<FEDRawDataCollection> raw;
00396 if ( e.getByLabel(FEDRawDataCollection_, raw) ) {
00397
00398 for ( int iDcc = 0; iDcc < nEBDcc; ++iDcc ) {
00399
00400 EBDccEventSize_->Fill(iDcc+1, ((double)raw->FEDData(610+iDcc).size())/kByte );
00401 EBDccEventSizeMap_->Fill(iDcc+1, ((double)raw->FEDData(610+iDcc).size())/kByte);
00402
00403 }
00404
00405 } else {
00406 edm::LogWarning("EBSelectiveReadoutTask") << FEDRawDataCollection_ << " not available";
00407 }
00408
00409
00410 int nFRO, nCompleteZS, nDroppedFRO;
00411 nFRO = 0;
00412 nCompleteZS = 0;
00413 nDroppedFRO = 0;
00414 edm::Handle<EBSrFlagCollection> ebSrFlags;
00415 if ( e.getByLabel(EBSRFlagCollection_,ebSrFlags) ) {
00416
00417
00418 double aLowInterest=0;
00419 double aHighInterest=0;
00420 double aAnyInterest=0;
00421
00422 edm::Handle<EBDigiCollection> ebDigis;
00423 if ( e.getByLabel(EBDigiCollection_ , ebDigis) ) {
00424
00425 anaDigiInit();
00426
00427
00428 edm::ESHandle<EcalChannelStatus> pChannelStatus;
00429 c.get<EcalChannelStatusRcd>().get(pChannelStatus);
00430 const EcalChannelStatus* chStatus = pChannelStatus.product();
00431
00432 for (unsigned int digis=0; digis<ebDigis->size(); ++digis){
00433 EBDataFrame ebdf = (*ebDigis)[digis];
00434 EBDetId id = ebdf.id();
00435 EcalChannelStatusMap::const_iterator chit;
00436 chit = chStatus->getMap().find(id.rawId());
00437 uint16_t statusCode = 0;
00438 if( chit != chStatus->getMap().end() ) {
00439 EcalChannelStatusCode ch_code = (*chit);
00440 statusCode = ch_code.getStatusCode();
00441 }
00442 anaDigi(ebdf, *ebSrFlags, statusCode);
00443 }
00444
00445
00446 aLowInterest = nEbLI_*bytesPerCrystal/kByte;
00447 EBLowInterestPayload_->Fill(aLowInterest);
00448
00449
00450 aHighInterest = nEbHI_*bytesPerCrystal/kByte;
00451 EBHighInterestPayload_->Fill(aHighInterest);
00452
00453
00454 aAnyInterest = getEbEventSize(nEb_)/kByte;
00455 EBEventSize_->Fill(aAnyInterest);
00456
00457
00458 for(int ietindex = 0; ietindex < 34; ietindex++ ) {
00459 for(int iptindex = 0; iptindex < 72; iptindex++ ) {
00460
00461 float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
00462 float xipt = iptindex + 0.5;
00463
00464 double towerSize = nCryTower[iptindex][ietindex] * bytesPerCrystal;
00465 EBTowerSize_->Fill(xipt, xiet, towerSize);
00466
00467 }
00468 }
00469 } else {
00470 edm::LogWarning("EBSelectiveReadoutTask") << EBDigiCollection_ << " not available";
00471 }
00472
00473
00474 std::map< int, std::vector<short> > towersStatus;
00475 edm::Handle<EcalRawDataCollection> dcchs;
00476
00477 if( e.getByLabel(FEDRawDataCollection_, dcchs) ) {
00478 for ( EcalRawDataCollection::const_iterator dcchItr = dcchs->begin(); dcchItr != dcchs->end(); ++dcchItr ) {
00479 if ( Numbers::subDet( *dcchItr ) != EcalBarrel ) continue;
00480 int ism = Numbers::iSM( *dcchItr, EcalBarrel );
00481 towersStatus.insert(std::make_pair(ism, dcchItr->getFEStatus()));
00482 }
00483 }
00484
00485 for ( EBSrFlagCollection::const_iterator it = ebSrFlags->begin(); it != ebSrFlags->end(); ++it ) {
00486
00487 EcalTrigTowerDetId id = it->id();
00488
00489 if ( Numbers::subDet( id ) != EcalBarrel ) continue;
00490
00491 int iet = id.ieta();
00492 int ietindex = (iet>0) ? iet - 1 : 16 + std::abs(iet);
00493
00494
00495 int ipt = id.iphi() + 2;
00496 if ( ipt > 72 ) ipt = ipt - 72;
00497 int iptindex = ipt - 1;
00498 int ism = Numbers::iSM( id );
00499 int itt = Numbers::iTT( id );
00500
00501 nEvtAnyReadout[iptindex][ietindex]++;
00502
00503 int flag = it->value() & ~EcalSrFlag::SRF_FORCED_MASK;
00504
00505 int status=0;
00506 if( towersStatus[ism].size() > 0 ) status = (towersStatus[ism])[itt];
00507
00508 if(flag == EcalSrFlag::SRF_FULL) {
00509 nEvtFullReadout[iptindex][ietindex]++;
00510 nFRO++;
00511 if(nPerRu_[ism-1][itt-1] == 0) {
00512 if(status != 1) nEvtDroppedReadoutIfFR[iptindex][ietindex]++;
00513 nDroppedFRO++;
00514 }
00515 }
00516
00517 if(flag == EcalSrFlag::SRF_ZS1) nEvtZS1Readout[iptindex][ietindex]++;
00518
00519 if(it->value() & EcalSrFlag::SRF_FORCED_MASK) nEvtRUForced[iptindex][ietindex]++;
00520
00521 if(flag == EcalSrFlag::SRF_ZS1 || flag == EcalSrFlag::SRF_ZS2) {
00522 nEvtZSReadout[iptindex][ietindex]++;
00523 if(nPerRu_[ism-1][itt-1] == getCrystalCount()) {
00524 if(status != 1) nEvtCompleteReadoutIfZS[iptindex][ietindex]++;
00525 nCompleteZS++;
00526 }
00527 }
00528
00529 }
00530 } else {
00531 edm::LogWarning("EBSelectiveReadoutTask") << EBSRFlagCollection_ << " not available";
00532 }
00533
00534 for(int ietindex = 0; ietindex < 34; ietindex++ ) {
00535 for(int iptindex = 0; iptindex < 72; iptindex++ ) {
00536
00537 if(nEvtAnyReadout[iptindex][ietindex]) {
00538
00539 float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
00540 float xipt = iptindex + 0.5;
00541
00542 float fraction = float(nEvtFullReadout[iptindex][ietindex]) / float(nEvtAnyReadout[iptindex][ietindex]);
00543 float error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
00544
00545 TH2F *h2d = EBFullReadoutSRFlagMap_->getTH2F();
00546
00547 int binet=0, binpt=0;
00548
00549 if ( h2d ) {
00550 binpt = h2d->GetXaxis()->FindBin(xipt);
00551 binet = h2d->GetYaxis()->FindBin(xiet);
00552 }
00553
00554 EBFullReadoutSRFlagMap_->setBinContent(binpt, binet, fraction);
00555 EBFullReadoutSRFlagMap_->setBinError(binpt, binet, error);
00556
00557
00558 fraction = float(nEvtZS1Readout[iptindex][ietindex]) / float(nEvtAnyReadout[iptindex][ietindex]);
00559 error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
00560
00561 h2d = EBZeroSuppression1SRFlagMap_->getTH2F();
00562
00563 if ( h2d ) {
00564 binpt = h2d->GetXaxis()->FindBin(xipt);
00565 binet = h2d->GetYaxis()->FindBin(xiet);
00566 }
00567
00568 EBZeroSuppression1SRFlagMap_->setBinContent(binpt, binet, fraction);
00569 EBZeroSuppression1SRFlagMap_->setBinError(binpt, binet, error);
00570
00571
00572 fraction = float(nEvtRUForced[iptindex][ietindex]) / float(nEvtAnyReadout[iptindex][ietindex]);
00573 error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
00574
00575 h2d = EBReadoutUnitForcedBitMap_->getTH2F();
00576
00577 if ( h2d ) {
00578 binpt = h2d->GetXaxis()->FindBin(xipt);
00579 binet = h2d->GetYaxis()->FindBin(xiet);
00580 }
00581
00582 EBReadoutUnitForcedBitMap_->setBinContent(binpt, binet, fraction);
00583 EBReadoutUnitForcedBitMap_->setBinError(binpt, binet, error);
00584
00585 if( nEvtZSReadout[iptindex][ietindex] ) {
00586 fraction = float(nEvtCompleteReadoutIfZS[iptindex][ietindex]) / float(nEvtZSReadout[iptindex][ietindex]);
00587 error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
00588
00589 h2d = EBCompleteZSMap_->getTH2F();
00590
00591 if ( h2d ) {
00592 binpt = h2d->GetXaxis()->FindBin(xipt);
00593 binet = h2d->GetYaxis()->FindBin(xiet);
00594 }
00595
00596 EBCompleteZSMap_->setBinContent(binpt, binet, fraction);
00597 EBCompleteZSMap_->setBinError(binpt, binet, error);
00598 }
00599
00600 if( nEvtFullReadout[iptindex][ietindex] ) {
00601 fraction = float(nEvtDroppedReadoutIfFR[iptindex][ietindex]) / float(nEvtFullReadout[iptindex][ietindex]);
00602 error = sqrt(fraction*(1-fraction)/float(nEvtAnyReadout[iptindex][ietindex]));
00603
00604 h2d = EBDroppedFRMap_->getTH2F();
00605
00606 if ( h2d ) {
00607 binpt = h2d->GetXaxis()->FindBin(xipt);
00608 binet = h2d->GetYaxis()->FindBin(xiet);
00609 }
00610
00611 EBDroppedFRMap_->setBinContent(binpt, binet, fraction);
00612 EBDroppedFRMap_->setBinError(binpt, binet, error);
00613 }
00614 }
00615
00616 }
00617 }
00618
00619 EBFullReadoutSRFlagCount_->Fill( nFRO );
00620 EBCompleteZSCount_->Fill( nCompleteZS );
00621 EBDroppedFRCount_->Fill( nDroppedFRO );
00622
00623 edm::Handle<EcalTrigPrimDigiCollection> TPCollection;
00624 if ( e.getByLabel(EcalTrigPrimDigiCollection_, TPCollection) ) {
00625
00626
00627 EcalTrigPrimDigiCollection::const_iterator TPdigi;
00628 for (TPdigi = TPCollection->begin(); TPdigi != TPCollection->end(); ++TPdigi ) {
00629
00630 if ( Numbers::subDet( TPdigi->id() ) != EcalBarrel ) continue;
00631
00632 int iet = TPdigi->id().ieta();
00633 int ietindex = (iet>0) ? iet - 1 : 16 + std::abs(iet);
00634
00635
00636 int ipt = TPdigi->id().iphi() + 2;
00637 if ( ipt > 72 ) ipt = ipt - 72;
00638 int iptindex = ipt - 1;
00639
00640 nEvtAnyInterest[iptindex][ietindex]++;
00641
00642 if ( (TPdigi->ttFlag() & 0x3) == 0 ) nEvtLowInterest[iptindex][ietindex]++;
00643
00644 if ( (TPdigi->ttFlag() & 0x3) == 1 ) nEvtMediumInterest[iptindex][ietindex]++;
00645
00646 if ( (TPdigi->ttFlag() & 0x3) == 3 ) nEvtHighInterest[iptindex][ietindex]++;
00647
00648 EBTTFlags_->Fill( TPdigi->ttFlag() );
00649
00650 float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
00651 float xipt = iptindex + 0.5;
00652
00653 if ( ((TPdigi->ttFlag() & 0x3) == 1 || (TPdigi->ttFlag() & 0x3) == 3)
00654 && nCryTower[iptindex][ietindex] != 25 ) EBTTFMismatch_->Fill(xipt, xiet);
00655
00656 }
00657 } else {
00658 edm::LogWarning("EBSelectiveReadoutTask") << EcalTrigPrimDigiCollection_ << " not available";
00659 }
00660
00661 for(int ietindex = 0; ietindex < 34; ietindex++ ) {
00662 for(int iptindex = 0; iptindex < 72; iptindex++ ) {
00663
00664 if(nEvtAnyInterest[iptindex][ietindex]) {
00665
00666 float xiet = (ietindex < 17) ? ietindex + 0.5 : (16-ietindex) + 0.5;
00667 float xipt = iptindex + 0.5;
00668
00669 float fraction = float(nEvtHighInterest[iptindex][ietindex]) / float(nEvtAnyInterest[iptindex][ietindex]);
00670 float error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[iptindex][ietindex]));
00671
00672 TH2F *h2d = EBHighInterestTriggerTowerFlagMap_->getTH2F();
00673
00674 int binet=0, binpt=0;
00675
00676 if ( h2d ) {
00677 binpt = h2d->GetXaxis()->FindBin(xipt);
00678 binet = h2d->GetYaxis()->FindBin(xiet);
00679 }
00680
00681 EBHighInterestTriggerTowerFlagMap_->setBinContent(binpt, binet, fraction);
00682 EBHighInterestTriggerTowerFlagMap_->setBinError(binpt, binet, error);
00683
00684
00685 fraction = float(nEvtMediumInterest[iptindex][ietindex]) / float(nEvtAnyInterest[iptindex][ietindex]);
00686 error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[iptindex][ietindex]));
00687
00688 h2d = EBMediumInterestTriggerTowerFlagMap_->getTH2F();
00689
00690 if ( h2d ) {
00691 binpt = h2d->GetXaxis()->FindBin(xipt);
00692 binet = h2d->GetYaxis()->FindBin(xiet);
00693 }
00694
00695 EBMediumInterestTriggerTowerFlagMap_->setBinContent(binpt, binet, fraction);
00696 EBMediumInterestTriggerTowerFlagMap_->setBinError(binpt, binet, error);
00697
00698
00699 fraction = float(nEvtLowInterest[iptindex][ietindex]) / float(nEvtAnyInterest[iptindex][ietindex]);
00700 error = sqrt(fraction*(1-fraction)/float(nEvtAnyInterest[iptindex][ietindex]));
00701
00702 h2d = EBLowInterestTriggerTowerFlagMap_->getTH2F();
00703
00704 if ( h2d ) {
00705 binpt = h2d->GetXaxis()->FindBin(xipt);
00706 binet = h2d->GetYaxis()->FindBin(xiet);
00707 }
00708
00709 EBLowInterestTriggerTowerFlagMap_->setBinContent(binpt, binet, fraction);
00710 EBLowInterestTriggerTowerFlagMap_->setBinError(binpt, binet, error);
00711
00712 }
00713
00714 }
00715 }
00716
00717
00718 }
00719
00720 void EBSelectiveReadoutTask::anaDigi(const EBDataFrame& frame, const EBSrFlagCollection& srFlagColl, uint16_t statusCode){
00721
00722 EBDetId id = frame.id();
00723
00724 bool barrel = (id.subdetId()==EcalBarrel);
00725
00726 if(barrel){
00727 ++nEb_;
00728
00729 int ieta = id.ieta();
00730 int iphi = id.iphi();
00731
00732 int iEta0 = iEta2cIndex(ieta);
00733 int iPhi0 = iPhi2cIndex(iphi);
00734 if(!ebRuActive_[iEta0/ebTtEdge][iPhi0/ebTtEdge]){
00735 ++nRuPerDcc_[dccNum(id)-1];
00736 ebRuActive_[iEta0/ebTtEdge][iPhi0/ebTtEdge] = true;
00737 }
00738
00739 EcalTrigTowerDetId towid = id.tower();
00740 int iet = towid.ieta();
00741 int ietindex = (iet>0) ? iet - 1 : 16 + std::abs(iet);
00742
00743
00744 int ipt = towid.iphi() + 2;
00745 if ( ipt > 72 ) ipt = ipt - 72;
00746 int iptindex = ipt - 1;
00747
00748 int ism = Numbers::iSM( id );
00749 int itt = Numbers::iTT( towid );
00750
00751 nCryTower[iptindex][ietindex]++;
00752
00753 EBSrFlagCollection::const_iterator srf = srFlagColl.find(readOutUnitOf(id));
00754
00755 if(srf == srFlagColl.end()){
00756 return;
00757 }
00758
00759 bool highInterest = ((srf->value() & ~EcalSrFlag::SRF_FORCED_MASK)
00760 == EcalSrFlag::SRF_FULL);
00761
00762
00763 int dccZsFIRval = dccZsFIR(frame, firWeights_, firstFIRSample_, 0);
00764
00765 if(highInterest){
00766 ++nEbHI_;
00767
00768 EBHighInterestZsFIR_->Fill( dccZsFIRval );
00769 } else{
00770 ++nEbLI_;
00771
00772 EBLowInterestZsFIR_->Fill( dccZsFIRval );
00773 }
00774 ++nPerDcc_[dccNum(id)-1];
00775 ++nPerRu_[ism-1][itt-1];
00776 }
00777
00778 }
00779
00780 void EBSelectiveReadoutTask::anaDigiInit(){
00781 nEb_ = 0;
00782 nEbLI_ = 0;
00783 nEbHI_ = 0;
00784 bzero(nPerDcc_, sizeof(nPerDcc_));
00785 bzero(nRuPerDcc_, sizeof(nRuPerDcc_));
00786 bzero(ebRuActive_, sizeof(ebRuActive_));
00787
00788 for(int idcc=0; idcc<nECALDcc; idcc++) {
00789 for(int isc=0; isc<nDccChs; isc++) {
00790 nPerRu_[idcc][isc] = 0;
00791 }
00792 }
00793
00794 for(int ietindex = 0; ietindex < 34; ietindex++ ) {
00795 for(int iptindex = 0; iptindex < 72; iptindex++ ) {
00796 nCryTower[iptindex][ietindex] = 0;
00797 }
00798 }
00799
00800 }
00801
00802 EcalTrigTowerDetId
00803 EBSelectiveReadoutTask::readOutUnitOf(const EBDetId& xtalId) const{
00804 return xtalId.tower();
00805 }
00806
00807 unsigned EBSelectiveReadoutTask::dccNum(const DetId& xtalId) const{
00808 int j;
00809 int k;
00810
00811 if ( xtalId.det()!=DetId::Ecal ) {
00812 throw cms::Exception("EBSelectiveReadoutTask") << "Crystal does not belong to ECAL";
00813 }
00814
00815 if(xtalId.subdetId()==EcalBarrel){
00816 EBDetId ebDetId(xtalId);
00817 j = iEta2cIndex(ebDetId.ieta());
00818 k = iPhi2cIndex(ebDetId.iphi());
00819 } else {
00820 throw cms::Exception("EBSelectiveReadoutTask") << "Not ECAL barrel.";
00821 }
00822 int iDcc0 = dccIndex(j,k);
00823 assert(iDcc0>=0 && iDcc0<nECALDcc);
00824 return iDcc0+1;
00825 }
00826
00827 double EBSelectiveReadoutTask::getEbEventSize(double nReadXtals) const{
00828 double ruHeaderPayload = 0.;
00829 const int nEEDcc = 18;
00830 const int firstEbDcc0 = nEEDcc/2;
00831 for (int iDcc0 = firstEbDcc0; iDcc0 < firstEbDcc0 + nEBDcc; ++iDcc0 ) {
00832 ruHeaderPayload += nRuPerDcc_[iDcc0]*8.;
00833 }
00834 return getDccOverhead(EB)*nEBDcc +
00835 nReadXtals*bytesPerCrystal +
00836 ruHeaderPayload;
00837 }
00838
00839 int EBSelectiveReadoutTask::dccPhiIndexOfRU(int i, int j) const {
00840
00841
00842 return j/4;
00843 }
00844
00845 int EBSelectiveReadoutTask::dccIndex(int i, int j) const {
00846
00847 int iEtaSM = i/85;
00848
00849 int iPhiSM = j/20;
00850
00851 return 9+18*iEtaSM+iPhiSM;
00852 }
00853
00854
00855
00856 int
00857 EBSelectiveReadoutTask::dccZsFIR(const EcalDataFrame& frame,
00858 const std::vector<int>& firWeights,
00859 int firstFIRSample,
00860 bool* saturated){
00861 const int nFIRTaps = 6;
00862
00863 const std::vector<int>& w = firWeights;
00864
00865
00866 int acc = 0;
00867 bool gain12saturated = false;
00868 const int gain12 = 0x01;
00869 const int lastFIRSample = firstFIRSample + nFIRTaps - 1;
00870
00871 int iWeight = 0;
00872 for(int iSample=firstFIRSample-1;
00873 iSample<lastFIRSample; ++iSample, ++iWeight){
00874 if(iSample>=0 && iSample < frame.size()){
00875 EcalMGPASample sample(frame[iSample]);
00876 if(sample.gainId()!=gain12) gain12saturated = true;
00877 LogTrace("DccFir") << (iSample>=firstFIRSample?"+":"") << sample.adc()
00878 << "*(" << w[iWeight] << ")";
00879 acc+=sample.adc()*w[iWeight];
00880 } else{
00881 edm::LogWarning("DccFir") << __FILE__ << ":" << __LINE__ <<
00882 ": Not enough samples in data frame or 'ecalDccZs1stSample' module "
00883 "parameter is not valid...";
00884 }
00885 }
00886 LogTrace("DccFir") << "\n";
00887
00888
00889
00890 acc = (acc>=0)?(acc >> 8):-(-acc >> 8);
00891
00892
00893
00894
00895 LogTrace("DccFir") << "acc: " << acc << "\n"
00896 << "saturated: " << (gain12saturated?"yes":"no") << "\n";
00897
00898 if(saturated){
00899 *saturated = gain12saturated;
00900 }
00901
00902 return gain12saturated?std::numeric_limits<int>::max():acc;
00903 }
00904
00905 std::vector<int>
00906 EBSelectiveReadoutTask::getFIRWeights(const std::vector<double>&
00907 normalizedWeights){
00908 const int nFIRTaps = 6;
00909 std::vector<int> firWeights(nFIRTaps, 0);
00910 const static int maxWeight = 0xEFF;
00911 for(unsigned i=0; i < std::min((size_t)nFIRTaps,normalizedWeights.size()); ++i){
00912 firWeights[i] = lround(normalizedWeights[i] * (1<<10));
00913 if(std::abs(firWeights[i])>maxWeight){
00914 firWeights[i] = firWeights[i]<0?-maxWeight:maxWeight;
00915 }
00916 }
00917 return firWeights;
00918 }
00919
00920 void
00921 EBSelectiveReadoutTask::configFirWeights(std::vector<double> weightsForZsFIR){
00922 bool notNormalized = false;
00923 bool notInt = false;
00924 for(unsigned i=0; i < weightsForZsFIR.size(); ++i){
00925 if(weightsForZsFIR[i] > 1.) notNormalized = true;
00926 if((int)weightsForZsFIR[i]!=weightsForZsFIR[i]) notInt = true;
00927 }
00928 if(notInt && notNormalized){
00929 throw cms::Exception("InvalidParameter")
00930 << "weigtsForZsFIR paramater values are not valid: they "
00931 << "must either be integer and uses the hardware representation "
00932 << "of the weights or less or equal than 1 and used the normalized "
00933 << "representation.";
00934 }
00935 edm::LogInfo log("DccFir");
00936 if(notNormalized){
00937 firWeights_ = std::vector<int>(weightsForZsFIR.size());
00938 for(unsigned i = 0; i< weightsForZsFIR.size(); ++i){
00939 firWeights_[i] = (int)weightsForZsFIR[i];
00940 }
00941 } else{
00942 firWeights_ = getFIRWeights(weightsForZsFIR);
00943 }
00944
00945 log << "Input weights for FIR: ";
00946 for(unsigned i = 0; i < weightsForZsFIR.size(); ++i){
00947 log << weightsForZsFIR[i] << "\t";
00948 }
00949
00950 double s2 = 0.;
00951 log << "\nActual FIR weights: ";
00952 for(unsigned i = 0; i < firWeights_.size(); ++i){
00953 log << firWeights_[i] << "\t";
00954 s2 += firWeights_[i]*firWeights_[i];
00955 }
00956
00957 s2 = sqrt(s2);
00958 log << "\nNormalized FIR weights after hw representation rounding: ";
00959 for(unsigned i = 0; i < firWeights_.size(); ++i){
00960 log << firWeights_[i] / (double)(1<<10) << "\t";
00961 }
00962
00963 log <<"\nFirst FIR sample: " << firstFIRSample_;
00964 }
00965