Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 "CondCore/EcalPlugins/plugins/EcalDrawUtils.h"
0006 #include "CondCore/EcalPlugins/plugins/EcalBadCrystalsCount.h"
0007 // the data format of the condition to be inspected
0008 #include "CondFormats/EcalObjects/interface/EcalTPGCrystalStatus.h"
0009 
0010 #include "TH2F.h"
0011 #include "TCanvas.h"
0012 #include "TStyle.h"
0013 #include "TLine.h"
0014 #include "TLatex.h"
0015 
0016 #include <string>
0017 #include <memory>
0018 #include <array>
0019 
0020 namespace {
0021   enum { kEBChannels = 61200, kEEChannels = 14648, kSides = 2 };
0022   enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 };  // barrel lower and upper bounds on eta and phi
0023   enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 };         // endcaps lower and upper bounds on x and y
0024 
0025   /***********************************************
0026      2d plot of ECAL TPGCrystalStatus of 1 IOV
0027   ************************************************/
0028   class EcalTPGCrystalStatusPlot : public cond::payloadInspector::PlotImage<EcalTPGCrystalStatus> {
0029   public:
0030     EcalTPGCrystalStatusPlot()
0031         : cond::payloadInspector::PlotImage<EcalTPGCrystalStatus>("ECAL TPGCrystalStatus - map ") {
0032       setSingleIov(true);
0033     }
0034 
0035     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
0036       TH2F* barrel = new TH2F("EB", "EB TPG Crystal Status", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0037       TH2F* endc_p = new TH2F("EE+", "EE+ TPG Crystal Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0038       TH2F* endc_m = new TH2F("EE-", "EE- TPG Crystal Status", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0039       int EBstat = 0, EEstat[2] = {0, 0};
0040 
0041       auto iov = iovs.front();
0042       std::shared_ptr<EcalTPGCrystalStatus> payload = fetchPayload(std::get<1>(iov));
0043       unsigned int run = std::get<0>(iov);
0044       if (payload.get()) {
0045         for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
0046           Double_t eta = (Double_t)ieta;
0047           if (ieta == 0)
0048             continue;
0049           else if (ieta > 0.)
0050             eta = eta - 0.5;  //   0.5 to 84.5
0051           else
0052             eta = eta + 0.5;  //  -84.5 to -0.5
0053           for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
0054             Double_t phi = (Double_t)iphi - 0.5;
0055             EBDetId id(ieta, iphi);
0056             double val = (*payload)[id.rawId()].getStatusCode();
0057             barrel->Fill(phi, eta, val);
0058             if (val > 0)
0059               EBstat++;
0060           }
0061         }
0062 
0063         for (int sign = 0; sign < kSides; sign++) {
0064           int thesign = sign == 1 ? 1 : -1;
0065           for (int ix = 1; ix <= IX_MAX; ix++) {
0066             for (int iy = 1; iy <= IY_MAX; iy++) {
0067               if (!EEDetId::validDetId(ix, iy, thesign))
0068                 continue;
0069               EEDetId id(ix, iy, thesign);
0070               double val = (*payload)[id.rawId()].getStatusCode();
0071               if (thesign == 1) {
0072                 endc_p->Fill(ix, iy, val);
0073                 if (val > 0)
0074                   EEstat[1]++;
0075               } else {
0076                 endc_m->Fill(ix, iy, val);
0077                 if (val > 0)
0078                   EEstat[0]++;
0079               }
0080             }  // iy
0081           }  // ix
0082         }  // side
0083       }  // payload
0084 
0085       gStyle->SetPalette(1);
0086       gStyle->SetOptStat(0);
0087       //      TCanvas canvas("CC map","CC map", 1600, 450);
0088       Double_t w = 1200;
0089       Double_t h = 1400;
0090       TCanvas canvas("c", "c", w, h);
0091       canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
0092 
0093       TLatex t1;
0094       t1.SetNDC();
0095       t1.SetTextAlign(26);
0096       t1.SetTextSize(0.05);
0097       t1.DrawLatex(0.5, 0.96, Form("Ecal TPGCrystalStatus, IOV %i", run));
0098 
0099       //      float xmi[3] = {0.0 , 0.24, 0.76};
0100       //      float xma[3] = {0.24, 0.76, 1.00};
0101       float xmi[3] = {0.0, 0.0, 0.5};
0102       float xma[3] = {1.0, 0.5, 1.0};
0103       float ymi[3] = {0.47, 0.0, 0.0};
0104       float yma[3] = {0.94, 0.47, 0.47};
0105       std::array<std::unique_ptr<TPad>, 3> pad;
0106       for (int obj = 0; obj < 3; obj++) {
0107         pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]);
0108         pad[obj]->Draw();
0109       }
0110 
0111       pad[0]->cd();
0112       DrawEB(barrel, 0., 1.);
0113       t1.DrawLatex(0.2, 0.94, Form("%i crystals", EBstat));
0114       pad[1]->cd();
0115       DrawEE(endc_m, 0., 1.);
0116       t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[0]));
0117       pad[2]->cd();
0118       DrawEE(endc_p, 0., 1.);
0119       t1.DrawLatex(0.15, 0.92, Form("%i crystals", EEstat[1]));
0120 
0121       std::string ImageName(m_imageFileName);
0122       canvas.SaveAs(ImageName.c_str());
0123       return true;
0124     }  // fill method
0125   };
0126 
0127   /************************************************************************
0128      2d plot of ECAL TPGCrystalStatus difference between 2 IOVs
0129   ************************************************************************/
0130   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0131   class EcalTPGCrystalStatusDiffBase : public cond::payloadInspector::PlotImage<EcalTPGCrystalStatus, nIOVs, ntags> {
0132   public:
0133     EcalTPGCrystalStatusDiffBase()
0134         : cond::payloadInspector::PlotImage<EcalTPGCrystalStatus, nIOVs, ntags>("ECAL TPGCrystalStatus difference") {}
0135 
0136     bool fill() override {
0137       TH2F* barrel = new TH2F("EB", "EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0138       TH2F* endc_p = new TH2F("EE+", "EE+ difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0139       TH2F* endc_m = new TH2F("EE-", "EE- difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0140       int EBstat = 0, EEstat[2] = {0, 0};
0141 
0142       unsigned int run[2] = {0, 0};
0143       float vEB[kEBChannels], vEE[kEEChannels];
0144       std::string l_tagname[2];
0145       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0146       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0147       auto firstiov = iovs.front();
0148       run[0] = std::get<0>(firstiov);
0149       std::tuple<cond::Time_t, cond::Hash> lastiov;
0150       if (ntags == 2) {
0151         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0152         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0153         lastiov = tag2iovs.front();
0154       } else {
0155         lastiov = iovs.back();
0156         l_tagname[1] = l_tagname[0];
0157       }
0158       run[1] = std::get<0>(lastiov);
0159       for (int irun = 0; irun < nIOVs; irun++) {
0160         std::shared_ptr<EcalTPGCrystalStatus> payload;
0161         if (irun == 0) {
0162           payload = this->fetchPayload(std::get<1>(firstiov));
0163         } else {
0164           payload = this->fetchPayload(std::get<1>(lastiov));
0165         }
0166         if (payload.get()) {
0167           for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
0168             Double_t eta = (Double_t)ieta;
0169             if (ieta == 0)
0170               continue;
0171             else if (ieta > 0.)
0172               eta = eta - 0.5;  //   0.5 to 84.5
0173             else
0174               eta = eta + 0.5;  //  -84.5 to -0.5
0175             for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
0176               Double_t phi = (Double_t)iphi - 0.5;
0177               EBDetId id(ieta, iphi);
0178               int channel = id.hashedIndex();
0179               double val = (*payload)[id.rawId()].getStatusCode();
0180               if (irun == 0)
0181                 vEB[channel] = val;
0182               else {
0183                 double diff = val - vEB[channel];
0184                 barrel->Fill(phi, eta, diff);
0185                 if (diff != 0)
0186                   EBstat++;
0187                 //      std::cout << " entry " << EBtot << " mean " << EBmean << " rms " << EBrms << std::endl;
0188               }
0189             }
0190           }
0191 
0192           for (int sign = 0; sign < kSides; sign++) {
0193             int thesign = sign == 1 ? 1 : -1;
0194             for (int ix = 1; ix <= IX_MAX; ix++) {
0195               for (int iy = 1; iy <= IY_MAX; iy++) {
0196                 if (!EEDetId::validDetId(ix, iy, thesign))
0197                   continue;
0198                 EEDetId id(ix, iy, thesign);
0199                 int channel = id.hashedIndex();
0200                 double val = (*payload)[id.rawId()].getStatusCode();
0201                 if (irun == 0)
0202                   vEE[channel] = val;
0203                 else {
0204                   double diff = val - vEE[channel];
0205                   if (thesign == 1) {
0206                     endc_p->Fill(ix, iy, diff);
0207                     if (diff != 0)
0208                       EEstat[1]++;
0209                   } else {
0210                     endc_m->Fill(ix, iy, diff);
0211                     if (diff != 0)
0212                       EEstat[0]++;
0213                   }
0214                 }
0215               }  // iy
0216             }  // ix
0217           }  // side
0218         }  // payload
0219         else
0220           return false;
0221       }  // loop over IOVs
0222 
0223       gStyle->SetPalette(1);
0224       gStyle->SetOptStat(0);
0225       Double_t w = 1200;
0226       Double_t h = 1400;
0227       TCanvas canvas("c", "c", w, h);
0228       canvas.SetWindowSize(w + (w - canvas.GetWw()), h + (h - canvas.GetWh()));
0229 
0230       TLatex t1;
0231       t1.SetNDC();
0232       t1.SetTextAlign(26);
0233       int len = l_tagname[0].length() + l_tagname[1].length();
0234       if (ntags == 2) {
0235         if (len < 80) {
0236           t1.SetTextSize(0.03);
0237           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]));
0238         } else {
0239           t1.SetTextSize(0.05);
0240           t1.DrawLatex(0.5, 0.96, Form("Ecal TPGCrystalStatus, IOV %i - %i", run[1], run[0]));
0241         }
0242       } else {
0243         t1.SetTextSize(0.03);
0244         t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0245       }
0246 
0247       //      float xmi[3] = {0.0 , 0.24, 0.76};
0248       //      float xma[3] = {0.24, 0.76, 1.00};
0249       float xmi[3] = {0.0, 0.0, 0.5};
0250       float xma[3] = {1.0, 0.5, 1.0};
0251       float ymi[3] = {0.47, 0.0, 0.0};
0252       float yma[3] = {0.94, 0.47, 0.47};
0253       std::vector<std::unique_ptr<TPad>> pad;
0254       for (int obj = 0; obj < 3; obj++) {
0255         pad.emplace_back(new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], ymi[obj], xma[obj], yma[obj]));
0256         pad[obj]->Draw();
0257       }
0258 
0259       pad[0]->cd();
0260       DrawEB(barrel, -1., 1.);
0261       t1.DrawLatex(0.2, 0.94, Form("%i differences", EBstat));
0262       pad[1]->cd();
0263       DrawEE(endc_m, -1., 1.);
0264       t1.DrawLatex(0.15, 0.92, Form("%i differences", EEstat[0]));
0265       pad[2]->cd();
0266       DrawEE(endc_p, -1., 1.);
0267       t1.DrawLatex(0.15, 0.92, Form("%i differences", EEstat[1]));
0268 
0269       std::string ImageName(this->m_imageFileName);
0270       canvas.SaveAs(ImageName.c_str());
0271       return true;
0272     }  // fill method
0273   };  // class EcalTPGCrystalStatusDiffBase
0274   using EcalTPGCrystalStatusDiffOneTag = EcalTPGCrystalStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0275   using EcalTPGCrystalStatusDiffTwoTags = EcalTPGCrystalStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0276 
0277   /*********************************************************
0278     2d plot of EcalTPGCrystalStatus Error Summary of 1 IOV
0279    *********************************************************/
0280   class EcalTPGCrystalStatusSummaryPlot : public cond::payloadInspector::PlotImage<EcalTPGCrystalStatus> {
0281   public:
0282     EcalTPGCrystalStatusSummaryPlot()
0283         : cond::payloadInspector::PlotImage<EcalTPGCrystalStatus>("Ecal TPGCrystal Status Error Summary - map ") {
0284       setSingleIov(true);
0285     }
0286 
0287     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash>>& iovs) override {
0288       auto iov = iovs.front();  //get reference to 1st element in the vector iovs
0289       std::shared_ptr<EcalTPGCrystalStatus> payload =
0290           fetchPayload(std::get<1>(iov));   //std::get<1>(iov) refers to the Hash in the tuple iov
0291       unsigned int run = std::get<0>(iov);  //referes to Time_t in iov.
0292       TH2F* align;                          //pointer to align which is a 2D histogram
0293 
0294       int NbRows = 3;
0295       int NbColumns = 3;
0296 
0297       if (payload.get()) {  //payload is an iov retrieved from payload using hash.
0298 
0299         align = new TH2F("Ecal TPGCrystal Status Error Summary",
0300                          "EB/EE-/EE+            ErrorCount            Total Number",
0301                          NbColumns,
0302                          0,
0303                          NbColumns,
0304                          NbRows,
0305                          0,
0306                          NbRows);
0307 
0308         long unsigned int ebErrorCount = 0;
0309         long unsigned int ee1ErrorCount = 0;
0310         long unsigned int ee2ErrorCount = 0;
0311 
0312         long unsigned int ebTotal = (payload->barrelItems()).size();
0313         long unsigned int ee1Total = 0;
0314         long unsigned int ee2Total = 0;
0315 
0316         getBarrelErrorSummary<EcalTPGCrystalStatusCode>(payload->barrelItems(), ebErrorCount);
0317         getEndCapErrorSummary<EcalTPGCrystalStatusCode>(
0318             payload->endcapItems(), ee1ErrorCount, ee2ErrorCount, ee1Total, ee2Total);
0319 
0320         double row = NbRows - 0.5;
0321 
0322         //EB summary values
0323         align->Fill(0.5, row, 1);
0324         align->Fill(1.5, row, ebErrorCount);
0325         align->Fill(2.5, row, ebTotal);
0326 
0327         row--;
0328         //EE- summary values
0329         align->Fill(0.5, row, 2);
0330         align->Fill(1.5, row, ee1ErrorCount);
0331         align->Fill(2.5, row, ee1Total);
0332 
0333         row--;
0334 
0335         //EE+ summary values
0336         align->Fill(0.5, row, 3);
0337         align->Fill(1.5, row, ee2ErrorCount);
0338         align->Fill(2.5, row, ee2Total);
0339 
0340       }  // if payload.get()
0341       else
0342         return false;
0343 
0344       gStyle->SetPalette(1);
0345       gStyle->SetOptStat(0);
0346       TCanvas canvas("CC map", "CC map", 1000, 1000);
0347       TLatex t1;
0348       t1.SetNDC();
0349       t1.SetTextAlign(26);
0350       t1.SetTextSize(0.04);
0351       t1.SetTextColor(2);
0352       t1.DrawLatex(0.5, 0.96, Form("EcalTPGCrystalStatus Error Summary, IOV %i", run));
0353 
0354       TPad pad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0355       pad.Draw();
0356       pad.cd();
0357       align->Draw("TEXT");
0358 
0359       drawTable(NbRows, NbColumns);
0360 
0361       align->GetXaxis()->SetTickLength(0.);
0362       align->GetXaxis()->SetLabelSize(0.);
0363       align->GetYaxis()->SetTickLength(0.);
0364       align->GetYaxis()->SetLabelSize(0.);
0365 
0366       std::string ImageName(m_imageFileName);
0367       canvas.SaveAs(ImageName.c_str());
0368       return true;
0369     }  // fill method
0370   };
0371 
0372 }  // namespace
0373 
0374 // Register the classes as boost python plugin
0375 PAYLOAD_INSPECTOR_MODULE(EcalTPGCrystalStatus) {
0376   PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusPlot);
0377   PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusDiffOneTag);
0378   PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusDiffTwoTags);
0379   PAYLOAD_INSPECTOR_CLASS(EcalTPGCrystalStatusSummaryPlot);
0380 }