Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-10 22:49:17

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 
0007 // the data format of the condition to be inspected
0008 #include "CondFormats/EcalObjects/interface/EcalCondObjectContainer.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 
0018 namespace {
0019   enum { kEBChannels = 61200, kEEChannels = 14648, kSides = 2, kRMS = 5 };
0020   enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 };  // barrel lower and upper bounds on eta and phi
0021   enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 };         // endcaps lower and upper bounds on x and y
0022 
0023   /*****************************************************
0024      2d plot of ECAL FloatCondObjectContainer of 1 IOV
0025   *****************************************************/
0026   class EcalFloatCondObjectContainerPlot : public cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer> {
0027   public:
0028     EcalFloatCondObjectContainerPlot()
0029         : cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer>("ECAL FloatCondObjectContainer - 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", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0035       TH2F* endc_p = new TH2F("EE+", "EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0036       TH2F* endc_m = new TH2F("EE-", "EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0037       double EBmean = 0., EBrms = 0., EEmean = 0., EErms = 0.;
0038       int EBtot = 0, EEtot = 0;
0039 
0040       auto iov = iovs.front();
0041       std::shared_ptr<EcalFloatCondObjectContainer> payload = fetchPayload(std::get<1>(iov));
0042       unsigned int run = std::get<0>(iov);
0043       if (payload.get()) {
0044         for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
0045           Double_t eta = (Double_t)ieta;
0046           if (ieta == 0)
0047             continue;
0048           else if (ieta > 0.)
0049             eta = eta - 0.5;  //   0.5 to 84.5
0050           else
0051             eta = eta + 0.5;  //  -84.5 to -0.5
0052           for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
0053             Double_t phi = (Double_t)iphi - 0.5;
0054             EBDetId id(ieta, iphi);
0055             double val = (*payload)[id.rawId()];
0056             barrel->Fill(phi, eta, val);
0057             EBmean = EBmean + val;
0058             EBrms = EBrms + val * val;
0059             EBtot++;
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()];
0071               EEmean = EEmean + val;
0072               EErms = EErms + val * val;
0073               EEtot++;
0074               if (thesign == 1)
0075                 endc_p->Fill(ix, iy, val);
0076               else
0077                 endc_m->Fill(ix, iy, val);
0078             }  // iy
0079           }    // ix
0080         }      // side
0081       }        // payload
0082       double vt = (double)EBtot;
0083       EBmean = EBmean / vt;
0084       EBrms = EBrms / vt - (EBmean * EBmean);
0085       EBrms = sqrt(EBrms);
0086       if (EBrms == 0.)
0087         EBrms = 0.001;
0088       double pEBmin = EBmean - kRMS * EBrms;
0089       double pEBmax = EBmean + kRMS * EBrms;
0090       //      std::cout << " mean " << EBmean << " rms " << EBrms << " entries " << EBtot << " min " << pEBmin << " max " << pEBmax << std::endl;
0091       vt = (double)EEtot;
0092       EEmean = EEmean / vt;
0093       EErms = EErms / vt - (EEmean * EEmean);
0094       EErms = sqrt(EErms);
0095       if (EErms == 0.)
0096         EErms = 0.001;
0097       double pEEmin = EEmean - kRMS * EErms;
0098       double pEEmax = EEmean + kRMS * EErms;
0099       //      std::cout << " mean " << EEmean << " rms " << EErms << " entries " << EEtot << " min " << pEEmin << " max " << pEEmax << std::endl;
0100 
0101       gStyle->SetPalette(1);
0102       gStyle->SetOptStat(0);
0103       TCanvas canvas("CC map", "CC map", 1600, 450);
0104       TLatex t1;
0105       t1.SetNDC();
0106       t1.SetTextAlign(26);
0107       t1.SetTextSize(0.05);
0108       t1.DrawLatex(0.5, 0.96, Form("Ecal FloatCondObjectContainer, IOV %i", run));
0109 
0110       float xmi[3] = {0.0, 0.24, 0.76};
0111       float xma[3] = {0.24, 0.76, 1.00};
0112       TPad** pad = new TPad*[3];
0113       for (int obj = 0; obj < 3; obj++) {
0114         pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0115         pad[obj]->Draw();
0116       }
0117 
0118       pad[0]->cd();
0119       DrawEE(endc_m, pEEmin, pEEmax);
0120       pad[1]->cd();
0121       DrawEB(barrel, pEBmin, pEBmax);
0122       pad[2]->cd();
0123       DrawEE(endc_p, pEEmin, pEEmax);
0124 
0125       std::string ImageName(m_imageFileName);
0126       canvas.SaveAs(ImageName.c_str());
0127       return true;
0128     }  // fill method
0129   };
0130 
0131   /************************************************************************
0132      2d plot of ECAL FloatCondObjectContainer difference between 2 IOVs
0133   ************************************************************************/
0134   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0135   class EcalFloatCondObjectContainerDiffBase
0136       : public cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer, nIOVs, ntags> {
0137   public:
0138     EcalFloatCondObjectContainerDiffBase()
0139         : cond::payloadInspector::PlotImage<EcalFloatCondObjectContainer, nIOVs, ntags>(
0140               "ECAL FloatCondObjectContainer difference") {}
0141 
0142     bool fill() override {
0143       TH2F* barrel = new TH2F("EB", "EB difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0144       TH2F* endc_p = new TH2F("EE+", "EE+ difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0145       TH2F* endc_m = new TH2F("EE-", "EE- difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0146       double EBmean = 0., EBrms = 0., EEmean = 0., EErms = 0.;
0147       int EBtot = 0, EEtot = 0;
0148 
0149       unsigned int run[2];
0150       float vEB[kEBChannels], vEE[kEEChannels];
0151       std::string l_tagname[2];
0152       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0153       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0154       auto firstiov = iovs.front();
0155       run[0] = std::get<0>(firstiov);
0156       std::tuple<cond::Time_t, cond::Hash> lastiov;
0157       if (ntags == 2) {
0158         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0159         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0160         lastiov = tag2iovs.front();
0161       } else {
0162         lastiov = iovs.back();
0163         l_tagname[1] = l_tagname[0];
0164       }
0165       run[1] = std::get<0>(lastiov);
0166       for (int irun = 0; irun < nIOVs; irun++) {
0167         std::shared_ptr<EcalFloatCondObjectContainer> payload;
0168         if (irun == 0) {
0169           payload = this->fetchPayload(std::get<1>(firstiov));
0170         } else {
0171           payload = this->fetchPayload(std::get<1>(lastiov));
0172         }
0173         if (payload.get()) {
0174           for (int ieta = -MAX_IETA; ieta <= MAX_IETA; ieta++) {
0175             Double_t eta = (Double_t)ieta;
0176             if (ieta == 0)
0177               continue;
0178             else if (ieta > 0.)
0179               eta = eta - 0.5;  //   0.5 to 84.5
0180             else
0181               eta = eta + 0.5;  //  -84.5 to -0.5
0182             for (int iphi = 1; iphi <= MAX_IPHI; iphi++) {
0183               Double_t phi = (Double_t)iphi - 0.5;
0184               EBDetId id(ieta, iphi);
0185               int channel = id.hashedIndex();
0186               double val = (*payload)[id.rawId()];
0187               if (irun == 0)
0188                 vEB[channel] = val;
0189               else {
0190                 double diff = val - vEB[channel];
0191                 barrel->Fill(phi, eta, diff);
0192                 EBmean = EBmean + diff;
0193                 EBrms = EBrms + diff * diff;
0194                 EBtot++;
0195                 //        std::cout << " entry " << EBtot << " mean " << EBmean << " rms " << EBrms << std::endl;
0196               }
0197             }
0198           }
0199 
0200           for (int sign = 0; sign < kSides; sign++) {
0201             int thesign = sign == 1 ? 1 : -1;
0202             for (int ix = 1; ix <= IX_MAX; ix++) {
0203               for (int iy = 1; iy <= IY_MAX; iy++) {
0204                 if (!EEDetId::validDetId(ix, iy, thesign))
0205                   continue;
0206                 EEDetId id(ix, iy, thesign);
0207                 int channel = id.hashedIndex();
0208                 double val = (*payload)[id.rawId()];
0209                 if (irun == 0)
0210                   vEE[channel] = val;
0211                 else {
0212                   double diff = val - vEE[channel];
0213                   EEmean = EEmean + diff;
0214                   EErms = EErms + diff * diff;
0215                   EEtot++;
0216                   if (thesign == 1)
0217                     endc_p->Fill(ix, iy, diff);
0218                   else
0219                     endc_m->Fill(ix, iy, diff);
0220                 }
0221               }  // iy
0222             }    // ix
0223           }      // side
0224         }        // payload
0225         else
0226           return false;
0227       }  // loop over IOVs
0228 
0229       double vt = (double)EBtot;
0230       EBmean = EBmean / vt;
0231       EBrms = EBrms / vt - (EBmean * EBmean);
0232       EBrms = sqrt(EBrms);
0233       if (EBrms == 0.)
0234         EBrms = 0.001;
0235       double pEBmin = EBmean - kRMS * EBrms;
0236       double pEBmax = EBmean + kRMS * EBrms;
0237       //      std::cout << " mean " << EBmean << " rms " << EBrms << " entries " << EBtot << " min " << pEBmin << " max " << pEBmax << std::endl;
0238       vt = (double)EEtot;
0239       EEmean = EEmean / vt;
0240       EErms = EErms / vt - (EEmean * EEmean);
0241       EErms = sqrt(EErms);
0242       if (EErms == 0.)
0243         EErms = 0.001;
0244       double pEEmin = EEmean - kRMS * EErms;
0245       double pEEmax = EEmean + kRMS * EErms;
0246       //      std::cout << " mean " << EEmean << " rms " << EErms << " entries " << EEtot << " min " << pEEmin << " max " << pEEmax << std::endl;
0247 
0248       gStyle->SetPalette(1);
0249       gStyle->SetOptStat(0);
0250       TCanvas canvas("CC map", "CC map", 1600, 450);
0251       TLatex t1;
0252       t1.SetNDC();
0253       t1.SetTextAlign(26);
0254       int len = l_tagname[0].length() + l_tagname[1].length();
0255       if (ntags == 2 && len < 150) {
0256         t1.SetTextSize(0.04);
0257         t1.DrawLatex(
0258             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]));
0259       } else {
0260         t1.SetTextSize(0.05);
0261         t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0262       }
0263       float xmi[3] = {0.0, 0.24, 0.76};
0264       float xma[3] = {0.24, 0.76, 1.00};
0265       TPad** pad = new TPad*[3];
0266       for (int obj = 0; obj < 3; obj++) {
0267         pad[obj] = new TPad(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0268         pad[obj]->Draw();
0269       }
0270 
0271       pad[0]->cd();
0272       DrawEE(endc_m, pEEmin, pEEmax);
0273       pad[1]->cd();
0274       DrawEB(barrel, pEBmin, pEBmax);
0275       pad[2]->cd();
0276       DrawEE(endc_p, pEEmin, pEEmax);
0277 
0278       std::string ImageName(this->m_imageFileName);
0279       canvas.SaveAs(ImageName.c_str());
0280       return true;
0281     }  // fill method
0282   };   // class EcalFloatCondObjectContainerDiffBase
0283   using EcalFloatCondObjectContainerDiffOneTag =
0284       EcalFloatCondObjectContainerDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0285   using EcalFloatCondObjectContainerDiffTwoTags =
0286       EcalFloatCondObjectContainerDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0287 }  // namespace
0288 
0289 // Register the classes as boost python plugin
0290 PAYLOAD_INSPECTOR_MODULE(EcalFloatCondObjectContainer) {
0291   PAYLOAD_INSPECTOR_CLASS(EcalFloatCondObjectContainerPlot);
0292   PAYLOAD_INSPECTOR_CLASS(EcalFloatCondObjectContainerDiffOneTag);
0293   PAYLOAD_INSPECTOR_CLASS(EcalFloatCondObjectContainerDiffTwoTags);
0294 }