Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/EcalDQMTowerStatus.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 
0022   enum { kEBTotalTowers = 2448, kEETotalTowers = 1584 };
0023   enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 17, MAX_IPHI = 72 };  // barrel lower and upper bounds on eta and phi
0024   enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 20, IY_MAX = 20 };          // endcaps lower and upper bounds on x and y
0025   /***********************************************
0026     2d plot of EcalDQMTowerStatus of 1 IOV
0027 ************************************************/
0028   class EcalDQMTowerStatusPlot : public cond::payloadInspector::PlotImage<EcalDQMTowerStatus> {
0029   public:
0030     EcalDQMTowerStatusPlot() : cond::payloadInspector::PlotImage<EcalDQMTowerStatus>("EcalDQMTowerStatus - map ") {
0031       setSingleIov(true);
0032     }
0033 
0034     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0035       TH2F* barrel = new TH2F("EB", "EB DQM Tower Status", 72, 0, 72, 34, -17, 17);
0036       TH2F* endc_p = new TH2F("EE+", "EE+ DQM Tower Status", 22, 0, 22, 22, 0, 22);
0037       TH2F* endc_m = new TH2F("EE-", "EE- DQM Tower Status", 22, 0, 22, 22, 0, 22);
0038 
0039       auto iov = iovs.front();
0040       std::shared_ptr<EcalDQMTowerStatus> payload = fetchPayload(std::get<1>(iov));
0041       unsigned int run = std::get<0>(iov);
0042       double maxEB = 0, maxEE = 0;
0043 
0044       if (payload.get()) {
0045         for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEBTotalTowers; ++cellid) {
0046           if (payload->barrelItems().empty())
0047             break;
0048           EcalTrigTowerDetId rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
0049           if ((*payload).find(rawid) == (*payload).end())
0050             continue;
0051 
0052           int ieta = rawid.ieta();
0053           if (ieta > 0)
0054             ieta--;                     // 1 to 17
0055           int iphi = rawid.iphi() - 1;  // 0 to 71
0056           barrel->Fill(iphi, ieta, (*payload)[rawid].getStatusCode());
0057 
0058           if (maxEB < (*payload)[rawid].getStatusCode())
0059             maxEB = (*payload)[rawid].getStatusCode();
0060         }
0061 
0062         if (payload->endcapItems().empty())
0063           return false;
0064 
0065         for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEETotalTowers; ++cellid) {
0066           if (EcalScDetId::validHashIndex(cellid)) {
0067             EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
0068             if ((*payload).find(rawid) == (*payload).end())
0069               continue;
0070             int ix = rawid.ix();  // 1 to 20
0071             int iy = rawid.iy();  // 1 to 20
0072             int side = rawid.zside();
0073             if (side == -1)
0074               endc_m->Fill(ix, iy, (*payload)[rawid].getStatusCode());
0075             else
0076               endc_p->Fill(ix, iy, (*payload)[rawid].getStatusCode());
0077 
0078             if (maxEE < (*payload)[rawid].getStatusCode())
0079               maxEE = (*payload)[rawid].getStatusCode();
0080           }
0081         }
0082 
0083       }  // payload
0084 
0085       TCanvas canvas("CC map", "CC map", 800, 800);
0086       TLatex t1;
0087       t1.SetNDC();
0088       t1.SetTextAlign(26);
0089       t1.SetTextSize(0.05);
0090       t1.DrawLatex(0.5, 0.96, Form("Ecal DQM Tower Status, IOV %i", run));
0091 
0092       //TPad* padb = new TPad("padb","padb", 0., 0.55, 1., 1.);
0093       TPad* padb = new TPad("padb", "padb", 0., 0.45, 1., 0.9);
0094       padb->Draw();
0095       TPad* padem = new TPad("padem", "padem", 0., 0., 0.45, 0.45);
0096       padem->Draw();
0097       TPad* padep = new TPad("padep", "padep", 0.55, 0., 1., 0.45);
0098       padep->Draw();
0099 
0100       TLine* l = new TLine(0., 0., 0., 0.);
0101       l->SetLineWidth(1);
0102       padb->cd();
0103       barrel->SetStats(false);
0104       barrel->SetMaximum(maxEB);
0105       barrel->SetMinimum(0);
0106       barrel->Draw("colz");
0107       //barrel->Draw("col");
0108       for (int i = 0; i < 17; i++) {
0109         Double_t x = 4. + (i * 4);
0110         l = new TLine(x, -17., x, 17.);
0111         l->Draw();
0112       }
0113 
0114       l = new TLine(0., 0., 72., 0.);
0115       l->Draw();
0116 
0117       padem->cd();
0118       DrawEE_Tower(endc_m, l, 0, maxEE);
0119 
0120       padep->cd();
0121       DrawEE_Tower(endc_p, l, 0, maxEE);
0122 
0123       std::string ImageName(m_imageFileName);
0124       canvas.SaveAs(ImageName.c_str());
0125       return true;
0126     }  // fill method
0127   };
0128 
0129   /***************************************************
0130     2d plot of EcalDQMTowerStatus Diff between 2 IOV
0131    ****************************************************/
0132   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0133   class EcalDQMTowerStatusDiffBase : public cond::payloadInspector::PlotImage<EcalDQMTowerStatus, nIOVs, ntags> {
0134   public:
0135     EcalDQMTowerStatusDiffBase()
0136         : cond::payloadInspector::PlotImage<EcalDQMTowerStatus, nIOVs, ntags>("EcalDQMTowerStatusDiff - map ") {}
0137     bool fill() override {
0138       TH2F* barrel = new TH2F("EB", "EB DQM Tower Status", 72, 0, 72, 34, -17, 17);
0139       TH2F* endc_p = new TH2F("EE+", "EE+ DQM Tower Status", 22, 0, 22, 22, 0, 22);
0140       TH2F* endc_m = new TH2F("EE-", "EE- DQM Tower Status", 22, 0, 22, 22, 0, 22);
0141 
0142       unsigned int run[2];
0143       float pEB[kEBTotalTowers], pEE[kEETotalTowers];
0144       std::string l_tagname[2];
0145 
0146       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0147       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0148       auto firstiov = iovs.front();
0149       run[0] = std::get<0>(firstiov);
0150       std::tuple<cond::Time_t, cond::Hash> lastiov;
0151       if (ntags == 2) {
0152         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0153         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0154         lastiov = tag2iovs.front();
0155       } else {
0156         lastiov = iovs.back();
0157         l_tagname[1] = l_tagname[0];
0158       }
0159       run[1] = std::get<0>(lastiov);
0160       for (int irun = 0; irun < nIOVs; irun++) {
0161         std::shared_ptr<EcalDQMTowerStatus> payload;
0162         if (irun == 0) {
0163           payload = this->fetchPayload(std::get<1>(firstiov));
0164         } else {
0165           payload = this->fetchPayload(std::get<1>(lastiov));
0166         }
0167         if (payload.get()) {
0168           for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEBTotalTowers; ++cellid) {
0169             if (payload->barrelItems().empty())
0170               break;
0171 
0172             EcalTrigTowerDetId rawid = EcalTrigTowerDetId::detIdFromDenseIndex(cellid);
0173             if ((*payload).find(rawid) == (*payload).end())
0174               continue;
0175 
0176             float weight = (*payload)[rawid].getStatusCode();
0177 
0178             if (irun == 0) {
0179               pEB[cellid] = weight;
0180             } else {
0181               int ieta = rawid.ieta();
0182               if (ieta > 0)
0183                 ieta--;                     // 1 to 17
0184               int iphi = rawid.iphi() - 1;  // 0 to 71
0185               unsigned int new_status = (*payload)[rawid].getStatusCode();
0186               if (new_status != pEB[cellid]) {
0187                 int tmp3 = 0;
0188 
0189                 if (new_status > pEB[cellid])
0190                   tmp3 = 1;
0191                 else
0192                   tmp3 = -1;
0193 
0194                 barrel->Fill(iphi, ieta, 0.05 + 0.95 * (tmp3 > 0));
0195               }
0196             }
0197           }
0198 
0199           if (payload->endcapItems().empty())
0200             return false;
0201 
0202           for (uint cellid = 0; cellid < EcalTrigTowerDetId::kEETotalTowers; ++cellid) {
0203             if (EcalScDetId::validHashIndex(cellid)) {
0204               EcalScDetId rawid = EcalScDetId::unhashIndex(cellid);
0205               if ((*payload).find(rawid) == (*payload).end())
0206                 continue;
0207 
0208               float weight = (*payload)[rawid].getStatusCode();
0209 
0210               if (irun == 0) {
0211                 pEE[cellid] = weight;
0212               } else {
0213                 int ix = rawid.ix();  // 1 to 20
0214                 int iy = rawid.iy();  // 1 to 20
0215                 int side = rawid.zside();
0216 
0217                 unsigned int new_status = (*payload)[rawid].getStatusCode();
0218                 if (new_status != pEE[cellid]) {
0219                   int tmp3 = 0;
0220 
0221                   if (new_status > pEE[cellid])
0222                     tmp3 = 1;
0223                   else
0224                     tmp3 = -1;
0225 
0226                   if (side == -1)
0227                     endc_m->Fill(ix, iy, 0.05 + 0.95 * (tmp3 > 0));
0228                   else
0229                     endc_p->Fill(ix, iy, 0.05 + 0.95 * (tmp3 > 0));
0230                 }
0231               }
0232             }
0233           }
0234         }  // payload
0235       }
0236 
0237       TCanvas canvas("CC map", "CC map", 800, 800);
0238       TLatex t1;
0239       t1.SetNDC();
0240       t1.SetTextAlign(26);
0241       int len = l_tagname[0].length() + l_tagname[1].length();
0242       if (ntags == 2 && len < 58) {
0243         t1.SetTextSize(0.025);
0244         t1.DrawLatex(
0245             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]));
0246       } else {
0247         t1.SetTextSize(0.04);
0248         t1.DrawLatex(0.5, 0.96, Form("Ecal DQM Tower Status (Diff), IOV %i vs %i", run[0], run[1]));
0249       }
0250       TPad* padb = new TPad("padb", "padb", 0., 0.45, 1., 0.9);
0251       padb->Draw();
0252       TPad* padem = new TPad("padem", "padem", 0., 0., 0.45, 0.45);
0253       padem->Draw();
0254       TPad* padep = new TPad("padep", "padep", 0.55, 0., 1., 0.45);
0255       padep->Draw();
0256 
0257       TLine* l = new TLine(0., 0., 0., 0.);
0258       l->SetLineWidth(1);
0259       padb->cd();
0260       barrel->SetStats(false);
0261       barrel->SetMaximum(1.15);
0262       barrel->SetMinimum(0);
0263       barrel->Draw("colz");
0264       //barrel->Draw("col");
0265       for (int i = 0; i < 17; i++) {
0266         Double_t x = 4. + (i * 4);
0267         l = new TLine(x, -17., x, 17.);
0268         l->Draw();
0269       }
0270 
0271       l = new TLine(0., 0., 72., 0.);
0272       l->Draw();
0273 
0274       padem->cd();
0275       DrawEE_Tower(endc_m, l, 0, 1.15);
0276 
0277       padep->cd();
0278       DrawEE_Tower(endc_p, l, 0, 1.15);
0279 
0280       std::string ImageName(this->m_imageFileName);
0281       canvas.SaveAs(ImageName.c_str());
0282       return true;
0283     }  // fill method
0284   };   // class EcalDQMTowerStatusDiffBase
0285   using EcalDQMTowerStatusDiffOneTag = EcalDQMTowerStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0286   using EcalDQMTowerStatusDiffTwoTags = EcalDQMTowerStatusDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0287 
0288 }  // namespace
0289 
0290 // Register the classes as boost python plugin
0291 PAYLOAD_INSPECTOR_MODULE(EcalDQMTowerStatus) {
0292   PAYLOAD_INSPECTOR_CLASS(EcalDQMTowerStatusPlot);
0293   PAYLOAD_INSPECTOR_CLASS(EcalDQMTowerStatusDiffOneTag);
0294   PAYLOAD_INSPECTOR_CLASS(EcalDQMTowerStatusDiffTwoTags);
0295 }