Back to home page

Project CMSSW displayed by LXR

 
 

    


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