Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/EcalTimeCalibErrors.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 Time Calib Errors of 1 IOV 
0042 
0043   *******************************************************/
0044 
0045   // inherit from one of the predefined plot class: Histogram2D
0046   class EcalTimeCalibErrorsEBMap : public cond::payloadInspector::Histogram2D<EcalTimeCalibErrors> {
0047   public:
0048     EcalTimeCalibErrorsEBMap()
0049         : cond::payloadInspector::Histogram2D<EcalTimeCalibErrors>("ECAL Barrel Time Calib 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<EcalTimeCalibErrors> 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 Time Calib 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    
0097      2d histogram of ECAL EndCaps Time Calib Errors of 1 IOV 
0098 
0099   *******************************************************/
0100 
0101   class EcalTimeCalibErrorsEEMap : public cond::payloadInspector::Histogram2D<EcalTimeCalibErrors> {
0102   private:
0103     int EEhistSplit = 20;
0104 
0105   public:
0106     EcalTimeCalibErrorsEEMap()
0107         : cond::payloadInspector::Histogram2D<EcalTimeCalibErrors>("ECAL Endcap Time Calib Errors - map ",
0108                                                                    "ix",
0109                                                                    EEhistXMax,
0110                                                                    IX_MIN,
0111                                                                    EEhistXMax + 1,
0112                                                                    "iy",
0113                                                                    IY_MAX,
0114                                                                    IY_MIN,
0115                                                                    IY_MAX + 1) {
0116       Base::setSingleIov(true);
0117     }
0118 
0119     bool fill() override {
0120       auto tag = PlotBase::getTag<0>();
0121       for (auto const& iov : tag.iovs) {
0122         std::shared_ptr<EcalTimeCalibErrors> payload = Base::fetchPayload(std::get<1>(iov));
0123         if (payload.get()) {
0124           if (payload->endcapItems().empty())
0125             return false;
0126 
0127           // set to -1 everywhwere
0128           for (int ix = IX_MIN; ix < EEhistXMax + 1; ix++)
0129             for (int iy = IY_MAX; iy < IY_MAX + 1; iy++)
0130               fillWithValue(ix, iy, -1);
0131 
0132           for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {  // loop on EE cells
0133             if (EEDetId::validHashIndex(cellid)) {
0134               uint32_t rawid = EEDetId::unhashIndex(cellid);
0135               EcalFloatCondObjectContainer::const_iterator value_ptr = payload->find(rawid);
0136               if (value_ptr == payload->end())
0137                 continue;  // cell absent from payload
0138 
0139               float weight = (float)(*value_ptr);
0140               EEDetId myEEId(rawid);
0141               if (myEEId.zside() == -1)
0142                 fillWithValue(myEEId.ix(), myEEId.iy(), weight);
0143               else
0144                 fillWithValue(myEEId.ix() + IX_MAX + EEhistSplit, myEEId.iy(), weight);
0145             }  // validDetId
0146           }    // loop over cellid
0147 
0148         }  // payload
0149       }    // loop over IOV's (1 in this case)
0150       return true;
0151     }  // fill method
0152   };
0153 
0154   /*************************************************
0155      2d plot of Ecal Time Calib Errors of 1 IOV
0156   *************************************************/
0157   class EcalTimeCalibErrorsPlot : public cond::payloadInspector::PlotImage<EcalTimeCalibErrors> {
0158   public:
0159     EcalTimeCalibErrorsPlot()
0160         : cond::payloadInspector::PlotImage<EcalTimeCalibErrors>("Ecal Time Calib Errors - map ") {
0161       setSingleIov(true);
0162     }
0163 
0164     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0165       TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0166       TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0167       TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0168 
0169       auto iov = iovs.front();
0170       std::shared_ptr<EcalTimeCalibErrors> payload = fetchPayload(std::get<1>(iov));
0171       unsigned int run = std::get<0>(iov);
0172 
0173       if (payload.get()) {
0174         if (payload->barrelItems().empty())
0175           return false;
0176 
0177         fillEBMap_SingleIOV<EcalTimeCalibErrors>(payload, barrel);
0178 
0179         if (payload->endcapItems().empty())
0180           return false;
0181 
0182         fillEEMap_SingleIOV<EcalTimeCalibErrors>(payload, endc_m, endc_p);
0183 
0184       }  // payload
0185 
0186       gStyle->SetPalette(1);
0187       gStyle->SetOptStat(0);
0188       TCanvas canvas("CC map", "CC map", 1600, 450);
0189       TLatex t1;
0190       t1.SetNDC();
0191       t1.SetTextAlign(26);
0192       t1.SetTextSize(0.05);
0193       t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Errors, IOV %i", run));
0194 
0195       float xmi[3] = {0.0, 0.24, 0.76};
0196       float xma[3] = {0.24, 0.76, 1.00};
0197       std::array<std::unique_ptr<TPad>, 3> pad;
0198       for (int obj = 0; obj < 3; obj++) {
0199         pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0200         pad[obj]->Draw();
0201       }
0202       //      EcalDrawMaps ICMap;
0203       pad[0]->cd();
0204       //      ICMap.DrawEE(endc_m, 0., 2.);
0205       DrawEE(endc_m, 0., 2.5);
0206       pad[1]->cd();
0207       //      ICMap.DrawEB(barrel, 0., 2.);
0208       DrawEB(barrel, 0., 2.5);
0209       pad[2]->cd();
0210       //      ICMap.DrawEE(endc_p, 0., 2.);
0211       DrawEE(endc_p, 0., 2.5);
0212 
0213       std::string ImageName(m_imageFileName);
0214       canvas.SaveAs(ImageName.c_str());
0215       return true;
0216     }  // fill method
0217   };
0218 
0219   /*****************************************************************
0220      2d plot of Ecal Time Calib Errors difference between 2 IOVs
0221   *****************************************************************/
0222   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags, int method>
0223   class EcalTimeCalibErrorsBase : public cond::payloadInspector::PlotImage<EcalTimeCalibErrors, nIOVs, ntags> {
0224   public:
0225     EcalTimeCalibErrorsBase()
0226         : cond::payloadInspector::PlotImage<EcalTimeCalibErrors, nIOVs, ntags>("Ecal Time Calib Errors comparison") {}
0227 
0228     bool fill() override {
0229       TH2F* barrel = new TH2F("EB", "mean EB", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0230       TH2F* endc_p = new TH2F("EE+", "mean EE+", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0231       TH2F* endc_m = new TH2F("EE-", "mean EE-", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0232       float pEBmin, pEEmin, pEBmax, pEEmax;
0233       pEBmin = 10.;
0234       pEEmin = 10.;
0235       pEBmax = -10.;
0236       pEEmax = -10.;
0237 
0238       unsigned int run[2];
0239       float pEB[kEBChannels], pEE[kEEChannels];
0240       std::string l_tagname[2];
0241       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0242       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0243       auto firstiov = iovs.front();
0244       run[0] = std::get<0>(firstiov);
0245       std::tuple<cond::Time_t, cond::Hash> lastiov;
0246       if (ntags == 2) {
0247         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0248         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0249         lastiov = tag2iovs.front();
0250       } else {
0251         lastiov = iovs.back();
0252         l_tagname[1] = l_tagname[0];
0253       }
0254       run[1] = std::get<0>(lastiov);
0255       for (int irun = 0; irun < nIOVs; irun++) {
0256         std::shared_ptr<EcalTimeCalibErrors> payload;
0257         if (irun == 0) {
0258           payload = this->fetchPayload(std::get<1>(firstiov));
0259         } else {
0260           payload = this->fetchPayload(std::get<1>(lastiov));
0261         }
0262         if (payload.get()) {
0263           if (payload->barrelItems().empty())
0264             return false;
0265 
0266           fillEBMap_TwoIOVs<EcalTimeCalibErrors>(payload, barrel, irun, pEB, pEBmin, pEBmax, method);
0267 
0268           if (payload->endcapItems().empty())
0269             return false;
0270 
0271           fillEEMap_TwoIOVs<EcalTimeCalibErrors>(payload, endc_m, endc_p, irun, pEE, pEEmin, pEEmax, method);
0272 
0273         }  // payload
0274       }    // loop over IOVs
0275 
0276       gStyle->SetPalette(1);
0277       gStyle->SetOptStat(0);
0278       TCanvas canvas("CC map", "CC map", 1600, 450);
0279       TLatex t1;
0280       t1.SetNDC();
0281       t1.SetTextAlign(26);
0282       int len = l_tagname[0].length() + l_tagname[1].length();
0283       std::string dr[2] = {"-", "/"};
0284       if (ntags == 2) {
0285         if (len < 170) {
0286           t1.SetTextSize(0.05);
0287           t1.DrawLatex(0.5,
0288                        0.96,
0289                        Form("%s IOV %i %s %s  IOV %i",
0290                             l_tagname[1].c_str(),
0291                             run[1],
0292                             dr[method].c_str(),
0293                             l_tagname[0].c_str(),
0294                             run[0]));
0295         } else {
0296           t1.SetTextSize(0.05);
0297           t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Errors, IOV %i%s  %i", run[1], dr[method].c_str(), run[0]));
0298         }
0299       } else {
0300         t1.SetTextSize(0.05);
0301         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]));
0302       }
0303       float xmi[3] = {0.0, 0.24, 0.76};
0304       float xma[3] = {0.24, 0.76, 1.00};
0305       std::array<std::unique_ptr<TPad>, 3> pad;
0306 
0307       for (int obj = 0; obj < 3; obj++) {
0308         pad[obj] = std::make_unique<TPad>(Form("p_%i", obj), Form("p_%i", obj), xmi[obj], 0.0, xma[obj], 0.94);
0309         pad[obj]->Draw();
0310       }
0311 
0312       pad[0]->cd();
0313       DrawEE(endc_m, pEEmin, pEEmax);
0314       pad[1]->cd();
0315       DrawEB(barrel, pEBmin, pEBmax);
0316       pad[2]->cd();
0317       DrawEE(endc_p, pEEmin, pEEmax);
0318 
0319       std::string ImageName(this->m_imageFileName);
0320       canvas.SaveAs(ImageName.c_str());
0321       return true;
0322     }  // fill method
0323   };   // class EcalTimeCalibErrorsDiffBase
0324   using EcalTimeCalibErrorsDiffOneTag = EcalTimeCalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 1, 0>;
0325   using EcalTimeCalibErrorsDiffTwoTags = EcalTimeCalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 2, 0>;
0326   using EcalTimeCalibErrorsRatioOneTag = EcalTimeCalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 1, 1>;
0327   using EcalTimeCalibErrorsRatioTwoTags = EcalTimeCalibErrorsBase<cond::payloadInspector::SINGLE_IOV, 2, 1>;
0328 
0329   /*******************************************************
0330      2d plot of Ecal Time Calib Errors Summary of 1 IOV
0331    *******************************************************/
0332   class EcalTimeCalibErrorsSummaryPlot : public cond::payloadInspector::PlotImage<EcalTimeCalibErrors> {
0333   public:
0334     EcalTimeCalibErrorsSummaryPlot()
0335         : cond::payloadInspector::PlotImage<EcalTimeCalibErrors>("Ecal Time Calib Errors Summary- map ") {
0336       setSingleIov(true);
0337     }
0338 
0339     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0340       auto iov = iovs.front();
0341       std::shared_ptr<EcalTimeCalibErrors> payload = fetchPayload(std::get<1>(iov));
0342       unsigned int run = std::get<0>(iov);
0343       TH2F* align;
0344       int NbRows;
0345 
0346       if (payload.get()) {
0347         NbRows = 2;
0348         align = new TH2F("", "", 0, 0, 0, 0, 0, 0);
0349 
0350         float mean_x_EB = 0.0f;
0351         float mean_x_EE = 0.0f;
0352 
0353         float rms_EB = 0.0f;
0354         float rms_EE = 0.0f;
0355 
0356         int num_x_EB = 0;
0357         int num_x_EE = 0;
0358 
0359         payload->summary(mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
0360         fillTableWithSummary(align, "Ecal Time Calib Errors", mean_x_EB, rms_EB, num_x_EB, mean_x_EE, rms_EE, num_x_EE);
0361 
0362       } else
0363         return false;
0364 
0365       gStyle->SetPalette(1);
0366       gStyle->SetOptStat(0);
0367       TCanvas canvas("CC map", "CC map", 1000, 1000);
0368       TLatex t1;
0369       t1.SetNDC();
0370       t1.SetTextAlign(26);
0371       t1.SetTextSize(0.04);
0372       t1.SetTextColor(2);
0373       t1.DrawLatex(0.5, 0.96, Form("Ecal Time Calib Errors Summary, IOV %i", run));
0374 
0375       TPad pad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0376       pad.Draw();
0377       pad.cd();
0378       align->Draw("TEXT");
0379 
0380       drawTable(NbRows, 4);
0381 
0382       std::string ImageName(m_imageFileName);
0383       canvas.SaveAs(ImageName.c_str());
0384 
0385       return true;
0386     }
0387   };
0388 
0389 }  // namespace
0390 
0391 // Register the classes as boost python plugin
0392 PAYLOAD_INSPECTOR_MODULE(EcalTimeCalibErrors) {
0393   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsEBMap);
0394   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsEEMap);
0395   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsPlot);
0396   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsDiffOneTag);
0397   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsDiffTwoTags);
0398   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsRatioOneTag);
0399   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsRatioTwoTags);
0400   PAYLOAD_INSPECTOR_CLASS(EcalTimeCalibErrorsSummaryPlot);
0401 }