Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:29

0001 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0002 #include "CondCore/Utilities/interface/PayloadInspector.h"
0003 #include "CondCore/CondDB/interface/Time.h"
0004 
0005 // the data format of the condition to be inspected
0006 #include "CondFormats/ESObjects/interface/ESChannelStatus.h"
0007 #include "CondFormats/ESObjects/interface/ESChannelStatusCode.h"
0008 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0009 #include "CondCore/EcalPlugins/plugins/ESDrawUtils.h"
0010 
0011 #include <memory>
0012 #include <sstream>
0013 
0014 #include "TStyle.h"
0015 #include "TH2F.h"
0016 #include "TCanvas.h"
0017 #include "TLine.h"
0018 #include "TLatex.h"
0019 
0020 namespace {
0021   enum { kESChannels = 137216 };
0022   enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 40, IY_MAX = 40 };  // endcaps lower and upper bounds on x and y
0023 
0024   /********************************************
0025       2d plot of ES channel status of 1 IOV
0026   *********************************************/
0027   class ESChannelStatusPlot : public cond::payloadInspector::PlotImage<ESChannelStatus> {
0028   public:
0029     ESChannelStatusPlot() : cond::payloadInspector::PlotImage<ESChannelStatus>("ES channel status") {
0030       setSingleIov(true);
0031     }
0032     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0033       TH2F*** esmap = new TH2F**[2];
0034       std::string title[2][2] = {{"ES+F", "ES-F"}, {"ES+R", "ES-R"}};
0035       for (int plane = 0; plane < 2; plane++) {
0036         esmap[plane] = new TH2F*[2];
0037         for (int side = 0; side < 2; side++)
0038           esmap[plane][side] = new TH2F(
0039               Form("esmap%i%i", plane, side), title[plane][side].c_str(), IX_MAX, 0, IX_MAX, IY_MAX, 0, IY_MAX);
0040       }
0041       Int_t escount = 0;
0042       unsigned int run = 0;
0043       auto iov = iovs.front();
0044       std::shared_ptr<ESChannelStatus> payload = fetchPayload(std::get<1>(iov));
0045       run = std::get<0>(iov);
0046       if (payload.get()) {
0047         // looping over all the ES channels
0048         for (int id = 0; id < kESChannels; id++)
0049           if (ESDetId::validHashIndex(id)) {
0050             ESDetId myESId = ESDetId::unhashIndex(id);
0051             int side = myESId.zside();  // -1, 1
0052             if (side < 0)
0053               side = 1;
0054             else
0055               side = 0;
0056             int plane = myESId.plane() - 1;  // 1, 2
0057             if (side < 0 || side > 1 || plane < 0 || plane > 1) {
0058               std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane() << std::endl;
0059               return false;
0060             }
0061             ESChannelStatusCode status_it = (payload->getMap())[myESId];
0062             int status = status_it.getStatusCode();
0063             if (status != 0) {
0064               if (myESId.strip() == 1) {  // we get 32 times the same status, plot it only once!
0065                 esmap[plane][side]->Fill(myESId.six() - 1, myESId.siy() - 1, status);
0066                 //      std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane()
0067                 //            << " x " << myESId.six() << " y " << myESId.siy() << " strip " << myESId.strip()
0068                 //            << " status " << status << std::endl;
0069                 escount++;
0070               }
0071             }
0072           }  // validHashIndex
0073       }  // payload
0074 
0075       gStyle->SetOptStat(0);
0076       gStyle->SetPalette(1);
0077       TCanvas canvas("CC map", "CC map", 1680, 1320);
0078       TLatex t1;
0079       t1.SetNDC();
0080       t1.SetTextAlign(26);
0081       t1.SetTextSize(0.05);
0082       t1.DrawLatex(0.5, 0.96, Form("ES Channel Status, IOV %i", run));
0083       t1.SetTextSize(0.025);
0084 
0085       float xmi[2] = {0.0, 0.5};
0086       float xma[2] = {0.5, 1.0};
0087       TPad*** pad = new TPad**[2];
0088       for (int plane = 0; plane < 2; plane++) {
0089         pad[plane] = new TPad*[2];
0090         for (int side = 0; side < 2; side++) {
0091           float yma = 0.94 - (0.46 * plane);
0092           float ymi = yma - 0.44;
0093           pad[plane][side] =
0094               new TPad(Form("p_%i_%i", plane, side), Form("p_%i_%i", plane, side), xmi[side], ymi, xma[side], yma);
0095           pad[plane][side]->Draw();
0096         }
0097       }
0098 
0099       for (int side = 0; side < 2; side++) {
0100         for (int plane = 0; plane < 2; plane++) {
0101           pad[plane][side]->cd();
0102           esmap[plane][side]->Draw("colz1");
0103           DrawES(plane, side);
0104         }
0105       }
0106       canvas.cd();
0107       t1.SetTextSize(0.025);
0108       int Nbdead = escount * 32;
0109       //      int ipercent = Nbdead * 1000000 / kESChannels;
0110       //      float percent = (float)ipercent / 1000000.;    // keep 2 digits
0111       //      t1.DrawLatex(0.1, 0.94, Form("Number of dead strips %i (%f)", Nbdead, percent));
0112       t1.DrawLatex(0.5, 0.92, Form("Number of dead strips %i", Nbdead));
0113 
0114       std::string ImageName(m_imageFileName);
0115       canvas.SaveAs(ImageName.c_str());
0116       return true;
0117     }  // fill method
0118   };
0119 
0120   /*************************************************************
0121       2d plot of ES channel status difference between 2 IOVs
0122   **************************************************************/
0123   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0124   class ESChannelStatusDiffBase : public cond::payloadInspector::PlotImage<ESChannelStatus, nIOVs, ntags> {
0125   public:
0126     ESChannelStatusDiffBase()
0127         : cond::payloadInspector::PlotImage<ESChannelStatus, nIOVs, ntags>("ES channel status difference") {}
0128     bool fill() override {
0129       TH2F*** esmap = new TH2F**[2];
0130       std::string title[2][2] = {{"ES+F", "ES-F"}, {"ES+R", "ES-R"}};
0131       for (int plane = 0; plane < 2; plane++) {
0132         esmap[plane] = new TH2F*[2];
0133         for (int side = 0; side < 2; side++)
0134           esmap[plane][side] = new TH2F(
0135               Form("esmap%i%i", plane, side), title[plane][side].c_str(), IX_MAX, 0, IX_MAX, IY_MAX, 0, IY_MAX);
0136       }
0137       Int_t escount = 0;
0138       unsigned int run[2] = {0, 0};
0139       int stat[kESChannels];
0140       std::string l_tagname[2];
0141       //      std::cout << " running with " << nIOVs << " IOVs and " << ntags << " tags " << std::endl;
0142       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0143       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0144       auto firstiov = iovs.front();
0145       run[0] = std::get<0>(firstiov);
0146       std::tuple<cond::Time_t, cond::Hash> lastiov;
0147       if (ntags == 2) {
0148         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0149         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0150         lastiov = tag2iovs.front();
0151       } else {
0152         lastiov = iovs.back();
0153         l_tagname[1] = l_tagname[0];
0154       }
0155       run[1] = std::get<0>(lastiov);
0156       for (int irun = 0; irun < nIOVs; irun++) {
0157         std::shared_ptr<ESChannelStatus> payload;
0158         if (irun == 0) {
0159           payload = this->fetchPayload(std::get<1>(firstiov));
0160         } else {
0161           payload = this->fetchPayload(std::get<1>(lastiov));
0162         }
0163         //  std::cout << " irun " << irun << " tag " << l_tagname[irun] << " IOV " << run[irun] << std ::endl;
0164         if (payload.get()) {
0165           for (int id = 0; id < kESChannels; id++)  // looping over all the ES channels
0166             if (ESDetId::validHashIndex(id)) {
0167               ESDetId myESId = ESDetId::unhashIndex(id);
0168               ESChannelStatusCode status_it = (payload->getMap())[myESId];
0169               int status = status_it.getStatusCode();
0170               if (irun == 0)
0171                 stat[id] = status;
0172               else {
0173                 int side = myESId.zside();  // -1, 1
0174                 if (side < 0)
0175                   side = 1;
0176                 else
0177                   side = 0;
0178                 int plane = myESId.plane() - 1;  // 1, 2
0179                 if (side < 0 || side > 1 || plane < 0 || plane > 1) {
0180                   std::cout << " channel " << id << " side " << myESId.zside() << " plane " << myESId.plane()
0181                             << std::endl;
0182                   return false;
0183                 }
0184                 int diff = status - stat[id];
0185                 if (diff != 0) {
0186                   if (myESId.strip() == 1) {  // we get 32 times the same status, plot it only once!
0187                     esmap[plane][side]->Fill(myESId.six() - 1, myESId.siy() - 1, diff);
0188                     escount++;
0189                   }
0190                 }
0191               }  // 2nd IOV
0192             }  // validHashIndex
0193         }  // payload
0194       }  // loop over IOVs
0195 
0196       gStyle->SetOptStat(0);
0197       gStyle->SetPalette(1);
0198       TCanvas canvas("CC map", "CC map", 1680, 1320);
0199       TLatex t1;
0200       t1.SetNDC();
0201       t1.SetTextAlign(26);
0202       int len = l_tagname[0].length() + l_tagname[1].length();
0203       if (ntags == 2) {
0204         if (len < 60) {
0205           t1.SetTextSize(0.03);
0206           t1.DrawLatex(
0207               0.5, 0.96, Form("%s IOV %i - %s  IOV %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
0208         } else {
0209           t1.SetTextSize(0.05);
0210           t1.DrawLatex(0.5, 0.96, Form("ES Channel Status, IOV %i - %i", run[1], run[0]));
0211         }
0212       } else {
0213         t1.SetTextSize(0.05);
0214         t1.DrawLatex(0.5, 0.96, Form("%s IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0215       }
0216 
0217       float xmi[2] = {0.0, 0.5};
0218       float xma[2] = {0.5, 1.0};
0219       TPad*** pad = new TPad**[2];
0220       for (int plane = 0; plane < 2; plane++) {
0221         pad[plane] = new TPad*[2];
0222         for (int side = 0; side < 2; side++) {
0223           float yma = 0.94 - (0.46 * plane);
0224           float ymi = yma - 0.44;
0225           pad[plane][side] =
0226               new TPad(Form("p_%i_%i", plane, side), Form("p_%i_%i", plane, side), xmi[side], ymi, xma[side], yma);
0227           pad[plane][side]->Draw();
0228         }
0229       }
0230 
0231       for (int side = 0; side < 2; side++) {
0232         for (int plane = 0; plane < 2; plane++) {
0233           pad[plane][side]->cd();
0234           esmap[plane][side]->Draw("colz1");
0235           DrawES(plane, side);
0236         }
0237       }
0238       canvas.cd();
0239       t1.SetTextSize(0.025);
0240       int Nbdead = escount * 32;
0241       //      int ipercent = Nbdead * 1000000 / kESChannels;
0242       //      float percent = (float)ipercent / 1000000.;    // keep 2 digits
0243       //      t1.DrawLatex(0.1, 0.94, Form("Number of dead strips %i (%f)", Nbdead, percent));
0244       t1.DrawLatex(0.5, 0.92, Form("Number of different strips %i", Nbdead));
0245 
0246       std::string ImageName(this->m_imageFileName);
0247       canvas.SaveAs(ImageName.c_str());
0248       return true;
0249     }  // fill method
0250   };
0251   using ESChannelStatusDiffOneTag = ESChannelStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0252   using ESChannelStatusDiffTwoTags = ESChannelStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0253 }  // namespace
0254 
0255 // Register the classes as boost python plugin
0256 PAYLOAD_INSPECTOR_MODULE(ESChannelStatus) {
0257   PAYLOAD_INSPECTOR_CLASS(ESChannelStatusPlot);
0258   PAYLOAD_INSPECTOR_CLASS(ESChannelStatusDiffOneTag);
0259   PAYLOAD_INSPECTOR_CLASS(ESChannelStatusDiffTwoTags);
0260 }