Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:45

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