Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:26

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 
0008 // the data format of the condition to be inspected
0009 #include "CondFormats/EcalObjects/interface/EcalGainRatios.h"
0010 
0011 #include "TH2F.h"
0012 #include "TCanvas.h"
0013 #include "TLine.h"
0014 #include "TStyle.h"
0015 #include "TLatex.h"
0016 #include "TPave.h"
0017 #include "TPaveStats.h"
0018 #include <string>
0019 #include <fstream>
0020 
0021 namespace {
0022   enum { kEBChannels = 61200, kEEChannels = 14648 };
0023   enum { MIN_IETA = 1, MIN_IPHI = 1, MAX_IETA = 85, MAX_IPHI = 360 };  // barrel lower and upper bounds on eta and phi
0024   enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 };         // endcaps lower and upper bounds on x and y
0025 
0026   /******************************************
0027      2d plot of ECAL GainRatios of 1 IOV
0028   ******************************************/
0029   class EcalGainRatiosPlot : public cond::payloadInspector::PlotImage<EcalGainRatios> {
0030   public:
0031     EcalGainRatiosPlot() : cond::payloadInspector::PlotImage<EcalGainRatios>("ECAL Gain Ratios - map ") {
0032       setSingleIov(true);
0033     }
0034 
0035     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0036       TH2F* barrel_12O6 = new TH2F("EB_12O6", "EB gain 12/6", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0037       TH2F* endc_p_12O6 = new TH2F("EE+_12O6", "EE+ gain 12/6", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0038       TH2F* endc_m_12O6 = new TH2F("EE-_12O6", "EE- gain 12/6", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0039       TH2F* barrel_6O1 = new TH2F("EB_6O1", "EB gain 6/1", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0040       TH2F* endc_p_6O1 = new TH2F("EE+_6O1", "EE+ gain 6/1", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0041       TH2F* endc_m_6O1 = new TH2F("EE-_6O1", "EE- gain 6/1", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0042       TH1F* b_12O6 = new TH1F("b_12O6", "EB gain 12/6", 50, 1.8, 2.1);
0043       TH1F* e_12O6 = new TH1F("e_12O6", "EE gain 12/6", 50, 1.8, 2.1);
0044       TH1F* b_6O1 = new TH1F("b_6O1", "EB gain 6/1", 100, 5.3, 6.3);
0045       TH1F* e_6O1 = new TH1F("e_6O1", "EE gain 6/1", 100, 5.3, 6.3);
0046 
0047       auto iov = iovs.front();
0048       std::shared_ptr<EcalGainRatios> payload = fetchPayload(std::get<1>(iov));
0049       unsigned int run = std::get<0>(iov);
0050       if (payload.get()) {
0051         // looping over the EB channels, via the dense-index, mapped into EBDetId's
0052         for (int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {  // loop on EB cells
0053           uint32_t rawid = EBDetId::unhashIndex(cellid);
0054           Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
0055           Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
0056           if (eta > 0.)
0057             eta = eta - 0.5;  //   0.5 to 84.5
0058           else
0059             eta = eta + 0.5;  //  -84.5 to -0.5
0060           barrel_12O6->Fill(phi, eta, (*payload)[rawid].gain12Over6());
0061           barrel_6O1->Fill(phi, eta, (*payload)[rawid].gain6Over1());
0062           b_12O6->Fill((*payload)[rawid].gain12Over6());
0063           b_6O1->Fill((*payload)[rawid].gain6Over1());
0064         }  // loop over cellid
0065 
0066         // looping over the EE channels
0067         for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
0068           if (!EEDetId::validHashIndex(cellid))
0069             continue;
0070           uint32_t rawid = EEDetId::unhashIndex(cellid);
0071           EEDetId myEEId(rawid);
0072           if (myEEId.zside() == 1) {
0073             endc_p_12O6->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain12Over6());
0074             endc_p_6O1->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain6Over1());
0075           } else {
0076             endc_m_12O6->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain12Over6());
0077             endc_m_6O1->Fill(myEEId.ix(), myEEId.iy(), (*payload)[rawid].gain6Over1());
0078           }
0079           e_12O6->Fill((*payload)[rawid].gain12Over6());
0080           e_6O1->Fill((*payload)[rawid].gain6Over1());
0081         }  // validDetId
0082       }  // if payload.get()
0083       else
0084         return false;
0085 
0086       gStyle->SetPalette(1);
0087       gStyle->SetOptStat(0);
0088       TCanvas canvas("CC map", "CC map", 1680, 1320);
0089       TLatex t1;
0090       t1.SetNDC();
0091       t1.SetTextAlign(26);
0092       t1.SetTextSize(0.05);
0093       t1.DrawLatex(0.5, 0.96, Form("Ecal Gain Ratios, IOV %i", run));
0094 
0095       float xmi[3] = {0.0, 0.22, 0.78};
0096       float xma[3] = {0.22, 0.78, 1.00};
0097       TPad*** pad = new TPad**[2];
0098       for (int gId = 0; gId < 2; gId++) {
0099         pad[gId] = new TPad*[3];
0100         for (int obj = 0; obj < 3; obj++) {
0101           float yma = 0.94 - (0.32 * gId);
0102           float ymi = yma - 0.28;
0103           pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId), Form("p_%i_%i", obj, gId), xmi[obj], ymi, xma[obj], yma);
0104           pad[gId][obj]->Draw();
0105         }
0106       }
0107       TPad** pad1 = new TPad*[4];
0108       for (int obj = 0; obj < 4; obj++) {
0109         float xmi = 0.26 * obj;
0110         float xma = xmi + 0.22;
0111         pad1[obj] = new TPad(Form("p1_%i", obj), Form("p1_%i", obj), xmi, 0.0, xma, 0.32);
0112         pad1[obj]->Draw();
0113       }
0114 
0115       float min12O6 = 1.8, max12O6 = 2.1, min6O1 = 5.3, max6O1 = 6.3;
0116       pad[0][0]->cd();
0117       DrawEE(endc_m_12O6, min12O6, max12O6);
0118       endc_m_12O6->SetStats(false);
0119       pad[0][1]->cd();
0120       DrawEB(barrel_12O6, min12O6, max12O6);
0121       barrel_12O6->SetStats(false);
0122       pad[0][2]->cd();
0123       DrawEE(endc_p_12O6, min12O6, max12O6);
0124       endc_p_12O6->SetStats(false);
0125       pad[1][0]->cd();
0126       DrawEE(endc_m_6O1, min6O1, max6O1);
0127       endc_m_6O1->SetStats(false);
0128       pad[1][1]->cd();
0129       DrawEB(barrel_6O1, min6O1, max6O1);
0130       barrel_6O1->SetStats(false);
0131       pad[1][2]->cd();
0132       DrawEE(endc_p_6O1, min6O1, max6O1);
0133       endc_p_6O1->SetStats(false);
0134 
0135       gStyle->SetOptStat(111110);
0136       pad1[0]->cd();
0137       b_12O6->Draw();
0138       pad1[0]->Update();
0139       TPaveStats* st = (TPaveStats*)b_12O6->FindObject("stats");
0140       st->SetX1NDC(0.6);   //new x start position
0141       st->SetY1NDC(0.75);  //new y start position
0142       pad1[1]->cd();
0143       e_12O6->Draw();
0144       pad1[0]->Update();
0145       st = (TPaveStats*)e_12O6->FindObject("stats");
0146       st->SetX1NDC(0.6);   //new x start position
0147       st->SetY1NDC(0.75);  //new y start position
0148       pad1[2]->cd();
0149       b_6O1->Draw();
0150       pad1[0]->Update();
0151       st = (TPaveStats*)b_6O1->FindObject("stats");
0152       st->SetX1NDC(0.6);   //new x start position
0153       st->SetY1NDC(0.75);  //new y start position
0154       pad1[3]->cd();
0155       e_6O1->Draw();
0156       pad1[0]->Update();
0157       st = (TPaveStats*)e_6O1->FindObject("stats");
0158       st->SetX1NDC(0.6);   //new x start position
0159       st->SetY1NDC(0.75);  //new y start position
0160 
0161       std::string ImageName(m_imageFileName);
0162       canvas.SaveAs(ImageName.c_str());
0163       return true;
0164     }  // fill method
0165   };
0166 
0167   /**********************************************************
0168      2d plot of ECAL GainRatios difference between 2 IOVs
0169   **********************************************************/
0170   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0171   class EcalGainRatiosDiffBase : public cond::payloadInspector::PlotImage<EcalGainRatios, nIOVs, ntags> {
0172   public:
0173     EcalGainRatiosDiffBase()
0174         : cond::payloadInspector::PlotImage<EcalGainRatios, nIOVs, ntags>("ECAL Gain Ratios difference") {}
0175 
0176     bool fill() override {
0177       TH2F* barrel_12O6 =
0178           new TH2F("EB_12O6", "EB gain 12/6 difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0179       TH2F* endc_p_12O6 =
0180           new TH2F("EE+_12O6", "EE+ gain 12/6 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0181       TH2F* endc_m_12O6 =
0182           new TH2F("EE-_12O6", "EE- gain 12/6 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0183       TH2F* barrel_6O1 =
0184           new TH2F("EB_6O1", "EB gain 6/1 difference", MAX_IPHI, 0, MAX_IPHI, 2 * MAX_IETA, -MAX_IETA, MAX_IETA);
0185       TH2F* endc_p_6O1 =
0186           new TH2F("EE+_6O1", "EE+ gain 6/1 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0187       TH2F* endc_m_6O1 =
0188           new TH2F("EE-_6O1", "EE- gain 6/1 difference", IX_MAX, IX_MIN, IX_MAX + 1, IY_MAX, IY_MIN, IY_MAX + 1);
0189       TH1F* b_12O6 = new TH1F("b_12O6", "EB gain 12/6 difference", 50, -0.1, 0.1);
0190       TH1F* e_12O6 = new TH1F("e_12O6", "EE gain 12/6 difference", 50, -0.1, 0.1);
0191       TH1F* b_6O1 = new TH1F("b_6O1", "EB gain 6/1 difference", 100, -0.1, 0.1);
0192       TH1F* e_6O1 = new TH1F("e_6O1", "EE gain 6/1 difference", 100, -0.1, 0.1);
0193 
0194       unsigned int run[2];
0195       float gEB[3][kEBChannels], gEE[3][kEEChannels];
0196       std::string l_tagname[2];
0197       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0198       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0199       auto firstiov = iovs.front();
0200       run[0] = std::get<0>(firstiov);
0201       std::tuple<cond::Time_t, cond::Hash> lastiov;
0202       if (ntags == 2) {
0203         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0204         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0205         lastiov = tag2iovs.front();
0206       } else {
0207         lastiov = iovs.back();
0208         l_tagname[1] = l_tagname[0];
0209       }
0210       run[1] = std::get<0>(lastiov);
0211       for (int irun = 0; irun < nIOVs; irun++) {
0212         std::shared_ptr<EcalGainRatios> payload;
0213         if (irun == 0) {
0214           payload = this->fetchPayload(std::get<1>(firstiov));
0215         } else {
0216           payload = this->fetchPayload(std::get<1>(lastiov));
0217         }
0218         if (payload.get()) {
0219           // looping over the EB channels, via the dense-index, mapped into EBDetId's
0220           for (int cellid = 0; cellid < EBDetId::kSizeForDenseIndexing; ++cellid) {  // loop on EB cells
0221             uint32_t rawid = EBDetId::unhashIndex(cellid);
0222             if (irun == 0) {
0223               gEB[0][cellid] = (*payload)[rawid].gain12Over6();
0224               gEB[1][cellid] = (*payload)[rawid].gain6Over1();
0225             } else {
0226               Double_t phi = (Double_t)(EBDetId(rawid)).iphi() - 0.5;
0227               Double_t eta = (Double_t)(EBDetId(rawid)).ieta();
0228               if (eta > 0.)
0229                 eta = eta - 0.5;  //   0.5 to 84.5
0230               else
0231                 eta = eta + 0.5;  //  -84.5 to -0.5
0232               float diff = gEB[0][cellid] - (*payload)[rawid].gain12Over6();
0233               barrel_12O6->Fill(phi, eta, diff);
0234               b_12O6->Fill(diff);
0235               diff = gEB[1][cellid] - (*payload)[rawid].gain6Over1();
0236               barrel_6O1->Fill(phi, eta, diff);
0237               b_6O1->Fill(diff);
0238             }
0239           }  // loop over cellid
0240 
0241           // looping over the EE channels
0242           for (int cellid = 0; cellid < EEDetId::kSizeForDenseIndexing; ++cellid) {
0243             if (!EEDetId::validHashIndex(cellid))
0244               continue;
0245             uint32_t rawid = EEDetId::unhashIndex(cellid);
0246             EEDetId myEEId(rawid);
0247             if (irun == 0) {
0248               gEE[0][cellid] = (*payload)[rawid].gain12Over6();
0249               gEE[1][cellid] = (*payload)[rawid].gain6Over1();
0250             } else {
0251               float diff1 = gEE[0][cellid] - (*payload)[rawid].gain12Over6();
0252               float diff2 = gEE[1][cellid] - (*payload)[rawid].gain6Over1();
0253               if (myEEId.zside() == 1) {
0254                 endc_p_12O6->Fill(myEEId.ix(), myEEId.iy(), diff1);
0255                 endc_p_6O1->Fill(myEEId.ix(), myEEId.iy(), diff2);
0256               } else {
0257                 endc_m_12O6->Fill(myEEId.ix(), myEEId.iy(), diff1);
0258                 endc_m_6O1->Fill(myEEId.ix(), myEEId.iy(), diff2);
0259               }
0260               e_12O6->Fill(diff1);
0261               e_6O1->Fill(diff2);
0262             }
0263           }  // loop over cellid
0264         }  //  if payload.get()
0265         else
0266           return false;
0267       }  // loop over IOVs
0268 
0269       gStyle->SetPalette(1);
0270       gStyle->SetOptStat(0);
0271       TCanvas canvas("CC map", "CC map", 1680, 1320);
0272       TLatex t1;
0273       t1.SetNDC();
0274       t1.SetTextAlign(26);
0275       int len = l_tagname[0].length() + l_tagname[1].length();
0276       if (ntags == 2 && len < 70) {
0277         t1.SetTextSize(0.03);
0278         t1.DrawLatex(
0279             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]));
0280       } else {
0281         t1.SetTextSize(0.05);
0282         t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0283       }
0284 
0285       float xmi[3] = {0.0, 0.22, 0.78};
0286       float xma[3] = {0.22, 0.78, 1.00};
0287       TPad*** pad = new TPad**[2];
0288       for (int gId = 0; gId < 2; gId++) {
0289         pad[gId] = new TPad*[3];
0290         for (int obj = 0; obj < 3; obj++) {
0291           float yma = 0.94 - (0.32 * gId);
0292           float ymi = yma - 0.28;
0293           pad[gId][obj] = new TPad(Form("p_%i_%i", obj, gId), Form("p_%i_%i", obj, gId), xmi[obj], ymi, xma[obj], yma);
0294           pad[gId][obj]->Draw();
0295         }
0296       }
0297       TPad** pad1 = new TPad*[4];
0298       for (int obj = 0; obj < 4; obj++) {
0299         float xmi = 0.26 * obj;
0300         float xma = xmi + 0.22;
0301         pad1[obj] = new TPad(Form("p1_%i", obj), Form("p1_%i", obj), xmi, 0.0, xma, 0.32);
0302         pad1[obj]->Draw();
0303       }
0304 
0305       float min12O6 = -0.1, max12O6 = 0.1, min6O1 = -0.1, max6O1 = 0.1;
0306       pad[0][0]->cd();
0307       DrawEE(endc_m_12O6, min12O6, max12O6);
0308       endc_m_12O6->SetStats(false);
0309       pad[0][1]->cd();
0310       DrawEB(barrel_12O6, min12O6, max12O6);
0311       barrel_12O6->SetStats(false);
0312       pad[0][2]->cd();
0313       DrawEE(endc_p_12O6, min12O6, max12O6);
0314       endc_p_12O6->SetStats(false);
0315       pad[1][0]->cd();
0316       DrawEE(endc_m_6O1, min6O1, max6O1);
0317       endc_m_6O1->SetStats(false);
0318       pad[1][1]->cd();
0319       DrawEB(barrel_6O1, min6O1, max6O1);
0320       barrel_6O1->SetStats(false);
0321       pad[1][2]->cd();
0322       DrawEE(endc_p_6O1, min6O1, max6O1);
0323       endc_p_6O1->SetStats(false);
0324 
0325       gStyle->SetOptStat(111110);
0326       pad1[0]->cd();
0327       b_12O6->Draw();
0328       pad1[0]->Update();
0329       TPaveStats* st = (TPaveStats*)b_12O6->FindObject("stats");
0330       st->SetX1NDC(0.6);   //new x start position
0331       st->SetY1NDC(0.75);  //new y start position
0332       pad1[1]->cd();
0333       e_12O6->Draw();
0334       pad1[0]->Update();
0335       st = (TPaveStats*)e_12O6->FindObject("stats");
0336       st->SetX1NDC(0.6);   //new x start position
0337       st->SetY1NDC(0.75);  //new y start position
0338       pad1[2]->cd();
0339       b_6O1->Draw();
0340       pad1[0]->Update();
0341       st = (TPaveStats*)b_6O1->FindObject("stats");
0342       st->SetX1NDC(0.6);   //new x start position
0343       st->SetY1NDC(0.75);  //new y start position
0344       pad1[3]->cd();
0345       e_6O1->Draw();
0346       pad1[0]->Update();
0347       st = (TPaveStats*)e_6O1->FindObject("stats");
0348       st->SetX1NDC(0.6);   //new x start position
0349       st->SetY1NDC(0.75);  //new y start position
0350 
0351       std::string ImageName(this->m_imageFileName);
0352       canvas.SaveAs(ImageName.c_str());
0353       return true;
0354     }  // fill method
0355   };  // class EcalGainRatiosDiffBase
0356   using EcalGainRatiosDiffOneTag = EcalGainRatiosDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0357   using EcalGainRatiosDiffTwoTags = EcalGainRatiosDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0358 
0359 }  // namespace
0360 
0361 // Register the classes as boost python plugin
0362 PAYLOAD_INSPECTOR_MODULE(EcalGainRatios) {
0363   PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosPlot);
0364   PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosDiffOneTag);
0365   PAYLOAD_INSPECTOR_CLASS(EcalGainRatiosDiffTwoTags);
0366 }