Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:23

0001 #include <iostream>
0002 
0003 #include "FWCore/ServiceRegistry/interface/Service.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 
0011 #include <DataFormats/EcalDetId/interface/ESDetId.h>
0012 
0013 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
0014 #include "CondFormats/RunInfo/interface/RunSummary.h"
0015 #include "CondFormats/RunInfo/interface/RunInfo.h"
0016 
0017 #include "DQMServices/Core/interface/DQMStore.h"
0018 
0019 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0020 
0021 #include "Geometry/EcalMapping/interface/ESElectronicsMapper.h"
0022 
0023 #include "DQM/EcalPreshowerMonitorModule/interface/ESDaqInfoTask.h"
0024 
0025 using namespace cms;
0026 using namespace edm;
0027 using namespace std;
0028 
0029 ESDaqInfoTask::ESDaqInfoTask(const ParameterSet& ps) {
0030   usesResource("DQMStore");
0031   dqmStore_ = Service<DQMStore>().operator->();
0032   runInfoToken_ = esConsumes<edm::Transition::BeginLuminosityBlock>();
0033   prefixME_ = ps.getUntrackedParameter<string>("prefixME", "");
0034 
0035   mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns", false);
0036 
0037   ESFedRangeMin_ = ps.getUntrackedParameter<int>("ESFedRangeMin", 520);
0038   ESFedRangeMax_ = ps.getUntrackedParameter<int>("ESFedRangeMax", 575);
0039 
0040   meESDaqFraction_ = nullptr;
0041   meESDaqActiveMap_ = nullptr;
0042   meESDaqError_ = nullptr;
0043 
0044   for (int i = 0; i < 56; i++) {
0045     meESDaqActive_[i] = nullptr;
0046   }
0047 
0048   if (ps.exists("esMapping")) {
0049     edm::ParameterSet esMap = ps.getParameter<edm::ParameterSet>("esMapping");
0050     es_mapping_ = new ESElectronicsMapper(esMap);
0051   } else {
0052     edm::LogError("ESDaqInfoTask") << "preshower mapping pointer not initialized. Temporary.";
0053     es_mapping_ = nullptr;
0054   }
0055 }
0056 
0057 ESDaqInfoTask::~ESDaqInfoTask() { delete es_mapping_; }
0058 
0059 void ESDaqInfoTask::beginJob(void) {
0060   char histo[200];
0061 
0062   if (dqmStore_) {
0063     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo");
0064 
0065     sprintf(histo, "DAQSummary");
0066     meESDaqFraction_ = dqmStore_->bookFloat(histo);
0067     meESDaqFraction_->Fill(0.0);
0068 
0069     sprintf(histo, "DAQSummaryMap");
0070     meESDaqActiveMap_ = dqmStore_->book2D(histo, histo, 80, 0.5, 80.5, 80, 0.5, 80.5);
0071     meESDaqActiveMap_->setAxisTitle("Si X", 1);
0072     meESDaqActiveMap_->setAxisTitle("Si Y", 2);
0073 
0074     dqmStore_->setCurrentFolder(prefixME_ + "/EventInfo/DAQContents");
0075 
0076     for (int i = 0; i < 56; i++) {
0077       sprintf(histo, "EcalPreshower_%d", ESFedRangeMin_ + i);
0078       meESDaqActive_[i] = dqmStore_->bookFloat(histo);
0079       meESDaqActive_[i]->Fill(0.0);
0080 
0081       ESOnFed_[i] = false;
0082       for (int x = 0; x < 80; x++) {
0083         for (int y = 0; y < 80; y++) {
0084           if (getFEDNumber(x, y) == ESFedRangeMin_ + i) {
0085             ESOnFed_[i] = true;
0086             break;
0087           }
0088         }
0089         if (ESOnFed_[i] == true)
0090           break;
0091       }
0092     }
0093 
0094     dqmStore_->setCurrentFolder(prefixME_ + "/ESIntegrityTask");
0095     sprintf(histo, "DAQError");
0096     meESDaqError_ = dqmStore_->book1D(histo, histo, 56, ESFedRangeMin_ - 0.5, ESFedRangeMax_ + 0.5);
0097     meESDaqError_->setAxisTitle("FedID", 1);
0098   }
0099 }
0100 
0101 void ESDaqInfoTask::endJob(void) {}
0102 
0103 void ESDaqInfoTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiBlock, const edm::EventSetup& iSetup) {
0104   this->reset();
0105 
0106   for (int x = 0; x < 80; ++x) {
0107     for (int y = 0; y < 80; ++y) {
0108       if (getFEDNumber(x, y) > 0)
0109         meESDaqActiveMap_->setBinContent(x + 1, y + 1, 0.0);
0110       else
0111         meESDaqActiveMap_->setBinContent(x + 1, y + 1, -1.0);
0112     }
0113   }
0114 
0115   for (int i = 0; i < 56; i++) {
0116     if (meESDaqError_)
0117       meESDaqError_->setBinContent(i, 0.0);
0118   }
0119 
0120   if (auto runInfoRec = iSetup.tryToGet<RunInfoRcd>()) {
0121     const auto& sumFED = runInfoRec->getHandle(runInfoToken_);
0122 
0123     std::vector<int> FedsInIds = sumFED->m_fed_in;
0124 
0125     float ESFedCount = 0.;
0126 
0127     for (unsigned int fedItr = 0; fedItr < FedsInIds.size(); ++fedItr) {
0128       int fedID = FedsInIds[fedItr];
0129 
0130       if (fedID >= ESFedRangeMin_ && fedID <= ESFedRangeMax_) {
0131         if (ESOnFed_[fedID - ESFedRangeMin_])
0132           ESFedCount++;
0133 
0134         if (meESDaqActive_[fedID - ESFedRangeMin_])
0135           meESDaqActive_[fedID - ESFedRangeMin_]->Fill(1.0);
0136 
0137         if (meESDaqActiveMap_) {
0138           for (int x = 0; x < 80; x++) {
0139             for (int y = 0; y < 80; y++) {
0140               if (fedID == getFEDNumber(x, y))
0141                 meESDaqActiveMap_->setBinContent(x + 1, y + 1, 1.0);
0142             }
0143           }
0144         }
0145 
0146         if (meESDaqFraction_)
0147           meESDaqFraction_->Fill(ESFedCount / 40.);
0148 
0149         if (meESDaqError_) {
0150           for (int i = 0; i < 56; i++) {
0151             if (ESOnFed_[fedID - ESFedRangeMin_])
0152               meESDaqError_->setBinContent(i + 1, 1.0);
0153             else
0154               meESDaqError_->setBinContent(i + 1, 2.0);
0155           }
0156         }
0157       }
0158     }
0159 
0160   } else {
0161     LogWarning("ESDaqInfoTask") << "Cannot find any RunInfoRcd" << endl;
0162   }
0163 }
0164 
0165 void ESDaqInfoTask::endLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) {}
0166 
0167 void ESDaqInfoTask::reset(void) {
0168   if (meESDaqFraction_)
0169     meESDaqFraction_->Reset();
0170 
0171   for (int i = 0; i < 56; i++) {
0172     if (meESDaqActive_[i])
0173       meESDaqActive_[i]->Reset();
0174   }
0175 
0176   if (meESDaqActiveMap_)
0177     meESDaqActiveMap_->Reset();
0178 
0179   if (meESDaqError_)
0180     meESDaqError_->Reset();
0181 }
0182 
0183 void ESDaqInfoTask::analyze(const Event& e, const EventSetup& c) {}
0184 
0185 DEFINE_FWK_MODULE(ESDaqInfoTask);