File indexing completed on 2024-10-25 05:06:28
0001 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0002 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0003 #include "CondFormats/DataRecord/interface/RunSummaryRcd.h"
0004 #include "CondFormats/RunInfo/interface/RunInfo.h"
0005 #include "DataFormats/Histograms/interface/DQMToken.h"
0006 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0007 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0008 #include "DQM/SiStripMonitorClient/interface/SiStripUtility.h"
0009 #include "DQMServices/Core/interface/DQMStore.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/Framework/interface/ESHandle.h"
0012 #include "FWCore/Framework/interface/LuminosityBlock.h"
0013 #include "FWCore/Framework/interface/Run.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/ServiceRegistry/interface/Service.h"
0018 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0019
0020 #include <iostream>
0021 #include <fstream>
0022 #include <string>
0023 #include <vector>
0024 #include <map>
0025
0026 class SiStripDetCabling;
0027
0028 class SiStripCertificationInfo
0029 : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns, edm::one::WatchLuminosityBlocks> {
0030 public:
0031 typedef dqm::harvesting::MonitorElement MonitorElement;
0032 typedef dqm::harvesting::DQMStore DQMStore;
0033
0034 SiStripCertificationInfo(const edm::ParameterSet& ps);
0035
0036 private:
0037 void beginRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
0038 void beginLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& eSetup) override {}
0039 void endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) override;
0040 void endRun(edm::Run const& run, edm::EventSetup const& eSetup) override;
0041 void analyze(edm::Event const&, edm::EventSetup const&) override;
0042
0043 void bookSiStripCertificationMEs(DQMStore& dqm_store);
0044 void resetSiStripCertificationMEs(DQMStore& dqm_store);
0045 void fillSiStripCertificationMEs(DQMStore& dqm_store, edm::EventSetup const& eSetup);
0046
0047 void fillDummySiStripCertification(DQMStore& dqm_store);
0048 void fillSiStripCertificationMEsAtLumi(DQMStore& dqm_store);
0049
0050 struct SubDetMEs {
0051 MonitorElement* det_fractionME;
0052 std::string folder_name;
0053 std::string subdet_tag;
0054 int n_layer;
0055 };
0056
0057 MonitorElement* SiStripCertification{nullptr};
0058 MonitorElement* SiStripCertificationMap{nullptr};
0059 std::map<std::string, SubDetMEs> SubDetMEsMap{};
0060 MonitorElement* SiStripCertificationSummaryMap{nullptr};
0061
0062 bool sistripCertificationBooked_{false};
0063
0064 edm::ESHandle<SiStripDetCabling> detCabling_{};
0065
0066 int nFEDConnected_{};
0067
0068 const edm::ESGetToken<SiStripDetCabling, SiStripDetCablingRcd> detCablingToken_;
0069 const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0070 const edm::ESGetToken<RunInfo, RunInfoRcd> runInfoToken_;
0071 };
0072
0073 SiStripCertificationInfo::SiStripCertificationInfo(edm::ParameterSet const&)
0074 : detCablingToken_(esConsumes<edm::Transition::BeginRun>()),
0075 tTopoToken_(esConsumes<edm::Transition::EndRun>()),
0076 runInfoToken_(esConsumes<edm::Transition::BeginRun>()) {
0077 usesResource("DQMStore");
0078 consumes<DQMToken, edm::InRun>(edm::InputTag("siStripOfflineAnalyser", "DQMGenerationSiStripAnalyserRun"));
0079 consumes<DQMToken, edm::InLumi>(edm::InputTag("siStripOfflineAnalyser", "DQMGenerationSiStripAnalyserLumi"));
0080 }
0081
0082 void SiStripCertificationInfo::beginRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0083 edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo:: Begining of Run";
0084 detCabling_ = &eSetup.getData(detCablingToken_);
0085
0086 constexpr int siStripFedIdMin{FEDNumbering::MINSiStripFEDID};
0087 constexpr int siStripFedIdMax{FEDNumbering::MAXSiStripFEDID};
0088
0089 if (eSetup.tryToGet<RunInfoRcd>()) {
0090 if (auto sumFED = eSetup.getHandle(runInfoToken_)) {
0091 for (auto const fedID : sumFED->m_fed_in) {
0092 if (fedID >= siStripFedIdMin && fedID <= siStripFedIdMax)
0093 ++nFEDConnected_;
0094 }
0095 LogDebug("SiStripDcsInfo") << " SiStripDcsInfo :: Connected FEDs " << nFEDConnected_;
0096 }
0097 }
0098
0099 auto& dqm_store = *edm::Service<DQMStore>{};
0100 bookSiStripCertificationMEs(dqm_store);
0101 fillDummySiStripCertification(dqm_store);
0102 }
0103
0104
0105
0106 void SiStripCertificationInfo::bookSiStripCertificationMEs(DQMStore& dqm_store) {
0107 if (sistripCertificationBooked_)
0108 return;
0109
0110 dqm_store.cd();
0111 std::string strip_dir = "";
0112 SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
0113 if (!strip_dir.empty())
0114 dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
0115 else
0116 dqm_store.setCurrentFolder("SiStrip/EventInfo");
0117
0118 SiStripCertification = dqm_store.bookFloat("CertificationSummary");
0119
0120 std::string hname = "CertificationReportMap";
0121 std::string htitle = "SiStrip Certification for Good Detector Fraction";
0122 SiStripCertificationSummaryMap = dqm_store.book2D(hname, htitle, 6, 0.5, 6.5, 9, 0.5, 9.5);
0123 SiStripCertificationSummaryMap->setAxisTitle("Sub Detector Type", 1);
0124 SiStripCertificationSummaryMap->setAxisTitle("Layer/Disc Number", 2);
0125 int ibin = 0;
0126 for (auto const& pr : SubDetMEsMap) {
0127 ++ibin;
0128 auto const& det = pr.first;
0129 SiStripCertificationSummaryMap->setBinLabel(ibin, det);
0130 }
0131
0132 SubDetMEs local_mes;
0133 std::string tag;
0134 dqm_store.cd();
0135 if (!strip_dir.empty())
0136 dqm_store.setCurrentFolder(strip_dir + "/EventInfo/CertificationContents");
0137 else
0138 dqm_store.setCurrentFolder("SiStrip/EventInfo/CertificationContents");
0139 tag = "TIB";
0140
0141 local_mes.folder_name = "TIB";
0142 local_mes.subdet_tag = "TIB";
0143 local_mes.n_layer = 4;
0144 local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
0145 SubDetMEsMap.emplace(tag, local_mes);
0146
0147 tag = "TOB";
0148 local_mes.folder_name = "TOB";
0149 local_mes.subdet_tag = "TOB";
0150 local_mes.n_layer = 6;
0151 local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
0152 SubDetMEsMap.emplace(tag, local_mes);
0153
0154 tag = "TECF";
0155 local_mes.folder_name = "TEC/PLUS";
0156 local_mes.subdet_tag = "TEC+";
0157 local_mes.n_layer = 9;
0158 local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
0159 SubDetMEsMap.emplace(tag, local_mes);
0160
0161 tag = "TECB";
0162 local_mes.folder_name = "TEC/MINUS";
0163 local_mes.subdet_tag = "TEC-";
0164 local_mes.n_layer = 9;
0165 local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
0166 SubDetMEsMap.emplace(tag, local_mes);
0167
0168 tag = "TIDF";
0169 local_mes.folder_name = "TID/PLUS";
0170 local_mes.subdet_tag = "TID+";
0171 local_mes.n_layer = 3;
0172 local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
0173 SubDetMEsMap.emplace(tag, local_mes);
0174
0175 tag = "TIDB";
0176 local_mes.folder_name = "TID/MINUS";
0177 local_mes.subdet_tag = "TID-";
0178 local_mes.n_layer = 3;
0179 local_mes.det_fractionME = dqm_store.bookFloat("SiStrip_" + tag);
0180 SubDetMEsMap.emplace(tag, local_mes);
0181
0182 dqm_store.cd();
0183 if (!strip_dir.empty())
0184 dqm_store.setCurrentFolder(strip_dir + "/EventInfo");
0185
0186 sistripCertificationBooked_ = true;
0187 dqm_store.cd();
0188 }
0189
0190 void SiStripCertificationInfo::analyze(edm::Event const& event, edm::EventSetup const& eSetup) {}
0191
0192 void SiStripCertificationInfo::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg, edm::EventSetup const& iSetup) {
0193 edm::LogInfo("SiStripDaqInfo") << "SiStripDaqInfo::endLuminosityBlock";
0194
0195 if (nFEDConnected_ > 0) {
0196 auto& dqm_store = *edm::Service<DQMStore>{};
0197 fillSiStripCertificationMEsAtLumi(dqm_store);
0198 }
0199 }
0200
0201 void SiStripCertificationInfo::endRun(edm::Run const& run, edm::EventSetup const& eSetup) {
0202 edm::LogInfo("SiStripCertificationInfo") << "SiStripCertificationInfo:: End Run";
0203
0204 if (nFEDConnected_ > 0) {
0205 auto& dqm_store = *edm::Service<DQMStore>{};
0206 fillSiStripCertificationMEs(dqm_store, eSetup);
0207 }
0208 }
0209
0210
0211
0212
0213 void SiStripCertificationInfo::fillSiStripCertificationMEs(DQMStore& dqm_store, edm::EventSetup const& eSetup) {
0214 if (!sistripCertificationBooked_) {
0215 edm::LogError("SiStripCertificationInfo")
0216 << " SiStripCertificationInfo::fillSiStripCertificationMEs : MEs missing ";
0217 return;
0218 }
0219
0220
0221 const auto tTopo = &eSetup.getData(tTopoToken_);
0222
0223 resetSiStripCertificationMEs(dqm_store);
0224 std::string mdir = "MechanicalView";
0225 dqm_store.cd();
0226 if (!SiStripUtility::goToDir(dqm_store, mdir))
0227 return;
0228 std::string mechanical_dir = dqm_store.pwd();
0229 uint16_t nDetTot = 0;
0230 uint16_t nFaultyTot = 0;
0231 uint16_t nSToNTot = 0;
0232 float sToNTot = 0.0;
0233 SiStripFolderOrganizer folder_organizer;
0234 int xbin = 0;
0235 for (auto const& [name, subDetME] : SubDetMEsMap) {
0236 ++xbin;
0237 MonitorElement* me = subDetME.det_fractionME;
0238 if (!me)
0239 continue;
0240 std::string tag = subDetME.subdet_tag;
0241 std::string bad_module_folder = mechanical_dir + "/" + subDetME.folder_name + "/" + "BadModuleList";
0242 std::vector<MonitorElement*> faulty_detMEs = dqm_store.getContents(bad_module_folder);
0243
0244 uint16_t ndet_subdet = 0;
0245 uint16_t nfaulty_subdet = 0;
0246 int nlayer = subDetME.n_layer;
0247 int ybin = 0;
0248 for (int ilayer = 0; ilayer < nlayer; ilayer++) {
0249 uint16_t ndet_layer = detCabling_->connectedNumber(tag, ilayer + 1);
0250 ndet_subdet += ndet_layer;
0251 ybin++;
0252 uint16_t nfaulty_layer = 0;
0253 for (auto me : faulty_detMEs) {
0254 if (me->kind() != MonitorElement::Kind::INT)
0255 continue;
0256 if (me->getIntValue() == 0)
0257 continue;
0258 uint32_t detId = atoi(me->getName().c_str());
0259 std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detId, tTopo, false);
0260 if (abs(det_layer_pair.second) == ilayer + 1)
0261 nfaulty_layer++;
0262 }
0263
0264 nfaulty_subdet += nfaulty_layer;
0265 float fraction_layer = -1.0;
0266 if (ndet_layer > 0)
0267 fraction_layer = 1 - ((nfaulty_layer * 1.0) / ndet_layer);
0268 if (SiStripCertificationSummaryMap)
0269 SiStripCertificationSummaryMap->Fill(xbin, ilayer + 1, fraction_layer);
0270 }
0271 if (SiStripCertificationSummaryMap && ybin <= SiStripCertificationSummaryMap->getNbinsY()) {
0272 for (int k = ybin + 1; k <= SiStripCertificationSummaryMap->getNbinsY(); k++)
0273 SiStripCertificationSummaryMap->Fill(xbin, k, -1.0);
0274 }
0275 float fraction_subdet = -1.0;
0276 if (ndet_subdet > 0)
0277 fraction_subdet = 1 - ((nfaulty_subdet * 1.0) / ndet_subdet);
0278
0279 std::string full_path = mechanical_dir.substr(0, mechanical_dir.find_last_of('/')) +
0280 "/EventInfo/reportSummaryContents/SiStrip_SToNFlag_" + name;
0281 MonitorElement* me_ston = dqm_store.get(full_path);
0282 me->Reset();
0283 if (me_ston && me_ston->kind() == MonitorElement::Kind::REAL) {
0284 float ston_flg = me_ston->getFloatValue();
0285 sToNTot += ston_flg;
0286 nSToNTot++;
0287 me->Fill(fminf(fraction_subdet, ston_flg));
0288 } else
0289 me->Fill(fraction_subdet);
0290 nDetTot += ndet_subdet;
0291 nFaultyTot += nfaulty_subdet;
0292 }
0293 float fraction_global = -1.0;
0294 if (nDetTot > 0)
0295 fraction_global = 1.0 - ((nFaultyTot * 1.0) / nDetTot);
0296 float ston_frac_global = 1.0;
0297 if (nSToNTot > 0)
0298 ston_frac_global = sToNTot / nSToNTot;
0299 SiStripCertification->Fill(fminf(fraction_global, ston_frac_global));
0300 }
0301
0302
0303
0304 void SiStripCertificationInfo::resetSiStripCertificationMEs(DQMStore& dqm_store) {
0305 if (!sistripCertificationBooked_) {
0306 bookSiStripCertificationMEs(dqm_store);
0307 }
0308 assert(sistripCertificationBooked_);
0309
0310 SiStripCertification->Reset();
0311 for (auto const& pr : SubDetMEsMap) {
0312 pr.second.det_fractionME->Reset();
0313 }
0314 SiStripCertificationSummaryMap->Reset();
0315 }
0316
0317
0318
0319 void SiStripCertificationInfo::fillDummySiStripCertification(DQMStore& dqm_store) {
0320 resetSiStripCertificationMEs(dqm_store);
0321 if (sistripCertificationBooked_) {
0322 SiStripCertification->Fill(-1.0);
0323 for (auto const& pr : SubDetMEsMap) {
0324 pr.second.det_fractionME->Reset();
0325 pr.second.det_fractionME->Fill(-1.0);
0326 }
0327
0328 for (int xbin = 1; xbin < SiStripCertificationSummaryMap->getNbinsX() + 1; xbin++) {
0329 for (int ybin = 1; ybin < SiStripCertificationSummaryMap->getNbinsY() + 1; ybin++) {
0330 SiStripCertificationSummaryMap->Fill(xbin, ybin, -1.0);
0331 }
0332 }
0333 }
0334 }
0335
0336
0337
0338 void SiStripCertificationInfo::fillSiStripCertificationMEsAtLumi(DQMStore& dqm_store) {
0339 if (!sistripCertificationBooked_) {
0340 edm::LogError("SiStripCertificationInfo")
0341 << " SiStripCertificationInfo::fillSiStripCertificationMEsAtLumi : MEs missing ";
0342 return;
0343 }
0344 resetSiStripCertificationMEs(dqm_store);
0345 dqm_store.cd();
0346 std::string strip_dir = "";
0347 SiStripUtility::getTopFolderPath(dqm_store, "SiStrip", strip_dir);
0348 if (strip_dir.empty())
0349 strip_dir = "SiStrip";
0350
0351 std::string full_path;
0352 float dcs_flag = 1.0;
0353 float dqm_flag = 1.0;
0354 for (auto const& [type, subDetME] : SubDetMEsMap) {
0355 full_path = strip_dir + "/EventInfo/DCSContents/SiStrip_" + type;
0356 MonitorElement* me_dcs = dqm_store.get(full_path);
0357 if (me_dcs && me_dcs->kind() == MonitorElement::Kind::REAL)
0358 dcs_flag = me_dcs->getFloatValue();
0359 full_path = strip_dir + "/EventInfo/reportSummaryContents/SiStrip_" + type;
0360 MonitorElement* me_dqm = dqm_store.get(full_path);
0361 if (me_dqm && me_dqm->kind() == MonitorElement::Kind::REAL)
0362 dqm_flag = me_dqm->getFloatValue();
0363 subDetME.det_fractionME->Reset();
0364 subDetME.det_fractionME->Fill(fminf(dqm_flag, dcs_flag));
0365 }
0366 dcs_flag = 1.0;
0367 dqm_flag = 1.0;
0368 full_path = strip_dir + "/EventInfo/reportSummary";
0369 MonitorElement* me_dqm = dqm_store.get(full_path);
0370 if (me_dqm && me_dqm->kind() == MonitorElement::Kind::REAL)
0371 dqm_flag = me_dqm->getFloatValue();
0372 full_path = strip_dir + "/EventInfo/DCSSummary";
0373 MonitorElement* me_dcs = dqm_store.get(full_path);
0374 if (me_dcs && me_dcs->kind() == MonitorElement::Kind::REAL)
0375 dcs_flag = me_dcs->getFloatValue();
0376 SiStripCertification->Reset();
0377 SiStripCertification->Fill(fminf(dqm_flag, dcs_flag));
0378 }
0379 #include "FWCore/Framework/interface/MakerMacros.h"
0380 DEFINE_FWK_MODULE(SiStripCertificationInfo);