Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-10 02:53:51

0001 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0002 #include "CondCore/Utilities/interface/PayloadInspector.h"
0003 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0004 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0005 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0006 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
0007 #include "CondCore/EcalPlugins/plugins/EcalDrawUtils.h"
0008 
0009 // the data format of the condition to be inspected
0010 #include "CondFormats/EcalObjects/interface/EcalTPGTowerStatus.h"
0011 
0012 #include "TH2F.h"
0013 #include "TCanvas.h"
0014 #include "TStyle.h"
0015 #include "TLine.h"
0016 #include "TLatex.h"
0017 
0018 #include <string>
0019 
0020 namespace {
0021   enum { kEBTotalTowers = 2448 };
0022   enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 17, MAX_IPHI = 72 };  // barrel lower and upper bounds on eta and phi
0023 
0024   /***********************************************
0025      2d plot of ECAL TPGTowerStatus of 1 IOV
0026   ************************************************/
0027   class EcalTPGTowerStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
0028   public:
0029     EcalTPGTowerStatusPlot() : cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("ECAL TPGTowerStatus - map ") {
0030       setSingleIov(true);
0031     }
0032 
0033     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0034       TH2F* barrel = new TH2F("EB", "EB TPG Tower Status", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0035       int EBstat = 0;
0036 
0037       auto iov = iovs.front();
0038       std::shared_ptr<EcalTPGTowerStatus> payload = fetchPayload(std::get<1>(iov));
0039       unsigned int run = std::get<0>(iov);
0040       if (payload.get()) {
0041         const EcalTPGTowerStatusMap& towerMap = (*payload).getMap();
0042         //  std::cout << " tower map size " << towerMap.size() << std::endl;
0043         EcalTPGTowerStatusMapIterator it;
0044         for (it = towerMap.begin(); it != towerMap.end(); ++it) {
0045           if ((*it).second > 0) {
0046             EcalTrigTowerDetId ttId((*it).first);
0047             int ieta = ttId.ieta();
0048             //      if(ieta < 0) ieta--;   // -1 to -17
0049             int iphi = ttId.iphi() - 1;  // 0 to 71
0050             //      std::cout << " sub det " << ttId.subDet() << " phi " << iphi << " eta " << ieta << std::endl;
0051             // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
0052             ieta--;
0053             if (ttId.subDet() == 1) {  // barrel
0054               barrel->Fill(iphi, ieta, (*it).second);
0055               EBstat++;
0056             }
0057           }
0058         }
0059       }  // payload
0060 
0061       gStyle->SetPalette(1);
0062       gStyle->SetOptStat(0);
0063       //      TCanvas canvas("CC map","CC map", 1600, 450);
0064       Double_t w = 1400;
0065       Double_t h = 1200;
0066       TCanvas canvas("c", "c", w, h);
0067       //      canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
0068 
0069       TLatex t1;
0070       t1.SetNDC();
0071       t1.SetTextAlign(26);
0072       t1.SetTextSize(0.05);
0073       t1.DrawLatex(0.5, 0.96, Form("Ecal TPGTowerStatus, IOV %i", run));
0074 
0075       TPad** pad = new TPad*;
0076       for (int obj = 0; obj < 1; obj++) {
0077         pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), 0.0, 0.04, 1.0, 0.94);
0078         pad[obj]->Draw();
0079       }
0080       t1.SetTextSize(0.03);
0081       t1.DrawLatex(0.2, 0.88, Form("%i towers", EBstat));
0082       //      canvas.cd();
0083       pad[0]->cd();
0084       //      barrel->SetStats(false);
0085       barrel->Draw("col");
0086       TLine* l = new TLine(0., 0., 0., 0.);
0087       l->SetLineWidth(1);
0088       for (int i = 0; i < MAX_IETA; i++) {
0089         Double_t x = 4. + (i * 4);
0090         l = new TLine(x, -MAX_IETA, x, MAX_IETA);
0091         l->Draw();
0092       }
0093       l = new TLine(0., 0., 72., 0.);
0094       l->Draw();
0095 
0096       std::string ImageName(m_imageFileName);
0097       canvas.SaveAs(ImageName.c_str());
0098       return true;
0099     }  // fill method
0100   };
0101 
0102   /************************************************************************
0103      2d plot of ECAL TPGTowerStatus difference between 2 IOVs
0104   ************************************************************************/
0105   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0106   class EcalTPGTowerStatusDiffBase : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus, nIOVs, ntags> {
0107   public:
0108     EcalTPGTowerStatusDiffBase()
0109         : cond::payloadInspector::PlotImage<EcalTPGTowerStatus, nIOVs, ntags>("ECAL TPGTowerStatus difference") {}
0110 
0111     bool fill() override {
0112       TH2F* barrel = new TH2F("EB", "EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0113       //      int EBstat[2] = {0, 0};
0114       int EBstat = 0;
0115 
0116       unsigned int run[2] = {0, 0}, vEB[kEBTotalTowers];
0117       std::string l_tagname[2];
0118       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0119       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0120       auto firstiov = iovs.front();
0121       run[0] = std::get<0>(firstiov);
0122       std::tuple<cond::Time_t, cond::Hash> lastiov;
0123       if (ntags == 2) {
0124         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0125         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0126         lastiov = tag2iovs.front();
0127       } else {
0128         lastiov = iovs.back();
0129         l_tagname[1] = l_tagname[0];
0130       }
0131       run[1] = std::get<0>(lastiov);
0132       for (int irun = 0; irun < nIOVs; irun++) {
0133         std::shared_ptr<EcalTPGTowerStatus> payload;
0134         if (irun == 0) {
0135           payload = this->fetchPayload(std::get<1>(firstiov));
0136         } else {
0137           payload = this->fetchPayload(std::get<1>(lastiov));
0138         }
0139         if (payload.get()) {
0140           const EcalTPGTowerStatusMap& towerMap = (*payload).getMap();
0141           //      std::cout << " tower map size " << towerMap.size() << std::endl;
0142           EcalTPGTowerStatusMapIterator it;
0143           for (it = towerMap.begin(); it != towerMap.end(); ++it) {
0144             EcalTrigTowerDetId ttId((*it).first);
0145             int ieta = ttId.ieta();
0146             if (ieta < 0)
0147               ieta--;                    // 1 to 17
0148             int iphi = ttId.iphi() - 1;  // 0 to 71
0149             int towerId = ttId.hashedIndex();
0150             int stat = (*it).second;
0151             if (irun == 0) {
0152               if (ttId.subDet() == 1) {  // barrel
0153                 vEB[towerId] = stat;
0154                 if (stat > 0) {  // bad tower
0155                   if (towerId >= kEBTotalTowers)
0156                     std::cout << " strange tower Id " << towerId << std::endl;
0157                 }
0158               }                          // barrel
0159             }                            // 1st run
0160             else {                       // 2nd run
0161               if (ttId.subDet() == 1) {  // barrel
0162                 if (stat > 0) {          // bad tower
0163                   if (towerId >= kEBTotalTowers)
0164                     std::cout << " strange tower Id " << towerId << std::endl;
0165                   //          else std::cout << " phi " << iphi << " eta " << ieta << std::endl;
0166                 }  //  bad tower
0167                 int diff = stat - vEB[towerId];
0168                 // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
0169                 ieta--;
0170                 if (diff != 0)
0171                   barrel->Fill(iphi, ieta, diff);
0172                 //        vEB[towerId] = 0;
0173                 EBstat += diff;
0174               }  // barrel
0175             }    // 2nd run
0176           }      // loop over towers
0177         }        // payload
0178         else
0179           return false;
0180       }  // loop over IOVs
0181       /*
0182       // now check if towers have disappered
0183       for(int it = 0; it < kEBTotalTowers; it++) {
0184     if(vEB[it] != 0) {
0185       std::cout << " tower " << vEB[it] << " not found in run 2, plot it" << std::endl;
0186       EcalTrigTowerDetId ttId = EBId[it];
0187       int ieta = ttId.ieta();
0188       // ieta goes from -18 to -2 and 1 to 17. Change it to -17/-1 and 0/16
0189       ieta--;
0190       int iphi = ttId.iphi() - 1;  // 0 to 71
0191       barrel->Fill(iphi, ieta, vEB[it]);
0192     }
0193       }
0194       */
0195       gStyle->SetPalette(1);
0196       gStyle->SetOptStat(0);
0197       Double_t w = 1400;
0198       Double_t h = 1200;
0199       TCanvas canvas("c", "c", w, h);
0200       //      canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
0201 
0202       TLatex t1;
0203       t1.SetNDC();
0204       t1.SetTextAlign(26);
0205       int len = l_tagname[0].length() + l_tagname[1].length();
0206       if (ntags == 2) {
0207         if (len < 80) {
0208           t1.SetTextSize(0.03);
0209           t1.DrawLatex(0.5, 0.96, Form("%s %i - %s %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
0210         } else {
0211           t1.SetTextSize(0.05);
0212           t1.DrawLatex(0.5, 0.96, Form("Ecal TPGTowerStatus, IOV %i - %i", run[1], run[0]));
0213         }
0214       } else {
0215         t1.SetTextSize(0.05);
0216         t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0217       }
0218       t1.SetTextSize(0.05);
0219 
0220       TPad** pad = new TPad*;
0221       for (int obj = 0; obj < 1; obj++) {
0222         pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), 0.0, 0.04, 1.0, 0.94);
0223         pad[obj]->Draw();
0224       }
0225       t1.SetTextSize(0.03);
0226       t1.DrawLatex(0.2, 0.88, Form("%i tower(s)", EBstat));
0227 
0228       pad[0]->cd();
0229       //      barrel->SetStats(false);
0230       barrel->Draw("colz");
0231       TLine* l = new TLine(0., 0., 0., 0.);
0232       l->SetLineWidth(1);
0233       for (int i = 0; i < MAX_IETA; i++) {
0234         Double_t x = 4. + (i * 4);
0235         l = new TLine(x, -MAX_IETA, x, MAX_IETA);
0236         l->Draw();
0237       }
0238       l = new TLine(0., 0., 72., 0.);
0239       l->Draw();
0240 
0241       std::string ImageName(this->m_imageFileName);
0242       canvas.SaveAs(ImageName.c_str());
0243       return true;
0244     }  // fill method
0245   };   // class EcalTPGTowerStatusDiffBase
0246   using EcalTPGTowerStatusDiffOneTag = EcalTPGTowerStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0247   using EcalTPGTowerStatusDiffTwoTags = EcalTPGTowerStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0248 
0249   /*******************************************************
0250     2d plot of EcalTPGTowerStatus Error Summary of 1 IOV
0251   ********************************************************/
0252   class EcalTPGTowerStatusSummaryPlot : public cond::payloadInspector::PlotImage<EcalTPGTowerStatus> {
0253   public:
0254     EcalTPGTowerStatusSummaryPlot()
0255         : cond::payloadInspector::PlotImage<EcalTPGTowerStatus>("Ecal TPGTower Status Summary - map ") {
0256       setSingleIov(true);
0257     }
0258 
0259     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0260       auto iov = iovs.front();  //get reference to 1st element in the vector iovs
0261       std::shared_ptr<EcalTPGTowerStatus> payload =
0262           fetchPayload(std::get<1>(iov));   //std::get<1>(iov) refers to the Hash in the tuple iov
0263       unsigned int run = std::get<0>(iov);  //referes to Time_t in iov.
0264       TH2F* align;                          //pointer to align which is a 2D histogram
0265 
0266       int NbRows = 1;
0267       int NbColumns = 2;
0268 
0269       if (payload.get()) {  //payload is an iov retrieved from payload using hash.
0270         const EcalTPGTowerStatusMap& towerMap = (*payload).getMap();
0271 
0272         align = new TH2F("Ecal TPGTower Status Summary",
0273                          "Total                NumberOfMasked",
0274                          NbColumns,
0275                          0,
0276                          NbColumns,
0277                          NbRows,
0278                          0,
0279                          NbRows);
0280 
0281         int NbMaskedTT = 0;
0282 
0283         for (EcalTPGTowerStatusMapIterator it = towerMap.begin(); it != towerMap.end(); ++it)
0284           if ((*it).second > 0)
0285             NbMaskedTT++;
0286 
0287         align->Fill(0.5, 0.5, towerMap.size());
0288         align->Fill(1.5, 0.5, NbMaskedTT);
0289 
0290       }  // if payload.get()
0291       else
0292         return false;
0293 
0294       gStyle->SetPalette(1);
0295       gStyle->SetOptStat(0);
0296       TCanvas canvas("CC map", "CC map", 1000, 1000);
0297       TLatex t1;
0298       t1.SetNDC();
0299       t1.SetTextAlign(26);
0300       t1.SetTextSize(0.04);
0301       t1.SetTextColor(2);
0302       t1.DrawLatex(0.5, 0.96, Form("Barrel masked Trigger Towers, IOV %i", run));
0303 
0304       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0305       pad->Draw();
0306       pad->cd();
0307       align->Draw("TEXT");
0308 
0309       drawTable(NbRows, NbColumns);
0310 
0311       align->GetXaxis()->SetTickLength(0.);
0312       align->GetXaxis()->SetLabelSize(0.);
0313       align->GetYaxis()->SetTickLength(0.);
0314       align->GetYaxis()->SetLabelSize(0.);
0315 
0316       std::string ImageName(m_imageFileName);
0317       canvas.SaveAs(ImageName.c_str());
0318       return true;
0319     }  // fill method
0320   };
0321 
0322 }  // namespace
0323 
0324 // Register the classes as boost python plugin
0325 PAYLOAD_INSPECTOR_MODULE(EcalTPGTowerStatus) {
0326   PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusPlot);
0327   PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusDiffOneTag);
0328   PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusDiffTwoTags);
0329   PAYLOAD_INSPECTOR_CLASS(EcalTPGTowerStatusSummaryPlot);
0330 }