File indexing completed on 2024-04-06 12:32:33
0001 #include <iostream>
0002 #include <fstream>
0003 #include <vector>
0004 #include <unistd.h>
0005
0006 #include "FWCore/Framework/interface/Run.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013
0014 #include "DQMServices/Core/interface/DQMEDHarvester.h"
0015 #include "DQMServices/Core/interface/DQMStore.h"
0016 #include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
0017 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0018
0019 class HGCalDigiClient : public DQMEDHarvester {
0020 private:
0021 const std::string nameDetector_;
0022 const int verbosity_;
0023 const edm::ESGetToken<HGCalDDDConstants, IdealGeometryRecord> tok_hgcal_;
0024 int layers_;
0025
0026 public:
0027 explicit HGCalDigiClient(const edm::ParameterSet &);
0028 ~HGCalDigiClient() override = default;
0029
0030 void beginRun(const edm::Run &run, const edm::EventSetup &c) override;
0031 void dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) override;
0032 void runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig);
0033 int digisEndjob(const std::vector<MonitorElement *> &hgcalMEs);
0034 };
0035
0036 HGCalDigiClient::HGCalDigiClient(const edm::ParameterSet &iConfig)
0037 : nameDetector_(iConfig.getParameter<std::string>("DetectorName")),
0038 verbosity_(iConfig.getUntrackedParameter<int>("Verbosity", 0)),
0039 tok_hgcal_(esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
0040 edm::ESInputTag{"", nameDetector_})) {}
0041
0042 void HGCalDigiClient::beginRun(const edm::Run &run, const edm::EventSetup &iSetup) {
0043 const HGCalDDDConstants *hgcons = &iSetup.getData(tok_hgcal_);
0044 layers_ = hgcons->layers(true);
0045 }
0046
0047 void HGCalDigiClient::dqmEndJob(DQMStore::IBooker &ib, DQMStore::IGetter &ig) { runClient_(ib, ig); }
0048
0049 void HGCalDigiClient::runClient_(DQMStore::IBooker &ib, DQMStore::IGetter &ig) {
0050 ig.setCurrentFolder("/");
0051 if (verbosity_)
0052 edm::LogVerbatim("HGCalValidation") << "\nrunClient";
0053 std::vector<MonitorElement *> hgcalMEs;
0054 std::vector<std::string> fullDirPath = ig.getSubdirs();
0055
0056 for (unsigned int i = 0; i < fullDirPath.size(); i++) {
0057 if (verbosity_)
0058 edm::LogVerbatim("HGCalValidation") << "\nfullPath: " << fullDirPath.at(i);
0059 ig.setCurrentFolder(fullDirPath.at(i));
0060 std::vector<std::string> fullSubDirPath = ig.getSubdirs();
0061
0062 for (unsigned int j = 0; j < fullSubDirPath.size(); j++) {
0063 if (verbosity_)
0064 edm::LogVerbatim("HGCalValidation") << "fullSubPath: " << fullSubDirPath.at(j);
0065 std::string nameDirectory = "HGCAL/HGCalDigisV/" + nameDetector_;
0066 if (strcmp(fullSubDirPath.at(j).c_str(), nameDirectory.c_str()) == 0) {
0067 hgcalMEs = ig.getContents(fullSubDirPath.at(j));
0068 if (verbosity_)
0069 edm::LogVerbatim("HGCalValidation") << "hgcalMES size : " << hgcalMEs.size();
0070 if (!digisEndjob(hgcalMEs))
0071 edm::LogVerbatim("HGCalValidation") << "\nError in DigisEndjob!";
0072 }
0073 }
0074 }
0075 }
0076
0077 int HGCalDigiClient::digisEndjob(const std::vector<MonitorElement *> &hgcalMEs) {
0078 std::vector<MonitorElement *> charge_;
0079 std::vector<MonitorElement *> DigiOccupancy_XY_;
0080 std::vector<MonitorElement *> ADC_;
0081 std::vector<MonitorElement *> DigiOccupancy_Plus_;
0082 std::vector<MonitorElement *> DigiOccupancy_Minus_;
0083 std::vector<MonitorElement *> MeanDigiOccupancy_Plus_;
0084 std::vector<MonitorElement *> MeanDigiOccupancy_Minus_;
0085 std::ostringstream name;
0086 double nevent;
0087 int nbinsx, nbinsy;
0088
0089 for (int ilayer = 0; ilayer < layers_; ilayer++) {
0090
0091 name.str("");
0092 name << "charge_layer_" << ilayer;
0093 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0094 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
0095 charge_.push_back(hgcalMEs[ih]);
0096 }
0097
0098 nevent = charge_.at(ilayer)->getEntries();
0099 nbinsx = charge_.at(ilayer)->getNbinsX();
0100 for (int i = 1; i <= nbinsx; i++) {
0101 double binValue = charge_.at(ilayer)->getBinContent(i) / nevent;
0102 charge_.at(ilayer)->setBinContent(i, binValue);
0103 }
0104
0105
0106 name.str("");
0107 name << "DigiOccupancy_XY_"
0108 << "layer_" << ilayer;
0109 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0110 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
0111 DigiOccupancy_XY_.push_back(hgcalMEs[ih]);
0112 }
0113
0114
0115 nevent = DigiOccupancy_XY_.at(ilayer)->getEntries();
0116 nbinsx = DigiOccupancy_XY_.at(ilayer)->getNbinsX();
0117 nbinsy = DigiOccupancy_XY_.at(ilayer)->getNbinsY();
0118 for (int i = 1; i <= nbinsx; ++i) {
0119 for (int j = 1; j <= nbinsy; ++j) {
0120 double binValue = DigiOccupancy_XY_.at(ilayer)->getBinContent(i, j) / nevent;
0121 DigiOccupancy_XY_.at(ilayer)->setBinContent(i, j, binValue);
0122 }
0123 }
0124
0125
0126 name.str("");
0127 name << "ADC_layer_" << ilayer;
0128 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0129 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0)
0130 ADC_.push_back(hgcalMEs[ih]);
0131 }
0132
0133
0134 nevent = ADC_.at(ilayer)->getEntries();
0135 nbinsx = ADC_.at(ilayer)->getNbinsX();
0136 for (int i = 1; i <= nbinsx; ++i) {
0137 double binValue = ADC_.at(ilayer)->getBinContent(i) / nevent;
0138 ADC_.at(ilayer)->setBinContent(i, binValue);
0139 }
0140
0141
0142 name.str("");
0143 name << "DigiOccupancy_Plus_layer_" << ilayer;
0144 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0145 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
0146 DigiOccupancy_Plus_.push_back(hgcalMEs[ih]);
0147 }
0148 }
0149
0150 name.str("");
0151 name << "DigiOccupancy_Minus_layer_" << ilayer;
0152 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0153 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
0154 DigiOccupancy_Minus_.push_back(hgcalMEs[ih]);
0155 }
0156 }
0157
0158
0159 nevent = DigiOccupancy_Plus_.at(ilayer)->getEntries();
0160 nbinsx = DigiOccupancy_Plus_.at(ilayer)->getNbinsX();
0161 for (int i = 1; i <= nbinsx; ++i) {
0162 double binValue = DigiOccupancy_Plus_.at(ilayer)->getBinContent(i) / nevent;
0163 DigiOccupancy_Plus_.at(ilayer)->setBinContent(i, binValue);
0164 }
0165
0166 nevent = DigiOccupancy_Minus_.at(ilayer)->getEntries();
0167 nbinsx = DigiOccupancy_Minus_.at(ilayer)->getNbinsX();
0168 for (int i = 1; i <= nbinsx; ++i) {
0169 double binValue = DigiOccupancy_Minus_.at(ilayer)->getBinContent(i) / nevent;
0170 DigiOccupancy_Minus_.at(ilayer)->setBinContent(i, binValue);
0171 }
0172
0173 }
0174
0175 name.str("");
0176 name << "SUMOfDigiOccupancy_Plus";
0177 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0178 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
0179 MeanDigiOccupancy_Plus_.push_back(hgcalMEs[ih]);
0180 unsigned indx = MeanDigiOccupancy_Plus_.size() - 1;
0181 for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
0182 double meanVal = DigiOccupancy_Plus_.at(ilayer)->getMean();
0183 MeanDigiOccupancy_Plus_[indx]->setBinContent(ilayer + 1, meanVal);
0184 }
0185 break;
0186 }
0187 }
0188
0189 name.str("");
0190 name << "SUMOfDigiOccupancy_Plus";
0191 for (unsigned int ih = 0; ih < hgcalMEs.size(); ih++) {
0192 if (strcmp(hgcalMEs[ih]->getName().c_str(), name.str().c_str()) == 0) {
0193 MeanDigiOccupancy_Minus_.push_back(hgcalMEs[ih]);
0194 unsigned indx = MeanDigiOccupancy_Minus_.size() - 1;
0195 for (int ilayer = 0; ilayer < static_cast<int>(layers_); ++ilayer) {
0196 double meanVal = DigiOccupancy_Minus_.at(ilayer)->getMean();
0197 MeanDigiOccupancy_Minus_[indx]->setBinContent(ilayer + 1, meanVal);
0198 }
0199 break;
0200 }
0201 }
0202 return 1;
0203 }
0204
0205 #include "FWCore/Framework/interface/MakerMacros.h"
0206
0207 DEFINE_FWK_MODULE(HGCalDigiClient);