Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/EcalSamplesCorrelation.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 Samples Correlation of 1 IOV
0025  *******************************************************/
0026   class EcalSamplesCorrelationPlot : public cond::payloadInspector::PlotImage<EcalSamplesCorrelation> {
0027   public:
0028     //void fill_align(const std::vector<double>& vect,TH2F* align, const int column, int row);
0029 
0030     EcalSamplesCorrelationPlot()
0031         : cond::payloadInspector::PlotImage<EcalSamplesCorrelation>("Ecal Samples Correlation - map ") {
0032       setSingleIov(true);
0033     }
0034 
0035     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0036       auto iov = iovs.front();
0037       std::shared_ptr<EcalSamplesCorrelation> payload = fetchPayload(std::get<1>(iov));
0038       unsigned int run = std::get<0>(iov);
0039       TH2F* align;
0040       int NbRows;
0041 
0042       if (payload.get()) {
0043         EcalSamplesCorrelation it = (*payload);
0044         NbRows = it.EBG12SamplesCorrelation.size();
0045         if (NbRows == 0)
0046           return false;
0047 
0048         align = new TH2F("Ecal Samples Correlation",
0049                          "EBG12          EBG06          EBG01          EEG12          EEG06          EEG01",
0050                          6,
0051                          0,
0052                          6,
0053                          NbRows,
0054                          0,
0055                          NbRows);
0056 
0057         double row = NbRows - 0.5;
0058 
0059         fill_align(it.EBG12SamplesCorrelation, align, 0.5, row);
0060         fill_align(it.EBG6SamplesCorrelation, align, 1.5, row);
0061         fill_align(it.EBG1SamplesCorrelation, align, 2.5, row);
0062 
0063         fill_align(it.EEG12SamplesCorrelation, align, 3.5, row);
0064         fill_align(it.EEG6SamplesCorrelation, align, 4.5, row);
0065         fill_align(it.EEG1SamplesCorrelation, align, 5.5, row);
0066 
0067       } else
0068         return false;
0069 
0070       gStyle->SetPalette(1);
0071       gStyle->SetOptStat(0);
0072       TCanvas canvas("CC map", "CC map", 1000, 1000);
0073       TLatex t1;
0074       t1.SetNDC();
0075       t1.SetTextAlign(26);
0076       t1.SetTextSize(0.05);
0077       t1.SetTextColor(2);
0078       t1.DrawLatex(0.5, 0.96, Form("Ecal Samples Correlation, IOV %i", run));
0079 
0080       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0081       pad->Draw();
0082       pad->cd();
0083       align->Draw("TEXT");
0084 
0085       drawTable(NbRows, 6);
0086 
0087       align->GetXaxis()->SetTickLength(0.);
0088       align->GetXaxis()->SetLabelSize(0.);
0089       align->GetYaxis()->SetTickLength(0.);
0090       align->GetYaxis()->SetLabelSize(0.);
0091 
0092       std::string ImageName(m_imageFileName);
0093       canvas.SaveAs(ImageName.c_str());
0094 
0095       return true;
0096     }
0097 
0098     void fill_align(const std::vector<double>& vect, TH2F* align, const float column, double row) {
0099       for (std::vector<double>::const_iterator i = vect.begin(); i != vect.end(); ++i) {
0100         align->Fill(column, row, *i);
0101         row = row - 1;
0102       }
0103     }
0104   };
0105 
0106   /*******************************************************
0107  2d plot of Ecal Samples Correlation difference between 2 IOVs
0108 *******************************************************/
0109   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0110   class EcalSamplesCorrelationDiffBase
0111       : public cond::payloadInspector::PlotImage<EcalSamplesCorrelation, nIOVs, ntags> {
0112   public:
0113     EcalSamplesCorrelationDiffBase()
0114         : cond::payloadInspector::PlotImage<EcalSamplesCorrelation, nIOVs, ntags>(
0115               "Ecal Samples Correlation difference") {}
0116     bool fill() override {
0117       unsigned int run[2];
0118       float val[6][36];
0119       TH2F* align = new TH2F("", "", 1, 0., 1., 1, 0., 1.);  // pseudo creation
0120       int NbRows = 0;
0121       std::string l_tagname[2];
0122 
0123       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0124       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0125       auto firstiov = iovs.front();
0126       run[0] = std::get<0>(firstiov);
0127       std::tuple<cond::Time_t, cond::Hash> lastiov;
0128       if (ntags == 2) {
0129         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0130         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0131         lastiov = tag2iovs.front();
0132       } else {
0133         lastiov = iovs.back();
0134         l_tagname[1] = l_tagname[0];
0135       }
0136       run[1] = std::get<0>(lastiov);
0137       for (int irun = 0; irun < nIOVs; irun++) {
0138         std::shared_ptr<EcalSamplesCorrelation> payload;
0139         if (irun == 0) {
0140           payload = this->fetchPayload(std::get<1>(firstiov));
0141         } else {
0142           payload = this->fetchPayload(std::get<1>(lastiov));
0143         }
0144 
0145         if (payload.get()) {
0146           EcalSamplesCorrelation it = (*payload);
0147           NbRows = it.EBG12SamplesCorrelation.size();
0148 
0149           if (irun == 1) {
0150             align = new TH2F("Ecal Samples Correlation",
0151                              "EBG12          EBG06          EBG01          EEG12          EEG06          EEG01",
0152                              6,
0153                              0,
0154                              6,
0155                              NbRows,
0156                              0,
0157                              NbRows);
0158           }
0159 
0160           double row = NbRows - 0.5;
0161 
0162           fill_align(it.EBG12SamplesCorrelation, align, val[0], 0.5, row, irun);
0163           fill_align(it.EBG6SamplesCorrelation, align, val[1], 1.5, row, irun);
0164           fill_align(it.EBG1SamplesCorrelation, align, val[2], 2.5, row, irun);
0165 
0166           fill_align(it.EEG12SamplesCorrelation, align, val[3], 3.5, row, irun);
0167           fill_align(it.EEG6SamplesCorrelation, align, val[4], 4.5, row, irun);
0168           fill_align(it.EEG1SamplesCorrelation, align, val[5], 5.5, row, irun);
0169 
0170         }  //  if payload.get()
0171         else
0172           return false;
0173       }  // loop over IOVs
0174 
0175       gStyle->SetPalette(1);
0176       gStyle->SetOptStat(0);
0177       TCanvas canvas("CC map", "CC map", 1000, 1000);
0178       TLatex t1;
0179       t1.SetNDC();
0180       t1.SetTextAlign(26);
0181       t1.SetTextSize(0.05);
0182       t1.SetTextColor(2);
0183       t1.DrawLatex(0.5, 0.96, Form("Ecal Samples Correlation, IOV %i - %i", run[1], run[0]));
0184 
0185       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0186       pad->Draw();
0187       pad->cd();
0188       align->Draw("TEXT");
0189       TLine* l = new TLine;
0190       l->SetLineWidth(1);
0191 
0192       drawTable(NbRows, 6);
0193 
0194       align->GetXaxis()->SetTickLength(0.);
0195       align->GetXaxis()->SetLabelSize(0.);
0196       align->GetYaxis()->SetTickLength(0.);
0197       align->GetYaxis()->SetLabelSize(0.);
0198 
0199       std::string ImageName(this->m_imageFileName);
0200       canvas.SaveAs(ImageName.c_str());
0201 
0202       return true;
0203     }
0204 
0205     void fill_align(
0206         const std::vector<double>& vect, TH2F* align, float val[], const float column, double row, unsigned irun) {
0207       int irow = 0;
0208 
0209       for (std::vector<double>::const_iterator i = vect.begin(); i != vect.end(); ++i) {
0210         if (irun == 0) {
0211           val[irow] = (*i);
0212         } else {
0213           align->Fill(column, row, (*i) - val[irow]);
0214           row--;
0215         }
0216         irow++;
0217       }
0218     }
0219   };  // class EcalSamplesCorrelationDiffBase
0220   using EcalSamplesCorrelationDiffOneTag = EcalSamplesCorrelationDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0221   using EcalSamplesCorrelationDiffTwoTags = EcalSamplesCorrelationDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0222 
0223 }  // namespace
0224 
0225 // Register the classes as boost python plugin
0226 PAYLOAD_INSPECTOR_MODULE(EcalSamplesCorrelation) {
0227   PAYLOAD_INSPECTOR_CLASS(EcalSamplesCorrelationPlot);
0228   PAYLOAD_INSPECTOR_CLASS(EcalSamplesCorrelationDiffOneTag);
0229   PAYLOAD_INSPECTOR_CLASS(EcalSamplesCorrelationDiffTwoTags);
0230 }