Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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/Alignment/interface/Alignments.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   enum { kEBChannels = 61200, kEEChannels = 14648 };
0023   enum {
0024     MIN_IETA = 1,
0025     MIN_IPHI = 1,
0026     MAX_IETA = 85,
0027     MAX_IPHI = 360
0028   };  // barrel (EB) lower and upper bounds on eta and phi
0029   enum { IX_MIN = 1, IY_MIN = 1, IX_MAX = 100, IY_MAX = 100 };  // endcaps (EE) lower and upper bounds on x and y
0030 
0031   /*****************************************
0032  2d plot of ECAL Alignment of 1 IOV
0033  ******************************************/
0034   class EcalAlignmentPlot : public cond::payloadInspector::PlotImage<Alignments> {
0035   public:
0036     EcalAlignmentPlot() : cond::payloadInspector::PlotImage<Alignments>("ECAL Alignment - map ") { setSingleIov(true); }
0037 
0038     bool fill(const std::vector<std::tuple<cond::Time_t, cond::Hash> >& iovs) override {
0039       auto iov = iovs.front();  //get reference to 1st element in the vector iovs
0040       std::shared_ptr<Alignments> payload =
0041           fetchPayload(std::get<1>(iov));   //std::get<1>(iov) refers to the Hash in the tuple iov
0042       unsigned int run = std::get<0>(iov);  //referes to Time_t in iov.
0043       TH2F* align;                          //pointer to align which is a 2D histogram
0044       std::string subdet;
0045       int NbRows;
0046       if (payload.get()) {  //payload is an iov retrieved from payload using hash.
0047         NbRows = (*payload).m_align.size();
0048         if (NbRows == 36)
0049           subdet = "EB";
0050         else if (NbRows == 4)
0051           subdet = "EE";
0052         else if (NbRows == 8)
0053           subdet = "ES";
0054         else
0055           subdet = "unknown";
0056         //  align = new TH2F("Align",Form("Alignment %s", subdet.c_str()),6, 0, 6, NbRows, 0, NbRows);
0057         align = new TH2F("Align",
0058                          "x           y            z               Phi         Theta         Psi",
0059                          6,
0060                          0,
0061                          6,
0062                          NbRows,
0063                          0,
0064                          NbRows);
0065 
0066         double row = NbRows - 0.5;
0067         for (std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
0068              it != (*payload).m_align.end();
0069              it++) {
0070           align->Fill(0.5, row, (*it).translation().x());
0071           align->Fill(1.5, row, (*it).translation().y());
0072           align->Fill(2.5, row, (*it).translation().z());
0073           align->Fill(3.5, row, (*it).rotation().getPhi());
0074           align->Fill(4.5, row, (*it).rotation().getTheta());
0075           align->Fill(5.5, row, (*it).rotation().getPsi());
0076           row = row - 1.;
0077         }
0078       }  // if payload.get()
0079       else
0080         return false;
0081 
0082       gStyle->SetPalette(1);
0083       gStyle->SetOptStat(0);
0084       TCanvas canvas("CC map", "CC map", 1000, 1000);
0085       TLatex t1;
0086       t1.SetNDC();
0087       t1.SetTextAlign(26);
0088       t1.SetTextSize(0.05);
0089       t1.SetTextColor(2);
0090       t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i", subdet.c_str(), run));
0091       //      t1.SetTextSize(0.03);
0092       //      t1.DrawLatex(0.3, 0.94, "x          y           z           Phi          Theta          Psi");
0093 
0094       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0095       pad->Draw();
0096       pad->cd();
0097       align->Draw("TEXT");
0098       TLine* l = new TLine;
0099       l->SetLineWidth(1);
0100       for (int i = 1; i < NbRows; i++) {
0101         double y = (double)i;
0102         l = new TLine(0., y, 6., y);
0103         l->Draw();
0104       }
0105 
0106       for (int i = 1; i < 6; i++) {
0107         double x = (double)i;
0108         double y = (double)NbRows;
0109         l = new TLine(x, 0., x, y);
0110         l->Draw();
0111       }
0112 
0113       align->GetXaxis()->SetTickLength(0.);
0114       align->GetXaxis()->SetLabelSize(0.);
0115       align->GetYaxis()->SetTickLength(0.);
0116       align->GetYaxis()->SetLabelSize(0.);
0117 
0118       std::string ImageName(m_imageFileName);
0119       canvas.SaveAs(ImageName.c_str());
0120       return true;
0121     }  // fill method
0122   };
0123 
0124   /*********************************************************
0125       2d plot of ECAL Alignment difference between 2 IOVs
0126   **********************************************************/
0127   template <cond::payloadInspector::IOVMultiplicity nIOVs, int ntags>
0128   class EcalAlignmentDiffBase : public cond::payloadInspector::PlotImage<Alignments, nIOVs, ntags> {
0129   public:
0130     EcalAlignmentDiffBase()
0131         : cond::payloadInspector::PlotImage<Alignments, nIOVs, ntags>("ECAL Alignment difference") {}
0132 
0133     bool fill() override {
0134       unsigned int run[2];
0135       float val[6][36];
0136       TH2F* align = new TH2F("", "", 1, 0., 1., 1, 0., 1.);  // pseudo creation
0137       std::string subdet;
0138       int NbRows = 0;
0139       std::string l_tagname[2];
0140 
0141       auto iovs = cond::payloadInspector::PlotBase::getTag<0>().iovs;
0142       l_tagname[0] = cond::payloadInspector::PlotBase::getTag<0>().name;
0143       auto firstiov = iovs.front();
0144       run[0] = std::get<0>(firstiov);
0145       std::tuple<cond::Time_t, cond::Hash> lastiov;
0146       if (ntags == 2) {
0147         auto tag2iovs = cond::payloadInspector::PlotBase::getTag<1>().iovs;
0148         l_tagname[1] = cond::payloadInspector::PlotBase::getTag<1>().name;
0149         lastiov = tag2iovs.front();
0150       } else {
0151         lastiov = iovs.back();
0152         l_tagname[1] = l_tagname[0];
0153       }
0154       run[1] = std::get<0>(lastiov);
0155 
0156       for (int irun = 0; irun < nIOVs; irun++) {
0157         std::shared_ptr<Alignments> payload;
0158         if (irun == 0) {
0159           payload = this->fetchPayload(std::get<1>(firstiov));
0160         } else {
0161           payload = this->fetchPayload(std::get<1>(lastiov));
0162         }
0163 
0164         if (payload.get()) {
0165           NbRows = (*payload).m_align.size();
0166           if (irun == 1) {
0167             if (NbRows == 36)
0168               subdet = "EB";
0169             else if (NbRows == 4)
0170               subdet = "EE";
0171             else if (NbRows == 8)
0172               subdet = "ES";
0173             else
0174               subdet = "unknown";
0175             delete align;
0176             align = new TH2F("Align",
0177                              "x           y            z               Phi         Theta         Psi",
0178                              6,
0179                              0,
0180                              6,
0181                              NbRows,
0182                              0,
0183                              NbRows);
0184           }
0185 
0186           double row = NbRows - 0.5;
0187           int irow = 0;
0188           for (std::vector<AlignTransform>::const_iterator it = (*payload).m_align.begin();
0189                it != (*payload).m_align.end();
0190                it++) {
0191             if (irun == 0) {
0192               val[0][irow] = (*it).translation().x();
0193               val[1][irow] = (*it).translation().y();
0194               val[2][irow] = (*it).translation().z();
0195               val[3][irow] = (*it).rotation().getPhi();
0196               val[4][irow] = (*it).rotation().getTheta();
0197               val[5][irow] = (*it).rotation().getPsi();
0198             } else {
0199               align->Fill(0.5, row, (*it).translation().x() - val[0][irow]);
0200               align->Fill(1.5, row, (*it).translation().y() - val[1][irow]);
0201               align->Fill(2.5, row, (*it).translation().z() - val[2][irow]);
0202               align->Fill(3.5, row, (*it).rotation().getPhi() - val[3][irow]);
0203               align->Fill(4.5, row, (*it).rotation().getTheta() - val[3][irow]);
0204               align->Fill(5.5, row, (*it).rotation().getPsi() - val[5][irow]);
0205               row = row - 1.;
0206             }
0207             irow++;
0208           }  // loop over alignment rows
0209 
0210         }  //  if payload.get()
0211         else
0212           return false;
0213       }  // loop over IOVs
0214 
0215       gStyle->SetPalette(1);
0216       gStyle->SetOptStat(0);
0217       TCanvas canvas("CC map", "CC map", 1000, 1000);
0218       TLatex t1;
0219       t1.SetNDC();
0220       t1.SetTextAlign(26);
0221       t1.SetTextColor(2);
0222       int len = l_tagname[0].length() + l_tagname[1].length();
0223       if (ntags == 2 && len < 58) {
0224         t1.SetTextSize(0.025);
0225         t1.DrawLatex(
0226             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]));
0227       } else {
0228         t1.SetTextSize(0.05);
0229         t1.DrawLatex(0.5, 0.96, Form("Ecal %s Alignment, IOV %i - %i", subdet.c_str(), run[1], run[0]));
0230       }
0231       TPad* pad = new TPad("pad", "pad", 0.0, 0.0, 1.0, 0.94);
0232       pad->Draw();
0233       pad->cd();
0234       align->Draw("TEXT");
0235       TLine* l = new TLine;
0236       l->SetLineWidth(1);
0237 
0238       for (int i = 1; i < NbRows; i++) {
0239         double y = (double)i;
0240         l = new TLine(0., y, 6., y);
0241         l->Draw();
0242       }
0243 
0244       for (int i = 1; i < 6; i++) {
0245         double x = (double)i;
0246         double y = (double)NbRows;
0247         l = new TLine(x, 0., x, y);
0248         l->Draw();
0249       }
0250 
0251       align->GetXaxis()->SetTickLength(0.);
0252       align->GetXaxis()->SetLabelSize(0.);
0253       align->GetYaxis()->SetTickLength(0.);
0254       align->GetYaxis()->SetLabelSize(0.);
0255 
0256       std::string ImageName(this->m_imageFileName);
0257       canvas.SaveAs(ImageName.c_str());
0258       return true;
0259     }  // fill method
0260   };  // class EcalAlignmentDiffBase
0261   using EcalAlignmentDiffOneTag = EcalAlignmentDiffBase<cond::payloadInspector::SINGLE_IOV, 1>;
0262   using EcalAlignmentDiffTwoTags = EcalAlignmentDiffBase<cond::payloadInspector::SINGLE_IOV, 2>;
0263 
0264 }  // namespace
0265 
0266 // Register the classes as boost python plugin
0267 PAYLOAD_INSPECTOR_MODULE(EcalAlignment) {
0268   PAYLOAD_INSPECTOR_CLASS(EcalAlignmentPlot);
0269   PAYLOAD_INSPECTOR_CLASS(EcalAlignmentDiffOneTag);
0270   PAYLOAD_INSPECTOR_CLASS(EcalAlignmentDiffTwoTags);
0271 }