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