Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-24 04:11:35

0001 #include "CondCore/Utilities/interface/PayloadInspectorModule.h"
0002 #include "CondCore/Utilities/interface/PayloadInspector.h"
0003 #include "CondCore/CondDB/interface/Time.h"
0004 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0005 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0006 #include "CondCore/EcalPlugins/plugins/EcalDrawUtils.h"
0007 #include "CondCore/EcalPlugins/plugins/EcalFloatCondObjectContainerUtils.h"
0008 // the data format of the condition to be inspected
0009 #include "CondFormats/EcalObjects/interface/EcalIntercalibErrors.h"
0010 
0011 #include "TH2F.h"
0012 #include "TCanvas.h"
0013 #include "TStyle.h"
0014 #include "TLine.h"
0015 #include "TLatex.h"
0016 
0017 #include <memory>
0018 #include <sstream>
0019 #include <array>
0020 
0021 namespace {
0022 
0023   enum { kEBChannels = 61200, kEEChannels = 14648 };
0024   enum {
0025     MIN_IETA = 1,
0026     MIN_IPHI = 1,
0027     MAX_IETA = 85,
0028     MAX_IPHI = 360,
0029     EBhistEtaMax = 171
0030   };  // barrel lower and upper bounds on eta and phi
0031   enum {
0032     IX_MIN = 1,
0033     IY_MIN = 1,
0034     IX_MAX = 100,
0035     IY_MAX = 100,
0036     EEhistXMax = 220
0037   };  // endcaps lower and upper bounds on x and y
0038 
0039   /*******************************************************
0040    
0041      2d histogram of ECAL barrel Intercalib Errors of 1 IOV 
0042 
0043   *******************************************************/
0044 
0045   // inherit from one of the predefined plot class: Histogram2D
0046   class EcalIntercalibErrorsEBMap : public cond::payloadInspector::Histogram2D<EcalIntercalibErrors> {
0047   public:
0048     EcalIntercalibErrorsEBMap()
0049         : cond::payloadInspector::Histogram2D<EcalIntercalibErrors>("ECAL Barrel Intercalib Errors- map ",
0050                                                                     "iphi",
0051                                                                     MAX_IPHI,
0052                                                                     MIN_IPHI,
0053                                                                     MAX_IPHI + 1,
0054                                                                     "ieta",
0055                                                                     EBhistEtaMax,
0056                                                                     -MAX_IETA,
0057                                                                     MAX_IETA + 1) {
0058       Base::setSingleIov(true);
0059     }
0060 
0061     // Histogram2D::fill (virtual) needs be overridden - the implementation should use fillWithValue
0062     bool fill() override {
0063       auto tag = PlotBase::getTag<0>();
0064       for (auto const& iov : tag.iovs) {
0065         std::shared_ptr<EcalIntercalibErrors> payload = Base::fetchPayload(std::get<1>(iov));
0066         if (payload.get()) {
0067           // looping over the EB channels, via the dense-index, mapped into EBDetId's
0068           if (payload->barrelItems().empty())
0069             return false;
0070           // set to -1 for ieta 0 (no crystal)
0071           for (int iphi = MIN_IPHI; iphi < MAX_IPHI + 1; iphi++)
0072             fillWithValue(iphi, 0, -1);
0073 
0074           for (int cellid = EBDetId::MIN_HASH; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {
0075             uint32_t rawid = EBDetId::unhashIndex(cellid);
0076 
0077             // check the existence of ECAL Intercalib Errors, for a given ECAL barrel channel
0078             EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
0079             if (value_ptr == payload->end())
0080               continue;  // cell absent from payload
0081 
0082             float weight = (float)(*value_ptr);
0083 
0084             // fill the Histogram2D here
0085             fillWithValue((EBDetId(rawid)).iphi(), (EBDetId(rawid)).ieta(), weight);
0086           }  // loop over cellid
0087         }    // if payload.get()
0088       }      // loop over IOV's (1 in this case)
0089 
0090       return true;
0091 
0092     }  //fill method
0093   };
0094 
0095   /*************************************************************
0096      2d histogram of ECAL EndCaps Intercalib Errors of 1 IOV 
0097   *************************************************************/
0098   class EcalIntercalibErrorsEEMap : public cond::payloadInspector::Histogram2D<EcalIntercalibErrors> {
0099   private:
0100     int EEhistSplit = 20;
0101 
0102   public:
0103     EcalIntercalibErrorsEEMap()
0104         : cond::payloadInspector::Histogram2D<EcalIntercalibErrors>("ECAL Endcap Intercalib Errors - map ",
0105                                                                     "ix",
0106                                                                     EEhistXMax,
0107                                                                     IX_MIN,
0108                                                                     EEhistXMax + 1,
0109                                                                     "iy",
0110                                                                     IY_MAX,
0111                                                                     IY_MIN,
0112                                                                     IY_MAX + 1) {
0113       Base::setSingleIov(true);
0114     }
0115 
0116     bool fill() override {
0117       auto tag = PlotBase::getTag<0>();
0118       for (auto const& iov : tag.iovs) {
0119         std::shared_ptr<EcalIntercalibErrors> payload = Base::fetchPayload(std::get<1>(iov));
0120         if (payload.get()) {
0121           if (payload->endcapItems().empty())
0122             return false;
0123 
0124           // set to -1 everywhwere
0125           for (int ix = IX_MIN; ix < EEhistXMax + 1; ix++)
0126             for (int iy = IY_MAX; iy < IY_MAX + 1; iy++)
0127               fillWithValue(ix, iy, -1);
0128 
0129           for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {  // loop on EE cells
0130             if (EEDetId::validHashIndex(cellid)) {
0131               uint32_t rawid = EEDetId::unhashIndex(cellid);
0132               EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
0133               if (value_ptr == payload->end())
0134                 continue;  // cell absent from payload
0135 
0136               float weight = (float)(*value_ptr);
0137               EEDetId myEEId(rawid);
0138               if (myEEId.zside() == -1)
0139                 fillWithValue(myEEId.ix(), myEEId.iy(), weight);
0140               else
0141                 fillWithValue(myEEId.ix() + IX_MAX + EEhistSplit, myEEId.iy(), weight);
0142             }  // validDetId
0143           }    // loop over cellid
0144 
0145         }  // payload
0146       }    // loop over IOV's (1 in this case)
0147       return true;
0148     }  // fill method
0149   };
0150 
0151   /*************************************************
0152      2d plot of ECAL Intercalib Errors of 1 IOV
0153   *************************************************/
0154   class EcalIntercalibErrorsPlot : public cond::payloadInspector::PlotImage<EcalIntercalibErrors> {
0155   public:
0156     EcalIntercalibErrorsPlot()
0157         : cond::payloadInspector::PlotImage<EcalIntercalibErrors>("ECAL Intercalib Error - map ") {
0158       setSingleIov(true);
0159     }
0160 
0161     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0162       TH2F* barrel = new TH2F("EB", "Intercalib Error EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0163       TH2F* endc_p = new TH2F("EE+", "Intercalib Error EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0164       TH2F* endc_m = new TH2F("EE-", "Intercalib Error EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0165 
0166       auto iov = iovs.front();
0167       std::shared_ptr<EcalIntercalibErrors> payload = fetchPayload(std::get<1>(iov));
0168       unsigned int run = std::get<0>(iov);
0169 
0170       if (payload.get()) {
0171         if (payload->barrelItems().empty())
0172           return false;
0173 
0174         fillEBMap_SingleIOV<EcalIntercalibErrors>(payload, barrel);
0175 
0176         if (payload->endcapItems().empty())
0177           return false;
0178 
0179         fillEEMap_SingleIOV<EcalIntercalibErrors>(payload, endc_m, endc_p);
0180 
0181       }  // payload
0182 
0183       gStyle->SetPalette(1);
0184       gStyle->SetOptStat(0);
0185       TCanvas canvas("CC map", "CC map", 1600, 450);
0186       TLatex t1;
0187       t1.SetNDC();
0188       t1.SetTextAlign(26);
0189       t1.SetTextSize(0.05);
0190       t1.DrawLatex(0.5, 0.96, Form("Ecal Intercalib Errors, IOV %i", run));
0191 
0192       float xmi[3] = {0.0, 0.24, 0.76};
0193       float xma[3] = {0.24, 0.76, 1.00};
0194       std::array<std::unique_ptr<TPad>, 3> pad;
0195       for (int obj = 0; obj < 3; obj++) {
0196         pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0197         pad[obj]->Draw();
0198       }
0199       //      EcalDrawMaps ICMap;
0200       pad[0]->cd();
0201       //      ICMap.DrawEE(endc_m, 0., 2.);
0202       DrawEE(endc_m, 0., 2.5);
0203       pad[1]->cd();
0204       //      ICMap.DrawEB(barrel, 0., 2.);
0205       DrawEB(barrel, 0., 2.5);
0206       pad[2]->cd();
0207       //      ICMap.DrawEE(endc_p, 0., 2.);
0208       DrawEE(endc_p, 0., 2.5);
0209 
0210       std::string ImageName(m_imageFileName);
0211       canvas.SaveAs(ImageName.c_str());
0212       return true;
0213     }  // fill method
0214   };
0215 
0216   /*****************************************************************
0217      2d plot of ECAL Intercalib Errors difference between 2 IOVs
0218   *****************************************************************/
0219   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags, int method>
0220   class EcalIntercalibErrorsBase : public cond::payloadInspector::PlotImage<EcalIntercalibErrors, nIOVs, ntags> {
0221   public:
0222     EcalIntercalibErrorsBase()
0223         : cond::payloadInspector::PlotImage<EcalIntercalibErrors, nIOVs, ntags>("ECAL Intercalib Error comparison") {}
0224 
0225     bool fill() override {
0226       TH2F* barrel = new TH2F("EB", "Intercalib Error EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0227       TH2F* endc_p = new TH2F("EE+", "Intercalib Error EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0228       TH2F* endc_m = new TH2F("EE-", "Intercalib Error EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0229       float pEBmin, pEEmin, pEBmax, pEEmax;
0230       pEBmin = 10.;
0231       pEEmin = 10.;
0232       pEBmax = -10.;
0233       pEEmax = -10.;
0234 
0235       unsigned int run[2];
0236       float pEB[kEBChannels], pEE[kEEChannels];
0237       std::string l_tagname[2];
0238       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0239       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0240       auto firstiov = iovs.front();
0241       run[0] = std::get<0>(firstiov);
0242       std::tuple<cond::Time_t, cond::Hash> lastiov;
0243       if (ntags == 2) {
0244         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0245         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0246         lastiov = tag2iovs.front();
0247       } else {
0248         lastiov = iovs.back();
0249         l_tagname[1] = l_tagname[0];
0250       }
0251       run[1] = std::get<0>(lastiov);
0252       for (int irun = 0; irun < nIOVs; irun++) {
0253         std::shared_ptr<EcalIntercalibErrors> payload;
0254         if (irun == 0) {
0255           payload = this->fetchPayload(std::get<1>(firstiov));
0256         } else {
0257           payload = this->fetchPayload(std::get<1>(lastiov));
0258         }
0259         if (payload.get()) {
0260           if (payload->barrelItems().empty())
0261             return false;
0262           fillEBMap_TwoIOVs<EcalIntercalibErrors>(payload, barrel, irun, pEB, pEBmin, pEBmax, method);
0263           if (payload->endcapItems().empty())
0264             return false;
0265           fillEEMap_TwoIOVs<EcalIntercalibErrors>(payload, endc_m, endc_p, irun, pEE, pEEmin, pEEmax, method);
0266         }  // payload
0267       }    // loop over IOVs
0268 
0269       gStyle->SetPalette(1);
0270       gStyle->SetOptStat(0);
0271       TCanvas canvas("CC map", "CC map", 1600, 450);
0272       TLatex t1;
0273       t1.SetNDC();
0274       t1.SetTextAlign(26);
0275       int len = l_tagname[0].length() + l_tagname[1].length();
0276       std::string dr[2] = {"-", "/"};
0277       if (ntags == 2) {
0278         if (len < 170) {
0279           t1.SetTextSize(0.05);
0280           t1.DrawLatex(0.5,
0281                        0.96,
0282                        Form("%s IOV %i %s %s  IOV %i",
0283                             l_tagname[1].c_str(),
0284                             run[1],
0285                             dr[method].c_str(),
0286                             l_tagname[0].c_str(),
0287                             run[0]));
0288         } else {
0289           t1.SetTextSize(0.05);
0290           t1.DrawLatex(0.5, 0.96, Form("Ecal IntercalibErrorss, IOV %i %s %i", run[1], dr[method].c_str(), run[0]));
0291         }
0292       } else {
0293         t1.SetTextSize(0.05);
0294         t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i %s %i", l_tagname[0].c_str(), run[1], dr[method].c_str(), run[0]));
0295       }
0296 
0297       float xmi[3] = {0.0, 0.24, 0.76};
0298       float xma[3] = {0.24, 0.76, 1.00};
0299       std::array<std::unique_ptr<TPad>, 3> pad;
0300 
0301       for (int obj = 0; obj < 3; obj++) {
0302         pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0303         pad[obj]->Draw();
0304       }
0305 
0306       pad[0]->cd();
0307       DrawEE(endc_m, pEEmin, pEEmax);
0308       pad[1]->cd();
0309       DrawEB(barrel, pEBmin, pEBmax);
0310       pad[2]->cd();
0311       DrawEE(endc_p, pEEmin, pEEmax);
0312 
0313       std::string ImageName(this->m_imageFileName);
0314       canvas.SaveAs(ImageName.c_str());
0315       return true;
0316     }  // fill method
0317   };   // class EcalIntercalibErrorsDiffBase
0318   using EcalIntercalibErrorsDiffOneTag = EcalIntercalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 1, 0>;
0319   using EcalIntercalibErrorsDiffTwoTags = EcalIntercalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 2, 0>;
0320   using EcalIntercalibErrorsRatioOneTag = EcalIntercalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 1, 1>;
0321   using EcalIntercalibErrorsRatioTwoTags = EcalIntercalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 2, 1>;
0322 
0323   /*******************************************************
0324      2d plot of Ecal Intercalib Errors Summary of 1 IOV
0325    *******************************************************/
0326   class EcalIntercalibErrorsSummaryPlot : public cond::payloadInspector::PlotImage<EcalIntercalibErrors> {
0327   public:
0328     EcalIntercalibErrorsSummaryPlot()
0329         : cond::payloadInspector::PlotImage<EcalIntercalibErrors>("Ecal Intercalib Errors Summary- map ") {
0330       setSingleIov(true);
0331     }
0332 
0333     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0334       auto iov = iovs.front();
0335       std::shared_ptr<EcalIntercalibErrors> payload = fetchPayload(std::get<1>(iov));
0336       unsigned int run = std::get<0>(iov);
0337       TH2F* align;
0338       int NbRows;
0339 
0340       if (payload.get()) {
0341         NbRows = 2;
0342         align = new TH2F("", "", 0, 0, 0, 0, 0, 0);
0343 
0344         float mean_x_EB = 0.0f;
0345         float mean_x_EE = 0.0f;
0346 
0347         float rms_EB = 0.0f;
0348         float rms_EE = 0.0f;
0349 
0350         int num_x_EB = 0;
0351         int num_x_EE = 0;
0352 
0353         payload->summary(mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
0354         fillTableWithSummary(align, "Ecal Intercalib Errors", mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
0355 
0356       } else
0357         return false;
0358 
0359       gStyle->SetPalette(1);
0360       gStyle->SetOptStat(0);
0361       TCanvas canvas("CC map", "CC map", 1000, 1000);
0362       TLatex t1;
0363       t1.SetNDC();
0364       t1.SetTextAlign(26);
0365       t1.SetTextSize(0.04);
0366       t1.SetTextColor(2);
0367       t1.DrawLatex(0.5, 0.96, Form("Ecal Intercalib Errors Summary, IOV %i", run));
0368 
0369       TPad pad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0370       pad.Draw();
0371       pad.cd();
0372       align->Draw("TEXT");
0373 
0374       drawTable(NbRows, 4);
0375 
0376       std::string ImageName(m_imageFileName);
0377       canvas.SaveAs(ImageName.c_str());
0378 
0379       return true;
0380     }
0381   };
0382 
0383 }  // namespace
0384 
0385 // Register the classes as boost python plugin
0386 PAYLOAD_INSPECTOR_MODULE(EcalIntercalibErrors) {
0387   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsEBMap);
0388   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsEEMap);
0389   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsPlot);
0390   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsDiffOneTag);
0391   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsDiffTwoTags);
0392   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsRatioOneTag);
0393   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsRatioTwoTags);
0394   PAYLOAD_INSPECTOR_CLASS(EcalIntercalibErrorsSummaryPlot);
0395 }