CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DQM/EcalBarrelMonitorTasks/src/SelectiveReadoutTask.cc

Go to the documentation of this file.
00001 #include "../interface/SelectiveReadoutTask.h"
00002 
00003 #include "FWCore/Framework/interface/ESHandle.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "CondFormats/EcalObjects/interface/EcalSRSettings.h"
00007 #include "CondFormats/DataRecord/interface/EcalSRSettingsRcd.h"
00008 #include "CondFormats/DataRecord/interface/EcalChannelStatusRcd.h"
00009 
00010 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00011 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00012 
00013 #include "DataFormats/EcalDetId/interface/EcalDetIdCollections.h"
00014 
00015 #include "DQM/EcalCommon/interface/FEFlags.h"
00016 #include "DQM/EcalCommon/interface/EcalDQMCommonUtils.h"
00017 
00018 namespace ecaldqm {
00019 
00020   SelectiveReadoutTask::SelectiveReadoutTask(const edm::ParameterSet &_params, const edm::ParameterSet& _paths) :
00021     DQWorkerTask(_params, _paths, "SelectiveReadoutTask"),
00022     useCondDb_(false),
00023     iFirstSample_(0),
00024     channelStatus_(0),
00025     ebSRFs_(0),
00026     eeSRFs_(0),
00027     frFlaggedTowers_(),
00028     zsFlaggedTowers_()
00029   {
00030     collectionMask_ = 
00031       (0x1 << kRun) |
00032       (0x1 << kSource) |
00033       (0x1 << kEcalRawData) |
00034       (0x1 << kEBSrFlag) |
00035       (0x1 << kEESrFlag) |
00036       (0x1 << kEBDigi) |
00037       (0x1 << kEEDigi);
00038 
00039     dependencies_.push_back(std::pair<Collections, Collections>(kEBDigi, kEcalRawData));
00040     dependencies_.push_back(std::pair<Collections, Collections>(kEEDigi, kEcalRawData));
00041 
00042     edm::ParameterSet const& taskParams(_params.getUntrackedParameterSet(name_));
00043 
00044     useCondDb_ = taskParams.getUntrackedParameter<bool>("useCondDb");
00045     iFirstSample_ = taskParams.getUntrackedParameter<int>("DCCZS1stSample");
00046 
00047     std::vector<double> normWeights(taskParams.getUntrackedParameter<std::vector<double> >("ZSFIRWeights", std::vector<double>(0)));
00048     if(normWeights.size()) setFIRWeights_(normWeights);
00049   }
00050 
00051   SelectiveReadoutTask::~SelectiveReadoutTask()
00052   {
00053   }
00054 
00055   void
00056   SelectiveReadoutTask::beginRun(const edm::Run &, const edm::EventSetup &_es)
00057   {
00058     using namespace std;
00059 
00060     if(useCondDb_){
00061       edm::ESHandle<EcalSRSettings> hSr;
00062       _es.get<EcalSRSettingsRcd>().get(hSr);
00063 
00064       vector<vector<float> > weights(hSr->dccNormalizedWeights_);
00065       if(weights.size() == 1){
00066         vector<double> normWeights;
00067         for(vector<float>::iterator it(weights[0].begin()); it != weights[0].end(); it++)
00068           normWeights.push_back(*it);
00069 
00070         setFIRWeights_(normWeights);
00071       }
00072       else edm::LogWarning("EcalDQM") << "SelectiveReadoutTask: DCC weight set is not exactly 1.";
00073     }
00074 
00075     edm::ESHandle<EcalChannelStatus> chSHndl;
00076     _es.get<EcalChannelStatusRcd>().get(chSHndl);
00077     channelStatus_ = chSHndl.product();
00078     if(!channelStatus_)
00079       throw cms::Exception("EventSetup") << "EcalChannelStatusRcd";
00080   }
00081 
00082   void
00083   SelectiveReadoutTask::beginEvent(const edm::Event &, const edm::EventSetup &)
00084   {
00085     for(int iDCC(0); iDCC < 54; iDCC++) feStatus_[iDCC].clear();
00086     frFlaggedTowers_.clear();
00087     zsFlaggedTowers_.clear();
00088   }
00089 
00090   void
00091   SelectiveReadoutTask::runOnSource(const FEDRawDataCollection &_fedRaw)
00092   {
00093     float ebSize(0.), eeSize(0.);
00094 
00095     // DCC event size
00096     for(unsigned iFED(601); iFED <= 654; iFED++){
00097       float size(_fedRaw.FEDData(iFED).size() / 1024.);
00098       MEs_[kDCCSize]->fill(iFED - 600, size);
00099       if(iFED - 601 <= kEEmHigh || iFED - 601 >= kEEpLow) eeSize += size;
00100       else ebSize += size;
00101     }
00102 
00103     MEs_[kEventSize]->fill(unsigned(BinService::kEE) + 1, eeSize / 18.);
00104     MEs_[kEventSize]->fill(unsigned(BinService::kEB) + 1, ebSize / 36.);
00105   }
00106 
00107   void
00108   SelectiveReadoutTask::runOnRawData(const EcalRawDataCollection &_dcchs)
00109   {
00110     for(EcalRawDataCollection::const_iterator dcchItr(_dcchs.begin()); dcchItr != _dcchs.end(); ++dcchItr){
00111       const std::vector<short> &feStatus(dcchItr->getFEStatus());
00112       feStatus_[dcchItr->id() - 1].assign(feStatus.begin(), feStatus.end());
00113     }
00114   }
00115 
00116   void
00117   SelectiveReadoutTask::runOnEBSrFlags(const EBSrFlagCollection &_srfs)
00118   {
00119     float nFR(0.);
00120 
00121     ebSRFs_ = &_srfs;
00122 
00123     for(EBSrFlagCollection::const_iterator srfItr(_srfs.begin()); srfItr != _srfs.end(); ++srfItr)
00124       runOnSrFlag_(srfItr->id(), srfItr->value(), nFR);
00125 
00126     MEs_[kFullReadout]->fill(unsigned(BinService::kEB) + 1, nFR);
00127   }
00128 
00129   void
00130   SelectiveReadoutTask::runOnEESrFlags(const EESrFlagCollection &_srfs)
00131   {
00132     float nFR(0.);
00133 
00134     eeSRFs_ = &_srfs;
00135 
00136     for(EESrFlagCollection::const_iterator srfItr(_srfs.begin()); srfItr != _srfs.end(); ++srfItr)
00137       runOnSrFlag_(srfItr->id(), srfItr->value(), nFR);
00138 
00139     MEs_[kFullReadout]->fill(unsigned(BinService::kEE) + 1, nFR);
00140   }
00141 
00142   void
00143   SelectiveReadoutTask::runOnSrFlag_(const DetId &_id, int _flag, float& nFR)
00144   {
00145     uint32_t rawId(_id.rawId());
00146     int dccid(dccId(_id));
00147     int towerid(towerId(_id));
00148 
00149     MEs_[kFlagCounterMap]->fill(_id);
00150 
00151     short status(feStatus_[dccid - 1].size() ? feStatus_[dccid - 1][towerid - 1] : 0); // check: towerid == feId??
00152  
00153     switch(_flag & ~EcalSrFlag::SRF_FORCED_MASK){
00154     case EcalSrFlag::SRF_FULL:
00155       MEs_[kFullReadoutMap]->fill(_id);
00156       nFR += 1.;
00157       if(status != Disabled) frFlaggedTowers_.insert(rawId); // will be used in Digi loop
00158       break;
00159     case EcalSrFlag::SRF_ZS1:
00160       MEs_[kZS1Map]->fill(_id);
00161       // fallthrough
00162     case EcalSrFlag::SRF_ZS2:
00163       MEs_[kZSMap]->fill(_id);
00164       if(status != Disabled) zsFlaggedTowers_.insert(rawId);
00165       break;
00166     default:
00167       break;
00168     }
00169 
00170     if(_flag & EcalSrFlag::SRF_FORCED_MASK)
00171       MEs_[kRUForcedMap]->fill(_id);
00172   }
00173   
00174   void
00175   SelectiveReadoutTask::runOnDigis(const EcalDigiCollection &_digis, Collections _collection)
00176   {
00177     using namespace std;
00178 
00179     map<uint32_t, pair<int, int> > flagAndSizeMap;
00180     map<uint32_t, pair<int, int> >::iterator fasItr;
00181 
00182     int nHighInt(0), nLowInt(0); // one or two entries will be empty
00183 
00184     for(EcalDigiCollection::const_iterator digiItr(_digis.begin()); digiItr != _digis.end(); ++digiItr){
00185 
00186       DetId id(digiItr->id());
00187 
00188       pair<int, int> *flagAndSize(0);
00189 
00190       if(_collection == kEBDigi){
00191         EcalTrigTowerDetId ttid(EBDetId(id).tower());
00192         uint32_t rawId(ttid.rawId());
00193 
00194         fasItr = flagAndSizeMap.find(rawId);
00195 
00196         if(fasItr == flagAndSizeMap.end()){
00197           flagAndSize = &(flagAndSizeMap[rawId]);
00198 
00199           EBSrFlagCollection::const_iterator srItr(ebSRFs_->find(ttid));
00200           if(srItr != ebSRFs_->end()) flagAndSize->first = srItr->value();
00201           else flagAndSize->first = -1;
00202         }else{
00203           flagAndSize = &(fasItr->second);
00204         }
00205       }else{
00206         EcalScDetId scid(EEDetId(id).sc());
00207         uint32_t rawId(scid.rawId());
00208 
00209         fasItr = flagAndSizeMap.find(rawId);
00210 
00211         if(fasItr == flagAndSizeMap.end()){
00212           flagAndSize = &(flagAndSizeMap[rawId]);
00213 
00214           EESrFlagCollection::const_iterator srItr(eeSRFs_->find(scid));
00215           if(srItr != eeSRFs_->end()) flagAndSize->first = srItr->value();
00216           else flagAndSize->first = -1;
00217         }else{
00218           flagAndSize = &(fasItr->second);
00219         }
00220       }
00221 
00222       if(flagAndSize->first < 0) continue;
00223 
00224       flagAndSize->second += 1;
00225 
00226       // SR filter output calculation
00227 
00228       EcalDataFrame frame(*digiItr);
00229 
00230       int ZSFIRValue(0); // output
00231 
00232       bool gain12saturated(false);
00233       const int gain12(0x01);
00234 
00235       for(int iWeight(0); iWeight < nFIRTaps; ++iWeight){
00236 
00237         int iSample(iFirstSample_ + iWeight - 1);
00238 
00239         if(iSample >= 0 && iSample < frame.size()){
00240           EcalMGPASample sample(frame[iSample]);
00241           if(sample.gainId() != gain12){
00242             gain12saturated = true;
00243             break;
00244           }
00245           ZSFIRValue += sample.adc() * ZSFIRWeights_[iWeight];
00246         }else{
00247           edm::LogWarning("EcalDQM") << "SelectiveReadoutTask: Not enough samples in data frame or 'ecalDccZs1stSample' module parameter is not valid";
00248         }
00249 
00250       }
00251 
00252       if(gain12saturated) ZSFIRValue = std::numeric_limits<int>::max();
00253       else ZSFIRValue /= (0x1 << 8); //discards the 8 LSBs
00254 
00255       //ZS passed if weighted sum above ZS threshold or if
00256       //one sample has a lower gain than gain 12 (that is gain 12 output
00257       //is saturated)
00258 
00259       bool highInterest((flagAndSize->first & ~EcalSrFlag::SRF_FORCED_MASK) == EcalSrFlag::SRF_FULL);
00260 
00261       if(highInterest){
00262         MEs_[kHighIntOutput]->fill(id, ZSFIRValue);
00263         nHighInt += 1;
00264       }else{
00265         MEs_[kLowIntOutput]->fill(id, ZSFIRValue);
00266         nLowInt += 1;
00267       }
00268     }
00269 
00270     unsigned iSubdet(_collection == kEBDigi ? BinService::kEB : BinService::kEE);
00271     float denom(_collection == kEBDigi ? 36. : 18.);
00272 
00273     float highIntPayload(nHighInt * bytesPerCrystal / 1024. / denom);
00274     MEs_[kHighIntPayload]->fill(iSubdet + 1, highIntPayload);
00275 
00276     float lowIntPayload(nLowInt * bytesPerCrystal / 1024. / denom);
00277     MEs_[kLowIntPayload]->fill(iSubdet + 1, lowIntPayload);
00278 
00279     // Check for "ZS-flagged but readout" and "FR-flagged but dropped" towers
00280 
00281     float nZSFullReadout(0.);
00282     for(unsigned iTower(0); iTower < EcalTrigTowerDetId::kEBTotalTowers + EcalScDetId::kSizeForDenseIndexing; iTower++){
00283       DetId id;
00284       if(iTower < EcalTrigTowerDetId::kEBTotalTowers) id = EcalTrigTowerDetId::detIdFromDenseIndex(iTower);
00285       else id = EcalScDetId::unhashIndex(iTower - EcalTrigTowerDetId::kEBTotalTowers);
00286 
00287       fasItr = flagAndSizeMap.find(id.rawId());
00288 
00289       float towerSize(0.);
00290       if(fasItr != flagAndSizeMap.end()) towerSize = fasItr->second.second * bytesPerCrystal;
00291 
00292       MEs_[kTowerSize]->fill(id, towerSize);
00293 
00294       if(fasItr == flagAndSizeMap.end() || fasItr->second.first < 0) continue; // not read out || no flag set
00295 
00296       bool ruFullyReadout(unsigned(fasItr->second.second) == getElectronicsMap()->dccTowerConstituents(dccId(id), towerId(id)).size());
00297 
00298       if(ruFullyReadout && zsFlaggedTowers_.find(id.rawId()) != zsFlaggedTowers_.end()){
00299         MEs_[kZSFullReadoutMap]->fill(id);
00300         nZSFullReadout += 1.;
00301       }
00302 
00303       // we will later use the list of FR flagged towers that do not have data
00304       // if the tower is in flagAndSizeMap then there is data; remove it from the list
00305       if(frFlaggedTowers_.find(id.rawId()) != frFlaggedTowers_.end()) frFlaggedTowers_.erase(id.rawId());
00306     }
00307 
00308     MEs_[kZSFullReadout]->fill(iSubdet + 1, nZSFullReadout);
00309 
00310     float nFRDropped(0.);
00311 
00312     for(set<uint32_t>::iterator frItr(frFlaggedTowers_.begin()); frItr != frFlaggedTowers_.end(); ++frItr){
00313       DetId id(*frItr);
00314 
00315       MEs_[kFRDroppedMap]->fill(id);
00316       nFRDropped += 1.;
00317     }
00318 
00319     MEs_[kFRDropped]->fill(iSubdet + 1, nFRDropped);
00320 
00321   }
00322 
00323   void
00324   SelectiveReadoutTask::setFIRWeights_(const std::vector<double> &_normWeights)
00325   {
00326     if(_normWeights.size() < nFIRTaps)
00327       throw cms::Exception("InvalidConfiguration") << "weightsForZsFIR" << std::endl;
00328 
00329     bool notNormalized(false), notInt(false);
00330     for(std::vector<double>::const_iterator it(_normWeights.begin()); it != _normWeights.end(); ++it){
00331       if(*it > 1.) notNormalized = true;
00332       if((int)(*it) != *it) notInt = true;
00333     }
00334     if(notInt && notNormalized){
00335       throw cms::Exception("InvalidConfiguration")
00336         << "weigtsForZsFIR paramater values are not valid: they "
00337         << "must either be integer and uses the hardware representation "
00338         << "of the weights or less or equal than 1 and used the normalized "
00339         << "representation.";
00340     }
00341 
00342     ZSFIRWeights_.clear();
00343     ZSFIRWeights_.resize(_normWeights.size());
00344 
00345     if(notNormalized){
00346       for(unsigned i(0); i< ZSFIRWeights_.size(); ++i)
00347         ZSFIRWeights_[i] = (int)_normWeights[i];
00348     }else{
00349       const unsigned maxWeight(0xEFF); //weights coded on 11+1 signed bits
00350       for(unsigned i(0); i < ZSFIRWeights_.size(); ++i){
00351         ZSFIRWeights_[i] = lround(_normWeights[i] * (1<<10));
00352         if(abs(ZSFIRWeights_[i]) > (int)maxWeight) //overflow
00353           ZSFIRWeights_[i] = ZSFIRWeights_[i] < 0 ? -maxWeight : maxWeight;
00354       }
00355     }
00356   }
00357 
00358   /*static*/
00359   void
00360   SelectiveReadoutTask::setMEData(std::vector<MEData>& _data)
00361   {
00362     BinService::AxisSpecs axis;
00363 
00364     axis.low = 0.;
00365     axis.high = 50.;
00366     _data[kTowerSize] = MEData("TowerSize", BinService::kEcal2P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TPROFILE2D, 0, 0, &axis);
00367 
00368     axis.title = "event size (kB)";
00369     axis.nbins = 78; // 10 zero-bins + 68
00370     axis.edges = new double[79];
00371     float fullTTSize(0.608);
00372     for(int i(0); i <= 10; i++) axis.edges[i] = fullTTSize / 10. * i;
00373     for(int i(11); i < 79; i++) axis.edges[i] = fullTTSize * (i - 10);
00374     _data[kDCCSize] = MEData("DCCSize", BinService::kEcal2P, BinService::kDCC, MonitorElement::DQM_KIND_TH2F, 0, &axis);
00375     delete [] axis.edges;
00376     axis.edges = 0;
00377 
00378     axis.nbins = 100;
00379     axis.low = 0.;
00380     axis.high = 3.;
00381     axis.title = "event size (kB)";
00382     _data[kEventSize] = MEData("EventSize", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00383     _data[kFlagCounterMap] = MEData("FlagCounterMap", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00384     _data[kRUForcedMap] = MEData("RUForcedMap", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00385 
00386     axis.nbins = 100;
00387     axis.low = 0.;
00388     axis.high = 200.;
00389     axis.title = "number of towers";
00390     _data[kFullReadout] = MEData("FullReadout", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00391     _data[kFullReadoutMap] = MEData("FullReadoutMap", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00392     _data[kZS1Map] = MEData("ZS1Map", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00393     _data[kZSMap] = MEData("ZSMap", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00394 
00395     axis.nbins = 20;
00396     axis.low = 0.;
00397     axis.high = 20.;
00398     axis.title = "number of towers";
00399     _data[kZSFullReadout] = MEData("ZSFullReadout", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00400     _data[kZSFullReadoutMap] = MEData("ZSFullReadoutMap", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00401     _data[kFRDropped] = MEData("FRDropped", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00402     _data[kFRDroppedMap] = MEData("FRDroppedMap", BinService::kEcal3P, BinService::kSuperCrystal, MonitorElement::DQM_KIND_TH2F);
00403 
00404     axis.nbins = 100;
00405     axis.low = 0.;
00406     axis.high = 3.;
00407     axis.title = "event size (kB)";
00408     _data[kHighIntPayload] = MEData("HighIntPayload", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00409     _data[kLowIntPayload] = MEData("LowIntPayload", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00410 
00411     axis.nbins = 100;
00412     axis.low = -60.;
00413     axis.high = 60.;
00414     axis.title = "ADC counts*4";
00415     _data[kHighIntOutput] = MEData("HighIntOutput", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00416     _data[kLowIntOutput] = MEData("LowIntOutput", BinService::kEcal2P, BinService::kUser, MonitorElement::DQM_KIND_TH1F, &axis);
00417   }
00418 
00419   DEFINE_ECALDQM_WORKER(SelectiveReadoutTask);
00420 }
00421 
00422