Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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