Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-05 04:09:28

0001 /*!
0002   \file SiStripFedCabling_PayloadInspector
0003   \Payload Inspector Plugin for SiStrip Fed Cabling
0004   \author M. Musich
0005   \version $Revision: 1.0 $
0006   \date $Date: 2018/11/02 17:05:56 $
0007 */
0008 
0009 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0010 #include "CondCore/Utilities/interface/PayloadInspector.h"
0011 #include "CondCore/CondDB/interface/Time.h"
0012 
0013 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0014 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0015 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0016 
0017 #include "CommonTools/TrackerMap/interface/TrackerMap.h"
0018 #include "CondCore/SiStripPlugins/interface/SiStripPayloadInspectorHelper.h"
0019 #include "CalibTracker/StandaloneTrackerTopology/interface/StandaloneTrackerTopology.h"
0020 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
0021 
0022 #include <memory>
0023 #include <sstream>
0024 #include <TCanvas.h>
0025 #include <TH2D.h>
0026 #include <TLatex.h>
0027 
0028 namespace {
0029 
0030   using namespace cond::payloadInspector;
0031 
0032   /************************************************
0033     TrackerMap of SiStrip FED Cabling
0034   *************************************************/
0035   class SiStripFedCabling_TrackerMap : public PlotImage<SiStripFedCabling, SINGLE_IOV> {
0036   public:
0037     SiStripFedCabling_TrackerMap() : PlotImage<SiStripFedCabling, SINGLE_IOV>("Tracker Map SiStrip Fed Cabling") {}
0038 
0039     bool fill() override {
0040       auto tag = PlotBase::getTag<0>();
0041       auto iov = tag.iovs.front();
0042       std::shared_ptr<SiStripFedCabling> payload = fetchPayload(std::get<1>(iov));
0043 
0044       std::unique_ptr<TrackerMap> tmap = std::make_unique<TrackerMap>("SiStripFedCabling");
0045       tmap->setPalette(1);
0046       std::string titleMap = "TrackerMap of SiStrip Fed Cabling per module, IOV : " + std::to_string(std::get<0>(iov));
0047       tmap->setTitle(titleMap);
0048 
0049       TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0050           edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
0051       std::unique_ptr<SiStripDetCabling> detCabling_ = std::make_unique<SiStripDetCabling>(*(payload.get()), &tTopo);
0052 
0053       std::vector<uint32_t> activeDetIds;
0054       detCabling_->addActiveDetectorsRawIds(activeDetIds);
0055 
0056       for (const auto& detId : activeDetIds) {
0057         int32_t n_conn = 0;
0058         for (uint32_t connDet_i = 0; connDet_i < detCabling_->getConnections(detId).size(); connDet_i++) {
0059           if (detCabling_->getConnections(detId)[connDet_i] != nullptr &&
0060               detCabling_->getConnections(detId)[connDet_i]->isConnected() != 0)
0061             n_conn++;
0062         }
0063         if (n_conn != 0) {
0064           tmap->fill(detId, n_conn * 2);
0065         }
0066       }
0067 
0068       std::string fileName(m_imageFileName);
0069       tmap->save(true, 0., 6., fileName);
0070 
0071       return true;
0072     }
0073   };
0074 
0075   /************************************************
0076     Summary Plot of SiStrip FED Cabling
0077   *************************************************/
0078   class SiStripFedCabling_Summary : public PlotImage<SiStripFedCabling, SINGLE_IOV> {
0079   public:
0080     SiStripFedCabling_Summary() : PlotImage<SiStripFedCabling, SINGLE_IOV>("SiStrip Fed Cabling Summary") {}
0081 
0082     bool fill() override {
0083       auto tag = PlotBase::getTag<0>();
0084       auto iov = tag.iovs.front();
0085       std::shared_ptr<SiStripFedCabling> payload = fetchPayload(std::get<1>(iov));
0086       int IOV = std::get<0>(iov);
0087       std::vector<uint32_t> activeDetIds;
0088 
0089       TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(
0090           edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
0091       std::unique_ptr<SiStripDetCabling> detCabling_ = std::make_unique<SiStripDetCabling>(*(payload.get()), &tTopo);
0092 
0093       detCabling_->addActiveDetectorsRawIds(activeDetIds);
0094 
0095       containers myCont;
0096       containers allCounts;
0097 
0098       const auto detInfo =
0099           SiStripDetInfoFileReader::read(edm::FileInPath(SiStripDetInfoFileReader::kDefaultFile).fullPath());
0100       for (const auto& it : detInfo.getAllData()) {
0101         // check if det id is correct and if it is actually cabled in the detector
0102         if (it.first == 0 || it.first == 0xFFFFFFFF) {
0103           edm::LogError("DetIdNotGood") << "@SUB=analyze"
0104                                         << "Wrong det id: " << it.first << "  ... neglecting!" << std::endl;
0105           continue;
0106         }
0107         updateCounters(it.first, allCounts, tTopo);
0108       }
0109 
0110       for (const auto& detId : activeDetIds) {
0111         updateCounters(detId, myCont, tTopo);
0112       }
0113 
0114       TH2D* ME = new TH2D("SummaryOfCabling", "SummaryOfCabling", 6, 0.5, 6.5, 9, 0.5, 9.5);
0115       ME->GetXaxis()->SetTitle("Sub Det");
0116       ME->GetYaxis()->SetTitle("Layer");
0117 
0118       ME->SetTitle("");
0119 
0120       ME->GetXaxis()->SetBinLabel(1, "TIB");
0121       ME->GetXaxis()->SetBinLabel(2, "TID F");
0122       ME->GetXaxis()->SetBinLabel(3, "TID B");
0123       ME->GetXaxis()->SetBinLabel(4, "TOB");
0124       ME->GetXaxis()->SetBinLabel(5, "TEC F");
0125       ME->GetXaxis()->SetBinLabel(6, "TEC B");
0126 
0127       for (int i = 0; i < 4; i++) {
0128         ME->Fill(1, i + 1, float(myCont.counterTIB[i]) / allCounts.counterTIB[i]);
0129       }
0130 
0131       for (int i = 0; i < 2; i++) {
0132         for (int j = 0; j < 3; j++) {
0133           ME->Fill(i + 2, j + 1, float(myCont.counterTID[i][j]) / allCounts.counterTID[i][j]);
0134         }
0135       }
0136 
0137       for (int i = 0; i < 6; i++) {
0138         ME->Fill(4, i + 1, float(myCont.counterTOB[i]) / allCounts.counterTOB[i]);
0139       }
0140 
0141       for (int i = 0; i < 2; i++) {
0142         for (int j = 0; j < 9; j++) {
0143           ME->Fill(i + 5, j + 1, float(myCont.counterTEC[i][j]) / allCounts.counterTEC[i][j]);
0144         }
0145       }
0146 
0147       TCanvas c1("SiStrip FED cabling summary", "SiStrip FED cabling summary", 800, 600);
0148       c1.SetTopMargin(0.07);
0149       c1.SetBottomMargin(0.10);
0150       c1.SetLeftMargin(0.07);
0151       c1.SetRightMargin(0.10);
0152 
0153       ME->Draw("colz");
0154       ME->Draw("TEXTsame");
0155       ME->SetStats(kFALSE);
0156 
0157       TLatex t1;
0158       t1.SetNDC();
0159       t1.SetTextAlign(26);
0160       t1.SetTextSize(0.05);
0161       t1.DrawLatex(0.5, 0.96, Form("SiStrip FedCabling, IOV %i", IOV));
0162 
0163       std::string fileName(m_imageFileName);
0164       c1.SaveAs(fileName.c_str());
0165 
0166       return true;
0167     }
0168 
0169   private:
0170     struct containers {
0171     public:
0172       int counterTIB[4] = {0};
0173       int counterTID[2][3] = {{0}};
0174       int counterTOB[6] = {0};
0175       int counterTEC[2][9] = {{0}};
0176     };
0177 
0178     void updateCounters(int detId, containers& cont, const TrackerTopology& tTopo) {
0179       StripSubdetector subdet(detId);
0180 
0181       switch (subdet.subdetId()) {
0182         case StripSubdetector::TIB: {
0183           int i = tTopo.tibLayer(detId) - 1;
0184           cont.counterTIB[i]++;
0185           break;
0186         }
0187         case StripSubdetector::TID: {
0188           int j = tTopo.tidWheel(detId) - 1;
0189           int side = tTopo.tidSide(detId);
0190           if (side == 2) {
0191             cont.counterTID[0][j]++;
0192           } else if (side == 1) {
0193             cont.counterTID[1][j]++;
0194           }
0195           break;
0196         }
0197         case StripSubdetector::TOB: {
0198           int i = tTopo.tobLayer(detId) - 1;
0199           cont.counterTOB[i]++;
0200           break;
0201         }
0202         case StripSubdetector::TEC: {
0203           int j = tTopo.tecWheel(detId) - 1;
0204           int side = tTopo.tecSide(detId);
0205           if (side == 2) {
0206             cont.counterTEC[0][j]++;
0207           } else if (side == 1) {
0208             cont.counterTEC[1][j]++;
0209           }
0210           break;
0211         }
0212       }
0213     }
0214   };
0215 
0216 }  // namespace
0217 
0218 PAYLOAD_INSPECTOR_MODULE(SiStripFedCabling) {
0219   PAYLOAD_INSPECTOR_CLASS(SiStripFedCabling_TrackerMap);
0220   PAYLOAD_INSPECTOR_CLASS(SiStripFedCabling_Summary);
0221 }