Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-10 02:53:49

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/EcalTimeOffsetConstant.h"
0010 
0011 #include "TH2F.h"  // a 2-D histogram with four bytes per cell (float)
0012 #include "TCanvas.h"
0013 #include "TLine.h"
0014 #include "TStyle.h"
0015 #include "TLatex.h"  //write mathematical equations.
0016 #include "TPave.h"
0017 #include "TPaveStats.h"
0018 #include <string>
0019 #include <fstream>
0020 
0021 namespace {
0022 
0023   /*******************************************************
0024  2d plot of Ecal Time Offset Constant of 1 IOV
0025  *******************************************************/
0026   class EcalTimeOffsetConstantPlot : public cond::payloadInspector::PlotImage<EcalTimeOffsetConstant> {
0027   public:
0028     EcalTimeOffsetConstantPlot()
0029         : cond::payloadInspector::PlotImage<EcalTimeOffsetConstant>("Ecal Time Offset Constant - map ") {
0030       setSingleIov(true);
0031     }
0032 
0033     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0034       auto iov = iovs.front();
0035       std::shared_ptr<EcalTimeOffsetConstant> payload = fetchPayload(std::get<1>(iov));
0036       unsigned int run = std::get<0>(iov);
0037       TH2F* align;
0038       int NbRows;
0039 
0040       if (payload.get()) {
0041         NbRows = 1;
0042         align = new TH2F("Time Offset Constant [ns]", "EB          EE", 2, 0, 2, NbRows, 0, NbRows);
0043         EcalTimeOffsetConstant it = (*payload);
0044 
0045         double row = NbRows - 0.5;
0046 
0047         align->Fill(0.5, row, it.getEBValue());
0048         align->Fill(1.5, row, it.getEEValue());
0049       } else
0050         return false;
0051 
0052       gStyle->SetPalette(1);
0053       gStyle->SetOptStat(0);
0054       TCanvas canvas("CC map", "CC map", 1000, 1000);
0055       TLatex t1;
0056       t1.SetNDC();
0057       t1.SetTextAlign(26);
0058       t1.SetTextSize(0.05);
0059       t1.SetTextColor(2);
0060       t1.DrawLatex(0.5, 0.96, Form("Ecal Time Offset Constant, IOV %i", run));
0061 
0062       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0063       pad->Draw();
0064       pad->cd();
0065       align->Draw("TEXT");
0066 
0067       drawTable(NbRows, 2);
0068 
0069       align->GetXaxis()->SetTickLength(0.);
0070       align->GetXaxis()->SetLabelSize(0.);
0071       align->GetYaxis()->SetTickLength(0.);
0072       align->GetYaxis()->SetLabelSize(0.);
0073 
0074       std::string ImageName(m_imageFileName);
0075       canvas.SaveAs(ImageName.c_str());
0076 
0077       return true;
0078     }
0079   };
0080 
0081   /*****************************************************************
0082      2d plot of Ecal Time Offset Constant difference between 2 IOVs
0083    *****************************************************************/
0084   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0085   class EcalTimeOffsetConstantDiffBase
0086       : public cond::payloadInspector::PlotImage<EcalTimeOffsetConstant, nIOVs, ntags> {
0087   public:
0088     EcalTimeOffsetConstantDiffBase()
0089         : cond::payloadInspector::PlotImage<EcalTimeOffsetConstant, nIOVs, ntags>(
0090               "Ecal Time Offset Constant difference") {}
0091 
0092     bool fill() override {
0093       unsigned int run[2], NbRows = 0;
0094       float val[2] = {};
0095       TH2F* align = new TH2F("", "", 1, 0., 1., 1, 0., 1.);  // pseudo creation
0096       std::string l_tagname[2];
0097       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0098       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0099       auto firstiov = iovs.front();
0100       run[0] = std::get<0>(firstiov);
0101       std::tuple<cond::Time_t, cond::Hash> lastiov;
0102       if (ntags == 2) {
0103         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0104         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0105         lastiov = tag2iovs.front();
0106       } else {
0107         lastiov = iovs.back();
0108         l_tagname[1] = l_tagname[0];
0109       }
0110       run[1] = std::get<0>(lastiov);
0111       for (int irun = 0; irun < nIOVs; irun++) {
0112         std::shared_ptr<EcalTimeOffsetConstant> payload;
0113         if (irun == 0) {
0114           payload = this->fetchPayload(std::get<1>(firstiov));
0115         } else {
0116           payload = this->fetchPayload(std::get<1>(lastiov));
0117         }
0118         if (payload.get()) {
0119           NbRows = 1;
0120 
0121           if (irun == 1)
0122             align = new TH2F("Ecal Time Offset Constant [ns]", "EB          EE", 2, 0, 2, NbRows, 0, NbRows);
0123 
0124           EcalTimeOffsetConstant it = (*payload);
0125 
0126           if (irun == 0) {
0127             val[0] = it.getEBValue();
0128             val[1] = it.getEEValue();
0129 
0130           } else {
0131             double row = NbRows - 0.5;
0132             align->Fill(0.5, row, it.getEBValue() - val[0]);
0133             align->Fill(1.5, row, it.getEEValue() - val[1]);
0134           }
0135 
0136         }  //  if payload.get()
0137         else
0138           return false;
0139       }  // loop over IOVs
0140 
0141       gStyle->SetPalette(1);
0142       gStyle->SetOptStat(0);
0143       TCanvas canvas("CC map", "CC map", 1000, 1000);
0144       TLatex t1;
0145       t1.SetNDC();
0146       t1.SetTextAlign(26);
0147       t1.SetTextColor(2);
0148       int len = l_tagname[0].length() + l_tagname[1].length();
0149       if (ntags == 2) {
0150         if (len < 80) {
0151           t1.SetTextSize(0.02);
0152           t1.DrawLatex(0.5, 0.96, Form("%s %i - %s %i", l_tagname[1].c_str(), run[1], l_tagname[0].c_str(), run[0]));
0153         } else {
0154           t1.SetTextSize(0.03);
0155           t1.DrawLatex(0.5, 0.96, Form("Ecal Time Offset Constant, IOV %i - %i", run[1], run[0]));
0156         }
0157       } else {
0158         t1.SetTextSize(0.03);
0159         t1.DrawLatex(0.5, 0.96, Form("%s, IOV %i - %i", l_tagname[0].c_str(), run[1], run[0]));
0160       }
0161 
0162       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0163       pad->Draw();
0164       pad->cd();
0165       align->Draw("TEXT");
0166 
0167       drawTable(NbRows, 2);
0168 
0169       align->GetXaxis()->SetTickLength(0.);
0170       align->GetXaxis()->SetLabelSize(0.);
0171       align->GetYaxis()->SetTickLength(0.);
0172       align->GetYaxis()->SetLabelSize(0.);
0173 
0174       std::string ImageName(this->m_imageFileName);
0175       canvas.SaveAs(ImageName.c_str());
0176       return true;
0177     }
0178   };  // class EcalTimeOffsetConstantDiffBase
0179   using EcalTimeOffsetConstantDiffOneTag = EcalTimeOffsetConstantDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0180   using EcalTimeOffsetConstantDiffTwoTags = EcalTimeOffsetConstantDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0181 
0182 }  // namespace
0183 
0184 // Register the classes as boost python plugin
0185 PAYLOAD_INSPECTOR_MODULE(EcalTimeOffsetConstant) {
0186   PAYLOAD_INSPECTOR_CLASS(EcalTimeOffsetConstantPlot);
0187   PAYLOAD_INSPECTOR_CLASS(EcalTimeOffsetConstantDiffOneTag);
0188   PAYLOAD_INSPECTOR_CLASS(EcalTimeOffsetConstantDiffTwoTags);
0189 }