Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <iostream>
00011 #include <vector>
00012
00013 #include "FWCore/ServiceRegistry/interface/Service.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017
00018 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00019
00020 #include "CondFormats/EcalObjects/interface/EcalDAQTowerStatus.h"
00021 #include "CondFormats/DataRecord/interface/EcalDAQTowerStatusRcd.h"
00022
00023 #include "DQMServices/Core/interface/MonitorElement.h"
00024 #include "DQMServices/Core/interface/DQMStore.h"
00025
00026 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00027
00028 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
00029
00030 #include "DQM/EcalCommon/interface/Numbers.h"
00031
00032 #include "DQM/EcalEndcapMonitorTasks/interface/EEDaqInfoTask.h"
00033
00034 EEDaqInfoTask::EEDaqInfoTask(const edm::ParameterSet& ps) {
00035
00036 dqmStore_ = edm::Service<DQMStore>().operator->();
00037
00038 prefixME_ = ps.getUntrackedParameter<std::string>("prefixME", "");
00039
00040 enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup", false);
00041
00042 mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
00043
00044 meEEDaqFraction_ = 0;
00045 meEEDaqActiveMap_ = 0;
00046 for (int i = 0; i < 18; i++) {
00047 meEEDaqActive_[i] = 0;
00048 }
00049
00050 }
00051
00052 EEDaqInfoTask::~EEDaqInfoTask() {
00053
00054 }
00055
00056 void EEDaqInfoTask::beginJob(void){
00057
00058 char histo[200];
00059
00060 if ( dqmStore_ ) {
00061
00062 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00063
00064 sprintf(histo, "DAQSummary");
00065 meEEDaqFraction_ = dqmStore_->bookFloat(histo);
00066 meEEDaqFraction_->Fill(0.0);
00067
00068 sprintf(histo, "DAQSummaryMap");
00069 meEEDaqActiveMap_ = dqmStore_->book2D(histo,histo, 40, 0., 200., 20, 0., 100.);
00070 meEEDaqActiveMap_->setAxisTitle("ix / ix+100", 1);
00071 meEEDaqActiveMap_->setAxisTitle("iy", 2);
00072
00073 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
00074
00075 for (int i = 0; i < 18; i++) {
00076 sprintf(histo, "EcalEndcap_%s", Numbers::sEE(i+1).c_str());
00077 meEEDaqActive_[i] = dqmStore_->bookFloat(histo);
00078 meEEDaqActive_[i]->Fill(0.0);
00079 }
00080
00081 }
00082
00083 }
00084
00085 void EEDaqInfoTask::endJob(void) {
00086
00087 if ( enableCleanup_ ) this->cleanup();
00088
00089 }
00090
00091 void EEDaqInfoTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const edm::EventSetup& iSetup){
00092
00093
00094 for ( int itx = 0; itx < 40; itx++ ) {
00095 for ( int ity = 0; ity < 20; ity++ ) {
00096 readyLumi[itx][ity] = 1;
00097 }
00098 }
00099
00100 if ( !iSetup.find( edm::eventsetup::EventSetupRecordKey::makeKey<EcalDAQTowerStatusRcd>() ) ) {
00101 edm::LogWarning("EEDaqInfoTask") << "EcalDAQTowerStatus record not found";
00102 return;
00103 }
00104
00105 edm::ESHandle<EcalDAQTowerStatus> pDAQStatus;
00106 iSetup.get<EcalDAQTowerStatusRcd>().get(pDAQStatus);
00107 if ( !pDAQStatus.isValid() ) {
00108 edm::LogWarning("EEDaqInfoTask") << "EcalDAQTowerStatus record not valid";
00109 return;
00110 }
00111 const EcalDAQTowerStatus* daqStatus = pDAQStatus.product();
00112
00113 edm::ESHandle< EcalElectronicsMapping > pElecMapping;
00114 iSetup.get< EcalMappingRcd >().get(pElecMapping);
00115 if( !pElecMapping.isValid() ) {
00116 edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00117 return;
00118 }
00119 const EcalElectronicsMapping *map = pElecMapping.product();
00120
00121 std::vector<DetId> crystals;
00122 std::vector<EcalScDetId> scs;
00123
00124 for(unsigned i=0 ; i<sizeof(DccId_)/sizeof(int) ; i++){
00125 for(int t=1 ; t<=nTowerMax_ ; t++){
00126
00127 crystals = map->dccTowerConstituents(DccId_[i], t);
00128 if(!crystals.size()) continue;
00129
00130 scs = map->getEcalScDetId(DccId_[i], t, false);
00131
00132 for(unsigned u=0 ; u<scs.size() ; u++){
00133
00134 uint16_t dbStatus = 0;
00135 EcalDAQTowerStatus::const_iterator daqStatusIt = daqStatus->find( scs[u].rawId() );
00136 if ( daqStatusIt != daqStatus->end() ) dbStatus = daqStatusIt->getStatusCode();
00137
00138 if ( dbStatus > 0 ) {
00139 int jx = scs[u].ix() - 1 + (scs[u].zside()<0 ? 0 : 20);
00140 int jy = scs[u].iy() - 1;
00141 readyRun[jx][jy] = 0;
00142 readyLumi[jx][jy] = 0;
00143 }
00144 }
00145 }
00146 }
00147
00148 }
00149
00150 void EEDaqInfoTask::endLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const edm::EventSetup& iSetup) {
00151
00152 edm::ESHandle< EcalElectronicsMapping > handle;
00153 iSetup.get< EcalMappingRcd >().get(handle);
00154 const EcalElectronicsMapping *map = handle.product();
00155 if( ! map ) edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00156 else this->fillMonitorElements(readyLumi, map);
00157
00158 }
00159
00160 void EEDaqInfoTask::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00161
00162 if ( ! mergeRuns_ ) this->reset();
00163
00164 for ( int itx = 0; itx < 40; itx++ ) {
00165 for ( int ity = 0; ity < 20; ity++ ) {
00166 readyRun[itx][ity] = 1;
00167 }
00168 }
00169
00170 }
00171
00172 void EEDaqInfoTask::endRun(const edm::Run& r, const edm::EventSetup& c) {
00173
00174 edm::ESHandle< EcalElectronicsMapping > handle;
00175 c.get< EcalMappingRcd >().get(handle);
00176 const EcalElectronicsMapping *map = handle.product();
00177 if( ! map ) edm::LogWarning("EEDaqInfoTask") << "EcalElectronicsMapping not available";
00178 else this->fillMonitorElements(readyRun, map);
00179
00180 }
00181
00182 void EEDaqInfoTask::reset(void) {
00183
00184 if ( meEEDaqFraction_ ) meEEDaqFraction_->Reset();
00185
00186 for (int i = 0; i < 18; i++) {
00187 if ( meEEDaqActive_[i] ) meEEDaqActive_[i]->Reset();
00188 }
00189
00190 if ( meEEDaqActiveMap_ ) meEEDaqActiveMap_->Reset();
00191
00192 }
00193
00194
00195 void EEDaqInfoTask::cleanup(void){
00196
00197 if ( dqmStore_ ) {
00198
00199 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
00200
00201 if ( meEEDaqFraction_ ) dqmStore_->removeElement( meEEDaqFraction_->getName() );
00202
00203 if ( meEEDaqActiveMap_ ) dqmStore_->removeElement( meEEDaqActiveMap_->getName() );
00204
00205 dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
00206
00207 for (int i = 0; i < 18; i++) {
00208 if ( meEEDaqActive_[i] ) dqmStore_->removeElement( meEEDaqActive_[i]->getName() );
00209 }
00210
00211 }
00212
00213 }
00214
00215 void EEDaqInfoTask::fillMonitorElements(int ready[40][20], const EcalElectronicsMapping *map) {
00216
00217 float readySum[18];
00218 int nValidChannels[18];
00219 for ( int ism = 0; ism < 18; ism++ ) {
00220 readySum[ism] = 0;
00221 nValidChannels[ism] = 0;
00222 }
00223 float readySumTot = 0.;
00224 int nValidChannelsTot = 0;
00225
00226 if(meEEDaqActiveMap_){
00227 for(int ix=1 ; ix<=meEEDaqActiveMap_->getNbinsX() ; ix++){
00228 for(int iy=1 ; iy<=meEEDaqActiveMap_->getNbinsY() ; iy++){
00229 meEEDaqActiveMap_->setBinContent( ix, iy, -1.0 );
00230 }
00231 }
00232 }
00233
00234 std::vector<DetId> crystals;
00235 std::vector<EcalScDetId> scs;
00236
00237 for ( unsigned iDcc = 0; iDcc < sizeof(DccId_)/sizeof(int); iDcc++) {
00238 for ( int t = 1; t<=nTowerMax_; t++ ) {
00239
00240 crystals = map->dccTowerConstituents(DccId_[iDcc], t);
00241 if(!crystals.size()) continue;
00242
00243 scs = map->getEcalScDetId(DccId_[iDcc], t, false);
00244
00245 for(unsigned u=0 ; u<scs.size() ; u++){
00246
00247 int jx = scs[u].ix() - 1 + (scs[u].zside()<0 ? 0 : 20);
00248 int jy = scs[u].iy() - 1;
00249
00250 if(meEEDaqActiveMap_) meEEDaqActiveMap_->setBinContent( jx+1, jy+1, ready[jx][jy] );
00251
00252 int ncrystals = 0;
00253
00254 for(std::vector<DetId>::const_iterator it=crystals.begin() ; it!=crystals.end() ; ++it){
00255 EEDetId id(*it);
00256 if( id.zside() == scs[u].zside() && (id.ix()-1)/5+1 == scs[u].ix() && (id.iy()-1)/5+1 == scs[u].iy() ) ncrystals++;
00257 }
00258
00259 if(ready[jx][jy]) {
00260 readySum[iDcc] += ncrystals;
00261 readySumTot += ncrystals;
00262 }
00263
00264 nValidChannels[iDcc] += ncrystals;
00265 nValidChannelsTot += ncrystals;
00266
00267 }
00268 }
00269 if( meEEDaqActive_[iDcc] ) meEEDaqActive_[iDcc]->Fill( readySum[iDcc]/float(nValidChannels[iDcc]) );
00270 }
00271
00272 if( meEEDaqFraction_ ) meEEDaqFraction_->Fill( readySumTot/float(nValidChannelsTot) );
00273
00274 }
00275
00276 void EEDaqInfoTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00277
00278 }